Utopia  2
Framework for studying models of complex & adaptive systems.
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
Utopia::Models::SEIRD::SEIRD Class Reference

SEIRD model on a grid. More...

#include <SEIRD.hh>

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

Public Types

using Base = Model< SEIRD, 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, SEIRD >
 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< SEIRD, CDTypes >
using Config = typename ModelTypes::Config
 Data type that holds the configuration. More...
 
using DataManager = DataIO::Default::DefaultDataManager< SEIRD >
 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 >
 SEIRD (const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
 Construct the SEIRD 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< SEIRD, CDTypes >
 Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< SEIRD > &w_deciders=DataIO::Default::default_deciders< SEIRD >, const DataIO::Default::DefaultTriggermap< SEIRD > &w_triggers=DataIO::Default::default_triggers< SEIRD >)
 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< DataGroupget_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< RNGget_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< MonitorManagerget_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< 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. More...
 
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. More...
 
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. More...
 
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. More...
 

Protected Member Functions

void update_densities ()
 Update the densities array. More...
 
void identify_clusters ()
 Identify clusters. More...
 
void exposure_control ()
 Apply exposure control. More...
 
void immunity_control ()
 Apply immunity control. More...
 
void transmission_control ()
 Apply transmission control. More...
 
- Protected Member Functions inherited from Utopia::Model< SEIRD, 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...
 
SEIRD & impl ()
 cast to the derived class More...
 
const SEIRD & 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 susceptibles. More...
 
RuleFunc _move_away_from_infected
 Move the agent on the cell away from an infected neighboring cell. More...
 
RuleFunc _move_randomly
 Move randomly to a neighboring cell if that cell is empty. More...
 
- Protected Attributes inherited from Utopia::Model< SEIRD, 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, static_cast< char >Kind::COUNT)> _densities
 Densities for all states. More...
 
Counters< std::size_t > _counts
 Cumulative counters for state transitions and other events More...
 
const int _compression
 The compression level used for all datasets. More...
 
bool _write_ca_data
 If false, writes only the non-spatial densities and counts data. More...
 
std::shared_ptr< DataSet_dset_densities
 2D dataset (densities array and time) of density values More...
 
std::shared_ptr< DataSet_dset_counts
 2D dataset (counts array and time) of cumulative state counters More...
 
std::shared_ptr< DataSet_dset_kind
 2D dataset (cell ID and time) of cell kinds More...
 
std::shared_ptr< DataSet_dset_immune
 2D dataset (cell ID and time) of cell's immunity More...
 
std::shared_ptr< DataSet_dset_num_recoveries
 2D dataset (cell ID and time) of cell's number of recoveries More...
 
std::shared_ptr< DataSet_dset_age
 2D dataset (cell ID and time) of cell's age 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< SEIRD, CDTypes >
static constexpr WriteMode _write_mode
 Which data-writing mode the base model should use. More...
 

Detailed Description

SEIRD model on a grid.

In this model, we model the spread of a disease using a SEIRD (susceptible-exposed-infected-recovered-deceased) model on a 2D grid.

Member Typedef Documentation

◆ Base

The base model type.

◆ Cell

Type of a cell.

◆ CellContainer

Type of a container of shared pointers to cells.

◆ CellManager

Type of the CellManager to use.

◆ DataGroup

Data type for a data group.

◆ DataSet

Data type for a dataset.

◆ RuleFunc

Rule function type.

Constructor & Destructor Documentation

◆ SEIRD()

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

Construct the SEIRD 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

Member Function Documentation

◆ exposure_control()

void Utopia::Models::SEIRD::SEIRD::exposure_control ( )
inlineprotected

Apply exposure control.

Add exposures if the iteration step matches the ones specified in the configuration. There are two available modes of exposure control that are applied, if provided, in this order:

  1. At specified times (parameter: at_times) a number of additional exposures is added (parameter: num_additional_exposures)
  2. The parameter p_exposed is changed to a new value at given times. This can happen multiple times. Parameter: change_p_exposed

◆ identify_clusters()

void Utopia::Models::SEIRD::SEIRD::identify_clusters ( )
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

◆ immunity_control()

void Utopia::Models::SEIRD::SEIRD::immunity_control ( )
inlineprotected

Apply immunity control.

Add cell immunities if the iteration step matches the ones specified in the configuration. There are two available modes of immunity control that are applied, if provided, in this order:

  1. At specified times (parameter: at_times) a number of additional immmunities is added (parameter: num_additional_immmunities)
  2. The parameter immune is changed to a new value at given times. This can happen multiple times. Parameter: change_immune

◆ monitor()

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

Monitor model information.

Supplies the densities and counts arrays to the monitor.

◆ perform_step()

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

Iterate a single time step.

This updates all cells (synchronously) according to the _update rule. For specifics, see there.

If exposure control is activated, the cells are first modified according to the specific exposure control parameters.

◆ transmission_control()

void Utopia::Models::SEIRD::SEIRD::transmission_control ( )
inlineprotected

Apply transmission control.

Change the transmitting probability p_transmit for a subset of cells of a specified kind if the iteration step matches the ones specified in the configuration. The parameter p_transmit is changed to a new value at given times for a number of randomly chosen cells of specified kins. This can happen multiple times. Parameter: change_p_transmit

◆ update_densities()

void Utopia::Models::SEIRD::SEIRD::update_densities ( )
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.

Attention
It is possible that rounding errors occur due to the division, thus, it is not guaranteed that the densities exactly add up to 1. The errors should be negligible.

◆ write_data()

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

Write data.

Member Data Documentation

◆ _cluster_id_cnt

unsigned int Utopia::Models::SEIRD::SEIRD::_cluster_id_cnt
private

The incremental cluster tag.

◆ _cluster_members

std::vector<std::shared_ptr<CellManager::Cell> > Utopia::Models::SEIRD::SEIRD::_cluster_members
private

A temporary container for use in cluster identification.

◆ _cm

CellManager Utopia::Models::SEIRD::SEIRD::_cm
private

The cell manager.

◆ _compression

const int Utopia::Models::SEIRD::SEIRD::_compression
private

The compression level used for all datasets.

◆ _counts

Counters<std::size_t> Utopia::Models::SEIRD::SEIRD::_counts
private

Cumulative counters for state transitions and other events

◆ _densities

std::array<double, static_cast<char>Kind::COUNT)> Utopia::Models::SEIRD::SEIRD::_densities
private

Densities for all states.

Array indices are linked to Utopia::Models::SEIRD::Kind

Warning
This array is used for temporary storage; it is not automatically updated but only upon write operations.

◆ _dset_age

std::shared_ptr<DataSet> Utopia::Models::SEIRD::SEIRD::_dset_age
private

2D dataset (cell ID and time) of cell's age

◆ _dset_cluster_id

std::shared_ptr<DataSet> Utopia::Models::SEIRD::SEIRD::_dset_cluster_id
private

The dataset for storing the cluster ID associated with each cell.

◆ _dset_counts

std::shared_ptr<DataSet> Utopia::Models::SEIRD::SEIRD::_dset_counts
private

2D dataset (counts array and time) of cumulative state counters

◆ _dset_densities

std::shared_ptr<DataSet> Utopia::Models::SEIRD::SEIRD::_dset_densities
private

2D dataset (densities array and time) of density values

◆ _dset_immune

std::shared_ptr<DataSet> Utopia::Models::SEIRD::SEIRD::_dset_immune
private

2D dataset (cell ID and time) of cell's immunity

◆ _dset_kind

std::shared_ptr<DataSet> Utopia::Models::SEIRD::SEIRD::_dset_kind
private

2D dataset (cell ID and time) of cell kinds

◆ _dset_num_recoveries

std::shared_ptr<DataSet> Utopia::Models::SEIRD::SEIRD::_dset_num_recoveries
private

2D dataset (cell ID and time) of cell's number of recoveries

◆ _identify_cluster

RuleFunc Utopia::Models::SEIRD::SEIRD::_identify_cluster
protected

Identify each cluster of susceptibles.

◆ _move_away_from_infected

RuleFunc Utopia::Models::SEIRD::SEIRD::_move_away_from_infected
protected
Initial value:
= [this](const auto& cell) {
auto& state = cell->state;
auto neighbors = _cm.neighbors_of(cell);
for (const auto& nb : neighbors) {
if (nb->state.kind == Kind::infected) {
std::shuffle(neighbors.begin(), neighbors.end(), *this->_rng);
for (const auto& _nb : neighbors) {
if (_nb->state.kind == Kind::empty) {
std::swap(state, _nb->state);
break;
}
}
break;
}
}
return state;
}
CellContainer< Cell > neighbors_of(const Cell &cell) const
Retrieve the given cell's neighbors.
Definition: cell_manager.hh:458
Counters< std::size_t > _counts
Cumulative counters for state transitions and other events
Definition: SEIRD.hh:93
CellManager _cm
The cell manager.
Definition: SEIRD.hh:70
void swap(WriteTask< BGB, DW, DB, AWG, AWD > &lhs, WriteTask< BGB, DW, DB, AWG, AWD > &rhs)
Swaps the state of lhs and rhs.
Definition: write_task.hh:240
@ neighbors
Iterate over neighbors (adjacent_vertices).
@ infected
Cell is infected.
void increment_move_away_from_infected()
Increment counter for movement events away from an infected agent.
Definition: counters.hh:113

Move the agent on the cell away from an infected neighboring cell.

Check whether there is an infected cell in the neighborhood. If there is an empty cell in the neighborhood, move to it. If there is no empty spot in the neighborhood do nothing.

◆ _move_randomly

RuleFunc Utopia::Models::SEIRD::SEIRD::_move_randomly
protected

Move randomly to a neighboring cell if that cell is empty.

If the cell is not empty, an inert cell, or a source: move to neighboring empty location with probability p_move_randomly. If no neighboring cell is empty, do nothing.

◆ _params

const Params Utopia::Models::SEIRD::SEIRD::_params
private

Model parameters.

◆ _prob_distr

std::uniform_real_distribution<double> Utopia::Models::SEIRD::SEIRD::_prob_distr
private

The range [0, 1] distribution to use for probability checks.

◆ _update

RuleFunc Utopia::Models::SEIRD::SEIRD::_update
protected

Define the update rule.

Update the given cell according to the following rules:

  • Empty cells grow susceptible cells with probability p_susceptible.
  • Cells in neighborhood of an infected cell do not get exposed with the probability p_random_immunity.
  • Exposed cells become infected cells after a certain incubation period.
  • Infected cells die with probability p_deceased and become an empty cell or they become recovered cells with 1-p_deceased.

◆ _write_ca_data

bool Utopia::Models::SEIRD::SEIRD::_write_ca_data
private

If false, writes only the non-spatial densities and counts data.


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