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  using namespace amrex::literals;
34 
35 #if defined(WARPX_DIM_RZ)
36  amrex::ParticleReal const theta = p.rdata(T_PIdx::theta);
37  amrex::ParticleReal const r = p.pos(T_PIdx::x);
38  x = r*std::cos(theta);
39  y = r*std::sin(theta);
40  z = p.pos(PIdx::z);
41 #elif defined(WARPX_DIM_3D)
42  x = p.pos(PIdx::x);
43  y = p.pos(PIdx::y);
44  z = p.pos(PIdx::z);
45 #elif defined(WARPX_DIM_XZ)
46  x = p.pos(PIdx::x);
47  y = 0_prt;
48  z = p.pos(PIdx::z);
49 #else
50  x = 0_prt;
51  y = 0_prt;
52  z = p.pos(PIdx::z);
53 #endif
54 }
55 
61 template<typename T_PIdx = PIdx>
63 {
64  using RType = amrex::ParticleReal;
65 
66 #if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ)
67  const RType* AMREX_RESTRICT m_x = nullptr;
68  const RType* AMREX_RESTRICT m_z = nullptr;
69 #elif defined(WARPX_DIM_3D)
70  const RType* AMREX_RESTRICT m_x = nullptr;
71  const RType* AMREX_RESTRICT m_y = nullptr;
72  const RType* AMREX_RESTRICT m_z = nullptr;
73 #elif defined(WARPX_DIM_1D_Z)
74  const RType* AMREX_RESTRICT m_z = nullptr;
75 #endif
76 
77 #if defined(WARPX_DIM_RZ)
78  const RType* m_theta = nullptr;
79 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
80  static constexpr RType m_y_default = RType(0.0);
81 #elif defined(WARPX_DIM_1D_Z)
82  static constexpr RType m_x_default = RType(0.0);
83  static constexpr RType m_y_default = RType(0.0);
84 #endif
85 
86  GetParticlePosition () = default;
87 
95  template <typename ptiType>
96  GetParticlePosition (const ptiType& a_pti, long a_offset = 0) noexcept
97  {
98  const auto& soa = a_pti.GetStructOfArrays();
99 
100 #if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ)
101  m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
102  m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
103 #elif defined(WARPX_DIM_3D)
104  m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
105  m_y = soa.GetRealData(PIdx::y).dataPtr() + a_offset;
106  m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
107 #elif defined(WARPX_DIM_1D_Z)
108  m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
109 #endif
110 #if defined(WARPX_DIM_RZ)
111  m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
112 #endif
113  }
114 
119  void operator() (const long i, RType& x, RType& y, RType& z) const noexcept
120  {
121 #ifdef WARPX_DIM_RZ
122  RType const r = m_x[i];
123  x = r*std::cos(m_theta[i]);
124  y = r*std::sin(m_theta[i]);
125  z = m_z[i];
126 #elif WARPX_DIM_3D
127  x = m_x[i];
128  y = m_y[i];
129  z = m_z[i];
130 #elif WARPX_DIM_XZ
131  x = m_x[i];
132  y = m_y_default;
133  z = m_z[i];
134 #else
135  x = m_x_default;
136  y = m_y_default;
137  z = m_z[i];
138 #endif
139  }
140 
147  void AsStored (const long i, RType& x, RType& y, RType& z) const noexcept
148  {
149 #ifdef WARPX_DIM_RZ
150  x = m_x[i];
151  y = m_theta[i];
152  z = m_z[i];
153 #elif WARPX_DIM_3D
154  x = m_x[i];
155  y = m_y[i];
156  z = m_z[i];
157 #elif WARPX_DIM_XZ
158  x = m_x[i];
159  y = m_y_default;
160  z = m_z[i];
161 #else
162  x = m_x_default;
163  y = m_y_default;
164  z = m_z[i];
165 #endif
166  }
167 };
168 
176 template<typename T_PIdx = PIdx>
178 {
179  using RType = amrex::ParticleReal;
180 
181 #if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ)
184 #elif defined(WARPX_DIM_3D)
186  RType* AMREX_RESTRICT m_y;
188 #elif defined(WARPX_DIM_1D_Z)
190 #endif
191 #if defined(WARPX_DIM_RZ)
193 #endif
194 
195  template <typename ptiType>
196  SetParticlePosition (const ptiType& a_pti, long a_offset = 0) noexcept
197  {
198  auto& soa = a_pti.GetStructOfArrays();
199 #if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ)
200  m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
201  m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
202 #elif defined(WARPX_DIM_3D)
203  m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
204  m_y = soa.GetRealData(PIdx::y).dataPtr() + a_offset;
205  m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
206 #elif defined(WARPX_DIM_1D_Z)
207  m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
208 #endif
209 #if defined(WARPX_DIM_RZ)
210  m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
211 #endif
212  }
213 
217  void operator() (const long i, RType x, RType y, RType z) const noexcept
218  {
219 #if defined(WARPX_DIM_XZ)
221 #endif
222 #if defined(WARPX_DIM_1D_Z)
224 #endif
225 #ifdef WARPX_DIM_RZ
226  m_theta[i] = std::atan2(y, x);
227  m_x[i] = std::sqrt(x*x + y*y);
228  m_z[i] = z;
229 #elif WARPX_DIM_3D
230  m_x[i] = x;
231  m_y[i] = y;
232  m_z[i] = z;
233 #elif WARPX_DIM_XZ
234  m_x[i] = x;
235  m_z[i] = z;
236 #else
237  m_z[i] = z;
238 #endif
239  }
240 
246  void AsStored (const long i, RType x, RType y, RType z) const noexcept
247  {
248 #if defined(WARPX_DIM_XZ)
250 #endif
251 #if defined(WARPX_DIM_1D_Z)
253 #endif
254 #ifdef WARPX_DIM_RZ
255  m_x[i] = x;
256  m_theta[i] = y;
257  m_z[i] = z;
258 #elif WARPX_DIM_3D
259  m_x[i] = x;
260  m_y[i] = y;
261  m_z[i] = z;
262 #elif WARPX_DIM_XZ
263  m_x[i] = x;
264  m_z[i] = z;
265 #else
266  m_z[i] = z;
267 #endif
268  }
269 };
270 
271 #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:63
const RType *AMREX_RESTRICT m_x
Definition: GetAndSetPosition.H:67
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:147
GetParticlePosition(const ptiType &a_pti, long a_offset=0) noexcept
Definition: GetAndSetPosition.H:96
amrex::ParticleReal RType
Definition: GetAndSetPosition.H:64
GetParticlePosition()=default
const RType *AMREX_RESTRICT m_z
Definition: GetAndSetPosition.H:68
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:119
const RType * m_theta
Definition: GetAndSetPosition.H:78
@ x
Definition: NamedComponentParticleContainer.H:27
@ z
Definition: NamedComponentParticleContainer.H:32
Functor that can be used to modify the positions of the macroparticles, inside a ParallelFor kernel.
Definition: GetAndSetPosition.H:178
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:217
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:246
RType *AMREX_RESTRICT m_z
Definition: GetAndSetPosition.H:183
SetParticlePosition(const ptiType &a_pti, long a_offset=0) noexcept
Definition: GetAndSetPosition.H:196
RType *AMREX_RESTRICT m_theta
Definition: GetAndSetPosition.H:192
amrex::ParticleReal RType
Definition: GetAndSetPosition.H:179
RType *AMREX_RESTRICT m_x
Definition: GetAndSetPosition.H:182