Commit 59d65fff authored by Aaron Bray's avatar Aaron Bray
Browse files

More fixes due to keeping around the actions in the managers

Also fixed auto serialization testing, and some bugs there...
parent acca001e
{
{"Scenario": {
"Name":"BasicStandard",
"Description":"Basic scenario measuring patient vitals with no insults or interventions",
"EngineStateFile":"./states/StandardMale@0s.pbb",
......@@ -93,4 +93,21 @@
{"DecimalFormat":{"Precision":2}, "Category":"LiquidCompartment","CompartmentName":"Pericardium","PropertyName":"Pressure","Unit":"mmHg"}
]},
"AnyAction":[{"AdvanceTime":{"Time":{"ScalarTime":{"Value":2.0,"Unit":"min"}}}}]}
\ No newline at end of file
"AnyAction":[{"AdvanceTime":{"Time":{"ScalarTime":{"Value":2.0,"Unit":"min"}}}}]},
"Configuration": {
"AutoSerialization": {
"Directory": "./states/testing/",
"Filename": "patient/HemorrhageVaryingSeverity",
"AfterActions": "On",
"Period": {
"ScalarTime": {
"Value": 5.0,
"Unit": "s"
}
},
"PeriodTimeStamps": "On",
"ReloadState": "On"
}
}
}
......@@ -20,7 +20,7 @@ Threads=-1
#UseStates=true
# AutoSerialize = Directory,Period(in seconds, 0 turns off constant saving),TimeStampPeriods,AfterActions,Reload
# Time stamp periods is creating a file per save and using the time stamp as naming convention
#AutoSerialization=./states/testing/,5,On,On,On
#AutoSerialization=./states/testing/,0,On,On,On
Executor=com.kitware.pulse.cdm.testing.CDMUnitTestDriver
Executor=com.kitware.pulse.engine.testing.EngineUnitTestDriver
......
{
"Name": "EnvironmentExposure",
"Description": "Showcase scenario: Patient is exposed to sub-zero temperatures and develops hypothermia.",
"PatientConfiguration": { "PatientFile": "Jane.json" },
"PatientConfiguration": { "PatientFile": "Jane.json" },
"DataRequestManager": {
"DataRequest": [{
"DecimalFormat": {
......
......@@ -20,7 +20,7 @@ SEAutoSerialization::~SEAutoSerialization()
SAFE_DELETE(m_Period);
m_PeriodTimeStamps = eSwitch::Off;
m_AfterActions = eSwitch::Off;
m_AfterActions = eSwitch::Off;
m_ReloadState = eSwitch::Off;
m_Directory = "";
m_FileName = "";
}
......@@ -30,16 +30,16 @@ void SEAutoSerialization::Clear()
INVALIDATE_PROPERTY(m_Period);
m_PeriodTimeStamps = eSwitch::Off;
m_AfterActions = eSwitch::Off;
m_AfterActions = eSwitch::Off;
m_ReloadState = eSwitch::Off;
m_Directory = "";
m_FileName = "";
}
bool SEAutoSerialization::IsValid() const
{
if (!HasPeriod())
if (HasPeriod() && m_Period->IsNegative())
return false;
if (m_Period->IsNegative())
else if (m_AfterActions == eSwitch::Off)
return false;
if (!HasDirectory())
return false;
......
......@@ -163,6 +163,7 @@ void SEEngineTracker::SetupRequests()
bool isOpen = m_ResultsStream.is_open();
if (!isOpen || m_ForceConnection)
{// Process/Hook up all requests with their associated scalers
DELETE_MAP_SECOND(m_Request2Scalar);// Get our scalars again
for (SEDataRequest* dr : m_DataRequestMgr->GetDataRequests())
{
if (!TrackRequest(*dr))
......
......@@ -261,7 +261,7 @@ CDM_BIND::AnesthesiaMachineOxygenTankPressureLossData* PBEquipmentAction::Unload
void PBEquipmentAction::Serialize(const SEAnesthesiaMachineOxygenTankPressureLoss& src, CDM_BIND::AnesthesiaMachineOxygenTankPressureLossData& dst)
{
PBEquipmentAction::Serialize(src, *dst.mutable_anesthesiamachineaction());
dst.set_state(src.IsActive() ? CDM_BIND::eSwitch::On : CDM_BIND::eSwitch::Off);
dst.set_state(src.GetState()==eSwitch::On ? CDM_BIND::eSwitch::On : CDM_BIND::eSwitch::Off);
}
void PBEquipmentAction::Copy(const SEAnesthesiaMachineOxygenTankPressureLoss& src, SEAnesthesiaMachineOxygenTankPressureLoss& dst)
{
......@@ -290,7 +290,7 @@ CDM_BIND::AnesthesiaMachineOxygenWallPortPressureLossData* PBEquipmentAction::Un
void PBEquipmentAction::Serialize(const SEAnesthesiaMachineOxygenWallPortPressureLoss& src, CDM_BIND::AnesthesiaMachineOxygenWallPortPressureLossData& dst)
{
PBEquipmentAction::Serialize(src, *dst.mutable_anesthesiamachineaction());
dst.set_state(src.IsActive() ? CDM_BIND::eSwitch::On : CDM_BIND::eSwitch::Off);
dst.set_state(src.GetState()==eSwitch::On ? CDM_BIND::eSwitch::On : CDM_BIND::eSwitch::Off);
}
void PBEquipmentAction::Copy(const SEAnesthesiaMachineOxygenWallPortPressureLoss& src, SEAnesthesiaMachineOxygenWallPortPressureLoss& dst)
{
......
......@@ -328,7 +328,6 @@ void PBSubstance::Serialize(const CDM_BIND::SubstanceCompoundData& src, SESubsta
std::string err;
const SESubstance* substance = nullptr;
SESubstanceConcentration* cc;
for (int i = 0; i < src.component_size(); i++)
{
const CDM_BIND::SubstanceConcentrationData& cData = src.component(i);
......@@ -339,10 +338,8 @@ void PBSubstance::Serialize(const CDM_BIND::SubstanceCompoundData& src, SESubsta
dst.Fatal("Could not load find substance compound component : " + cData.name(), "SESubstanceCompound::Load");
continue;
}
cc = new SESubstanceConcentration(*substance);
PBSubstance::Load(cData, *cc);
dst.m_Components.push_back(cc);
dst.m_cComponents.push_back(cc);
SESubstanceConcentration& sc = dst.GetComponent(*substance);
PBSubstance::Load(cData, sc);
}
}
......
......@@ -43,10 +43,7 @@ bool SESupplementalOxygen::IsValid() const
bool SESupplementalOxygen::IsActive() const
{
if (!SEPatientAction::IsActive())
return false;
return m_Device != eSupplementalOxygen_Device::None;
// Defaults will be used if no flow/volume supplied
return SEPatientAction::IsActive();
}
void SESupplementalOxygen::Deactivate()
{
......
......@@ -68,7 +68,7 @@ const std::vector<const SESubstanceConcentration*>& SESubstanceCompound::GetComp
{
return m_cComponents;
}
const SESubstanceConcentration& SESubstanceCompound::GetComponent(SESubstance& substance)
SESubstanceConcentration& SESubstanceCompound::GetComponent(const SESubstance& substance)
{
for (SESubstanceConcentration* sq : m_Components)
{
......@@ -81,7 +81,7 @@ const SESubstanceConcentration& SESubstanceCompound::GetComponent(SESubstance& s
m_cComponents.push_back(sq);
return *sq;
}
const SESubstanceConcentration* SESubstanceCompound::GetComponent(SESubstance& substance) const
const SESubstanceConcentration* SESubstanceCompound::GetComponent(const SESubstance& substance) const
{
for (SESubstanceConcentration* sq : m_Components)
{
......@@ -100,6 +100,7 @@ void SESubstanceCompound::RemoveComponent(const SESubstance& substance)
m_Components.erase(m_Components.begin() + i);
m_cComponents.erase(m_cComponents.begin() + i);
delete sq;
break;
}
i++;
}
......
......@@ -26,10 +26,10 @@ public:
bool HasComponent() const;
bool HasComponent(const SESubstance& substance) const;
const std::vector<SESubstanceConcentration*>& GetComponents();
const std::vector<SESubstanceConcentration*>& GetComponents();
const std::vector<const SESubstanceConcentration*>& GetComponents() const;
const SESubstanceConcentration& GetComponent(SESubstance& substance);
const SESubstanceConcentration* GetComponent(SESubstance& substance) const;
SESubstanceConcentration& GetComponent(const SESubstance& substance);
const SESubstanceConcentration* GetComponent(const SESubstance& substance) const;
void RemoveComponent(const SESubstance& substance);
protected:
......
......@@ -134,9 +134,7 @@ bool SEEnvironment::ProcessChange(SEChangeEnvironmentalConditions& change, SESub
{
// If we have data then we merge it, if a file was provided
// we reset and set the environment to the file, so we only have the file data
if (change.HasEnvironmentalConditions())
GetEnvironmentalConditions().Merge(change.GetEnvironmentalConditions(), subMgr);
else if (change.HasEnvironmentalConditionsFile())
if (change.HasEnvironmentalConditionsFile())
{
// Update the action with the file contents
std::string cfg_file = change.GetEnvironmentalConditionsFile();
......@@ -148,6 +146,8 @@ bool SEEnvironment::ProcessChange(SEChangeEnvironmentalConditions& change, SESub
}
GetEnvironmentalConditions().Merge(change.GetEnvironmentalConditions(), subMgr);
}
else if (change.HasEnvironmentalConditions())
GetEnvironmentalConditions().Merge(change.GetEnvironmentalConditions(), subMgr);
StateChange();
return true;
}
......
......@@ -329,14 +329,19 @@ double SEEnvironmentalConditions::GetRespirationAmbientTemperature(const Tempera
bool SEEnvironmentalConditions::HasAmbientGas() const
{
return m_AmbientGases.size() == 0 ? false : true;
if (m_AmbientGases.empty())
return false;
for (auto g : m_AmbientGases)
if (g->HasFractionAmount() && g->GetFractionAmount().IsPositive())
return true;
return false;
}
bool SEEnvironmentalConditions::HasAmbientGas(const SESubstance& s) const
{
for (const SESubstanceFraction* sf : m_AmbientGases)
{
if (&s == &sf->GetSubstance())
return sf->GetFractionAmount() > 0;
return sf->HasFractionAmount() && sf->GetFractionAmount() > 0;
}
return false;
}
......@@ -385,14 +390,19 @@ void SEEnvironmentalConditions::RemoveAmbientGases()
bool SEEnvironmentalConditions::HasAmbientAerosol() const
{
return m_AmbientAerosols.size() == 0 ? false : true;
if (m_AmbientAerosols.empty())
return false;
for (auto a : m_AmbientAerosols)
if (a->HasConcentration() && a->GetConcentration().IsPositive())
return true;
return false;
}
bool SEEnvironmentalConditions::HasAmbientAerosol(const SESubstance& substance) const
{
for (SESubstanceConcentration* sc : m_AmbientAerosols)
{
if (&substance == &sc->GetSubstance())
return sc->GetConcentration().IsPositive();
return sc->HasConcentration() && sc->GetConcentration().IsPositive();
}
return false;
}
......
......@@ -49,6 +49,10 @@ const SEScalar* SEAnesthesiaMachineOxygenTankPressureLoss::GetScalar(const std::
return nullptr;
}
eSwitch SEAnesthesiaMachineOxygenTankPressureLoss::GetState() const
{
return m_State.GetEnum();
}
void SEAnesthesiaMachineOxygenTankPressureLoss::SetState(eSwitch state)
{
m_State.SetEnum(state);
......
......@@ -18,6 +18,7 @@ public:
virtual bool IsActive() const;
virtual void Deactivate();
virtual eSwitch GetState() const;
virtual void SetState(eSwitch state);
virtual void ToString(std::ostream &str) const;
......
......@@ -49,6 +49,11 @@ const SEScalar* SEAnesthesiaMachineOxygenWallPortPressureLoss::GetScalar(const s
return nullptr;
}
eSwitch SEAnesthesiaMachineOxygenWallPortPressureLoss::GetState() const
{
return m_State.GetEnum();
}
void SEAnesthesiaMachineOxygenWallPortPressureLoss::SetState(eSwitch state)
{
m_State.SetEnum(state);
......
......@@ -18,6 +18,7 @@ public:
virtual bool IsActive() const;
virtual void Deactivate();
virtual eSwitch GetState() const;
virtual void SetState(eSwitch state);
virtual void ToString(std::ostream &str) const;
......
......@@ -692,7 +692,12 @@ eMechanicalVentilator_DriverWaveform SEMechanicalVentilator::GetInspirationWavef
bool SEMechanicalVentilator::HasFractionInspiredGas() const
{
return m_FractionInspiredGases.size() == 0 ? false : true;
if (m_FractionInspiredGases.empty())
return false;
for (auto a : m_FractionInspiredGases)
if (a->HasFractionAmount() && a->GetFractionAmount().IsPositive())
return true;
return false;
}
bool SEMechanicalVentilator::HasFractionInspiredGas(const SESubstance& s) const
{
......@@ -748,7 +753,12 @@ void SEMechanicalVentilator::RemoveFractionInspiredGases()
bool SEMechanicalVentilator::HasConcentrationInspiredAerosol() const
{
return m_ConcentrationInspiredAerosols.size() == 0 ? false : true;
if (m_ConcentrationInspiredAerosols.empty())
return false;
for (auto a : m_ConcentrationInspiredAerosols)
if (a->HasConcentration() && a->GetConcentration().IsPositive())
return true;
return false;
}
bool SEMechanicalVentilator::HasConcentrationInspiredAerosol(const SESubstance& substance) const
{
......
......@@ -167,37 +167,33 @@ bool PulseScenarioExec::Execute(PhysiologyEngine& engine, const PulseScenario& s
return success;
}
bool PulseScenarioExec::ProcessActions(PulseEngine& engine, const SEScenario& scenario)
bool PulseScenarioExec::ProcessActions(PhysiologyEngine& engine, const SEScenario& scenario)
{
return SEScenarioExec::ProcessActions(engine, scenario);
}
bool PulseScenarioExec::ProcessAction(PulseEngine& engine, const SEAction& action)
bool PulseScenarioExec::ProcessAction(PhysiologyEngine& engine, const SEAction& action)
{
if (m_AutoSerializationAfterActions == eSwitch::On)
if (m_AutoSerializationAfterActions == eSwitch::On && m_AutoSerializationActions.str().empty())
{
m_ss << action;
size_t start = m_ss.str().find(": ") + 2;
size_t end = m_ss.str().find('\n');
m_AutoSerializationActions << "-" << m_ss.str().substr(start, end - start);
m_ss.str("");
m_AutoSerializationActions << "/AfterActions";
}
return SEScenarioExec::ProcessAction(engine, action);
}
void PulseScenarioExec::AdvanceEngine(PulseEngine& engine)
void PulseScenarioExec::AdvanceEngine(PhysiologyEngine& engine)
{
if (m_AutoSerializationPeriod_s > 0)
{
m_AutoSerializationTime_s += engine.GetTimeStep(TimeUnit::s);
if (m_AutoSerializationTime_s >= m_AutoSerializationPeriod_s)
{
Info("Serializing state after requested period : " + m_AutoSerializationActions.str());
m_AutoSerializationTime_s = 0;
m_AutoSerializationOutput.str("");
m_AutoSerializationOutput << m_AutoSerializationDirectory <<"/"<< m_AutoSerializationFileName;
if (m_AutoSerializationTimeStamps == eSwitch::On)
m_AutoSerializationOutput << "@" << engine.GetSimulationTime(TimeUnit::s);
m_AutoSerializationOutput << "/" << m_AutoSerializationFileName<< "@" << engine.GetSimulationTime(TimeUnit::s);
engine.SerializeToFile(m_AutoSerializationOutput.str() + ".json");
Info("Serializing state after requested period : " + m_AutoSerializationOutput.str() + ".json");
if (m_AutoSerializationReload == eSwitch::On)
{
engine.SerializeFromFile(m_AutoSerializationOutput.str() + ".json");
......@@ -208,14 +204,15 @@ void PulseScenarioExec::AdvanceEngine(PulseEngine& engine)
engine.AdvanceModelTime();
if (m_AutoSerializationActions.str().length() > 0)
{
Info("Serializing state after actions : " + m_AutoSerializationActions.str());
m_AutoSerializationOutput.str("");
m_AutoSerializationOutput << m_AutoSerializationDirectory <<"/"<< m_AutoSerializationFileName<<m_AutoSerializationActions.str();
if (m_AutoSerializationTimeStamps == eSwitch::On)
m_AutoSerializationOutput << "@" << engine.GetSimulationTime(TimeUnit::s);
engine.SerializeToFile(m_AutoSerializationOutput.str() + ".json");
Info("Serializing state after actions : " + m_AutoSerializationOutput.str()+".json");
if (m_AutoSerializationReload == eSwitch::On)
{
Info("Reloading and saving reloaded state to : " + m_AutoSerializationOutput.str() + ".Reload.json");
engine.SerializeFromFile(m_AutoSerializationOutput.str() + ".json");
engine.SerializeToFile(m_AutoSerializationOutput.str() + ".Reloaded.json");
}
......
......@@ -35,7 +35,7 @@ protected:
std::stringstream m_AutoSerializationOutput;
std::stringstream m_AutoSerializationActions;
virtual bool ProcessActions(PulseEngine& engine, const SEScenario& scenario);
virtual bool ProcessAction(PulseEngine& engine, const SEAction& action);
virtual void AdvanceEngine(PulseEngine& engine);
virtual bool ProcessActions(PhysiologyEngine& engine, const SEScenario& scenario) override;
virtual bool ProcessAction(PhysiologyEngine& engine, const SEAction& action) override;
virtual void AdvanceEngine(PhysiologyEngine& engine) override;
};
\ No newline at end of file
......@@ -153,7 +153,7 @@ void Environment::StateChange()
if (m_AmbientGases == nullptr ||m_AmbientAerosols == nullptr)
return;
if (GetEnvironmentalConditions().GetAmbientGases().size() > 0)
if (GetEnvironmentalConditions().HasAmbientGas())
{
// Add Gases to the environment
//Check to make sure fractions sum to 1.0
......
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