Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
Utopia::Models::Dummy::Dummy Class Reference

Dummy model with simple update rule. More...

#include <dummy.hh>

Inheritance diagram for Utopia::Models::Dummy::Dummy:
Inheritance graph
[legend]
Collaboration diagram for Utopia::Models::Dummy::Dummy:
Collaboration graph
[legend]

Public Types

using Base = Model< Dummy, DummyTypes >
 The base model class.
 
using Data = std::vector< double >
 The data type to use for _state and _bc members.
 
using DataSet = Base::DataSet
 
- Public Types inherited from Utopia::Model< Dummy, DummyTypes >
using Config = typename ModelTypes::Config
 Data type that holds the configuration.
 
using DataManager = DataIO::Default::DefaultDataManager< Dummy >
 The data manager to use, specialized with the derived model.
 
using DataGroup = typename ModelTypes::DataGroup
 Data type that is used for storing datasets.
 
using DataSet = typename ModelTypes::DataSet
 Data type that is used for storing data.
 
using RNG = typename ModelTypes::RNG
 Data type of the shared RNG.
 
using Space = typename ModelTypes::Space
 Data type of the space this model resides in.
 
using Time = typename ModelTypes::Time
 Data type for the model time.
 
using Monitor = typename ModelTypes::Monitor
 Data type for the monitor.
 
using MonitorManager = typename ModelTypes::MonitorManager
 Data type for the monitor manager.
 
using Level = typename ModelTypes::Level
 Data type for the hierarchical level.
 

Public Member Functions

template<class ParentModel >
 Dummy (const std::string &name, const ParentModel &parent_model, const Data &initial_state, const DataIO::Config &custom_cfg={})
 Construct the dummy model with an initial state.
 
void perform_step ()
 Iterate by one time step.
 
void monitor ()
 Monitor model information.
 
void write_data ()
 Write data into a dataset that corresponds to the current step.
 
- Public Member Functions inherited from Utopia::Model< Dummy, DummyTypes >
 Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< Dummy > &w_deciders=DataIO::Default::default_deciders< Dummy >, const DataIO::Default::DefaultTriggermap< Dummy > &w_triggers=DataIO::Default::default_triggers< Dummy >)
 Constructs a Model instance.
 
const std::shared_ptr< Space > & get_space () const
 Return the space this model resides in.
 
Time get_time () const
 Return the current time of this model.
 
Time get_time_max () const
 Return the maximum time possible for this model.
 
Config get_cfg () const
 Return the config node of this model.
 
std::string get_name () const
 Return the name of this model instance.
 
std::string get_full_name () const
 Return the full name of this model within the model hierarchy.
 
std::shared_ptr< DataGroupget_hdfgrp () const
 Return a pointer to the HDF group this model stores data in.
 
Time get_write_start () const
 Return the parameter that controls when write_data is called first.
 
Time get_write_every () const
 Return the parameter that controls how often write_data is called.
 
DataManager get_datamanager () const
 return the datamanager
 
hsize_t get_remaining_num_writes () const
 Return the number of remaining write_data calls this model will make.
 
std::shared_ptr< RNGget_rng () const
 Return a pointer to the shared RNG.
 
std::shared_ptr< spdlog::logger > get_logger () const
 Return a pointer to the logger of this model.
 
Monitor get_monitor () const
 Return the monitor of this model.
 
std::shared_ptr< MonitorManagerget_monitor_manager () const
 Get the monitor manager of the root model.
 
Level get_level () const
 Return the hierarchical level within the model hierarchy.
 
virtual void prolog ()
 A function that is called before starting model iteration.
 
virtual void epilog ()
 A function that is called after the last iteration of a model.
 
void iterate ()
 Iterate one (time) step of this model.
 
void run ()
 Run the model from the current time to the maximum time.
 
std::shared_ptr< DataSetcreate_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.
 
std::shared_ptr< DataSetcreate_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.
 
std::shared_ptr< DataSetcreate_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.
 
std::shared_ptr< DataSetcreate_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.
 

Private Attributes

Data _state
 The current state of the model.
 
Data _bc
 The boundary conditions of the model.
 
std::shared_ptr< DataSet_dset_state
 Dataset to write the state to.
 

Additional Inherited Members

- Protected Member Functions inherited from Utopia::Model< Dummy, DummyTypes >
void __perform_step ()
 Perform the computation of a step.
 
void __monitor ()
 Monitor information in the terminal.
 
void __write_data ()
 Write data; calls the implementation's write_data method.
 
void __write_initial_state ()
 Write the initial state.
 
void increment_time (const Time dt=1)
 Increment time.
 
void __prolog ()
 The default prolog of a model.
 
void __epilog ()
 The default epilog of a model.
 
Dummy & impl ()
 cast to the derived class
 
const Dummy & impl () const
 const cast to the derived interface
 
- Protected Attributes inherited from Utopia::Model< Dummy, DummyTypes >
const std::string _name
 Name of the model instance.
 
const std::string _full_name
 The full name within the model hierarchy.
 
const Level _level
 The level within the model hierarchy.
 
const Config _cfg
 Config node belonging to this model instance.
 
const std::shared_ptr< RNG_rng
 The RNG shared between models.
 
const std::shared_ptr< spdlog::logger > _log
 The (model) logger.
 
std::shared_ptr< Space_space
 The space this model resides in.
 
Time _time
 Model-internal current time stamp.
 
const Time _time_max
 Model-internal maximum time stamp.
 
const std::shared_ptr< DataGroup_hdfgrp
 The HDF group this model instance should write its data to.
 
const Time _write_start
 First time at which write_data is called.
 
const Time _write_every
 How often to call write_data from iterate.
 
Monitor _monitor
 The monitor.
 
DataManager _datamanager
 Manager object for handling data output; see DataManager.
 
- Static Protected Attributes inherited from Utopia::Model< Dummy, DummyTypes >
static constexpr WriteMode _write_mode
 Which data-writing mode the base model should use.
 

Detailed Description

Dummy model with simple update rule.

Holds a vector of doubles and increments its entries by random numbers with the bounds determined by the boundary condition vector.

Member Typedef Documentation

◆ Base

The base model class.

◆ Data

The data type to use for _state and _bc members.

◆ DataSet

Constructor & Destructor Documentation

◆ Dummy()

template<class ParentModel >
Utopia::Models::Dummy::Dummy::Dummy ( const std::string &  name,
const ParentModel parent_model,
const Data initial_state,
const DataIO::Config custom_cfg = {} 
)
inline

Construct the dummy model with an initial state.

Parameters
nameName of this model instance
parent_modelThe parent model instance this instance resides in
initial_stateInitial state of the model
custom_cfgA custom configuration to use instead of the one extracted from the parent model using the instance name
54 {}
55 )
56 :
57 // Use the base constructor for the main parts
59
60 // Initialise state and boundary condition members
62 _bc(_state.size(), 1.0),
63 _dset_state(this->create_dset("state", {_state.size()}))
64 {}
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.
Definition model.hh:752
Data _state
The current state of the model.
Definition dummy.hh:32
std::shared_ptr< DataSet > _dset_state
Dataset to write the state to.
Definition dummy.hh:38
Data _bc
The boundary conditions of the model.
Definition dummy.hh:35
Model< Dummy, DummyTypes > Base
The base model class.
Definition dummy.hh:22
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213

Member Function Documentation

◆ monitor()

void Utopia::Models::Dummy::Dummy::monitor ( )
inline

Monitor model information.

Supply a function that calculates the state mean, if the monitor will perform an emission.

89 {
90 // Supply the state mean to the monitor
91 _monitor.set_by_func("state_mean", [this](){
92 const double sum = std::accumulate(this->_state.begin(),
93 this->_state.end(),
94 0);
95 return sum / this->_state.size();
96 });
97 }
Monitor _monitor
The monitor.
Definition model.hh:188

◆ perform_step()

void Utopia::Models::Dummy::Dummy::perform_step ( )
inline

Iterate by one time step.

This writes random numbers into the state vector, incrementing the already existing ones. Thus, with numbers between 0 and 1, the mean value of the state increases by 0.5 for each performed step.

74 {
75 // Write some random numbers into the state vector
76 auto gen = std::bind(std::uniform_real_distribution<>(), *this->_rng);
77 std::generate(_bc.begin(), _bc.end(), gen);
78 std::transform(_state.begin(), _state.end(),
79 _bc.begin(), _state.begin(),
80 [](const auto a, const auto b) { return a + b; });
81 }
const std::shared_ptr< RNG > _rng
The RNG shared between models.
Definition model.hh:161
OutputIt transform(const Utopia::ExecPolicy policy, InputIt first1, InputIt last1, OutputIt d_first, UnaryOperation unary_op)
Apply a unary operator to a range and store the result in a new range.
Definition parallel.hh:368

◆ write_data()

void Utopia::Models::Dummy::Dummy::write_data ( )
inline

Write data into a dataset that corresponds to the current step.

102 {
103 _dset_state->write(_state.begin(), _state.end(),
104 [](auto& value) { return value; });
105 }

Member Data Documentation

◆ _bc

Data Utopia::Models::Dummy::Dummy::_bc
private

The boundary conditions of the model.

◆ _dset_state

std::shared_ptr<DataSet> Utopia::Models::Dummy::Dummy::_dset_state
private

Dataset to write the state to.

◆ _state

Data Utopia::Models::Dummy::Dummy::_state
private

The current state of the model.


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