model.h Source File
|
CPP API
|
lct_secir/model.h
Go to the documentation of this file.
54 class Model : public CompartmentalModel<FP, InfectionState, LctPopulations<FP, LctStates...>, Parameters<FP>>
58 using Base = CompartmentalModel<FP, InfectionState, LctPopulations<FP, LctStates...>, Parameters<FP>>;
90 void get_derivatives(Eigen::Ref<const Eigen::VectorX<FP>> pop, Eigen::Ref<const Eigen::VectorX<FP>> y, FP t,
116 if (!(this->populations.get_num_compartments() == (size_t)subcompartments_ts.get_num_elements())) {
123 for (Eigen::Index timepoint = 0; timepoint < subcompartments_ts.get_num_time_points(); ++timepoint) {
153 void compress_vector(const Eigen::VectorX<FP>& subcompartments, Eigen::VectorX<FP>& compartments) const
155 static_assert((Group < num_groups) && (Group >= 0), "The template parameter Group should be valid.");
158 // Define first index of the group Group in a vector including all compartments without a resolution
187 void get_derivatives_impl(Eigen::Ref<const Eigen::VectorX<FP>> pop, Eigen::Ref<const Eigen::VectorX<FP>> y, FP t,
190 static_assert((Group < num_groups) && (Group >= 0), "The template parameter Group should be valid.");
198 size_t Ei_first_index = first_index_group + LctStateGroup::template get_first_index<InfectionState::Exposed>();
200 first_index_group + LctStateGroup::template get_first_index<InfectionState::InfectedNoSymptoms>();
202 first_index_group + LctStateGroup::template get_first_index<InfectionState::InfectedSymptoms>();
206 first_index_group + LctStateGroup::template get_first_index<InfectionState::InfectedCritical>();
207 size_t Ri = first_index_group + LctStateGroup::template get_first_index<InfectionState::Recovered>();
208 size_t Di = first_index_group + LctStateGroup::template get_first_index<InfectionState::Dead>();
215 for (size_t subcomp = 0; subcomp < LctStateGroup::template get_num_subcompartments<InfectionState::Exposed>();
218 // Ei_first_index + subcomp is always the index of a (sub-)compartment of Exposed and Ei_first_index
229 subcomp < LctStateGroup::template get_num_subcompartments<InfectionState::InfectedNoSymptoms>();
231 flow = (FP)LctStateGroup::template get_num_subcompartments<InfectionState::InfectedNoSymptoms>() *
240 dydt[Ri] = dydt[ISyi_first_index] * params.template get<RecoveredPerInfectedNoSymptoms<FP>>()[Group];
242 dydt[ISyi_first_index] * (1 - params.template get<RecoveredPerInfectedNoSymptoms<FP>>()[Group]);
244 subcomp < LctStateGroup::template get_num_subcompartments<InfectionState::InfectedSymptoms>(); subcomp++) {
245 flow = (FP)LctStateGroup::template get_num_subcompartments<InfectionState::InfectedSymptoms>() *
252 dydt[Ri] += dydt[ISevi_first_index] * (1 - params.template get<SeverePerInfectedSymptoms<FP>>()[Group]);
253 dydt[ISevi_first_index] = dydt[ISevi_first_index] * params.template get<SeverePerInfectedSymptoms<FP>>()[Group];
255 subcomp < LctStateGroup::template get_num_subcompartments<InfectionState::InfectedSevere>(); subcomp++) {
264 dydt[ICri_first_index] = dydt[ICri_first_index] * params.template get<CriticalPerSevere<FP>>()[Group];
266 subcomp < LctStateGroup::template get_num_subcompartments<InfectionState::InfectedCritical>() - 1;
268 flow = (FP)LctStateGroup::template get_num_subcompartments<InfectionState::InfectedCritical>() *
274 // Must be calculated separately in order not to overwrite the already calculated values for Recovered.
275 flow = (FP)LctStateGroup::template get_num_subcompartments<InfectionState::InfectedCritical>() *
299 void interact(Eigen::Ref<const Eigen::VectorX<FP>> pop, Eigen::Ref<const Eigen::VectorX<FP>> y, FP t,
352 static_assert((Group < num_groups) && (Group >= 0), "The template parameter Group should be valid.");
356 log_warning("Constraint check: The number of subcompartments for Susceptibles of group {} should be one!",
361 log_warning("Constraint check: The number of subcompartments for Recovered of group {} should be one!",
366 log_warning("Constraint check: The number of subcompartments for Dead of group {} should be one!", Group);
A class template for compartment populations of LCT models.
Definition: lct_populations.h:57
size_t get_num_compartments() const
get_num_compartments Returns the number of compartments.
Definition: lct_populations.h:75
stores vectors of values at time points (or some other abstract variable) the value at each time poin...
Definition: time_series.h:58
Eigen::Index get_num_elements() const
number of elements of vector at each time point
Definition: time_series.h:205
Eigen::Index get_num_time_points() const
number of time points in the series
Definition: time_series.h:197
FP & get_time(Eigen::Index i)
time of time point at index i
Definition: time_series.h:272
Eigen::Ref< Vector > add_time_point()
add one uninitialized time point
Definition: time_series.h:221
Parameters of the simulation that are the same everywhere within the Model.
Definition: abm/parameters.h:764
bool check_constraints() const
Checks whether all Parameters satisfy their corresponding constraints and logs an error if constraint...
Definition: abm/parameters.h:793
void compress_vector(const Eigen::VectorX< FP > &subcompartments, Eigen::VectorX< FP > &compartments) const
Converts a vector with subcompartments in a vector without subcompartments by summing up subcompartme...
Definition: lct_secir/model.h:153
bool check_constraints() const
Checks that the model satisfies all constraints (e.g.
Definition: lct_secir/model.h:135
void get_derivatives_impl(Eigen::Ref< const Eigen::VectorX< FP >> pop, Eigen::Ref< const Eigen::VectorX< FP >> y, FP t, Eigen::Ref< Eigen::VectorX< FP >> dydt) const
Evaluates the right-hand-side f of the ODE dydt = f(y, t) recursively for each group.
Definition: lct_secir/model.h:187
void interact(Eigen::Ref< const Eigen::VectorX< FP >> pop, Eigen::Ref< const Eigen::VectorX< FP >> y, FP t, Eigen::Ref< Eigen::VectorX< FP >> dydt) const
Calculates the derivative of the Susceptible compartment for Group1.
Definition: lct_secir/model.h:299
TimeSeries< FP > calculate_compartments(const TimeSeries< FP > &subcompartments_ts) const
Cumulates a simulation result with subcompartments to produce a result that divides the population on...
Definition: lct_secir/model.h:111
void get_derivatives(Eigen::Ref< const Eigen::VectorX< FP >> pop, Eigen::Ref< const Eigen::VectorX< FP >> y, FP t, Eigen::Ref< Eigen::VectorX< FP >> dydt) const override
Evaluates the right-hand-side f of the ODE dydt = f(y, t).
Definition: lct_secir/model.h:90
bool check_constraints_impl() const
Checks whether LctState of a group satisfies all constraints.
Definition: lct_secir/model.h:350
Model(const Populations &pop, const ParameterSet ¶ms)
Constructor using Populations and ParameterSet.
Definition: lct_secir/model.h:74
ad::internal::unary_intermediate< AD_TAPE_REAL, ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 >, ad::operations::ad_sin< AD_TAPE_REAL > > sin(const ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > &x1)
Definition: ad.hpp:913
InfectionState
The InfectionState enum describes the basic categories for the infection state of persons.
Definition: lct_secir/infection_state.h:34
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
void log_warning(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:112
typename type_at_index< Index, Types... >::type type_at_index_t
The type at the Index-th position in the list Types.
Definition: metaprogramming.h:118
void log_error(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:100
constexpr std::tuple_element< I, std::tuple< Index< CategoryTags >... > >::type & get(Index< CategoryTags... > &i) noexcept
Retrieves the Index (by reference) at the Ith position of a MultiIndex.
Definition: index.h:294
CompartmentalModel is a template for a compartmental model for an array of initial populations and a ...
Definition: compartmental_model.h:59
Populations populations
Definition: compartmental_model.h:156
LctPopulations< FP, LctStates... > Populations
Definition: compartmental_model.h:62
Parameters< FP > ParameterSet
Definition: compartmental_model.h:63
ParameterSet parameters
Definition: compartmental_model.h:157
Collection of types. Each type is mapped to an index of type size_t.
Definition: type_list.h:32
The contact patterns within the society are modelled using an UncertainContactMatrix.
Definition: lct_secir/parameters.h:143
The risk of infection from symptomatic cases for each group in the SECIR model.
Definition: lct_secir/parameters.h:179
Generated by