mrgsolve
datarecord.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 
22 #ifndef DATARECORD_H
23 #define DATARECORD_H
24 //#include <boost/shared_ptr.hpp>
25 #include "mrgsolv.h"
26 #include "LSODA.h"
27 
28 class odeproblem;
29 class datarecord;
30 typedef std::shared_ptr<datarecord> rec_ptr;
31 typedef std::vector<rec_ptr> reclist;
32 
33 #define NEWREC std::make_shared<datarecord>
34 
35 class datarecord {
36 
37 public:
39  datarecord(double time_, int pos_, bool output_);
40 
42  datarecord(double time_, short int cmt_, int pos_, double id_);
43 
45  datarecord(short int cmt_, int evid_, double amt_, double time_, double rate_,
46  int pos_, double id_);
47 
49  datarecord(short int cmt_, int evid_, double amt_, double time_, double rate_);
50 
51  ~datarecord();
52 
53  double time() {return Time;}
54  void time(double time_){Time = time_;}
55 
56  double id() {return Id;}
57  void id(double id_) {Id = id_;}
58 
59  unsigned int evid() {return Evid;}
60  void evid(unsigned short int evid_){Evid=evid_;}
61 
62  int pos(){return Pos;}
63  void pos(int pos_) {Pos=pos_;}
64 
65  short int cmt(){return Cmt;}
66  short int cmtn(){return std::abs(Cmt)-1;}
67 
68  void output(bool in){Output=in;}
69  bool output(){return Output;}
70 
71  bool from_data(){return Fromdata;}
72  void from_data(bool val){Fromdata = val;}
73 
74  double amt(){return Amt;}
75 
76  double rate(){return Rate;}
77  void rate(double value) {Rate = value;}
78 
79  double dur(double b);
80 
81  void addl(int addl_){Addl = std::max(0,addl_);}
82  unsigned int addl(){return Addl;}
83 
84  void ss(int ss_){Ss = std::max(0,ss_);}
85  unsigned short ss(){return Ss;}
86 
87  void ii(double ii_){Ii = ii_;}
88  double ii(){return Ii;}
89 
90  void schedule(std::vector<rec_ptr>& thisi, double maxtime, bool put_ev_first,
91  const unsigned int maxpos, double Fn);
92  void implement(odeproblem* prob);
93  void steady_zero(odeproblem* prob, LSODA& solver);
94  void steady_infusion(odeproblem* prob,reclist& thisi,LSODA& solver);
95  void steady_bolus(odeproblem* prob,LSODA& solver);
96  void steady(odeproblem* prob, reclist& thisi,double Fn,LSODA& solver);
97 
98  bool infusion(){return (Evid==1 || Evid==4 || Evid==5) && (Rate > 0);}
99  bool int_infusion(){return (Evid==1 || Evid==4 || Evid==5) && (Rate > 0) && (Amt > 0);}
100  bool ss_int_infusion(){return (Evid==1 || Evid==4 || Evid==5) && (Rate > 0) && (Amt > 0) && (Ss > 0);}
101  bool const_infusion(){return (Evid==1) && (Rate > 0) && (Amt == 0);}
102  bool ss_infusion();
103  bool is_event() {return (Evid > 0);}
104  bool is_dose(){return (Evid==1) || (Evid==4);}
105  bool is_event_data() {return (Evid != 0) && (Evid != 2) && Fromdata;}
106  bool needs_sorting(){return ((Addl > 0) || (Ss == 1));}
107 
108  bool unarmed() {return !Armed;}
109  void arm() {Armed=true;}
110  bool armed() {return Armed;}
111  void unarm() {Armed=false;}
112 
113  void phantom_rec() {Output=false; Fromdata=false;}
114  bool is_phantom() {return !Output && !Fromdata;}
115 
116  double Time;
117  double Id;
118  int Pos;
119  unsigned short int Evid;
120  bool Output;
121  bool Fromdata;
122  short int Cmt;
123  unsigned int Addl;
124  unsigned short int Ss;
125  double Amt;
126  double Rate;
127  double Ii;
128  bool Armed;
129 
130 };
131 
132 
133 bool CompByTimePosRec(const rec_ptr& a, const rec_ptr& b);
134 bool CompEqual(const reclist& a, double time, unsigned int evid, int cmt);
135 
145 struct CompRec {
146  inline bool operator()(const rec_ptr& a, const rec_ptr& b) {
147  if(a->time() == b->time()) {
148  return a->pos() < b->pos();
149  }
150  return a->time() < b->time();
151  }
152 };
153 
154 #endif
datarecord::ss_infusion
bool ss_infusion()
Definition: datarecord.cpp:136
CompRec
Functor for sorting data records in reclist.
Definition: datarecord.h:145
datarecord::rate
void rate(double value)
Definition: datarecord.h:77
datarecord::Evid
unsigned short int Evid
record event ID
Definition: datarecord.h:119
datarecord::evid
void evid(unsigned short int evid_)
Definition: datarecord.h:60
datarecord::is_dose
bool is_dose()
Definition: datarecord.h:104
datarecord::is_event
bool is_event()
Definition: datarecord.h:103
datarecord::evid
unsigned int evid()
Definition: datarecord.h:59
datarecord::armed
bool armed()
Definition: datarecord.h:110
datarecord::amt
double amt()
Definition: datarecord.h:74
datarecord::int_infusion
bool int_infusion()
Definition: datarecord.h:99
rec_ptr
std::shared_ptr< datarecord > rec_ptr
Definition: datarecord.h:29
datarecord::steady_bolus
void steady_bolus(odeproblem *prob, LSODA &solver)
Definition: datarecord.cpp:221
CompRec::operator()
bool operator()(const rec_ptr &a, const rec_ptr &b)
Definition: datarecord.h:146
datarecord::pos
void pos(int pos_)
Definition: datarecord.h:63
datarecord::time
void time(double time_)
Definition: datarecord.h:54
datarecord::Ii
double Ii
record inter-dose interval value
Definition: datarecord.h:127
datarecord::ss
unsigned short ss()
Definition: datarecord.h:85
datarecord::id
double id()
Definition: datarecord.h:56
datarecord::addl
unsigned int addl()
Definition: datarecord.h:82
datarecord::Output
bool Output
should this record be included in output?
Definition: datarecord.h:120
datarecord::ss
void ss(int ss_)
Definition: datarecord.h:84
datarecord::const_infusion
bool const_infusion()
Definition: datarecord.h:101
datarecord::output
void output(bool in)
Definition: datarecord.h:68
datarecord::dur
double dur(double b)
Definition: datarecord.cpp:132
datarecord::steady_zero
void steady_zero(odeproblem *prob, LSODA &solver)
Definition: datarecord.cpp:470
datarecord::steady_infusion
void steady_infusion(odeproblem *prob, reclist &thisi, LSODA &solver)
Definition: datarecord.cpp:311
datarecord::Amt
double Amt
record dosing amount value
Definition: datarecord.h:125
mrgsolv.h
datarecord::datarecord
datarecord(double time_, int pos_, bool output_)
constructor
Definition: datarecord.cpp:35
datarecord::ii
double ii()
Definition: datarecord.h:88
reclist
std::vector< rec_ptr > reclist
Definition: datarecord.h:31
datarecord::pos
int pos()
Definition: datarecord.h:62
datarecord::Addl
unsigned int Addl
number of additional doses
Definition: datarecord.h:123
datarecord::unarmed
bool unarmed()
Definition: datarecord.h:108
datarecord::phantom_rec
void phantom_rec()
Definition: datarecord.h:113
CompEqual
bool CompEqual(const reclist &a, double time, unsigned int evid, int cmt)
Definition: datarecord.cpp:122
datarecord::is_phantom
bool is_phantom()
Definition: datarecord.h:114
datarecord::Pos
int Pos
record position number
Definition: datarecord.h:118
datarecord::implement
void implement(odeproblem *prob)
Definition: datarecord.cpp:140
datarecord::Fromdata
bool Fromdata
is this record from the original data set?
Definition: datarecord.h:121
datarecord::needs_sorting
bool needs_sorting()
Definition: datarecord.h:106
datarecord::~datarecord
~datarecord()
Definition: datarecord.cpp:114
datarecord::schedule
void schedule(std::vector< rec_ptr > &thisi, double maxtime, bool put_ev_first, const unsigned int maxpos, double Fn)
Definition: datarecord.cpp:539
datarecord::is_event_data
bool is_event_data()
Definition: datarecord.h:105
datarecord::time
double time()
Definition: datarecord.h:53
datarecord
Definition: datarecord.h:35
datarecord::from_data
bool from_data()
Definition: datarecord.h:71
datarecord::arm
void arm()
Definition: datarecord.h:109
datarecord::cmtn
short int cmtn()
Definition: datarecord.h:66
datarecord::from_data
void from_data(bool val)
Definition: datarecord.h:72
datarecord::addl
void addl(int addl_)
Definition: datarecord.h:81
datarecord::output
bool output()
Definition: datarecord.h:69
datarecord::Ss
unsigned short int Ss
record steady-state indicator
Definition: datarecord.h:124
datarecord::ss_int_infusion
bool ss_int_infusion()
Definition: datarecord.h:100
datarecord::Armed
bool Armed
only armed records are actually executed
Definition: datarecord.h:128
LSODA
Definition: LSODA.h:42
datarecord::Id
double Id
record ID value
Definition: datarecord.h:117
datarecord::cmt
short int cmt()
Definition: datarecord.h:65
datarecord::Rate
double Rate
record infusion rate value
Definition: datarecord.h:126
datarecord::Time
double Time
record time
Definition: datarecord.h:116
datarecord::Cmt
short int Cmt
record compartment number
Definition: datarecord.h:122
datarecord::id
void id(double id_)
Definition: datarecord.h:57
CompByTimePosRec
bool CompByTimePosRec(const rec_ptr &a, const rec_ptr &b)
Definition: datarecord.cpp:116
datarecord::infusion
bool infusion()
Definition: datarecord.h:98
datarecord::steady
void steady(odeproblem *prob, reclist &thisi, double Fn, LSODA &solver)
Definition: datarecord.cpp:214
datarecord::ii
void ii(double ii_)
Definition: datarecord.h:87
datarecord::unarm
void unarm()
Definition: datarecord.h:111
datarecord::rate
double rate()
Definition: datarecord.h:76
odeproblem
Definition: odeproblem.h:94
LSODA.h