parameters.h Source File

CPP API: parameters.h Source File
sde_sir/parameters.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Nils Wassmuth, Rene Schmieding, Martin J. Kuehn
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 MIO_SDE_SIR_PARAMETERS_H
22 #define MIO_SDE_SIR_PARAMETERS_H
23 
27 
28 namespace mio
29 {
30 namespace ssir
31 {
32 
33 /*******************************************
34  * Define Parameters of the SIR model *
35  *******************************************/
36 
40 template <typename FP>
43  static Type get_default()
44  {
45  return Type(1.0);
46  }
47  static std::string name()
48  {
49  return "TransmissionProbabilityOnContact";
50  }
51 };
52 
56 template <typename FP>
57 struct TimeInfected {
59  static Type get_default()
60  {
61  return Type(6.0);
62  }
63  static std::string name()
64  {
65  return "TimeInfected";
66  }
67 };
68 
72 template <typename FP>
75  static Type get_default()
76  {
77  return Type{1};
78  }
79  static std::string name()
80  {
81  return "ContactPatterns";
82  }
83 };
84 
85 template <typename FP>
87 
91 template <typename FP>
92 class Parameters : public ParametersBase<FP>
93 {
94 public:
96  : ParametersBase<FP>()
97  {
98  }
99 
114  {
115  FP tol_times = 1e-1;
116 
117  int corrected = false;
118  if (this->template get<TimeInfected<FP>>() < tol_times) {
119  log_warning("Constraint check: Parameter TimeInfected changed from {} to {}. Please note that "
120  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
121  "and reset parameters.",
122  this->template get<TimeInfected<FP>>(), tol_times);
123  this->template get<TimeInfected<FP>>() = tol_times;
124  corrected = true;
125  }
126  if (this->template get<TransmissionProbabilityOnContact<FP>>() < 0.0 ||
127  this->template get<TransmissionProbabilityOnContact<FP>>() > 1.0) {
128  log_warning("Constraint check: Parameter TransmissionProbabilityOnContact changed from {} to {} ",
129  this->template get<TransmissionProbabilityOnContact<FP>>(), 0.0);
130  this->template get<TransmissionProbabilityOnContact<FP>>() = 0.0;
131  corrected = true;
132  }
133  return corrected;
134  }
135 
141  bool check_constraints() const
142  {
143  FP tol_times = 1e-1;
144 
145  if (this->template get<TimeInfected<FP>>() < tol_times) {
146  log_warning("Constraint check: Parameter TimeInfected {} smaller or equal {}. Please note that "
147  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
148  "and reset parameters.",
149  this->template get<TimeInfected<FP>>(), tol_times);
150  return true;
151  }
152  if (this->template get<TransmissionProbabilityOnContact<FP>>() < 0.0 ||
153  this->template get<TransmissionProbabilityOnContact<FP>>() > 1.0) {
154  log_error("Constraint check: Parameter TransmissionProbabilityOnContact {} smaller {} or greater {}",
155  this->template get<TransmissionProbabilityOnContact<FP>>(), 0.0, 1.0);
156  return true;
157  }
158  return false;
159  }
160 
161 private:
163  : ParametersBase<FP>(std::move(base))
164  {
165  }
166 
167 public:
172  template <class IOContext>
173  static IOResult<Parameters> deserialize(IOContext& io)
174  {
175  BOOST_OUTCOME_TRY(auto&& base, ParametersBase<FP>::deserialize(io));
176  return success(Parameters(std::move(base)));
177  }
178 };
179 
180 } // namespace ssir
181 } // namespace mio
182 
183 #endif // MIO_SDE_SIR_PARAMETERS_H
represents time dependent contact frequencies between groups.
Definition: contact_matrix.h:505
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 SIR model.
Definition: sde_sir/parameters.h:93
static IOResult< Parameters > deserialize(IOContext &io)
deserialize an object of this class.
Definition: sde_sir/parameters.h:173
Parameters()
Definition: sde_sir/parameters.h:95
bool apply_constraints()
Checks whether all Parameters satisfy their corresponding constraints and applies them,...
Definition: sde_sir/parameters.h:113
bool check_constraints() const
Checks whether all Parameters satisfy their corresponding constraints and logs an error if constraint...
Definition: sde_sir/parameters.h:141
Parameters(ParametersBase< FP > &&base)
Definition: sde_sir/parameters.h:162
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
void log_warning(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:112
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
the contact patterns within the society are modelled using a ContactMatrix
Definition: sde_sir/parameters.h:73
static std::string name()
Definition: sde_sir/parameters.h:79
static Type get_default()
Definition: sde_sir/parameters.h:75
the infectious time in day unit
Definition: sde_sir/parameters.h:57
UncertainValue< FP > Type
Definition: sde_sir/parameters.h:58
static std::string name()
Definition: sde_sir/parameters.h:63
static Type get_default()
Definition: sde_sir/parameters.h:59
probability of getting infected from a contact
Definition: sde_sir/parameters.h:41
static Type get_default()
Definition: sde_sir/parameters.h:43
static std::string name()
Definition: sde_sir/parameters.h:47
UncertainValue< FP > Type
Definition: sde_sir/parameters.h:42