|
1 | 1 | /* |
2 | | -* Copyright (C) 2020-2021 German Aerospace Center (DLR-SC) |
| 2 | +* Copyright (C) 2020-2023 German Aerospace Center (DLR-SC) |
3 | 3 | * |
4 | 4 | * Authors: Rene Schmieding |
5 | 5 | * |
@@ -29,77 +29,77 @@ namespace mio |
29 | 29 | { |
30 | 30 | namespace benchmark |
31 | 31 | { |
32 | | - /// @brief parameters for integrator-step benchmark |
33 | | - struct IntegratorStepConfig { |
34 | | - int num_agegroups; |
35 | | - double t_init, dt_init, abs_tol, rel_tol, dt_min, dt_max; |
36 | | - Eigen::VectorXd yt, ytp1; |
37 | | - /** |
| 32 | +/// @brief parameters for integrator-step benchmark |
| 33 | +struct IntegratorStepConfig { |
| 34 | + int num_agegroups; |
| 35 | + double t_init, dt_init, abs_tol, rel_tol, dt_min, dt_max; |
| 36 | + Eigen::VectorXd yt, ytp1; |
| 37 | + /** |
38 | 38 | * @brief creates configuration with default parameters for a secir model |
39 | 39 | * @return configuration for integrator-step benchmark |
40 | 40 | */ |
41 | | - static IntegratorStepConfig initialize() |
42 | | - { |
43 | | - const double vals[8] = {6377.873644, 35.249156, 30.029611, 182.145865, |
44 | | - 66.153059, 79.530621, 3069.383604, 159.634440}; |
45 | | - return IntegratorStepConfig{1, |
46 | | - 50, |
47 | | - 1, |
48 | | - 1e-10, |
49 | | - 1e-5, |
50 | | - std::numeric_limits<double>::min(), |
51 | | - std::numeric_limits<double>::max(), |
52 | | - Eigen::Matrix<double, 8, 1>(vals), |
53 | | - Eigen::VectorXd::Zero(8)}; |
54 | | - } |
55 | | - /** |
| 41 | + static IntegratorStepConfig initialize() |
| 42 | + { |
| 43 | + const double vals[8] = {6377.873644, 35.249156, 30.029611, 182.145865, |
| 44 | + 66.153059, 79.530621, 3069.383604, 159.634440}; |
| 45 | + return IntegratorStepConfig{1, |
| 46 | + 50, |
| 47 | + 1, |
| 48 | + 1e-10, |
| 49 | + 1e-5, |
| 50 | + std::numeric_limits<double>::min(), |
| 51 | + std::numeric_limits<double>::max(), |
| 52 | + Eigen::Matrix<double, 8, 1>(vals), |
| 53 | + Eigen::VectorXd::Zero(8)}; |
| 54 | + } |
| 55 | + /** |
56 | 56 | * @brief reads configuration from json file |
57 | 57 | * @param path the path of the configfile |
58 | 58 | * @return configuration for integrator-step benchmark |
59 | 59 | */ |
60 | | - static IntegratorStepConfig initialize(std::string path) |
61 | | - { |
62 | | - auto result = mio::read_json(path, mio::Tag<IntegratorStepConfig>{}); |
63 | | - if (!result) { // failed to read config |
64 | | - mio::log(mio::LogLevel::critical, result.error().formatted_message()); |
65 | | - abort(); |
66 | | - } |
67 | | - return result.value(); |
68 | | - } |
69 | | - /// @brief function implementing mio::deserialize, used by read_json in initialize |
70 | | - template <class IOContext> |
71 | | - static mio::IOResult<IntegratorStepConfig> deserialize(IOContext& io) |
72 | | - { |
73 | | - auto obj = io.expect_object("integrator_step"); |
74 | | - auto num_agegroups_io = obj.expect_element("num_agegroups", mio::Tag<int>{}); |
75 | | - auto t_init_io = obj.expect_element("t_init", mio::Tag<double>{}); |
76 | | - auto dt_init_io = obj.expect_element("dt_init", mio::Tag<double>{}); |
77 | | - auto abs_tol_io = obj.expect_element("abs_tol", mio::Tag<double>{}); |
78 | | - auto rel_tol_io = obj.expect_element("rel_tol", mio::Tag<double>{}); |
79 | | - auto dt_min_io = obj.expect_element("dt_min", mio::Tag<double>{}); |
80 | | - auto dt_max_io = obj.expect_element("dt_max", mio::Tag<double>{}); |
81 | | - auto yt_io = obj.expect_list("yt", mio::Tag<double>{}); |
82 | | - return mio::apply( |
83 | | - io, |
84 | | - [](auto&& num_agegroups, auto&& t_init, auto&& dt_init, auto&& abs_tol, auto&& rel_tol, auto&& dt_min, |
85 | | - auto&& dt_max, auto&& yt) { |
86 | | - IntegratorStepConfig cfg{num_agegroups, |
87 | | - t_init, |
88 | | - dt_init, |
89 | | - abs_tol, |
90 | | - rel_tol, |
91 | | - dt_min, |
92 | | - dt_max, |
93 | | - Eigen::VectorXd::Zero(yt.size()), |
94 | | - Eigen::VectorXd::Zero(yt.size())}; |
95 | | - for (size_t i = 0; i < yt.size(); i++) { |
96 | | - cfg.yt[i] = yt[i]; |
97 | | - } |
98 | | - return cfg; |
99 | | - }, |
100 | | - num_agegroups_io, t_init_io, dt_init_io, abs_tol_io, rel_tol_io, dt_min_io, dt_max_io, yt_io); |
| 60 | + static IntegratorStepConfig initialize(std::string path) |
| 61 | + { |
| 62 | + auto result = mio::read_json(path, mio::Tag<IntegratorStepConfig>{}); |
| 63 | + if (!result) { // failed to read config |
| 64 | + mio::log(mio::LogLevel::critical, result.error().formatted_message()); |
| 65 | + abort(); |
101 | 66 | } |
102 | | - }; |
| 67 | + return result.value(); |
| 68 | + } |
| 69 | + /// @brief function implementing mio::deserialize, used by read_json in initialize |
| 70 | + template <class IOContext> |
| 71 | + static mio::IOResult<IntegratorStepConfig> deserialize(IOContext& io) |
| 72 | + { |
| 73 | + auto obj = io.expect_object("integrator_step"); |
| 74 | + auto num_agegroups_io = obj.expect_element("num_agegroups", mio::Tag<int>{}); |
| 75 | + auto t_init_io = obj.expect_element("t_init", mio::Tag<double>{}); |
| 76 | + auto dt_init_io = obj.expect_element("dt_init", mio::Tag<double>{}); |
| 77 | + auto abs_tol_io = obj.expect_element("abs_tol", mio::Tag<double>{}); |
| 78 | + auto rel_tol_io = obj.expect_element("rel_tol", mio::Tag<double>{}); |
| 79 | + auto dt_min_io = obj.expect_element("dt_min", mio::Tag<double>{}); |
| 80 | + auto dt_max_io = obj.expect_element("dt_max", mio::Tag<double>{}); |
| 81 | + auto yt_io = obj.expect_list("yt", mio::Tag<double>{}); |
| 82 | + return mio::apply( |
| 83 | + io, |
| 84 | + [](auto&& num_agegroups, auto&& t_init, auto&& dt_init, auto&& abs_tol, auto&& rel_tol, auto&& dt_min, |
| 85 | + auto&& dt_max, auto&& yt) { |
| 86 | + IntegratorStepConfig cfg{num_agegroups, |
| 87 | + t_init, |
| 88 | + dt_init, |
| 89 | + abs_tol, |
| 90 | + rel_tol, |
| 91 | + dt_min, |
| 92 | + dt_max, |
| 93 | + Eigen::VectorXd::Zero(yt.size()), |
| 94 | + Eigen::VectorXd::Zero(yt.size())}; |
| 95 | + for (size_t i = 0; i < yt.size(); i++) { |
| 96 | + cfg.yt[i] = yt[i]; |
| 97 | + } |
| 98 | + return cfg; |
| 99 | + }, |
| 100 | + num_agegroups_io, t_init_io, dt_init_io, abs_tol_io, rel_tol_io, dt_min_io, dt_max_io, yt_io); |
| 101 | + } |
| 102 | +}; |
103 | 103 | } // namespace benchmark |
104 | 104 |
|
105 | 105 | } // namespace mio |
|
0 commit comments