@@ -66,14 +66,46 @@ void Model::initialize(ScalarType dt)
6666 m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Recovered)] -
6767 m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Dead)];
6868 }
69+ else if (m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Susceptible)] > 1e-12 ) {
70+ // take initialized value for Susceptibles if value can't be calculated via the standard formula
71+ m_initialization_method = 2 ;
72+ // calculate other compartment sizes for t=0
73+ other_compartments_current_timestep (dt);
74+
75+ // R; need an initial value for R, therefore do not calculate via compute_recovered()
76+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Recovered)] =
77+ m_N - m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Susceptible)] -
78+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Exposed)] -
79+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedNoSymptoms)] -
80+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedSymptoms)] -
81+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedSevere)] -
82+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedCritical)] -
83+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Dead)];
84+ }
85+ else if (m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Recovered)] > 1e-12 ) {
86+ // if value for Recovered is initialized and standard method is not applicable, calculate Susceptibles via other compartments
87+ // determining other compartment sizes is not dependent of Susceptibles(0), just of the transitions of the past.
88+ // calculate other compartment sizes for t=0
89+ m_initialization_method = 3 ;
90+ other_compartments_current_timestep (dt);
91+
92+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Susceptible)] =
93+ m_N - m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Exposed)] -
94+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedNoSymptoms)] -
95+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedSymptoms)] -
96+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedSevere)] -
97+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedCritical)] -
98+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Recovered)] -
99+ m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Dead)];
100+ }
69101 else {
70102
71103 // compute Susceptibles at time 0 and m_forceofinfection at time -dt as initial values for discretization scheme
72104 // use m_forceofinfection at -dt to be consistent with further calculations of S (see compute_susceptibles()),
73105 // where also the value of m_forceofinfection for the previous timestep is used
74106 update_forceofinfection (dt, true );
75107 if (m_forceofinfection > 1e-12 ) {
76- m_initialization_method = 2 ;
108+ m_initialization_method = 4 ;
77109 m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Susceptible)] =
78110 m_transitions.get_last_value ()[Eigen::Index (InfectionTransition::SusceptibleToExposed)] /
79111 (dt * m_forceofinfection);
@@ -91,46 +123,14 @@ void Model::initialize(ScalarType dt)
91123 m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedCritical)] -
92124 m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Dead)];
93125 }
94- else if (m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Susceptible)] > 1e-12 ) {
95- // take initialized value for Susceptibles if value can't be calculated via the standard formula
96- m_initialization_method = 3 ;
97- // calculate other compartment sizes for t=0
98- other_compartments_current_timestep (dt);
99-
100- // R; need an initial value for R, therefore do not calculate via compute_recovered()
101- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Recovered)] =
102- m_N - m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Susceptible)] -
103- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Exposed)] -
104- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedNoSymptoms)] -
105- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedSymptoms)] -
106- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedSevere)] -
107- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedCritical)] -
108- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Dead)];
109- }
110- else if (m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Recovered)] > 1e-12 ) {
111- // if value for Recovered is initialized and standard method is not applicable, calculate Susceptibles via other compartments
112- // determining other compartment sizes is not dependent of Susceptibles(0), just of the transitions of the past.
113- // calculate other compartment sizes for t=0
114- m_initialization_method = 4 ;
115- other_compartments_current_timestep (dt);
116-
117- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Susceptible)] =
118- m_N - m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Exposed)] -
119- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedNoSymptoms)] -
120- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedSymptoms)] -
121- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedSevere)] -
122- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::InfectedCritical)] -
123- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Recovered)] -
124- m_populations[Eigen::Index (0 )][Eigen::Index (InfectionState::Dead)];
125- }
126126 else {
127127 m_initialization_method = -1 ;
128128 log_error (" Error occured while initializing compartments: Force of infection is evaluated to 0 and neither "
129129 " Susceptibles nor Recovered or total confirmed cases for time 0 were set. One of them should be "
130130 " larger 0." );
131131 }
132132 }
133- // compute m_forceofinfection at time 0 needed for further simulation
133+ // Compute m_forceofinfection at time 0 needed for further simulation.
134134 update_forceofinfection (dt);
135135}
136136
0 commit comments