WarpX
ParticleUtils.H
Go to the documentation of this file.
1 /* Copyright 2019-2020 Neil Zaim, Yinjian Zhao
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef WARPX_PARTICLE_UTILS_H_
8 #define WARPX_PARTICLE_UTILS_H_
9 
11 
12 #include <AMReX_DenseBins.H>
13 #include <AMReX_Particles.H>
14 
15 #include <AMReX_BaseFwd.H>
16 
17 namespace ParticleUtils {
18 
30  amrex::DenseBins<WarpXParticleContainer::ParticleType>
31  findParticlesInEachCell( int const lev, amrex::MFIter const& mfi,
33 
43  AMREX_GPU_HOST_DEVICE AMREX_INLINE
44  void getRandomVector ( amrex::Real& x, amrex::Real& y, amrex::Real& z,
45  amrex::RandomEngine const& engine )
46  {
47  using std::sqrt;
48  using std::cos;
49  using std::sin;
50  using namespace amrex::literals;
51 
52  amrex::Real const theta = amrex::Random(engine) * 2.0_rt * MathConst::pi;
53  z = 2.0_rt * amrex::Random(engine) - 1.0_rt;
54  amrex::Real const xy = sqrt(1_rt - z*z);
55  x = xy * cos(theta);
56  y = xy * sin(theta);
57  }
58 
59 
66  AMREX_GPU_HOST_DEVICE AMREX_INLINE
67  void RandomizeVelocity ( amrex::ParticleReal& ux, amrex::ParticleReal& uy,
68  amrex::ParticleReal& uz,
69  const amrex::ParticleReal vp,
70  amrex::RandomEngine const& engine )
71  {
72  amrex::Real x, y, z;
73  // generate random unit vector for the new velocity direction
74  getRandomVector(x, y, z, engine);
75 
76  // scale new vector to have the desired magnitude
77  ux = x * vp;
78  uy = y * vp;
79  uz = z * vp;
80  }
81 }
82 
83 #endif // WARPX_PARTICLE_UTILS_H_
def x
Definition: read_lab_particles.py:25
AMREX_GPU_HOST_DEVICE AMREX_INLINE void RandomizeVelocity(amrex::ParticleReal &ux, amrex::ParticleReal &uy, amrex::ParticleReal &uz, const amrex::ParticleReal vp, amrex::RandomEngine const &engine)
Function to perform scattering of a particle that results in a random velocity vector with given magn...
Definition: ParticleUtils.H:67
WarpXParticleContainer::ParticleTileType ParticleTileType
Definition: ParticleUtils.cpp:30
AMREX_GPU_HOST_DEVICE AMREX_INLINE void getRandomVector(amrex::Real &x, amrex::Real &y, amrex::Real &z, amrex::RandomEngine const &engine)
Generate random unit vector in 3 dimensions https://mathworld.wolfram.com/SpherePointPicking.html.
Definition: ParticleUtils.H:44
def uz
Definition: read_lab_particles.py:29
def z
Definition: read_lab_particles.py:26
ParticleBins findParticlesInEachCell(int const lev, MFIter const &mfi, ParticleTileType const &ptile)
Definition: ParticleUtils.cpp:37
Definition: ParticleUtils.cpp:25
def ux
Definition: read_lab_particles.py:28