mrgsolve
modelheader.h
Go to the documentation of this file.
1 // Copyright (C) 2013 - 2019 Metrum Research Group
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 
18 #ifndef MODELHEADER_H
19 #define MODELHEADER_H
20 
21 #include <vector>
22 #include <math.h>
23 #include "mrgsolv.h"
24 
25 typedef double local_double;
26 typedef int local_int;
27 typedef bool local_bool;
28 typedef double capture;
29 
30 // pred_P definitions for $PKMODEL
31 // Note that V/VC/V2 are synonymous when using the pred_P construct
32 // Also, V3/V3 are synonyms as well
33 #define pred_CL _pred_[0]
34 #define pred_V _pred_[1]
35 #define pred_VC _pred_[1]
36 #define pred_V2 _pred_[1]
37 #define pred_KA _pred_[2]
38 #define pred_Q _pred_[3]
39 #define pred_V3 _pred_[4]
40 #define pred_VP _pred_[4]
41 
42 // advan/trans combinations
43 // These definitions are added by mrgsolve at the end of $MAIN
44 // when $PKMODEL is called; trans 2/4 are default; when 11 is picked ... tack on a `i` at the end
45 #define __ADVAN1_TRANS2__ pred_CL = CL; pred_V = V;
46 #define __ADVAN2_TRANS2__ pred_CL = CL; pred_V = V; pred_KA = KA;
47 #define __ADVAN3_TRANS4__ pred_CL = CL; pred_V2 = V1; pred_Q = Q; pred_V3 = V2;
48 #define __ADVAN4_TRANS4__ pred_CL = CL; pred_V2 = V2; pred_Q = Q; pred_V3 = V3; pred_KA = KA;
49 #define __ADVAN1_TRANS11__ pred_CL = CLi; pred_V = Vi;
50 #define __ADVAN2_TRANS11__ pred_CL = CLi; pred_V = Vi; pred_KA = KAi;
51 #define __ADVAN3_TRANS11__ pred_CL = CLi; pred_V2 = V1i; pred_Q = Qi; pred_V3 = V2i;
52 #define __ADVAN4_TRANS11__ pred_CL = CLi; pred_V2 = V2i; pred_Q = Qi; pred_V3 = V3i; pred_KA = KAi;
53 
54 // Don't need this?
55 #define __BEGIN_pred__ extern "C" {void __ODEFUN___(MRGSOLVE_PRED_SIGNATURE) {
56 
57 // $MAIN, $ODE, and $TABLE get translated into these functions
58 // We need ODEFUN___ and INITFUN___ and TABLECODE___ defined in the
59 // .cpp.cpp model file
60 #define __BEGIN_config__ extern "C" { void __CONFIGFUN___(MRGSOLVE_CONFIG_SIGNATURE) {
61 #define __END_config__ __DONE__
62 #define __BEGIN_ode__ extern "C" { void __ODEFUN___(MRGSOLVE_ODE_SIGNATURE) {
63 #define __END_ode__ __DONE__
64 #define __BEGIN_main__ extern "C" { void __INITFUN___(MRGSOLVE_INIT_SIGNATURE) {
65 #define __END_main__ __DONE__
66 #define __BEGIN_table__ extern "C" { void __TABLECODE___(MRGSOLVE_TABLE_SIGNATURE) {
67 #define __END_table__ __DONE__
68 #define __DONE__ }}
69 
70 
71 // New individual flag
72 #define NEWIND self.newind
73 // The data set time
74 #define TIME self.time
75 // The ode solver time
76 #define SOLVERTIME _ODETIME_[0]
77 // Event ID
78 #define EVID self.evid
79 // Data set individual
80 #define ID self.id
81 // Data set amt
82 #define AMT self.amt
83 // Data set cmt
84 #define CMT self.cmt
85 // Bool flag indicating that the system is advancing to steady-state
86 #define SS_ADVANCE _ss_flag_
87 
88 // These are the fundamental macros for
89 // bioavailability, infusion rate, infusion duration
90 // and dose lag time. Keep these here, but
91 // the model spec should prefer F_CMT, R_CMT, D_CMT, ALAG_CMT
92 #define _F(a) _F_[a-1]
93 #define _R(a) _R_[a-1]
94 #define _D(a) _D_[a-1]
95 #define _ALAG(a) _ALAG_[a-1]
96 
97 // These are the fundamental macros for
98 // random effects. These might get used,
99 // but users are allowed to insert labels to
100 // avoid directly accessing the macros.
101 #define ETA(a) self.ETA.at(a-1)
102 #define EPS(a) self.EPS.at(a-1)
103 #define _xETA(a) self.ETA[a-1]
104 #define _xEPS(a) self.EPS[a-1]
105 
106 // Number of equations
107 #define _NEQ (_A_0_.size())
108 
109 // Extract objects out of $ENV
110 #define _MRGX_GET(a,b) b = mrgx::get<a>(self,#b);
111 #define _MRGX_GET_LOCAL(a,b) a b = mrgx::get<a>(self,#b);
112 #define _MRGX_MT_FUN(a) Rcpp::Function a = mrgx::mt_fun();
113 
114 // Macros related to stopping the advance of the system
115 // once a condition is met
116 #define SYSTEMSTOPADVANCING() (self.SYSTEMOFF=1);
117 #define STOPADVANCING() SYSTEMSTOPADVANCING() // Not sure why this is here
118 #define CFONSTOP() (self.CFONSTOP = true); // Carry forward on stop
119 #define SYSTEMNOTADVANCING (self.SYSTEMOFF)
120 #define SOLVINGPROBLEM (self.solving)
121 #define _SETINIT if(self.newind <=1) // Convenience
122 #define _STOP_ID() (self.SYSTEMOFF=2);
123 #define _STOP_ID_CF() (self.SYSTEMOFF=1);
124 #define _STOP_ERROR() (self.SYSTEMOFF=9);
125 
126 // Macro to insert dxdt_CMT = 0; for all compartments
127 #define DXDTZERO() for(int _i_ = 0; _i_ < _nEQ; ++_i_) _DADT_[_i_] = 0;
128 
129 #endif
capture
double capture
Definition: modelheader.h:28
mrgsolv.h
local_bool
bool local_bool
Definition: modelheader.h:27
local_double
double local_double
Definition: modelheader.h:25
local_int
int local_int
Definition: modelheader.h:26