WarpX
GetAndSetPosition.H
Go to the documentation of this file.
1 /* Copyright 2019 David Grote, Maxence Thevenet, Remi Lehe
2  * Weiqun Zhang
3  *
4  * This file is part of WarpX.
5  *
6  * License: BSD-3-Clause-LBNL
7  */
8 #ifndef WARPX_PARTICLES_PUSHER_GETANDSETPOSITION_H_
9 #define WARPX_PARTICLES_PUSHER_GETANDSETPOSITION_H_
10 
13 
14 #include <AMReX.H>
15 #include <AMReX_REAL.H>
16 
17 #include <cmath>
18 #include <limits>
19 
26 template<typename T_PIdx = PIdx>
29  amrex::ParticleReal& x,
30  amrex::ParticleReal& y,
31  amrex::ParticleReal& z) noexcept
32 {
33 #ifdef WARPX_DIM_RZ
34  const amrex::ParticleReal theta = p.rdata(T_PIdx::theta);
35  const amrex::ParticleReal r = p.pos(0);
36  x = r*std::cos(theta);
37  y = r*std::sin(theta);
38  z = p.pos(1);
39 #elif WARPX_DIM_3D
40  x = p.pos(0);
41  y = p.pos(1);
42  z = p.pos(2);
43 #elif WARPX_DIM_XZ
44  x = p.pos(0);
45  y = amrex::ParticleReal(0.0);
46  z = p.pos(1);
47 #else
48  x = amrex::ParticleReal(0.0);
49  y = amrex::ParticleReal(0.0);
50  z = p.pos(0);
51 #endif
52 }
53 
59 template<typename T_PIdx = PIdx>
61 {
63  using RType = amrex::ParticleReal;
64 
65  const PType* AMREX_RESTRICT m_structs = nullptr;
66 #if defined(WARPX_DIM_RZ)
67  const RType* m_theta = nullptr;
68 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
69  static constexpr RType m_y_default = RType(0.0);
70 #elif defined(WARPX_DIM_1D_Z)
71  static constexpr RType m_x_default = RType(0.0);
72  static constexpr RType m_y_default = RType(0.0);
73 #endif
74 
75  GetParticlePosition () = default;
76 
84  template <typename ptiType>
85  GetParticlePosition (const ptiType& a_pti, long a_offset = 0) noexcept
86  {
87  const auto& aos = a_pti.GetArrayOfStructs();
88  m_structs = aos().dataPtr() + a_offset;
89 #if defined(WARPX_DIM_RZ)
90  const auto& soa = a_pti.GetStructOfArrays();
91  m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
92 #endif
93  }
94 
99  void operator() (const long i, RType& x, RType& y, RType& z) const noexcept
100  {
101  const PType& p = m_structs[i];
102 #ifdef WARPX_DIM_RZ
103  const RType r = p.pos(0);
104  x = r*std::cos(m_theta[i]);
105  y = r*std::sin(m_theta[i]);
106  z = p.pos(1);
107 #elif WARPX_DIM_3D
108  x = p.pos(0);
109  y = p.pos(1);
110  z = p.pos(2);
111 #elif WARPX_DIM_XZ
112  x = p.pos(0);
113  y = m_y_default;
114  z = p.pos(1);
115 #else
116  x = m_x_default;
117  y = m_y_default;
118  z = p.pos(0);
119 #endif
120  }
121 
128  void AsStored (const long i, RType& x, RType& y, RType& z) const noexcept
129  {
130  const PType& p = m_structs[i];
131 #ifdef WARPX_DIM_RZ
132  x = p.pos(0);
133  y = m_theta[i];
134  z = p.pos(1);
135 #elif WARPX_DIM_3D
136  x = p.pos(0);
137  y = p.pos(1);
138  z = p.pos(2);
139 #elif WARPX_DIM_XZ
140  x = p.pos(0);
141  y = m_y_default;
142  z = p.pos(1);
143 #else
144  x = m_x_default;
145  y = m_y_default;
146  z = p.pos(0);
147 #endif
148  }
149 };
150 
158 template<typename T_PIdx = PIdx>
160 {
162  using RType = amrex::ParticleReal;
163 
165 #if defined(WARPX_DIM_RZ)
167 #endif
168 
169  template <typename ptiType>
170  SetParticlePosition (const ptiType& a_pti, long a_offset = 0) noexcept
171  {
172  auto& aos = a_pti.GetArrayOfStructs();
173  m_structs = aos().dataPtr() + a_offset;
174 #if defined(WARPX_DIM_RZ)
175  auto& soa = a_pti.GetStructOfArrays();
176  m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
177 #endif
178  }
179 
183  void operator() (const long i, RType x, RType y, RType z) const noexcept
184  {
185 #if defined(WARPX_DIM_XZ)
187 #endif
188 #if defined(WARPX_DIM_1D_Z)
190 #endif
191 #ifdef WARPX_DIM_RZ
192  m_theta[i] = std::atan2(y, x);
193  m_structs[i].pos(0) = std::sqrt(x*x + y*y);
194  m_structs[i].pos(1) = z;
195 #elif WARPX_DIM_3D
196  m_structs[i].pos(0) = x;
197  m_structs[i].pos(1) = y;
198  m_structs[i].pos(2) = z;
199 #elif WARPX_DIM_XZ
200  m_structs[i].pos(0) = x;
201  m_structs[i].pos(1) = z;
202 #else
203  m_structs[i].pos(0) = z;
204 #endif
205  }
206 
212  void AsStored (const long i, RType x, RType y, RType z) const noexcept
213  {
214 #if defined(WARPX_DIM_XZ)
216 #endif
217 #if defined(WARPX_DIM_1D_Z)
219 #endif
220 #ifdef WARPX_DIM_RZ
221  m_structs[i].pos(0) = x;
222  m_theta[i] = y;
223  m_structs[i].pos(1) = z;
224 #elif WARPX_DIM_3D
225  m_structs[i].pos(0) = x;
226  m_structs[i].pos(1) = y;
227  m_structs[i].pos(2) = z;
228 #elif WARPX_DIM_XZ
229  m_structs[i].pos(0) = x;
230  m_structs[i].pos(1) = z;
231 #else
232  m_structs[i].pos(0) = z;
233 #endif
234  }
235 };
236 
237 #endif // WARPX_PARTICLES_PUSHER_GETANDSETPOSITION_H_
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void get_particle_position(const WarpXParticleContainer::SuperParticleType &p, amrex::ParticleReal &x, amrex::ParticleReal &y, amrex::ParticleReal &z) noexcept
Extract the cartesian position coordinates of the particle p and store them in the variables x,...
Definition: GetAndSetPosition.H:28
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
i
Definition: check_interp_points_and_weights.py:174
Functor that can be used to extract the positions of the macroparticles inside a ParallelFor kernel.
Definition: GetAndSetPosition.H:61
WarpXParticleContainer::ParticleType PType
Definition: GetAndSetPosition.H:62
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void AsStored(const long i, RType &x, RType &y, RType &z) const noexcept
Extract the position coordinates of the particle as stored located at index i + a_offset and store th...
Definition: GetAndSetPosition.H:128
const PType *AMREX_RESTRICT m_structs
Definition: GetAndSetPosition.H:65
GetParticlePosition(const ptiType &a_pti, long a_offset=0) noexcept
Definition: GetAndSetPosition.H:85
amrex::ParticleReal RType
Definition: GetAndSetPosition.H:63
GetParticlePosition()=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(const long i, RType &x, RType &y, RType &z) const noexcept
Extract the cartesian position coordinates of the particle located at index i + a_offset and store th...
Definition: GetAndSetPosition.H:99
const RType * m_theta
Definition: GetAndSetPosition.H:67
Functor that can be used to modify the positions of the macroparticles, inside a ParallelFor kernel.
Definition: GetAndSetPosition.H:160
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(const long i, RType x, RType y, RType z) const noexcept
Set the position of the particle at index i + a_offset to x, y, z
Definition: GetAndSetPosition.H:183
PType *AMREX_RESTRICT m_structs
Definition: GetAndSetPosition.H:164
WarpXParticleContainer::ParticleType PType
Definition: GetAndSetPosition.H:161
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void AsStored(const long i, RType x, RType y, RType z) const noexcept
Set the position of the particle at index i + a_offset to x, y, z This is only different for RZ since...
Definition: GetAndSetPosition.H:212
SetParticlePosition(const ptiType &a_pti, long a_offset=0) noexcept
Definition: GetAndSetPosition.H:170
RType *AMREX_RESTRICT m_theta
Definition: GetAndSetPosition.H:166
amrex::ParticleReal RType
Definition: GetAndSetPosition.H:162