1#ifndef UTOPIA_MODELS_SEIRD_HH
2#define UTOPIA_MODELS_SEIRD_HH
135 template<
class ParentModel>
183 _densities.fill(std::numeric_limits<double>::quiet_NaN());
193 this->
_log->info(
"Setting cells to be inert ...");
200 [](
const auto&
cell) {
201 auto& state =
cell->state;
207 this->
_log->info(
"Set {} cells to be inert using selection mode "
214 if (
_cfg[
"infection_source"]
and
217 this->
_log->info(
"Setting cells to be infection sources ...");
221 [](
const auto&
cell) {
222 auto& state =
cell->state;
229 "Set {} cells to be infection sources using "
230 "selection mode '{}'.",
237 this->
_log->debug(
"Stored metadata in 'kind' dataset.");
245 _dset_counts->add_attribute(
"coords_mode__label",
"values");
248 this->
_log->debug(
"Added coordinate labels to 'densities' and "
249 "'counts' datasets.");
252 this->
_log->info(
"{} model fully set up.", this->
_name);
253 this->
_log->info(
" Writing CA data? {}",
284 d /=
static_cast<double>(this->
_cm.
cells().size());
322 [&](
const auto&
cell) {
330 std::back_inserter(
sample),
348 const auto change_p_exposed =
351 if (this->
_time == change_p_exposed.first) {
382 [&](
const auto&
cell) {
390 std::back_inserter(
sample),
396 cell->state.immune =
true;
407 const auto change_p_immune =
410 if (this->
_time == change_p_immune.first) {
434 const auto change_p_transmit =
438 const auto num_cells = std::get<1>(change_p_transmit);
439 const auto cell_kind = std::get<2>(change_p_transmit);
440 const auto p_transmit = std::get<3>(change_p_transmit);
446 [&](
const auto&
cell) {
454 std::back_inserter(
sample),
460 cell->state.p_transmit = p_transmit;
482 auto state =
cell->state;
483 state.cluster_id = 0;
500 state.num_recoveries = 0;
501 state.immune =
false;
520 state.immune =
false;
530 state.num_recoveries = 0;
608 ++state.exposed_time;
613 ++state.num_recoveries;
633 state.immune =
false;
643 state.immune =
false;
644 state.num_recoveries = 0;
659 if (
cell->state.cluster_id != 0
or
677 for (
unsigned int i = 0;
i <
cluster.size(); ++
i) {
682 if (
nb->state.cluster_id == 0
and
702 auto& state =
cell->state;
715 std::swap(state,
_nb->state);
738 auto& state =
cell->state;
758 std::swap(state,
_nb->state);
842 [](
const auto&
cell) {
843 return static_cast<char>(cell->state.kind);
849 [](
const auto&
cell) {
850 return static_cast<char>(cell->state.immune);
856 [](
const auto&
cell) {
857 return static_cast<unsigned short>(
858 cell->state.num_recoveries);
864 [](
const auto&
cell) {
865 return cell->state.age;
872 [](
const auto&
cell) {
873 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
SEIRD model on a grid.
Definition SEIRD.hh:41
const Params _params
Model parameters.
Definition SEIRD.hh:73
std::shared_ptr< DataSet > _dset_kind
2D dataset (cell ID and time) of cell kinds
Definition SEIRD.hh:110
unsigned int _cluster_id_cnt
The incremental cluster tag.
Definition SEIRD.hh:79
typename CellManager::Cell Cell
Type of a cell.
Definition SEIRD.hh:56
typename Base::DataGroup DataGroup
Data type for a data group.
Definition SEIRD.hh:47
std::array< double, static_cast< char >(Kind::COUNT)> _densities
Densities for all states.
Definition SEIRD.hh:90
std::shared_ptr< DataSet > _dset_age
2D dataset (cell ID and time) of cell's age
Definition SEIRD.hh:119
void monitor()
Monitor model information.
Definition SEIRD.hh:817
Utopia::CellContainer< Cell > CellContainer
Type of a container of shared pointers to cells.
Definition SEIRD.hh:59
void identify_clusters()
Identify clusters.
Definition SEIRD.hh:293
void immunity_control()
Apply immunity control.
Definition SEIRD.hh:371
std::vector< std::shared_ptr< CellManager::Cell > > _cluster_members
A temporary container for use in cluster identification.
Definition SEIRD.hh:82
void transmission_control()
Apply transmission control.
Definition SEIRD.hh:427
typename Base::DataSet DataSet
Data type for a dataset.
Definition SEIRD.hh:50
RuleFunc _identify_cluster
Identify each cluster of susceptibles.
Definition SEIRD.hh:658
std::shared_ptr< DataSet > _dset_num_recoveries
2D dataset (cell ID and time) of cell's number of recoveries
Definition SEIRD.hh:116
Counters< std::size_t > _counts
Cumulative counters for state transitions and other events
Definition SEIRD.hh:93
RuleFunc _move_randomly
Move randomly to a neighboring cell if that cell is empty.
Definition SEIRD.hh:736
void write_data()
Write data.
Definition SEIRD.hh:825
std::shared_ptr< DataSet > _dset_immune
2D dataset (cell ID and time) of cell's immunity
Definition SEIRD.hh:113
RuleFunc _move_away_from_infected
Move the agent on the cell away from an infected neighboring cell.
Definition SEIRD.hh:700
CellManager _cm
The cell manager.
Definition SEIRD.hh:70
typename CellManager::RuleFunc RuleFunc
Rule function type.
Definition SEIRD.hh:62
std::uniform_real_distribution< double > _prob_distr
The range [0, 1] distribution to use for probability checks.
Definition SEIRD.hh:76
void perform_step()
Iterate a single time step.
Definition SEIRD.hh:779
SEIRD(const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
Construct the SEIRD model.
Definition SEIRD.hh:136
void exposure_control()
Apply exposure control.
Definition SEIRD.hh:311
void update_densities()
Update the densities array.
Definition SEIRD.hh:268
bool _write_ca_data
If false, writes only the non-spatial densities and counts data.
Definition SEIRD.hh:101
std::shared_ptr< DataSet > _dset_densities
2D dataset (densities array and time) of density values
Definition SEIRD.hh:104
const int _compression
The compression level used for all datasets.
Definition SEIRD.hh:98
std::shared_ptr< DataSet > _dset_counts
2D dataset (counts array and time) of cumulative state counters
Definition SEIRD.hh:107
std::shared_ptr< DataSet > _dset_cluster_id
The dataset for storing the cluster ID associated with each cell.
Definition SEIRD.hh:122
Model< SEIRD, CDTypes > Base
The base model type.
Definition SEIRD.hh:44
RuleFunc _update
Define the update rule.
Definition SEIRD.hh:480
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
@ neighbors
Iterate over neighbors (adjacent_vertices).
@ condition
Select if a condition is fulfilled.
@ sample
Select a random sample of entities with a known sample size.
Definition counters.hh:10
const std::array< std::string, static_cast< char >(Kind::COUNT)> kind_names
The associated string names of each Kind enum entry.
Definition state.hh:76
@ source
Cell is an infection source: constantly infected, spreading infection.
@ inert
Cell does not partake in the dynamics.
@ COUNT
The number of kinds (COUNT)
@ recovered
Cell is recovered.
@ infected
Cell is infected.
@ deceased
Cell is deceased.
@ exposed
Cell is exposed to the dease but not yet infected.
@ susceptible
Cell represents a susceptible.
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
A struct holding counters for state transitions and other global counters.
Definition counters.hh:21
void increment_susceptible_to_exposed_random()
Increment counter for transitions from susceptible to exposed (random)
Definition counters.hh:78
void increment_infected_to_recovered()
Increment counter for transitions from infected to recovered.
Definition counters.hh:93
const auto & labels()
The labels cooresponding to each entry of the counts array.
Definition counters.hh:58
void increment_empty_to_susceptible()
Increment counter for transitions from empty to susceptible.
Definition counters.hh:63
void increment_recovered_to_susceptible()
Increment counter for transitions from recovered to susceptible.
Definition counters.hh:103
static constexpr std::size_t size
Number of counters.
Definition counters.hh:25
void increment_move_randomly()
Increment counter for random movement events.
Definition counters.hh:108
void increment_susceptible_to_exposed_controlled()
Increment counter for transitions from susceptible to exposed (control)
Definition counters.hh:83
void increment_infected_to_deceased()
Increment counter for transitions from infected to deceased.
Definition counters.hh:98
auto counts()
Return a copy of the current value of all counts.
Definition counters.hh:53
void increment_living_to_empty()
Increment counter for transitions from living to empty.
Definition counters.hh:68
void increment_move_away_from_infected()
Increment counter for movement events away from an infected agent.
Definition counters.hh:113
void increment_exposed_to_infected()
Increment counter for transitions from exposed to infected.
Definition counters.hh:88
void increment_susceptible_to_exposed_contact()
Increment counter for transitions from susceptible to exposed (contact)
Definition counters.hh:73
TimesQueue at_times
Add additional exposures at these time steps.
Definition params.hh:32
const std::size_t num_additional_exposures
The number of exposures added to the default p_expose.
Definition params.hh:29
const bool enabled
Whether exposure control is enabled.
Definition params.hh:26
TimesValuesQueue change_p_exposed
Change p_expose to new value at given times.
Definition params.hh:39
const std::size_t num_additional_immunities
The number of immunities added to the default p_expose.
Definition params.hh:114
TimesValuesQueue change_p_immune
Change p_immune to new value at given times.
Definition params.hh:124
TimesQueue at_times
Add additional immunities at these time steps.
Definition params.hh:117
const bool enabled
Whether immunity control is enabled.
Definition params.hh:111
Parameters of the SEIRD.
Definition params.hh:261
double p_deceased
Probability for a cell to desease.
Definition params.hh:287
double p_lose_immunity
The probability to loose immunity if a cell is recovered.
Definition params.hh:293
const double p_susceptible
Probability per site and time step to go from state empty to susceptible.
Definition params.hh:263
const ImmunityContParams immunity_control
Immunity control parameters.
Definition params.hh:305
bool move_away_from_infected
Whether to globally allow moving away from infected neighboring cells.
Definition params.hh:296
double p_move_randomly
Probability to move randomly if the neighboring cell is empty.
Definition params.hh:299
const double p_random_immunity
Definition params.hh:270
double p_immune
Probability per transition to susceptible via p_susceptible to be immune.
Definition params.hh:266
double p_exposed
Definition params.hh:274
const TransmitContParams transmission_control
Transmit control parameters.
Definition params.hh:308
double p_empty
Probability for a cell to become empty.
Definition params.hh:290
double p_infected
Definition params.hh:281
double p_recovered
Probability for a cell to recover.
Definition params.hh:284
const ExposureContParams exposure_control
Exposure control parameters.
Definition params.hh:302
static double initialize_p_transmit(const DataIO::Config &cfg, const std::shared_ptr< RNG > &rng)
Initialize p_transmit from a configuration node.
Definition state.hh:171
const bool enabled
Whether immunity control is enabled.
Definition params.hh:197
TimesValuesQueue change_p_transmit
Change p_transmit to new value at given times.
Definition params.hh:205