@@ -34,19 +34,17 @@ namespace abm
3434
3535ScalarType daily_transmissions_by_contacts (const ContactExposureRates& rates, const CellIndex cell_index,
3636 const VirusVariant virus, const AgeGroup age_receiver,
37- size_t num_persons_in_age_receiverer_group,
38- const LocalInfectionParameters& params)
37+ size_t age_receiver_group_size, const LocalInfectionParameters& params)
3938{
4039 assert (age_receiver < rates.size <AgeGroup>());
4140 ScalarType prob = 0 ;
4241 for (AgeGroup age_transmitter (0 ); age_transmitter < rates.size <AgeGroup>(); ++age_transmitter) {
4342 if (age_receiver == age_transmitter &&
44- num_persons_in_age_receiverer_group > 1 ) // adjust for the person not meeting themself
43+ age_receiver_group_size > 1 ) // adjust for the person not meeting themself
4544 {
4645 prob += rates[{cell_index, virus, age_transmitter}] *
47- params.get <ContactRates>()[{age_receiver, age_transmitter}] * num_persons_in_age_receiverer_group /
48- (num_persons_in_age_receiverer_group - 1 ) *
49- params.get <ContactRates>()[{age_receiver, age_transmitter}];
46+ params.get <ContactRates>()[{age_receiver, age_transmitter}] * age_receiver_group_size /
47+ (age_receiver_group_size - 1 );
5048 }
5149 else {
5250 prob += rates[{cell_index, virus, age_transmitter}] *
@@ -63,9 +61,9 @@ ScalarType daily_transmissions_by_air(const AirExposureRates& rates, const CellI
6361}
6462
6563void interact (PersonalRandomNumberGenerator& personal_rng, Person& person, const Location& location,
66- const CustomIndexArray<std:: atomic_int_fast32_t , CellIndex, AgeGroup>& local_population_per_age ,
67- const AirExposureRates& local_air_exposure , const ContactExposureRates& local_contact_exposure ,
68- const TimePoint t, const TimeSpan dt, const Parameters& global_parameters)
64+ const PopulationByAge& local_population_by_age, const AirExposureRates& local_air_exposure ,
65+ const ContactExposureRates& local_contact_exposure , const TimePoint t, const TimeSpan dt ,
66+ const Parameters& global_parameters)
6967{
7068 // make sure all dimensions are set correctly and all indices are valid
7169 assert (location.get_cells ().size () == local_air_exposure.size <CellIndex>().get ());
@@ -87,11 +85,11 @@ void interact(PersonalRandomNumberGenerator& personal_rng, Person& person, const
8785 for (CellIndex cell_index : person.get_cells ()) {
8886 std::pair<VirusVariant, ScalarType> local_indiv_trans_prob[static_cast <uint32_t >(VirusVariant::Count)];
8987 for (uint32_t v = 0 ; v != static_cast <uint32_t >(VirusVariant::Count); ++v) {
90- VirusVariant virus = static_cast <VirusVariant>(v);
91- size_t local_population_per_age_receiver = local_population_per_age [{cell_index, age_receiver}];
88+ VirusVariant virus = static_cast <VirusVariant>(v);
89+ size_t local_population_by_age_receiver = local_population_by_age [{cell_index, age_receiver}];
9290 ScalarType local_indiv_trans_prob_v =
9391 (daily_transmissions_by_contacts (local_contact_exposure, cell_index, virus, age_receiver,
94- local_population_per_age_receiver , local_parameters) +
92+ local_population_by_age_receiver , local_parameters) +
9593 daily_transmissions_by_air (local_air_exposure, cell_index, virus, global_parameters)) *
9694 (1 - mask_protection) * (1 - person.get_protection_factor (t, virus, global_parameters));
9795
@@ -142,19 +140,18 @@ void add_exposure_contribution(AirExposureRates& local_air_exposure, ContactExpo
142140 }
143141}
144142
145- void normalize_exposure_contribution (
146- ContactExposureRates& local_contact_exposure,
147- const CustomIndexArray<std::atomic_int_fast32_t , CellIndex, AgeGroup>& local_population_per_age,
148- size_t num_agegroups)
143+ void normalize_exposure_contribution (ContactExposureRates& local_contact_exposure,
144+ const PopulationByAge& local_population_by_age)
149145{
150- for (CellIndex cell = 0 ; cell < local_contact_exposure.size <CellIndex>(); ++cell) {
151- for (auto && virus : enum_members<VirusVariant>()) {
152- for (auto age_group = AgeGroup (0 ); age_group < AgeGroup (num_agegroups); age_group++) {
153- if (local_population_per_age[{cell, age_group}] > 0 ) {
154- local_contact_exposure[{cell, virus, age_group}] =
155- local_contact_exposure[{cell, virus, age_group}] / local_population_per_age[{cell, age_group}];
156- }
157- }
146+ // make sure all dimensions are set correctly and all indices are valid
147+ assert (local_population_by_age.size <AgeGroup>() == local_contact_exposure.size <AgeGroup>());
148+ assert (local_population_by_age.size <CellIndex>() == local_contact_exposure.size <CellIndex>());
149+ assert (local_contact_exposure.size <VirusVariant>() == VirusVariant::Count);
150+
151+ for (auto index : make_index_range (local_contact_exposure.size ())) {
152+ auto age_index = reduce_index<Index<CellIndex, AgeGroup>>(index);
153+ if (local_population_by_age[age_index] > 0 ) {
154+ local_contact_exposure[index] = local_contact_exposure[index] / local_population_by_age[age_index];
158155 }
159156 }
160157}
0 commit comments