diff --git a/cpp/models/ide_secir/model.cpp b/cpp/models/ide_secir/model.cpp index 54f90ca4e1..196e6dd775 100644 --- a/cpp/models/ide_secir/model.cpp +++ b/cpp/models/ide_secir/model.cpp @@ -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()[idx_InfectionTransitions].get_support_max(dt) / dt); + parameters.get()[idx_InfectionTransitions].get_support_max(dt, m_tol) / dt); Eigen::Index num_time_points = m_transitions.get_num_time_points(); @@ -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()[(int)InfectionTransition::InfectedNoSymptomsToInfectedSymptoms] - .get_support_max(dt), + .get_support_max(dt, m_tol), parameters.get()[(int)InfectionTransition::InfectedNoSymptomsToRecovered] - .get_support_max(dt), + .get_support_max(dt, m_tol), parameters.get()[(int)InfectionTransition::InfectedSymptomsToInfectedSevere] - .get_support_max(dt), + .get_support_max(dt, m_tol), parameters.get()[(int)InfectionTransition::InfectedSymptomsToRecovered] - .get_support_max(dt)}); + .get_support_max(dt, m_tol)}); // corresponding index /* need calc_time_index timesteps in sum, @@ -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()[idx_TransitionDistribution1].get_support_max(dt), - parameters.get()[idx_TransitionDistribution2].get_support_max(dt)); + std::max(parameters.get()[idx_TransitionDistribution1].get_support_max(dt, m_tol), + parameters.get()[idx_TransitionDistribution2].get_support_max(dt, m_tol)); Eigen::Index calc_time_index = (Eigen::Index)std::ceil(calc_time / dt) - 1; diff --git a/cpp/models/ide_secir/model.h b/cpp/models/ide_secir/model.h index d3050d30d4..a4193b7877 100644 --- a/cpp/models/ide_secir/model.h +++ b/cpp/models/ide_secir/model.h @@ -74,23 +74,23 @@ class Model ScalarType support_max = std::max( {parameters.get()[(int)InfectionTransition::ExposedToInfectedNoSymptoms] - .get_support_max(dt), + .get_support_max(dt, m_tol), parameters.get()[(int)InfectionTransition::InfectedNoSymptomsToInfectedSymptoms] - .get_support_max(dt), + .get_support_max(dt, m_tol), parameters.get()[(int)InfectionTransition::InfectedNoSymptomsToRecovered] - .get_support_max(dt), + .get_support_max(dt, m_tol), parameters.get()[(int)InfectionTransition::InfectedSymptomsToInfectedSevere] - .get_support_max(dt), + .get_support_max(dt, m_tol), parameters.get()[(int)InfectionTransition::InfectedSymptomsToRecovered] - .get_support_max(dt), + .get_support_max(dt, m_tol), parameters.get()[(int)InfectionTransition::InfectedSevereToInfectedCritical] - .get_support_max(dt), + .get_support_max(dt, m_tol), parameters.get()[(int)InfectionTransition::InfectedSevereToRecovered] - .get_support_max(dt), + .get_support_max(dt, m_tol), parameters.get()[(int)InfectionTransition::InfectedCriticalToDead] - .get_support_max(dt), + .get_support_max(dt, m_tol), parameters.get()[(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( @@ -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 @@ -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 diff --git a/cpp/tests/test_ide_secir.cpp b/cpp/tests/test_ide_secir.cpp index b6047b0528..23bd2d935d 100755 --- a/cpp/tests/test_ide_secir.cpp +++ b/cpp/tests/test_ide_secir.cpp @@ -86,6 +86,8 @@ class ModelTestIdeSecir : public testing::Test model->parameters.set(prob); model->parameters.set(prob); model->parameters.set(prob); + + model->set_tol_for_support_max(1e-10); } virtual void TearDown()