-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathsimulation.h
More file actions
92 lines (87 loc) · 3.66 KB
/
simulation.h
File metadata and controls
92 lines (87 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Copyright (C) 2020-2026 MEmilio
*
* Authors: Rene Schmieding
*
* Contact: Martin J. Kuehn <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ODE_SIMULATION_CONFIG_H
#define ODE_SIMULATION_CONFIG_H
#include "memilio/io/json_serializer.h"
#include "memilio/utils/logging.h"
#include "benchmark/benchmark.h"
namespace mio
{
namespace benchmark
{
/// @brief parameters for simulation benchmark
struct SimulationConfig {
int num_agegroups;
ScalarType t0, t_max, dt, abs_tol, rel_tol, dt_min, dt_max;
/**
* @brief creates configuration with default parameters for a secir model
* @param num_agegroups number of agegroups
* @return configuration for simulation benchmark
*/
static SimulationConfig initialize(int num_agegroups = 10)
{
return SimulationConfig{num_agegroups,
0,
100,
0.5,
1e-10,
1e-5,
std::numeric_limits<ScalarType>::min(),
std::numeric_limits<ScalarType>::max()};
}
/**
* @brief reads configuration from json file
* @param path the path of the configfile
* @return configuration for simulation benchmark
*/
static SimulationConfig initialize(std::string path)
{
auto result = mio::read_json(path, mio::Tag<SimulationConfig>{});
if (!result) { // failed to read config
mio::log(mio::LogLevel::critical, result.error().formatted_message());
abort();
}
return result.value();
}
/// @brief function implementing mio::deserialize, used by read_json in initialize
template <class IOContext>
static mio::IOResult<SimulationConfig> deserialize(IOContext& io)
{
auto obj = io.expect_object("bench_simulation");
auto num_agegroups_io = obj.expect_element("num_agegroups", mio::Tag<int>{});
auto t_io = obj.expect_element("t0", mio::Tag<ScalarType>{});
auto t_max_io = obj.expect_element("t_max", mio::Tag<ScalarType>{});
auto dt_io = obj.expect_element("dt", mio::Tag<ScalarType>{});
auto abs_tol_io = obj.expect_element("abs_tol", mio::Tag<ScalarType>{});
auto rel_tol_io = obj.expect_element("rel_tol", mio::Tag<ScalarType>{});
auto dt_min_io = obj.expect_element("dt_min", mio::Tag<ScalarType>{});
auto dt_max_io = obj.expect_element("dt_max", mio::Tag<ScalarType>{});
return mio::apply(
io,
[](auto&& num_agegroups_, auto&& t0_, auto&& t_max_, auto&& dt_, auto&& abs_tol_, auto&& rel_tol_,
auto&& dt_min_, auto&& dt_max_) {
return SimulationConfig{num_agegroups_, t0_, t_max_, dt_, abs_tol_, rel_tol_, dt_min_, dt_max_};
},
num_agegroups_io, t_io, t_max_io, dt_io, abs_tol_io, rel_tol_io, dt_min_io, dt_max_io);
}
};
} // namespace benchmark
} // namespace mio
#endif // ODE_SIMULATION_CONFIG_H