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>
28 amrex::ParticleReal& x,
29 amrex::ParticleReal& y,
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{
76 using RType = amrex::ParticleReal;
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 GetParticlePosition (const ptiType& a_pti, long a_offset = 0) noexcept
104 {
105 const auto& soa = a_pti.GetStructOfArrays();
106
107#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ)
108 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
109 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
110#elif defined(WARPX_DIM_3D)
111 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
112 m_y = soa.GetRealData(PIdx::y).dataPtr() + a_offset;
113 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
114#elif defined(WARPX_DIM_1D_Z)
115 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
116#elif defined(WARPX_DIM_RCYLINDER)
117 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
118 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
119#elif defined(WARPX_DIM_RSPHERE)
120 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
121 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
122 m_phi = soa.GetRealData(T_PIdx::phi).dataPtr() + a_offset;
123#endif
124#if defined(WARPX_DIM_RZ)
125 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
126#endif
127 }
128
133 void operator() (const long i, RType& x, RType& y, RType& z) const noexcept
134 {
135#if defined(WARPX_DIM_RZ)
136 RType const r = m_x[i];
137 x = r*std::cos(m_theta[i]);
138 y = r*std::sin(m_theta[i]);
139 z = m_z[i];
140#elif defined(WARPX_DIM_RCYLINDER)
141 RType const r = m_x[i];
142 x = r*std::cos(m_theta[i]);
143 y = r*std::sin(m_theta[i]);
144 z = m_z_default;
145#elif defined(WARPX_DIM_RSPHERE)
146 RType const r = m_x[i];
147 x = r*std::cos(m_theta[i])*std::cos(m_phi[i]);
148 y = r*std::sin(m_theta[i])*std::cos(m_phi[i]);
149 z = r*std::sin(m_phi[i]);
150#elif defined(WARPX_DIM_3D)
151 x = m_x[i];
152 y = m_y[i];
153 z = m_z[i];
154#elif defined(WARPX_DIM_XZ)
155 x = m_x[i];
156 y = m_y_default;
157 z = m_z[i];
158#elif defined(WARPX_DIM_1D_Z)
159 x = m_x_default;
160 y = m_y_default;
161 z = m_z[i];
162#endif
163 }
164
171 void AsStored (const long i, RType& x, RType& y, RType& z) const noexcept
172 {
173#if defined(WARPX_DIM_RZ)
174 x = m_x[i];
175 y = m_theta[i];
176 z = m_z[i];
177#elif defined(WARPX_DIM_RCYLINDER)
178 x = m_x[i];
179 y = m_theta[i];
180 z = m_z_default;
181#elif defined(WARPX_DIM_RSPHERE)
182 x = m_x[i];
183 y = m_theta[i];
184 z = m_phi[i];
185#elif defined(WARPX_DIM_3D)
186 x = m_x[i];
187 y = m_y[i];
188 z = m_z[i];
189#elif defined(WARPX_DIM_XZ)
190 x = m_x[i];
191 y = m_y_default;
192 z = m_z[i];
193#elif defined(WARPX_DIM_1D_Z)
194 x = m_x_default;
195 y = m_y_default;
196 z = m_z[i];
197#endif
198 }
199};
200
208template<typename T_PIdx = PIdx>
210{
211 using RType = amrex::ParticleReal;
212
213#if defined(WARPX_DIM_3D)
217#elif defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ)
220#elif defined(WARPX_DIM_1D_Z)
222#elif defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
223 RType* AMREX_RESTRICT m_x = nullptr;
224#endif
225
226#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
228#endif
229#if defined(WARPX_DIM_RSPHERE)
230 RType* AMREX_RESTRICT m_phi;
231#endif
232
233 template <typename ptiType>
234 SetParticlePosition (const ptiType& a_pti, long a_offset = 0) noexcept
235 {
236 auto& soa = a_pti.GetStructOfArrays();
237#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_XZ)
238 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
239 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
240#elif defined(WARPX_DIM_3D)
241 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
242 m_y = soa.GetRealData(PIdx::y).dataPtr() + a_offset;
243 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
244#elif defined(WARPX_DIM_1D_Z)
245 m_z = soa.GetRealData(PIdx::z).dataPtr() + a_offset;
246#elif defined(WARPX_DIM_RCYLINDER)
247 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
248 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
249#elif defined(WARPX_DIM_RSPHERE)
250 m_x = soa.GetRealData(PIdx::x).dataPtr() + a_offset;
251 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
252 m_phi = soa.GetRealData(T_PIdx::phi).dataPtr() + a_offset;
253#endif
254#if defined(WARPX_DIM_RZ)
255 m_theta = soa.GetRealData(T_PIdx::theta).dataPtr() + a_offset;
256#endif
257 }
258
262 void operator() (const long i, RType x, RType y, RType z) const noexcept
263 {
265#if defined(WARPX_DIM_RZ)
266 m_theta[i] = std::atan2(y, x);
267 m_x[i] = std::sqrt(x*x + y*y);
268 m_z[i] = z;
269#elif defined(WARPX_DIM_RCYLINDER)
270 m_theta[i] = std::atan2(y, x);
271 m_x[i] = std::sqrt(x*x + y*y);
272#elif defined(WARPX_DIM_RSPHERE)
273 RType const rxy = std::sqrt(x*x + y*y);
274 RType const r = std::sqrt(x*x + y*y + z*z);
275 m_x[i] = r;
276 m_theta[i] = std::atan2(y, x);
277 m_phi[i] = std::atan2(z, rxy);
278#elif defined(WARPX_DIM_3D)
279 m_x[i] = x;
280 m_y[i] = y;
281 m_z[i] = z;
282#elif defined(WARPX_DIM_XZ)
283 m_x[i] = x;
284 m_z[i] = z;
285#elif defined(WARPX_DIM_1D_Z)
286 m_z[i] = z;
287#endif
288 }
289
295 void AsStored (const long i, RType x, RType y, RType z) const noexcept
296 {
298#if defined(WARPX_DIM_RZ)
299 m_x[i] = x;
300 m_theta[i] = y;
301 m_z[i] = z;
302#elif defined(WARPX_DIM_RCYLINDER)
303 m_x[i] = x;
304 m_theta[i] = y;
305#elif defined(WARPX_DIM_RSPHERE)
306 m_x[i] = x;
307 m_theta[i] = y;
308 m_phi[i] = z;
309#elif defined(WARPX_DIM_3D)
310 m_x[i] = x;
311 m_y[i] = y;
312 m_z[i] = z;
313#elif defined(WARPX_DIM_XZ)
314 m_x[i] = x;
315 m_z[i] = z;
316#elif defined(WARPX_DIM_1D_Z)
317 m_z[i] = z;
318#endif
319 }
320};
321
322#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
__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:171
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:103
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:133
@ x
Definition WarpXParticleContainer.H:61
@ z
Definition WarpXParticleContainer.H:67
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:262
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:295
RType *AMREX_RESTRICT m_z
Definition GetAndSetPosition.H:219
SetParticlePosition(const ptiType &a_pti, long a_offset=0) noexcept
Definition GetAndSetPosition.H:234
RType *AMREX_RESTRICT m_theta
Definition GetAndSetPosition.H:227
amrex::ParticleReal RType
Definition GetAndSetPosition.H:211
RType *AMREX_RESTRICT m_x
Definition GetAndSetPosition.H:218