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 ...@@ -216,6 +216,7 @@ const PulseConfiguration& PulseData::GetConfiguration() const { return *m_Config
const SEScalarTime& PulseData::GetEngineTime() const { return m_CurrentTime; } const SEScalarTime& PulseData::GetEngineTime() const { return m_CurrentTime; }
const SEScalarTime& PulseData::GetSimulationTime() const { return m_SimulationTime; } const SEScalarTime& PulseData::GetSimulationTime() const { return m_SimulationTime; }
const SEScalarTime& PulseData::GetTimeStep() const { return m_Config->GetTimeStep(); } 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; } bool PulseData::HasOverride() const { return m_ScalarOverrides.size() > 0; }
const std::vector<SEScalarProperty>& PulseData::GetOverrides() const { return m_ScalarOverrides; } const std::vector<SEScalarProperty>& PulseData::GetOverrides() const { return m_ScalarOverrides; }
...@@ -602,11 +603,11 @@ bool PulseController::AdvanceModelTime(double time, const TimeUnit& unit) ...@@ -602,11 +603,11 @@ bool PulseController::AdvanceModelTime(double time, const TimeUnit& unit)
else else
{ {
double time_s = Convert(time, unit, TimeUnit::s) + m_SpareAdvanceTime_s; 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++) for (int i = 0; i < count; i++)
if (!AdvanceModelTime()) if (!AdvanceModelTime())
return false; return false;
m_SpareAdvanceTime_s = time_s - (count * GetTimeStep().GetValue(TimeUnit::s)); m_SpareAdvanceTime_s = time_s - (count * GetTimeStep_s());
} }
return true; return true;
} }
......
...@@ -135,6 +135,7 @@ public: ...@@ -135,6 +135,7 @@ public:
virtual const PulseConfiguration& GetConfiguration() const; virtual const PulseConfiguration& GetConfiguration() const;
virtual double GetTimeStep_s() const;
virtual const SEScalarTime& GetTimeStep() const; virtual const SEScalarTime& GetTimeStep() const;
virtual const SEScalarTime& GetEngineTime() const; virtual const SEScalarTime& GetEngineTime() const;
virtual const SEScalarTime& GetSimulationTime() const; virtual const SEScalarTime& GetSimulationTime() const;
......
...@@ -123,7 +123,6 @@ void AnesthesiaMachine::Initialize() ...@@ -123,7 +123,6 @@ void AnesthesiaMachine::Initialize()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void AnesthesiaMachine::SetUp() void AnesthesiaMachine::SetUp()
{ {
m_dt_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
m_actions = &m_data.GetActions().GetEquipmentActions(); m_actions = &m_data.GetActions().GetEquipmentActions();
m_dValveOpenResistance_cmH2O_s_Per_L = m_data.GetConfiguration().GetMachineOpenResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L); 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); m_dValveClosedResistance_cmH2O_s_Per_L = m_data.GetConfiguration().GetMachineClosedResistance(PressureTimePerVolumeUnit::cmH2O_s_Per_L);
...@@ -529,7 +528,7 @@ void AnesthesiaMachine::CalculateSourceStatus() ...@@ -529,7 +528,7 @@ void AnesthesiaMachine::CalculateSourceStatus()
double dBottle1Volume_L = GetOxygenBottleOne().GetVolume().GetValue(VolumeUnit::L); double dBottle1Volume_L = GetOxygenBottleOne().GetVolume().GetValue(VolumeUnit::L);
if (dBottle1Volume_L > 0.0) 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 else if (dBottle1Volume_L <= 0.0) //Empty
{ {
...@@ -544,7 +543,7 @@ void AnesthesiaMachine::CalculateSourceStatus() ...@@ -544,7 +543,7 @@ void AnesthesiaMachine::CalculateSourceStatus()
double dBottle2Volume_L = GetOxygenBottleTwo().GetVolume().GetValue(VolumeUnit::L); double dBottle2Volume_L = GetOxygenBottleTwo().GetVolume().GetValue(VolumeUnit::L);
if (dBottle2Volume_L > 0.0) 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) else if (dBottle2Volume_L <= 0.0)
{ {
...@@ -731,7 +730,7 @@ void AnesthesiaMachine::CalculateVentilatorPressure() ...@@ -731,7 +730,7 @@ void AnesthesiaMachine::CalculateVentilatorPressure()
void AnesthesiaMachine::CalculateCyclePhase() void AnesthesiaMachine::CalculateCyclePhase()
{ {
//Determine where we are in the cycle //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 if (m_currentbreathingCycleTime_s > m_totalBreathingCycleTime_s) //End of the cycle
{ {
m_totalBreathingCycleTime_s=0.0; m_totalBreathingCycleTime_s=0.0;
......
...@@ -65,7 +65,6 @@ protected: ...@@ -65,7 +65,6 @@ protected:
double m_totalBreathingCycleTime_s; double m_totalBreathingCycleTime_s;
// Stateless member variable (Set in SetUp()) // Stateless member variable (Set in SetUp())
double m_dt_s;
double m_dValveOpenResistance_cmH2O_s_Per_L; double m_dValveOpenResistance_cmH2O_s_Per_L;
double m_dValveClosedResistance_cmH2O_s_Per_L; double m_dValveClosedResistance_cmH2O_s_Per_L;
double m_dSwitchOpenResistance_cmH2O_s_Per_L; double m_dSwitchOpenResistance_cmH2O_s_Per_L;
......
...@@ -78,7 +78,7 @@ void ECG::Initialize() ...@@ -78,7 +78,7 @@ void ECG::Initialize()
void ECG::SetUp() void ECG::SetUp()
{ {
m_dt_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
...@@ -110,7 +110,7 @@ void ECG::PreProcess() ...@@ -110,7 +110,7 @@ void ECG::PreProcess()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void ECG::Process(bool solve_and_transport) 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) if (m_heartRhythmTime_s >= m_heartRhythmPeriod_s)
{ {
m_heartRhythmTime_s = 0; m_heartRhythmTime_s = 0;
......
...@@ -41,5 +41,4 @@ protected: ...@@ -41,5 +41,4 @@ protected:
SEElectroCardioGramWaveformInterpolator* m_interpolator; SEElectroCardioGramWaveformInterpolator* m_interpolator;
// Stateless member variable (Set in SetUp()) // Stateless member variable (Set in SetUp())
double m_dt_s;
}; };
...@@ -63,9 +63,6 @@ void Inhaler::Initialize() ...@@ -63,9 +63,6 @@ void Inhaler::Initialize()
void Inhaler::SetUp() 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_AmbientEnv = m_data.GetCompartments().GetGasCompartment(pulse::EnvironmentCompartment::Ambient);
m_Mouthpiece = m_data.GetCompartments().GetGasCompartment(pulse::InhalerCompartment::Mouthpiece); m_Mouthpiece = m_data.GetCompartments().GetGasCompartment(pulse::InhalerCompartment::Mouthpiece);
m_AerosolMouthpiece = m_data.GetCompartments().GetLiquidCompartment(pulse::InhalerCompartment::Mouthpiece); m_AerosolMouthpiece = m_data.GetCompartments().GetLiquidCompartment(pulse::InhalerCompartment::Mouthpiece);
......
...@@ -43,7 +43,6 @@ protected: ...@@ -43,7 +43,6 @@ protected:
// Serializable member variables (Set in Initialize and in schema) // Serializable member variables (Set in Initialize and in schema)
// Stateless member variable (Set in SetUp()) // Stateless member variable (Set in SetUp())
double m_dt_s;
SEGasCompartment *m_Mouthpiece; SEGasCompartment *m_Mouthpiece;
SELiquidCompartment *m_AerosolMouthpiece; SELiquidCompartment *m_AerosolMouthpiece;
SEGasCompartment *m_AmbientEnv; SEGasCompartment *m_AmbientEnv;
......
...@@ -83,8 +83,6 @@ void MechanicalVentilator::Initialize() ...@@ -83,8 +83,6 @@ void MechanicalVentilator::Initialize()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void MechanicalVentilator::SetUp() void MechanicalVentilator::SetUp()
{ {
m_dt_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
// Compartments // Compartments
m_Environment = m_data.GetCompartments().GetGasCompartment(pulse::EnvironmentCompartment::Ambient); m_Environment = m_data.GetCompartments().GetGasCompartment(pulse::EnvironmentCompartment::Ambient);
m_Ventilator = m_data.GetCompartments().GetGasCompartment(pulse::MechanicalVentilatorCompartment::MechanicalVentilator); m_Ventilator = m_data.GetCompartments().GetGasCompartment(pulse::MechanicalVentilatorCompartment::MechanicalVentilator);
...@@ -320,7 +318,7 @@ void MechanicalVentilator::PreProcess() ...@@ -320,7 +318,7 @@ void MechanicalVentilator::PreProcess()
SetVentilatorDriver(); SetVentilatorDriver();
SetResistances(); SetResistances();
m_CurrentPeriodTime_s += m_dt_s; m_CurrentPeriodTime_s += m_data.GetTimeStep_s();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
...@@ -405,7 +403,7 @@ void MechanicalVentilator::CalculateInspiration() ...@@ -405,7 +403,7 @@ void MechanicalVentilator::CalculateInspiration()
return; 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 // Check trigger
if (HasExpirationCycleTime()) if (HasExpirationCycleTime())
......
...@@ -62,8 +62,6 @@ protected: ...@@ -62,8 +62,6 @@ protected:
eBreathState m_CurrentBreathState; eBreathState m_CurrentBreathState;
// Stateless member variable (Set in SetUp()) // Stateless member variable (Set in SetUp())
double m_dt_s;
SEGasCompartment* m_Environment; SEGasCompartment* m_Environment;
SEGasCompartment* m_Ventilator; SEGasCompartment* m_Ventilator;
SELiquidCompartment* m_VentilatorAerosol; SELiquidCompartment* m_VentilatorAerosol;
......
...@@ -265,7 +265,6 @@ void Cardiovascular::Initialize() ...@@ -265,7 +265,6 @@ void Cardiovascular::Initialize()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void Cardiovascular::SetUp() void Cardiovascular::SetUp()
{ {
m_dT_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
m_minIndividialSystemicResistance_mmHg_s_Per_mL = 0.1; m_minIndividialSystemicResistance_mmHg_s_Per_mL = 0.1;
//Circuits //Circuits
...@@ -529,7 +528,7 @@ void Cardiovascular::ChronicPericardialEffusion() ...@@ -529,7 +528,7 @@ void Cardiovascular::ChronicPericardialEffusion()
//Just throw this all on at once //Just throw this all on at once
//Only do this for a single time-step! //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) ...@@ -626,8 +625,8 @@ void Cardiovascular::Process(bool solve_and_transport)
{ {
if (solve_and_transport) if (solve_and_transport)
{ {
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_dT_s); m_circuitCalculator->Process(*m_CirculatoryCircuit, m_data.GetTimeStep_s());
m_transporter->Transport(*m_CirculatoryGraph, m_dT_s); m_transporter->Transport(*m_CirculatoryGraph, m_data.GetTimeStep_s());
} }
CalculateVitalSigns(); CalculateVitalSigns();
ComputeExposedModelParameters(); ComputeExposedModelParameters();
...@@ -698,7 +697,7 @@ void Cardiovascular::CalculateVitalSigns() ...@@ -698,7 +697,7 @@ void Cardiovascular::CalculateVitalSigns()
m_pAortaToSplanchnic->GetNextFlow(VolumePerTimeUnit::mL_Per_s); m_pAortaToSplanchnic->GetNextFlow(VolumePerTimeUnit::mL_Per_s);
// Calculate heart rate - Threshold of 0.1 is empirically determined. Approximate zero makes it too noisy. // 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) if (LHeartFlow_mL_Per_s > 0.1 && !m_HeartFlowDetected)
{ {
m_HeartFlowDetected = true; m_HeartFlowDetected = true;
...@@ -723,7 +722,7 @@ void Cardiovascular::CalculateVitalSigns() ...@@ -723,7 +722,7 @@ void Cardiovascular::CalculateVitalSigns()
m_CardiacCycleDiastolicVolume_mL = LHeartVolume_mL; m_CardiacCycleDiastolicVolume_mL = LHeartVolume_mL;
// Increment stroke volume. Get samples for running means // 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_CardiacCycleArterialPressure_mmHg->Sample(AortaNodePressure_mmHg);
m_CardiacCycleArterialCO2PartialPressure_mmHg->Sample(AortaNodeCO2PartialPressure_mmHg); m_CardiacCycleArterialCO2PartialPressure_mmHg->Sample(AortaNodeCO2PartialPressure_mmHg);
m_CardiacCyclePulmonaryCapillariesWedgePressure_mmHg->Sample(PulmVeinNodePressure_mmHg); m_CardiacCyclePulmonaryCapillariesWedgePressure_mmHg->Sample(PulmVeinNodePressure_mmHg);
...@@ -1297,7 +1296,7 @@ void Cardiovascular::Hemorrhage() ...@@ -1297,7 +1296,7 @@ void Cardiovascular::Hemorrhage()
h->GetFlowRate().SetValue(hemorrhagePathFlow_mL_Per_s, VolumePerTimeUnit::mL_Per_s); h->GetFlowRate().SetValue(hemorrhagePathFlow_mL_Per_s, VolumePerTimeUnit::mL_Per_s);
} }
hemorrhagePathFlow_mL_Per_s = h->HasFlowRate() ? h->GetFlowRate(VolumePerTimeUnit::mL_Per_s) : 0; 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() ...@@ -1354,7 +1353,7 @@ void Cardiovascular::Hemorrhage()
InternalHemorrhagePressureApplication(); InternalHemorrhagePressureApplication();
GetTotalHemorrhageRate().SetValue(TotalLossRate_mL_Per_s, VolumePerTimeUnit::mL_Per_s); 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() ...@@ -1549,7 +1548,7 @@ void Cardiovascular::CalculateAndSetCPRcompressionForce()
compressionForce_N = m_data.GetActions().GetPatientActions().GetChestCompressionForce().GetForce().GetValue(ForceUnit::N); 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) if (compressionForce_N > compressionForceMax_N)
{ {
...@@ -1593,7 +1592,7 @@ void Cardiovascular::CardiacArrest() ...@@ -1593,7 +1592,7 @@ void Cardiovascular::CardiacArrest()
// The cardiac arrest event will be triggered by CardiacCycleCalculations() at the end of the cardiac cycle. // The cardiac arrest event will be triggered by CardiacCycleCalculations() at the end of the cardiac cycle.
m_EnterCardiacArrest = true; m_EnterCardiacArrest = true;
//Force a new cardiac cycle to start when cardiac arrest is removed //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 else
{ {
...@@ -1670,7 +1669,7 @@ void Cardiovascular::HeartDriver() ...@@ -1670,7 +1669,7 @@ void Cardiovascular::HeartDriver()
if (!m_data.GetEvents().IsEventActive(eEvent::CardiacArrest)) 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 m_StartSystole = true; // A new cardiac cycle will begin next time step
AdjustVascularTone(); AdjustVascularTone();
...@@ -1684,7 +1683,7 @@ void Cardiovascular::HeartDriver() ...@@ -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) // 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). // 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. // 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() ...@@ -1944,7 +1943,7 @@ void Cardiovascular::CalculateHeartRate()
{ {
// The time that the flow actually decreased below the threshold was last time slice (when m_HeartFlowDetected // 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. // 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); GetHeartRate().SetValue(HeartRate_Per_s * 60.0, FrequencyUnit::Per_min);
m_CurrentCardiacCycleDuration_s = 0; m_CurrentCardiacCycleDuration_s = 0;
} }
...@@ -2039,7 +2038,7 @@ void Cardiovascular::CalculatePleuralCavityVenousEffects() ...@@ -2039,7 +2038,7 @@ void Cardiovascular::CalculatePleuralCavityVenousEffects()
double dampenFraction_perSec = 0.001 * 50.0; double dampenFraction_perSec = 0.001 * 50.0;
double previousRightHeartResistance_mmHg_s_Per_mL = m_RightHeartResistance->GetResistance(PressureTimePerVolumeUnit::mmHg_s_Per_mL); 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; rightHeartResistance_mmHg_s_Per_mL = previousRightHeartResistance_mmHg_s_Per_mL + resistanceChange_L_Per_mmHg_s_Per_mL;
...@@ -2103,7 +2102,7 @@ void Cardiovascular::TuneCircuit() ...@@ -2103,7 +2102,7 @@ void Cardiovascular::TuneCircuit()
{ {
m_data.AdvanceCallback(-1); m_data.AdvanceCallback(-1);
HeartDriver(); HeartDriver();
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_dT_s); m_circuitCalculator->Process(*m_CirculatoryCircuit, m_data.GetTimeStep_s());
CalculateVitalSigns(); CalculateVitalSigns();
m_circuitCalculator->PostProcess(*m_CirculatoryCircuit); m_circuitCalculator->PostProcess(*m_CirculatoryCircuit);
//return; //Skip stabelization for debugging //return; //Skip stabelization for debugging
...@@ -2115,8 +2114,8 @@ void Cardiovascular::TuneCircuit() ...@@ -2115,8 +2114,8 @@ void Cardiovascular::TuneCircuit()
meanCVP_mmHg = GetMeanCentralVenousPressure(PressureUnit::mmHg); meanCVP_mmHg = GetMeanCentralVenousPressure(PressureUnit::mmHg);
blood_mL = GetBloodVolume(VolumeUnit::mL); blood_mL = GetBloodVolume(VolumeUnit::mL);
stableTime_s += m_dT_s; stableTime_s += m_data.GetTimeStep_s();
currentStableTime_s += m_dT_s; currentStableTime_s += m_data.GetTimeStep_s();
bool stableMAP = true; bool stableMAP = true;
if (GeneralMath::PercentDifference(tgt_map_mmHg, map_mmHg) > stabPercentTolerance) if (GeneralMath::PercentDifference(tgt_map_mmHg, map_mmHg) > stabPercentTolerance)
{ {
...@@ -2172,7 +2171,7 @@ void Cardiovascular::TuneCircuit() ...@@ -2172,7 +2171,7 @@ void Cardiovascular::TuneCircuit()
circuitTrk.CreateFile(m_TuningFile.c_str(), circuitFile); circuitTrk.CreateFile(m_TuningFile.c_str(), circuitFile);
circuitTrk.StreamTrackToFile(circuitFile); circuitTrk.StreamTrackToFile(circuitFile);
} }
time_s += m_dT_s; time_s += m_data.GetTimeStep_s();
} }
if (!m_TuneCircuit) if (!m_TuneCircuit)
{ {
...@@ -2447,13 +2446,13 @@ void Cardiovascular::TuneTissue(double time_s, DataTrack& circuitTrk, std::ofstr ...@@ -2447,13 +2446,13 @@ void Cardiovascular::TuneTissue(double time_s, DataTrack& circuitTrk, std::ofstr
{ {
m_data.AdvanceCallback(-1); m_data.AdvanceCallback(-1);
HeartDriver(); HeartDriver();
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_dT_s); m_circuitCalculator->Process(*m_CirculatoryCircuit, m_data.GetTimeStep_s());
CalculateVitalSigns(); CalculateVitalSigns();
m_circuitCalculator->PostProcess(*m_CirculatoryCircuit); m_circuitCalculator->PostProcess(*m_CirculatoryCircuit);
//return; //Skip stabelization for debugging //return; //Skip stabelization for debugging
time_s += m_dT_s; time_s += m_data.GetTimeStep_s();
currentStableTime_s += m_dT_s; currentStableTime_s += m_data.GetTimeStep_s();
for (size_t m=0; m<tissueResistancePaths.size(); m++) for (size_t m=0; m<tissueResistancePaths.size(); m++)
{ {
...@@ -2529,10 +2528,10 @@ void Cardiovascular::TuneTissue(double time_s, DataTrack& circuitTrk, std::ofstr ...@@ -2529,10 +2528,10 @@ void Cardiovascular::TuneTissue(double time_s, DataTrack& circuitTrk, std::ofstr
{ {
m_data.AdvanceCallback(-1); m_data.AdvanceCallback(-1);
HeartDriver(); HeartDriver();
m_circuitCalculator->Process(*m_CirculatoryCircuit, m_dT_s); m_circuitCalculator->Process(*m_CirculatoryCircuit, m_data.GetTimeStep_s());
CalculateVitalSigns(); CalculateVitalSigns();
m_circuitCalculator->PostProcess(*m_CirculatoryCircuit); m_circuitCalculator->PostProcess(*m_CirculatoryCircuit);
time_s += m_dT_s; time_s += m_data.GetTimeStep_s();
if (!m_TuningFile.empty()) if (!m_TuningFile.empty())
{ {
circuitTrk.Track(time_s, *m_CirculatoryCircuit); circuitTrk.Track(time_s, *m_CirculatoryCircuit);
......
...@@ -126,7 +126,6 @@ protected: ...@@ -126,7 +126,6 @@ protected:
SERunningAverage* m_CardiacCycleSkinFlow_mL_Per_s; SERunningAverage* m_CardiacCycleSkinFlow_mL_Per_s;
// Stateless member variable (Set in SetUp()) // Stateless member variable (Set in SetUp())
double m_dT_s;
bool m_TuneCircuit = true; bool m_TuneCircuit = true;
std::string m_TuningFile; std::string m_TuningFile;
......
...@@ -110,7 +110,6 @@ void Drugs::Initialize() ...@@ -110,7 +110,6 @@ void Drugs::Initialize()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void Drugs::SetUp() void Drugs::SetUp()
{ {
m_dt_s = m_data.GetTimeStep().GetValue(TimeUnit::s);
m_muscleIntracellular = m_data.GetCompartments().GetLiquidCompartment(pulse::ExtravascularCompartment::MuscleIntracellular); m_muscleIntracellular = m_data.GetCompartments().GetLiquidCompartment(pulse::ExtravascularCompartment::MuscleIntracellular);
m_aortaVascular = m_data.GetCompartments().GetLiquidCompartment(pulse::VascularCompartment::Aorta); m_aortaVascular = m_data.GetCompartments().GetLiquidCompartment(pulse::VascularCompartment::Aorta);
m_venaCavaVascular = m_data.GetCompartments().GetLiquidCompartment(pulse::VascularCompartment::VenaCava); m_venaCavaVascular = m_data.GetCompartments().GetLiquidCompartment(pulse::VascularCompartment::VenaCava);
...@@ -237,7 +236,7 @@ void Drugs::AdministerSubstanceBolus() ...@@ -237,7 +236,7 @@ void Drugs::AdministerSubstanceBolus()
} }
administrationTime_s = bolus->GetAdminDuration(TimeUnit::s); administrationTime_s = bolus->GetAdminDuration(TimeUnit::s);
concentration_ugPermL = bolus->GetConcentration(MassPerVolumeUnit::ug_Per_mL); 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->GetMass().IncrementValue(massIncrement_ug, MassUnit::ug);
subQ->Balance(BalanceLiquidBy::Mass); subQ->Balance(BalanceLiquidBy::Mass);
bolus->GetAdministeredDose().IncrementValue(massIncrement_ug / concentration_ugPermL, VolumeUnit::mL); bolus->GetAdministeredDose().IncrementValue(massIncrement_ug / concentration_ugPermL, VolumeUnit::mL);
...@@ -275,7 +274,7 @@ void Drugs::AdministerSubstanceInfusion() ...@@ -275,7 +274,7 @@ void Drugs::AdministerSubstanceInfusion()
concentration_ug_Per_mL = infusion->GetConcentration().GetValue(MassPerVolumeUnit::ug_Per_mL); concentration_ug_Per_mL = infusion->GetConcentration().GetValue(MassPerVolumeUnit::ug_Per_mL);
rate_mL_Per_s = infusion->GetRate().GetValue(VolumePerTimeUnit::mL_Per_s); 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 = m_venaCavaVascular->GetSubstanceQuantity(infusion->GetSubstance());
subQ->GetMass().IncrementValue(massIncrement_ug, MassUnit::ug); subQ->GetMass().IncrementValue(massIncrement_ug, MassUnit::ug);
/// \todo Enforce limits and remove the fatal error /// \todo Enforce limits and remove the fatal error
...@@ -336,7 +335,7 @@ void Drugs::AdministerSubstanceCompoundInfusion() ...@@ -336,7 +335,7 @@ void Drugs::AdministerSubstanceCompoundInfusion()
return; 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); double total_mL = infusion->GetBagVolume().GetValue(VolumeUnit::mL);
if (total_mL <= 0) if (total_mL <= 0)
{ /// \todo correct the mass based on what we have left in the bag { /// \todo correct the mass based on what we have left in the bag
...@@ -347,7 +346,7 @@ void Drugs::AdministerSubstanceCompoundInfusion() ...@@ -347,7 +346,7 @@ void Drugs::AdministerSubstanceCompoundInfusion()
for (const SESubstanceConcentration* component : compound->GetComponents()) for (const SESubstanceConcentration* component : compound->GetComponents())
{ {
subQ = m_venaCavaVascular->GetSubstanceQuantity(component->GetSubstance()); 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->GetMass().IncrementValue(massIncrement_ug, MassUnit::ug);
subQ->Balance(BalanceLiquidBy::Mass); subQ->Balance(BalanceLiquidBy::Mass);
} }
...@@ -356,7 +355,7 @@ void Drugs::AdministerSubstanceCompoundInfusion() ...@@ -356,7 +355,7 @@ void Drugs::AdministerSubstanceCompoundInfusion()
densityFluid_kg_Per_mL = m_data.GetConfiguration().GetWaterDensity(MassPerVolumeUnit::kg_Per_mL); densityFluid_kg_Per_mL = m_data.GetConfiguration().GetWaterDensity(MassPerVolumeUnit::kg_Per_mL);
else if (compound->GetName().compare("Blood") == 0) else if (compound->GetName().compare("Blood") == 0)
densityFluid_kg_Per_mL = m_data.GetBloodChemistry().GetBloodDensity(MassPerVolumeUnit::kg_Per_mL); densityFluid_kg_Per_mL = m_data.GetBloodChemistry().GetBloodDensity(MassPerVolumeUnit::kg_Per_mL);