WarpX
ParticleBoundaries_K.H
Go to the documentation of this file.
1 /* Copyright 2021 David Grote
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef PARTICLEBOUNDARIES_K_H_
8 #define PARTICLEBOUNDARIES_K_H_
9 
10 #include "ParticleBoundaries.H"
11 
12 #include <AMReX_AmrCore.H>
13 
15 
16  /* \brief Applies the boundary condition on a specific axis
17  * This is called by apply_boundaries.
18  */
20  void
21  apply_boundary (amrex::ParticleReal& x, amrex::Real xmin, amrex::Real xmax,
22  bool& change_sign_ux, bool& particle_lost,
24  amrex::Real refl_probability_xmin, amrex::Real refl_probability_xmax,
25  amrex::RandomEngine const& engine )
26  {
27  if (x < xmin) {
28  if (xmin_bc == ParticleBoundaryType::Open) {
29  particle_lost = true;
30  }
31  else if (xmin_bc == ParticleBoundaryType::Absorbing) {
32  if (refl_probability_xmin == 0 || amrex::Random(engine) > refl_probability_xmin) {
33  particle_lost = true;
34  }
35  else
36  {
37  x = 2*xmin - x;
38  change_sign_ux = true;
39  }
40  }
41  else if (xmin_bc == ParticleBoundaryType::Reflecting) {
42  x = 2*xmin - x;
43  change_sign_ux = true;
44  }
45  }
46  else if (x > xmax) {
47  if (xmax_bc == ParticleBoundaryType::Open) {
48  particle_lost = true;
49  }
50  else if (xmax_bc == ParticleBoundaryType::Absorbing) {
51  if (refl_probability_xmax == 0 || amrex::Random(engine) > refl_probability_xmax) {
52  particle_lost = true;
53  }
54  else
55  {
56  x = 2*xmax - x;
57  change_sign_ux = true;
58  }
59  }
60  else if (xmax_bc == ParticleBoundaryType::Reflecting) {
61  x = 2*xmax - x;
62  change_sign_ux = true;
63  }
64  }
65  }
66 
67  /* \brief Applies absorbing or reflecting boundary condition to the input particles, along all axis.
68  * For reflecting boundaries, the position of the particle is changed appropriately and
69  * the sign of the velocity is changed (depending on the reflect_all_velocities flag).
70  * For absorbing, a flag is set whether the particle has been lost (it is up to the calling
71  * code to take appropriate action to remove any lost particles). Absorbing boundaries can
72  * be given a reflection coefficient for stochastic reflection of particles, this
73  * coefficient is zero by default.
74  * Note that periodic boundaries are handled in AMReX code.
75  *
76  * \param x, xmin, xmax: particle x position, location of x boundary
77  * \param y, ymin, ymax: particle y position, location of y boundary (3D only)
78  * \param z, zmin, zmax: particle z position, location of z boundary
79  * \param ux, uy, uz: particle momenta
80  * \param particle_lost: output, flags whether the particle was lost
81  * \param boundaries: object with boundary condition settings
82  */
84  void
86 #ifndef WARPX_DIM_1D_Z
87  amrex::ParticleReal& x, amrex::Real xmin, amrex::Real xmax,
88 #endif
89 #ifdef WARPX_DIM_3D
90  amrex::ParticleReal& y, amrex::Real ymin, amrex::Real ymax,
91 #endif
92  amrex::ParticleReal& z, amrex::Real zmin, amrex::Real zmax,
93  amrex::ParticleReal& ux, amrex::ParticleReal& uy, amrex::ParticleReal& uz,
94  bool& particle_lost,
96  amrex::RandomEngine const& engine)
97  {
98  bool change_sign_ux = false;
99  bool change_sign_uy = false;
100  bool change_sign_uz = false;
101 
102 #ifndef WARPX_DIM_1D_Z
103  apply_boundary(x, xmin, xmax, change_sign_ux, particle_lost,
104  boundaries.xmin_bc, boundaries.xmax_bc,
105  boundaries.reflection_model_xlo(-ux), boundaries.reflection_model_xhi(ux),
106  engine);
107 #endif
108 #ifdef WARPX_DIM_3D
109  apply_boundary(y, ymin, ymax, change_sign_uy, particle_lost,
110  boundaries.ymin_bc, boundaries.ymax_bc,
111  boundaries.reflection_model_ylo(-uy), boundaries.reflection_model_yhi(uy),
112  engine);
113 #endif
114  apply_boundary(z, zmin, zmax, change_sign_uz, particle_lost,
115  boundaries.zmin_bc, boundaries.zmax_bc,
116  boundaries.reflection_model_zlo(-uz), boundaries.reflection_model_zhi(uz),
117  engine);
118 
119  if (boundaries.reflect_all_velocities && (change_sign_ux | change_sign_uy | change_sign_uz)) {
120  change_sign_ux = true;
121  change_sign_uy = true;
122  change_sign_uz = true;
123  }
124  if (change_sign_ux) ux = -ux;
125  if (change_sign_uy) uy = -uy;
126  if (change_sign_uz) uz = -uz;
127  }
128 
129 }
130 #endif
ParticleBoundaryType zmax_bc
Definition: ParticleBoundaries.H:56
particles are reflected
particles cross domain boundary leave with damped j
Definition: ParticleBoundaries_K.H:14
ParticleBoundaryType xmax_bc
Definition: ParticleBoundaries.H:52
amrex::ParserExecutor< 1 > reflection_model_yhi
Definition: ParticleBoundaries.H:61
particles crossing domain boundary are removed
Real Random()
bool reflect_all_velocities
Definition: ParticleBoundaries.H:65
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void apply_boundary(amrex::ParticleReal &x, amrex::Real xmin, amrex::Real xmax, bool &change_sign_ux, bool &particle_lost, ParticleBoundaryType xmin_bc, ParticleBoundaryType xmax_bc, amrex::Real refl_probability_xmin, amrex::Real refl_probability_xmax, amrex::RandomEngine const &engine)
Definition: ParticleBoundaries_K.H:21
amrex::ParserExecutor< 1 > reflection_model_xlo
Definition: ParticleBoundaries.H:58
ParticleBoundaryType ymin_bc
Definition: ParticleBoundaries.H:53
Definition: ParticleBoundaries.H:49
#define AMREX_FORCE_INLINE
ParticleBoundaryType xmin_bc
Definition: ParticleBoundaries.H:51
#define AMREX_GPU_HOST_DEVICE
amrex::ParserExecutor< 1 > reflection_model_zhi
Definition: ParticleBoundaries.H:63
amrex::ParserExecutor< 1 > reflection_model_ylo
Definition: ParticleBoundaries.H:60
amrex::ParserExecutor< 1 > reflection_model_xhi
Definition: ParticleBoundaries.H:59
ParticleBoundaryType ymax_bc
Definition: ParticleBoundaries.H:54
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void apply_boundaries(amrex::ParticleReal &x, amrex::Real xmin, amrex::Real xmax, amrex::ParticleReal &z, amrex::Real zmin, amrex::Real zmax, amrex::ParticleReal &ux, amrex::ParticleReal &uy, amrex::ParticleReal &uz, bool &particle_lost, ParticleBoundaries::ParticleBoundariesData const &boundaries, amrex::RandomEngine const &engine)
Definition: ParticleBoundaries_K.H:85
amrex::ParserExecutor< 1 > reflection_model_zlo
Definition: ParticleBoundaries.H:62
ParticleBoundaryType zmin_bc
Definition: ParticleBoundaries.H:55
ParticleBoundaryType
Definition: WarpXAlgorithmSelection.H:147