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: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [ ] optional weights in communications
- [ ] make weight buffers for computing moments optional
- [ ] make writing (outputting) of weights optional
2 changes: 1 addition & 1 deletion input.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
ppc0 = ""
# Toggle for using particle weights
# @type: bool
# @default: false
# @default: false [Cartesian]; true [otherwise]
use_weights = ""
# Timesteps between particle re-sorting (removing dead particles)
# @type: uint
Expand Down
12 changes: 9 additions & 3 deletions src/framework/containers/particles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ namespace ntt {
float ch,
npart_t maxnpart,
const PrtlPusher& pusher,
bool use_weights,
bool use_gca,
const Cooling& cooling,
unsigned short npld)
: ParticleSpecies(index, label, m, ch, maxnpart, pusher, use_gca, cooling, npld) {
: ParticleSpecies(index, label, m, ch, maxnpart, pusher, use_weights, use_gca, cooling, npld) {

if constexpr (D == Dim::_1D or D == Dim::_2D or D == Dim::_3D) {
i1 = array_t<int*> { label + "_i1", maxnpart };
Expand All @@ -52,7 +53,9 @@ namespace ntt {
ux2 = array_t<real_t*> { label + "_ux2", maxnpart };
ux3 = array_t<real_t*> { label + "_ux3", maxnpart };

weight = array_t<real_t*> { label + "_w", maxnpart };
if (this->use_weights()) {
weight = array_t<real_t*> { label + "_w", maxnpart };
}

tag = array_t<short*> { label + "_tag", maxnpart };

Expand Down Expand Up @@ -200,7 +203,10 @@ namespace ntt {
RemoveDeadInArray(ux1, indices_alive);
RemoveDeadInArray(ux2, indices_alive);
RemoveDeadInArray(ux3, indices_alive);
RemoveDeadInArray(weight, indices_alive);

if (this->use_weights()) {
RemoveDeadInArray(weight, indices_alive);
}

if constexpr (D == Dim::_2D && C != Coord::Cart) {
RemoveDeadInArray(phi, indices_alive);
Expand Down
3 changes: 3 additions & 0 deletions src/framework/containers/particles.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace ntt {
* @param ch The charge of the species
* @param maxnpart The maximum number of allocated particles for the species
* @param pusher The pusher assigned for the species
* @param use_weights Use weights for the species
* @param use_gca Use hybrid GCA pusher for the species
* @param cooling The cooling mechanism assigned for the species
* @param npld The number of payloads for the species
Expand All @@ -86,6 +87,7 @@ namespace ntt {
float ch,
npart_t maxnpart,
const PrtlPusher& pusher,
bool use_weights,
bool use_gca,
const Cooling& cooling,
unsigned short npld = 0);
Expand All @@ -102,6 +104,7 @@ namespace ntt {
spec.charge(),
spec.maxnpart(),
spec.pusher(),
spec.use_weights(),
spec.use_gca(),
spec.cooling(),
spec.npld()) {}
Expand Down
10 changes: 10 additions & 0 deletions src/framework/containers/species.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace ntt {
// Pusher assigned for the species
const PrtlPusher m_pusher;

// Use particle weights
const bool m_use_weights;
// Use byrid gca pusher for the species
const bool m_use_gca;

Expand All @@ -50,6 +52,7 @@ namespace ntt {
, m_charge { 0.0 }
, m_maxnpart { 0 }
, m_pusher { PrtlPusher::INVALID }
, m_use_weights { false }
, m_use_gca { false }
, m_cooling { Cooling::INVALID }
, m_npld { 0 } {}
Expand All @@ -70,6 +73,7 @@ namespace ntt {
float ch,
npart_t maxnpart,
const PrtlPusher& pusher,
bool use_weights,
bool use_gca,
const Cooling& cooling,
unsigned short npld = 0)
Expand All @@ -79,6 +83,7 @@ namespace ntt {
, m_charge { ch }
, m_maxnpart { maxnpart }
, m_pusher { pusher }
, m_use_weights { use_weights }
, m_use_gca { use_gca }
, m_cooling { cooling }
, m_npld { npld } {}
Expand Down Expand Up @@ -120,6 +125,11 @@ namespace ntt {
return m_pusher;
}

[[nodiscard]]
auto use_weights() const -> bool {
return m_use_weights;
}

[[nodiscard]]
auto use_gca() const -> bool {
return m_use_gca;
Expand Down
8 changes: 6 additions & 2 deletions src/framework/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ namespace ntt {
const auto ppc0 = toml::find<real_t>(toml_data, "particles", "ppc0");
set("particles.ppc0", ppc0);
raise::ErrorIf(ppc0 <= 0.0, "ppc0 must be positive", HERE);
set("particles.use_weights",
toml::find_or(toml_data, "particles", "use_weights", false));
const auto use_weights = toml::find_or(toml_data,
"particles",
"use_weights",
coord_enum != Coord::Cart);
set("particles.use_weights", use_weights);

/* [particles.species] -------------------------------------------------- */
std::vector<ParticleSpecies> species;
Expand Down Expand Up @@ -241,6 +244,7 @@ namespace ntt {
charge,
maxnpart,
pusher_enum,
use_weights,
use_gca,
cooling_enum,
npayloads));
Expand Down
7 changes: 5 additions & 2 deletions src/kernels/currents_deposit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ namespace kernel {
const M metric;
const real_t charge, inv_dt;

const bool use_weights;

public:
/**
* @brief explicit constructor.
Expand Down Expand Up @@ -90,7 +92,8 @@ namespace kernel {
, tag { tag }
, metric { metric }
, charge { charge }
, inv_dt { ONE / dt } {}
, inv_dt { ONE / dt }
, use_weights { weight.extent(0) > 0 } {}

/**
* @brief Iteration of the loop over particles.
Expand Down Expand Up @@ -155,7 +158,7 @@ namespace kernel {
vp[2] *= inv_energy;
}

const real_t coeff { weight(p) * charge };
const real_t coeff { (use_weights ? weight(p) : ONE) * charge };

const auto dxp_r_1 { static_cast<prtldx_t>(i1(p) == i1_prev(p)) *
(dx1(p) + dx1_prev(p)) * static_cast<prtldx_t>(INV_2) };
Expand Down
Loading