diff --git a/cpp/benchmarks/abm.cpp b/cpp/benchmarks/abm.cpp index a9a179ae1d..1d40d27290 100644 --- a/cpp/benchmarks/abm.cpp +++ b/cpp/benchmarks/abm.cpp @@ -156,8 +156,8 @@ void abm_benchmark(benchmark::State& state, size_t num_persons, std::initializer std::cout << "num_persons = " << num_persons << "\n"; for (auto inf_state = 0; inf_state < (int)mio::abm::InfectionState::Count; inf_state++) { std::cout << "inf_state = " << inf_state << ", sum = " - << sim.get_model().get_subpopulation_combined(sim.get_time(), - mio::abm::InfectionState(inf_state)) + << sim.get_model().get_subpopulation_inf_state_combined(sim.get_time(), + mio::abm::InfectionState(inf_state)) << "\n"; } } diff --git a/cpp/examples/graph_abm.cpp b/cpp/examples/graph_abm.cpp index 34e89485c9..8e14234df8 100644 --- a/cpp/examples/graph_abm.cpp +++ b/cpp/examples/graph_abm.cpp @@ -57,7 +57,7 @@ struct Logger : mio::LogAlways { for (size_t i = 0; i < static_cast(mio::abm::InfectionState::Count); ++i) { auto inf_state = mio::abm::InfectionState(i); persons_per_infection_state.insert( - {inf_state, sim.get_model().get_subpopulation(loc.get_id(), t, inf_state)}); + {inf_state, sim.get_model().get_subpopulation_inf_state(loc.get_id(), t, inf_state)}); } location_information.push_back(std::make_tuple(loc.get_model_id(), loc.get_type(), loc.get_id(), sim.get_model().get_number_persons(loc.get_id()), diff --git a/cpp/models/abm/common_abm_loggers.h b/cpp/models/abm/common_abm_loggers.h index a453d9554b..59fc231efe 100644 --- a/cpp/models/abm/common_abm_loggers.h +++ b/cpp/models/abm/common_abm_loggers.h @@ -180,8 +180,8 @@ struct LogInfectionState : mio::LogAlways { PRAGMA_OMP(for) for (auto& location : sim.get_model().get_locations()) { for (uint32_t inf_state = 0; inf_state < (int)mio::abm::InfectionState::Count; inf_state++) { - sum[inf_state] += sim.get_model().get_subpopulation(location.get_id(), curr_time, - mio::abm::InfectionState(inf_state)); + sum[inf_state] += sim.get_model().get_subpopulation_inf_state(location.get_id(), curr_time, + mio::abm::InfectionState(inf_state)); } } return std::make_pair(curr_time, sum); diff --git a/cpp/models/abm/model.cpp b/cpp/models/abm/model.cpp index 2b19d8af1a..8a8fafeb32 100755 --- a/cpp/models/abm/model.cpp +++ b/cpp/models/abm/model.cpp @@ -292,6 +292,12 @@ void Model::compute_exposure_caches(TimePoint t, TimeSpan dt) get_location(person.get_location()), t, dt); } } // implicit taskloop barrier + + // 3) normalize the exposure caches + PRAGMA_OMP(taskloop) + for (size_t i = 0; i < num_locations; ++i) { + } + } // implicit single barrier } @@ -341,19 +347,20 @@ LocationId Model::find_location(LocationType type, const PersonId person) const return find_location(type, get_person(person)); } -size_t Model::get_subpopulation_combined(TimePoint t, InfectionState s) const +size_t Model::get_subpopulation_inf_state_combined(TimePoint t, InfectionState s) const { return std::accumulate(m_locations.begin(), m_locations.end(), (size_t)0, [t, s, this](size_t running_sum, const Location& loc) { - return running_sum + get_subpopulation(loc.get_id(), t, s); + return running_sum + get_subpopulation_inf_state(loc.get_id(), t, s); }); } -size_t Model::get_subpopulation_combined_per_location_type(TimePoint t, InfectionState s, LocationType type) const +size_t Model::get_subpopulation_inf_state_combined_per_location_type(TimePoint t, InfectionState s, + LocationType type) const { return std::accumulate( m_locations.begin(), m_locations.end(), (size_t)0, [t, s, type, this](size_t running_sum, const Location& loc) { - return loc.get_type() == type ? running_sum + get_subpopulation(loc.get_id(), t, s) : running_sum; + return loc.get_type() == type ? running_sum + get_subpopulation_inf_state(loc.get_id(), t, s) : running_sum; }); } diff --git a/cpp/models/abm/model.h b/cpp/models/abm/model.h index 452210da29..d97fb69b54 100644 --- a/cpp/models/abm/model.h +++ b/cpp/models/abm/model.h @@ -259,7 +259,7 @@ class Model * @param[in] t Specified #TimePoint. * @param[in] s Specified #InfectionState. */ - size_t get_subpopulation_combined(TimePoint t, InfectionState s) const; + size_t get_subpopulation_inf_state_combined(TimePoint t, InfectionState s) const; /** * @brief Get the number of Persons in one #InfectionState at all Location%s of a type. @@ -267,7 +267,8 @@ class Model * @param[in] s Specified #InfectionState. * @param[in] type Specified #LocationType. */ - size_t get_subpopulation_combined_per_location_type(TimePoint t, InfectionState s, LocationType type) const; + size_t get_subpopulation_inf_state_combined_per_location_type(TimePoint t, InfectionState s, + LocationType type) const; /** * @brief Get the mobility data. @@ -379,7 +380,7 @@ class Model * @param[in] state #InfectionState of interest. * @return Amount of Person%s of the #InfectionState in all Cell%s of the Location. */ - size_t get_subpopulation(LocationId location, TimePoint t, InfectionState state) const + size_t get_subpopulation_inf_state(LocationId location, TimePoint t, InfectionState state) const { return std::count_if(m_persons.begin(), m_persons.end(), [&](auto&& p) { return p.get_location_model_id() == m_id && p.get_location() == location && @@ -387,6 +388,20 @@ class Model }); } + /** + * @brief Get the number of Person%s of a particular #AgeGrou for all Cell%s. + * @param[in] location A LocationId from the Model. + * @param[in] t TimePoint of querry. + * @param[in] agegroup #AgeGroup of interest. + * @return Amount of Person%s of the #InfectionState in all Cell%s of the Location. + */ + size_t get_subpopulation_age(LocationId location, AgeGroup age) const + { + return std::count_if(m_persons.begin(), m_persons.end(), [&](auto&& p) { + return p.get_location_model_id() == m_id && p.get_location() == location && p.get_age() == age; + }); + } + /** * @brief Get the total number of Person%s at the Location. * @param[in] location A LocationId from the Model. diff --git a/cpp/models/abm/simulation.h b/cpp/models/abm/simulation.h index 2f973cf092..a86945b562 100644 --- a/cpp/models/abm/simulation.h +++ b/cpp/models/abm/simulation.h @@ -97,7 +97,6 @@ class Simulation } private: - void store_result_at(TimePoint t); void evolve_model(TimePoint tmax) { auto dt = std::min(m_dt, tmax - m_t); diff --git a/cpp/tests/test_abm_model.cpp b/cpp/tests/test_abm_model.cpp index dbf398632a..c44040f794 100644 --- a/cpp/tests/test_abm_model.cpp +++ b/cpp/tests/test_abm_model.cpp @@ -124,15 +124,15 @@ TEST_F(TestModel, getSubpopulationCombined) add_test_person(model, home1, age_group_15_to_34, mio::abm::InfectionState::InfectedNoSymptoms); // Verify the count of susceptible persons across all School locations. - EXPECT_EQ(model.get_subpopulation_combined_per_location_type(t, mio::abm::InfectionState::Susceptible, - mio::abm::LocationType::School), + EXPECT_EQ(model.get_subpopulation_inf_state_combined_per_location_type(t, mio::abm::InfectionState::Susceptible, + mio::abm::LocationType::School), 3); // Verify the count of persons with no symptoms across all School locations. - EXPECT_EQ(model.get_subpopulation_combined_per_location_type(t, mio::abm::InfectionState::InfectedNoSymptoms, - mio::abm::LocationType::School), + EXPECT_EQ(model.get_subpopulation_inf_state_combined_per_location_type( + t, mio::abm::InfectionState::InfectedNoSymptoms, mio::abm::LocationType::School), 2); // Verify the total count of persons with no symptoms across all locations. - EXPECT_EQ(model.get_subpopulation_combined(t, mio::abm::InfectionState::InfectedNoSymptoms), 3); + EXPECT_EQ(model.get_subpopulation_inf_state_combined(t, mio::abm::InfectionState::InfectedNoSymptoms), 3); } /**