1#ifndef UTOPIA_MODELS_CONTDISEASE_HH
2#define UTOPIA_MODELS_CONTDISEASE_HH
51 public Model<ContDisease, CDTypes>
129 template<
class ParentModel>
131 const std::string& name,
166 _densities.fill(std::numeric_limits<double>::quiet_NaN());
174 this->
_log->info(
"Setting cells to be stones ...");
181 [](
const auto&
cell){
182 auto& state =
cell->state;
189 this->
_log->info(
"Set {} cells to be stones using selection mode "
195 if (
_cfg[
"infection_source"]
198 this->
_log->info(
"Setting cells to be infection sources ...");
202 [](
const auto&
cell){
203 auto& state =
cell->state;
210 this->
_log->info(
"Set {} cells to be infection sources using "
219 std::vector<std::string>{
220 "empty",
"tree",
"infected",
"source",
"stone"
222 this->
_log->debug(
"Added coordinates to densities dataset.");
225 this->
_log->debug(
"{} model fully set up.", this->
_name);
253 d /=
static_cast<double>(this->
_cm.
cells().size());
291 [&](
const auto&
cell){
300 std::back_inserter(
sample),
318 const auto change_p_infect =
321 if (this->
_time == change_p_infect.first) {
341 auto state =
cell->state;
342 state.cluster_id = 0;
417 for (
unsigned int i = 0;
i <
cluster.size(); ++
i) {
422 if (
nb->state.cluster_id == 0
488 [](
const auto&
cell) {
489 return static_cast<char>(cell->state.kind);
495 [](
const auto&
cell) {
496 return static_cast<unsigned short int>(cell->state.age);
503 [](
const auto&
cell) {
504 return cell->state.cluster_id;
typename std::function< CellState(const std::shared_ptr< Cell > &)> RuleFunc
The type of a rule function acting on cells of this cell manager.
Definition cell_manager.hh:84
CellContainer< Cell > select_cells(Args &&... args) const
Select cells using the Utopia::select_entities interface.
Definition cell_manager.hh:342
CellContainer< Cell > neighbors_of(const Cell &cell) const
Retrieve the given cell's neighbors.
Definition cell_manager.hh:458
const CellContainer< Cell > & cells() const
Return const reference to the managed CA cells.
Definition cell_manager.hh:219
Utopia::Cell< CDCellTraits > Cell
Type of the managed cells.
Definition cell_manager.hh:47
Base class interface for Models using the CRT Pattern.
Definition model.hh:112
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
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 Config _cfg
Config node belonging to this model instance.
Definition model.hh:158
Time _time
Model-internal current time stamp.
Definition model.hh:170
const std::string _name
Name of the model instance.
Definition model.hh:149
typename ModelTypes::DataGroup DataGroup
Data type that is used for storing datasets.
Definition model.hh:122
const std::shared_ptr< spdlog::logger > _log
The (model) logger.
Definition model.hh:164
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
Contagious disease model on a grid.
Definition ContDisease.hh:52
std::array< double, 5 > _densities
Densities for all states.
Definition ContDisease.hh:101
void update_densities()
Update the densities array.
Definition ContDisease.hh:238
RuleFunc _update
Define the update rule.
Definition ContDisease.hh:339
void identify_clusters()
Identify clusters.
Definition ContDisease.hh:263
void write_data()
Write data.
Definition ContDisease.hh:473
typename Base::DataGroup DataGroup
Data type for a data group.
Definition ContDisease.hh:58
void perform_step()
Iterate a single time step.
Definition ContDisease.hh:447
std::shared_ptr< DataSet > _dset_cluster_id
The dataset for storing the cluster ID associated with each cell.
Definition ContDisease.hh:116
RuleFunc _identify_cluster
Identify each cluster of trees.
Definition ContDisease.hh:400
void infection_control()
Apply infection control.
Definition ContDisease.hh:281
typename CellManager::RuleFunc RuleFunc
Rule function type.
Definition ContDisease.hh:73
Utopia::CellContainer< Cell > CellContainer
Type of a container of shared pointers to cells.
Definition ContDisease.hh:70
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
typename Base::DataSet DataSet
Data type for a dataset.
Definition ContDisease.hh:61
std::shared_ptr< DataSet > _dset_densities
2D dataset (densities array and time) of density values
Definition ContDisease.hh:107
void monitor()
Monitor model information.
Definition ContDisease.hh:463
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
typename CellManager::Cell Cell
Type of a cell.
Definition ContDisease.hh:67
std::uniform_real_distribution< double > _prob_distr
The range [0, 1] distribution to use for probability checks.
Definition ContDisease.hh:87
ContDisease(const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
Construct the ContDisease model.
Definition ContDisease.hh:130
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
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition types.hh:71
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
@ condition
Select if a condition is fulfilled.
@ sample
Select a random sample of entities with a known sample size.
Definition ContDisease.hh:18
@ stone
Cell cannot be infected.
@ source
Cell is an infection source: constantly infected, spreading infection.
@ infected
Cell is infected.
@ tree
Cell represents a tree.
EntityContainer< CellType > CellContainer
Type of the variably sized container for cells.
Definition types.hh:26
The entity traits struct gathers types to be used for specializing an entity.
Definition entity.hh:49
Wrapper struct for defining model class data types.
Definition model.hh:92
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
const bool enabled
Whether infection control is enabled.
Definition params.hh:24
Parameters of the ContDisease.
Definition params.hh:133
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
double p_infect
Definition params.hh:143
const InfectionContParams infection_control
Infection control parameters.
Definition params.hh:146