Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions cpp/models/ide_secir/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void Model::compute_flow(int idx_InfectionTransitions, Eigen::Index idx_Incoming
This needs to be adjusted if we are changing the finite difference scheme */

Eigen::Index calc_time_index = (Eigen::Index)std::ceil(
parameters.get<TransitionDistributions>()[idx_InfectionTransitions].get_support_max(dt) / dt);
parameters.get<TransitionDistributions>()[idx_InfectionTransitions].get_support_max(dt, m_tol) / dt);

Eigen::Index num_time_points = m_transitions.get_num_time_points();

Expand Down Expand Up @@ -196,13 +196,13 @@ void Model::update_forceofinfection(ScalarType dt, bool initialization)
// determine the relevant calculation area = union of the supports of the relevant transition distributions
ScalarType calc_time = std::max(
{parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedNoSymptomsToInfectedSymptoms]
.get_support_max(dt),
.get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedNoSymptomsToRecovered]
.get_support_max(dt),
.get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSymptomsToInfectedSevere]
.get_support_max(dt),
.get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSymptomsToRecovered]
.get_support_max(dt)});
.get_support_max(dt, m_tol)});

// corresponding index
/* need calc_time_index timesteps in sum,
Expand Down Expand Up @@ -262,8 +262,8 @@ void Model::compute_compartment(Eigen::Index idx_InfectionState, Eigen::Index id

// determine relevant calculation area and corresponding index
ScalarType calc_time =
std::max(parameters.get<TransitionDistributions>()[idx_TransitionDistribution1].get_support_max(dt),
parameters.get<TransitionDistributions>()[idx_TransitionDistribution2].get_support_max(dt));
std::max(parameters.get<TransitionDistributions>()[idx_TransitionDistribution1].get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[idx_TransitionDistribution2].get_support_max(dt, m_tol));

Eigen::Index calc_time_index = (Eigen::Index)std::ceil(calc_time / dt) - 1;

Expand Down
29 changes: 20 additions & 9 deletions cpp/models/ide_secir/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ class Model

ScalarType support_max = std::max(
{parameters.get<TransitionDistributions>()[(int)InfectionTransition::ExposedToInfectedNoSymptoms]
.get_support_max(dt),
.get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedNoSymptomsToInfectedSymptoms]
.get_support_max(dt),
.get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedNoSymptomsToRecovered]
.get_support_max(dt),
.get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSymptomsToInfectedSevere]
.get_support_max(dt),
.get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSymptomsToRecovered]
.get_support_max(dt),
.get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSevereToInfectedCritical]
.get_support_max(dt),
.get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSevereToRecovered]
.get_support_max(dt),
.get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedCriticalToDead]
.get_support_max(dt),
.get_support_max(dt, m_tol),
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedCriticalToRecovered]
.get_support_max(dt)});
.get_support_max(dt, m_tol)});

if (m_transitions.get_num_time_points() < (Eigen::Index)std::ceil(support_max / dt)) {
log_error(
Expand Down Expand Up @@ -195,6 +195,16 @@ class Model
*/
void compute_recovered();

/**
* @brief Setter for the tolerance used to calculate the maximum support of the TransitionDistributions.
*
* @param[in] new_tol New tolerance.
*/
void set_tol_for_support_max(ScalarType new_tol)
{
m_tol = new_tol;
}

ParameterSet parameters{}; ///< ParameterSet of Model Parameters.
/* Attention: m_populations and m_transitions do not necessarily have the same number of time points due to the initialization part. */
TimeSeries<ScalarType>
Expand All @@ -206,6 +216,7 @@ class Model
ScalarType m_forceofinfection{0}; ///< Force of infection term needed for numerical scheme.
ScalarType m_N{0}; ///< Total population size of the considered region.
ScalarType m_deaths_before{0}; ///< Deaths before start of simulation (at time -m_dt).
ScalarType m_tol{1e-10}; ///< Tolerance used to calculate the maximum support of the TransitionDistributions.
};

} // namespace isecir
Expand Down
2 changes: 2 additions & 0 deletions cpp/tests/test_ide_secir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class ModelTestIdeSecir : public testing::Test
model->parameters.set<mio::isecir::TransmissionProbabilityOnContact>(prob);
model->parameters.set<mio::isecir::RelativeTransmissionNoSymptoms>(prob);
model->parameters.set<mio::isecir::RiskOfInfectionFromSymptomatic>(prob);

model->set_tol_for_support_max(1e-10);
}

virtual void TearDown()
Expand Down