diff --git a/include/pops/actions.hpp b/include/pops/actions.hpp index 33d0603c..7aa25360 100644 --- a/include/pops/actions.hpp +++ b/include/pops/actions.hpp @@ -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. diff --git a/include/pops/model.hpp b/include/pops/model.hpp index 3aecdaa6..763b2a36 100644 --- a/include/pops/model.hpp +++ b/include/pops/model.hpp @@ -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> - spread_action{dispersal_kernel}; - SpreadAction< StandardMultiHostPool, StandardPestPool, @@ -306,7 +296,7 @@ class Model RasterIndex, decltype(dispersal_kernel), RandomNumberGeneratorProvider> - 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 @@ -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]) { diff --git a/include/pops/multi_host_pool.hpp b/include/pops/multi_host_pool.hpp index 468dd8c7..e4c702ff 100644 --- a/include/pops/multi_host_pool.hpp +++ b/include/pops/multi_host_pool.hpp @@ -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 int disperser_to(RasterIndex row, RasterIndex col, Generator& generator) {