Skip to content

Commit

Permalink
Fixed main.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
m4n4n committed Aug 8, 2018
1 parent 96858e0 commit 35ea9d9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 147 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Expand Up @@ -15,8 +15,6 @@ list(APPEND HEADER_FILES

list(APPEND SOURCE_FILES
src/PulsePhysiology/main.cpp
src/PulsePhysiology/EngineUse.cpp

)


Expand Down
186 changes: 41 additions & 145 deletions src/PulsePhysiology/main.cpp
@@ -1,59 +1,21 @@
/* Distributed under the Apache License, Version 2.0.
See accompanying NOTICE file for details.*/

/* Distributed under the Apache License, Version 2.0.*/
// Include the various types you will be using in your code
#include "CommonDataModel.h"
#include "PulsePhysiologyEngine.h"
#include "scenario/SEDataRequestManager.h"
#include "patient/actions/SEHemorrhage.h"
#include "patient/actions/SESubstanceCompoundInfusion.h"
#include "system/physiology/SEBloodChemistrySystem.h"
#include "system/physiology/SECardiovascularSystem.h"
#include "system/physiology/SEEnergySystem.h"
#include "system/physiology/SERespiratorySystem.h"
#include "substance/SESubstanceManager.h"
#include "substance/SESubstanceCompound.h"
#include "properties/SEScalar0To1.h"
#include "properties/SEScalarFrequency.h"
#include "properties/SEScalarMass.h"
#include "properties/SEScalarMassPerVolume.h"
#include "properties/SEScalarPressure.h"
#include "properties/SEScalarTemperature.h"
#include "properties/SEScalarTime.h"
#include "properties/SEScalarVolume.h"
#include "properties/SEScalarVolumePerTime.h"
#include "engine/SEEngineTracker.h"
#include "compartment/SECompartmentManager.h"

/// This class is here to demonstrate executing the engine
/// The class in this file is here to demonstrate executing the engine
/// and populating a txt file with data from the engine
/// This class will handle advancing time on the engine
class HowToTracker
{
private:
double m_dT_s; // Cached Engine Time Step
PhysiologyEngine& m_Engine;
public:
HowToTracker(PhysiologyEngine& engine) : m_Engine(engine)
{
m_dT_s = m_Engine.GetTimeStep(TimeUnit::s);
}
~HowToTracker() { }

// This class will operate on seconds
void AdvanceModelTime(double time_s)
{
// This samples the engine at each time step
int count = static_cast<int>(time_s / m_dT_s);
for (int i = 0; i <= count; i++)
{
m_Engine.AdvanceModelTime(); // Compute 1 time step

// Pull Track will pull data from the engine and append it to the file
m_Engine.GetEngineTracker()->TrackData(m_Engine.GetSimulationTime(TimeUnit::s));
}
}
};
#include "AirwayObstruction.cpp"
#include "AnesthesiaMachine.cpp"
#include "Asthma.cpp"
#include "BolusDrug.cpp"
#include "BrainInjury.cpp"
#include "COPD.cpp"
#include "CPR.cpp"
#include "LobarPneumonia.cpp"
#include "PulmonaryFunctionTest.cpp"
#include "Smoke.cpp"
#include "TensionPneumothorax.cpp"
#include <string.h>

//--------------------------------------------------------------------------------------------------
/// \brief
Expand All @@ -66,97 +28,31 @@ class HowToTracker
//--------------------------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
// Create the engine and load the patient
std::unique_ptr<PhysiologyEngine> pe = CreatePulseEngine("HowToHemorrhage.log");
pe->GetLogger()->Info("HowToHemorrhage");
if (!pe->LoadStateFile("/mnt/data/pulse/install/bin/states/StandardMale@0s.pba"))
{
pe->GetLogger()->Error("Could not load state, check the error");
return -1;
}

// The tracker is responsible for advancing the engine time and outputting the data requests below at each time step
HowToTracker tracker(*pe);

// Create data requests for each value that should be written to the output log as the engine is executing
// Physiology System Names are defined on the System Objects
// defined in the Physiology.xsd file
SEDataRequestManager sedrm =pe->GetEngineTracker()->GetDataRequestManager();
sedrm.CreatePhysiologyDataRequest("HeartRate", FrequencyUnit::Per_min);
sedrm.CreatePhysiologyDataRequest("BloodVolume", VolumeUnit::mL);
sedrm.CreatePhysiologyDataRequest("CardiacOutput", VolumePerTimeUnit::mL_Per_min);
sedrm.CreatePhysiologyDataRequest("MeanArterialPressure", PressureUnit::mmHg);
sedrm.CreatePhysiologyDataRequest("SystolicArterialPressure", PressureUnit::mmHg);
sedrm.CreatePhysiologyDataRequest("DiastolicArterialPressure", PressureUnit::mmHg);
sedrm.CreatePhysiologyDataRequest("HemoglobinContent",MassUnit::g);

sedrm.SetResultsFilename("HowToHemorrhage.txt");

pe->GetLogger()->Info("The patient is nice and healthy");
pe->GetLogger()->Info(std::stringstream() <<"Cardiac Output : " << pe->GetCardiovascularSystem()->GetCardiacOutput(VolumePerTimeUnit::mL_Per_min) << VolumePerTimeUnit::mL_Per_min);
pe->GetLogger()->Info(std::stringstream() <<"Hemoglobin Content : " << pe->GetBloodChemistrySystem()->GetHemoglobinContent(MassUnit::g) << MassUnit::g);
pe->GetLogger()->Info(std::stringstream() <<"Blood Volume : " << pe->GetCardiovascularSystem()->GetBloodVolume(VolumeUnit::mL) << VolumeUnit::mL);
pe->GetLogger()->Info(std::stringstream() <<"Mean Arterial Pressure : " << pe->GetCardiovascularSystem()->GetMeanArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Systolic Pressure : " << pe->GetCardiovascularSystem()->GetSystolicArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Diastolic Pressure : " << pe->GetCardiovascularSystem()->GetDiastolicArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Heart Rate : " << pe->GetCardiovascularSystem()->GetHeartRate(FrequencyUnit::Per_min) << "bpm");;

// Hemorrhage Starts - instantiate a hemorrhage action and have the engine process it
SEHemorrhage hemorrhageLeg;
hemorrhageLeg.SetCompartment(pulse::VascularCompartment::RightLeg);//the location of the hemorrhage
hemorrhageLeg.GetRate().SetValue(250,VolumePerTimeUnit::mL_Per_min);//the rate of hemorrhage
pe->ProcessAction(hemorrhageLeg);

// Advance some time to let the body bleed out a bit
tracker.AdvanceModelTime(300);

pe->GetLogger()->Info("The patient has been hemorrhaging for 300s");
pe->GetLogger()->Info(std::stringstream() <<"Cardiac Output : " << pe->GetCardiovascularSystem()->GetCardiacOutput(VolumePerTimeUnit::mL_Per_min) << VolumePerTimeUnit::mL_Per_min);
pe->GetLogger()->Info(std::stringstream() <<"Hemoglobin Content : " << pe->GetBloodChemistrySystem()->GetHemoglobinContent(MassUnit::g) << MassUnit::g);
pe->GetLogger()->Info(std::stringstream() <<"Blood Volume : " << pe->GetCardiovascularSystem()->GetBloodVolume(VolumeUnit::mL) << VolumeUnit::mL);
pe->GetLogger()->Info(std::stringstream() <<"Mean Arterial Pressure : " << pe->GetCardiovascularSystem()->GetMeanArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Systolic Pressure : " << pe->GetCardiovascularSystem()->GetSystolicArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Diastolic Pressure : " << pe->GetCardiovascularSystem()->GetDiastolicArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Heart Rate : " << pe->GetCardiovascularSystem()->GetHeartRate(FrequencyUnit::Per_min) << "bpm");;

// Hemorrhage is sealed
hemorrhageLeg.SetCompartment(pulse::VascularCompartment::RightLeg);//location of hemorrhage
hemorrhageLeg.GetRate().SetValue(0,VolumePerTimeUnit::mL_Per_min);//rate is set to 0 to close the bleed
pe->ProcessAction(hemorrhageLeg);


// Advance some time while the medic gets the drugs ready
tracker.AdvanceModelTime(100);

pe->GetLogger()->Info("The patient has NOT been hemorrhaging for 100s");
pe->GetLogger()->Info(std::stringstream() <<"Cardiac Output : " << pe->GetCardiovascularSystem()->GetCardiacOutput(VolumePerTimeUnit::mL_Per_min) << VolumePerTimeUnit::mL_Per_min);
pe->GetLogger()->Info(std::stringstream() <<"Hemoglobin Content : " << pe->GetBloodChemistrySystem()->GetHemoglobinContent(MassUnit::g) << MassUnit::g);
pe->GetLogger()->Info(std::stringstream() <<"Blood Volume : " << pe->GetCardiovascularSystem()->GetBloodVolume(VolumeUnit::mL) << VolumeUnit::mL);
pe->GetLogger()->Info(std::stringstream() <<"Mean Arterial Pressure : " << pe->GetCardiovascularSystem()->GetMeanArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Systolic Pressure : " << pe->GetCardiovascularSystem()->GetSystolicArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Diastolic Pressure : " << pe->GetCardiovascularSystem()->GetDiastolicArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Heart Rate : " << pe->GetCardiovascularSystem()->GetHeartRate(FrequencyUnit::Per_min) << "bpm");;

// Patient is stabilizing, but not great

// Let's administer a saline drip, we need to get saline from the substance maganer
SESubstanceCompound* saline = pe->GetSubstanceManager().GetCompound("Saline");
SESubstanceCompoundInfusion iVSaline(*saline);
iVSaline.GetBagVolume().SetValue(500,VolumeUnit::mL);//the total volume in the bag of Saline
iVSaline.GetRate().SetValue(100,VolumePerTimeUnit::mL_Per_min);//The rate to admnister the compound in the bag in this case saline
pe->ProcessAction(iVSaline);

tracker.AdvanceModelTime(400);

pe->GetLogger()->Info("The patient has been getting fluids for the past 400s");
pe->GetLogger()->Info(std::stringstream() <<"Cardiac Output : " << pe->GetCardiovascularSystem()->GetCardiacOutput(VolumePerTimeUnit::mL_Per_min) << VolumePerTimeUnit::mL_Per_min);
pe->GetLogger()->Info(std::stringstream() <<"Hemoglobin Content : " << pe->GetBloodChemistrySystem()->GetHemoglobinContent(MassUnit::g) << MassUnit::g);
pe->GetLogger()->Info(std::stringstream() <<"Blood Volume : " << pe->GetCardiovascularSystem()->GetBloodVolume(VolumeUnit::mL) << VolumeUnit::mL);
pe->GetLogger()->Info(std::stringstream() <<"Mean Arterial Pressure : " << pe->GetCardiovascularSystem()->GetMeanArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Systolic Pressure : " << pe->GetCardiovascularSystem()->GetSystolicArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Diastolic Pressure : " << pe->GetCardiovascularSystem()->GetDiastolicArterialPressure(PressureUnit::mmHg) << PressureUnit::mmHg);
pe->GetLogger()->Info(std::stringstream() <<"Heart Rate : " << pe->GetCardiovascularSystem()->GetHeartRate(FrequencyUnit::Per_min) << "bpm");;
pe->GetLogger()->Info("Finished");

return 0;
if ( strcmp( argv[1], "AirwayObstruction") == 0 )
HowToAirwayObstruction();
else if ( strcmp( argv[1], "AnesthesiaMachine") == 0)
HowToAnesthesiaMachine();
else if ( strcmp( argv[1], "Asthma") == 0)
HowToAsthmaAttack();
else if ( strcmp( argv[1], "BolusDrug") == 0)
HowToBolusDrug();
else if ( strcmp( argv[1], "BrainInjury") == 0)
HowToBrainInjury();
else if ( strcmp( argv[1], "COPD") == 0)
HowToCOPD();
else if ( strcmp( argv[1], "CPR") == 0)
HowToCPR();
else if ( strcmp( argv[1], "LobarPneumonia") == 0)
HowToLobarPneumonia();
else if ( strcmp( argv[1], "PulmonaryFunctionTest") == 0)
HowToPulmonaryFunctionTest();
else if ( strcmp( argv[1], "Smoke") == 0)
HowToSmoke();
else if ( strcmp( argv[1], "TensionPneumothorax") == 0)
HowToTensionPneumothorax();
else if ( strcmp( argv[1], "AnesthesiaMachine") == 0)
HowToAnesthesiaMachine();
else {
std::cout<<"\nUNKNOWN STATE ENTERED \n Try again";
}
}

0 comments on commit 35ea9d9

Please sign in to comment.