LCOV - code coverage report
Current view: top level - models/ide_secir - simulation.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 10 10 100.0 %
Date: 2024-11-18 12:45:26 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /* 
       2             : * Copyright (C) 2020-2024 MEmilio
       3             : *
       4             : * Authors: Martin J Kuehn, Anna Wendler, Lena Ploetzke
       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 IDE_SECIR_SIMULATION_H
      21             : #define IDE_SECIR_SIMULATION_H
      22             : 
      23             : #include "ide_secir/model.h"
      24             : #include "memilio/config.h"
      25             : #include "memilio/utils/time_series.h"
      26             : #include <memory>
      27             : #include <cstdio>
      28             : 
      29             : namespace mio
      30             : {
      31             : namespace isecir
      32             : {
      33             : 
      34             : /**
      35             :  * run the simulation in discrete steps and report results.
      36             :  */
      37             : class Simulation
      38             : {
      39             : 
      40             : public:
      41             :     /**
      42             :      * @brief setup the Simulation for an IDE model.
      43             :      * @param[in] model An instance of the IDE model.
      44             :      * @param[in] dt Step size of numerical solver.
      45             :      */
      46          14 :     Simulation(Model const& model, ScalarType dt = 0.1)
      47          14 :         : m_model(std::make_unique<Model>(model))
      48          14 :         , m_dt(dt)
      49             :     {
      50          14 :     }
      51             : 
      52             :     /** 
      53             :      * Run the simulation from the current time to tmax.
      54             :      * @param tmax Time to stop.
      55             :      */
      56             :     void advance(ScalarType tmax);
      57             : 
      58             :     /**
      59             :      * @brief Get the result of the simulation.
      60             :      * Return the number of persons in all #InfectionState%s.
      61             :      * @return The result of the simulation.
      62             :      */
      63           7 :     TimeSeries<double>& get_result()
      64             :     {
      65           7 :         return m_model->m_populations;
      66             :     }
      67             : 
      68             :     /**
      69             :      * @brief Get the result of the simulation.
      70             :      * Return the number of persons in all #InfectionState%s.
      71             :      * @return The result of the simulation.
      72             :      */
      73             :     const TimeSeries<double>& get_result() const
      74             :     {
      75             :         return m_model->m_populations;
      76             :     }
      77             : 
      78             :     /**
      79             :      * @brief Get the transitions between the different #InfectionState%s.
      80             :      * 
      81             :      * @return TimeSeries with stored transitions calculated in the simulation.
      82             :      */
      83           3 :     TimeSeries<ScalarType> const& get_transitions()
      84             :     {
      85           3 :         return m_model->m_transitions;
      86             :     }
      87             : 
      88             :     /**
      89             :      * @brief returns the simulation model used in simulation.
      90             :      */
      91             :     const Model& get_model() const
      92             :     {
      93             :         return *m_model;
      94             :     }
      95             : 
      96             :     /**
      97             :      * @brief returns the simulation model used in simulation.
      98             :      */
      99           6 :     Model& get_model()
     100             :     {
     101           6 :         return *m_model;
     102             :     }
     103             : 
     104             :     /**
     105             :      * @brief get the time step of the simulation.
     106             :      * 
     107             :      */
     108             :     ScalarType get_dt()
     109             :     {
     110             :         return m_dt;
     111             :     }
     112             : 
     113             : private:
     114             :     std::unique_ptr<Model> m_model; ///< Unique pointer to the Model simulated.
     115             :     ScalarType m_dt; ///< Time step used for numerical computations in simulation.
     116             : };
     117             : 
     118             : /**
     119             :  * @brief Run a Simulation of an IDE-SECIR model.
     120             :  *
     121             :  * @param[in] tmax End time.
     122             :  * @param[in] dt Initial step size of integration.
     123             :  * @param[in] model An instance of an IDE-SECIR model.
     124             :  * @return A TimeSeries to represent the final simulation result.
     125             :  */
     126             : TimeSeries<ScalarType> simulate(double tmax, double dt, Model const& model);
     127             : 
     128             : } // namespace isecir
     129             : } // namespace mio
     130             : 
     131             : #endif //IDE_SECIR_SIMULATION_H

Generated by: LCOV version 1.14