Skip to content

Commit

Permalink
Accumulate dispersers from multiple hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzeslaus committed Nov 6, 2023
1 parent bf8c4c4 commit f3581d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
6 changes: 3 additions & 3 deletions include/pops/actions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class SpreadAction
for (auto indices : host_pool.suitable_cells()) {
int i = indices[0];
int j = indices[1];
if (host_pool.infected_at(i, j) > 0) {
int dispersers_from_cell =
host_pool.dispersers_from(i, j, generator.disperser_generation());
int dispersers_from_cell =
host_pool.dispersers_from(i, j, generator.disperser_generation());
if (dispersers_from_cell > 0) {
if (soil_pool_) {
// From all the generated dispersers, some go to the soil in the
// same cell and don't participate in the kernel-driven dispersal.
Expand Down
20 changes: 2 additions & 18 deletions include/pops/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,6 @@ class Model
if (config_.spread_schedule()[step]) {
auto dispersal_kernel = kernel_factory_(config_, dispersers, network);

SpreadAction<
StandardSingleHostPool,
StandardPestPool,
IntegerRaster,
FloatRaster,
RasterIndex,
decltype(dispersal_kernel),
RandomNumberGeneratorProvider<Generator>>
spread_action{dispersal_kernel};

SpreadAction<
StandardMultiHostPool,
StandardPestPool,
Expand All @@ -306,7 +296,7 @@ class Model
RasterIndex,
decltype(dispersal_kernel),
RandomNumberGeneratorProvider<Generator>>
multi_spread_action{dispersal_kernel};
spread_action{dispersal_kernel};

environment_.set_total_population(&total_populations);
// Soils are activated by an independent function call for model, but spread
Expand All @@ -315,13 +305,7 @@ class Model
spread_action.activate_soils(
soil_pool_, config_.dispersers_to_soils_percentage);
}
if (this->soil_pool_) {
multi_spread_action.activate_soils(
soil_pool_, config_.dispersers_to_soils_percentage);
}
spread_action.generate(host_pool, pest_pool, generator_provider_);
multi_spread_action.disperse(
multi_host_pool, pest_pool, generator_provider_);
spread_action.action(multi_host_pool, pest_pool, generator_provider_);
host_pool.step_forward(step);
}
if (config_.use_mortality && config_.mortality_schedule()[step]) {
Expand Down
9 changes: 9 additions & 0 deletions include/pops/multi_host_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ class MultiHostPool
return hosts.at(distribution(generator));
}

int dispersers_from(RasterIndex row, RasterIndex col, Generator& generator) const
{
int sum{0};
for (auto& host_pool : host_pools_) {
sum += host_pool->dispersers_from(row, col, generator);
}
return sum;
}

template<typename Generator>
int disperser_to(RasterIndex row, RasterIndex col, Generator& generator)
{
Expand Down

0 comments on commit f3581d5

Please sign in to comment.