Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cla_prosim_driver
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fmg005
cla_prosim_driver
Commits
5c25f4bf
Commit
5c25f4bf
authored
May 03, 2018
by
fmg005
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reimplemented realtime method :)
parent
1fdc5324
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
38 deletions
+40
-38
Realtime.cpp
Realtime.cpp
+24
-17
SimulationEngine.cpp
SimulationEngine.cpp
+4
-8
include/Realtime.h
include/Realtime.h
+10
-6
resources/scenario.cfg
resources/scenario.cfg
+2
-7
No files found.
Realtime.cpp
View file @
5c25f4bf
...
...
@@ -4,28 +4,35 @@ using namespace CLA;
Realtime
::
Realtime
(
std
::
unique_ptr
<
PhysiologyEngine
>&
engine
,
CLA
::
LOGGER
*
logger
)
:
m_engine
(
engine
),
m_logger
(
logger
)
{
m_cycles
=
0
;
}
void
Realtime
::
AdvanceModelTime
(
double
time
)
{
m_cycles
=
static_cast
<
uint
>
(
time
*
N
);
/*
synchronize simulation time to real clock
i.e., 1s of Simulation = 1s of real-time
*/
m_start
=
clock
();
m_engine
->
AdvanceModelTime
(
1.0
,
TimeUnit
::
s
);
m_end
=
clock
();
for
(
int
i
=
0
;
i
<
m_cycles
;
i
++
)
{
m_engine
->
AdvanceModelTime
(
time
,
TimeUnit
::
s
);
}
}
/* start time for the next execution */
m_real_time
=
m_start
+
(
m_next_start
*
time
);
void
Realtime
::
LoadConfig
(
const
char
*
file_path
)
{
try
{
m_cfg
.
readFile
(
file_path
);
// Read configration file
}
catch
(
const
FileIOException
&
fioex
)
{
m_logger
->
error
(
"I/O error while reading file."
);
}
catch
(
const
ParseException
&
pex
)
{
m_logger
->
error
(
"Error parsing configuration file."
);
}
N
=
m_cfg
.
lookup
(
"realtime.time_steps"
);
/* check if simuation takes longer than expected */
if
((
m_end
-
m_start
)
>
m_real_time
)
m_logger
->
error
(
"Simulation too slow"
);
/* wait until start time of next execution is reached i.e., 1s of real-time */
while
(
true
)
{
m_delta
=
m_real_time
-
clock
();
if
(
m_delta
<=
0
)
break
;
m_delta_secs
=
long
(((
double
)
m_delta
)
/
CLOCKS_PER_SEC
);
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
m_delta_secs
));
}
/* track data */
m_engine
->
GetEngineTracker
()
->
TrackData
(
m_engine
->
GetSimulationTime
(
TimeUnit
::
s
));
}
Realtime
::~
Realtime
()
{
...
...
SimulationEngine.cpp
View file @
5c25f4bf
...
...
@@ -62,7 +62,7 @@ void Simulation(const string patient_name, const std::shared_ptr<Config>& cfg, c
pe
->
GetEngineTracker
()
->
GetDataRequestManager
().
SetResultsFilename
(
prosim_results_dir
+
"PulseSimEngine_"
+
patient_name
+
".txt"
);
SEHemorrhage
hemorrhageLeg
;
double
initialMAP
=
7
5
.0
;
double
initialMAP
=
7
6
.0
;
double
currentMAP
;
CLA
::
Environment
sim_env
;
Global_LoadConfig
(
pe
,
cfg
,
filepath
,
&
sim_env
);
...
...
@@ -82,14 +82,12 @@ void Simulation(const string patient_name, const std::shared_ptr<Config>& cfg, c
HardwareSimulator
prosim
(
&
myserial
,
&
logger
,
&
sim_env
);
prosim
.
LoadConfig
(
filepath
);
CLA
::
Realtime
rt
(
pe
,
&
logger
);
rt
.
LoadConfig
(
filepath
);
bool
STOP
=
false
;
// Execute stop hemmorrhage only once; without this it be executed for each timestep
bool
DEVICES_START
=
false
;
prosim
.
SetRemoteMode
(
);
CLA
::
Realtime
rt
(
pe
,
&
logger
);
prosim
.
SetRemoteMode
();
// stop when the set time is reached
while
(
sim_env
.
time_index
<=
sim_env
.
simulation_timesteps
)
{
// event_hemorrage_start
...
...
@@ -122,10 +120,8 @@ void Simulation(const string patient_name, const std::shared_ptr<Config>& cfg, c
// track patient data
//pe->GetEngineTracker()->TrackData(pe->GetSimulationTime(TimeUnit::s));
//pe->AdvanceModelTime();
rt
.
AdvanceModelTime
(
1.0
);
rt
.
AdvanceModelTime
(
1.0
);
//Advance Engine at 1s in real time
sim_env
.
time_index
++
;
pe
->
GetEngineTracker
()
->
TrackData
((
double
)
sim_env
.
time_index
);
}
// End while looop
}
// End Simulation function
...
...
include/Realtime.h
View file @
5c25f4bf
#ifndef REALTIME_H
#define REALTIME_H
#ifndef REALTIME
2
_H
#define REALTIME
2
_H
#include <time.h>
#include <string>
#include <chrono>
#include <thread>
#include <libconfig.h++>
#include "CLA_Logger.h"
#include "PulsePhysiologyEngine.h"
...
...
@@ -10,21 +13,22 @@
#include "properties/SEScalarTime.h"
using
namespace
libconfig
;
using
namespace
std
;
namespace
CLA
{
class
Realtime
{
private:
double
N
;
//system clock: 1s->600 sim time steps or 12 sim secs
std
::
unique_ptr
<
PhysiologyEngine
>&
m_engine
;
uint
m_cycles
;
Config
m_cfg
;
CLA
::
LOGGER
*
m_logger
;
Config
m_cfg
;
clock_t
m_real_time
,
real_start
,
m_delta
,
m_start
,
m_end
;
clock_t
m_next_start
=
CLOCKS_PER_SEC
;
long
m_delta_secs
;
public:
Realtime
(
std
::
unique_ptr
<
PhysiologyEngine
>&
,
CLA
::
LOGGER
*
);
~
Realtime
();
void
AdvanceModelTime
(
double
);
void
LoadConfig
(
const
char
*
);
};
}
...
...
resources/scenario.cfg
View file @
5c25f4bf
# Configuration file
prosim = {
delay_5_sec = 5.0; # Prosim delay-->arbitrary value
}
realtime = {
time_steps = 12.0; # How many simulation seconds result into 1s of real time
}
simulation = {
time = {
run =
12
0.0; # Time -> Seconds # How long should simulation run
run =
6
0.0; # Time -> Seconds # How long should simulation run
injury_start = 5.0; # When should injury be introduced to patient
injury_stop = 700.0; # When should injury be stopped
}
}
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment