SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
real_time_buffer.h
Go to the documentation of this file.
1 #pragma once
2 #ifndef SYDEVS_SYSTEMS_REAL_TIME_BUFFER_H_
3 #define SYDEVS_SYSTEMS_REAL_TIME_BUFFER_H_
4 
5 #include <sydevs/core/timer.h>
7 #include <array>
8 
9 namespace sydevs {
10 namespace systems {
11 
12 
41 {
42 public:
43  real_time_buffer(float64 t_adv_rate, int64 t_syn_rate);
44 
47 
48  void update_time_advancement_rate(float64 t_adv_rate);
49  void update_time_synchronization_rate(float64 t_syn_rate);
50 
53 
54  void update_synchronization_time(const time_point& sim_t, const clock_time& clk_t);
55 
56  time_point current_time() const;
58 
59  void update_current_time(const time_point& sim_t, const clock_time& clk_t, duration planned_sim_dt);
60 
62 
63 private:
64  void recompute_planned_clock_duration();
65 
66  float64 t_adv_rate_; // time advancement rate
67  float64 t_syn_rate_; // time synchronization rate
68  time_point syn_sim_t_; // synchronization simulated time
69  clock_time syn_clk_t_; // synchronization clock time
70  time_point current_sim_t_; // current simulated time
71  clock_time current_clk_t_; // current clock time
72  duration planned_sim_dt_; // planned simulated time duration
73  float64 planned_clk_dt_; // planned simulated time duration
74  int64 syn_count_; // synchronization step count
75 };
76 
77 
79 {
80  return t_adv_rate_;
81 }
82 
83 
85 {
86  return t_syn_rate_;
87 }
88 
89 
91 {
92  return syn_sim_t_;
93 }
94 
95 
97 {
98  return syn_clk_t_;
99 }
100 
101 
103 {
104  return current_sim_t_;
105 }
106 
107 
109 {
110  return current_clk_t_;
111 }
112 
113 
115 {
116  return current_clk_t_ + std::chrono::milliseconds(int64(planned_clk_dt_));
117 }
118 
119 
120 } // namespace
121 } // namespace
122 
123 #endif
time_point current_time() const
Returns the current simulated time.
Definition: real_time_buffer.h:102
clock_time planned_clock_time() const
Returns the recommended point in wallclock time of the planned event.
Definition: real_time_buffer.h:114
void update_current_time(const time_point &sim_t, const clock_time &clk_t, duration planned_sim_dt)
Updates the current time and the planned duration of simulated time until the planned event...
Definition: real_time_buffer.cpp:47
clock_time current_clock_time() const
Returns the current wallclock time.
Definition: real_time_buffer.h:108
A data structure which suggests event wallclock times to aid in the synchronization of a simulation's...
Definition: real_time_buffer.h:40
void update_synchronization_time(const time_point &sim_t, const clock_time &clk_t)
Updates the synchonization reference point and recomputes the planned wallclock time.
Definition: real_time_buffer.cpp:38
void update_time_advancement_rate(float64 t_adv_rate)
Updates the time advancement rate and recomputes the planned wallclock time.
Definition: real_time_buffer.cpp:22
clock_time synchronization_clock_time() const
Returns the wallclock time of the synchronization reference point.
Definition: real_time_buffer.h:96
float64 time_synchronization_rate() const
Returns the time synchronization rate.
Definition: real_time_buffer.h:84
real_time_buffer(float64 t_adv_rate, int64 t_syn_rate)
Constructs a real time buffer with the specified time advancement rate t_adv_rate and time synchroniz...
Definition: real_time_buffer.cpp:7
void update_time_synchronization_rate(float64 t_syn_rate)
Updates the time synchonization rate and recomputes the planned wallclock time.
Definition: real_time_buffer.cpp:30
A data structure which represents a point in time as an arbitrary-precision multiple of its shortest ...
Definition: time_point.h:84
std::chrono::time_point< clock > clock_time
Definition: timer.h:11
int64_t int64
Definition: number_types.h:14
time_point synchronization_time() const
Returns the simulated time of the synchronization reference point.
Definition: real_time_buffer.h:90
double float64
Definition: number_types.h:22
float64 time_advancement_rate() const
Returns the time advancement rate.
Definition: real_time_buffer.h:78