SimulationBase< FP, M, Integrands > Class Template Reference

CPP API: mio::details::SimulationBase< FP, M, Integrands > Class Template Reference
mio::details::SimulationBase< FP, M, Integrands > Class Template Reference

Base class to define a Simulation. More...

#include <simulation_base.h>

Collaboration diagram for mio::details::SimulationBase< FP, M, Integrands >:

Public Types

using Core = IntegratorCore< FP, Integrands... >
 
using Model = M
 

Public Member Functions

SimulationBaseoperator= (const SimulationBase &other)
 
void set_integrator_core (std::unique_ptr< Core > &&integrator_core)
 Set the IntegratorCore used in the simulation. More...
 
 SimulationBase (const SimulationBase &other)
 
 SimulationBase (Model const &model, std::unique_ptr< Core > &&integrator_core, FP t0, FP dt)
 Create a SimulationBase. More...
 
Coreget_integrator_core ()
 Access the IntegratorCore used in the simulation. More...
 
const Coreget_integrator_core () const
 Access the IntegratorCore used in the simulation. More...
 
TimeSeries< FP > & get_result ()
 Returns the simulation result describing the model population in each time step. More...
 
const TimeSeries< FP > & get_result () const
 Returns the simulation result describing the model population in each time step. More...
 
const Modelget_model () const
 Get a reference to the model owned and used by the simulation. More...
 
Modelget_model ()
 Get a reference to the model owned and used by the simulation. More...
 
FP & get_dt ()
 Returns the step size used by the integrator. More...
 
const FP & get_dt () const
 Returns the step size used by the integrator. More...
 

Protected Member Functions

Eigen::Ref< Eigen::VectorX< FP > > advance (const Integrands &... fs, FP tmax, TimeSeries< FP > &results)
 Run the simulation up to a given time. More...
 

Private Attributes

FP m_dt
 The time step used (and possibly set) by m_integrator::m_core::step. More...
 
SystemIntegrator< FP, Integrands... > m_integrator
 Integrates the DerivFunction (see advance) and stores resutls in m_result. More...
 
std::unique_ptr< Modelm_model
 The model defining the ODE system and initial conditions. More...
 
TimeSeries< FP > m_result
 The simulation results. More...
 

Detailed Description

template<typename FP, IsCompartmentalModel< FP > M, class... Integrands>
class mio::details::SimulationBase< FP, M, Integrands >

Base class to define a Simulation.

Provides a protected advance method that accepts the specified integrands, that must be exposed by the Derived class. Also defines all relevant members and accessors for a Simulation.

Template Parameters
FPA floating point type, e.g. double.
MAn implementation of CompartmentalModel.
IntegrandsOne or more function types used for defining the right hand side of a system of equations.

Member Typedef Documentation

◆ Core

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
using mio::details::SimulationBase< FP, M, Integrands >::Core = IntegratorCore<FP, Integrands...>

◆ Model

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
using mio::details::SimulationBase< FP, M, Integrands >::Model = M

Constructor & Destructor Documentation

◆ SimulationBase() [1/2]

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
mio::details::SimulationBase< FP, M, Integrands >::SimulationBase ( Model const &  model,
std::unique_ptr< Core > &&  integrator_core,
FP  t0,
FP  dt 
)
inline

Create a SimulationBase.

Parameters
[in]modelAn instance of a compartmental model
[in]integrator_coreA unique pointer to an object derived from IntegratorCore.
[in]t0Start time.
[in]dtInitial step size of integration

◆ SimulationBase() [2/2]

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
mio::details::SimulationBase< FP, M, Integrands >::SimulationBase ( const SimulationBase< FP, M, Integrands > &  other)
inline

Member Function Documentation

◆ advance()

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
Eigen::Ref<Eigen::VectorX<FP> > mio::details::SimulationBase< FP, M, Integrands >::advance ( const Integrands &...  fs,
FP  tmax,
TimeSeries< FP > &  results 
)
inlineprotected

Run the simulation up to a given time.

Parameters
[in]fsIntegrands passed to the integrator, e.g. a wrapper for get_derivatives.
[in]tmaxNext stopping point of the simulation.
[in,out]resultsThe TimeSeries to use as initial value and for storing integration results.
Returns
The simulation result at tmax.

◆ get_dt() [1/2]

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
FP& mio::details::SimulationBase< FP, M, Integrands >::get_dt ( )
inline

Returns the step size used by the integrator.

When using a integration scheme with adaptive time stepping, the integrator will store its estimate for the next step size in this value.

◆ get_dt() [2/2]

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
const FP& mio::details::SimulationBase< FP, M, Integrands >::get_dt ( ) const
inline

Returns the step size used by the integrator.

When using a integration scheme with adaptive time stepping, the integrator will store its estimate for the next step size in this value.

◆ get_integrator_core() [1/2]

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
Core& mio::details::SimulationBase< FP, M, Integrands >::get_integrator_core ( )
inline

Access the IntegratorCore used in the simulation.

Returns
A reference to the IntegratorCore used in the simulation

◆ get_integrator_core() [2/2]

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
const Core& mio::details::SimulationBase< FP, M, Integrands >::get_integrator_core ( ) const
inline

Access the IntegratorCore used in the simulation.

Returns
A reference to the IntegratorCore used in the simulation

◆ get_model() [1/2]

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
Model& mio::details::SimulationBase< FP, M, Integrands >::get_model ( )
inline

Get a reference to the model owned and used by the simulation.

Returns
The simulation model.

◆ get_model() [2/2]

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
const Model& mio::details::SimulationBase< FP, M, Integrands >::get_model ( ) const
inline

Get a reference to the model owned and used by the simulation.

Returns
The simulation model.

◆ get_result() [1/2]

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
TimeSeries<FP>& mio::details::SimulationBase< FP, M, Integrands >::get_result ( )
inline

Returns the simulation result describing the model population in each time step.

Which compartments are used by the model is defined by the Comp template argument for the CompartmentalModel (usually an enum named InfectionState).

Returns
A TimeSeries to represent a numerical solution for the population of the model. For each simulated time step, the TimeSeries contains the population size in each compartment.

◆ get_result() [2/2]

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
const TimeSeries<FP>& mio::details::SimulationBase< FP, M, Integrands >::get_result ( ) const
inline

Returns the simulation result describing the model population in each time step.

Which compartments are used by the model is defined by the Comp template argument for the CompartmentalModel (usually an enum named InfectionState).

Returns
A TimeSeries to represent a numerical solution for the population of the model. For each simulated time step, the TimeSeries contains the population size in each compartment.

◆ operator=()

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
SimulationBase& mio::details::SimulationBase< FP, M, Integrands >::operator= ( const SimulationBase< FP, M, Integrands > &  other)
inline

◆ set_integrator_core()

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
void mio::details::SimulationBase< FP, M, Integrands >::set_integrator_core ( std::unique_ptr< Core > &&  integrator_core)
inline

Set the IntegratorCore used in the simulation.

Parameters
[in]integrator_coreA unique pointer to an object derived from IntegratorCore.

Member Data Documentation

◆ m_dt

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
FP mio::details::SimulationBase< FP, M, Integrands >::m_dt
private

The time step used (and possibly set) by m_integrator::m_core::step.

◆ m_integrator

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
SystemIntegrator<FP, Integrands...> mio::details::SimulationBase< FP, M, Integrands >::m_integrator
private

Integrates the DerivFunction (see advance) and stores resutls in m_result.

◆ m_model

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
std::unique_ptr<Model> mio::details::SimulationBase< FP, M, Integrands >::m_model
private

The model defining the ODE system and initial conditions.

◆ m_result

template<typename FP , IsCompartmentalModel< FP > M, class... Integrands>
TimeSeries<FP> mio::details::SimulationBase< FP, M, Integrands >::m_result
private

The simulation results.