An update will be applied January 25th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

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

Activate new conditions, Add Multiply Scalar support, and other bug fixes

parent 71aee7a6
......@@ -48,13 +48,13 @@ void SEGasSubstanceQuantity::Clear()
void SEGasSubstanceQuantity::SetToZero()
{
auto pp = GetPartialPressure();
auto& pp = GetPartialPressure();
if (pp.HasUnit())
pp.SetValue(0, *pp.GetUnit());
else
pp.SetValue(0, PressureUnit::mmHg);
auto vol = GetVolume();
auto& vol = GetVolume();
if (vol.HasUnit())
vol.SetValue(0, *vol.GetUnit());
else
......
......@@ -85,19 +85,19 @@ void SELiquidSubstanceQuantity::Clear()
void SELiquidSubstanceQuantity::SetToZero()
{
auto c = GetConcentration();
auto& c = GetConcentration();
if (c.HasUnit())
c.SetValue(0, *c.GetUnit());
else
c.SetValue(0, MassPerVolumeUnit::mg_Per_mL);
auto m = GetMass();
auto& m = GetMass();
if (m.HasUnit())
m.SetValue(0, *m.GetUnit());
else
m.SetValue(0, MassUnit::mg);
auto mol = GetMolarity();
auto& mol = GetMolarity();
if (mol.HasUnit())
mol.SetValue(0, *mol.GetUnit());
else
......@@ -105,7 +105,7 @@ void SELiquidSubstanceQuantity::SetToZero()
if (m_Substance.GetState() == eSubstance_State::Gas)
{
auto pp = GetPartialPressure();
auto& pp = GetPartialPressure();
if (pp.HasUnit())
pp.SetValue(0, *pp.GetUnit());
else
......@@ -115,19 +115,19 @@ void SELiquidSubstanceQuantity::SetToZero()
if (m_isO2 || m_isCO || m_isCO2)
GetSaturation().SetValue(0);
auto mc = GetMassCleared();
auto& mc = GetMassCleared();
if (mc.HasUnit())
mc.SetValue(0, *mc.GetUnit());
else
mc.SetValue(0, MassUnit::mg);
auto md = GetMassDeposited();
auto& md = GetMassDeposited();
if (md.HasUnit())
md.SetValue(0, *md.GetUnit());
else
md.SetValue(0, MassUnit::mg);
auto me = GetMassExcreted();
auto& me = GetMassExcreted();
if (me.HasUnit())
me.SetValue(0, *me.GetUnit());
else
......@@ -379,7 +379,7 @@ SEScalarAmountPerVolume& SELiquidSubstanceQuantity::GetMolarity()
m_Molarity->Invalidate();
else
{
double molarity_mmol_Per_mL = GetMass(MassUnit::mg) / m_Substance.GetMolarMass(MassPerAmountUnit::mg_Per_mmol) / m_Compartment.GetVolume(VolumeUnit::mL);
double molarity_mmol_Per_mL = GetMass(MassUnit::mg) / m_Substance.GetMolarMass(MassPerAmountUnit::mg_Per_mmol) / m_Compartment.GetVolume(VolumeUnit::mL);
m_Molarity->SetValue(molarity_mmol_Per_mL, AmountPerVolumeUnit::mmol_Per_mL);
}
m_Molarity->SetReadOnly(true);
......
......@@ -408,6 +408,8 @@ const SEInitialEnvironmentConditions* SEConditionManager::GetInitialEnvironmentC
void SEConditionManager::GetAllConditions(std::vector<const SECondition*>& conditions) const
{
if (HasAcuteRespiratoryDistressSyndrome())
conditions.push_back(GetAcuteRespiratoryDistressSyndrome());
if (HasChronicAnemia())
conditions.push_back(GetChronicAnemia());
if (HasChronicObstructivePulmonaryDisease())
......@@ -424,12 +426,17 @@ void SEConditionManager::GetAllConditions(std::vector<const SECondition*>& condi
conditions.push_back(GetImpairedAlveolarExchange());
if (HasLobarPneumonia())
conditions.push_back(GetLobarPneumonia());
if (HasSepsis())
conditions.push_back(GetSepsis());
if (HasInitialEnvironmentConditions())
conditions.push_back(GetInitialEnvironmentConditions());
}
bool SEConditionManager::IsEmpty() const
{
if (HasAcuteRespiratoryDistressSyndrome())
return false;
if (HasChronicAnemia())
return false;
if (HasChronicObstructivePulmonaryDisease())
......@@ -446,6 +453,9 @@ bool SEConditionManager::IsEmpty() const
return false;
if (HasLobarPneumonia())
return false;
if (HasSepsis())
return false;
if (HasInitialEnvironmentConditions())
return false;
return true;
......
......@@ -36,7 +36,7 @@ SEScalar::~SEScalar()
void SEScalar::Clear()
{
SEProperty::Clear();
SEProperty::Clear();
m_readOnly = false;
Invalidate();
}
......@@ -51,7 +51,7 @@ bool SEScalar::Set(const SEScalar& s)
throw CommonDataModelException("Scalar is marked read-only");
m_value = s.m_value;
m_isnan = (std::isnan(m_value)) ? true : false;
m_isinf = (std::isinf(m_value)) ? true : false;
m_isinf = (std::isinf(m_value)) ? true : false;
return true;
}
......@@ -154,6 +154,27 @@ double SEScalar::IncrementValue(double d)
return m_value;
}
double SEScalar::Multiply(const SEScalar& s)
{
if (!s.IsValid())
Invalidate();
else
MultiplyValue(s.GetValue());
return m_value;
}
double SEScalar::MultiplyValue(double d)
{
if (!IsValid())
{
SetValue(d);
return d;
}
SetValue(m_value * d);
return m_value;
}
void SEScalar::Average(int cnt)
{
if (!IsValid() || cnt == 0)
......
......@@ -66,6 +66,9 @@ public:
double Increment(const SEScalar& s);
double IncrementValue(double d);
double Multiply(const SEScalar& s);
double MultiplyValue(double d);
void Average(int cnt);
bool Equals(const SEScalar& to) const;
......@@ -117,6 +120,7 @@ public:
virtual void SetValue(double d, const CCompoundUnit& unit) = 0;
virtual void ForceValue(double d, const CCompoundUnit& unit) = 0;
virtual double IncrementValue(double d, const CCompoundUnit& unit) = 0;
virtual double MultiplyValue(double d, const CCompoundUnit& unit) = 0;
protected:
virtual const CCompoundUnit* GetCompoundUnit(const std::string& unit) const = 0;
......@@ -145,6 +149,7 @@ protected:
virtual void SetValue(double d, const CCompoundUnit& unit);
virtual void ForceValue(double d, const CCompoundUnit& unit);
virtual double IncrementValue(double d, const CCompoundUnit& unit);
virtual double MultiplyValue(double d, const CCompoundUnit& unit);
virtual const CCompoundUnit* GetCompoundUnit(const std::string& unit) const;
......@@ -171,6 +176,12 @@ public:
double Increment(const SEScalar& s) = delete;// Must provide a unit
virtual double Increment(const SEScalarQuantity& s);
double MultiplyValue(double d) = delete;// Must provide a unit
virtual double MultiplyValue(double d, const Unit& unit);
double Multiply(const SEScalar& s) = delete;// Must provide a unit
virtual double Multiply(const SEScalarQuantity& s);
bool Equals(const SEScalar& to) const = delete;// Must provide a unit
virtual bool Equals(const SEScalarQuantity<Unit>& to) const;
......
......@@ -181,6 +181,38 @@ double SEScalarQuantity<Unit>::IncrementValue(double d, const CCompoundUnit& uni
return this->IncrementValue(d, *u);
}
template<typename Unit>
double SEScalarQuantity<Unit>::Multiply(const SEScalarQuantity<Unit>& s)
{
if (!s.IsValid())
this->Invalidate();
else
return this->MultiplyValue(s.m_value, *s.m_unit);
return m_value;
}
template<typename Unit>
double SEScalarQuantity<Unit>::MultiplyValue(double d, const Unit& unit)
{
if (!IsValid())
{
this->SetValue(d, unit);
return d;
}
this->SetValue(m_value * Convert(d, unit, *m_unit), *m_unit);
return Convert(m_value, *m_unit, unit);
}
template<typename Unit>
double SEScalarQuantity<Unit>::MultiplyValue(double d, const CCompoundUnit& unit)
{
const Unit* u = dynamic_cast<const Unit*>(&unit);
if (u == nullptr)
throw CommonDataModelException("Provided unit is not of proper quantity type");
return this->MultiplyValue(d, *u);
}
template<typename Unit>
bool SEScalarQuantity<Unit>::Equals(const SEScalarQuantity<Unit>& to) const
{
......
......@@ -36,6 +36,7 @@ SERespiratorySystem::SERespiratorySystem(Logger* logger) : SESystem(logger)
m_InspiratoryFlow = nullptr;
m_InspiratoryPulmonaryResistance = nullptr;
m_IntrapleuralPressure = nullptr;
m_IntrapulmonaryPressure = nullptr;
m_LungCompliance = nullptr;
m_MaximalInspiratoryPressure = nullptr;
m_PatientPowerOfBreathing = nullptr;
......@@ -61,6 +62,7 @@ SERespiratorySystem::SERespiratorySystem(Logger* logger) : SESystem(logger)
m_TransairwayPressure = nullptr;
m_TransalveolarPressure = nullptr;
m_TransChestWallPressure = nullptr;
m_TransMusclePressure = nullptr;
m_TranspulmonaryPressure = nullptr;
m_TransrespiratoryPressure = nullptr;
m_TransthoracicPressure = nullptr;
......@@ -93,6 +95,7 @@ void SERespiratorySystem::Clear()
SAFE_DELETE(m_InspiratoryFlow);
SAFE_DELETE(m_InspiratoryPulmonaryResistance);
SAFE_DELETE(m_IntrapleuralPressure);
SAFE_DELETE(m_IntrapulmonaryPressure);
SAFE_DELETE(m_LungCompliance);
SAFE_DELETE(m_MaximalInspiratoryPressure);
SAFE_DELETE(m_PatientPowerOfBreathing);
......@@ -118,6 +121,7 @@ void SERespiratorySystem::Clear()
SAFE_DELETE(m_TransairwayPressure);
SAFE_DELETE(m_TransalveolarPressure);
SAFE_DELETE(m_TransChestWallPressure);
SAFE_DELETE(m_TransMusclePressure);
SAFE_DELETE(m_TranspulmonaryPressure);
SAFE_DELETE(m_TransrespiratoryPressure);
SAFE_DELETE(m_TransthoracicPressure);
......
......@@ -175,8 +175,6 @@ bool PulseEngine::InitializeEngine(const SEPatientConfiguration& patient_configu
if(patient_configuration.HasConditions())
m_Conditions->Copy(*patient_configuration.GetConditions());
AtSteadyState(EngineState::AtInitialStableState);// This will peek at conditions
// Copy any changes to the current patient to the initial patient
m_InitialPatient->Copy(*m_CurrentPatient);
m_State = EngineState::SecondaryStabilization;
// Apply conditions and anything else to the physiology
......@@ -193,6 +191,8 @@ bool PulseEngine::InitializeEngine(const SEPatientConfiguration& patient_configu
return false;
}
AtSteadyState(EngineState::AtSecondaryStableState);
// Copy any changes to the current patient to the initial patient
m_InitialPatient->Copy(*m_CurrentPatient);
m_State = EngineState::Active;
// Hook up the handlers (Note events will still be in the log)
......
......@@ -31,6 +31,6 @@ Macro EngineUnitTest=EngineUnitTestDriver FastPlot Baseline=unit_tests/pulse/ Co
Macro EngineUnitTestFull=EngineUnitTestDriver FullPlot Baseline=unit_tests/pulse/ Computed=./test_results/unit_tests/pulse
Macro ScenarioTest=ScenarioTestDriver FastPlot Baseline=scenarios/ Computed=./test_results/scenarios
#patient/BasicStandard.json = ScenarioTest
patient/ARDSExacerbation.json = ScenarioTest
#patient/ARDSModerateBothLungs.json = ScenarioTest
RespiratoryDriver = EngineUnitTest Results=RespiratoryDriverOutput
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