@@ -130,8 +130,6 @@ gsl_integration_workspace *gsl_intgr_wksp = gsl_integration_workspace_alloc (GSL
130130// gsl_integration_workspace_free (gsl_intgr_wksp);
131131
132132double LSTMDrugThreeComp::calculateFactor (const Params_fC& p, double duration) const {
133- std::cout << " INSIDE LSTMDrugThreeComp::calculateFactor" << std::endl;
134- exit (0 );
135133 gsl_function F;
136134 F.function = &func_fC;
137135 // gsl_function doesn't accept const; we re-apply const later
@@ -160,7 +158,11 @@ double LSTMDrugThreeComp::calculateFactor(const Params_fC& p, double duration) c
160158
161159// TODO: in high transmission, is this going to get called more often than updateConcentration?
162160// When does it make sense to try to optimise (avoid doing decay calcuations here)?
163- double LSTMDrugThreeComp::calculateDrugFactor (LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass) const {
161+ double LSTMDrugThreeComp::calculateDrugFactor (LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass,
162+ const std::string& drugName,
163+ std::vector<std::tuple<std::string, double , double >>& pkpdTimeToDrugConcentrationMap,
164+ std::vector<std::tuple<std::string, double , double >>& pkpdTimeToTotalFactorMap
165+ ) const {
164166 if ( conc () == 0.0 && doses.size () == 0 ) return 1.0 ; // nothing to do
165167 updateCached (body_mass);
166168
@@ -180,26 +182,61 @@ double LSTMDrugThreeComp::calculateDrugFactor(LocalRng& rng, WithinHost::CommonI
180182 if ( time_conc.first < 1.0 /* i.e. today*/ ){
181183 if ( time < time_conc.first ){
182184 double duration = time_conc.first - time;
185+
186+ // Add concentration and factor tracking before duration
187+ double current_conc = p.cA + p.cB + p.cC - p.cABC ;
188+ pkpdTimeToDrugConcentrationMap.push_back (std::tuple<std::string, double , double >{drugName, time, current_conc});
189+
183190 totalFactor *= calculateFactor (p, duration);
191+ pkpdTimeToTotalFactorMap.push_back (std::tuple<std::string, double , double >{drugName, time, totalFactor});
192+
193+ // Update concentrations after duration
184194 p.cA *= exp (p.na * duration);
185195 p.cB *= exp (p.nb * duration);
186196 p.cC *= exp (p.ng * duration);
187197 p.cABC *= exp (p.nka * duration);
198+
199+ // Add concentration tracking after duration
200+ current_conc = p.cA + p.cB + p.cC - p.cABC ;
201+ pkpdTimeToDrugConcentrationMap.push_back (std::tuple<std::string, double , double >{drugName, time, current_conc});
202+
188203 time = time_conc.first ;
189204 }else { assert ( time == time_conc.first ); }
190205 // add dose:
191206 p.cA += A * time_conc.second ;
192207 p.cB += B * time_conc.second ;
193208 p.cC += C * time_conc.second ;
194209 p.cABC += (A + B + C) * time_conc.second ;
210+
211+ // Add concentration tracking after dose
212+ double current_conc = p.cA + p.cB + p.cC - p.cABC ;
213+ pkpdTimeToDrugConcentrationMap.push_back (std::tuple<std::string, double , double >{drugName, time, current_conc});
195214 }else /* i.e. tomorrow or later*/ {
196215 // ignore
197216 }
198217 }
199218 if ( time < 1.0 ){
200- totalFactor *= calculateFactor (p, 1.0 - time);
219+ double duration = 1.0 - time;
220+
221+ // // Add concentration and factor tracking before final duration
222+ // double current_conc = p.cA + p.cB + p.cC - p.cABC;
223+ // pkpdTimeToDrugConcentrationMap.push_back(std::tuple<std::string, double, double>{drugName, time, current_conc});
224+
225+ totalFactor *= calculateFactor (p, duration);
226+ pkpdTimeToTotalFactorMap.push_back (std::tuple<std::string, double , double >{drugName, time, totalFactor});
227+
228+ // // Add concentration tracking after final duration
229+ // p.cA *= exp(p.na * duration);
230+ // p.cB *= exp(p.nb * duration);
231+ // p.cC *= exp(p.ng * duration);
232+ // p.cABC *= exp(p.nka * duration);
233+ const double current_conc = p.cA + p.cB + p.cC - p.cABC ;
234+ pkpdTimeToDrugConcentrationMap.push_back (std::tuple<std::string, double , double >{drugName, time, current_conc});
201235 }
202236
237+ // Add final total factor entry
238+ pkpdTimeToTotalFactorMap.push_back (std::tuple<std::string, double , double >{drugName, time, totalFactor});
239+
203240 return totalFactor;
204241}
205242
0 commit comments