SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sydevs::systems::simulation< Node > Class Template Reference

A class template for running simulations. More...

#include <simulation.h>

Inherited by sydevs::systems::real_time_simulation< Node >.

Public Member Functions

 simulation (const time_point &start_t, const time_point &end_t, bool can_end_early, int64 seed, std::ostream &stream)
 Constructs a simulation with the full set of configuration options. More...
 
 simulation (duration total_dt, int64 seed, std::ostream &stream)
 Constructs a simulation with a reduced set of configuration options. More...
 
 simulation (const simulation &)=delete
 No copy constructor. More...
 
simulationoperator= (const simulation &)=delete
 No copy assignment. More...
 
 simulation (simulation &&)=delete
 No move constructor. More...
 
simulationoperator= (simulation &&)=delete
 No move assignment. More...
 
virtual ~simulation ()=default
 Destructor. More...
 
const time_pointstart_time () const
 Returns the start time of the simulation. More...
 
const time_pointend_time () const
 Returns the end time of the simulation. More...
 
bool can_end_early () const
 Returns true if the simulation can end before the specified end time. More...
 
bool started () const
 Returns true if the simulation has started. More...
 
bool finishing () const
 Returns true if all events are finished except finalization. More...
 
bool finished () const
 Returns true if the simulation has finished. More...
 
const discrete_event_timetime () const
 Returns the current point in discrete event time. More...
 
duration imminent_duration () const
 Returns the duration until the imminent event. More...
 
void process_next_event ()
 Runs the next event of the topmost system node. More...
 
int64 process_next_events ()
 Runs all events until simulated time advances; returns the number of processed events. More...
 
int64 process_events_until (const time_point &t)
 Runs all events until simulated time advances at least to t; returns the number of processed events. More...
 
int64 process_remaining_events ()
 Runs simulation until completion; returns the number of processed events. More...
 
const timerevent_timer () const
 Returns the object that accumulated wallclock event durations. More...
 

Public Attributes

Node top
 The topmost system node. More...
 

Detailed Description

template<typename Node>
class sydevs::systems::simulation< Node >

A class template for running simulations.

The simulation class template represents a simulation run based on a system_node class specified as a template parameter. Member functions allow the represented simulation to be performed one event at a time or until completion.

Below is an example of how a simulation object can be instantiated and used.

try {
// Create an object to simulate a building for 5 minutes of simulated
// time with a random seed of 0 and printed results directed to std::cout.
simulation<building_closed_system> sim(5_min, 0, std::cout);
// Print the initial temperature.
sim.top.initial_temperature.parameter.print_on_use();
// Print every outdoor temperature send from the weather node.
sim.top.building_dynamics.weather.outdoor_temperature_output.print_on_use();
// Print every outdoor temperature received by the thermodynamics node.
sim.top.building_dynamics.thermodynamics.outdoor_temperature_input.print_on_use();
// Print every event experienced by the occupant node.
sim.top.building_dynamics.occupant.print_on_event();
// Run the simulation until completion.
sim.process_remaining_events();
}
catch (const system_node::error& e) {
std::cout << "SYSTEM NODE ERROR: " << e.what() << std::endl;
}
catch (const std::exception& e) {
std::cout << "OTHER ERROR: " << e.what() << std::endl;
}

It is also possible to obtain wallclock times at each level in a model hierarchy, the cumulative time that the computer has spent executing events.

// [...]
// Run the simulation until completion.
sim.process_remaining_events();
// Obtain and print cumulative wallclock time of all nodes.
auto sim_dt = sim.event_timer().cumulative_duration();
std::cout << "sim: " << sim_dt << std::endl;
// Obtain and print cumulative wallclock time of all event functions in single node.
auto node_dt = sim.top.building_dynamics.thermodynamics.event_timer().cumulative_duration();
std::cout << "sim.top.building_dynamics.thermodynamics: " << node_dt << std::endl;

Constructor & Destructor Documentation

template<typename Node >
sydevs::systems::simulation< Node >::simulation ( const time_point start_t,
const time_point end_t,
bool  can_end_early,
int64  seed,
std::ostream &  stream 
)
inline

Constructs a simulation with the full set of configuration options.

Parameters
start_tThe starting point in simulated time.
end_tThe end point in simulated time; only finalization events can occur at this time.
can_end_earlyFlag indicating that the simulation will end before the specified end time if all events are exhausted.
seedThe integer used to seed the random number generator.
streamThe output steam onto which printed results are directed.
Template Parameters
NodeThe port-free system_node on which the simulation is based.
template<typename Node >
sydevs::systems::simulation< Node >::simulation ( duration  total_dt,
int64  seed,
std::ostream &  stream 
)
inline

Constructs a simulation with a reduced set of configuration options.

Parameters
total_dtThe duration of the simulation in simulated time; the simulation starts at time zero and does not end early.
seedThe integer used to seed the random number generator.
streamThe output steam onto which printed results are directed.
Template Parameters
NodeThe port-free system_node on which the simulation is based.
template<typename Node >
sydevs::systems::simulation< Node >::simulation ( const simulation< Node > &  )
delete

No copy constructor.

template<typename Node >
sydevs::systems::simulation< Node >::simulation ( simulation< Node > &&  )
delete

No move constructor.

template<typename Node >
virtual sydevs::systems::simulation< Node >::~simulation ( )
virtualdefault

Destructor.

Member Function Documentation

template<typename Node >
bool sydevs::systems::simulation< Node >::can_end_early ( ) const
inline

Returns true if the simulation can end before the specified end time.

template<typename Node >
const time_point & sydevs::systems::simulation< Node >::end_time ( ) const
inline

Returns the end time of the simulation.

template<typename Node >
const timer & sydevs::systems::simulation< Node >::event_timer ( ) const
inline

Returns the object that accumulated wallclock event durations.

template<typename Node >
bool sydevs::systems::simulation< Node >::finished ( ) const
inline

Returns true if the simulation has finished.

template<typename Node >
bool sydevs::systems::simulation< Node >::finishing ( ) const
inline

Returns true if all events are finished except finalization.

template<typename Node >
duration sydevs::systems::simulation< Node >::imminent_duration ( ) const
inline

Returns the duration until the imminent event.

template<typename Node >
simulation& sydevs::systems::simulation< Node >::operator= ( const simulation< Node > &  )
delete

No copy assignment.

template<typename Node >
simulation& sydevs::systems::simulation< Node >::operator= ( simulation< Node > &&  )
delete

No move assignment.

template<typename Node >
int64 sydevs::systems::simulation< Node >::process_events_until ( const time_point t)
inline

Runs all events until simulated time advances at least to t; returns the number of processed events.

template<typename Node >
void sydevs::systems::simulation< Node >::process_next_event ( )
inline

Runs the next event of the topmost system node.

template<typename Node >
int64 sydevs::systems::simulation< Node >::process_next_events ( )
inline

Runs all events until simulated time advances; returns the number of processed events.

template<typename Node >
int64 sydevs::systems::simulation< Node >::process_remaining_events ( )
inline

Runs simulation until completion; returns the number of processed events.

template<typename Node >
const time_point & sydevs::systems::simulation< Node >::start_time ( ) const
inline

Returns the start time of the simulation.

template<typename Node >
bool sydevs::systems::simulation< Node >::started ( ) const
inline

Returns true if the simulation has started.

template<typename Node >
const discrete_event_time & sydevs::systems::simulation< Node >::time ( ) const
inline

Returns the current point in discrete event time.

Member Data Documentation

template<typename Node >
Node sydevs::systems::simulation< Node >::top

The topmost system node.


The documentation for this class was generated from the following file: