Commit f030a53d authored by Aaron Bray's avatar Aaron Bray
Browse files

Provide the user the ability to dynamically define the time step

parent d8649680
......@@ -45,6 +45,7 @@
PulseConfiguration::PulseConfiguration(Logger* logger) : SEEngineConfiguration(logger)
{
m_TimeStep = nullptr;
m_AllowDynamicTimeStep = eSwitch::Off;
m_TimedStabilization = nullptr;
m_DynamicStabilization = nullptr;
m_AutoSerialization = nullptr;
......@@ -175,6 +176,7 @@ PulseConfiguration::PulseConfiguration(Logger* logger) : SEEngineConfiguration(l
PulseConfiguration::~PulseConfiguration()
{
SAFE_DELETE(m_TimeStep);
m_AllowDynamicTimeStep = eSwitch::Off;
SAFE_DELETE(m_AutoSerialization);
SAFE_DELETE(m_InitialOverrides);
......@@ -295,6 +297,7 @@ PulseConfiguration::~PulseConfiguration()
void PulseConfiguration::Clear()
{
INVALIDATE_PROPERTY(m_TimeStep);
m_AllowDynamicTimeStep = eSwitch::Off;
RemoveStabilization();
if(m_AutoSerialization)
m_AutoSerialization->Clear();
......@@ -454,6 +457,7 @@ void PulseConfiguration::Initialize(const std::string& dataDir, SESubstanceManag
// Reset to default values
GetTimeStep().SetValue(1.0 / 50.0, TimeUnit::s);
m_AllowDynamicTimeStep = eSwitch::Off;
if (!dataDir.empty())
{
GetECGInterpolator().SerializeFromFile(dataDir + "/ecg/StandardECG.json", &GetTimeStep());
......
......@@ -37,6 +37,9 @@ public:
virtual SEScalarTime& GetTimeStep();
virtual double GetTimeStep(const TimeUnit& unit) const;
virtual eSwitch AllowDynamicTimeStep() const { return m_AllowDynamicTimeStep; }
virtual void AllowDynamicTimeStep(eSwitch s) { m_AllowDynamicTimeStep = s; }
// You can have either a timed or dynamic stabilization object (cannot have both)
virtual bool HasStabilization() const;
virtual SEEngineStabilization* GetStabilization();
......@@ -68,6 +71,7 @@ public:
protected:
SEScalarTime* m_TimeStep;
eSwitch m_AllowDynamicTimeStep;
SETimedStabilization* m_TimedStabilization;
SEDynamicStabilization* m_DynamicStabilization;
SEAutoSerialization* m_AutoSerialization;
......
......@@ -594,12 +594,20 @@ bool PulseController::AdvanceModelTime()
bool PulseController::AdvanceModelTime(double time, const TimeUnit& unit)
{
double time_s = Convert(time, unit, TimeUnit::s) + m_SpareAdvanceTime_s;
int count = (int)(time_s / GetTimeStep().GetValue(TimeUnit::s));
for (int i = 0; i < count; i++)
if (!AdvanceModelTime())
return false;
m_SpareAdvanceTime_s = time_s - (count * GetTimeStep().GetValue(TimeUnit::s));
if (m_Config->AllowDynamicTimeStep() == eSwitch::On)
{
m_Config->GetTimeStep().SetValue(time, unit);
return AdvanceModelTime();
}
else
{
double time_s = Convert(time, unit, TimeUnit::s) + m_SpareAdvanceTime_s;
int count = (int)(time_s / GetTimeStep().GetValue(TimeUnit::s));
for (int i = 0; i < count; i++)
if (!AdvanceModelTime())
return false;
m_SpareAdvanceTime_s = time_s - (count * GetTimeStep().GetValue(TimeUnit::s));
}
return true;
}
......
......@@ -39,6 +39,8 @@ void PBPulseConfiguration::Serialize(const PULSE_BIND::ConfigurationData& src, P
if (src.has_timestep())
PBProperty::Load(src.timestep(), dst.GetTimeStep());
if (src.allowdynamictimestep() != CDM_BIND::eSwitch::NullSwitch)
dst.AllowDynamicTimeStep((eSwitch)src.allowdynamictimestep());
if (src.has_timedstabilization())
PBEngine::Load(src.timedstabilization(), dst.GetTimedStabilization());
else if (src.has_dynamicstabilization())
......@@ -365,6 +367,7 @@ void PBPulseConfiguration::Serialize(const PulseConfiguration& src, PULSE_BIND::
dst.set_allocated_dynamicstabilization(PBEngine::Unload(*src.m_DynamicStabilization));
if (src.HasTimeStep())
dst.set_allocated_timestep(PBProperty::Unload(*src.m_TimeStep));
dst.set_allowdynamictimestep((CDM_BIND::eSwitch)src.m_AllowDynamicTimeStep);
if (src.HasAutoSerialization())
dst.set_allocated_autoserialization(PBEngine::Unload(*src.m_AutoSerialization));
dst.set_writepatientbaselinefile((CDM_BIND::eSwitch)src.m_WritePatientBaselineFile);
......
......@@ -178,27 +178,29 @@ message ConfigurationData
}
pulse.cdm.bind.ScalarTimeData TimeStep = 1;/**<< @brief */
pulse.cdm.bind.eSwitch AllowDynamicTimeStep = 2;/**<< @brief The time step will be replaced to whatever is provided via AdvanceModelTime(double time, const TimeUnit& unit)*/
oneof StabilizationCriteria
{
string StabilizationFileName = 2;/**<< @brief */
pulse.cdm.bind.TimedStabilizationData TimedStabilization = 3;/**<< @brief */
pulse.cdm.bind.DynamicStabilizationData DynamicStabilization = 4;/**<< @brief */
string StabilizationFileName = 3;/**<< @brief */
pulse.cdm.bind.TimedStabilizationData TimedStabilization = 4;/**<< @brief */
pulse.cdm.bind.DynamicStabilizationData DynamicStabilization = 5;/**<< @brief */
}
pulse.cdm.bind.eSwitch WritePatientBaselineFile = 5;/**<< @brief Inform execution to write out patient object after stabilization completes. */
pulse.cdm.bind.AutoSerializationData AutoSerialization = 6;
BloodChemistryConfigurationData BloodChemistryConfiguration = 7;
CardiovascularConfigurationData CardiovascularConfiguration = 8;
CircuitConfigurationData CircuitConfiguration = 9;
ConstantsConfigurationData ConstantsConfiguration = 10;
DrugsConfigurationData DrugsConfiguration = 11;
ECGConfigurationData ECGConfiguration = 12;
EnergyConfigurationData EnergyConfiguration = 13;
EnvironmentConfigurationData EnvironmentConfiguration = 14;
GastrointestinalConfigurationData GastrointestinalConfiguration = 15;
NervousConfigurationData NervousConfiguration = 16;
RenalConfigurationData RenalConfiguration = 17;
RespiratoryConfigurationData RespiratoryConfiguration = 18;
TissueConfigurationData TissueConfiguration = 19;
pulse.cdm.bind.OverridesData InitialOverrides = 20;
pulse.cdm.bind.eSwitch WritePatientBaselineFile = 6;/**<< @brief Inform execution to write out patient object after stabilization completes. */
pulse.cdm.bind.AutoSerializationData AutoSerialization = 7;
BloodChemistryConfigurationData BloodChemistryConfiguration = 8;
CardiovascularConfigurationData CardiovascularConfiguration = 9;
CircuitConfigurationData CircuitConfiguration = 10;
ConstantsConfigurationData ConstantsConfiguration = 11;
DrugsConfigurationData DrugsConfiguration = 12;
ECGConfigurationData ECGConfiguration = 13;
EnergyConfigurationData EnergyConfiguration = 14;
EnvironmentConfigurationData EnvironmentConfiguration = 15;
GastrointestinalConfigurationData GastrointestinalConfiguration = 16;
NervousConfigurationData NervousConfiguration = 17;
RenalConfigurationData RenalConfiguration = 18;
RespiratoryConfigurationData RespiratoryConfiguration = 19;
TissueConfigurationData TissueConfiguration = 20;
pulse.cdm.bind.OverridesData InitialOverrides = 21;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment