Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

660 compare IDE and ODE models #672

Draft
wants to merge 141 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
7da18d5
Add files
Nov 21, 2022
1e9971e
completed setup
lenaploetzke Nov 28, 2022
341d50f
added first ideas for IDE-SECIR-model
lenaploetzke Nov 28, 2022
418b38e
Little changes
Dec 2, 2022
483984c
implemented some of the necessary simulation functions
lenaploetzke Dec 5, 2022
04abd2f
Add function and example
Dec 7, 2022
7e84de9
Change name: IdeSeirModel -> Model
Dec 9, 2022
a9a7b03
Try example
annawendler Dec 9, 2022
9922053
Merge branch 'main' into 378-implement-ide-model-with-more-compartments
mknaranja Dec 9, 2022
9b736e2
added Deaths etc
lenaploetzke Dec 12, 2022
a31ef6b
Example is running now
annawendler Dec 13, 2022
731edc3
Test example
annawendler Dec 16, 2022
f7183e3
Correct code
annawendler Dec 19, 2022
3138206
Change order in simulate and infection age in compute_flow
annawendler Dec 20, 2022
35c02b4
Convert from index to infection age
annawendler Dec 20, 2022
ebb0be4
InfectionTransitionsMap
mknaranja Dec 20, 2022
bf93ce7
Use infection age instead of get_time()
annawendler Dec 20, 2022
295f990
small bug fixes and cleaning up
lenaploetzke Jan 2, 2023
7667fe7
added transitions to Recovered
lenaploetzke Jan 2, 2023
27a1601
Minor changes
annawendler Jan 9, 2023
4838073
Add dependence of infection_age to TransmissionProbabilityOnContact
annawendler Jan 12, 2023
bd3ce7a
Merge branch '521-extend-parameters' of https://github.com/DLR-SC/mem…
annawendler Jan 12, 2023
5e24d9b
Template for parameter functions
annawendler Jan 13, 2023
1503dcc
Remove some comments
annawendler Jan 16, 2023
abff57a
Remove some comments2
annawendler Jan 16, 2023
0c26e4d
corrected probability in get_size_compartments
lenaploetzke Jan 16, 2023
1f5ca3b
add a documentation
lenaploetzke Jan 16, 2023
3053b41
added std::move() to parameters
lenaploetzke Jan 16, 2023
be58959
Default parameters can be used now; remove TODOs
annawendler Jan 17, 2023
ccc40c6
Change type of tmax, N, Dead0 and dt to ScalarType
annawendler Jan 17, 2023
29bd745
Not working: test_ide_secir.cpp
annawendler Jan 23, 2023
d459220
Make const& for parameters
annawendler Feb 6, 2023
ae787fa
test is now working
lenaploetzke Feb 6, 2023
bacae1c
Some changes and error in test
annawendler Feb 10, 2023
f39a318
Resolved error in test and some documentation
lenaploetzke Feb 13, 2023
9fb34b3
add system test
lenaploetzke Feb 13, 2023
d0d38f7
added test for transitions
lenaploetzke Feb 13, 2023
7a20f04
move initialization so that no faults occur
lenaploetzke Feb 13, 2023
60caf9d
Correct simulation functions and add test
annawendler Feb 24, 2023
f267030
change documentation, Dead0, calculation of forceofinfection
lenaploetzke Feb 27, 2023
5cd738b
deleted temporary dummy file, not needed
lenaploetzke Feb 27, 2023
aacfa2f
delete dt sometimes (is included in transitions)
lenaploetzke Feb 27, 2023
e991c37
Adjust formulas for flows wrt to dt
annawendler Mar 3, 2023
e6538c3
Adjust calc_time_index in compute_flow
annawendler Mar 6, 2023
4ca0b70
Merge branch '378-implement-ide-model-with-more-compartments' into 58…
annawendler Mar 6, 2023
34d513d
Not working: first ideas to implement exp distr
annawendler Mar 6, 2023
b1cfecd
Update documentation and add README
annawendler Mar 9, 2023
3c26770
included tests; fixed some typos
lenaploetzke Mar 9, 2023
67894fc
Creating Simulation class for IDE Secir and small adjustments here an…
mknaranja Mar 14, 2023
dd8ca56
implemented suggested changes and small other fixes
lenaploetzke Mar 16, 2023
e7abe4f
Add constraints to check_constraints
annawendler Mar 16, 2023
6870987
Add constraints to check constraints Co-authored-by: Lena Plötzke <Le…
annawendler Mar 16, 2023
7be0fbc
Merge branch '378-implement-ide-model-with-more-compartments' of http…
annawendler Mar 16, 2023
551789e
Set m_max_support from outside, test for influence
annawendler Mar 17, 2023
e3a04dc
Small change in test
annawendler Mar 17, 2023
6948af0
Add test for proportion between R and D
annawendler Mar 17, 2023
2553d41
Rework initalization, separate tests + small
annawendler Mar 27, 2023
44d401c
Sort functions in model.cpp and model.h
annawendler Apr 5, 2023
c4ad763
Extend check_constraints()
annawendler Apr 5, 2023
9b58470
fix build error
annawendler Apr 17, 2023
3975cd5
merge
annawendler Apr 18, 2023
bc313d2
fix merging mistakes
lenaploetzke Apr 18, 2023
2d49f80
merge main into branch
annawendler Apr 20, 2023
98bc4b7
idea for generalization, not working yet
lenaploetzke Apr 20, 2023
aa3fa4d
less errors
annawendler Apr 22, 2023
b8713b6
building now
annawendler Apr 25, 2023
f01dfef
can (in theory) set stateagefunction and funcapram
annawendler May 3, 2023
187d66b
running now
annawendler May 11, 2023
de02cfb
adapt tests
annawendler May 11, 2023
794609b
remove nnecessary functions
annawendler May 15, 2023
3011083
add documentation
annawendler May 15, 2023
1d4adcb
adapt check constraints, StateAgeFunction not
annawendler May 16, 2023
14aca3a
add virtual destructor and special member funcs
annawendler May 22, 2023
4f44af1
merge branch 521 (state age dependent parameters)
annawendler May 22, 2023
1a41053
Use StateAgeFunctionWrapper instead of
annawendler May 22, 2023
1972374
basic version of get_max_support
annawendler May 22, 2023
f9beba8
Make Function in StateAgeFunction pure virtual
annawendler May 30, 2023
294e8f2
add test for safwrapper
annawendler Jun 2, 2023
ba6b394
small stuff
annawendler Jun 2, 2023
8014532
merge 521 into this branch
annawendler Jun 2, 2023
fd0df5e
Merge 588-exponential-distribution-in-transitiondistribution
annawendler Jun 5, 2023
164beb9
compute inital flows from compartments;
annawendler Jun 9, 2023
5b26b72
working now
annawendler Jun 9, 2023
b8e4b3a
eval instead of Function
annawendler Jun 15, 2023
fa3a41d
Merge 521 and adapt accordingly
annawendler Jun 15, 2023
f43d9bf
try out stuff
annawendler Jun 16, 2023
4cc4c6f
Merge branch '588-exponential-distribution-in-transitiondistribution'…
annawendler Jun 16, 2023
50e2d8e
some changes
annawendler Jun 28, 2023
5ac75ab
current status
annawendler Jul 17, 2023
ada724a
update support_max after setting a new parameter
annawendler Aug 7, 2023
f7e541c
add test
annawendler Aug 7, 2023
e954560
remove print
annawendler Aug 8, 2023
95e7930
correct formula
annawendler Aug 8, 2023
6357fc7
Merge branch 'main' into 660-compare-ide-and-ode-models
annawendler Aug 10, 2023
20aaf39
Merge branch '723-compute-support_max-after-setting-new-parameter-in-…
annawendler Aug 10, 2023
bc2cf0b
Merge branch '725-correction-of-formula-for-susceptibles-in-initializ…
annawendler Aug 10, 2023
875eef7
Merge branch 'main' into 660-compare-ide-and-ode-models
annawendler Aug 18, 2023
6344fa7
Merge branch 'main' into 660-compare-ide-and-ode-models
annawendler Aug 18, 2023
6b0bf0d
test is running now; rename files for debugging
annawendler Aug 21, 2023
c9035d9
correct times in time series now
annawendler Aug 21, 2023
7c438a5
Correct rates in TransitionDistributions, set SECIHUR0
annawendler Aug 25, 2023
fca50c8
adjust example, compute order of convergence
annawendler Sep 11, 2023
6062b7c
clean up
annawendler Oct 30, 2023
33157b0
convergence plots for all compartments
annawendler Jan 26, 2024
f6c53af
more flexible handling of numerical experiments
annawendler Feb 16, 2024
98c24e8
minor update of numerical experiments
annawendler Feb 21, 2024
5076119
adapt computation of flows from ode and small changes
annawendler Feb 22, 2024
f148d5e
clean up
annawendler Feb 23, 2024
b1c9f41
option for setting m_populations in cnstructor or initialize_solver
annawendler Feb 23, 2024
943fd6c
Merge branch 'main' into 660-compare-ide-and-ode-models
annawendler Feb 23, 2024
79e787a
adapt constructor
annawendler Feb 26, 2024
b323fa0
go back to case distinction with need_flow_init
annawendler Feb 26, 2024
7ffa592
try different order in initialization and adjust accordingly
annawendler Feb 29, 2024
d79e1f3
update settings
annawendler Mar 19, 2024
5625fa9
Merge branch 'main' into 660-compare-ide-and-ode-models
annawendler Mar 19, 2024
9e8bdb0
Merge branch 'main' into 660-compare-ide-and-ode-models
annawendler Mar 19, 2024
b5be2ce
Adjust to new parameters in ODE model
annawendler Mar 19, 2024
c91a6c6
correct reordering of initializations for solver
annawendler Mar 19, 2024
134912d
Initialize all IDE timesteps based on same ODE model
annawendler Mar 19, 2024
16ccacb
Investigate convergence of flows
annawendler Mar 22, 2024
c2c0d0d
adjust initialize_from_ode
annawendler Mar 26, 2024
fc6d8c1
add documentation
annawendler Mar 26, 2024
3bf3a66
change index
annawendler May 14, 2024
0813b38
merge main
annawendler May 14, 2024
36051ca
adjust to merge
annawendler May 14, 2024
0d2236a
temporary fix
annawendler May 14, 2024
b017124
adjust filepaths
annawendler May 14, 2024
a8f954b
small adaptations
annawendler May 16, 2024
0a7a5ff
Merge main
annawendler May 21, 2024
2cb68e2
adjust to main
annawendler May 22, 2024
28d22a9
adjust plots
annawendler May 31, 2024
60ab111
compute l2 norm for all compartments/flows
annawendler Jul 11, 2024
753c336
remove additional settings from bug search
annawendler Jul 15, 2024
763bced
adjust convergence plots
annawendler Jul 24, 2024
6f7dc00
Merge branch 'main' into 660-compare-ide-and-ode-models
lenaploetzke Jul 26, 2024
5301105
clean up and relative norm
lenaploetzke Jul 30, 2024
08d74f0
formatting and relative norm
lenaploetzke Jul 31, 2024
ddd13c5
make plots more beautiful
lenaploetzke Jul 31, 2024
f90f3f7
add r
lenaploetzke Jul 31, 2024
c630cd7
adapt label
lenaploetzke Aug 7, 2024
89bd4cf
adapt ylabel
annawendler Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ add_executable(history_example history.cpp)
target_link_libraries(history_example PRIVATE memilio)
target_compile_options(history_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(ide_ode_secir_example ide_ode_secir.cpp)
target_link_libraries(ide_ode_secir_example PRIVATE memilio ide_secir)

if(MEMILIO_HAS_JSONCPP)
add_executable(ode_secir_read_graph_example ode_secir_read_graph.cpp)
target_link_libraries(ode_secir_read_graph_example PRIVATE memilio ode_secir)
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/ide_initialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* limitations under the License.
*/

#include "ide_secir/model.h"
#include "ide_secir/model_ide.h"
#include "ide_secir/infection_state.h"
#include "ide_secir/simulation.h"
#include "ide_secir/parameters_io.h"
Expand Down
305 changes: 305 additions & 0 deletions cpp/examples/ide_ode_secir.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cpp/examples/ide_secir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* limitations under the License.
*/

#include "ide_secir/model.h"
#include "ide_secir/model_ide.h"
#include "ide_secir/infection_state.h"
#include "ide_secir/simulation.h"
#include "memilio/config.h"
Expand Down
6 changes: 4 additions & 2 deletions cpp/models/ide_secir/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
add_library(ide_secir
infection_state.h
model.h
model.cpp
model_ide.h
model_ide.cpp
simulation.h
simulation.cpp
parameters.h
initialize_from_ode.h
initialize_from_ode.cpp
parameters_io.h
parameters_io.cpp
)
Expand Down
160 changes: 160 additions & 0 deletions cpp/models/ide_secir/initialize_from_ode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* Copyright (C) 2020-2023 German Aerospace Center (DLR-SC)
*
* Authors: Anna Wendler
*
* Contact: Martin J. Kuehn <[email protected]>
*
* 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 "ide_secir/model_ide.h"
#include "ide_secir/parameters.h"
#include "ode_secir/model.h"
#include "infection_state.h"
#include "memilio/config.h"
#include "memilio/utils/logging.h"
#include "memilio/math/eigen.h"

namespace mio
{
namespace isecir
{
void get_flows_from_ode_compartments(mio::osecir::Model<ScalarType>& model_ode,
mio::TimeSeries<ScalarType> compartments, mio::TimeSeries<ScalarType>& flows,
ScalarType t_max, ScalarType t_window, ScalarType dt_reference,
ScalarType dt_comparison)
{ //TODO: Check that flows is an empty TimeSeries at the beginning.
int num_transitions = (int)mio::isecir::InfectionTransition::Count;

// Use scale_timesteps to get from index wrt ODE timestep to index wrt IDE timestep.
// Here we assume that we solve the ODE model on a finer scale (or equal scale) than the IDE model.

if (dt_comparison < 1e-10) {
dt_comparison = dt_reference;
}

ScalarType scale_timesteps = dt_comparison / dt_reference;

// Compute index variables with respect to dt_comparison.
Eigen::Index t_window_index = Eigen::Index(std::ceil(t_window / dt_comparison));
Eigen::Index t_max_index = Eigen::Index(std::ceil(t_max / dt_comparison));

Eigen::Index flows_start_index = t_max_index - t_window_index + 1;

// Add time points to TimeSeries containing flows.
for (Eigen::Index i = flows_start_index; i <= t_max_index; i++) {
flows.add_time_point(i * dt_comparison, mio::TimeSeries<ScalarType>::Vector::Constant(num_transitions, 0));
flows.get_last_value()[Eigen::Index(mio::isecir::InfectionTransition::SusceptibleToExposed)] +=
compartments[scale_timesteps * (i - 1)][Eigen::Index(mio::osecir::InfectionState::Susceptible)] -
compartments[scale_timesteps * i][Eigen::Index(mio::osecir::InfectionState::Susceptible)];
}

// compute resulting flows as combination of change in compartments and previously computed flows

// flow from E to C
for (int i = flows_start_index; i <= t_max_index; i++) {
flows[i - flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::ExposedToInfectedNoSymptoms)] =
compartments[scale_timesteps * (i - 1)][Eigen::Index(mio::osecir::InfectionState::Exposed)] -
compartments[scale_timesteps * i][Eigen::Index(mio::osecir::InfectionState::Exposed)] +
flows[i - flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::SusceptibleToExposed)];
}

// flow from C to I and from C to R
for (int i = flows_start_index; i <= t_max_index; i++) {
flows[i -
flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::InfectedNoSymptomsToInfectedSymptoms)] =
(1 -
model_ode.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<ScalarType>>()[(mio::AgeGroup)0]) *
(compartments[scale_timesteps * (i - 1)][Eigen::Index(mio::osecir::InfectionState::InfectedNoSymptoms)] -
compartments[scale_timesteps * i][Eigen::Index(mio::osecir::InfectionState::InfectedNoSymptoms)] +
flows[i - flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::ExposedToInfectedNoSymptoms)]);
flows[i - flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::InfectedNoSymptomsToRecovered)] =
(model_ode.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<ScalarType>>()[(mio::AgeGroup)0]) *
(compartments[scale_timesteps * (i - 1)][Eigen::Index(mio::osecir::InfectionState::InfectedNoSymptoms)] -
compartments[scale_timesteps * i][Eigen::Index(mio::osecir::InfectionState::InfectedNoSymptoms)] +
flows[i - flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::ExposedToInfectedNoSymptoms)]);
}

// flow from I to H and from I to R
for (int i = flows_start_index; i <= t_max_index; i++) {
flows[i - flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::InfectedSymptomsToInfectedSevere)] =
model_ode.parameters.get<mio::osecir::SeverePerInfectedSymptoms<ScalarType>>()[(mio::AgeGroup)0] *
(compartments[scale_timesteps * (i - 1)][Eigen::Index(mio::osecir::InfectionState::InfectedSymptoms)] -
compartments[scale_timesteps * i][Eigen::Index(mio::osecir::InfectionState::InfectedSymptoms)] +
flows[i - flows_start_index]
[Eigen::Index(mio::isecir::InfectionTransition::InfectedNoSymptomsToInfectedSymptoms)]);
flows[i - flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::InfectedSymptomsToRecovered)] =
(1 - model_ode.parameters.get<mio::osecir::SeverePerInfectedSymptoms<ScalarType>>()[(mio::AgeGroup)0]) *
(compartments[scale_timesteps * (i - 1)][Eigen::Index(mio::osecir::InfectionState::InfectedSymptoms)] -
compartments[scale_timesteps * i][Eigen::Index(mio::osecir::InfectionState::InfectedSymptoms)] +
flows[i - flows_start_index]
[Eigen::Index(mio::isecir::InfectionTransition::InfectedNoSymptomsToInfectedSymptoms)]);
}

// flow from H to U and from H to R
for (int i = flows_start_index; i <= t_max_index; i++) {
flows[i - flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::InfectedSevereToInfectedCritical)] =
model_ode.parameters.get<mio::osecir::CriticalPerSevere<ScalarType>>()[(mio::AgeGroup)0] *
(compartments[scale_timesteps * (i - 1)][Eigen::Index(mio::osecir::InfectionState::InfectedSevere)] -
compartments[scale_timesteps * i][Eigen::Index(mio::osecir::InfectionState::InfectedSevere)] +
flows[i - flows_start_index]
[Eigen::Index(mio::isecir::InfectionTransition::InfectedSymptomsToInfectedSevere)]);
flows[i - flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::InfectedSevereToRecovered)] =
(1 - model_ode.parameters.get<mio::osecir::CriticalPerSevere<ScalarType>>()[(mio::AgeGroup)0]) *
(compartments[scale_timesteps * (i - 1)][Eigen::Index(mio::osecir::InfectionState::InfectedSevere)] -
compartments[scale_timesteps * i][Eigen::Index(mio::osecir::InfectionState::InfectedSevere)] +
flows[i - flows_start_index]
[Eigen::Index(mio::isecir::InfectionTransition::InfectedSymptomsToInfectedSevere)]);
}

// flow from U to D and from U to R
for (int i = flows_start_index; i <= t_max_index; i++) {
flows[i - flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::InfectedCriticalToDead)] =
model_ode.parameters.get<mio::osecir::DeathsPerCritical<ScalarType>>()[(mio::AgeGroup)0] *
(compartments[scale_timesteps * (i - 1)][Eigen::Index(mio::osecir::InfectionState::InfectedCritical)] -
compartments[scale_timesteps * i][Eigen::Index(mio::osecir::InfectionState::InfectedCritical)] +
flows[i - flows_start_index]
[Eigen::Index(mio::isecir::InfectionTransition::InfectedSevereToInfectedCritical)]);
flows[i - flows_start_index][Eigen::Index(mio::isecir::InfectionTransition::InfectedCriticalToRecovered)] =
(1 - model_ode.parameters.get<mio::osecir::DeathsPerCritical<ScalarType>>()[(mio::AgeGroup)0]) *
(compartments[scale_timesteps * (i - 1)][Eigen::Index(mio::osecir::InfectionState::InfectedCritical)] -
compartments[scale_timesteps * i][Eigen::Index(mio::osecir::InfectionState::InfectedCritical)] +
flows[i - flows_start_index]
[Eigen::Index(mio::isecir::InfectionTransition::InfectedSevereToInfectedCritical)]);
}
}

void compute_initial_flows_for_ide_from_ode(mio::osecir::Model<ScalarType>& model_ode, mio::isecir::Model& model_ide,
mio::TimeSeries<ScalarType> secihurd_ode, ScalarType t0_ide,
ScalarType dt_ode, ScalarType dt_ide)
{
std::cout << "Computing initial flows. \n";

// Use t_window=t0_ide to get flows from t0 onwards.
get_flows_from_ode_compartments(model_ode, secihurd_ode, model_ide.m_transitions, t0_ide, t0_ide, dt_ode, dt_ide);

// Correct values in populations.
if (model_ide.m_populations.get_last_time() != model_ide.m_transitions.get_last_time()) {
model_ide.m_populations.remove_last_time_point();
model_ide.m_populations.add_time_point<Eigen::VectorXd>(
model_ide.m_transitions.get_last_time(),
TimeSeries<ScalarType>::Vector::Constant((int)InfectionState::Count, 0));
model_ide.m_populations[0][Eigen::Index(InfectionState::Dead)] =
secihurd_ode[(Eigen::Index)secihurd_ode.get_num_time_points() -
(secihurd_ode.get_last_time() - t0_ide) / dt_ode - 1]
[(Eigen::Index)mio::osecir::InfectionState::Dead];
}
}

} // namespace isecir
} // namespace mio
81 changes: 81 additions & 0 deletions cpp/models/ide_secir/initialize_from_ode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2020-2023 German Aerospace Center (DLR-SC)
*
* Authors: Anna Wendler
*
* Contact: Martin J. Kuehn <[email protected]>
*
* 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.
*/

#ifndef IDE_SECIR_INITIALIZE_FROM_ODE_H
#define IDE_SECIR_INITIALIZE_FROM_ODE_H

#include "ide_secir/model_ide.h"
#include "ide_secir/parameters.h"
#include "ode_secir/model.h"
#include "infection_state.h"
#include "memilio/config.h"
#include "memilio/utils/logging.h"
#include "memilio/math/eigen.h"

namespace mio
{
namespace isecir
{
/**
* @brief Takes the resulting compartments of an ODE simulation and computes the respective flows and stores them in a TimeSeries.
*
* With t_max and t_window it can be determined for which time window the flows will be computed.
* dt_reference is the time step size of the ODE simulation. By default, we compute the flows with the same time step size.
* It is also possible to compute the corresponding flows for a bigger time step which can be given by dt_comparison. Here we assume, that
* dt_comparison is a multiple of dt_reference.
*
* @param[in] model_ode ODE model that is used.
* @param[in] compartments TimeSeries containing compartments from ODE simulation
* @param[out] flows TimeSeries where the computed flows will be stored.
* @param[in] t_max Maximal time for which the flows are computed.
* @param[in] t_window Time window before t_max for which flows will be computed.
* @param[in] dt_reference Reference time step size (coming from ODE simulation).
* @param[in] dt_comparison Time step size. Default is dt_reference.
*/
void get_flows_from_ode_compartments(mio::osecir::Model<ScalarType>& model_ode,
mio::TimeSeries<ScalarType> compartments, mio::TimeSeries<ScalarType>& flows,
ScalarType t_max, ScalarType t_window, ScalarType dt_reference,
ScalarType dt_comparison = 0.);

/**
* @brief Computes the inital flows that are needed for an IDE simulation given we have the compartments from an ODE
* simulation for an adequate time window before t0_ide.
*
* Using model_ode we get simulated results for the compartments stored in secihurd_ode. Then we compute the needed iniital flows
* for the IDE model model_ide until time t0_ide. Here we assumen, that model_ode and model_ide are matching, i.e. that the parameters
* of model_ideare chosen such that model_ide shopuld reduce to model_ode by choosing exponentially distributed transitions with the
* the corresponding mean stay times etc. The time step size of ODE and IDE simulation can be chosen independently. However, we assume
* that dt_is a multiple of dt_ide.
*
* @param[in] model_ode ODE model that is used.
* @param[in] model_ide IDE model that is used.
* @param[in] secihurd_ode TimeSeries containing compartments from ODE simulation.
* @param[in] t0_ide Start time of IDE simulation until which we need to compute flows.
* @param[in] dt_ode Time step size of ODE simulation.
* @param[in] dt_ide Time step size of IDE simulation.
*/
void compute_initial_flows_for_ide_from_ode(mio::osecir::Model<ScalarType>& model_ode, mio::isecir::Model& model_ide,
mio::TimeSeries<ScalarType> secihurd_ode, ScalarType t0_ide,
ScalarType dt_ode, ScalarType dt_ide);

} // namespace isecir
} // namespace mio

#endif //IDE_SECIR_INITIALIZE_FROM_ODE_H
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ide_secir/model.h"
#include "ide_secir/model_ide.h"
#include "ide_secir/parameters.h"
#include "ode_secir/model.h"
#include "infection_state.h"
#include "memilio/config.h"
#include "memilio/utils/logging.h"
Expand Down
15 changes: 10 additions & 5 deletions cpp/models/ide_secir/model.h → cpp/models/ide_secir/model_ide.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "abm/virus_variant.h"
#include "ide_secir/parameters.h"
#include "ide_secir/infection_state.h"
#include "ode_secir/model.h"
#include "memilio/config.h"
#include "memilio/utils/time_series.h"

Expand Down Expand Up @@ -53,6 +54,7 @@ class Model
* @param[in] total_confirmed_cases Total confirmed cases at time t0 can be set if it should be used for initialization.
* @param[in, out] Parameterset_init Used Parameters for simulation.
*/

Model(TimeSeries<ScalarType>&& init, ScalarType N_init, ScalarType deaths, ScalarType total_confirmed_cases = 0,
const ParameterSet& Parameterset_init = ParameterSet());

Expand Down Expand Up @@ -205,8 +207,9 @@ class Model

// It may be possible to run the simulation with fewer time points, but this number ensures that it is possible.
if (m_transitions.get_num_time_points() < (Eigen::Index)std::ceil(get_global_support_max(dt) / dt)) {
log_error(
"Initialization failed. Not enough time points for transitions given before start of simulation.");
log_error("Initialization failed. Not enough time points for transitions given before start of simulation. "
"{} time points are required.",
(Eigen::Index)std::ceil(get_global_support_max(dt) / dt));
return true;
}

Expand All @@ -219,8 +222,10 @@ class Model
}
}
if (m_transitions.get_last_time() != m_populations.get_last_time()) {
log_error("Last time point of TimeSeries for transitions does not match last time point of TimeSeries for "
"compartments. Both of these time points have to agree for a sensible simulation.");
log_error(
"Last time point of TimeSeries for transitions {} does not match last time point of TimeSeries for "
"compartments {}. For a meaningful simulation, these two points must match.",
m_transitions.get_last_time(), m_populations.get_last_time());
return true;
}

Expand Down Expand Up @@ -304,7 +309,7 @@ class Model
ScalarType m_N{0}; ///< Total population size of the considered region.
ScalarType m_tol{1e-10}; ///< Tolerance used to calculate the maximum support of the TransitionDistributions.
int m_initialization_method{0}; ///< Gives the index of the method used for the initialization of the model.
//See also get_initialization_method_compartments() for the number code.
// See also get_initialization_method_compartments() for the number code.
};

} // namespace isecir
Expand Down
2 changes: 1 addition & 1 deletion cpp/models/ide_secir/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ namespace isecir
/**********************************************
* Define Parameters of the IDE-SECIHURD model *
**********************************************/

/**
* @brief Transition distribution for each transition in #InfectionTransition.
*
Expand Down Expand Up @@ -325,6 +324,7 @@ class Parameters : public ParametersBase
return false;
}

public:
/**
* deserialize an object of this class.
* @see mio::deserialize
Expand Down
2 changes: 1 addition & 1 deletion cpp/models/ide_secir/parameters_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#ifdef MEMILIO_HAS_JSONCPP

#include "ide_secir/model.h"
#include "ide_secir/model_ide.h"
#include "ide_secir/infection_state.h"
#include "memilio/math/eigen.h"
#include "memilio/io/epi_data.h"
Expand Down
2 changes: 1 addition & 1 deletion cpp/models/ide_secir/parameters_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#ifdef MEMILIO_HAS_JSONCPP

#include "ide_secir/model.h"
#include "ide_secir/model_ide.h"
#include "memilio/io/io.h"
#include "memilio/utils/date.h"

Expand Down
Loading