WarpX
Loading...
Searching...
No Matches
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
12
13#include <AMReX.H>
14#include <AMReX_REAL.H>
15
16#include <cmath>
17#include <limits>
18
25template<typename T_PIdx = PIdx>
30 amrex::ParticleReal& z) noexcept
31{
32 using namespace amrex::literals;
33
34#if defined(WARPX_DIM_RZ)
35 amrex::ParticleReal const theta = p.rdata(T_PIdx::theta);
36 amrex::ParticleReal const r = p.pos(T_PIdx::x);
37 x = r*std::cos(theta);
38 y = r*std::sin(theta);
39 z = p.pos(PIdx::z);
40#elif defined(WARPX_DIM_RCYLINDER)
41 amrex::ParticleReal const theta = p.rdata(T_PIdx::theta);
42 amrex::ParticleReal const r = p.pos(T_PIdx::x);
43 x = r*std::cos(theta);
44 y = r*std::sin(theta);
45 z = 0_prt;
46#elif defined(WARPX_DIM_RSPHERE)
47 amrex::ParticleReal const theta = p.rdata(T_PIdx::theta);
48 amrex::ParticleReal const phi = p.rdata(T_PIdx::phi);
49 amrex::ParticleReal const r = p.pos(T_PIdx::x);
50 x = r*std::cos(theta)*std::cos(phi);
51 y = r*std::sin(theta)*std::cos(phi);
52 z = r*std::sin(phi);
53#elif defined(WARPX_DIM_3D)
54 x = p.pos(PIdx::x);
55 y = p.pos(PIdx::y);
56 z = p.pos(PIdx::z);
57#elif defined(WARPX_DIM_XZ)
58 x = p.pos(PIdx::x);
59 y = 0_prt;
60 z = p.pos(PIdx::z);
61#else
62 x = 0_prt;
63 y = 0_prt;
64 z = p.pos(PIdx::z);
65#endif
66}
67
73template<typename T_PIdx = PIdx>
75{
77
78 const RType* AMREX_RESTRICT m_x = nullptr;
79 const RType* AMREX_RESTRICT m_y = nullptr;
80 const RType* AMREX_RESTRICT m_z = nullptr;
81
82#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
83 const RType* AMREX_RESTRICT m_theta = nullptr;
84#endif
85#if defined(WARPX_DIM_RSPHERE)
86 const RType* AMREX_RESTRICT m_phi = nullptr;
87#endif
88
89 static constexpr RType m_x_default = RType(0.0);
90 static constexpr RType m_y_default = RType(0.0);
91 static constexpr RType m_z_default = RType(0.0);
92
93 GetParticlePosition () = default;
94
102 template <typename ptiType>
103 explicit
104 GetParticlePosition (const ptiType& a_pti, long a_offset = 0) noexcept
105 {
106 const auto& soa = a_pti.GetStructOfArrays();
107
108#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ)
109 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
110 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
111#elif defined(WARPX_DIM_3D)
112 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
113 m_y = soa.GetRealData(PIdx::y).dataPtr() + a_offset;
114 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
115#elif defined(WARPX_DIM_1D_Z)
116 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
117#elif defined(WARPX_DIM_RCYLINDER)
118 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
119 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
120#elif defined(WARPX_DIM_RSPHERE)
121 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
122 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
123 m_phi = soa.GetRealData(T_PIdx::phi).dataPtr() + a_offset;
124#endif
125#if defined(WARPX_DIM_RZ)
126 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
127#endif
128 }
129
134 void operator() (const long i, RType& x, RType& y, RType& z) const noexcept
135 {
136#if defined(WARPX_DIM_RZ)
137 RType const r = m_x[i];
138 x = r*std::cos(m_theta[i]);
139 y = r*std::sin(m_theta[i]);
140 z = m_z[i];
141#elif defined(WARPX_DIM_RCYLINDER)
142 RType const r = m_x[i];
143 x = r*std::cos(m_theta[i]);
144 y = r*std::sin(m_theta[i]);
145 z = m_z_default;
146#elif defined(WARPX_DIM_RSPHERE)
147 RType const r = m_x[i];
148 x = r*std::cos(m_theta[i])*std::cos(m_phi[i]);
149 y = r*std::sin(m_theta[i])*std::cos(m_phi[i]);
150 z = r*std::sin(m_phi[i]);
151#elif defined(WARPX_DIM_3D)
152 x = m_x[i];
153 y = m_y[i];
154 z = m_z[i];
155#elif defined(WARPX_DIM_XZ)
156 x = m_x[i];
157 y = m_y_default;
158 z = m_z[i];
159#elif defined(WARPX_DIM_1D_Z)
160 x = m_x_default;
161 y = m_y_default;
162 z = m_z[i];
163#endif
164 }
165
172 void AsStored (const long i, RType& x, RType& y, RType& z) const noexcept
173 {
174#if defined(WARPX_DIM_RZ)
175 x = m_x[i];
176 y = m_theta[i];
177 z = m_z[i];
178#elif defined(WARPX_DIM_RCYLINDER)
179 x = m_x[i];
180 y = m_theta[i];
181 z = m_z_default;
182#elif defined(WARPX_DIM_RSPHERE)
183 x = m_x[i];
184 y = m_theta[i];
185 z = m_phi[i];
186#elif defined(WARPX_DIM_3D)
187 x = m_x[i];
188 y = m_y[i];
189 z = m_z[i];
190#elif defined(WARPX_DIM_XZ)
191 x = m_x[i];
192 y = m_y_default;
193 z = m_z[i];
194#elif defined(WARPX_DIM_1D_Z)
195 x = m_x_default;
196 y = m_y_default;
197 z = m_z[i];
198#endif
199 }
200};
201
209template<typename T_PIdx = PIdx>
211{
213
214#if defined(WARPX_DIM_3D)
218#elif defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ)
221#elif defined(WARPX_DIM_1D_Z)
223#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
224 RType* AMREX_RESTRICT m_x = nullptr;
225#endif
226
227#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
229#endif
230#if defined(WARPX_DIM_RSPHERE)
231 RType* AMREX_RESTRICT m_phi;
232#endif
233
234 template <typename ptiType>
235 explicit
236 SetParticlePosition (const ptiType& a_pti, long a_offset = 0) noexcept
237 {
238 auto& soa = a_pti.GetStructOfArrays();
239#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ)
240 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
241 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
242#elif defined(WARPX_DIM_3D)
243 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
244 m_y = soa.GetRealData(PIdx::y).dataPtr() + a_offset;
245 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
246#elif defined(WARPX_DIM_1D_Z)
247 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
248#elif defined(WARPX_DIM_RCYLINDER)
249 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
250 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
251#elif defined(WARPX_DIM_RSPHERE)
252 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
253 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
254 m_phi = soa.GetRealData(T_PIdx::phi).dataPtr() + a_offset;
255#endif
256#if defined(WARPX_DIM_RZ)
257 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
258#endif
259 }
260
264 void operator() (const long i, RType x, RType y, RType z) const noexcept
265 {
267#if defined(WARPX_DIM_RZ)
268 m_theta[i] = std::atan2(y, x);
269 m_x[i] = std::sqrt(x*x + y*y);
270 m_z[i] = z;
271#elif defined(WARPX_DIM_RCYLINDER)
272 m_theta[i] = std::atan2(y, x);
273 m_x[i] = std::sqrt(x*x + y*y);
274#elif defined(WARPX_DIM_RSPHERE)
275 RType const rxy = std::sqrt(x*x + y*y);
276 RType const r = std::sqrt(x*x + y*y + z*z);
277 m_x[i] = r;
278 m_theta[i] = std::atan2(y, x);
279 m_phi[i] = std::atan2(z, rxy);
280#elif defined(WARPX_DIM_3D)
281 m_x[i] = x;
282 m_y[i] = y;
283 m_z[i] = z;
284#elif defined(WARPX_DIM_XZ)
285 m_x[i] = x;
286 m_z[i] = z;
287#elif defined(WARPX_DIM_1D_Z)
288 m_z[i] = z;
289#endif
290 }
291
297 void AsStored (const long i, RType x, RType y, RType z) const noexcept
298 {
300#if defined(WARPX_DIM_RZ)
301 m_x[i] = x;
302 m_theta[i] = y;
303 m_z[i] = z;
304#elif defined(WARPX_DIM_RCYLINDER)
305 m_x[i] = x;
306 m_theta[i] = y;
307#elif defined(WARPX_DIM_RSPHERE)
308 m_x[i] = x;
309 m_theta[i] = y;
310 m_phi[i] = z;
311#elif defined(WARPX_DIM_3D)
312 m_x[i] = x;
313 m_y[i] = y;
314 m_z[i] = z;
315#elif defined(WARPX_DIM_XZ)
316 m_x[i] = x;
317 m_z[i] = z;
318#elif defined(WARPX_DIM_1D_Z)
319 m_z[i] = z;
320#endif
321 }
322};
323
324#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:27
amrex_particle_real ParticleReal
__host__ __device__ void ignore_unused(const Ts &...)
const RType *AMREX_RESTRICT m_y
Definition GetAndSetPosition.H:79
static constexpr RType m_y_default
Definition GetAndSetPosition.H:90
const RType *AMREX_RESTRICT m_x
Definition GetAndSetPosition.H:78
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:172
const RType *AMREX_RESTRICT m_theta
Definition GetAndSetPosition.H:83
static constexpr RType m_x_default
Definition GetAndSetPosition.H:89
GetParticlePosition(const ptiType &a_pti, long a_offset=0) noexcept
Definition GetAndSetPosition.H:104
static constexpr RType m_z_default
Definition GetAndSetPosition.H:91
amrex::ParticleReal RType
Definition GetAndSetPosition.H:76
GetParticlePosition()=default
const RType *AMREX_RESTRICT m_z
Definition GetAndSetPosition.H:80
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:134
@ x
Definition WarpXParticleContainer.H:70
@ z
Definition WarpXParticleContainer.H:70
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:264
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:297
RType *AMREX_RESTRICT m_z
Definition GetAndSetPosition.H:220
SetParticlePosition(const ptiType &a_pti, long a_offset=0) noexcept
Definition GetAndSetPosition.H:236
RType *AMREX_RESTRICT m_theta
Definition GetAndSetPosition.H:228
amrex::ParticleReal RType
Definition GetAndSetPosition.H:212
RType *AMREX_RESTRICT m_x
Definition GetAndSetPosition.H:219