Utopia
2
Framework for studying models of complex & adaptive systems.
|
Contagious disease model on a grid. More...
#include <ContDisease.hh>
Public Types | |
using | Base = Model< ContDisease, CDTypes > |
The base model type. More... | |
using | DataGroup = typename Base::DataGroup |
Data type for a data group. More... | |
using | DataSet = typename Base::DataSet |
Data type for a dataset. More... | |
using | CellManager = Utopia::CellManager< CDCellTraits, ContDisease > |
Type of the CellManager to use. More... | |
using | Cell = typename CellManager::Cell |
Type of a cell. More... | |
using | CellContainer = Utopia::CellContainer< Cell > |
Type of a container of shared pointers to cells. More... | |
using | RuleFunc = typename CellManager::RuleFunc |
Rule function type. More... | |
Public Types inherited from Utopia::Model< ContDisease, CDTypes > | |
using | Config = typename ModelTypes::Config |
Data type that holds the configuration. More... | |
using | DataManager = DataIO::Default::DefaultDataManager< ContDisease > |
The data manager to use, specialized with the derived model. More... | |
using | DataGroup = typename ModelTypes::DataGroup |
Data type that is used for storing datasets. More... | |
using | DataSet = typename ModelTypes::DataSet |
Data type that is used for storing data. More... | |
using | RNG = typename ModelTypes::RNG |
Data type of the shared RNG. More... | |
using | Space = typename ModelTypes::Space |
Data type of the space this model resides in. More... | |
using | Time = typename ModelTypes::Time |
Data type for the model time. More... | |
using | Monitor = typename ModelTypes::Monitor |
Data type for the monitor. More... | |
using | MonitorManager = typename ModelTypes::MonitorManager |
Data type for the monitor manager. More... | |
using | Level = typename ModelTypes::Level |
Data type for the hierarchical level. More... | |
Public Member Functions | |
template<class ParentModel > | |
ContDisease (const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={}) | |
Construct the ContDisease model. More... | |
void | perform_step () |
Iterate a single time step. More... | |
void | monitor () |
Monitor model information. More... | |
void | write_data () |
Write data. More... | |
Public Member Functions inherited from Utopia::Model< ContDisease, CDTypes > | |
Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< ContDisease > &w_deciders=DataIO::Default::default_deciders< ContDisease >, const DataIO::Default::DefaultTriggermap< ContDisease > &w_triggers=DataIO::Default::default_triggers< ContDisease >) | |
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... | |
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... | |
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... | |
Protected Member Functions | |
void | update_densities () |
Update the densities array. More... | |
void | identify_clusters () |
Identify clusters. More... | |
void | infection_control () |
Apply infection control. More... | |
Protected Member Functions inherited from Utopia::Model< ContDisease, CDTypes > | |
void | __perform_step () |
Perform the computation of a step. More... | |
void | __monitor () |
Monitor information in the terminal. More... | |
void | __write_data () |
Write data; calls the implementation's write_data method. More... | |
void | __write_initial_state () |
Write the initial state. More... | |
void | increment_time (const Time dt=1) |
Increment time. More... | |
void | __prolog () |
The default prolog of a model. More... | |
void | __epilog () |
The default epilog of a model. More... | |
ContDisease & | impl () |
cast to the derived class More... | |
const ContDisease & | impl () const |
const cast to the derived interface More... | |
Protected Attributes | |
RuleFunc | _update |
Define the update rule. More... | |
RuleFunc | _identify_cluster |
Identify each cluster of trees. More... | |
Protected Attributes inherited from Utopia::Model< ContDisease, CDTypes > | |
const std::string | _name |
Name of the model instance. More... | |
const std::string | _full_name |
The full name within the model hierarchy. More... | |
const Level | _level |
The level within the model hierarchy. More... | |
const Config | _cfg |
Config node belonging to this model instance. More... | |
const std::shared_ptr< RNG > | _rng |
The RNG shared between models. More... | |
const std::shared_ptr< spdlog::logger > | _log |
The (model) logger. More... | |
std::shared_ptr< Space > | _space |
The space this model resides in. More... | |
Time | _time |
Model-internal current time stamp. More... | |
const Time | _time_max |
Model-internal maximum time stamp. More... | |
const std::shared_ptr< DataGroup > | _hdfgrp |
The HDF group this model instance should write its data to. More... | |
const Time | _write_start |
First time at which write_data is called. More... | |
const Time | _write_every |
How often to call write_data from iterate. More... | |
Monitor | _monitor |
The monitor. More... | |
DataManager | _datamanager |
Manager object for handling data output; see DataManager. More... | |
Private Attributes | |
CellManager | _cm |
The cell manager. More... | |
const Params | _params |
Model parameters. More... | |
std::uniform_real_distribution< double > | _prob_distr |
The range [0, 1] distribution to use for probability checks. More... | |
unsigned int | _cluster_id_cnt |
The incremental cluster tag. More... | |
std::vector< std::shared_ptr< CellManager::Cell > > | _cluster_members |
A temporary container for use in cluster identification. More... | |
std::array< double, 5 > | _densities |
Densities for all states. More... | |
bool | _write_only_densities |
std::shared_ptr< DataSet > | _dset_densities |
2D dataset (densities array and time) of density values More... | |
std::shared_ptr< DataSet > | _dset_kind |
2D dataset (cell ID and time) of cell kinds More... | |
std::shared_ptr< DataSet > | _dset_age |
2D dataset (tree age and time) of cells More... | |
std::shared_ptr< DataSet > | _dset_cluster_id |
The dataset for storing the cluster ID associated with each cell. More... | |
Additional Inherited Members | |
Static Protected Attributes inherited from Utopia::Model< ContDisease, CDTypes > | |
static constexpr WriteMode | _write_mode |
Which data-writing mode the base model should use. More... | |
Contagious disease model on a grid.
In this model, we model the spread of a disease through a forest on a 2D grid. Each cell can have one of five different states: empty, tree, infected, source or empty. Each time step, cells update their state according to the update rules. Empty cells will convert with a certain probability to tress, while trees represent cells that can be infected. Infection can happen either through a neighboring cells, or through random point infection. An infected cells reverts back to empty after one time step. Stones represent cells that can not be infected, therefore represent a blockade for the spread of the infection. Infection sources are cells that continuously spread infection without dying themselves. Different starting conditions, and update mechanisms can be configured.
The base model type.
using Utopia::Models::ContDisease::ContDisease::Cell = typename CellManager::Cell |
Type of a cell.
Type of a container of shared pointers to cells.
using Utopia::Models::ContDisease::ContDisease::CellManager = Utopia::CellManager<CDCellTraits, ContDisease> |
Type of the CellManager to use.
using Utopia::Models::ContDisease::ContDisease::DataGroup = typename Base::DataGroup |
Data type for a data group.
using Utopia::Models::ContDisease::ContDisease::DataSet = typename Base::DataSet |
Data type for a dataset.
using Utopia::Models::ContDisease::ContDisease::RuleFunc = typename CellManager::RuleFunc |
Rule function type.
|
inline |
Construct the ContDisease model.
name | Name of this model instance; is used to extract the configuration from the parent model and set up a HDFGroup for this instance |
parent_model | The parent model this model instance resides in |
custom_cfg | A custom configuration to use instead of the one extracted from the parent model using the instance name |
|
inlineprotected |
Identify clusters.
This function identifies clusters and updates the cell specific cluster_id as well as the member variable cluster_id_cnt that counts the number of ids
|
inlineprotected |
Apply infection control.
Add infections if the iteration step matches the ones specified in the configuration. There are two available modes of infection control that are applied, if provided, in this order:
at_times
) a number of additional infections is added (parameter: num_additional_infections
)p_infect
is changed to a new value at given times. This can happen multiple times. Parameter: change_p_infect
|
inline |
Monitor model information.
Supplies the densities
array to the monitor.
|
inline |
Iterate a single time step.
This updates all cells (synchronously) according to the _update rule. For specifics, see there.
If infection control is activated, the cells are first modified according to the specific infection control parameters.
|
inlineprotected |
Update the densities array.
Each density is calculated by counting the number of state occurrences and afterwards dividing by the total number of cells.
|
inline |
Write data.
Writes out the cell state and the densities of cells with the states empty, tree, or infected (i.e.: those that may change)
|
private |
The incremental cluster tag.
|
private |
A temporary container for use in cluster identification.
|
private |
The cell manager.
|
private |
Densities for all states.
Array indices are linked to Utopia::Models::ContDisease::Kind
|
private |
2D dataset (tree age and time) of cells
|
private |
The dataset for storing the cluster ID associated with each cell.
|
private |
2D dataset (densities array and time) of density values
|
private |
2D dataset (cell ID and time) of cell kinds
|
protected |
Identify each cluster of trees.
|
private |
The range [0, 1] distribution to use for probability checks.
|
protected |
Define the update rule.
Update the given cell according to the following rules:
|
private |