|
17 | 17 | #include "Utils/ParticleUtils.H" |
18 | 18 | #include "Utils/WarpXAlgorithmSelection.H" |
19 | 19 |
|
| 20 | +#include <array> |
| 21 | + |
| 22 | +// Indices in PIdx of the spatial-position attributes, for the current |
| 23 | +// dimensionality. Note that they are not contiguous in PIdx for RZ-family |
| 24 | +// geometries (theta/phi come after `w`), so a simple 0..PIdx::w-1 loop would |
| 25 | +// miss them. |
| 26 | +#if defined(WARPX_DIM_1D_Z) |
| 27 | + static constexpr std::array<int, 1> position_indices = {PIdx::z}; |
| 28 | +#elif defined(WARPX_DIM_XZ) |
| 29 | + static constexpr std::array<int, 2> position_indices = {PIdx::x, PIdx::z}; |
| 30 | +#elif defined(WARPX_DIM_RZ) |
| 31 | + static constexpr std::array<int, 3> position_indices = {PIdx::x, PIdx::z, PIdx::theta}; |
| 32 | +#elif defined(WARPX_DIM_RCYLINDER) |
| 33 | + static constexpr std::array<int, 2> position_indices = {PIdx::x, PIdx::theta}; |
| 34 | +#elif defined(WARPX_DIM_RSPHERE) |
| 35 | + static constexpr std::array<int, 3> position_indices = {PIdx::x, PIdx::theta, PIdx::phi}; |
| 36 | +#elif defined(WARPX_DIM_3D) |
| 37 | + static constexpr std::array<int, 3> position_indices = {PIdx::x, PIdx::y, PIdx::z}; |
| 38 | +#endif |
| 39 | + |
20 | 40 | /** |
21 | 41 | * \brief This class defines an operator to create product particles from DSMC |
22 | 42 | * collisions and sets the particle properties (position, momentum, weight). |
@@ -360,9 +380,8 @@ public: |
360 | 380 | // For charge exchange, swap positions at which the products are created |
361 | 381 | // to ensure local charge conservation. For instance in the reaction |
362 | 382 | // `A+ + B -> A + B+`, B+ will be created at the position of A+, instead of that of B. |
363 | | - // Position components occupy indices 0 through PIdx::w-1 in m_rdata. |
364 | 383 | if (mask[i] == int(ScatteringProcessType::CHARGE_EXCHANGE)) { |
365 | | - for (int idim = 0; idim < PIdx::w; ++idim) { |
| 384 | + for (int idim : position_indices) { |
366 | 385 | soa_products_data[2].m_rdata[idim][slot2_idx] = soa_1.m_rdata[idim][src1_idx]; |
367 | 386 | soa_products_data[3].m_rdata[idim][slot3_idx] = soa_0.m_rdata[idim][src0_idx]; |
368 | 387 | } |
|
0 commit comments