Commit 317f0c9e authored by fmg005's avatar fmg005

Refactored towards a self contained clasim

parent 646821e5
......@@ -2,46 +2,57 @@ cmake_minimum_required(VERSION 3.9.4)
project(clasim)
find_path(CONFIG++_INCLUDE_DIR libconfig.h++)
find_library(CONFIG++_LIBRARY NAMES libconfig++.a)
# use dpkg -L libconfig++-dev to find the location of libconfig.h++ and libconfig++.a
find_path(CONFIG++_INCLUDE_DIR libconfig.h++ <libconfig.h++ location>)
find_library(CONFIG++_LIBRARY NAMES libconfig++.a PATH <libconfig++.a location>)
#clasim depends on pulse this will call will give you access to pulse directories
#needed by clasim
find_package(Pulse REQUIRED NO_MODULE)
# set your simulation source directory
set(SIM_SRC_DIR simsrc/mcps2018/algo1)
# Variables to be used in the source files
set(CLASIM_CONFIG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources/)
set(CLASIM_RESULTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/results/)
set(PULSE_STATE_DIR ${Pulse_INSTALL}/bin/states/)
# Create directory at build generation
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/results)
# Generate header file to include variables
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/simsrc/mcps2018/include/configure_clasim_paths.h.in
${CMAKE_CURRENT_SOURCE_DIR}/simsrc/mcps2018/include/configure_clasim_paths.h
)
# set your simulation source directory
set(SIM_SRC_PATH simsrc/mcps2018/algo1)
# *** include your source files
# list each file individually
set(MY_SOURCE_FILES
${SIM_SRC_DIR}/SimEngine.cpp
${SIM_SRC_DIR}/Monitor.cpp
${SIM_SRC_DIR}/Controller.cpp
${SIM_SRC_DIR}/Pump.cpp
${SIM_SRC_DIR}/SimulationLogger.cpp
${SIM_SRC_DIR}/MedicalDevice.cpp
${SIM_SRC_PATH}/SimEngine.cpp
${SIM_SRC_PATH}/Monitor.cpp
${SIM_SRC_PATH}/Controller.cpp
${SIM_SRC_PATH}/Pump.cpp
${SIM_SRC_PATH}/SimulationLogger.cpp
${SIM_SRC_PATH}/MedicalDevice.cpp
)
# set name of application created to run simulation
set(APPNAME clasim)
add_executable(${APPNAME} ${MY_SOURCE_FILES})
#cmd depends on pulse this will call will give you access to pulse directories
#needed by cmd
find_package(Pulse REQUIRED NO_MODULE)
add_executable(clasim ${MY_SOURCE_FILES})
#include directories
target_include_directories(${APPNAME} PRIVATE ${Pulse_INCLUDE_DIRS})
target_include_directories(${APPNAME} PRIVATE ${CONFIG++_INCLUDE_DIR})
target_include_directories(clasim PRIVATE ${Pulse_INCLUDE_DIRS})
target_include_directories(clasim PRIVATE ${CONFIG++_INCLUDE_DIR})
# *** include your simulation include directories here
target_include_directories(${APPNAME} PRIVATE simsrc/mcps2018/include/)
target_include_directories(clasim PRIVATE simsrc/mcps2018/include/)
#libraries
target_link_libraries(${APPNAME} debug "${Pulse_DEBUG_LIBS}")
target_link_libraries(${APPNAME} optimized "${Pulse_LIBS}")
target_link_libraries(${APPNAME} optimized "${CONFIG++_LIBRARY}")
target_link_libraries(clasim debug "${Pulse_DEBUG_LIBS}")
target_link_libraries(clasim optimized "${Pulse_LIBS}")
target_link_libraries(clasim optimized "${CONFIG++_LIBRARY}")
install(TARGETS ${APPNAME} RUNTIME DESTINATION ${Pulse_INSTALL}/bin)
install(TARGETS clasim RUNTIME DESTINATION ${Pulse_INSTALL}/bin)
# Configuration file for Heart Rate Scenario
## rate : Number of samples per second ## MAX: 50.0 Hz ## Type: double
monitor = {
input_rate = 0.02; ## MUST be multiple of 50.0
output_rate = 0.01; ## Must be less than monitor.rate and also multiple of 50.0
};
controller = {
rate = 0.01;
patientData = {
enabled = ["HeartRate", "BloodPressure", "BloodVolume"];
}
algorithm= {
wait_10 = 10.0; # Wait for 10 minutes
wait_5 = 5.0; # Wait for 5 minutes
}
};
pump = {
rate = 1.0; # Intercommand delay -> to be used later
delay = 15.0;
};
simulation = {
patients = {
names = ["Soldier", "Jeff", "Gus"];
}
time = {
run = 3600.0; # Time -> Seconds # How long should simulation run
injury_start = 15.0; # When should injury be introduced to patient
injury_stop = 700.0; # When should injury be stopped
}
path = "results"; # folder to store out sim output files -> to be used later
};
......@@ -52,70 +52,63 @@ using namespace libconfig;
int main(int argc, char * argv[]){
if(argc < 2)
{
cout << "Error: must provide a configuration file\n";
cout << "Usage: ./clasim configfile\n";
}
else
{
string f_path = argv[1];
const char* filepath = f_path.c_str();
clock_t t1, t2, sim_run_time;
vector<string> patients_list;
auto cf = std::make_shared<Config>();
float sim_time_secs, sim_time_mins;
string f_path = argv[1];
const char* filepath = f_path.c_str();
try
{
cf->readFile(filepath);
}
catch(const FileIOException &fioex) {
std::cerr << "I/O error while reading file: " << filepath << std::endl;
//return(EXIT_FAILURE);
}
clock_t t1, t2, sim_run_time;
vector<string> patients_list;
auto cf = std::make_shared<Config>();
float sim_time_secs, sim_time_mins;
string f_path = clasim_config_dir+"scenario.cfg";
const char* filepath = f_path.c_str();
catch(const ParseException &pex) {
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
<< " - " << pex.getError() << std::endl;
//return(EXIT_FAILURE);
}
try
{
cf->readFile(filepath);
}
patients_list = get_global_patients(cf);
catch(const FileIOException &fioex) {
std::cerr << "I/O error while reading file: " << filepath << std::endl;
//return(EXIT_FAILURE);
}
for(auto patient: patients_list) {
// start timer
t1 = clock();
catch(const ParseException &pex) {
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
<< " - " << pex.getError() << std::endl;
//return(EXIT_FAILURE);
}
//Simulation input : Name of patient
Simulation(patient, cf);
patients_list = get_global_patients(cf);
//stop timer
t2 = clock();
for(auto patient: patients_list) {
// start timer
t1 = clock();
//Simulation input : Name of patient
Simulation(patient, cf);
//stop timer
t2 = clock();
sim_run_time = t2 - t1;
sim_time_secs = ((float)sim_run_time)/CLOCKS_PER_SEC;
sim_time_mins = sim_time_secs/60.0;
cout << "\nThe Simulation for " << patient;
cout << " took "<< sim_time_secs <<" seconds ";
cout <<"or " << sim_time_mins <<" minutes"<<endl;
}
sim_run_time = t2 - t1;
sim_time_secs = ((float)sim_run_time)/CLOCKS_PER_SEC;
sim_time_mins = sim_time_secs/60.0;
cout << "\nThe Simulation for " << patient;
cout << " took "<< sim_time_secs <<" seconds ";
cout <<"or " << sim_time_mins <<" minutes"<<endl;
}
}
}
void Simulation(const string patient_name, const std::shared_ptr<Config>& cf)
{
// Create the engine and load the patient
std::unique_ptr<PhysiologyEngine> pe = CreatePulseEngine("SimulationEngine_"+patient_name+".log");
std::unique_ptr<PhysiologyEngine> pe =
CreatePulseEngine(clasim_results_dir+"SimulationEngine_"+patient_name+".log");
pe->GetLogger()->Info("CMD Simulation");
//if (!pe->LoadStateFile("./states/StandardMale@0s.pba"))
if (!pe->LoadStateFile("./states/"+patient_name+"@0s.pba"))
if (!pe->LoadStateFile(pulse_state_dir+patient_name+"@0s.pba"))
{
pe->GetLogger()->Error("Could not load state, check the error");
return;
......@@ -128,7 +121,7 @@ void Simulation(const string patient_name, const std::shared_ptr<Config>& cf)
pe->GetEngineTracker()->GetDataRequestManager().CreatePhysiologyDataRequest("HeartRate", FrequencyUnit::Per_min);
pe->GetEngineTracker()->GetDataRequestManager().CreatePhysiologyDataRequest("BloodVolume", VolumeUnit::mL);
pe->GetEngineTracker()->GetDataRequestManager().CreatePhysiologyDataRequest("MeanArterialPressure", PressureUnit::mmHg);
pe->GetEngineTracker()->GetDataRequestManager().SetResultsFilename("PulseSimEngine_"+patient_name+".txt");
pe->GetEngineTracker()->GetDataRequestManager().SetResultsFilename(clasim_results_dir+"PulseSimEngine_"+patient_name+".txt");
//instatiate Hemorrhage Action
SEHemorrhage hemorrhageLeg;
......@@ -168,7 +161,8 @@ void Simulation(const string patient_name, const std::shared_ptr<Config>& cf)
//logger
sim_env.logger = std::make_shared<SimulationLogger>("SimulationEngineLog_"+patient_name+".txt");
sim_env.logger =
std::make_shared<SimulationLogger>(clasim_results_dir+"SimulationEngineLog_"+patient_name+".txt");
bool STOP = false; // Execute stop hemmorrhage only once; without this it be executed for each timestep
bool DEVICES_START = false;
......
#ifndef SIMENGINE_H
#define SIMENGINE_H
#include<string>
#include <string>
#include "configure_clasim_paths.h"
void Simulation(const std::string, const std::shared_ptr<Config>& cf);
......
#ifndef CONFIGURE_SIM_PATHS_H
#define CONFIGURE_SIM_PATHS_H
#include <string>
#include <stdio.h>
// @variable@ from cmake file to be substituted with actual values
// after generation
const std::string clasim_config_dir = "@CLASIM_CONFIG_DIR@";
const std::string pulse_state_dir = "@PULSE_STATE_DIR@";
const std::string clasim_results_dir = "@CLASIM_RESULTS_DIR@";
#endif
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