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 
12 
13 #include <AMReX.H>
14 #include <AMReX_REAL.H>
15 
16 #include <cmath>
17 #include <limits>
18 
22 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
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 #else
39  x = p.pos(0);
40  y = amrex::ParticleReal(0.0);
41  z = p.pos(1);
42 #endif
43 }
44 
49 {
51  using RType = amrex::ParticleReal;
52 
53  const PType* AMREX_RESTRICT m_structs = nullptr;
54 #if (defined WARPX_DIM_RZ)
55  const RType* m_theta = nullptr;
56 #elif (AMREX_SPACEDIM == 2)
57  static constexpr RType m_y_default = RType(0.0);
58 #endif
59 
60  GetParticlePosition () = default;
61 
69  template <typename ptiType>
70  GetParticlePosition (const ptiType& a_pti, int a_offset = 0) noexcept
71  {
72  const auto& aos = a_pti.GetArrayOfStructs();
73  m_structs = aos().dataPtr() + a_offset;
74 #if (defined WARPX_DIM_RZ)
75  const auto& soa = a_pti.GetStructOfArrays();
76  m_theta = soa.GetRealData(PIdx::theta).dataPtr() + a_offset;
77 #endif
78  }
79 
83  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
84  void operator() (const int i, RType& x, RType& y, RType& z) const noexcept
85  {
86  const PType& p = m_structs[i];
87 #ifdef WARPX_DIM_RZ
88  RType r = p.pos(0);
89  x = r*std::cos(m_theta[i]);
90  y = r*std::sin(m_theta[i]);
91  z = p.pos(1);
92 #elif WARPX_DIM_3D
93  x = p.pos(0);
94  y = p.pos(1);
95  z = p.pos(2);
96 #else
97  x = p.pos(0);
98  y = m_y_default;
99  z = p.pos(1);
100 #endif
101  }
102 
108  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
109  void AsStored (const int i, RType& x, RType& y, RType& z) const noexcept
110  {
111  const PType& p = m_structs[i];
112 #ifdef WARPX_DIM_RZ
113  x = p.pos(0);
114  y = m_theta[i];
115  z = p.pos(1);
116 #elif WARPX_DIM_3D
117  x = p.pos(0);
118  y = p.pos(1);
119  z = p.pos(2);
120 #else
121  x = p.pos(0);
122  y = m_y_default;
123  z = p.pos(1);
124 #endif
125  }
126 };
127 
135 {
137  using RType = amrex::ParticleReal;
138 
139  PType* AMREX_RESTRICT m_structs;
140 #if (defined WARPX_DIM_RZ)
141  RType* AMREX_RESTRICT m_theta;
142 #endif
143  SetParticlePosition (WarpXParIter& a_pti, int a_offset = 0) noexcept
144  {
145  auto& aos = a_pti.GetArrayOfStructs();
146  m_structs = aos().dataPtr() + a_offset;
147 #if (defined WARPX_DIM_RZ)
148  auto& soa = a_pti.GetStructOfArrays();
149  m_theta = soa.GetRealData(PIdx::theta).dataPtr() + a_offset;
150 #endif
151  }
152 
155  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
156  void operator() (const int i, RType x, RType y, RType z) const noexcept
157  {
158 #if defined(WARPX_DIM_XZ)
159  amrex::ignore_unused(y);
160 #endif
161 #ifdef WARPX_DIM_RZ
162  m_theta[i] = std::atan2(y, x);
163  m_structs[i].pos(0) = std::sqrt(x*x + y*y);
164  m_structs[i].pos(1) = z;
165 #elif WARPX_DIM_3D
166  m_structs[i].pos(0) = x;
167  m_structs[i].pos(1) = y;
168  m_structs[i].pos(2) = z;
169 #else
170  m_structs[i].pos(0) = x;
171  m_structs[i].pos(1) = z;
172 #endif
173  }
174 
179  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
180  void AsStored (const int i, RType x, RType y, RType z) const noexcept
181  {
182 #if defined(WARPX_DIM_XZ)
183  amrex::ignore_unused(y);
184 #endif
185 #ifdef WARPX_DIM_RZ
186  m_structs[i].pos(0) = x;
187  m_theta[i] = y;
188  m_structs[i].pos(1) = z;
189 #elif WARPX_DIM_3D
190  m_structs[i].pos(0) = x;
191  m_structs[i].pos(1) = y;
192  m_structs[i].pos(2) = z;
193 #else
194  m_structs[i].pos(0) = x;
195  m_structs[i].pos(1) = z;
196 #endif
197  }
198 };
199 
200 #endif // WARPX_PARTICLES_PUSHER_GETANDSETPOSITION_H_
Definition: WarpXParticleContainer_fwd.H:30
def x
Definition: read_lab_particles.py:25
GetParticlePosition()=default
WarpXParticleContainer::ParticleType PType
Definition: GetAndSetPosition.H:50
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 z
Definition: read_lab_particles.py:26
GetParticlePosition(const ptiType &a_pti, int a_offset=0) noexcept
Definition: GetAndSetPosition.H:70
const RType * m_theta
Definition: GetAndSetPosition.H:55
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:84
amrex::ParticleReal RType
Definition: GetAndSetPosition.H:51
i
Definition: check_interp_points_and_weights.py:171
PType *AMREX_RESTRICT m_structs
Definition: GetAndSetPosition.H:139
typename WarpXParticleContainer::SuperParticleType SuperParticleType
Definition: FilterFunctors.H:19
RType *AMREX_RESTRICT m_theta
Definition: GetAndSetPosition.H:141
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:180
WarpXParticleContainer::ParticleType ParticleType
Definition: ParticleUtils.cpp:29
amrex::ParticleReal RType
Definition: GetAndSetPosition.H:137
const PType *AMREX_RESTRICT m_structs
Definition: GetAndSetPosition.H:53
WarpXParticleContainer::ParticleType PType
Definition: GetAndSetPosition.H:136
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:109
Functor that can be used to extract the positions of the macroparticles inside a ParallelFor kernel...
Definition: GetAndSetPosition.H:48
Functor that can be used to modify the positions of the macroparticles, inside a ParallelFor kernel...
Definition: GetAndSetPosition.H:134
Definition: WarpXParticleContainer.H:58
SetParticlePosition(WarpXParIter &a_pti, int a_offset=0) noexcept
Definition: GetAndSetPosition.H:143