model.h Source File

CPP API: model.h Source File
ode_seair/model.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Ralf Hannemann-Tamas
5 *
6 * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 
21 #ifndef ODESEAIR_MODEL_H
22 #define ODESEAIR_MODEL_H
23 
25 #include "memilio/config.h"
28 #include "ode_seair/parameters.h"
29 
30 namespace mio
31 {
32 namespace oseair
33 {
34 
35 template <typename FP>
36 class Model : public mio::CompartmentalModel<FP, InfectionState, mio::Populations<FP, InfectionState>, Parameters<FP>>
37 {
39 
40 public:
41  using typename Base::ParameterSet;
42  using typename Base::Populations;
43 
46  {
47  }
48 
49  void get_derivatives(Eigen::Ref<const Eigen::VectorX<FP>> pop, Eigen::Ref<const Eigen::VectorX<FP>> y, FP /* t */,
50  Eigen::Ref<Eigen::VectorX<FP>> dydt) const override
51  {
52  auto& params = this->parameters;
53  const auto pop_total = pop.sum();
54 
55  dydt[(size_t)InfectionState::Susceptible] =
56  -params.template get<SocialDistancing<FP>>() / pop_total * y[(size_t)InfectionState::Susceptible] *
57  pop[(size_t)InfectionState::Asymptomatic] -
58  params.template get<Quarantined<FP>>() / pop_total * y[(size_t)InfectionState::Susceptible] *
59  pop[(size_t)InfectionState::Infected] +
60  params.template get<TimeRecoveredInv<FP>>() * y[(size_t)InfectionState::Recovered];
61  dydt[(size_t)InfectionState::Exposed] =
62  params.template get<SocialDistancing<FP>>() / pop_total * y[(size_t)InfectionState::Susceptible] *
63  pop[(size_t)InfectionState::Asymptomatic] +
64  params.template get<Quarantined<FP>>() / pop_total * y[(size_t)InfectionState::Susceptible] *
65  pop[(size_t)InfectionState::Infected] -
66  y[(size_t)InfectionState::Exposed] / params.template get<TimeExposed<FP>>();
67  dydt[(size_t)InfectionState::Asymptomatic] =
68  y[(size_t)InfectionState::Exposed] / params.template get<TimeExposed<FP>>() -
69  (params.template get<TestingRate<FP>>() + params.template get<RecoveryRateFromAsymptomatic<FP>>()) *
71  dydt[(size_t)InfectionState::Infected] =
72  params.template get<TestingRate<FP>>() * y[(size_t)InfectionState::Asymptomatic] -
73  (params.template get<RecoveryRate<FP>>() + params.template get<DeathRate<FP>>()) *
74  y[(size_t)InfectionState::Infected];
75  dydt[(size_t)InfectionState::Recovered] =
76  params.template get<RecoveryRateFromAsymptomatic<FP>>() * y[(size_t)InfectionState::Asymptomatic] +
77  params.template get<RecoveryRate<FP>>() * y[(size_t)InfectionState::Infected] -
78  params.template get<TimeRecoveredInv<FP>>() * y[(size_t)InfectionState::Recovered];
79  dydt[(size_t)InfectionState::Dead] = params.template get<DeathRate<FP>>() * y[(size_t)InfectionState::Infected];
80  }
81 };
82 
83 } // namespace oseair
84 } // namespace mio
85 
86 #endif // ODESEAIR_MODEL_H
A class template for compartment populations.
Definition: populations.h:55
Definition: ode_seair/model.h:37
void get_derivatives(Eigen::Ref< const Eigen::VectorX< FP >> pop, Eigen::Ref< const Eigen::VectorX< FP >> y, FP, Eigen::Ref< Eigen::VectorX< FP >> dydt) const override
Definition: ode_seair/model.h:49
Model()
Definition: ode_seair/model.h:44
Parameters of an SEAIR model.
Definition: ode_seair/parameters.h:174
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
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
mio::Populations< FP, InfectionState > Populations
Definition: compartmental_model.h:62
Death Rate.
Definition: ode_seair/parameters.h:104
Infectious period for unconfirmed infected people.
Definition: ode_seair/parameters.h:136
Recovery rate.
Definition: ode_seair/parameters.h:88
Social distancing.
Definition: ode_seair/parameters.h:40
Rate of testing.
Definition: ode_seair/parameters.h:72
Rate recovered people become susceptible again.
Definition: ode_seair/parameters.h:152