Skip to content

Commit adc7c49

Browse files
kilianvolmerHenrZu
andauthored
1185 wrong index in ode seir model (#1186)
- Fixed wrong index in model.h of ODE SEIR model - Added test to test_odeseir.cpp that would have failed with the previous wrong index Co-authored-by: HenrZu <69154294+HenrZu@users.noreply.github.com>
1 parent 8958e31 commit adc7c49

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

cpp/models/ode_seir/model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Model
8080
const size_t Ii = this->populations.get_flat_index({i, InfectionState::Infected});
8181

8282
for (auto j : make_index_range(age_groups)) {
83-
const size_t Sj = this->populations.get_flat_index({i, InfectionState::Susceptible});
83+
const size_t Sj = this->populations.get_flat_index({j, InfectionState::Susceptible});
8484
const size_t Ej = this->populations.get_flat_index({j, InfectionState::Exposed});
8585
const size_t Ij = this->populations.get_flat_index({j, InfectionState::Infected});
8686
const size_t Rj = this->populations.get_flat_index({j, InfectionState::Recovered});

cpp/tests/test_odeseir.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,50 @@ TEST(TestSeir, get_flows)
362362
EXPECT_NEAR(dydt_default[2], 25, 1e-12);
363363
}
364364

365+
TEST(TestSeir, get_flows_two_agegroups)
366+
{
367+
mio::oseir::Model<double> model(2);
368+
auto nb_groups = model.parameters.get_num_groups();
369+
370+
constexpr double total_first_population = 400;
371+
constexpr double total_second_population = 200;
372+
373+
auto& params = model.parameters;
374+
375+
model.populations[{mio::AgeGroup(0), mio::oseir::InfectionState::Exposed}] = 100;
376+
model.populations[{mio::AgeGroup(0), mio::oseir::InfectionState::Infected}] = 100;
377+
model.populations[{mio::AgeGroup(0), mio::oseir::InfectionState::Recovered}] = 100;
378+
model.populations.set_difference_from_group_total<mio::AgeGroup>({mio::AgeGroup(0), mio::oseir::InfectionState::Susceptible},
379+
total_first_population);
380+
model.populations[{mio::AgeGroup(1), mio::oseir::InfectionState::Exposed}] = 10;
381+
model.populations[{mio::AgeGroup(1), mio::oseir::InfectionState::Infected}] = 10;
382+
model.populations[{mio::AgeGroup(1), mio::oseir::InfectionState::Recovered}] = 10;
383+
model.populations.set_difference_from_group_total<mio::AgeGroup>({mio::AgeGroup(1), mio::oseir::InfectionState::Susceptible},
384+
total_second_population);
385+
386+
for (auto i = mio::AgeGroup(0); i <= mio::AgeGroup(1); i++) {
387+
model.parameters.get<mio::oseir::TimeExposed<double>>()[i] = 2;
388+
model.parameters.get<mio::oseir::TimeInfected<double>>()[i] = 4;
389+
model.parameters.get<mio::oseir::TransmissionProbabilityOnContact<double>>()[i] = 1;
390+
}
391+
392+
mio::ContactMatrixGroup& contact_matrix = params.get<mio::oseir::ContactPatterns<double>>();
393+
contact_matrix[0] = mio::ContactMatrix(Eigen::MatrixXd::Constant((size_t)nb_groups, (size_t)nb_groups, 1.0));
394+
model.check_constraints();
395+
396+
auto dydt_default = Eigen::VectorXd(6);
397+
dydt_default.setZero();
398+
auto y0 = model.get_initial_values();
399+
model.get_flows(y0, y0, 0, dydt_default);
400+
401+
EXPECT_NEAR(dydt_default[0], 30, 1e-12);
402+
EXPECT_NEAR(dydt_default[1], 50, 1e-12);
403+
EXPECT_NEAR(dydt_default[2], 25, 1e-12);
404+
EXPECT_NEAR(dydt_default[3], 51, 1e-12);
405+
EXPECT_NEAR(dydt_default[4], 5, 1e-12);
406+
EXPECT_NEAR(dydt_default[5], 2.5, 1e-12);
407+
}
408+
365409
TEST(TestSeir, Simulation)
366410
{
367411
double t0 = 0;

0 commit comments

Comments
 (0)