Line data Source code
1 : /* 2 : * Copyright (C) 2020-2025 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 : #include "ide_secir/simulation.h" 21 : #include "ide_secir/model.h" 22 : #include "memilio/config.h" 23 : #include "memilio/utils/time_series.h" 24 : #include <memory> 25 : 26 : namespace mio 27 : { 28 : namespace isecir 29 : { 30 : 31 15 : void Simulation::advance(ScalarType tmax) 32 : { 33 15 : mio::log_info("Simulating IDE-SECIR from t0 = {} until tmax = {} with dt = {} .", 34 15 : m_model->m_transitions.get_last_time(), tmax, m_dt); 35 15 : m_model->set_transitiondistributions_support_max(m_dt); 36 15 : m_model->set_transitiondistributions_derivative(m_dt); 37 15 : m_model->set_transitiondistributions_in_forceofinfection(m_dt); 38 15 : m_model->initial_compute_compartments(m_dt); 39 : 40 : // For every time step: 41 123 : while (m_model->m_transitions.get_last_time() < tmax - m_dt / 2) { 42 : 43 108 : m_model->m_transitions.add_time_point(m_model->m_transitions.get_last_time() + m_dt); 44 108 : m_model->m_populations.add_time_point(m_model->m_populations.get_last_time() + m_dt); 45 : 46 : // compute Susceptibles: 47 108 : m_model->compute_susceptibles(m_dt); 48 : 49 : // Compute flows: 50 108 : m_model->flows_current_timestep(m_dt); 51 : 52 : // Update remaining compartments: 53 108 : m_model->update_compartments(); 54 : 55 : // Compute m_forceofinfection (only used for calculation of Susceptibles and flow SusceptibleToExposed in the next timestep!): 56 108 : m_model->compute_forceofinfection(m_dt); 57 : } 58 15 : } 59 : 60 2 : TimeSeries<ScalarType> simulate(ScalarType tmax, ScalarType dt, Model const& m_model) 61 : { 62 2 : m_model.check_constraints(dt); 63 2 : Simulation sim(m_model, dt); 64 2 : sim.advance(tmax); 65 4 : return sim.get_result(); 66 2 : } 67 : 68 : } // namespace isecir 69 : } // namespace mio