parameters.h Source File

CPP API: parameters.h Source File
ode_seair/parameters.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_PARAMETERS_H
22 #define ODESEAIR_PARAMETERS_H
23 
25 #include "memilio/utils/logging.h"
26 
27 namespace mio
28 {
29 namespace oseair
30 {
31 
32 /****************************************
33  * Define Parameters of the SEAIR model *
34  ****************************************/
35 
39 template <typename FP>
41  using Type = FP;
42  static Type get_default()
43  {
44  return Type(0.2);
45  }
46  static std::string name()
47  {
48  return "SocialDistancing";
49  }
50 };
51 
55 template <typename FP>
56 struct Quarantined {
57  using Type = FP;
58  static Type get_default()
59  {
60  return Type(0.2);
61  }
62  static std::string name()
63  {
64  return "Quarantined";
65  }
66 };
67 
71 template <typename FP>
72 struct TestingRate {
73  using Type = FP;
74  static Type get_default()
75  {
76  return Type(0.2);
77  }
78  static std::string name()
79  {
80  return "TestingRate";
81  }
82 };
83 
87 template <typename FP>
88 struct RecoveryRate {
89  using Type = FP;
90  static Type get_default()
91  {
92  return Type(0.0067);
93  }
94  static std::string name()
95  {
96  return "RecoveryRate";
97  }
98 };
99 
103 template <typename FP>
104 struct DeathRate {
105  using Type = FP;
106  static Type get_default()
107  {
108  return Type(0.0041);
109  }
110  static std::string name()
111  {
112  return "DeathRate";
113  }
114 };
115 
119 template <typename FP>
120 struct TimeExposed {
121  using Type = FP;
122  static Type get_default()
123  {
124  return Type(0.5);
125  }
126  static std::string name()
127  {
128  return "TimeExposed";
129  }
130 };
131 
135 template <typename FP>
137  using Type = FP;
138  static Type get_default()
139  {
140  return Type(0.1);
141  }
142  static std::string name()
143  {
144  return "RecoveryRateFromAsymptomatic";
145  }
146 };
147 
151 template <typename FP>
153  using Type = FP;
154  static Type get_default()
155  {
156  return Type(0.0);
157  }
158  static std::string name()
159  {
160  return "TimeRecoveredInv";
161  }
162 };
163 
164 template <typename FP>
168 
172 template <typename FP>
173 class Parameters : public ParametersBase<FP>
174 {
175 public:
177  : ParametersBase<FP>()
178  {
179  }
180 
186  bool check_constraints() const
187  {
188  if (this->template get<SocialDistancing<FP>>() < 0.0) {
189  log_error("Constraint check: Parameter SocialDistancing smaller {}", 0);
190  return true;
191  }
192 
193  if (this->template get<Quarantined<FP>>() < 0.0) {
194  log_error("Constraint check: Parameter Quarantined smaller {}", 0);
195  return true;
196  }
197 
198  const FP tol_times = 1e-1; // accepted tolerance for compartment stays
199  if (this->template get<TimeExposed<FP>>() < tol_times) {
200  log_error("Constraint check: Parameter TimeExposed {} smaller {}. Please "
201  "note that unreasonably small compartment stays lead to massively increased run time. "
202  "Consider to cancel and reset parameters.",
203  this->template get<TimeExposed<FP>>(), tol_times);
204  return true;
205  }
206 
207  if (this->template get<RecoveryRateFromAsymptomatic<FP>>() < 0.0) {
208  log_error("Constraint check: Parameter RecoveryRateFromAsymptomatic smaller {}", 0);
209  return true;
210  }
211 
212  if (this->template get<TestingRate<FP>>() < 0.0) {
213  log_error("Constraint check: Parameter TestingRate smaller {}", 0);
214  return true;
215  }
216 
217  if (this->template get<RecoveryRate<FP>>() < 0.0) {
218  log_error("Constraint check: Parameter RecoveryRate smaller {}", 0);
219  return true;
220  }
221 
222  if (this->template get<DeathRate<FP>>() < 0.0) {
223  log_error("Constraint check: Parameter DeathRate smaller {}", 0);
224  return true;
225  }
226 
227  if (this->template get<TimeRecoveredInv<FP>>() < 0.0) {
228  log_error("Constraint check: Parameter TimeRecoveredInv smaller {}", 0);
229  return true;
230  }
231 
232  return false;
233  }
234 
235 private:
237  : ParametersBase<FP>(std::move(base))
238  {
239  }
240 
241 public:
246  template <class IOContext>
247  static IOResult<Parameters> deserialize(IOContext& io)
248  {
249  BOOST_OUTCOME_TRY(auto&& base, ParametersBase<FP>::deserialize(io));
250  return success(Parameters(std::move(base)));
251  }
252 };
253 
254 } // namespace oseair
255 } // namespace mio
256 
257 #endif // ODESEAIR_PARAMETERS_H
a set of parameters defined at compile time
Definition: parameter_set.h:205
const ParameterTagTraits< Tag >::Type & get() const
get value of a parameter
Definition: parameter_set.h:262
Parameters of an SEAIR model.
Definition: ode_seair/parameters.h:174
static IOResult< Parameters > deserialize(IOContext &io)
deserialize an object of this class.
Definition: ode_seair/parameters.h:247
bool check_constraints() const
Checks whether all Parameters satisfy their corresponding constraints and logs an error if constraint...
Definition: ode_seair/parameters.h:186
Parameters(ParametersBase< FP > &&base)
Definition: ode_seair/parameters.h:236
Parameters()
Definition: ode_seair/parameters.h:176
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
auto success()
Create an object that is implicitly convertible to a succesful IOResult<void>.
Definition: io.h:359
void log_error(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:100
boost::outcome_v2::unchecked< T, IOStatus > IOResult
Value-or-error type for operations that return a value but can fail.
Definition: io.h:353
Definition: io.h:94
Death Rate.
Definition: ode_seair/parameters.h:104
FP Type
Definition: ode_seair/parameters.h:105
static Type get_default()
Definition: ode_seair/parameters.h:106
static std::string name()
Definition: ode_seair/parameters.h:110
Quarantining.
Definition: ode_seair/parameters.h:56
static std::string name()
Definition: ode_seair/parameters.h:62
static Type get_default()
Definition: ode_seair/parameters.h:58
FP Type
Definition: ode_seair/parameters.h:57
Infectious period for unconfirmed infected people.
Definition: ode_seair/parameters.h:136
static std::string name()
Definition: ode_seair/parameters.h:142
static Type get_default()
Definition: ode_seair/parameters.h:138
FP Type
Definition: ode_seair/parameters.h:137
Recovery rate.
Definition: ode_seair/parameters.h:88
static Type get_default()
Definition: ode_seair/parameters.h:90
static std::string name()
Definition: ode_seair/parameters.h:94
FP Type
Definition: ode_seair/parameters.h:89
Social distancing.
Definition: ode_seair/parameters.h:40
static std::string name()
Definition: ode_seair/parameters.h:46
static Type get_default()
Definition: ode_seair/parameters.h:42
FP Type
Definition: ode_seair/parameters.h:41
Rate of testing.
Definition: ode_seair/parameters.h:72
static Type get_default()
Definition: ode_seair/parameters.h:74
FP Type
Definition: ode_seair/parameters.h:73
static std::string name()
Definition: ode_seair/parameters.h:78
Inverse of the latent period of the virus.
Definition: ode_seair/parameters.h:120
static Type get_default()
Definition: ode_seair/parameters.h:122
static std::string name()
Definition: ode_seair/parameters.h:126
FP Type
Definition: ode_seair/parameters.h:121
Rate recovered people become susceptible again.
Definition: ode_seair/parameters.h:152
FP Type
Definition: ode_seair/parameters.h:153
static Type get_default()
Definition: ode_seair/parameters.h:154
static std::string name()
Definition: ode_seair/parameters.h:158