CompartmentalModel< FP, Comp, Pop, Params > Struct Template Reference

CPP API: mio::CompartmentalModel< FP, Comp, Pop, Params > Struct Template Reference
mio::CompartmentalModel< FP, Comp, Pop, Params > Struct Template Reference

CompartmentalModel is a template for a compartmental model for an array of initial populations and a parameter set. More...

#include <compartmental_model.h>

Inheritance diagram for mio::CompartmentalModel< FP, Comp, Pop, Params >:

Public Types

using Compartments = Comp
 
using ParameterSet = Params
 
using Populations = Pop
 

Public Member Functions

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...
 
virtual void get_derivatives (Eigen::Ref< const Eigen::VectorX< FP >>, Eigen::Ref< const Eigen::VectorX< FP >>, FP, Eigen::Ref< Eigen::VectorX< FP >>) const
 
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
 

Public Attributes

ParameterSet parameters {}
 
Populations populations {}
 

Detailed Description

template<typename FP, class Comp, class Pop, class Params>
struct mio::CompartmentalModel< FP, Comp, Pop, Params >

CompartmentalModel is a template for a compartmental model for an array of initial populations and a parameter set.

Template Parameters
FPA floating point type, e.g., double.

The Populations must be a concrete class derived from the Populations template, i.e. a multi-dimensional array of compartment populations where each dimension corresponds to a category.

The ParameterSet must be a concrete class derived form the ParameterSet template, i.e. a compile-time map of parameters used by the model. These can be referenced when defining the flows between compartments and they can be used for parameter studies.

Member Typedef Documentation

◆ Compartments

template<typename FP , class Comp , class Pop , class Params >
using mio::CompartmentalModel< FP, Comp, Pop, Params >::Compartments = Comp

◆ ParameterSet

template<typename FP , class Comp , class Pop , class Params >
using mio::CompartmentalModel< FP, Comp, Pop, Params >::ParameterSet = Params

◆ Populations

template<typename FP , class Comp , class Pop , class Params >
using mio::CompartmentalModel< FP, Comp, Pop, Params >::Populations = Pop

Constructor & Destructor Documentation

◆ CompartmentalModel() [1/3]

template<typename FP , class Comp , class Pop , class Params >
mio::CompartmentalModel< FP, Comp, Pop, Params >::CompartmentalModel ( Populations const &  po,
ParameterSet const &  pa 
)
inline

CompartmentalModel default constructor.

◆ CompartmentalModel() [2/3]

template<typename FP , class Comp , class Pop , class Params >
mio::CompartmentalModel< FP, Comp, Pop, Params >::CompartmentalModel ( const CompartmentalModel< FP, Comp, Pop, Params > &  )
default

◆ CompartmentalModel() [3/3]

template<typename FP , class Comp , class Pop , class Params >
mio::CompartmentalModel< FP, Comp, Pop, Params >::CompartmentalModel ( CompartmentalModel< FP, Comp, Pop, Params > &&  )
default

◆ ~CompartmentalModel()

template<typename FP , class Comp , class Pop , class Params >
virtual mio::CompartmentalModel< FP, Comp, Pop, Params >::~CompartmentalModel ( )
virtualdefault

Member Function Documentation

◆ apply_constraints()

template<typename FP , class Comp , class Pop , class Params >
bool mio::CompartmentalModel< FP, Comp, Pop, Params >::apply_constraints ( )
inline

Checks whether the model satisfies all constraints.

If not, it changes values to suffice their constraints.

Attention: This function should be used with care. It can not and will not set model parameters and compartments to meaningful values. In most cases it is preferable to use check_constraints, and correct values manually before proceeding with the simulation. The main usage for apply_constraints is in automated tests using random values for initialization.

Returns
Returns true if one or more constraints were corrected, false otherwise.

◆ check_constraints()

template<typename FP , class Comp , class Pop , class Params >
bool mio::CompartmentalModel< FP, Comp, Pop, Params >::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.

◆ eval_right_hand_side()

template<typename FP , class Comp , class Pop , class Params >
void mio::CompartmentalModel< FP, Comp, Pop, Params >::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
inline

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

The heart of the compartmental model is a first order ODE dydt = f(y,t), where y is a flat representation of all the compartmental populations at time t. This function evaluates the right-hand-side f of the ODE from the intercompartmental flows. It can be used in an ODE solver.

The distinction between pop and y is only for the case of mobility. If we have mobility, we want to evaluate the evolution of infection states for a small group of travellers (y) while they are in any population (pop). It is important that pop > y always applies.

If we consider a simulation without mobility, the function is called with model.eval_right_hand_side(y, y, t, dydt).

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.

◆ get_derivatives()

◆ get_initial_values()

template<typename FP , class Comp , class Pop , class Params >
Eigen::VectorX<FP> mio::CompartmentalModel< FP, Comp, Pop, Params >::get_initial_values ( ) const
inline

Get the initial conditions for the ODE dydt = f(y, t).

See eval_right_hand_side for more detail.

Returns
Current value of model populations as a flat vector.

◆ operator=() [1/2]

template<typename FP , class Comp , class Pop , class Params >
CompartmentalModel& mio::CompartmentalModel< FP, Comp, Pop, Params >::operator= ( CompartmentalModel< FP, Comp, Pop, Params > &&  )
default

◆ operator=() [2/2]

template<typename FP , class Comp , class Pop , class Params >
CompartmentalModel& mio::CompartmentalModel< FP, Comp, Pop, Params >::operator= ( const CompartmentalModel< FP, Comp, Pop, Params > &  )
default

Member Data Documentation

◆ parameters

template<typename FP , class Comp , class Pop , class Params >
ParameterSet mio::CompartmentalModel< FP, Comp, Pop, Params >::parameters {}

◆ populations

template<typename FP , class Comp , class Pop , class Params >
Populations mio::CompartmentalModel< FP, Comp, Pop, Params >::populations {}