Skip to content
Open
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
22 changes: 17 additions & 5 deletions src/engines/srpic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ namespace ntt {
: ZERO;
// cooling
const auto has_synchrotron = (cooling == Cooling::SYNCHROTRON);
const auto has_compton = (cooling == Cooling::COMPTON);
const auto sync_grad = has_synchrotron
? m_params.template get<real_t>(
"algorithms.synchrotron.gamma_rad")
Expand All @@ -328,7 +329,15 @@ namespace ntt {
"scales.omegaB0") /
(SQR(sync_grad) * species.mass())
: ZERO;

const auto comp_grad = has_compton
? m_params.template get<real_t>(
"algorithms.compton.gamma_rad")
: ZERO;
const auto comp_coeff = has_compton
? (real_t)(0.1) * dt *
m_params.template get<real_t>(
"scales.omegaB0") / (SQR(comp_grad) * species.mass())
: ZERO;
// toggle to indicate whether pgen defines the external force
bool has_extforce = false;
if constexpr (traits::has_member<traits::pgen::ext_force_t, pgen_t>::value) {
Expand All @@ -346,6 +355,9 @@ namespace ntt {
if (cooling == Cooling::SYNCHROTRON) {
cooling_tags = kernel::sr::Cooling::Synchrotron;
}
if (cooling == Cooling::COMPTON) {
cooling_tags = kernel::sr::Cooling::Compton;
}
// clang-format off
if (not has_atmosphere and not has_extforce) {
Kokkos::parallel_for(
Expand All @@ -368,7 +380,7 @@ namespace ntt {
domain.mesh.n_active(in::x2),
domain.mesh.n_active(in::x3),
domain.mesh.prtl_bc(),
gca_larmor_max, gca_eovrb_max, sync_coeff
gca_larmor_max, gca_eovrb_max, sync_coeff, comp_coeff
));
} else if (has_atmosphere and not has_extforce) {
const auto force =
Expand Down Expand Up @@ -398,7 +410,7 @@ namespace ntt {
domain.mesh.n_active(in::x2),
domain.mesh.n_active(in::x3),
domain.mesh.prtl_bc(),
gca_larmor_max, gca_eovrb_max, sync_coeff
gca_larmor_max, gca_eovrb_max, sync_coeff, comp_coeff
));
} else if (not has_atmosphere and has_extforce) {
if constexpr (traits::has_member<traits::pgen::ext_force_t, pgen_t>::value) {
Expand Down Expand Up @@ -427,7 +439,7 @@ namespace ntt {
domain.mesh.n_active(in::x2),
domain.mesh.n_active(in::x3),
domain.mesh.prtl_bc(),
gca_larmor_max, gca_eovrb_max, sync_coeff
gca_larmor_max, gca_eovrb_max, sync_coeff, comp_coeff
));
} else {
raise::Error("External force not implemented", HERE);
Expand Down Expand Up @@ -459,7 +471,7 @@ namespace ntt {
domain.mesh.n_active(in::x2),
domain.mesh.n_active(in::x3),
domain.mesh.prtl_bc(),
gca_larmor_max, gca_eovrb_max, sync_coeff
gca_larmor_max, gca_eovrb_max, sync_coeff, comp_coeff
));
} else {
raise::Error("External force not implemented", HERE);
Expand Down
15 changes: 15 additions & 0 deletions src/framework/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ namespace ntt {
promiseToDefine("algorithms.synchrotron.gamma_rad");
}

if (cooling_enum == Cooling::COMPTON) {
raise::ErrorIf(engine_enum != SimEngine::SRPIC,
"Inverse Compton cooling is only supported for SRPIC",
HERE);
promiseToDefine("algorithms.compton.gamma_rad");
}

species.emplace_back(ParticleSpecies(idx,
label,
mass,
Expand Down Expand Up @@ -916,6 +923,14 @@ namespace ntt {
"gamma_rad",
defaults::synchrotron::gamma_rad));
}
if (isPromised("algorithms.compton.gamma_rad")) {
set("algorithms.compton.gamma_rad",
toml::find_or(toml_data,
"algorithms",
"compton",
"gamma_rad",
defaults::compton::gamma_rad));
}

// @TODO: disabling stats for non-Cartesian
if (coord_enum != Coord::Cart) {
Expand Down
5 changes: 4 additions & 1 deletion src/global/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ namespace ntt::defaults {
namespace synchrotron {
const real_t gamma_rad = 1.0;
} // namespace synchrotron


namespace compton{
const real_t gamma_rad = 1.0;
}
} // namespace ntt::defaults

#endif // GLOBAL_DEFAULTS_H
9 changes: 5 additions & 4 deletions src/global/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* - enum ntt::FldsBC // periodic, match, fixed, atmosphere,
* custom, horizon, axis, conductor, sync
* - enum ntt::PrtlPusher // boris, vay, photon, none
* - enum ntt::Cooling // synchrotron, none
* - enum ntt::Cooling // compton, synchrotron, none
* - enum ntt::FldsID // e, dive, d, divd, b, h, j,
* a, t, rho, charge, n, nppc, v, custom
* - enum ntt::StatsID // b^2, e^2, exb, j.e, t, rho,
Expand Down Expand Up @@ -265,13 +265,14 @@ namespace ntt {
enum type : uint8_t {
INVALID = 0,
SYNCHROTRON = 1,
NONE = 2,
COMPTON = 2,
NONE = 3,
};

constexpr Cooling(uint8_t c) : enums_hidden::BaseEnum<Cooling> { c } {}

static constexpr type variants[] = { SYNCHROTRON, NONE };
static constexpr const char* lookup[] = { "synchrotron", "none" };
static constexpr type variants[] = { SYNCHROTRON, COMPTON, NONE };
static constexpr const char* lookup[] = { "synchrotron", "compton", "none" };
static constexpr std::size_t total = sizeof(variants) / sizeof(variants[0]);
};

Expand Down
41 changes: 35 additions & 6 deletions src/kernels/particle_pusher_sr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace kernel::sr {
enum CoolingTags_ {
None = 0,
Synchrotron = 1 << 0,
Compton = 1 << 1,
};
} // namespace Cooling

Expand Down Expand Up @@ -225,8 +226,8 @@ namespace kernel::sr {
bool is_axis_i2min { false }, is_axis_i2max { false };
// gca parameters
const real_t gca_larmor, gca_EovrB_sqr;
// synchrotron cooling parameters
const real_t coeff_sync;
// radiative cooling parameters
const real_t coeff_sync, coeff_comp;

public:
Pusher_kernel(const PrtlPusher::type& pusher,
Expand Down Expand Up @@ -263,7 +264,8 @@ namespace kernel::sr {
const boundaries_t<PrtlBC>& boundaries,
real_t gca_larmor_max,
real_t gca_eovrb_max,
real_t coeff_sync)
real_t coeff_sync,
real_t coeff_comp)
: pusher { pusher }
, GCA { GCA }
, ext_force { ext_force }
Expand Down Expand Up @@ -297,7 +299,8 @@ namespace kernel::sr {
, ni3 { ni3 }
, gca_larmor { gca_larmor_max }
, gca_EovrB_sqr { SQR(gca_eovrb_max) }
, coeff_sync { coeff_sync } {
, coeff_sync { coeff_sync }
, coeff_comp { coeff_comp } {
raise::ErrorIf(boundaries.size() < 1, "boundaries defined incorrectly", HERE);
is_absorb_i1min = (boundaries[0].first == PrtlBC::ATMOSPHERE) ||
(boundaries[0].first == PrtlBC::ABSORB);
Expand Down Expand Up @@ -366,7 +369,8 @@ namespace kernel::sr {
const boundaries_t<PrtlBC>& boundaries,
real_t gca_larmor_max,
real_t gca_eovrb_max,
real_t coeff_sync)
real_t coeff_sync,
real_t coeff_comp)
: Pusher_kernel(pusher,
GCA,
ext_force,
Expand Down Expand Up @@ -401,7 +405,8 @@ namespace kernel::sr {
boundaries,
gca_larmor_max,
gca_eovrb_max,
coeff_sync) {}
coeff_sync,
coeff_comp) {}

Inline void synchrotronDrag(index_t& p,
vec_t<Dim::_3D>& u_prime,
Expand Down Expand Up @@ -454,6 +459,22 @@ namespace kernel::sr {
ux3(p) += coeff_sync * (kappaR[2] - gamma_prime_sqr * u_prime[2] * chiR_sqr);
}

Inline void inverseComptonDrag(index_t& p,
vec_t<Dim::_3D>& u_prime
) const {
real_t gamma_prime_sqr = ONE / math::sqrt(ONE + NORM_SQR(u_prime[0],
u_prime[1],
u_prime[2]));
u_prime[0] *= gamma_prime_sqr;
u_prime[1] *= gamma_prime_sqr;
u_prime[2] *= gamma_prime_sqr;
gamma_prime_sqr = SQR(ONE / gamma_prime_sqr);

ux1(p) -= coeff_comp * gamma_prime_sqr * u_prime[0];
ux2(p) -= coeff_comp * gamma_prime_sqr * u_prime[1];
ux3(p) -= coeff_comp * gamma_prime_sqr * u_prime[2];
}

Inline void operator()(index_t p) const {
if (tag(p) != ParticleTag::alive) {
if (tag(p) != ParticleTag::dead) {
Expand Down Expand Up @@ -558,6 +579,14 @@ namespace kernel::sr {
synchrotronDrag(p, u_prime, ei_Cart_rad, bi_Cart_rad);
}
}
if (cooling & Cooling::Compton) {
if (!is_gca) {
u_prime[0] = HALF * (u_prime[0] + ux1(p));
u_prime[1] = HALF * (u_prime[1] + ux2(p));
u_prime[2] = HALF * (u_prime[2] + ux3(p));
inverseComptonDrag(p, u_prime);
}
}
// update position
posUpd(true, p, xp_Cd);
}
Expand Down