Skip to content

Commit 37d09ba

Browse files
committed
Add spin to particle container.
1 parent 88a4652 commit 37d09ba

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/particles/ImpactXParticleContainer.H

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ namespace impactx
5151
px, ///< momentum in x, scaled by the magnitude of the reference momentum [unitless] (at fixed s or t)
5252
py, ///< momentum in y, scaled by the magnitude of the reference momentum [unitless] (at fixed s or t)
5353
pt, ///< energy deviation, scaled by speed of light * the magnitude of the reference momentum [unitless] (at fixed s)
54+
sx, ///< spin vector x-component [unitless] (at fixed s or t)
55+
sy, ///< spin vector y-component [unitless] (at fixed s or t)
56+
sz, ///< spin vector z-component [unitless] (at fixed s or t)
5457
qm, ///< charge to mass ratio, in q_e/m_e [q_e/eV]
5558
w, ///< particle weight, number of real particles represented by this macroparticle [unitless]
5659
nattribs ///< the number of attributes above (always last)
@@ -63,9 +66,9 @@ namespace impactx
6366
};
6467

6568
//! named labels for fixed s
66-
static constexpr auto names_s = { "position_x", "position_y", "position_t", "momentum_x", "momentum_y", "momentum_t", "qm", "weighting" };
69+
static constexpr auto names_s = { "position_x", "position_y", "position_t", "momentum_x", "momentum_y", "momentum_t", "spin_x", "spin_y", "spin_z", "qm", "weighting" };
6770
//! named labels for fixed t
68-
static constexpr auto names_t = { "position_x", "position_y", "position_z", "momentum_x", "momentum_y", "momentum_z", "qm", "weighting" };
71+
static constexpr auto names_t = { "position_x", "position_y", "position_z", "momentum_x", "momentum_y", "momentum_z", "spin_x", "spin_y", "spin_z", "qm", "weighting" };
6972
static_assert(names_s.size() == nattribs);
7073
static_assert(names_t.size() == nattribs);
7174
};
@@ -176,6 +179,9 @@ namespace impactx
176179
* @param px momentum in x
177180
* @param py momentum in y
178181
* @param pt momentum in t
182+
* @param sx spin component in x
183+
* @param sy spin component in y
184+
* @param sz spin component in z
179185
* @param qm charge over mass in 1/eV
180186
* @param bunch_charge total charge within a bunch in C
181187
* @param w weight of each particle: how many real particles to represent
@@ -188,6 +194,9 @@ namespace impactx
188194
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & px,
189195
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & py,
190196
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & pt,
197+
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & sx,
198+
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & sy,
199+
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & sz,
191200
amrex::ParticleReal qm,
192201
std::optional<amrex::ParticleReal> bunch_charge = std::nullopt,
193202
std::optional<amrex::Gpu::DeviceVector<amrex::ParticleReal>> w = std::nullopt

src/particles/ImpactXParticleContainer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ namespace impactx
240240
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & px,
241241
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & py,
242242
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & pt,
243+
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & sx,
244+
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & sy,
245+
amrex::Gpu::DeviceVector<amrex::ParticleReal> const & sz,
243246
amrex::ParticleReal qm,
244247
std::optional<amrex::ParticleReal> bunch_charge,
245248
std::optional<amrex::Gpu::DeviceVector<amrex::ParticleReal>> w
@@ -260,6 +263,9 @@ namespace impactx
260263
AMREX_ALWAYS_ASSERT(x.size() == px.size());
261264
AMREX_ALWAYS_ASSERT(x.size() == py.size());
262265
AMREX_ALWAYS_ASSERT(x.size() == pt.size());
266+
AMREX_ALWAYS_ASSERT(x.size() == sx.size());
267+
AMREX_ALWAYS_ASSERT(x.size() == sy.size());
268+
AMREX_ALWAYS_ASSERT(x.size() == sz.size());
263269
if (has_w) { AMREX_ALWAYS_ASSERT(x.size() == w->size()); }
264270

265271
// number of particles to add
@@ -331,6 +337,9 @@ namespace impactx
331337
amrex::ParticleReal * const AMREX_RESTRICT px_arr = soa[RealSoA::px].dataPtr();
332338
amrex::ParticleReal * const AMREX_RESTRICT py_arr = soa[RealSoA::py].dataPtr();
333339
amrex::ParticleReal * const AMREX_RESTRICT pt_arr = soa[RealSoA::pt].dataPtr();
340+
amrex::ParticleReal * const AMREX_RESTRICT sx_arr = soa[RealSoA::sx].dataPtr();
341+
amrex::ParticleReal * const AMREX_RESTRICT sy_arr = soa[RealSoA::sy].dataPtr();
342+
amrex::ParticleReal * const AMREX_RESTRICT sz_arr = soa[RealSoA::sz].dataPtr();
334343
amrex::ParticleReal * const AMREX_RESTRICT qm_arr = soa[RealSoA::qm].dataPtr();
335344
amrex::ParticleReal * const AMREX_RESTRICT w_arr = soa[RealSoA::w ].dataPtr();
336345

@@ -342,6 +351,9 @@ namespace impactx
342351
amrex::ParticleReal const * const AMREX_RESTRICT px_ptr = px.data();
343352
amrex::ParticleReal const * const AMREX_RESTRICT py_ptr = py.data();
344353
amrex::ParticleReal const * const AMREX_RESTRICT pt_ptr = pt.data();
354+
amrex::ParticleReal const * const AMREX_RESTRICT sx_ptr = sx.data();
355+
amrex::ParticleReal const * const AMREX_RESTRICT sy_ptr = sy.data();
356+
amrex::ParticleReal const * const AMREX_RESTRICT sz_ptr = sz.data();
345357
amrex::ParticleReal const * const AMREX_RESTRICT w_ptr = has_w ? w->data() : nullptr;
346358
amrex::ParticleReal const bunch_charge_value = has_w ? 0_prt : bunch_charge.value();
347359

@@ -358,6 +370,10 @@ namespace impactx
358370
py_arr[old_np+i] = py_ptr[my_offset+i];
359371
pt_arr[old_np+i] = pt_ptr[my_offset+i];
360372

373+
sx_arr[old_np+i] = sx_ptr[my_offset+i];
374+
sy_arr[old_np+i] = sy_ptr[my_offset+i];
375+
sz_arr[old_np+i] = sz_ptr[my_offset+i];
376+
361377
qm_arr[old_np+i] = qm;
362378
w_arr[old_np+i] = has_w ? w_ptr[my_offset+i] : bunch_charge_value / ablastr::constant::SI::q_e/np;
363379
});

0 commit comments

Comments
 (0)