Skip to content
Closed
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
21 changes: 16 additions & 5 deletions src/metrics/kerr_schild.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace metric {

const real_t dr, dtheta, dphi;
const real_t dr_inv, dtheta_inv, dphi_inv;
const bool small_angle;

Inline auto Delta(real_t r) const -> real_t {
return SQR(r) - TWO * r + SQR(a);
Expand Down Expand Up @@ -85,7 +86,8 @@ namespace metric {
, dphi { (x3_max - x3_min) / nx3 }
, dr_inv { ONE / dr }
, dtheta_inv { ONE / dtheta }
, dphi_inv { ONE / dphi } {
, dphi_inv { ONE / dphi }
, small_angle { HALF * dtheta < constant::SMALL_ANGLE } {
set_dxMin(find_dxMin());
}

Expand Down Expand Up @@ -443,12 +445,21 @@ namespace metric {
/**
* differential area at the pole (used in axisymmetric solvers)
* @param x1 radial coordinate along the axis (code units)
* @note uses small-angle approximation when the resolution is too high
*/
Inline auto polar_area(real_t x1) const -> real_t {
return dr * (SQR(x1 * dr + x1_min) + SQR(a)) *
math::sqrt(ONE + TWO * (x1 * dr + x1_min) /
(SQR(x1 * dr + x1_min) + SQR(a))) *
(ONE - math::cos(HALF * dtheta));
if (small_angle) {
return dr * (SQR(x1 * dr + x1_min) + SQR(a)) *
math::sqrt(ONE + TWO * (x1 * dr + x1_min) /
(SQR(x1 * dr + x1_min) + SQR(a))) *
(static_cast<real_t>(48) - SQR(dtheta)) * SQR(dtheta) /
static_cast<real_t>(384);
} else {
return dr * (SQR(x1 * dr + x1_min) + SQR(a)) *
math::sqrt(ONE + TWO * (x1 * dr + x1_min) /
(SQR(x1 * dr + x1_min) + SQR(a))) *
(ONE - math::cos(HALF * dtheta));
}
}

/**
Expand Down
28 changes: 21 additions & 7 deletions src/metrics/qkerr_schild.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace metric {
const real_t chi_min, eta_min, phi_min;
const real_t dchi, deta, dphi;
const real_t dchi_inv, deta_inv, dphi_inv;
const bool small_angle;

Inline auto Delta(real_t r) const -> real_t {
return SQR(r) - TWO * r + SQR(a);
Expand Down Expand Up @@ -89,7 +90,8 @@ namespace metric {
, dphi { (x3_max - phi_min) / nx3 }
, dchi_inv { ONE / dchi }
, deta_inv { ONE / deta }
, dphi_inv { ONE / dphi } {
, dphi_inv { ONE / dphi }
, small_angle { eta2theta(HALF * deta) < constant::SMALL_ANGLE } {
set_dxMin(find_dxMin());
}

Expand Down Expand Up @@ -503,15 +505,27 @@ namespace metric {
* differential area at the pole (used in axisymmetric solvers)
* @note approximate solution for the polar area
* @param x1 radial coordinate along the axis (code units)
* @note uses small-angle approximation when the resolution is too high
*/
Inline auto polar_area(real_t x1) const -> real_t {
if constexpr (D != Dim::_1D) {
return dchi * math::exp(x1 * dchi + chi_min) *
(SQR(r0 + math::exp(x1 * dchi + chi_min)) + SQR(a)) *
math::sqrt(
ONE + TWO * (r0 + math::exp(x1 * dchi + chi_min)) /
(SQR(r0 + math::exp(x1 * dchi + chi_min)) + SQR(a))) *
(ONE - math::cos(eta2theta(HALF * deta)));
if (small_angle) {
const real_t dtheta = eta2theta(HALF * deta);
return dchi * math::exp(x1 * dchi + chi_min) *
(SQR(r0 + math::exp(x1 * dchi + chi_min)) + SQR(a)) *
math::sqrt(
ONE + TWO * (r0 + math::exp(x1 * dchi + chi_min)) /
(SQR(r0 + math::exp(x1 * dchi + chi_min)) + SQR(a))) *
(static_cast<real_t>(48) - SQR(dtheta)) * SQR(dtheta) /
static_cast<real_t>(384);
} else {
return dchi * math::exp(x1 * dchi + chi_min) *
(SQR(r0 + math::exp(x1 * dchi + chi_min)) + SQR(a)) *
math::sqrt(
ONE + TWO * (r0 + math::exp(x1 * dchi + chi_min)) /
(SQR(r0 + math::exp(x1 * dchi + chi_min)) + SQR(a))) *
(ONE - math::cos(eta2theta(HALF * deta)));
}
}
}

Expand Down