ARTEMIS
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 
24  amrex::ParticleReal& x,
25  amrex::ParticleReal& y,
26  amrex::ParticleReal& z) noexcept
27 {
28 #ifdef WARPX_DIM_RZ
29  amrex::ParticleReal theta = p.rdata(PIdx::theta);
30  amrex::ParticleReal r = p.pos(0);
31  x = r*std::cos(theta);
32  y = r*std::sin(theta);
33  z = p.pos(1);
34 #elif WARPX_DIM_3D
35  x = p.pos(0);
36  y = p.pos(1);
37  z = p.pos(2);
38 #elif WARPX_DIM_XZ
39  x = p.pos(0);
40  y = amrex::ParticleReal(0.0);
41  z = p.pos(1);
42 #else
43  x = amrex::ParticleReal(0.0);
44  y = amrex::ParticleReal(0.0);
45  z = p.pos(0);
46 #endif
47 }
48 
53 {
55  using RType = amrex::ParticleReal;
56 
57  const PType* AMREX_RESTRICT m_structs = nullptr;
58 #if defined(WARPX_DIM_RZ)
59  const RType* m_theta = nullptr;
60 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
61  static constexpr RType m_y_default = RType(0.0);
62 #elif defined(WARPX_DIM_1D_Z)
63  static constexpr RType m_x_default = RType(0.0);
64  static constexpr RType m_y_default = RType(0.0);
65 #endif
66 
67  GetParticlePosition () = default;
68 
76  template <typename ptiType>
77  GetParticlePosition (const ptiType& a_pti, int a_offset = 0) noexcept
78  {
79  const auto& aos = a_pti.GetArrayOfStructs();
80  m_structs = aos().dataPtr() + a_offset;
81 #if defined(WARPX_DIM_RZ)
82  const auto& soa = a_pti.GetStructOfArrays();
83  m_theta = soa.GetRealData(PIdx::theta).dataPtr() + a_offset;
84 #endif
85  }
86 
91  void operator() (const int i, RType& x, RType& y, RType& z) const noexcept
92  {
93  const PType& p = m_structs[i];
94 #ifdef WARPX_DIM_RZ
95  RType r = p.pos(0);
96  x = r*std::cos(m_theta[i]);
97  y = r*std::sin(m_theta[i]);
98  z = p.pos(1);
99 #elif WARPX_DIM_3D
100  x = p.pos(0);
101  y = p.pos(1);
102  z = p.pos(2);
103 #elif WARPX_DIM_XZ
104  x = p.pos(0);
105  y = m_y_default;
106  z = p.pos(1);
107 #else
108  x = m_x_default;
109  y = m_y_default;
110  z = p.pos(0);
111 #endif
112  }
113 
120  void AsStored (const int i, RType& x, RType& y, RType& z) const noexcept
121  {
122  const PType& p = m_structs[i];
123 #ifdef WARPX_DIM_RZ
124  x = p.pos(0);
125  y = m_theta[i];
126  z = p.pos(1);
127 #elif WARPX_DIM_3D
128  x = p.pos(0);
129  y = p.pos(1);
130  z = p.pos(2);
131 #elif WARPX_DIM_XZ
132  x = p.pos(0);
133  y = m_y_default;
134  z = p.pos(1);
135 #else
136  x = m_x_default;
137  y = m_y_default;
138  z = p.pos(0);
139 #endif
140  }
141 };
142 
150 {
152  using RType = amrex::ParticleReal;
153 
155 #if defined(WARPX_DIM_RZ)
157 #endif
158 
159  template <typename ptiType>
160  SetParticlePosition (const ptiType& a_pti, int a_offset = 0) noexcept
161  {
162  auto& aos = a_pti.GetArrayOfStructs();
163  m_structs = aos().dataPtr() + a_offset;
164 #if defined(WARPX_DIM_RZ)
165  auto& soa = a_pti.GetStructOfArrays();
166  m_theta = soa.GetRealData(PIdx::theta).dataPtr() + a_offset;
167 #endif
168  }
169 
173  void operator() (const int i, RType x, RType y, RType z) const noexcept
174  {
175 #if defined(WARPX_DIM_XZ)
177 #endif
178 #if defined(WARPX_DIM_1D_Z)
180 #endif
181 #ifdef WARPX_DIM_RZ
182  m_theta[i] = std::atan2(y, x);
183  m_structs[i].pos(0) = std::sqrt(x*x + y*y);
184  m_structs[i].pos(1) = z;
185 #elif WARPX_DIM_3D
186  m_structs[i].pos(0) = x;
187  m_structs[i].pos(1) = y;
188  m_structs[i].pos(2) = z;
189 #elif WARPX_DIM_XZ
190  m_structs[i].pos(0) = x;
191  m_structs[i].pos(1) = z;
192 #else
193  m_structs[i].pos(0) = z;
194 #endif
195  }
196 
202  void AsStored (const int i, RType x, RType y, RType z) const noexcept
203  {
204 #if defined(WARPX_DIM_XZ)
206 #endif
207 #if defined(WARPX_DIM_1D_Z)
209 #endif
210 #ifdef WARPX_DIM_RZ
211  m_structs[i].pos(0) = x;
212  m_theta[i] = y;
213  m_structs[i].pos(1) = z;
214 #elif WARPX_DIM_3D
215  m_structs[i].pos(0) = x;
216  m_structs[i].pos(1) = y;
217  m_structs[i].pos(2) = z;
218 #elif WARPX_DIM_XZ
219  m_structs[i].pos(0) = x;
220  m_structs[i].pos(1) = z;
221 #else
222  m_structs[i].pos(0) = z;
223 #endif
224  }
225 };
226 
227 #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:23
def y
Definition: Excitation_Flag_Generator.py:76
def x
Formats datastring to remove "+" at the end of the string #####.
Definition: Excitation_Flag_Generator.py:75
def z
Definition: Excitation_Flag_Generator.py:77
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:53
GetParticlePosition(const ptiType &a_pti, int a_offset=0) noexcept
Definition: GetAndSetPosition.H:77
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(const int 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:91
const PType *AMREX_RESTRICT m_structs
Definition: GetAndSetPosition.H:57
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void AsStored(const int 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:120
GetParticlePosition()=default
const RType * m_theta
Definition: GetAndSetPosition.H:59
amrex::ParticleReal RType
Definition: GetAndSetPosition.H:55
WarpXParticleContainer::ParticleType PType
Definition: GetAndSetPosition.H:54
@ theta
RZ needs all three position components.
Definition: NamedComponentParticleContainer.H:27
Functor that can be used to modify the positions of the macroparticles, inside a ParallelFor kernel.
Definition: GetAndSetPosition.H:150
WarpXParticleContainer::ParticleType PType
Definition: GetAndSetPosition.H:151
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void AsStored(const int 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:202
PType *AMREX_RESTRICT m_structs
Definition: GetAndSetPosition.H:154
RType *AMREX_RESTRICT m_theta
Definition: GetAndSetPosition.H:156
SetParticlePosition(const ptiType &a_pti, int a_offset=0) noexcept
Definition: GetAndSetPosition.H:160
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(const int 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:173
amrex::ParticleReal RType
Definition: GetAndSetPosition.H:152