flow_simulation_base.h Source File

CPP API: flow_simulation_base.h Source File
flow_simulation_base.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Rene Schmieding, Henrik Zunker
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 #ifndef MIO_COMPARTMENTS_FLOW_SIMULATION_BASE_H
21 #define MIO_COMPARTMENTS_FLOW_SIMULATION_BASE_H
22 
26 
27 namespace mio
28 {
29 namespace details
30 {
31 
40 template <typename FP, IsFlowModel<FP> M, class... Integrands>
41 class FlowSimulationBase : public SimulationBase<FP, M, Integrands...>
42 {
43 
44 public:
45  using Base = SimulationBase<FP, M, Integrands...>;
46  using Model = M;
47  using Core = IntegratorCore<FP, Integrands...>;
48 
56  FlowSimulationBase(Model const& model, std::unique_ptr<Core>&& integrator_core, FP t0, FP dt)
57  : Base(model, std::move(integrator_core), t0, dt)
58  , m_flow_result(t0, model.get_initial_flows())
59  {
60  }
61 
73  {
74  return m_flow_result;
75  }
76 
77  const TimeSeries<FP>& get_flows() const
78  {
79  return m_flow_result;
80  }
83 protected:
91  {
92  const auto& flows = get_flows();
93  const auto& model = this->get_model();
94  auto& result = this->get_result();
95  // take the last time point as base result (instead of the initial results), so that we use external changes
96  const size_t last_tp = result.get_num_time_points() - 1;
97  // calculate new time points
98  for (Eigen::Index i = result.get_num_time_points(); i < flows.get_num_time_points(); i++) {
99  result.add_time_point(flows.get_time(i));
100  model.get_derivatives(flows.get_value(i) - flows.get_value(last_tp), result.get_value(i));
101  result.get_value(i) += result.get_value(last_tp);
102  }
103  }
104 
105 private:
107 };
108 
110 template <typename FP, class M, class... Integrands>
111 class FlowSimulationBase<FP, M, SystemIntegrator<FP, Integrands...>> : public FlowSimulationBase<FP, M, Integrands...>
112 {
113  using FlowSimulationBase<FP, M, Integrands...>::FlowSimulationBase;
114 };
115 
116 } // namespace details
117 } // namespace mio
118 
119 #endif // MIO_COMPARTMENTS_FLOW_SIMULATION_BASE_H
Interface class defining the integration step used in a SystemIntegrator.
Definition: integrator.h:48
Integrate a system of equations over time.
Definition: integrator.h:147
stores vectors of values at time points (or some other abstract variable) the value at each time poin...
Definition: time_series.h:58
Base class to define a FlowSimulation.
Definition: flow_simulation_base.h:42
mio::TimeSeries< FP > m_flow_result
Flow result of the simulation.
Definition: flow_simulation_base.h:106
M Model
Definition: flow_simulation_base.h:46
void compute_population_results()
Computes the distribution of the Population to the InfectionStates based on the simulated flows.
Definition: flow_simulation_base.h:90
const TimeSeries< FP > & get_flows() const
Returns the simulation result describing the transitions between compartments for each time step.
Definition: flow_simulation_base.h:77
FlowSimulationBase(Model const &model, std::unique_ptr< Core > &&integrator_core, FP t0, FP dt)
Create a FlowSimulationBase.
Definition: flow_simulation_base.h:56
TimeSeries< FP > & get_flows()
Returns the simulation result describing the transitions between compartments for each time step.
Definition: flow_simulation_base.h:72
Base class to define a Simulation.
Definition: simulation_base.h:42
const Model & get_model() const
Get a reference to the model owned and used by the simulation.
Definition: simulation_base.h:131
TimeSeries< FP > & get_result()
Returns the simulation result describing the model population in each time step.
Definition: simulation_base.h:116
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
auto i
Definition: io.h:809
Definition: io.h:94