|
template<class ParentModel , class... WriterArgs> |
| Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< Derived > &w_deciders=DataIO::Default::default_deciders< Derived >, const DataIO::Default::DefaultTriggermap< Derived > &w_triggers=DataIO::Default::default_triggers< Derived >) |
| Constructs a Model instance. More...
|
|
const std::shared_ptr< Space > & | get_space () const |
| Return the space this model resides in. More...
|
|
Time | get_time () const |
| Return the current time of this model. More...
|
|
Time | get_time_max () const |
| Return the maximum time possible for this model. More...
|
|
Config | get_cfg () const |
| Return the config node of this model. More...
|
|
std::string | get_name () const |
| Return the name of this model instance. More...
|
|
std::string | get_full_name () const |
| Return the full name of this model within the model hierarchy. More...
|
|
std::shared_ptr< DataGroup > | get_hdfgrp () const |
| Return a pointer to the HDF group this model stores data in. More...
|
|
Time | get_write_start () const |
| Return the parameter that controls when write_data is called first. More...
|
|
Time | get_write_every () const |
| Return the parameter that controls how often write_data is called. More...
|
|
DataManager | get_datamanager () const |
| return the datamanager More...
|
|
hsize_t | get_remaining_num_writes () const |
| Return the number of remaining write_data calls this model will make. More...
|
|
std::shared_ptr< RNG > | get_rng () const |
| Return a pointer to the shared RNG. More...
|
|
std::shared_ptr< spdlog::logger > | get_logger () const |
| Return a pointer to the logger of this model. More...
|
|
Monitor | get_monitor () const |
| Return the monitor of this model. More...
|
|
std::shared_ptr< MonitorManager > | get_monitor_manager () const |
| Get the monitor manager of the root model. More...
|
|
Level | get_level () const |
| Return the hierarchical level within the model hierarchy. More...
|
|
virtual void | prolog () |
| A function that is called before starting model iteration. More...
|
|
virtual void | epilog () |
| A function that is called after the last iteration of a model. More...
|
|
void | iterate () |
| Iterate one (time) step of this model. More...
|
|
void | run () |
| Run the model from the current time to the maximum time. More...
|
|
std::shared_ptr< DataSet > | create_dset (const std::string name, const std::shared_ptr< DataGroup > &hdfgrp, std::vector< hsize_t > add_write_shape, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
| Create a new dataset within the given group. More...
|
|
std::shared_ptr< DataSet > | create_dset (const std::string name, const std::vector< hsize_t > add_write_shape, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
| Create a new dataset within the model's base data group. More...
|
|
template<class CellManager > |
std::shared_ptr< DataSet > | create_cm_dset (const std::string name, const CellManager &cm, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
| Create a dataset storing data from a CellManager. More...
|
|
template<class AgentManager > |
std::shared_ptr< DataSet > | create_am_dset (const std::string name, const AgentManager &am, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
| Create a dataset storing data from a AgentManager. More...
|
|
template<class Derived, typename ModelTypes>
class Utopia::Model< Derived, ModelTypes >
Base class interface for Models using the CRT Pattern.
- Template Parameters
-
Derived | Type of the derived model class |
ModelTypes | Traits of this model, can be used for specializing |
template<class Derived , typename ModelTypes >
Attaches signal handlers: SIGINT, SIGTERM, SIGUSR1.
These signals are caught and handled such that the run method is able to finish in an ordered manner, preventing data corruption. This is done by invoking attach_signal_handler and attaching the default_signal_handler to them.
The SIGUSR1 signal is sent by the frontend if the stop conditions for this simulation are all fulfilled. It will likewise lead to the invocation of the default_signal_handler.
template<class Derived , typename ModelTypes >
template<class AgentManager >
std::shared_ptr<DataSet> Utopia::Model< Derived, ModelTypes >::create_am_dset |
( |
const std::string |
name, |
|
|
const AgentManager & |
am, |
|
|
const std::size_t |
compression_level = 1 , |
|
|
const std::vector< hsize_t > |
chunksize = {} |
|
) |
| |
|
inline |
Create a dataset storing data from a AgentManager.
The required capacity - the shape of the dataset - is calculated using both data from the model and the AgentManager. Additionally, dimension and coordinate labels are added.
Agents are also labelled with a (trivial) ID, starting from zero.
- Note
- For the time dimension, the coordinates assume that data is written the first time at time 0 and then every _write_every. Time coordinates will be wrong if the model does not write the data this way. For such cases, it is advised to suppress writing of attributes by setting the config entry
write_dim_labels_and_coords
entry to false.
- Warning
- The number of agents present at the time this method is called determine the dataset's capacity. If the agent number increases beyond that point during the runtime of the simulation, data writing will fail because the datasets capacity will be too small!
- Parameters
-
name | The name of the dataset |
am | The AgentManager whose agents' states are to be stored in the dataset |
compression_level | The compression level |
chunksize | The chunk size |
- Returns
- std::shared_ptr<DataSet> The newly created HDFDataset
template<class Derived , typename ModelTypes >
template<class CellManager >
std::shared_ptr<DataSet> Utopia::Model< Derived, ModelTypes >::create_cm_dset |
( |
const std::string |
name, |
|
|
const CellManager & |
cm, |
|
|
const std::size_t |
compression_level = 1 , |
|
|
const std::vector< hsize_t > |
chunksize = {} |
|
) |
| |
|
inline |
Create a dataset storing data from a CellManager.
The required capacity - the shape of the dataset - is calculated using both data from the model and the CellManager. Additionally, dimension and coordinate labels are added.
- Note
- For the time dimension, the coordinates assume that data is written the first time at time 0 and then every _write_every. Time coordinates will be wrong if the model does not write the data this way. For such cases, it is advised to suppress writing of attributes by setting the _cfg['write_dim_labels_and_coords'] entry to false.
- Parameters
-
name | The name of the dataset |
cm | The CellManager whose cells' states are to be stored in the dataset |
compression_level | The compression level |
chunksize | The chunk size |
- Returns
- std::shared_ptr<DataSet> The newly created HDFDataset
template<class Derived , typename ModelTypes >
std::shared_ptr<DataSet> Utopia::Model< Derived, ModelTypes >::create_dset |
( |
const std::string |
name, |
|
|
const std::vector< hsize_t > |
add_write_shape, |
|
|
const std::size_t |
compression_level = 1 , |
|
|
const std::vector< hsize_t > |
chunksize = {} |
|
) |
| |
|
inline |
Create a new dataset within the model's base data group.
The capacity - the shape of the dataset - is calculated automatically from the num_steps and write_every parameter. Additionally, dataset attributes are set that carry information on dimension labels and coordinates.
- Note
- The attributes are only written for the
time
dimension, as that is the only one that is known in this method. Furthermore, this assumes that it writes at write_every
and - importantly - has the first write operation at time zero. Coordinates will be wrong if that is not the case! For such cases, it is advised to suppress writing of these attributes by setting the configuration entry _cfg['write_dim_labels_and_coords'] to false.
- Parameters
-
name | The name of the dataset |
add_write_shape | Additional write shape which, together with the number of time steps, is used to calculate the capacity of the dataset: (capacity = (num_time_steps, add_write_shape)). |
compression_level | The compression level |
chunksize | The chunk size |
- Returns
- std::shared_ptr<DataSet> The hdf dataset
template<class Derived , typename ModelTypes >
Return the number of remaining write_data
calls this model will make.
The 'remaining' refers to the current time being included into the calculation, e.g.: when writing every time, currently at time == 42 and time_max == 43, it will return the value 2, i.e. for the write operations at times 42 and 43
template<class Derived , typename ModelTypes >
Iterate one (time) step of this model.
Increment time, perform step, emit monitor data, and write data. Monitoring is performed differently depending on the model level. The write_data method is called depending on the configured value for the write_mode
(template parameter) and (if in mode basic
): the configuration parameters write_start
and write_every
.
template<class Derived , typename ModelTypes >
Run the model from the current time to the maximum time.
This repeatedly calls the iterate method until the maximum time is reached. Additionally, it calls the __write_data
method to allow it to write the initial state. In write mode basic
, this is only done if _write_start == _time
.