@@ -77,28 +77,35 @@ class Model : public mio::CompartmentalModel<FP, InfectionState, mio::Population
7777 return static_cast <size_t >(s);
7878 };
7979
80- FP I_total = y[idx (InfectionState::I1)] + y[idx (InfectionState::I2)] + y[idx (InfectionState::I3)] +
81- y[idx (InfectionState::I4)];
82- FP R_total = y[idx (InfectionState::R1)] + y[idx (InfectionState::R2)] + y[idx (InfectionState::R3)] +
83- y[idx (InfectionState::R4)];
84- FP N = pop.sum ();
80+ const FP I_total = y[idx (InfectionState::I1)] + y[idx (InfectionState::I2)] + y[idx (InfectionState::I3)] +
81+ y[idx (InfectionState::I4)];
82+ const FP R_total = y[idx (InfectionState::R1)] + y[idx (InfectionState::R2)] + y[idx (InfectionState::R3)] +
83+ y[idx (InfectionState::R4)];
84+ const FP N = pop.sum ();
85+ const FP inv_N = (N > Limits<FP>::zero_tolerance ())
86+ ? FP (1 ) / N
87+ : FP (0.0 ); // avoid excessive force of infection or division by zero when empty
88+ const FP lambda1 = beta1 * I_total * inv_N;
89+ const FP lambda2 = beta2 * I_total * inv_N;
90+ const FP lambda3 = beta3 * I_total * inv_N;
91+ const FP lambda4 = beta4 * I_total * inv_N;
8592
8693 // dM
8794 dydt[idx (InfectionState::MaternalImmune)] = mu * R_total - (xi + mu) * y[idx (InfectionState::MaternalImmune)];
8895
8996 // dS1
9097 dydt[idx (InfectionState::S1)] = mu * (N - R_total) + xi * y[idx (InfectionState::MaternalImmune)] -
91- mu * y[idx (InfectionState::S1)] - beta1 * I_total * y[idx (InfectionState::S1)];
98+ mu * y[idx (InfectionState::S1)] - lambda1 * y[idx (InfectionState::S1)];
9299
93100 // dE1..E4
94101 dydt[idx (InfectionState::E1 )] =
95- beta1 * I_total * y[idx (InfectionState::S1)] - (mu + sigma) * y[idx (InfectionState::E1 )];
102+ lambda1 * y[idx (InfectionState::S1)] - (mu + sigma) * y[idx (InfectionState::E1 )];
96103 dydt[idx (InfectionState::E2 )] =
97- beta2 * I_total * y[idx (InfectionState::S2)] - (mu + sigma) * y[idx (InfectionState::E2 )];
104+ lambda2 * y[idx (InfectionState::S2)] - (mu + sigma) * y[idx (InfectionState::E2 )];
98105 dydt[idx (InfectionState::E3 )] =
99- beta3 * I_total * y[idx (InfectionState::S3)] - (mu + sigma) * y[idx (InfectionState::E3 )];
106+ lambda3 * y[idx (InfectionState::S3)] - (mu + sigma) * y[idx (InfectionState::E3 )];
100107 dydt[idx (InfectionState::E4 )] =
101- beta4 * I_total * y[idx (InfectionState::S4)] - (mu + sigma) * y[idx (InfectionState::E4 )];
108+ lambda4 * y[idx (InfectionState::S4)] - (mu + sigma) * y[idx (InfectionState::E4 )];
102109
103110 // dI1..I4
104111 dydt[idx (InfectionState::I1)] = sigma * y[idx (InfectionState::E1 )] - (nu + mu) * y[idx (InfectionState::I1)];
@@ -113,12 +120,12 @@ class Model : public mio::CompartmentalModel<FP, InfectionState, mio::Population
113120 dydt[idx (InfectionState::R4)] = nu * y[idx (InfectionState::I4)] - (mu + gamma) * y[idx (InfectionState::R4)];
114121
115122 // dS2,S3,S4
116- dydt[idx (InfectionState::S2)] = gamma * y[ idx (InfectionState::R1)] - mu * y[ idx (InfectionState::S2)] -
117- beta2 * I_total * y[idx (InfectionState::S2)];
118- dydt[idx (InfectionState::S3)] = gamma * y[ idx (InfectionState::R2)] - mu * y[ idx (InfectionState::S3)] -
119- beta3 * I_total * y[idx (InfectionState::S3)];
123+ dydt[idx (InfectionState::S2)] =
124+ gamma * y[ idx (InfectionState::R1)] - mu * y[ idx (InfectionState::S2)] - lambda2 * y[idx (InfectionState::S2)];
125+ dydt[idx (InfectionState::S3)] =
126+ gamma * y[ idx (InfectionState::R2)] - mu * y[ idx (InfectionState::S3)] - lambda3 * y[idx (InfectionState::S3)];
120127 dydt[idx (InfectionState::S4)] = gamma * (y[idx (InfectionState::R3)] + y[idx (InfectionState::R4)]) -
121- mu * y[idx (InfectionState::S4)] - beta4 * I_total * y[idx (InfectionState::S4)];
128+ mu * y[idx (InfectionState::S4)] - lambda4 * y[idx (InfectionState::S4)];
122129 }
123130
124131 /* *
0 commit comments