Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
dummy.hh
Go to the documentation of this file.
1#ifndef UTOPIA_MODELS_DUMMY_HH
2#define UTOPIA_MODELS_DUMMY_HH
3
5
6
7namespace Utopia {
8namespace Models {
9namespace Dummy {
10
13
15
18class Dummy : public Model<Dummy, DummyTypes>
19{
20public:
23
25 using Data = std::vector<double>;
26
27 // Type shortcut for dataset
29
30private:
33
36
38 std::shared_ptr<DataSet> _dset_state;
39
40public:
42
49 template <class ParentModel>
51 const std::string& name,
53 const Data& initial_state,
54 const DataIO::Config& custom_cfg = {}
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 {}
65
66
68
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 }
82
83
85
88 void monitor ()
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 }
98
99
102 {
103 _dset_state->write(_state.begin(), _state.end(),
104 [](auto& value) { return value; });
105 }
106
107
108 // -- Getters and Setters -- //
109
110};
111
112} // namespace Dummy
113} // namespace Models
114} // namespace Utopia
115
116#endif // UTOPIA_MODELS_DUMMY_HH
Base class interface for Models using the CRT Pattern.
Definition model.hh:112
Monitor _monitor
The monitor.
Definition model.hh:188
typename ModelTypes::DataSet DataSet
Data type that is used for storing data.
Definition model.hh:125
const std::shared_ptr< RNG > _rng
The RNG shared between models.
Definition model.hh:161
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
Dummy model with simple update rule.
Definition dummy.hh:19
std::vector< double > Data
The data type to use for _state and _bc members.
Definition dummy.hh:25
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
void perform_step()
Iterate by one time step.
Definition dummy.hh:73
void monitor()
Monitor model information.
Definition dummy.hh:88
Base::DataSet DataSet
Definition dummy.hh:28
Data _bc
The boundary conditions of the model.
Definition dummy.hh:35
void write_data()
Write data into a dataset that corresponds to the current step.
Definition dummy.hh:101
Model< Dummy, DummyTypes > Base
The base model class.
Definition dummy.hh:22
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.
Definition dummy.hh:50
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
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition types.hh:71
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
Definition agent.hh:11
Wrapper struct for defining model class data types.
Definition model.hh:92