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
3 changes: 2 additions & 1 deletion examples/external_fields/pgen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ namespace user {
*/

// f_ext: external force-field (acceleration):
Inline auto fx1(const coord_t<D>&) const -> real_t {
Inline auto fx1(const coord_t<D>&, const ntt::ParticleArrays&, prtlidx_t) const
-> real_t {
return (sp % 2u == 0u) ? -HALF : HALF;
}

Expand Down
27 changes: 20 additions & 7 deletions src/global/traits/archetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @implements
* - EnrgDistClass<> - checks if a class can be used as an energy distribution
* - SpatialDistClass<> - checks if a class can be used as a spatial distribution
* - traits::fieldsetter::HasFx1, ::HasFx2, ::HasFx3 - checks for F functions in field setter class
* - traits::fieldsetter::HasFx1, ::HasFx2, ::HasFx3 - checks for particle-aware F functions fx*(x, particles, p)
* - traits::fieldsetter::HasEx1, ::HasEx2, ::HasEx3 - checks for E functions in field setter class
* - traits::fieldsetter::HasBx1, ::HasBx2, ::HasBx3 - checks for B functions in field setter class
* - traits::fieldsetter::HasDx1, ::HasDx2, ::HasDx3 - checks for D functions in field setter class
Expand All @@ -26,6 +26,10 @@

#include <Kokkos_Pair.hpp>

namespace ntt {
struct ParticleArrays;
} // namespace ntt

template <class ED, Dimension D>
concept EnrgDistClass = requires(const ED& edist,
const coord_t<D>& x_Ph,
Expand All @@ -50,18 +54,27 @@ concept SpatialDistClass = SimpleSpatialDistClass<SD, D> or

namespace traits::fieldsetter {
template <class T, Dimension D>
concept HasFx1 = requires(const T& t, const coord_t<D>& x_Ph) {
{ t.fx1(x_Ph) } -> std::convertible_to<real_t>;
concept HasFx1 = requires(const T& t,
const coord_t<D>& x_Ph,
const ntt::ParticleArrays& prtls,
prtlidx_t p) {
{ t.fx1(x_Ph, prtls, p) } -> std::convertible_to<real_t>;
};

template <class T, Dimension D>
concept HasFx2 = requires(const T& t, const coord_t<D>& x_Ph) {
{ t.fx2(x_Ph) } -> std::convertible_to<real_t>;
concept HasFx2 = requires(const T& t,
const coord_t<D>& x_Ph,
const ntt::ParticleArrays& prtls,
prtlidx_t p) {
{ t.fx2(x_Ph, prtls, p) } -> std::convertible_to<real_t>;
};

template <class T, Dimension D>
concept HasFx3 = requires(const T& t, const coord_t<D>& x_Ph) {
{ t.fx3(x_Ph) } -> std::convertible_to<real_t>;
concept HasFx3 = requires(const T& t,
const coord_t<D>& x_Ph,
const ntt::ParticleArrays& prtls,
prtlidx_t p) {
{ t.fx3(x_Ph, prtls, p) } -> std::convertible_to<real_t>;
};

template <class T, Dimension D>
Expand Down
9 changes: 5 additions & 4 deletions src/kernels/pushers/sr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ namespace kernel::sr {

// compute the external force either user-provided or from the atmosphere model
if constexpr (HasExtForce or Atm) {
getExternalForce(xp_Cd, xp_Ph, external_force_Cart);
getExternalForce(xp_Cd, xp_Ph, p, external_force_Cart);
}

if (ctx.pusher_flags & ParticlePusher::GCA) {
Expand Down Expand Up @@ -1425,18 +1425,19 @@ namespace kernel::sr {

Inline void getExternalForce(const coord_t<M::PrtlDim>& xp_Cd,
const coord_t<M::PrtlDim>& xp_Ph,
[[maybe_unused]] prtlidx_t p,
vec_t<Dim::_3D>& external_force_Cart) const
requires(Atm or HasExtForce)
{
real_t f_x1 = ZERO, f_x2 = ZERO, f_x3 = ZERO;
if constexpr (HasExtFx1) {
f_x1 = policies.external_fields_policy.fx1(xp_Ph);
f_x1 = policies.external_fields_policy.fx1(xp_Ph, particles, p);
}
if constexpr (HasExtFx2) {
f_x2 = policies.external_fields_policy.fx2(xp_Ph);
f_x2 = policies.external_fields_policy.fx2(xp_Ph, particles, p);
}
if constexpr (HasExtFx3) {
f_x3 = policies.external_fields_policy.fx3(xp_Ph);
f_x3 = policies.external_fields_policy.fx3(xp_Ph, particles, p);
}
if constexpr (Atm) {
if constexpr (D == Dim::_1D or D == Dim::_2D or D == Dim::_3D) {
Expand Down
3 changes: 2 additions & 1 deletion tests/archetypes/pgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ struct CustomFieldsetter {

template <Dimension D>
struct ExtForce {
Inline auto fx1(const coord_t<D>&) const -> real_t {
Inline auto fx1(const coord_t<D>&, const ntt::ParticleArrays&, prtlidx_t) const
-> real_t {
return ZERO;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/global/traits_archetypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ struct WithDx1Dx2Dx3 {
};

struct WithFx1Fx2Fx3 {
real_t fx1(const coord_t<Dimension::_2D>&) const {
real_t fx1(const coord_t<Dimension::_2D>&, const ntt::ParticleArrays&, prtlidx_t) const {
return ZERO;
}

real_t fx2(const coord_t<Dimension::_2D>&) const {
real_t fx2(const coord_t<Dimension::_2D>&, const ntt::ParticleArrays&, prtlidx_t) const {
return ZERO;
}

real_t fx3(const coord_t<Dimension::_2D>&) const {
real_t fx3(const coord_t<Dimension::_2D>&, const ntt::ParticleArrays&, prtlidx_t) const {
return ZERO;
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/global/traits_policies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static_assert(not EmissionPolicyClass<NoPayload_EmissionPolicy, MockMetric>);
// --- ExtFieldsPolicyClass ---

struct WithFx1 {
real_t fx1(const coord_t<Dimension::_2D>&) const {
real_t fx1(const coord_t<Dimension::_2D>&, const ntt::ParticleArrays&, prtlidx_t) const {
return ZERO;
}
};
Expand Down
9 changes: 6 additions & 3 deletions tests/kernels/ext_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ void put_value(array_t<T*>& arr, T v, prtlidx_t p) {
struct Force {
Force(real_t force) : force { force } {}

Inline auto fx1(const coord_t<Dim::_3D>&) const -> real_t {
Inline auto fx1(const coord_t<Dim::_3D>&, const ntt::ParticleArrays&, prtlidx_t) const
-> real_t {
return force * math::sin(ONE) * math::sin(ONE);
}

Inline auto fx2(const coord_t<Dim::_3D>&) const -> real_t {
Inline auto fx2(const coord_t<Dim::_3D>&, const ntt::ParticleArrays&, prtlidx_t) const
-> real_t {
return force * math::sin(ONE) * math::cos(ONE);
}

Inline auto fx3(const coord_t<Dim::_3D>&) const -> real_t {
Inline auto fx3(const coord_t<Dim::_3D>&, const ntt::ParticleArrays&, prtlidx_t) const
-> real_t {
return force * math::cos(ONE);
}

Expand Down
Loading