-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
511 Compute inflow and outflow of models (#574)
Co-authored-by: reneSchm <49305466+reneSchm@users.noreply.github.com> Co-authored-by: Martin J. Kühn <62713180+mknaranja@users.noreply.github.com> Co-authored-by: dabele <daniel.abele@dlr.de> - Compute and Integrate Flows between the Compartments of the ODE model - Backwards compatibility with old design (see FlowModel::get_derivatives) - New FlowModel extending the existing Compartmentalmodel - New FlowSimulation extending current Simulation which also calculates flows - Converted all ODE models (except ode_sir) to use the FlowModel/FlowSimulation - Adding Plot table feature for the time series - Some Performance/Design gains for the Integrator/Simulation - Removed TotalInfections compartment. This can now easily be computed using the flows - Added a TypeList with metaprogramming utilities: - type_at_index - index_of_type - is_type_in_list - Added function extend_index and reduce_index - And some benchmarks ... :)
- Loading branch information
Showing
46 changed files
with
4,123 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright (C) 2020-2023 German Aerospace Center (DLR-SC) | ||
* | ||
* Authors: Rene Schmieding, Daniel Abele, Martin J. Kuehn | ||
* | ||
* Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de> | ||
* | ||
* 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. | ||
*/ | ||
#include "benchmarks/simulation.h" | ||
#include "benchmarks/flow_simulation_ode_secirvvs.h" | ||
#include "memilio/compartments/flow_simulation.h" | ||
#include "memilio/compartments/simulation.h" | ||
#include "ode_secirvvs/model.h" | ||
#include <string> | ||
|
||
const std::string config_path = "../../benchmarks/simulation.config"; | ||
|
||
// simulation without flows (not in Model definition and not calculated by Simulation) | ||
void flowless_sim(::benchmark::State& state) | ||
{ | ||
using Model = mio::benchmark::FlowlessModel; | ||
// suppress non-critical messages | ||
mio::set_log_level(mio::LogLevel::critical); | ||
// load config | ||
auto cfg = mio::benchmark::SimulationConfig::initialize(config_path); | ||
// create model | ||
Model model(cfg.num_agegroups); | ||
mio::benchmark::setup_model(model); | ||
// create simulation | ||
std::shared_ptr<mio::IntegratorCore> I = | ||
std::make_shared<mio::ControlledStepperWrapper<boost::numeric::odeint::runge_kutta_cash_karp54>>( | ||
cfg.abs_tol, cfg.rel_tol, cfg.dt_min, cfg.dt_max); | ||
// run benchmark | ||
for (auto _ : state) { | ||
// This code gets timed | ||
mio::benchmark::Simulation<mio::Simulation<Model>> sim(model, cfg.t0, cfg.dt); | ||
sim.set_integrator(I); | ||
// run sim | ||
sim.advance(cfg.t_max); | ||
} | ||
} | ||
|
||
// simulation with flows (in Model definition, but NOT calculated by Simulation) | ||
void flow_sim_comp_only(::benchmark::State& state) | ||
{ | ||
using Model = mio::benchmark::FlowModel; | ||
// suppress non-critical messages | ||
mio::set_log_level(mio::LogLevel::critical); | ||
// load config | ||
auto cfg = mio::benchmark::SimulationConfig::initialize(config_path); | ||
// create model | ||
Model model(cfg.num_agegroups); | ||
mio::benchmark::setup_model(model); | ||
// create simulation | ||
std::shared_ptr<mio::IntegratorCore> I = | ||
std::make_shared<mio::ControlledStepperWrapper<boost::numeric::odeint::runge_kutta_cash_karp54>>( | ||
cfg.abs_tol, cfg.rel_tol, cfg.dt_min, cfg.dt_max); | ||
// run benchmark | ||
for (auto _ : state) { | ||
// This code gets timed | ||
mio::osecirvvs::Simulation<mio::Simulation<Model>> sim(model, cfg.t0, cfg.dt); | ||
sim.set_integrator(I); | ||
// run sim | ||
sim.advance(cfg.t_max); | ||
} | ||
} | ||
|
||
// simulation with flows (in Model definition and calculated by Simulation) | ||
void flow_sim(::benchmark::State& state) | ||
{ | ||
using Model = mio::benchmark::FlowModel; | ||
// suppress non-critical messages | ||
mio::set_log_level(mio::LogLevel::critical); | ||
// load config | ||
auto cfg = mio::benchmark::SimulationConfig::initialize(config_path); | ||
// create model | ||
Model model(cfg.num_agegroups); | ||
mio::benchmark::setup_model(model); | ||
// create simulation | ||
std::shared_ptr<mio::IntegratorCore> I = | ||
std::make_shared<mio::ControlledStepperWrapper<boost::numeric::odeint::runge_kutta_cash_karp54>>( | ||
cfg.abs_tol, cfg.rel_tol, cfg.dt_min, cfg.dt_max); | ||
// run benchmark | ||
for (auto _ : state) { | ||
// This code gets timed | ||
mio::osecirvvs::Simulation<mio::FlowSimulation<Model>> sim(model, cfg.t0, cfg.dt); | ||
sim.set_integrator(I); | ||
// run sim | ||
sim.advance(cfg.t_max); | ||
} | ||
} | ||
|
||
// register functions as a benchmarks and set a name | ||
// mitigate influence of cpu scaling | ||
BENCHMARK(flowless_sim)->Name("Dummy 1/3"); | ||
BENCHMARK(flowless_sim)->Name("Dummy 2/3"); | ||
BENCHMARK(flowless_sim)->Name("Dummy 3/3"); | ||
// actual benchmarks | ||
BENCHMARK(flowless_sim) | ||
->Name( | ||
"osecirvvs::Simulation<mio::Simulation> on osecirvvs::Model (osecirvvs::* from pre 511 branch) without flows"); | ||
BENCHMARK(flow_sim_comp_only)->Name("osecirvvs::Simulation<mio::Simulation> on osecirvvs::Model with flows"); | ||
BENCHMARK(flow_sim)->Name("osecirvvs::Simulation<mio::FlowSimulation> on osecirvvs::Model with flows"); | ||
// run all benchmarks | ||
BENCHMARK_MAIN(); |
Oops, something went wrong.