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 <limits>
17 
18 
26 {
28  using RType = amrex::ParticleReal;
29 
30  const PType* AMREX_RESTRICT m_structs = nullptr;
31 #if (defined WARPX_DIM_RZ)
32  const RType* m_theta = nullptr;
33 #elif (AMREX_SPACEDIM == 2)
34  static constexpr RType m_snan = std::numeric_limits<RType>::quiet_NaN();
35 #endif
36 
37  GetParticlePosition () = default;
38 
39  GetParticlePosition (const WarpXParIter& a_pti, int a_offset = 0) noexcept
40  {
41  const auto& aos = a_pti.GetArrayOfStructs();
42  m_structs = aos().dataPtr() + a_offset;
43 #if (defined WARPX_DIM_RZ)
44  const auto& soa = a_pti.GetStructOfArrays();
45  m_theta = soa.GetRealData(PIdx::theta).dataPtr() + a_offset;
46 #endif
47  }
48 
52  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
53  void operator() (const int i, RType& x, RType& y, RType& z) const noexcept
54  {
55 #ifdef WARPX_DIM_RZ
56  RType r = m_structs[i].pos(0);
57  x = r*std::cos(m_theta[i]);
58  y = r*std::sin(m_theta[i]);
59  z = m_structs[i].pos(1);
60 #elif WARPX_DIM_3D
61  x = m_structs[i].pos(0);
62  y = m_structs[i].pos(1);
63  z = m_structs[i].pos(2);
64 #else
65  x = m_structs[i].pos(0);
66  y = m_snan;
67  z = m_structs[i].pos(1);
68 #endif
69  }
70 };
71 
79 {
81  using RType = amrex::ParticleReal;
82 
83  PType* AMREX_RESTRICT m_structs;
84 #if (defined WARPX_DIM_RZ)
85  RType* AMREX_RESTRICT m_theta;
86 #endif
87  SetParticlePosition (WarpXParIter& a_pti, int a_offset = 0) noexcept
88  {
89  auto& aos = a_pti.GetArrayOfStructs();
90  m_structs = aos().dataPtr() + a_offset;
91 #if (defined WARPX_DIM_RZ)
92  auto& soa = a_pti.GetStructOfArrays();
93  m_theta = soa.GetRealData(PIdx::theta).dataPtr() + a_offset;
94 #endif
95  }
96 
99  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
100  void operator() (const int i, RType x, RType y, RType z) const noexcept
101  {
102 #if defined(WARPX_DIM_XZ)
103  amrex::ignore_unused(y);
104 #endif
105 #ifdef WARPX_DIM_RZ
106  m_theta[i] = std::atan2(y, x);
107  m_structs[i].pos(0) = std::sqrt(x*x + y*y);
108  m_structs[i].pos(1) = z;
109 #elif WARPX_DIM_3D
110  m_structs[i].pos(0) = x;
111  m_structs[i].pos(1) = y;
112  m_structs[i].pos(2) = z;
113 #else
114  m_structs[i].pos(0) = x;
115  m_structs[i].pos(1) = z;
116 #endif
117  }
118 };
119 
120 #endif // WARPX_PARTICLES_PUSHER_GETANDSETPOSITION_H_
GetParticlePosition(const WarpXParIter &a_pti, int a_offset=0) noexcept
Definition: GetAndSetPosition.H:39
def x
Definition: read_lab_particles.py:25
GetParticlePosition()=default
WarpXParticleContainer::ParticleType PType
Definition: GetAndSetPosition.H:27
def z
Definition: read_lab_particles.py:26
const RType * m_theta
Definition: GetAndSetPosition.H:32
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:53
amrex::ParticleReal RType
Definition: GetAndSetPosition.H:28
i
Definition: check_interp_points_and_weights.py:171
PType *AMREX_RESTRICT m_structs
Definition: GetAndSetPosition.H:83
RType *AMREX_RESTRICT m_theta
Definition: GetAndSetPosition.H:85
amrex::ParticleReal RType
Definition: GetAndSetPosition.H:81
const PType *AMREX_RESTRICT m_structs
Definition: GetAndSetPosition.H:30
Definition: WarpXParticleContainer.H:39
WarpXParticleContainer::ParticleType PType
Definition: GetAndSetPosition.H:80
Functor that can be used to extract the positions of the macroparticles inside a ParallelFor kernel...
Definition: GetAndSetPosition.H:25
Functor that can be used to modify the positions of the macroparticles, inside a ParallelFor kernel...
Definition: GetAndSetPosition.H:78
Definition: WarpXParticleContainer.H:76
WarpXParticleContainer::ParticleType ParticleType
Definition: CollisionType.cpp:46
SetParticlePosition(WarpXParIter &a_pti, int a_offset=0) noexcept
Definition: GetAndSetPosition.H:87