diff --git a/src/archetypes/spatial_dist.h b/src/archetypes/spatial_dist.h index 68477208..c8f3c8a3 100644 --- a/src/archetypes/spatial_dist.h +++ b/src/archetypes/spatial_dist.h @@ -41,8 +41,11 @@ namespace arch { struct Uniform : public SpatialDistribution { Uniform(const M& metric) : SpatialDistribution { metric } {} - Inline auto operator()(const coord_t&) const -> real_t { - return ONE; + Inline auto operator()(const coord_t&, + real_t& nppc_distribution, + real_t& weight_distribution) const { + nppc_distribution = ONE; + weight_distribution = ONE; } }; @@ -66,7 +69,9 @@ namespace arch { , target_density { target_density } , target_max_density { target_max_density } {} - Inline auto operator()(const coord_t& x_Ph) const -> real_t { + Inline auto operator()(const coord_t& x_Ph, + real_t& nppc_distribution, + real_t& weight_distribution) const { coord_t x_Cd { ZERO }; metric.template convert(x_Ph, x_Cd); real_t dens { ZERO }; @@ -86,9 +91,11 @@ namespace arch { } const auto target = target_density(x_Ph); if (0.9 * target > dens) { - return (target - dens) / target_max_density; + nppc_distribution = (target - dens) / target_max_density; + weight_distribution = ONE; } else { - return ZERO; + nppc_distribution = ZERO; + weight_distribution = ONE; } } }; @@ -110,7 +117,9 @@ namespace arch { , idx { idx } , target_density { target_density } {} - Inline auto operator()(const coord_t& x_Ph) const -> real_t { + Inline auto operator()(const coord_t& x_Ph, + real_t& nppc_distribution, + real_t& weight_distribution) const { coord_t x_Cd { ZERO }; metric.template convert(x_Ph, x_Cd); real_t dens { ZERO }; @@ -129,9 +138,11 @@ namespace arch { raise::KernelError(HERE, "Invalid dimension"); } if (0.9 * target_density > dens) { - return (target_density - dens) / target_density; + nppc_distribution = (target_density - dens) / target_density; + weight_distribution = ONE; } else { - return ZERO; + nppc_distribution = ZERO; + weight_distribution = ONE; } } }; diff --git a/src/engines/grpic.hpp b/src/engines/grpic.hpp index 35e544a9..4d9d89d9 100644 --- a/src/engines/grpic.hpp +++ b/src/engines/grpic.hpp @@ -94,9 +94,9 @@ namespace ntt { void step_forward(timer::Timers& timers, domain_t& dom) override { const auto fieldsolver_enabled = m_params.template get( - "algorithms.toggles.fieldsolver"); + "algorithms.fieldsolver.enable"); const auto deposit_enabled = m_params.template get( - "algorithms.toggles.deposit"); + "algorithms.deposit.enable"); const auto clear_interval = m_params.template get( "particles.clear_interval"); diff --git a/src/kernels/injectors.hpp b/src/kernels/injectors.hpp index cddb1883..c51f811f 100644 --- a/src/kernels/injectors.hpp +++ b/src/kernels/injectors.hpp @@ -615,8 +615,11 @@ namespace kernel { return idx_h(); } - Inline auto injected_ppc(const coord_t& x_Ph) const -> npart_t { - const auto ppc_real = ppc0 * spatial_dist(x_Ph); + Inline auto injected_ppc(const coord_t& x_Ph, + real_t& ppc_dist, + real_t& weight_dist) const -> npart_t { + spatial_dist(x_Ph, ppc_dist, weight_dist); + const auto ppc_real = ppc0 * ppc_dist; auto ppc = static_cast(ppc_real); auto rand_gen = random_pool.get_state(); if (Random(rand_gen) < (ppc_real - static_cast(ppc))) { @@ -682,15 +685,15 @@ namespace kernel { coord_t x_Cd { i1_ + HALF }; coord_t x_Ph { ZERO }; metric.template convert(x_Cd, x_Ph); - - const auto ppc = injected_ppc(x_Ph); + auto ppc_dist { ZERO }, weight_dist { ONE }; + const auto ppc = injected_ppc(x_Ph, ppc_dist, weight_dist); if (ppc == 0) { return; } - auto weight = ONE; + auto weight = ONE * weight_dist; if constexpr (M::CoordType != Coord::Cart) { - weight = metric.sqrt_det_h({ i1_ + HALF }) * inv_V0; + weight = metric.sqrt_det_h({ i1_ + HALF }) * inv_V0 * weight_dist; } for (auto p { 0u }; p < ppc; ++p) { const auto index = Kokkos::atomic_fetch_add(&idx(), 1); @@ -732,15 +735,16 @@ namespace kernel { x_Cd_[2] = ZERO; } metric.template convert(x_Cd, x_Ph); - - const auto ppc = injected_ppc(x_Ph); + + auto ppc_dist { ZERO }, weight_dist { ONE }; + const auto ppc = injected_ppc(x_Ph, ppc_dist, weight_dist); if (ppc == 0) { return; } - auto weight = ONE; + auto weight = ONE * weight_dist; if constexpr (M::CoordType != Coord::Cart) { - weight = metric.sqrt_det_h({ i1_ + HALF, i2_ + HALF }) * inv_V0; + weight = metric.sqrt_det_h({ i1_ + HALF, i2_ + HALF }) * inv_V0 * weight_dist; } for (auto p { 0u }; p < ppc; ++p) { const auto index = Kokkos::atomic_fetch_add(&idx(), 1); @@ -796,16 +800,16 @@ namespace kernel { coord_t x_Cd { i1_ + HALF, i2_ + HALF, i3_ + HALF }; coord_t x_Ph { ZERO }; metric.template convert(x_Cd, x_Ph); - - const auto ppc = injected_ppc(x_Ph); + auto ppc_dist { ZERO }, weight_dist { ONE }; + const auto ppc = injected_ppc(x_Ph, ppc_dist, weight_dist); if (ppc == 0) { return; } - auto weight = ONE; + auto weight = ONE * weight_dist; if constexpr (M::CoordType != Coord::Cart) { weight = metric.sqrt_det_h({ i1_ + HALF, i2_ + HALF, i3_ + HALF }) * - inv_V0; + inv_V0 * weight_dist; } for (auto p { 0u }; p < ppc; ++p) { const auto index = Kokkos::atomic_fetch_add(&idx(), 1);