mrgsolve
mrgsolv.h
Go to the documentation of this file.
1 // Copyright (C) 2013 - 2019 Metrum Research Group, LLC
2 //
3 // This file is part of mrgsolve.
4 //
5 // mrgsolve is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // mrgsolve is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with mrgsolve. If not, see <http://www.gnu.org/licenses/>.
17 
22 #ifndef MRGSOLV_H
23 #define MRGSOLV_H
24 
25 #include <vector>
26 #include <iostream>
27 
28 typedef void (*refun)(void*);
29 
30 namespace mrgsolve {
38 struct resim {
40  resim(refun x, void* y) : fun(x), prob(y){}
41  resim(){}
42  void operator()() {
43  return fun(prob);
44  }
45 
46 protected:
48  void* prob;
49 };
50 
51 struct evdata {
52  evdata(double a_, int b_) : time(a_), evid(b_) {
53  cmt = 1;
54  amt = 0.0;
55  rate = 0.0;
56  now = false;
57  }
58  double time;
59  int evid;
60  int cmt;
61  double amt;
62  double rate;
63  bool now;
64 };
65 
66 // Some functions for reporting values during a
67 // simulation run
68 template <class type> void report(type a) {
69  std::cout << "from report " << a << std::endl;
70 }
71 template <class type1, class type2> void report(type1 a, type2 b) {
72  std::cout << a << " " << b << std::endl;
73 }
74 
75 }
76 namespace mrg = mrgsolve;
77 
79 
87 class databox {
88 public:
89  std::vector<double> ETA;
90  std::vector<double> EPS;
91  unsigned int newind;
92  double time;
93  int evid;
94  unsigned short int SYSTEMOFF;
95  double id;
96  double amt;
97  short int cmt;
98  int nid;
99  int idn;
100  int nrow;
101  int rown;
102  bool CFONSTOP;
103  void* envir;
104  void stop() {SYSTEMOFF=9;}
105  void stop_id() {SYSTEMOFF=1;}
107  std::vector<mrgsolve::evdata> mevector;
108  void mevent(double time, int evid);
109  double mtime(double time);
110  double tad();
111 };
112 
114 typedef std::vector<double> dvec;
115 
117 #define MRGSOLVE_INIT_SIGNATURE dvec& _A_0_,const dvec& _A_, const dvec& _THETA_, dvec& _F_, dvec& _ALAG_, dvec& _R_, dvec& _D_, databox& self, dvec& _pred_, mrgsolve::resim& simeta
118 #define MRGSOLVE_INIT_SIGNATURE_N 10
119 
121 #define MRGSOLVE_TABLE_SIGNATURE const dvec& _A_, const dvec& _A_0_, dvec& _THETA_, const dvec& _F_, const dvec& _R_, databox& self, const dvec& _pred_, dvec& _capture_, mrgsolve::resim& simeps
122 #define MRGSOLVE_TABLE_SIGNATURE_N 9
123 
125 #define MRGSOLVE_ODE_SIGNATURE const double* _ODETIME_, const double* _A_, double* _DADT_, const dvec& _A_0_, const dvec& _THETA_, const bool _ss_flag_
126 #define MRGSOLVE_ODE_SIGNATURE_N 6
127 
129 #define MRGSOLVE_CONFIG_SIGNATURE databox& self, const dvec& _THETA_, const double neq, const double npar
130 #define MRGSOLVE_CONFIG_SIGNATURE_N 4
131 
132 #endif
databox::rown
int rown
current output row number
Definition: mrgsolv.h:101
mrgsolve::resim::prob
void * prob
object to pass to re-simulated function
Definition: mrgsolv.h:48
databox::SYSTEMOFF
unsigned short int SYSTEMOFF
flag to stop advancing system for current ID
Definition: mrgsolv.h:94
mrgsolve::evdata::cmt
int cmt
Definition: mrgsolv.h:60
databox::mevent
void mevent(double time, int evid)
constructor for evdata objects
Definition: databox_cpp.h:18
databox::stop_id
void stop_id()
stops solving for the current id, filling with NA
Definition: mrgsolv.h:105
refun
void(* refun)(void *)
Definition: mrgsolv.h:28
dvec
std::vector< double > dvec
vector of doubles
Definition: mrgsolv.h:114
databox::stop
void stop()
stops the problem when the next record is started
Definition: mrgsolv.h:104
databox::stop_id_cf
void stop_id_cf()
stops solving for the current id, filling last value
Definition: mrgsolv.h:106
mrgsolve::evdata::amt
double amt
Definition: mrgsolv.h:61
databox::id
double id
current ID
Definition: mrgsolv.h:95
databox::time
double time
current simulation time
Definition: mrgsolv.h:92
databox::amt
double amt
current dosing amount value
Definition: mrgsolv.h:96
databox::newind
unsigned int newind
new individual flag
Definition: mrgsolv.h:91
mrgsolve::resim::fun
refun fun
function to call to re-simulate
Definition: mrgsolv.h:47
mrgsolve::evdata::evdata
evdata(double a_, int b_)
Definition: mrgsolv.h:52
mrgsolve::resim::operator()
void operator()()
Definition: mrgsolv.h:42
databox::idn
int idn
current ID number
Definition: mrgsolv.h:99
databox::tad
double tad()
calculates time after dose
Definition: databox_cpp.h:36
databox::EPS
std::vector< double > EPS
vector of EPS values
Definition: mrgsolv.h:90
mrgsolve::resim::resim
resim(refun x, void *y)
resim constructor
Definition: mrgsolv.h:40
mrgsolve::resim::resim
resim()
Definition: mrgsolv.h:41
databox::cmt
short int cmt
current compartment value
Definition: mrgsolv.h:97
databox::CFONSTOP
bool CFONSTOP
carry forward on stop indicator
Definition: mrgsolv.h:102
mrgsolve::evdata
Definition: mrgsolv.h:51
databox::ETA
std::vector< double > ETA
vector of ETA values
Definition: mrgsolv.h:89
databox
member functions mevent and tad come in via housemodel; see inst/base/databox.cpp
Definition: mrgsolv.h:87
databox::mevector
std::vector< mrgsolve::evdata > mevector
a collection of model events to pass back
Definition: mrgsolv.h:107
mrgsolve::report
void report(type a)
Definition: mrgsolv.h:68
mrgsolve::resim
Resim functor.
Definition: mrgsolv.h:38
mrgsolve::evdata::time
double time
Definition: mrgsolv.h:58
mrgsolve
Definition: mrgsolv.h:30
databox::nrow
int nrow
number of rows in output data set
Definition: mrgsolv.h:100
mrgsolve::evdata::rate
double rate
Definition: mrgsolv.h:62
databox::mtime
double mtime(double time)
creates evdata object for simple model event time
Definition: databox_cpp.h:23
databox::evid
int evid
event ID flag
Definition: mrgsolv.h:93
mrgsolve::evdata::now
bool now
Definition: mrgsolv.h:63
databox::envir
void * envir
model environment
Definition: mrgsolv.h:103
databox::nid
int nid
number of IDs in the data set
Definition: mrgsolv.h:98
mrgsolve::evdata::evid
int evid
Definition: mrgsolv.h:59