Commit 60236f7b authored by Aaron Bray's avatar Aaron Bray
Browse files

Update systems to stop caching the time step

parent f030a53d
......@@ -216,6 +216,7 @@ const PulseConfiguration& PulseData::GetConfiguration() const { return *m_Config
const SEScalarTime& PulseData::GetEngineTime() const { return m_CurrentTime; }
const SEScalarTime& PulseData::GetSimulationTime() const { return m_SimulationTime; }
const SEScalarTime& PulseData::GetTimeStep() const { return m_Config->GetTimeStep(); }
double PulseData::GetTimeStep_s() const { return GetTimeStep().GetValue(TimeUnit::s); }
bool PulseData::HasOverride() const { return m_ScalarOverrides.size() > 0; }
const std::vector<SEScalarProperty>& PulseData::GetOverrides() const { return m_ScalarOverrides; }
......@@ -602,11 +603,11 @@ bool PulseController::AdvanceModelTime(double time, const TimeUnit& unit)
else
{
double time_s = Convert(time, unit, TimeUnit::s) + m_SpareAdvanceTime_s;
int count = (int)(time_s / GetTimeStep().GetValue(TimeUnit::s));
int count = (int)(time_s / GetTimeStep_s());
for (int i = 0; i < count; i++)
if (!AdvanceModelTime())
return false;
m_SpareAdvanceTime_s = time_s - (count * GetTimeStep().GetValue(TimeUnit::s));
m_SpareAdvanceTime_s = time_s - (count * GetTimeStep_s());
}
return true;
}
......
......@@ -135,6 +135,7 @@ public:
virtual const PulseConfiguration& GetConfiguration() const;
virtual double GetTimeStep_s() const;
virtual const SEScalarTime& GetTimeStep() const;
virtual const SEScalarTime& GetEngineTime() const;
virtual const SEScalarTime& GetSimulationTime() const;
......
......@@ -123,7 +123,6 @@ void AnesthesiaMachine::Initialize()
//--------------------------------------------------------------------------------------------------
void AnesthesiaMachine::SetUp()
{
m_dt_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
m_actions = &m_data.GetActions().GetEquipmentActions();
m_dValveOpenResistance_cmH2O_s_Per_L = m_data.GetConfiguration().GetMachineOpenResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
m_dValveClosedResistance_cmH2O_s_Per_L = m_data.GetConfiguration().GetMachineClosedResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
......@@ -529,7 +528,7 @@ void AnesthesiaMachine::CalculateSourceStatus()
double dBottle1Volume_L = GetOxygenBottleOne().GetVolume().GetValue(VolumeUnit::L);
if (dBottle1Volume_L > 0.0)
{
dBottle1Volume_L -= m_dt_s * dFlow_LPerS * m_O2InletVolumeFraction;
dBottle1Volume_L -= m_data.GetTimeStep_s() * dFlow_LPerS * m_O2InletVolumeFraction;
}
else if (dBottle1Volume_L <= 0.0) //Empty
{
......@@ -544,7 +543,7 @@ void AnesthesiaMachine::CalculateSourceStatus()
double dBottle2Volume_L = GetOxygenBottleTwo().GetVolume().GetValue(VolumeUnit::L);
if (dBottle2Volume_L > 0.0)
{
dBottle2Volume_L -= m_dt_s * dFlow_LPerS * m_O2InletVolumeFraction;
dBottle2Volume_L -= m_data.GetTimeStep_s() * dFlow_LPerS * m_O2InletVolumeFraction;
}
else if (dBottle2Volume_L <= 0.0)
{
......@@ -731,7 +730,7 @@ void AnesthesiaMachine::CalculateVentilatorPressure()
void AnesthesiaMachine::CalculateCyclePhase()
{
//Determine where we are in the cycle
m_currentbreathingCycleTime_s += m_dt_s;
m_currentbreathingCycleTime_s += m_data.GetTimeStep_s();
if (m_currentbreathingCycleTime_s > m_totalBreathingCycleTime_s) //End of the cycle
{
m_totalBreathingCycleTime_s=0.0;
......
......@@ -65,7 +65,6 @@ protected:
double m_totalBreathingCycleTime_s;
// Stateless member variable (Set in SetUp())
double m_dt_s;
double m_dValveOpenResistance_cmH2O_s_Per_L;
double m_dValveClosedResistance_cmH2O_s_Per_L;
double m_dSwitchOpenResistance_cmH2O_s_Per_L;
......
......@@ -78,7 +78,7 @@ void ECG::Initialize()
void ECG::SetUp()
{
m_dt_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
}
//--------------------------------------------------------------------------------------------------
......@@ -110,7 +110,7 @@ void ECG::PreProcess()
//--------------------------------------------------------------------------------------------------
void ECG::Process(bool solve_and_transport)
{
m_heartRhythmTime_s += m_dt_s;
m_heartRhythmTime_s += m_data.GetTimeStep_s();
if (m_heartRhythmTime_s >= m_heartRhythmPeriod_s)
{
m_heartRhythmTime_s = 0;
......
......@@ -41,5 +41,4 @@ protected:
SEElectroCardioGramWaveformInterpolator* m_interpolator;
// Stateless member variable (Set in SetUp())
double m_dt_s;
};
......@@ -63,9 +63,6 @@ void Inhaler::Initialize()
void Inhaler::SetUp()
{
// Time step - used by inhaler timer
m_dt_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
m_AmbientEnv = m_data.GetCompartments().GetGasCompartment(pulse::EnvironmentCompartment::Ambient);
m_Mouthpiece = m_data.GetCompartments().GetGasCompartment(pulse::InhalerCompartment::Mouthpiece);
m_AerosolMouthpiece = m_data.GetCompartments().GetLiquidCompartment(pulse::InhalerCompartment::Mouthpiece);
......
......@@ -43,7 +43,6 @@ protected:
// Serializable member variables (Set in Initialize and in schema)
// Stateless member variable (Set in SetUp())
double m_dt_s;
SEGasCompartment *m_Mouthpiece;
SELiquidCompartment *m_AerosolMouthpiece;
SEGasCompartment *m_AmbientEnv;
......
......@@ -83,8 +83,6 @@ void MechanicalVentilator::Initialize()
//--------------------------------------------------------------------------------------------------
void MechanicalVentilator::SetUp()
{
m_dt_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
// Compartments
m_Environment = m_data.GetCompartments().GetGasCompartment(pulse::EnvironmentCompartment::Ambient);
m_Ventilator = m_data.GetCompartments().GetGasCompartment(pulse::MechanicalVentilatorCompartment::MechanicalVentilator);
......@@ -320,7 +318,7 @@ void MechanicalVentilator::PreProcess()
SetVentilatorDriver();
SetResistances();
m_CurrentPeriodTime_s += m_dt_s;
m_CurrentPeriodTime_s += m_data.GetTimeStep_s();
}
//--------------------------------------------------------------------------------------------------
......@@ -405,7 +403,7 @@ void MechanicalVentilator::CalculateInspiration()
return;
}
m_CurrentInspiratoryVolume_L += m_YPieceToConnection->GetNextFlow(VolumePerTimeUnit::L_Per_s) * m_dt_s;
m_CurrentInspiratoryVolume_L += m_YPieceToConnection->GetNextFlow(VolumePerTimeUnit::L_Per_s) * m_data.GetTimeStep_s();
// Check trigger
if (HasExpirationCycleTime())
......
......@@ -62,8 +62,6 @@ protected:
eBreathState m_CurrentBreathState;
// Stateless member variable (Set in SetUp())
double m_dt_s;
SEGasCompartment* m_Environment;
SEGasCompartment* m_Ventilator;
SELiquidCompartment* m_VentilatorAerosol;
......
......@@ -265,7 +265,6 @@ void Cardiovascular::Initialize()
//--------------------------------------------------------------------------------------------------
void Cardiovascular::SetUp()
{
m_dT_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
m_minIndividialSystemicResistance_mmHg_s_Per_mL = 0.1;
//Circuits
......@@ -529,7 +528,7 @@ void Cardiovascular::ChronicPericardialEffusion()
//Just throw this all on at once
//Only do this for a single time-step!
m_pGndToPericardium->GetNextFlowSource().SetValue(deltaVolume_mL / m_dT_s, VolumePerTimeUnit::mL_Per_s);
m_pGndToPericardium->GetNextFlowSource().SetValue(deltaVolume_mL / m_data.GetTimeStep_s(), VolumePerTimeUnit::mL_Per_s);
}
//--------------------------------------------------------------------------------------------------
......@@ -626,8 +625,8 @@ void Cardiovascular::Process(bool solve_and_transport)
{
if (solve_and_transport)
{
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_dT_s);
m_transporter->Transport(*m_CirculatoryGraph, m_dT_s);
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_data.GetTimeStep_s());
m_transporter->Transport(*m_CirculatoryGraph, m_data.GetTimeStep_s());
}
CalculateVitalSigns();
ComputeExposedModelParameters();
......@@ -698,7 +697,7 @@ void Cardiovascular::CalculateVitalSigns()
m_pAortaToSplanchnic->GetNextFlow(VolumePerTimeUnit::mL_Per_s);
// Calculate heart rate - Threshold of 0.1 is empirically determined. Approximate zero makes it too noisy.
m_CurrentCardiacCycleDuration_s += m_dT_s;
m_CurrentCardiacCycleDuration_s += m_data.GetTimeStep_s();
if (LHeartFlow_mL_Per_s > 0.1 && !m_HeartFlowDetected)
{
m_HeartFlowDetected = true;
......@@ -723,7 +722,7 @@ void Cardiovascular::CalculateVitalSigns()
m_CardiacCycleDiastolicVolume_mL = LHeartVolume_mL;
// Increment stroke volume. Get samples for running means
m_CardiacCycleStrokeVolume_mL += LHeartFlow_mL_Per_s*m_dT_s;
m_CardiacCycleStrokeVolume_mL += LHeartFlow_mL_Per_s*m_data.GetTimeStep_s();
m_CardiacCycleArterialPressure_mmHg->Sample(AortaNodePressure_mmHg);
m_CardiacCycleArterialCO2PartialPressure_mmHg->Sample(AortaNodeCO2PartialPressure_mmHg);
m_CardiacCyclePulmonaryCapillariesWedgePressure_mmHg->Sample(PulmVeinNodePressure_mmHg);
......@@ -1297,7 +1296,7 @@ void Cardiovascular::Hemorrhage()
h->GetFlowRate().SetValue(hemorrhagePathFlow_mL_Per_s, VolumePerTimeUnit::mL_Per_s);
}
hemorrhagePathFlow_mL_Per_s = h->HasFlowRate() ? h->GetFlowRate(VolumePerTimeUnit::mL_Per_s) : 0;
h->GetTotalBloodLost().IncrementValue(hemorrhagePathFlow_mL_Per_s* m_dT_s, VolumeUnit::mL);
h->GetTotalBloodLost().IncrementValue(hemorrhagePathFlow_mL_Per_s* m_data.GetTimeStep_s(), VolumeUnit::mL);
}
}
......@@ -1354,7 +1353,7 @@ void Cardiovascular::Hemorrhage()
InternalHemorrhagePressureApplication();
GetTotalHemorrhageRate().SetValue(TotalLossRate_mL_Per_s, VolumePerTimeUnit::mL_Per_s);
GetTotalHemorrhagedVolume().IncrementValue((TotalLossRate_mL_Per_s* m_dT_s), VolumeUnit::mL);
GetTotalHemorrhagedVolume().IncrementValue((TotalLossRate_mL_Per_s* m_data.GetTimeStep_s()), VolumeUnit::mL);
}
//--------------------------------------------------------------------------------------------------
......@@ -1549,7 +1548,7 @@ void Cardiovascular::CalculateAndSetCPRcompressionForce()
compressionForce_N = m_data.GetActions().GetPatientActions().GetChestCompressionForce().GetForce().GetValue(ForceUnit::N);
}
m_CompressionTime_s += m_dT_s;
m_CompressionTime_s += m_data.GetTimeStep_s();
if (compressionForce_N > compressionForceMax_N)
{
......@@ -1593,7 +1592,7 @@ void Cardiovascular::CardiacArrest()
// The cardiac arrest event will be triggered by CardiacCycleCalculations() at the end of the cardiac cycle.
m_EnterCardiacArrest = true;
//Force a new cardiac cycle to start when cardiac arrest is removed
m_CurrentCardiacCycleTime_s = m_CardiacCyclePeriod_s - m_dT_s;
m_CurrentCardiacCycleTime_s = m_CardiacCyclePeriod_s - m_data.GetTimeStep_s();
}
else
{
......@@ -1670,7 +1669,7 @@ void Cardiovascular::HeartDriver()
if (!m_data.GetEvents().IsEventActive(eEvent::CardiacArrest))
{
if (m_CurrentCardiacCycleTime_s >= m_CardiacCyclePeriod_s - m_dT_s)
if (m_CurrentCardiacCycleTime_s >= m_CardiacCyclePeriod_s - m_data.GetTimeStep_s())
m_StartSystole = true; // A new cardiac cycle will begin next time step
AdjustVascularTone();
......@@ -1684,7 +1683,7 @@ void Cardiovascular::HeartDriver()
// Note that the cardiac cycle time (m_CurrentCardiacCycleTime_s) continues to increment until a cardiac cycle begins (a beat happens)
// So for a normal sinus rhythm, the maximum cardiac cycle time is equal to the cardiac cycle period (m_CardiacCyclePeriod_s).
// For any ineffective rhythm (no heart beat) the cardiac cycle time will be as long as it has been since the last time there was an effective beat.
m_CurrentCardiacCycleTime_s += m_dT_s;
m_CurrentCardiacCycleTime_s += m_data.GetTimeStep_s();
}
//--------------------------------------------------------------------------------------------------
......@@ -1944,7 +1943,7 @@ void Cardiovascular::CalculateHeartRate()
{
// The time that the flow actually decreased below the threshold was last time slice (when m_HeartFlowDetected
// was set back to false), so we need to subtract one time step from the interval.
double HeartRate_Per_s = 1.0 / (m_CurrentCardiacCycleDuration_s - m_dT_s);
double HeartRate_Per_s = 1.0 / (m_CurrentCardiacCycleDuration_s - m_data.GetTimeStep_s());
GetHeartRate().SetValue(HeartRate_Per_s * 60.0, FrequencyUnit::Per_min);
m_CurrentCardiacCycleDuration_s = 0;
}
......@@ -2039,7 +2038,7 @@ void Cardiovascular::CalculatePleuralCavityVenousEffects()
double dampenFraction_perSec = 0.001 * 50.0;
double previousRightHeartResistance_mmHg_s_Per_mL = m_RightHeartResistance->GetResistance(PressureTimePerVolumeUnit::mmHg_s_Per_mL);
double resistanceChange_L_Per_mmHg_s_Per_mL = (rightHeartResistance_mmHg_s_Per_mL - previousRightHeartResistance_mmHg_s_Per_mL) * dampenFraction_perSec * m_dT_s;
double resistanceChange_L_Per_mmHg_s_Per_mL = (rightHeartResistance_mmHg_s_Per_mL - previousRightHeartResistance_mmHg_s_Per_mL) * dampenFraction_perSec * m_data.GetTimeStep_s();
rightHeartResistance_mmHg_s_Per_mL = previousRightHeartResistance_mmHg_s_Per_mL + resistanceChange_L_Per_mmHg_s_Per_mL;
......@@ -2103,7 +2102,7 @@ void Cardiovascular::TuneCircuit()
{
m_data.AdvanceCallback(-1);
HeartDriver();
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_dT_s);
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_data.GetTimeStep_s());
CalculateVitalSigns();
m_circuitCalculator->PostProcess(*m_CirculatoryCircuit);
//return; //Skip stabelization for debugging
......@@ -2115,8 +2114,8 @@ void Cardiovascular::TuneCircuit()
meanCVP_mmHg = GetMeanCentralVenousPressure(PressureUnit::mmHg);
blood_mL = GetBloodVolume(VolumeUnit::mL);
stableTime_s += m_dT_s;
currentStableTime_s += m_dT_s;
stableTime_s += m_data.GetTimeStep_s();
currentStableTime_s += m_data.GetTimeStep_s();
bool stableMAP = true;
if (GeneralMath::PercentDifference(tgt_map_mmHg, map_mmHg) > stabPercentTolerance)
{
......@@ -2172,7 +2171,7 @@ void Cardiovascular::TuneCircuit()
circuitTrk.CreateFile(m_TuningFile.c_str(), circuitFile);
circuitTrk.StreamTrackToFile(circuitFile);
}
time_s += m_dT_s;
time_s += m_data.GetTimeStep_s();
}
if (!m_TuneCircuit)
{
......@@ -2447,13 +2446,13 @@ void Cardiovascular::TuneTissue(double time_s, DataTrack& circuitTrk, std::ofstr
{
m_data.AdvanceCallback(-1);
HeartDriver();
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_dT_s);
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_data.GetTimeStep_s());
CalculateVitalSigns();
m_circuitCalculator->PostProcess(*m_CirculatoryCircuit);
//return; //Skip stabelization for debugging
time_s += m_dT_s;
currentStableTime_s += m_dT_s;
time_s += m_data.GetTimeStep_s();
currentStableTime_s += m_data.GetTimeStep_s();
for (size_t m=0; m<tissueResistancePaths.size(); m++)
{
......@@ -2529,10 +2528,10 @@ void Cardiovascular::TuneTissue(double time_s, DataTrack& circuitTrk, std::ofstr
{
m_data.AdvanceCallback(-1);
HeartDriver();
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_dT_s);
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_data.GetTimeStep_s());
CalculateVitalSigns();
m_circuitCalculator->PostProcess(*m_CirculatoryCircuit);
time_s += m_dT_s;
time_s += m_data.GetTimeStep_s();
if (!m_TuningFile.empty())
{
circuitTrk.Track(time_s, *m_CirculatoryCircuit);
......
......@@ -126,7 +126,6 @@ protected:
SERunningAverage* m_CardiacCycleSkinFlow_mL_Per_s;
// Stateless member variable (Set in SetUp())
double m_dT_s;
bool m_TuneCircuit = true;
std::string m_TuningFile;
......
......@@ -110,7 +110,6 @@ void Drugs::Initialize()
//--------------------------------------------------------------------------------------------------
void Drugs::SetUp()
{
m_dt_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
m_muscleIntracellular = m_data.GetCompartments().GetLiquidCompartment(pulse::ExtravascularCompartment::MuscleIntracellular);
m_aortaVascular = m_data.GetCompartments().GetLiquidCompartment(pulse::VascularCompartment::Aorta);
m_venaCavaVascular = m_data.GetCompartments().GetLiquidCompartment(pulse::VascularCompartment::VenaCava);
......@@ -237,7 +236,7 @@ void Drugs::AdministerSubstanceBolus()
}
administrationTime_s = bolus->GetAdminDuration(TimeUnit::s);
concentration_ugPermL = bolus->GetConcentration(MassPerVolumeUnit::ug_Per_mL);
massIncrement_ug = dose_mL * concentration_ugPermL * m_dt_s / administrationTime_s;
massIncrement_ug = dose_mL * concentration_ugPermL * m_data.GetTimeStep_s() / administrationTime_s;
subQ->GetMass().IncrementValue(massIncrement_ug, MassUnit::ug);
subQ->Balance(BalanceLiquidBy::Mass);
bolus->GetAdministeredDose().IncrementValue(massIncrement_ug / concentration_ugPermL, VolumeUnit::mL);
......@@ -275,7 +274,7 @@ void Drugs::AdministerSubstanceInfusion()
concentration_ug_Per_mL = infusion->GetConcentration().GetValue(MassPerVolumeUnit::ug_Per_mL);
rate_mL_Per_s = infusion->GetRate().GetValue(VolumePerTimeUnit::mL_Per_s);
massIncrement_ug = rate_mL_Per_s*concentration_ug_Per_mL*m_dt_s;
massIncrement_ug = rate_mL_Per_s*concentration_ug_Per_mL*m_data.GetTimeStep_s();
subQ = m_venaCavaVascular->GetSubstanceQuantity(infusion->GetSubstance());
subQ->GetMass().IncrementValue(massIncrement_ug, MassUnit::ug);
/// \todo Enforce limits and remove the fatal error
......@@ -336,7 +335,7 @@ void Drugs::AdministerSubstanceCompoundInfusion()
return;
}
infusion->GetBagVolume().IncrementValue(-rate_mL_Per_s*m_dt_s, VolumeUnit::mL);
infusion->GetBagVolume().IncrementValue(-rate_mL_Per_s*m_data.GetTimeStep_s(), VolumeUnit::mL);
double total_mL = infusion->GetBagVolume().GetValue(VolumeUnit::mL);
if (total_mL <= 0)
{ /// \todo correct the mass based on what we have left in the bag
......@@ -347,7 +346,7 @@ void Drugs::AdministerSubstanceCompoundInfusion()
for (const SESubstanceConcentration* component : compound->GetComponents())
{
subQ = m_venaCavaVascular->GetSubstanceQuantity(component->GetSubstance());
massIncrement_ug = rate_mL_Per_s*component->GetConcentration(MassPerVolumeUnit::ug_Per_mL)*m_dt_s;
massIncrement_ug = rate_mL_Per_s*component->GetConcentration(MassPerVolumeUnit::ug_Per_mL)*m_data.GetTimeStep_s();
subQ->GetMass().IncrementValue(massIncrement_ug, MassUnit::ug);
subQ->Balance(BalanceLiquidBy::Mass);
}
......@@ -356,7 +355,7 @@ void Drugs::AdministerSubstanceCompoundInfusion()
densityFluid_kg_Per_mL = m_data.GetConfiguration().GetWaterDensity(MassPerVolumeUnit::kg_Per_mL);
else if (compound->GetName().compare("Blood") == 0)
densityFluid_kg_Per_mL = m_data.GetBloodChemistry().GetBloodDensity(MassPerVolumeUnit::kg_Per_mL);
patientMass_kg -= rate_mL_Per_s*densityFluid_kg_Per_mL*m_dt_s;
patientMass_kg -= rate_mL_Per_s*densityFluid_kg_Per_mL*m_data.GetTimeStep_s();
}
for (const SESubstanceCompound* c : emptyBags)
......@@ -649,7 +648,7 @@ void Drugs::CalculateSubstanceClearance()
SESubstanceClearance& clearance = sub->GetClearance();
//Renal Volume Cleared - Clearance happens through the renal system
RenalVolumeCleared_mL = (clearance.GetRenalClearance().GetValue(VolumePerTimeMassUnit::mL_Per_s_kg) * PatientWeight_kg * m_dt_s);
RenalVolumeCleared_mL = (clearance.GetRenalClearance().GetValue(VolumePerTimeMassUnit::mL_Per_s_kg) * PatientWeight_kg * m_data.GetTimeStep_s());
//Intrinsic Clearance
IntrinsicClearance_mLPersPerkg = clearance.GetIntrinsicClearance().GetValue(VolumePerTimeMassUnit::mL_Per_s_kg);
......@@ -657,10 +656,10 @@ void Drugs::CalculateSubstanceClearance()
//Hepatic Clearance
double LiverVascularFlow_mL_Per_s = m_liverVascular->GetInFlow().GetValue(VolumePerTimeUnit::mL_Per_s);
HepaticClearance_mLPers = (LiverVascularFlow_mL_Per_s * FractionUnboundInPlasma * IntrinsicClearance_mLPersPerkg * PatientWeight_kg) / (LiverVascularFlow_mL_Per_s + (FractionUnboundInPlasma * IntrinsicClearance_mLPersPerkg * PatientWeight_kg));
HepaticVolumeCleared_mL = HepaticClearance_mLPers * m_dt_s;
HepaticVolumeCleared_mL = HepaticClearance_mLPers * m_data.GetTimeStep_s();
//Systemic Clearance
TotalVolumeCleared_mL = clearance.GetSystemicClearance().GetValue(VolumePerTimeMassUnit::mL_Per_s_kg) * PatientWeight_kg * m_dt_s;
TotalVolumeCleared_mL = clearance.GetSystemicClearance().GetValue(VolumePerTimeMassUnit::mL_Per_s_kg) * PatientWeight_kg * m_data.GetTimeStep_s();
OtherSystemicVolumeCleared_mL = TotalVolumeCleared_mL - RenalVolumeCleared_mL - HepaticVolumeCleared_mL;
// The following makes it so that you cannot have more than the total systemic clearance for the substance.
LLIM(OtherSystemicVolumeCleared_mL, 0.);
......@@ -672,7 +671,7 @@ void Drugs::CalculateSubstanceClearance()
m_data.GetSubstances().CalculateGenericClearance(OtherSystemicVolumeCleared_mL, *m_venaCavaVascular, *sub);
//Hepatic Excretion
m_data.GetSubstances().CalculateGenericExcretion(LiverVascularFlow_mL_Per_s, *m_liverTissue, *sub, clearance.GetFractionExcretedInFeces().GetValue(), m_dt_s);
m_data.GetSubstances().CalculateGenericExcretion(LiverVascularFlow_mL_Per_s, *m_liverTissue, *sub, clearance.GetFractionExcretedInFeces().GetValue(), m_data.GetTimeStep_s());
}
}
......@@ -49,7 +49,6 @@ protected:
void CalculateDrugEffects();
// Stateless member variable (Set in SetUp())
double m_dt_s;
SELiquidCompartment* m_aortaVascular;
SELiquidCompartment* m_venaCavaVascular;
SELiquidCompartment* m_muscleIntracellular;
......
......@@ -65,7 +65,6 @@ void Endocrine::Initialize()
//--------------------------------------------------------------------------------------------------
void Endocrine::SetUp()
{
m_dt_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
SELiquidCompartment* aorta = m_data.GetCompartments().GetLiquidCompartment(pulse::VascularCompartment::Aorta);
SELiquidCompartment* rkidney = m_data.GetCompartments().GetLiquidCompartment(pulse::VascularCompartment::RightEfferentArteriole);
SELiquidCompartment* lkidney = m_data.GetCompartments().GetLiquidCompartment(pulse::VascularCompartment::LeftEfferentArteriole);
......@@ -123,7 +122,7 @@ void Endocrine::SynthesizeInsulin()
GetInsulinSynthesisRate().SetValue(insulinSynthesisRate_pmol_Per_min, AmountPerTimeUnit::pmol_Per_min);
insulinMassDelta_g = Convert(insulinSynthesisRate_pmol_Per_min, AmountPerTimeUnit::pmol_Per_min, AmountPerTimeUnit::mol_Per_s);
insulinMassDelta_g *= m_insulinMolarMass_g_Per_mol * m_dt_s;
insulinMassDelta_g *= m_insulinMolarMass_g_Per_mol * m_data.GetTimeStep_s();
}
m_splanchnicInsulin->GetMass().IncrementValue(insulinMassDelta_g, MassUnit::g);
m_splanchnicInsulin->Balance(BalanceLiquidBy::Mass);
......@@ -142,7 +141,7 @@ void Endocrine::ReleaseEpinephrine()
SEPatient& Patient = m_data.GetCurrentPatient();
double patientWeight_kg = Patient.GetWeight(MassUnit::kg);
double epinephrineBasalReleaseRate_ug_Per_min = .00229393 * patientWeight_kg; //We want it to be ~.18 ug/min for our StandardMale
double epinephrineRelease_ug = (epinephrineBasalReleaseRate_ug_Per_min / 60) * m_dt_s; //amount released per timestep
double epinephrineRelease_ug = (epinephrineBasalReleaseRate_ug_Per_min / 60) * m_data.GetTimeStep_s(); //amount released per timestep
double currentMetabolicRate_W = m_data.GetEnergy().GetTotalMetabolicRate(PowerUnit::W);
double basalMetabolicRate_W = Patient.GetBasalMetabolicRate(PowerUnit::W);
......
......@@ -43,7 +43,6 @@ protected:
// Serializable member variables (Set in Initialize and in schema)
// Stateless member variable (Set in SetUp())
double m_dt_s;
double m_insulinMolarMass_g_Per_mol;
SELiquidSubstanceQuantity* m_aortaGlucose = nullptr;
SELiquidSubstanceQuantity* m_aortaEpinephrine = nullptr;
......
......@@ -139,8 +139,6 @@ void Energy::Initialize()
//--------------------------------------------------------------------------------------------------
void Energy::SetUp()
{
m_dT_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
m_AortaHCO3 = m_data.GetCompartments().GetLiquidCompartment(pulse::VascularCompartment::Aorta)->GetSubstanceQuantity(m_data.GetSubstances().GetHCO3());
//Circuit elements
......@@ -360,7 +358,7 @@ void Energy::Exercise()
double lactateRate_W = lactateConstant_W*(normalizedUsableEnergyDeficit + normalizedPeakEnergyDeficit + normalizedMediumEnergyDeficit + normalizedEnduranceEnergyDeficit) / 4.0;
double tristearinRate_W = tristearinConstant_W*(normalizedUsableEnergyDeficit + normalizedPeakEnergyDeficit + normalizedMediumEnergyDeficit + normalizedEnduranceEnergyDeficit) / 4.0;
energyIncrement_J = (glucoseRate_W + lactateRate_W + tristearinRate_W)*m_dT_s;
energyIncrement_J = (glucoseRate_W + lactateRate_W + tristearinRate_W)*m_data.GetTimeStep_s();
if (m_EnduranceEnergyStore_J + energyIncrement_J > enduranceEnergyStoreFull_J){
glucoseRate_W = lactateRate_W = tristearinRate_W = 0.0;
......@@ -369,10 +367,10 @@ void Energy::Exercise()
double enduranceOutRate_W = (normalizedUsableEnergyDeficit + normalizedPeakEnergyDeficit + normalizedMediumEnergyDeficit)*maxEnduranceOutRate_W;
BLIM(enduranceOutRate_W, 0.0, maxEnduranceOutRate_W);
if (m_EnduranceEnergyStore_J + energyIncrement_J < enduranceOutRate_W*m_dT_s){
enduranceOutRate_W = (m_EnduranceEnergyStore_J + energyIncrement_J) / m_dT_s;
if (m_EnduranceEnergyStore_J + energyIncrement_J < enduranceOutRate_W*m_data.GetTimeStep_s()){
enduranceOutRate_W = (m_EnduranceEnergyStore_J + energyIncrement_J) / m_data.GetTimeStep_s();
}
m_EnduranceEnergyStore_J += energyIncrement_J - enduranceOutRate_W*m_dT_s;
m_EnduranceEnergyStore_J += energyIncrement_J - enduranceOutRate_W*m_data.GetTimeStep_s();
// The aerobic store has multiple outflow paths. One path represents purely aerobic energy
// usage, and the other paths represent the aerobic replenishment of the anaerobic stores. The following
......@@ -394,34 +392,34 @@ void Energy::Exercise()
double mediumFillRate_W = (1.0 - splitFraction)*enduranceToFillRate_W;
// Advance peak store state
energyIncrement_J = peakFillRate_W*m_dT_s;
energyIncrement_J = peakFillRate_W*m_data.GetTimeStep_s();
double peakOutRate_W = normalizedUsableEnergyDeficit*maxPeakOutRate_W*energyRateModifier;
BLIM(peakOutRate_W, 0.0, maxPeakOutRate_W);
if (m_PeakPowerEnergyStore_J + energyIncrement_J < peakOutRate_W*m_dT_s){
peakOutRate_W = (m_PeakPowerEnergyStore_J + energyIncrement_J) / m_dT_s;
if (m_PeakPowerEnergyStore_J + energyIncrement_J < peakOutRate_W*m_data.GetTimeStep_s()){
peakOutRate_W = (m_PeakPowerEnergyStore_J + energyIncrement_J) / m_data.GetTimeStep_s();
}
m_PeakPowerEnergyStore_J += energyIncrement_J - peakOutRate_W*m_dT_s;
m_PeakPowerEnergyStore_J += energyIncrement_J - peakOutRate_W*m_data.GetTimeStep_s();
// Advance medium store state
energyIncrement_J = mediumFillRate_W*m_dT_s;
energyIncrement_J = mediumFillRate_W*m_data.GetTimeStep_s();
double mediumOutRate_W = normalizedUsableEnergyDeficit*maxMediumOutRate_W*energyRateModifier;
BLIM(mediumOutRate_W, 0.0, maxMediumOutRate_W);
if (m_MediumPowerEnergyStore_J + energyIncrement_J < mediumOutRate_W*m_dT_s){
mediumOutRate_W = (m_MediumPowerEnergyStore_J + energyIncrement_J) / m_dT_s;
if (m_MediumPowerEnergyStore_J + energyIncrement_J < mediumOutRate_W*m_data.GetTimeStep_s()){
mediumOutRate_W = (m_MediumPowerEnergyStore_J + energyIncrement_J) / m_data.GetTimeStep_s();
}
m_MediumPowerEnergyStore_J += energyIncrement_J - mediumOutRate_W*m_dT_s;
m_MediumPowerEnergyStore_J += energyIncrement_J - mediumOutRate_W*m_data.GetTimeStep_s();
// Advance usable bucket state
energyIncrement_J = (enduranceToUsableRate_W + mediumOutRate_W + peakOutRate_W)*m_dT_s;
if (m_UsableEnergyStore_J + energyIncrement_J < workRateDesired_W*m_dT_s)
energyIncrement_J = (enduranceToUsableRate_W + mediumOutRate_W + peakOutRate_W)*m_data.GetTimeStep_s();
if (m_UsableEnergyStore_J + energyIncrement_J < workRateDesired_W*m_data.GetTimeStep_s())
{
workRate_W = (m_UsableEnergyStore_J + energyIncrement_J) / m_dT_s;
workRate_W = (m_UsableEnergyStore_J + energyIncrement_J) / m_data.GetTimeStep_s();
}
else
{
workRate_W = workRateDesired_W;
}
m_UsableEnergyStore_J += energyIncrement_J - workRate_W*m_dT_s;
m_UsableEnergyStore_J += energyIncrement_J - workRate_W*m_data.GetTimeStep_s();
GetTotalWorkRateLevel().SetValue(workRate_W / maxWorkRate_W);
double fatigue = (normalizedEnduranceEnergyDeficit + normalizedMediumEnergyDeficit + normalizedPeakEnergyDeficit + normalizedUsableEnergyDeficit) / 4.0;
......@@ -459,7 +457,7 @@ void Energy::Exercise()
// We only let exercise control the metabolic rate if it is active, otherwise the heat generation method is in charge of the metabolic rate.
if (m_data.GetActions().GetPatientActions().HasExercise())
{
double TotalMetabolicRateProduced_kcal_Per_day = currentMetabolicRate_kcal_Per_day + MetabolicRateGain*(TotalMetabolicRateSetPoint_kcal_Per_day - currentMetabolicRate_kcal_Per_day)*m_dT_s;
double TotalMetabolicRateProduced_kcal_Per_day = currentMetabolicRate_kcal_Per_day + MetabolicRateGain*(TotalMetabolicRateSetPoint_kcal_Per_day - currentMetabolicRate_kcal_Per_day)*m_data.GetTimeStep_s();
GetTotalMetabolicRate().SetValue(TotalMetabolicRateProduced_kcal_Per_day, PowerUnit::kcal_Per_day);
}
}
......@@ -477,7 +475,7 @@ void Energy::Exercise()
void Energy::Process(bool solve_and_transport)
{
if(solve_and_transport)
m_circuitCalculator->Process(*m_TemperatureCircuit, m_dT_s);
m_circuitCalculator->Process(*m_TemperatureCircuit, m_data.GetTimeStep_s());
CalculateVitalSigns();
ComputeExposedModelParameters();
}
......@@ -681,7 +679,7 @@ void Energy::CalculateSweatRate()
//Account for mass lost by substracting from the current patient mass
double massLost_kg = sweatRate_kg_Per_s*m_dT_s;
double massLost_kg = sweatRate_kg_Per_s*m_data.GetTimeStep_s();
m_data.GetCurrentPatient().GetWeight().IncrementValue(-massLost_kg, MassUnit::kg);
GetSweatRate().SetValue(sweatRate_kg_Per_s, MassPerTimeUnit::kg_Per_s);
......
......@@ -63,7 +63,6 @@ protected:
SERunningAverage* m_BicarbonateMolarity_mmol_Per_L;
// Stateless member variable (Set in SetUp())
double m_dT_s;
// Cmpts,Substance, and nodes
SELiquidSubstanceQuantity* m_AortaHCO3;
//Nodes
......
<
......@@ -124,7 +124,6 @@ void Gastrointestinal::SetUp()
m_SmallIntestineCalcium = m_SmallIntestine->GetSubstanceQuantity(m_data.GetSubstances().GetCalcium());
m_SmallIntestineSodium = m_SmallIntestine->GetSubstanceQuantity(m_data.GetSubstances().GetSodium());
m_SmallIntestineUrea = m_SmallIntestine->GetSubstanceQuantity(m_data.GetSubstances().GetUrea());
m_dT_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
}
//--------------------------------------------------------------------------------------------------
......@@ -175,7 +174,7 @@ void Gastrointestinal::PreProcess()
m_data.GetCurrentPatient().GetWeight().IncrementValue(c.GetNutrition().GetWeight(MassUnit::kg), MassUnit::kg);
m_data.GetActions().GetPatientActions().RemoveConsumeNutrients();
}
DigestStomachNutrients(m_dT_s);
DigestStomachNutrients(m_data.GetTimeStep_s());