1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#ifndef WARPX_PARTICLES_PUSHER_GETANDSETPOSITION_H_
#define WARPX_PARTICLES_PUSHER_GETANDSETPOSITION_H_
#include <limits>
#include <WarpXParticleContainer.H>
#include <AMReX_REAL.H>
#ifndef WARPX_DIM_RZ
/** \brief Extract the particle's coordinates from the ParticleType struct `p`,
* and stores them in the variables `x`, `y`, `z`. */
AMREX_GPU_HOST_DEVICE AMREX_INLINE
void GetPosition(
amrex::ParticleReal& x, amrex::ParticleReal& y, amrex::ParticleReal& z,
const WarpXParticleContainer::ParticleType& p)
{
#if (AMREX_SPACEDIM==3)
x = p.pos(0);
y = p.pos(1);
z = p.pos(2);
#else
x = p.pos(0);
y = std::numeric_limits<amrex::ParticleReal>::quiet_NaN();
z = p.pos(1);
#endif
}
/** \brief Set the particle's coordinates in the ParticleType struct `p`,
* from their values in the variables `x`, `y`, `z`. */
AMREX_GPU_HOST_DEVICE AMREX_INLINE
void SetPosition(
WarpXParticleContainer::ParticleType& p,
const amrex::ParticleReal x, const amrex::ParticleReal y, const amrex::ParticleReal z)
{
#if (AMREX_SPACEDIM==3)
p.pos(0) = x;
p.pos(1) = y;
p.pos(2) = z;
#else
p.pos(0) = x;
p.pos(1) = z;
#endif
}
# elif defined WARPX_DIM_RZ
/** \brief Extract the particle's coordinates from `theta` and the attributes
* of the ParticleType struct `p` (which contains the radius),
* and store them in the variables `x`, `y`, `z` */
AMREX_GPU_HOST_DEVICE AMREX_INLINE
void GetCartesianPositionFromCylindrical(
amrex::ParticleReal& x, amrex::ParticleReal& y, amrex::ParticleReal& z,
const WarpXParticleContainer::ParticleType& p, const amrex::ParticleReal theta)
{
const amrex::ParticleReal r = p.pos(0);
x = r*std::cos(theta);
y = r*std::sin(theta);
z = p.pos(1);
}
/** \brief Set the particle's cylindrical coordinates by setting `theta`
* and the attributes of the ParticleType struct `p` (which stores the radius),
* from the values of `x`, `y`, `z` */
AMREX_GPU_HOST_DEVICE AMREX_INLINE
void SetCylindricalPositionFromCartesian(
WarpXParticleContainer::ParticleType& p, amrex::ParticleReal& theta,
const amrex::ParticleReal x, const amrex::ParticleReal y, const amrex::ParticleReal z )
{
theta = std::atan2(y, x);
p.pos(0) = std::sqrt(x*x + y*y);
p.pos(1) = z;
}
#endif // WARPX_DIM_RZ
#endif // WARPX_PARTICLES_PUSHER_GETANDSETPOSITION_H_
|