Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/archetypes/spatial_dist.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ namespace arch {
struct Uniform : public SpatialDistribution<S, M> {
Uniform(const M& metric) : SpatialDistribution<S, M> { metric } {}

Inline auto operator()(const coord_t<M::Dim>&) const -> real_t {
return ONE;
Inline auto operator()(const coord_t<M::Dim>&,
real_t& nppc_distribution,
real_t& weight_distribution) const {
nppc_distribution = ONE;
weight_distribution = ONE;
}
};

Expand All @@ -66,7 +69,9 @@ namespace arch {
, target_density { target_density }
, target_max_density { target_max_density } {}

Inline auto operator()(const coord_t<M::Dim>& x_Ph) const -> real_t {
Inline auto operator()(const coord_t<M::Dim>& x_Ph,
real_t& nppc_distribution,
real_t& weight_distribution) const {
coord_t<M::Dim> x_Cd { ZERO };
metric.template convert<Crd::Ph, Crd::Cd>(x_Ph, x_Cd);
real_t dens { ZERO };
Expand All @@ -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;
}
}
};
Expand All @@ -110,7 +117,9 @@ namespace arch {
, idx { idx }
, target_density { target_density } {}

Inline auto operator()(const coord_t<M::Dim>& x_Ph) const -> real_t {
Inline auto operator()(const coord_t<M::Dim>& x_Ph,
real_t& nppc_distribution,
real_t& weight_distribution) const {
coord_t<M::Dim> x_Cd { ZERO };
metric.template convert<Crd::Ph, Crd::Cd>(x_Ph, x_Cd);
real_t dens { ZERO };
Expand All @@ -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;
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/engines/grpic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ namespace ntt {

void step_forward(timer::Timers& timers, domain_t& dom) override {
const auto fieldsolver_enabled = m_params.template get<bool>(
"algorithms.toggles.fieldsolver");
"algorithms.fieldsolver.enable");
const auto deposit_enabled = m_params.template get<bool>(
"algorithms.toggles.deposit");
"algorithms.deposit.enable");
const auto clear_interval = m_params.template get<std::size_t>(
"particles.clear_interval");

Expand Down
32 changes: 18 additions & 14 deletions src/kernels/injectors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,11 @@ namespace kernel {
return idx_h();
}

Inline auto injected_ppc(const coord_t<M::Dim>& x_Ph) const -> npart_t {
const auto ppc_real = ppc0 * spatial_dist(x_Ph);
Inline auto injected_ppc(const coord_t<M::Dim>& 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<npart_t>(ppc_real);
auto rand_gen = random_pool.get_state();
if (Random<real_t>(rand_gen) < (ppc_real - static_cast<real_t>(ppc))) {
Expand Down Expand Up @@ -682,15 +685,15 @@ namespace kernel {
coord_t<Dim::_1D> x_Cd { i1_ + HALF };
coord_t<Dim::_1D> x_Ph { ZERO };
metric.template convert<Crd::Cd, Crd::Ph>(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);
Expand Down Expand Up @@ -732,15 +735,16 @@ namespace kernel {
x_Cd_[2] = ZERO;
}
metric.template convert<Crd::Cd, Crd::Ph>(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);
Expand Down Expand Up @@ -796,16 +800,16 @@ namespace kernel {
coord_t<Dim::_3D> x_Cd { i1_ + HALF, i2_ + HALF, i3_ + HALF };
coord_t<Dim::_3D> x_Ph { ZERO };
metric.template convert<Crd::Cd, Crd::Ph>(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);
Expand Down