mrgsolve
Loading...
Searching...
No Matches
mrgsolv.h
Go to the documentation of this file.
1// Copyright (C) 2013 - 2026 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
21
22#ifndef MRGSOLV_H
23#define MRGSOLV_H
24
25#include <vector>
26#include <iostream>
27
28typedef void (*refun)(void*);
29
30namespace mrgsolve {
38struct resim {
40 resim(refun x, void* y) : fun(x), prob(y){}
42 void operator()() {
43 return fun(prob);
44 }
45
46protected:
48 void* prob;
49};
50
51struct evdata {
52 evdata(double a_, int b_) : time(a_), evid(b_) {
53 cmt = 1;
54 amt = 0.0;
55 rate = 0.0;
56 ii = 0.0;
57 ss = 0;
58 addl = 0;
59 now = false;
60 check_unique = false;
61 }
62 double time;
63 int evid;
64 int cmt;
65 double amt;
66 double rate;
67 double ii;
68 int ss;
69 int addl;
70 bool now;
72};
73
74// Some functions for reporting values during a
75// simulation run
76template <class type> void report(type a) {
77 std::cout << "from report " << a << std::endl;
78}
79template <class type1, class type2> void report(type1 a, type2 b) {
80 std::cout << a << " " << b << std::endl;
81}
82
83}
84namespace mrg = mrgsolve;
85
87
88
96class databox {
97public:
98 std::vector<double> ETA;
99 std::vector<double> EPS;
100 std::vector<double> SIGMA;
101 unsigned int newind;
102 double time;
103 int evid;
104 unsigned short int SYSTEMOFF;
105 double id;
106 double amt;
107 short int cmt;
108 int nid;
109 int idn;
110 int nrow;
111 int rown;
112 int irown;
113 int inrow;
114 bool CFONSTOP;
115 void* envir;
116 void stop() {SYSTEMOFF=9;}
117 void stop_id() {SYSTEMOFF=2;}
119 std::vector<mrgsolve::evdata> mevector;
120 void mevent(double time_, int evid_);
121 void push(mrgsolve::evdata x);
122 double mtime(double time_);
123 double tad();
124};
125
127typedef std::vector<double> dvec;
128
130#define MRGSOLVE_INIT_SIGNATURE \
131 dvec& _A_0_, \
132 const dvec& _A_, \
133 const dvec& _THETA_, \
134 dvec& _F_, \
135 dvec& _ALAG_, \
136 dvec& _R_, \
137 dvec& _D_, \
138 databox& self, \
139 dvec& _pred_, \
140 mrgsolve::resim& simeta
141#define MRGSOLVE_INIT_SIGNATURE_N 10
142
144#define MRGSOLVE_TABLE_SIGNATURE \
145 const dvec& _A_0_, \
146 const dvec& _A_, \
147 dvec& _THETA_, \
148 const dvec& _F_, \
149 const dvec& _ALAG_, \
150 const dvec& _R_, \
151 const dvec& _D_, \
152 databox& self, \
153 const dvec& _pred_, \
154 dvec& _capture_, \
155 mrgsolve::resim& simeta, \
156 mrgsolve::resim& simeps
157#define MRGSOLVE_TABLE_SIGNATURE_N 11
158
160#define MRGSOLVE_EVENT_SIGNATURE MRGSOLVE_TABLE_SIGNATURE
161#define MRGSOLVE_EVENT_SIGNATURE_N MRGSOLVE_TABLE_SIGNATURE_N
162
164#define MRGSOLVE_ODE_SIGNATURE \
165 const double* _ODETIME_, \
166 const double* _A_, \
167 double* _DADT_, \
168 const dvec& _A_0_, \
169 const dvec& _THETA_, \
170 const bool _ss_flag_
171#define MRGSOLVE_ODE_SIGNATURE_N 6
172
174#define MRGSOLVE_CONFIG_SIGNATURE \
175 databox& self, \
176 const dvec& _THETA_, \
177 const double neq, \
178 const double npar, \
179 bool& _check_modeled_infusions
180#define MRGSOLVE_CONFIG_SIGNATURE_N 5
181
182#endif
member functions mevent and tad come in via housemodel; see inst/base/databox.cpp
Definition mrgsolv.h:96
double time
current simulation time
Definition mrgsolv.h:102
void * envir
model environment
Definition mrgsolv.h:115
bool CFONSTOP
carry forward on stop indicator
Definition mrgsolv.h:114
int idn
current ID number
Definition mrgsolv.h:109
int irown
current output row number for current id
Definition mrgsolv.h:112
int evid
event ID flag
Definition mrgsolv.h:103
void stop()
stops the problem when the next record is started
Definition mrgsolv.h:116
double tad()
calculates time after dose
Definition databox_cpp.h:44
double mtime(double time_)
creates evdata object for simple model event time
Definition databox_cpp.h:29
double amt
current dosing amount value
Definition mrgsolv.h:106
void stop_id()
stops solving for the current id, filling with NA
Definition mrgsolv.h:117
unsigned short int SYSTEMOFF
flag to stop advancing system for current ID
Definition mrgsolv.h:104
std::vector< double > SIGMA
vector of on-diagonal sigma elements
Definition mrgsolv.h:100
int nid
number of IDs in the data set
Definition mrgsolv.h:108
int inrow
number of output rows for current id
Definition mrgsolv.h:113
void stop_id_cf()
stops solving for the current id, filling last value
Definition mrgsolv.h:118
int nrow
number of rows in output data set
Definition mrgsolv.h:110
unsigned int newind
new individual flag
Definition mrgsolv.h:101
int rown
current output row number
Definition mrgsolv.h:111
double id
current ID
Definition mrgsolv.h:105
void mevent(double time_, int evid_)
constructor for evdata objects
Definition databox_cpp.h:22
void push(mrgsolve::evdata x)
Definition databox_cpp.h:51
std::vector< mrgsolve::evdata > mevector
a collection of model events to pass back
Definition mrgsolv.h:119
std::vector< double > ETA
vector of ETA values
Definition mrgsolv.h:98
std::vector< double > EPS
vector of EPS values
Definition mrgsolv.h:99
short int cmt
current compartment value
Definition mrgsolv.h:107
std::vector< double > dvec
vector of doubles
Definition mrgsolv.h:127
void(* refun)(void *)
Definition mrgsolv.h:28
Definition mrgsolv.h:30
void report(type a)
Definition mrgsolv.h:76
Definition mrgsolv.h:51
double rate
Definition mrgsolv.h:66
double amt
Definition mrgsolv.h:65
bool now
Definition mrgsolv.h:70
double time
Definition mrgsolv.h:62
int evid
Definition mrgsolv.h:63
int addl
Definition mrgsolv.h:69
double ii
Definition mrgsolv.h:67
bool check_unique
Definition mrgsolv.h:71
int ss
Definition mrgsolv.h:68
evdata(double a_, int b_)
Definition mrgsolv.h:52
int cmt
Definition mrgsolv.h:64
resim()
Definition mrgsolv.h:41
void operator()()
Definition mrgsolv.h:42
resim(refun x, void *y)
resim constructor
Definition mrgsolv.h:40
void * prob
object to pass to re-simulated function
Definition mrgsolv.h:48
refun fun
function to call to re-simulate
Definition mrgsolv.h:47