@@ -1091,18 +1091,20 @@ TEST(TestOdeSECIRVVS, test_commuters)
10911091 model.parameters .get_commuter_nondetection () = non_detection_factor;
10921092 auto sim = mio::osecirvvs::Simulation<>(model);
10931093 auto before_testing = sim.get_result ().get_last_value ().eval ();
1094- auto mobile_population = (sim.get_result ().get_last_value () * mobility_factor).eval ();
1095- auto mobile_population_tested = mobile_population.eval ();
1094+ auto mobile_population = (sim.get_result ().get_last_value () * mobility_factor).eval ();
1095+ auto mobile_population_tested = mobile_population.eval ();
10961096
10971097 mio::osecirvvs::test_commuters<double >(sim, mobile_population_tested, 0.0 );
10981098
10991099 ASSERT_NEAR (mobile_population_tested[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsNaive)],
1100- mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsNaive)] * non_detection_factor,
1100+ mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsNaive)] *
1101+ non_detection_factor,
11011102 1e-5 );
11021103 ASSERT_NEAR (
11031104 sim.get_result ().get_last_value ()[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsNaiveConfirmed)],
11041105 before_testing[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsNaiveConfirmed)] +
1105- mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsNaive)] * (1 - non_detection_factor),
1106+ mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsNaive)] *
1107+ (1 - non_detection_factor),
11061108 1e-5 );
11071109 ASSERT_NEAR (mobile_population_tested[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsPartialImmunity)],
11081110 mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsPartialImmunity)] *
@@ -1115,10 +1117,11 @@ TEST(TestOdeSECIRVVS, test_commuters)
11151117 mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsPartialImmunity)] *
11161118 (1 - non_detection_factor),
11171119 1e-5 );
1118- ASSERT_NEAR (mobile_population_tested[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsImprovedImmunity)],
1119- mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsImprovedImmunity)] *
1120- non_detection_factor,
1121- 1e-5 );
1120+ ASSERT_NEAR (
1121+ mobile_population_tested[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsImprovedImmunity)],
1122+ mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsImprovedImmunity)] *
1123+ non_detection_factor,
1124+ 1e-5 );
11221125 ASSERT_NEAR (
11231126 sim.get_result ()
11241127 .get_last_value ()[Eigen::Index (mio::osecirvvs::InfectionState::InfectedSymptomsImprovedImmunityConfirmed)],
@@ -1128,29 +1131,32 @@ TEST(TestOdeSECIRVVS, test_commuters)
11281131 1e-5 );
11291132
11301133 ASSERT_NEAR (mobile_population_tested[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsNaive)],
1131- mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsNaive)] * non_detection_factor,
1134+ mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsNaive)] *
1135+ non_detection_factor,
11321136 1e-5 );
11331137 ASSERT_NEAR (sim.get_result ()
11341138 .get_last_value ()[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsNaiveConfirmed)],
11351139 before_testing[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsNaiveConfirmed)] +
11361140 mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsNaive)] *
11371141 (1 - non_detection_factor),
11381142 1e-5 );
1139- ASSERT_NEAR (mobile_population_tested[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsPartialImmunity)],
1140- mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsPartialImmunity)] *
1141- non_detection_factor,
1142- 1e-5 );
1143+ ASSERT_NEAR (
1144+ mobile_population_tested[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsPartialImmunity)],
1145+ mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsPartialImmunity)] *
1146+ non_detection_factor,
1147+ 1e-5 );
11431148 ASSERT_NEAR (
11441149 sim.get_result ()
11451150 .get_last_value ()[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsPartialImmunityConfirmed)],
11461151 before_testing[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsPartialImmunityConfirmed)] +
11471152 mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsPartialImmunity)] *
11481153 (1 - non_detection_factor),
11491154 1e-5 );
1150- ASSERT_NEAR (mobile_population_tested[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsImprovedImmunity)],
1151- mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsImprovedImmunity)] *
1152- non_detection_factor,
1153- 1e-5 );
1155+ ASSERT_NEAR (
1156+ mobile_population_tested[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsImprovedImmunity)],
1157+ mobile_population[Eigen::Index (mio::osecirvvs::InfectionState::InfectedNoSymptomsImprovedImmunity)] *
1158+ non_detection_factor,
1159+ 1e-5 );
11541160 ASSERT_NEAR (
11551161 sim.get_result ().get_last_value ()[Eigen::Index (
11561162 mio::osecirvvs::InfectionState::InfectedNoSymptomsImprovedImmunityConfirmed)],
@@ -1160,6 +1166,25 @@ TEST(TestOdeSECIRVVS, test_commuters)
11601166 1e-5 );
11611167}
11621168
1169+ // Test model initialization with total population of 0 and ensure get_flows returns no NaN values
1170+ TEST (TestOdeSECIRVVS, population_zero_no_nan)
1171+ {
1172+ // initialize simple model with total population 0
1173+ mio::osecirvvs::Model<double > model (1 );
1174+ model.populations .set_total (0.0 );
1175+
1176+ // call the get_flows function
1177+ auto dydt_default = Eigen::VectorXd (45 );
1178+ dydt_default.setZero ();
1179+ auto y0 = model.get_initial_values ();
1180+ model.get_flows (y0, y0, 0 , dydt_default);
1181+
1182+ // check that there are now NaN values in dydt_default
1183+ for (int i = 0 ; i < dydt_default.size (); i++) {
1184+ EXPECT_FALSE (std::isnan (dydt_default[i]));
1185+ }
1186+ }
1187+
11631188TEST (TestOdeSECIRVVS, check_constraints_parameters)
11641189{
11651190 auto model = mio::osecirvvs::Model<double >(1 );
0 commit comments