1717#include < AMReX_MultiFab.H>
1818#include < AMReX_ParIter.H>
1919#include < AMReX_Particles.H>
20+ #include < AMReX_ParticleTile.H>
2021
2122#include < AMReX_IntVect.H>
2223#include < AMReX_Vector.H>
2829
2930namespace impactx
3031{
31- /* * AMReX pre-defined Real attributes
32- *
33- * These are the AMReX pre-defined struct indexes for the Real attributes
34- * stored in an AoS in ImpactXParticleContainer. We document this here,
35- * because we change the meaning of these "positions" depending on the
36- * coordinate system we are currently in.
37- */
38- struct RealAoS
39- {
40- enum
41- {
42- x, // /< position in x [m] (at fixed s OR fixed t)
43- y, // /< position in y [m] (at fixed s OR fixed t)
44- t, // /< c * time-of-flight [m] (at fixed s)
45- nattribs // /< the number of attributes above (always last)
46- };
47-
48- // at fixed t, the third component represents the position z
49- enum {
50- z = t // /< position in z [m] (at fixed t)
51- };
52-
53- // ! named labels for fixed s
54- static constexpr auto names_s = { " position_x" , " position_y" , " position_t" };
55- // ! named labels for fixed t
56- static constexpr auto names_t = { " position_x" , " position_y" , " position_z" };
57- static_assert (names_s.size() == nattribs);
58- static_assert (names_t .size() == nattribs);
59- };
60-
61- /* * This struct indexes the additional Real attributes
32+ /* * This struct indexes the Real attributes
6233 * stored in an SoA in ImpactXParticleContainer
6334 */
6435 struct RealSoA
6536 {
6637 enum
6738 {
39+ x, // /< position in x [m] (at fixed s or t)
40+ y, // /< position in y [m] (at fixed s or t)
41+ t, // /< time-of-flight ct [m] (at fixed s)
6842 px, // /< momentum in x, scaled by the magnitude of the reference momentum [unitless] (at fixed s or t)
6943 py, // /< momentum in y, scaled by the magnitude of the reference momentum [unitless] (at fixed s or t)
7044 pt, // /< energy deviation, scaled by speed of light * the magnitude of the reference momentum [unitless] (at fixed s)
@@ -73,75 +47,85 @@ namespace impactx
7347 nattribs // /< the number of attributes above (always last)
7448 };
7549
76- // at fixed t, the third component represents the momentum in z
50+ // at fixed t, the third component represents the position z, the 6th component represents the momentum in z
7751 enum {
52+ z = t, // /< position in z [m] (at fixed t)
7853 pz = pt // /< momentum in z, scaled by the magnitude of the reference momentum [unitless] (at fixed t)
7954 };
8055
8156 // ! named labels for fixed s
82- static constexpr auto names_s = { " momentum_x" , " momentum_y" , " momentum_t" , " qm" , " weighting" };
57+ static constexpr auto names_s = { " position_x " , " position_y " , " position_t " , " momentum_x" , " momentum_y" , " momentum_t" , " qm" , " weighting" };
8358 // ! named labels for fixed t
84- static constexpr auto names_t = { " momentum_x" , " momentum_y" , " momentum_z" , " qm" , " weighting" };
59+ static constexpr auto names_t = { " position_x " , " position_y " , " position_z " , " momentum_x" , " momentum_y" , " momentum_z" , " qm" , " weighting" };
8560 static_assert (names_s.size() == nattribs);
8661 static_assert (names_t .size() == nattribs);
8762 };
8863
89- /* * This struct indexes the additional Integer attributes
64+ /* * This struct indexes the Integer attributes
9065 * stored in an SoA in ImpactXParticleContainer
9166 */
9267 struct IntSoA
9368 {
9469 enum
9570 {
96- nattribs // /< the number of particles above (always last)
71+ id, // /< unique particle id on the rank of particle creation
72+ cpu, // /< rank the particle was created on
73+ nattribs // /< the number of attributes above (always last)
9774 };
75+
76+ // ! named labels for fixed s
77+ static constexpr auto names_s = { " id" , " cpu" };
78+ // ! named labels for fixed t
79+ static constexpr auto names_t = { " id" , " cpu" };
80+ static_assert (names_s.size() == nattribs);
81+ static_assert (names_t .size() == nattribs);
9882 };
9983
10084 /* * AMReX iterator for particle boxes
10185 *
10286 * We subclass here to change the default threading strategy, which is
10387 * `static` in AMReX, to `dynamic` in ImpactX.
10488 */
105- class ParIter
106- : public amrex::ParIter< 0 , 0 , RealSoA::nattribs, IntSoA::nattribs>
89+ class ParIterSoA
90+ : public amrex::ParIterSoA< RealSoA::nattribs, IntSoA::nattribs>
10791 {
10892 public:
109- using amrex::ParIter< 0 , 0 , RealSoA::nattribs, IntSoA::nattribs>::ParIter ;
93+ using amrex::ParIterSoA< RealSoA::nattribs, IntSoA::nattribs>::ParIterSoA ;
11094
111- ParIter (ContainerType& pc, int level);
95+ ParIterSoA (ContainerType& pc, int level);
11296
113- ParIter (ContainerType& pc, int level, amrex::MFItInfo& info);
97+ ParIterSoA (ContainerType& pc, int level, amrex::MFItInfo& info);
11498 };
11599
116100 /* * Const AMReX iterator for particle boxes - data is read only.
117101 *
118102 * We subclass here to change the default threading strategy, which is
119103 * `static` in AMReX, to `dynamic` in ImpactX.
120104 */
121- class ParConstIter
122- : public amrex::ParConstIter< 0 , 0 , RealSoA::nattribs, IntSoA::nattribs>
105+ class ParConstIterSoA
106+ : public amrex::ParConstIterSoA< RealSoA::nattribs, IntSoA::nattribs>
123107 {
124108 public:
125- using amrex::ParConstIter< 0 , 0 , RealSoA::nattribs, IntSoA::nattribs>::ParConstIter ;
109+ using amrex::ParConstIterSoA< RealSoA::nattribs, IntSoA::nattribs>::ParConstIterSoA ;
126110
127- ParConstIter (ContainerType& pc, int level);
111+ ParConstIterSoA (ContainerType& pc, int level);
128112
129- ParConstIter (ContainerType& pc, int level, amrex::MFItInfo& info);
113+ ParConstIterSoA (ContainerType& pc, int level, amrex::MFItInfo& info);
130114 };
131115
132116 /* * Beam Particles in ImpactX
133117 *
134118 * This class stores particles, distributed over MPI ranks.
135119 */
136120 class ImpactXParticleContainer
137- : public amrex::ParticleContainer< 0 , 0 , RealSoA::nattribs, IntSoA::nattribs>
121+ : public amrex::ParticleContainerPureSoA< RealSoA::nattribs, IntSoA::nattribs>
138122 {
139123 public:
140124 // ! amrex iterator for particle boxes
141- using iterator = impactx::ParIter ;
125+ using iterator = impactx::ParIterSoA ;
142126
143127 // ! amrex constant iterator for particle boxes (read-only)
144- using const_iterator = impactx::ParConstIter ;
128+ using const_iterator = impactx::ParConstIterSoA ;
145129
146130 // ! Construct a new particle container
147131 ImpactXParticleContainer (amrex::AmrCore* amr_core);
0 commit comments