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

Contagious disease model on a grid. More...

#include <ContDisease.hh>

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

Public Types

using Base = Model< ContDisease, CDTypes >
 The base model type.
 
using DataGroup = typename Base::DataGroup
 Data type for a data group.
 
using DataSet = typename Base::DataSet
 Data type for a dataset.
 
using CellManager = Utopia::CellManager< CDCellTraits, ContDisease >
 Type of the CellManager to use.
 
using Cell = typename CellManager::Cell
 Type of a cell.
 
using CellContainer = Utopia::CellContainer< Cell >
 Type of a container of shared pointers to cells.
 
using RuleFunc = typename CellManager::RuleFunc
 Rule function type.
 
- Public Types inherited from Utopia::Model< ContDisease, CDTypes >
using Config = typename ModelTypes::Config
 Data type that holds the configuration.
 
using DataManager = DataIO::Default::DefaultDataManager< ContDisease >
 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 >
 ContDisease (const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
 Construct the ContDisease model.
 
void perform_step ()
 Iterate a single time step.
 
void monitor ()
 Monitor model information.
 
void write_data ()
 Write data.
 
- 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.
 
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.
 

Protected Member Functions

void update_densities ()
 Update the densities array.
 
void identify_clusters ()
 Identify clusters.
 
void infection_control ()
 Apply infection control.
 
- Protected Member Functions inherited from Utopia::Model< ContDisease, CDTypes >
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.
 
ContDisease & impl ()
 cast to the derived class
 
const ContDisease & impl () const
 const cast to the derived interface
 

Protected Attributes

RuleFunc _update
 Define the update rule.
 
RuleFunc _identify_cluster
 Identify each cluster of trees.
 
- Protected Attributes inherited from Utopia::Model< ContDisease, CDTypes >
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.
 

Private Attributes

CellManager _cm
 The cell manager.
 
const Params _params
 Model parameters.
 
std::uniform_real_distribution< double_prob_distr
 The range [0, 1] distribution to use for probability checks.
 
unsigned int _cluster_id_cnt
 The incremental cluster tag.
 
std::vector< std::shared_ptr< CellManager::Cell > > _cluster_members
 A temporary container for use in cluster identification.
 
std::array< double, 5 > _densities
 Densities for all states.
 
bool _write_only_densities
 
std::shared_ptr< DataSet_dset_densities
 2D dataset (densities array and time) of density values
 
std::shared_ptr< DataSet_dset_kind
 2D dataset (cell ID and time) of cell kinds
 
std::shared_ptr< DataSet_dset_age
 2D dataset (tree age and time) of cells
 
std::shared_ptr< DataSet_dset_cluster_id
 The dataset for storing the cluster ID associated with each cell.
 

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.
 

Detailed Description

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.

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

◆ ContDisease()

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

Construct the ContDisease 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
133 {}
134 )
135 :
136 // Initialize first via base model
138
139 // Initialize the cell manager, binding it to this model
140 _cm(*this),
141
142 // Carry over Parameters
143 _params(this->_cfg),
144
145 // Initialize remaining members
146 _prob_distr(0., 1.),
149 _densities{}, // undefined here, will be set in constructor body
150 _write_only_densities(get_as<bool>("write_only_densities",
151 this->_cfg)),
152
153 // Create the dataset for the densities; shape is known
154 _dset_densities(this->create_dset("densities", {5})),
155
156 // Create dataset for cell states
157 _dset_kind(this->create_cm_dset("kind", _cm)),
158
159 // Create dataset for tree age
160 _dset_age(this->create_cm_dset("age", _cm)),
161
162 // Create dataset for cluster id
163 _dset_cluster_id(this->create_cm_dset("cluster_id", _cm))
164 {
165 // Make sure the densities are not undefined
166 _densities.fill(std::numeric_limits<double>::quiet_NaN());
167
168 // Cells are already set up by the CellManager.
169 // Remaining initialization steps regard only macroscopic quantities,
170 // e.g. the setup of heterogeneities: Stones and infection source.
171
172 // Stones
173 if (_cfg["stones"] and get_as<bool>("enabled", _cfg["stones"])) {
174 this->_log->info("Setting cells to be stones ...");
175
176 // Get the container
177 auto to_turn_to_stone = _cm.select_cells(_cfg["stones"]);
178
179 // Apply a rule to all cells of that container: turn to stone
181 [](const auto& cell){
182 auto& state = cell->state;
183 state.kind = Kind::stone;
184 return state;
185 },
187 );
188
189 this->_log->info("Set {} cells to be stones using selection mode "
190 "'{}'.", to_turn_to_stone.size(),
191 get_as<std::string>("mode", _cfg["stones"]));
192 }
193
194 // Ignite some cells permanently: fire sources
195 if ( _cfg["infection_source"]
196 and get_as<bool>("enabled", _cfg["infection_source"]))
197 {
198 this->_log->info("Setting cells to be infection sources ...");
199 auto source_cells = _cm.select_cells(_cfg["infection_source"]);
200
202 [](const auto& cell){
203 auto& state = cell->state;
204 state.kind = Kind::source;
205 return state;
206 },
208 );
209
210 this->_log->info("Set {} cells to be infection sources using "
211 "selection mode '{}'.", source_cells.size(),
212 get_as<std::string>("mode", _cfg["infection_source"]));
213 }
214
215 // Add attributes to density dataset that provide coordinates
216 _dset_densities->add_attribute("dim_name__1", "kind");
217 _dset_densities->add_attribute("coords_mode__kind", "values");
218 _dset_densities->add_attribute("coords__kind",
219 std::vector<std::string>{
220 "empty", "tree", "infected", "source", "stone"
221 });
222 this->_log->debug("Added coordinates to densities dataset.");
223
224 // Initialization should be finished here.
225 this->_log->debug("{} model fully set up.", this->_name);
226 }
CellContainer< Cell > select_cells(Args &&... args) const
Select cells using the Utopia::select_entities interface.
Definition cell_manager.hh:342
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::string _name
Name of the model instance.
Definition model.hh:149
const std::shared_ptr< spdlog::logger > _log
The (model) logger.
Definition model.hh:164
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
std::array< double, 5 > _densities
Densities for all states.
Definition ContDisease.hh:101
std::shared_ptr< DataSet > _dset_cluster_id
The dataset for storing the cluster ID associated with each cell.
Definition ContDisease.hh:116
Model< ContDisease, CDTypes > Base
The base model type.
Definition ContDisease.hh:55
CellManager _cm
The cell manager.
Definition ContDisease.hh:81
unsigned int _cluster_id_cnt
The incremental cluster tag.
Definition ContDisease.hh:90
std::shared_ptr< DataSet > _dset_densities
2D dataset (densities array and time) of density values
Definition ContDisease.hh:107
const Params _params
Model parameters.
Definition ContDisease.hh:84
std::vector< std::shared_ptr< CellManager::Cell > > _cluster_members
A temporary container for use in cluster identification.
Definition ContDisease.hh:93
std::uniform_real_distribution< double > _prob_distr
The range [0, 1] distribution to use for probability checks.
Definition ContDisease.hh:87
std::shared_ptr< DataSet > _dset_kind
2D dataset (cell ID and time) of cell kinds
Definition ContDisease.hh:110
bool _write_only_densities
Definition ContDisease.hh:104
std::shared_ptr< DataSet > _dset_age
2D dataset (tree age and time) of cells
Definition ContDisease.hh:113
ReturnType get_as(const std::string &key, const DataIO::Config &node)
This function is a wrapper around the yaml-cpp YAML::Node::as function.
Definition cfg_utils.hh:158
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
@ stone
Cell cannot be infected.
@ source
Cell is an infection source: constantly infected, spreading infection.

Member Function Documentation

◆ identify_clusters()

void Utopia::Models::ContDisease::ContDisease::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

263 {
264 // reset cluster counter
265 _cluster_id_cnt = 0;
267 _cm.cells());
268 }
const CellContainer< Cell > & cells() const
Return const reference to the managed CA cells.
Definition cell_manager.hh:219
RuleFunc _identify_cluster
Identify each cluster of trees.
Definition ContDisease.hh:400

◆ infection_control()

void Utopia::Models::ContDisease::ContDisease::infection_control ( )
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:

  1. At specified times (parameter: at_times) a number of additional infections is added (parameter: num_additional_infections)
  2. The parameter p_infect is changed to a new value at given times. This can happen multiple times. Parameter: change_p_infect
281 {
282 // Check that time matches the first element of the sorted queue of
283 // time steps at which to apply the given number of infections.
285 // Check whether time has come for infections
286 if (this->_time == _params.infection_control.at_times.front()){
287 // Select cells that are trees
288 // (not empty, stones, infected, or source)
289 const auto cells_pool =
291 [&](const auto& cell){
292 return (cell->state.kind == Kind::tree);
293 }
294 );
295
296 // Sample cells from the pool and ...
298 std::sample(
299 cells_pool.begin(), cells_pool.end(),
300 std::back_inserter(sample),
302 *this->_rng
303 );
304
305 // ... and infect the sampled cells
306 for (const auto& cell : sample){
307 cell->state.kind = Kind::infected;
308 }
309
310 // Done. Can now remove first element of the queue.
312 }
313 }
314
315 // Change p_infect if the iteration step matches the ones
316 // specified in the configuration. This leads to constant time lookup.
318 const auto change_p_infect =
320
321 if (this->_time == change_p_infect.first) {
322 _params.p_infect = change_p_infect.second;
323
324 // Done. Can now remove the element from the queue.
326 }
327 }
328 }
Time _time
Model-internal current time stamp.
Definition model.hh:170
Utopia::CellContainer< Cell > CellContainer
Type of a container of shared pointers to cells.
Definition ContDisease.hh:70
@ condition
Select if a condition is fulfilled.
@ sample
Select a random sample of entities with a known sample size.
@ tree
Cell represents a tree.
TimesValuesQueue change_p_infect
Change p_infect to new value at given times.
Definition params.hh:37
const std::size_t num_additional_infections
The number of infections added to the default p_infect.
Definition params.hh:27
TimesQueue at_times
Add additional infections at these time steps.
Definition params.hh:30
double p_infect
Definition params.hh:143
const InfectionContParams infection_control
Infection control parameters.
Definition params.hh:146

◆ monitor()

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

Monitor model information.

Supplies the densities array to the monitor.

463 {
465 this->_monitor.set_entry("densities", _densities);
466 }
Monitor _monitor
The monitor.
Definition model.hh:188
void update_densities()
Update the densities array.
Definition ContDisease.hh:238

◆ perform_step()

void Utopia::Models::ContDisease::ContDisease::perform_step ( )
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.

447 {
448 // Apply infection control if enabled
451 }
452
453 // Apply the update rule to all cells.
455 // NOTE The cell state is updated synchronously, i.e.: only after all
456 // cells have been visited and know their state for the next step
457 }
RuleFunc _update
Define the update rule.
Definition ContDisease.hh:339
void infection_control()
Apply infection control.
Definition ContDisease.hh:281
const bool enabled
Whether infection control is enabled.
Definition params.hh:24

◆ update_densities()

void Utopia::Models::ContDisease::ContDisease::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.
238 {
239 // Temporarily overwrite every entry in the densities with zeroes
240 _densities.fill(0);
241
242 // Count the occurrence of each possible state. Use the _densities
243 // member for that in order to not create a new array.
244 for (const auto& cell : this->_cm.cells()) {
245 // Cast enum to integer to arrive at the corresponding index
246 ++_densities[static_cast<char>(cell->state.kind)];
247 }
248 // The _densities array now contains the counts.
249
250 // Calculate the actual densities by dividing the counts by the total
251 // number of cells.
252 for (auto&& d : _densities){
253 d /= static_cast<double>(this->_cm.cells().size());
254 }
255 };

◆ write_data()

void Utopia::Models::ContDisease::ContDisease::write_data ( )
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)

473 {
474 // Update densities and write them
477 // NOTE Although stones and source density are not changing, they are
478 // calculated anyway and writing them again is not a big cost
479 // (two doubles) while making analysis much easier.
480
481 // If only the densities are to be written, can stop here.
483 return;
484 }
485
486 // Write the cell state
487 _dset_kind->write(_cm.cells().begin(), _cm.cells().end(),
488 [](const auto& cell) {
489 return static_cast<char>(cell->state.kind);
490 }
491 );
492
493 // Write the tree ages
494 _dset_age->write(_cm.cells().begin(), _cm.cells().end(),
495 [](const auto& cell) {
496 return static_cast<unsigned short int>(cell->state.age);
497 }
498 );
499
500 // Identify clusters and write them out
502 _dset_cluster_id->write(_cm.cells().begin(), _cm.cells().end(),
503 [](const auto& cell) {
504 return cell->state.cluster_id;
505 });
506 }
void identify_clusters()
Identify clusters.
Definition ContDisease.hh:263

Member Data Documentation

◆ _cluster_id_cnt

unsigned int Utopia::Models::ContDisease::ContDisease::_cluster_id_cnt
private

The incremental cluster tag.

◆ _cluster_members

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

A temporary container for use in cluster identification.

◆ _cm

CellManager Utopia::Models::ContDisease::ContDisease::_cm
private

The cell manager.

◆ _densities

std::array<double, 5> Utopia::Models::ContDisease::ContDisease::_densities
private

Densities for all states.

Array indices are linked to Utopia::Models::ContDisease::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::ContDisease::ContDisease::_dset_age
private

2D dataset (tree age and time) of cells

◆ _dset_cluster_id

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

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

◆ _dset_densities

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

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

◆ _dset_kind

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

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

◆ _identify_cluster

RuleFunc Utopia::Models::ContDisease::ContDisease::_identify_cluster
protected

Identify each cluster of trees.

400 {
401 if (cell->state.cluster_id != 0 or cell->state.kind != Kind::tree) {
402 // already labelled, nothing to do. Return current state
403 return cell->state;
404 }
405 // else: need to label this cell
406
407 // Increment the cluster ID counter and label the given cell
409 cell->state.cluster_id = _cluster_id_cnt;
410
411 // Use existing cluster member container, clear it, add current cell
413 cluster.clear();
414 cluster.push_back(cell);
415
416 // Perform the percolation
417 for (unsigned int i = 0; i < cluster.size(); ++i) {
418 // Iterate over all potential cluster members c, i.e. all
419 // neighbors of cell cluster[i] that is already in the cluster
420 for (const auto& nb : this->_cm.neighbors_of(cluster[i])) {
421 // If it is a tree that is not yet in the cluster, add it.
422 if ( nb->state.cluster_id == 0
423 and nb->state.kind == Kind::tree)
424 {
425 nb->state.cluster_id = _cluster_id_cnt;
426 cluster.push_back(nb);
427 // This extends the outer for-loop...
428 }
429 }
430 }
431
432 return cell->state;
433 };

◆ _params

const Params Utopia::Models::ContDisease::ContDisease::_params
private

Model parameters.

◆ _prob_distr

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

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

◆ _update

RuleFunc Utopia::Models::ContDisease::ContDisease::_update
protected

Define the update rule.

Update the given cell according to the following rules:

  • Empty cells grow trees with probability p_growth.
  • Tree cells in neighborhood of an infected cell do not get infected with the probability p_immunity.
  • Infected cells die and become an empty cell.
339 {
340 // Get the current state of the cell and reset its cluster ID
341 auto state = cell->state;
342 state.cluster_id = 0;
343
344 // Distinguish by current state
345 if (state.kind == Kind::empty) {
346 // With a probability of p_growth, set the cell's state to tree
347 if (_prob_distr(*this->_rng) < _params.p_growth){
348 state.kind = Kind::tree;
349 return state;
350 }
351 }
352 else if (state.kind == Kind::tree){
353 // Increase the age of the tree
354 ++state.age;
355
356 // Tree can be infected by neighbor or by random-point-infection.
357
358 // Determine whether there will be a point infection
359 if (_prob_distr(*this->_rng) < _params.p_infect) {
360 // Yes, point infection occurred.
361 state.kind = Kind::infected;
362 return state;
363 }
364 else {
365 // Go through neighbor cells (according to Neighborhood type),
366 // and check if they are infected (or an infection source).
367 // If yes, infect cell with the probability 1-p_immunity.
368 for (const auto& nb: this->_cm.neighbors_of(cell)) {
369 // Get the neighbor cell's state
370 auto nb_state = nb->state;
371
372 if ( nb_state.kind == Kind::infected
373 or nb_state.kind == Kind::source)
374 {
375 // With a certain probability, become infected
376 if (_prob_distr(*this->_rng) > _params.p_immunity) {
377 state.kind = Kind::infected;
378 return state;
379 }
380 }
381 }
382 }
383 }
384 else if (state.kind == Kind::infected) {
385 // Decease -> become an empty cell
386 state.kind = Kind::empty;
387
388 // Reset the age of the cell to 0
389 state.age = 0;
390
391 return state;
392 }
393 // else: other cell states need no update
394
395 // Return the (potentially changed) cell state for the next round
396 return state;
397 };
const std::shared_ptr< RNG > _rng
The RNG shared between models.
Definition model.hh:161
const double p_growth
Probability per site and time step to go from state empty to tree.
Definition params.hh:135
const double p_immunity
Definition params.hh:139

◆ _write_only_densities

bool Utopia::Models::ContDisease::ContDisease::_write_only_densities
private

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