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

A very simple vegetation model. More...

#include <Vegetation.hh>

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

Public Types

using Base = Model< Vegetation, VegetationTypes >
 Type of the base class.
 
using Config = typename Base::Config
 Type of the config tree.
 
using DataSet = typename Base::DataSet
 Type of a data set.
 
using CellManager = Utopia::CellManager< CellTraits, Vegetation >
 Type of the cell manager used.
 
using RuleFunc = typename CellManager::RuleFunc
 Type of the update rule.
 
- Public Types inherited from Utopia::Model< Vegetation, VegetationTypes >
using Config = typename ModelTypes::Config
 Data type that holds the configuration.
 
using DataManager = DataIO::Default::DefaultDataManager< Vegetation >
 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 >
 Vegetation (const std::string &name, const ParentModel &parent_model, const DataIO::Config &custom_cfg={})
 Construct the Vegetation model.
 
void perform_step ()
 Iterate a single step.
 
void write_data ()
 Write the cell states (aka plant bio-mass)
 
void monitor ()
 Monitor the current model state; supplies the mean plant mass.
 
- Public Member Functions inherited from Utopia::Model< Vegetation, VegetationTypes >
 Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< Vegetation > &w_deciders=DataIO::Default::default_deciders< Vegetation >, const DataIO::Default::DefaultTriggermap< Vegetation > &w_triggers=DataIO::Default::default_triggers< Vegetation >)
 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 Member Functions

double calc_mean_mass () const
 Calculate the mean plant mass.
 

Private Attributes

CellManager _cm
 The grid manager.
 
std::normal_distribution< double_rain_dist
 Normal distribution for drawing random rain values.
 
double _growth_rate
 The growth rate (logistic growth model)
 
double _seeding_rate
 The seeding rate.
 
std::shared_ptr< DataSet_dset_plant_mass
 Plant mass dataset.
 
RuleFunc _growth_seeding
 Apply logistic growth and seeding.
 

Additional Inherited Members

- Protected Member Functions inherited from Utopia::Model< Vegetation, VegetationTypes >
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.
 
Vegetation & impl ()
 cast to the derived class
 
const Vegetation & impl () const
 const cast to the derived interface
 
- Protected Attributes inherited from Utopia::Model< Vegetation, VegetationTypes >
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< Vegetation, VegetationTypes >
static constexpr WriteMode _write_mode
 Which data-writing mode the base model should use.
 

Detailed Description

A very simple vegetation model.

Member Typedef Documentation

◆ Base

Type of the base class.

◆ CellManager

Type of the cell manager used.

◆ Config

Type of the config tree.

◆ DataSet

Type of a data set.

◆ RuleFunc

Type of the update rule.

Constructor & Destructor Documentation

◆ Vegetation()

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

Construct the Vegetation model.

Parameters
nameName of this model instance; is used to extract the configuration from the parent model and set up a HDFGroup for this instance
parent_modelThe parent model this model instance resides in
custom_cfgA custom configuration to use instead of the one extracted from the parent model using the instance name
146 {}
147 )
148 :
149 // Construct the base class
151
152 // Initialize the manager, setting the initial state
153 _cm(*this, CellState({0.0})),
154
155 // Initialize the rain distribution
156 _rain_dist{get_as<double>("rain_mean", this->_cfg),
157 get_as<double>("rain_std", this->_cfg)},
158
159 // Initialize model parameters from config file
160 _growth_rate(get_as<double>("growth_rate", this->_cfg)),
161 _seeding_rate(get_as<double>("seeding_rate", this->_cfg)),
162
163 // Open dataset for output of cell states
164 _dset_plant_mass(this->create_cm_dset("plant_mass", _cm))
165 {
166 this->_log->info("'{}' model fully set up.", name);
167 }
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.
Definition model.hh:849
const Config _cfg
Config node belonging to this model instance.
Definition model.hh:158
const std::shared_ptr< spdlog::logger > _log
The (model) logger.
Definition model.hh:164
double _seeding_rate
The seeding rate.
Definition Vegetation.hh:69
std::normal_distribution< double > _rain_dist
Normal distribution for drawing random rain values.
Definition Vegetation.hh:63
std::shared_ptr< DataSet > _dset_plant_mass
Plant mass dataset.
Definition Vegetation.hh:74
Model< Vegetation, VegetationTypes > Base
Type of the base class.
Definition Vegetation.hh:41
double _growth_rate
The growth rate (logistic growth model)
Definition Vegetation.hh:66
CellManager _cm
The grid manager.
Definition Vegetation.hh:57
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

◆ calc_mean_mass()

double Utopia::Models::Vegetation::Vegetation::calc_mean_mass ( ) const
inlineprivate

Calculate the mean plant mass.

122 {
123 return std::accumulate(_cm.cells().begin(),
124 _cm.cells().end(),
125 0.,
126 [](double sum, const auto& cell) {
127 return sum + cell->state().plant_mass;
128 }) / _cm.cells().size();
129 }
const CellContainer< Cell > & cells() const
Return const reference to the managed CA cells.
Definition cell_manager.hh:219

◆ monitor()

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

Monitor the current model state; supplies the mean plant mass.

186 {
187 this->_monitor.set_entry("mean_mass", calc_mean_mass());
188 }
Monitor _monitor
The monitor.
Definition model.hh:188
double calc_mean_mass() const
Calculate the mean plant mass.
Definition Vegetation.hh:122

◆ perform_step()

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

Iterate a single step.

171 {
173 }
RuleFunc _growth_seeding
Apply logistic growth and seeding.
Definition Vegetation.hh:87
void apply_rule(Rule &&rule, const ContTarget &cont_target, ContArgs &&... cont_args)
Sequential overload.
Definition apply.hh:133

◆ write_data()

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

Write the cell states (aka plant bio-mass)

177 {
178 _dset_plant_mass->write(_cm.cells().begin(),
179 _cm.cells().end(),
180 [](auto& cell) {
181 return cell->state().plant_mass; }
182 );
183 }

Member Data Documentation

◆ _cm

CellManager Utopia::Models::Vegetation::Vegetation::_cm
private

The grid manager.

◆ _dset_plant_mass

std::shared_ptr<DataSet> Utopia::Models::Vegetation::Vegetation::_dset_plant_mass
private

Plant mass dataset.

◆ _growth_rate

double Utopia::Models::Vegetation::Vegetation::_growth_rate
private

The growth rate (logistic growth model)

◆ _growth_seeding

RuleFunc Utopia::Models::Vegetation::Vegetation::_growth_seeding
private
Initial value:
= [this](const auto& cell){
auto state = cell->state();
auto rain = _rain_dist(*(this->_rng));
auto mass = state.plant_mass;
if (rain < 1e-16) {
rain = 0.;
}
if (not (mass < 1e-16)) {
state.plant_mass = ((_growth_rate + 1.) * mass)/(1. + (mass * (_growth_rate))/rain);
}
else {
state.plant_mass = _seeding_rate * rain;
}
return state;
}
const std::shared_ptr< RNG > _rng
The RNG shared between models.
Definition model.hh:161

Apply logistic growth and seeding.

For each cell, a random gauss-distributed number is drawn that represents the rainfall onto that cell. If the plant bio-mass at that cell is already non-zero, it is increased according to a logistic growth model, modelled by the Beverton-Holt discretisation of the logistic function. If it is zero, then the plant bio-mass is set proportional to the seeding rate and the amount of rain.

87 {
88 auto state = cell->state();
89 auto rain = _rain_dist(*(this->_rng));
90 auto mass = state.plant_mass;
91
92 if (rain < 1e-16) {
93 rain = 0.;
94 }
95
96 // Distinguish by mass whether to grow or to seed
97 // If negative or smaller than machine epsilon at 1.0 for doubles,
98 // consider invalid and reseed
99 if (not (mass < 1e-16)) {
100 // Logistic Growth
101 /* Use Beverton-Holt to approximate discretized logistic growth.
102 * Be careful that when using the Wikipedia version
103 * [https://en.wikipedia.org/wiki/Beverton–Holt_model], the R0
104 * parameter therein is >= 1 -> proliferation rate!
105 * This means that, as given therein, we have:
106 * n_{t+1} = (r*n_t)/(1 + (n_t*(r-1)/K))
107 * with r >= 1, which has to be turned into
108 * n_{t+1} =((r+1.)*n_t)/(1 +(n_t*r)/K)
109 * when r is given as a growth rate proper.
110 */
111 state.plant_mass = ((_growth_rate + 1.) * mass)/(1. + (mass * (_growth_rate))/rain);
112 }
113 else {
114 // Seeding
115 state.plant_mass = _seeding_rate * rain;
116 }
117
118 return state;
119 };

◆ _rain_dist

std::normal_distribution<double> Utopia::Models::Vegetation::Vegetation::_rain_dist
private

Normal distribution for drawing random rain values.

◆ _seeding_rate

double Utopia::Models::Vegetation::Vegetation::_seeding_rate
private

The seeding rate.


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