Model< FP, LctStates > Class Template Reference

CPP API: mio::lsecir2d::Model< FP, LctStates > Class Template Reference
mio::lsecir2d::Model< FP, LctStates > Class Template Reference

Class that defines an LCT-SECIR-2-DISEASE model. More...

#include <model.h>

Inheritance diagram for mio::lsecir2d::Model< FP, LctStates >:
Collaboration diagram for mio::lsecir2d::Model< FP, LctStates >:

Public Types

using Base = CompartmentalModel< FP, InfectionState, LctPopulations< FP, LctStates... >, Parameters< FP > >
 
using LctStatesGroups = TypeList< LctStates... >
 
- Public Types inherited from mio::CompartmentalModel< FP, InfectionState, LctPopulations< FP, LctStates... >, Parameters< FP > >
using Compartments = InfectionState
 
using ParameterSet = Parameters< FP >
 
using Populations = LctPopulations< FP, LctStates... >
 

Public Member Functions

TimeSeries< FP > calculate_compartments (const TimeSeries< FP > &subcompartments_ts) const
 Cumulates a simulation result with subcompartments to produce a result that divides the population only into the infection states defined in InfectionState. More...
 
bool check_constraints () const
 Checks that the model satisfies all constraints (e.g. More...
 
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). More...
 
 Model ()
 Default constructor. More...
 
 Model (const Populations &pop, const ParameterSet &params)
 Constructor using Populations and ParameterSet. More...
 
- Public Member Functions inherited from mio::CompartmentalModel< FP, InfectionState, LctPopulations< FP, LctStates... >, Parameters< FP > >
bool apply_constraints ()
 Checks whether the model satisfies all constraints. More...
 
bool check_constraints () const
 Checks that the model satisfies all constraints (e.g. More...
 
 CompartmentalModel (CompartmentalModel &&)=default
 
 CompartmentalModel (const CompartmentalModel &)=default
 
 CompartmentalModel (Populations const &po, ParameterSet const &pa)
 CompartmentalModel default constructor. More...
 
void eval_right_hand_side (Eigen::Ref< const Eigen::VectorX< FP >> pop, Eigen::Ref< const Eigen::VectorX< FP >> y, FP t, Eigen::Ref< Eigen::VectorX< FP >> dydt) const
 This function evaluates the right-hand-side f of the ODE dydt = f(y, t). More...
 
Eigen::VectorX< FP > get_initial_values () const
 Get the initial conditions for the ODE dydt = f(y, t). More...
 
CompartmentalModeloperator= (CompartmentalModel &&)=default
 
CompartmentalModeloperator= (const CompartmentalModel &)=default
 
virtual ~CompartmentalModel ()=default
 

Static Public Attributes

static constexpr size_t num_groups = sizeof...(LctStates)
 

Private Member Functions

template<size_t Group = 0>
bool check_constraints_impl () const
 Checks whether LctState of a group satisfies all constraints. More...
 
template<size_t Group = 0>
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 subcompartment values. More...
 
template<size_t Group = 0>
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. More...
 
template<size_t Group1, size_t Group2 = 0>
void interact (Eigen::Ref< const Eigen::VectorX< FP >> pop, Eigen::Ref< const Eigen::VectorX< FP >> y, FP t, Eigen::Ref< Eigen::VectorX< FP >> dydt, double *part_a, double *part_b, int relevant_disease) const
 Calculates flows that are caused by people becoming infected (outflow from compartment S, Ra or Rb) for Group1. More...
 

Additional Inherited Members

- Public Attributes inherited from mio::CompartmentalModel< FP, InfectionState, LctPopulations< FP, LctStates... >, Parameters< FP > >
ParameterSet parameters
 
Populations populations
 

Detailed Description

template<typename FP, class... LctStates>
class mio::lsecir2d::Model< FP, LctStates >

Class that defines an LCT-SECIR-2-DISEASE model.

Template Parameters
LctStatesThe LCT2D model can work with any number of LctStates, where each LctState corresponds to a group, e.g. one AgeGroup. The purpose of the LctStates is to define the number of subcompartments for each InfectionState. If you do not want to divide the population into groups, just use one LctState. If you want to divide the population according to more than one category, e.g. sex and age, you have to specify one LctState for each pair of groups, e.g. for (female, A00-A04), (female, A05-A14) etc. This is because the number of subcompartments can be different for each group. Therefore, the number of LctStates also determines the number of groups.

Member Typedef Documentation

◆ Base

template<typename FP , class... LctStates>
using mio::lsecir2d::Model< FP, LctStates >::Base = CompartmentalModel<FP, InfectionState, LctPopulations<FP, LctStates...>, Parameters<FP> >

◆ LctStatesGroups

template<typename FP , class... LctStates>
using mio::lsecir2d::Model< FP, LctStates >::LctStatesGroups = TypeList<LctStates...>

Constructor & Destructor Documentation

◆ Model() [1/2]

template<typename FP , class... LctStates>
mio::lsecir2d::Model< FP, LctStates >::Model ( )
inline

Default constructor.

◆ Model() [2/2]

template<typename FP , class... LctStates>
mio::lsecir2d::Model< FP, LctStates >::Model ( const Populations pop,
const ParameterSet params 
)
inline

Constructor using Populations and ParameterSet.

Parameters
[in]popAn instance of the Populations class.
[in]paramsParameters used to be used in the simulation.

Member Function Documentation

◆ calculate_compartments()

template<typename FP , class... LctStates>
TimeSeries<FP> mio::lsecir2d::Model< FP, LctStates >::calculate_compartments ( const TimeSeries< FP > &  subcompartments_ts) const
inline

Cumulates a simulation result with subcompartments to produce a result that divides the population only into the infection states defined in InfectionState.

If the model is used for simulation, we will get a result in form of a TimeSeries with infection states divided in subcompartments. The function calculates a TimeSeries without subcompartments from another TimeSeries with subcompartments. This is done by summing up the numbers in the subcompartments.

Parameters
[in]subcompartments_tsResult of a simulation with the model.
Returns
Result of the simulation divided in infection states without subcompartments. Returns TimeSeries with values -1 if calculation is not possible.

◆ check_constraints()

template<typename FP , class... LctStates>
bool mio::lsecir2d::Model< FP, LctStates >::check_constraints ( ) const
inline

Checks that the model satisfies all constraints (e.g.

parameter or population constraints).

Returns
Returns true if one or more constraints are not satisfied, false otherwise.

◆ check_constraints_impl()

template<typename FP , class... LctStates>
template<size_t Group = 0>
bool mio::lsecir2d::Model< FP, LctStates >::check_constraints_impl ( ) const
inlineprivate

Checks whether LctState of a group satisfies all constraints.

Recursively, it checks that all groups satisfy the constraints.

Template Parameters
groupThe group for which the constraints should be checked.
Returns
Returns true if one or more constraints are not satisfied, false otherwise.

◆ compress_vector()

template<typename FP , class... LctStates>
template<size_t Group = 0>
void mio::lsecir2d::Model< FP, LctStates >::compress_vector ( const Eigen::VectorX< FP > &  subcompartments,
Eigen::VectorX< FP > &  compartments 
) const
inlineprivate

Converts a vector with subcompartments in a vector without subcompartments by summing up subcompartment values.

This is done recursively for each group which corresponds to a slice of the vector.

Template Parameters
groupThe group specifying the slice of the vector being considered.
Parameters
[in]subcompartmentsThe vector that should be converted.
[out]compartmentsReference to the vector where the output is stored.

◆ get_derivatives()

template<typename FP , class... LctStates>
void mio::lsecir2d::Model< FP, LctStates >::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
inlineoverridevirtual

Evaluates the right-hand-side f of the ODE dydt = f(y, t).

The LCT-SECIR-2-DISEASE model is defined through ordinary differential equations of the form dydt = f(y, t). y is a vector containing the number of individuals for each (sub-) compartment. This function evaluates the right-hand-side f of the ODE and can be used in an ODE solver.

Parameters
[in]popThe current state of the population in the geographic unit we are considering.
[in]yThe current state of the model (or a subpopulation) as a flat array.
[in]tThe current time.
[out]dydtA reference to the calculated output.

Reimplemented from mio::CompartmentalModel< FP, InfectionState, LctPopulations< FP, LctStates... >, Parameters< FP > >.

◆ get_derivatives_impl()

template<typename FP , class... LctStates>
template<size_t Group = 0>
void mio::lsecir2d::Model< FP, LctStates >::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
inlineprivate

Evaluates the right-hand-side f of the ODE dydt = f(y, t) recursively for each group.

See also the function get_derivative. For each group, one slice of the output vector is calculated.

Template Parameters
groupThe group specifying the slice of the vector being considered.
Parameters
[in]popThe current state of the population in the geographic unit we are considering.
[in]yThe current state of the model (or a subpopulation) as a flat array.
[in]tThe current time.
[out]dydtA reference to the calculated output.

◆ interact()

template<typename FP , class... LctStates>
template<size_t Group1, size_t Group2 = 0>
void mio::lsecir2d::Model< FP, LctStates >::interact ( Eigen::Ref< const Eigen::VectorX< FP >>  pop,
Eigen::Ref< const Eigen::VectorX< FP >>  y,
FP  t,
Eigen::Ref< Eigen::VectorX< FP >>  dydt,
double *  part_a,
double *  part_b,
int  relevant_disease 
) const
inlineprivate

Calculates flows that are caused by people becoming infected (outflow from compartment S, Ra or Rb) for Group1.

This is done recursively by calculating the interaction terms with each group.

Template Parameters
Group1The group for which the derivative of the compartment should be calculated.
Group2The group that Group1 interacts with.
Parameters
[in]popThe current state of the population in the geographic unit we are considering.
[in]yThe current state of the model (or a subpopulation) as a flat array.
[in]tThe current time.
[out]dydtA reference to the calculated output. The flow from Susceptible needs to be split into 2 parts for Exposed_1a and Exposed_1b:
[out]part_aReference to amount of flow caused by people infected with disease a.
[out]part_bReference to amount of flow caused by people infected with disease b.
[in]relevant_diseaseIndex for which infected people cause the outflow (0 = a, 1 = b, 2 = a and b).

Member Data Documentation

◆ num_groups

template<typename FP , class... LctStates>
constexpr size_t mio::lsecir2d::Model< FP, LctStates >::num_groups = sizeof...(LctStates)
staticconstexpr