WarpX
Ionization.H
Go to the documentation of this file.
1 /* Copyright 2019-2020 Andrew Myers, Axel Huebl,
2  * Maxence Thevenet
3  *
4  * This file is part of WarpX.
5  *
6  * License: BSD-3-Clause-LBNL
7  */
8 #ifndef IONIZATION_H_
9 #define IONIZATION_H_
10 
15 #include "Utils/WarpXConst.H"
16 
17 #include <AMReX_Array.H>
18 #include <AMReX_Array4.H>
19 #include <AMReX_Dim3.H>
20 #include <AMReX_Extension.H>
21 #include <AMReX_GpuQualifiers.H>
22 #include <AMReX_IndexType.H>
23 #include <AMReX_REAL.H>
24 #include <AMReX_Random.H>
25 
26 #include <AMReX_BaseFwd.H>
27 
28 #include <cmath>
29 
31 {
32  const amrex::Real* AMREX_RESTRICT m_ionization_energies;
33  const amrex::Real* AMREX_RESTRICT m_adk_prefactor;
34  const amrex::Real* AMREX_RESTRICT m_adk_exp_prefactor;
35  const amrex::Real* AMREX_RESTRICT m_adk_power;
36 
37  int comp;
39 
43 
44  amrex::Array4<const amrex::Real> m_ex_arr;
45  amrex::Array4<const amrex::Real> m_ey_arr;
46  amrex::Array4<const amrex::Real> m_ez_arr;
47  amrex::Array4<const amrex::Real> m_bx_arr;
48  amrex::Array4<const amrex::Real> m_by_arr;
49  amrex::Array4<const amrex::Real> m_bz_arr;
50 
51  amrex::IndexType m_ex_type;
52  amrex::IndexType m_ey_type;
53  amrex::IndexType m_ez_type;
54  amrex::IndexType m_bx_type;
55  amrex::IndexType m_by_type;
56  amrex::IndexType m_bz_type;
57 
58  amrex::GpuArray<amrex::Real, 3> m_dx_arr;
59  amrex::GpuArray<amrex::Real, 3> m_xyzmin_arr;
60 
62  int m_nox;
64 
65  amrex::Dim3 m_lo;
66 
67  IonizationFilterFunc (const WarpXParIter& a_pti, int lev, amrex::IntVect ngE,
68  amrex::FArrayBox const& exfab,
69  amrex::FArrayBox const& eyfab,
70  amrex::FArrayBox const& ezfab,
71  amrex::FArrayBox const& bxfab,
72  amrex::FArrayBox const& byfab,
73  amrex::FArrayBox const& bzfab,
74  amrex::Array<amrex::Real,3> v_galilean,
75  const amrex::Real* const AMREX_RESTRICT a_ionization_energies,
76  const amrex::Real* const AMREX_RESTRICT a_adk_prefactor,
77  const amrex::Real* const AMREX_RESTRICT a_adk_exp_prefactor,
78  const amrex::Real* const AMREX_RESTRICT a_adk_power,
79  int a_comp,
80  int a_atomic_number,
81  int a_offset = 0) noexcept;
82 
83  template <typename PData>
84  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
85  bool operator() (const PData& ptd, int i, amrex::RandomEngine const& engine) const noexcept
86  {
87  using namespace amrex::literals;
88 
89  const int ion_lev = ptd.m_runtime_idata[comp][i];
90  if (ion_lev < m_atomic_number)
91  {
92  constexpr amrex::Real c = PhysConst::c;
93  constexpr amrex::Real c2_inv = amrex::Real(1.)/c/c;
94 
95  // gather E and B
96  amrex::ParticleReal xp, yp, zp;
97  m_get_position(i, xp, yp, zp);
98 
99  amrex::ParticleReal ex = 0._rt, ey = 0._rt, ez = 0._rt;
100  m_get_externalE(i, ex, ey, ez);
101 
102  amrex::ParticleReal bx = 0._rt, by = 0._rt, bz = 0._rt;
103  m_get_externalB(i, bx, by, bz);
104 
105  doGatherShapeN(xp, yp, zp, ex, ey, ez, bx, by, bz,
106  m_ex_arr, m_ey_arr, m_ez_arr, m_bx_arr, m_by_arr, m_bz_arr,
107  m_ex_type, m_ey_type, m_ez_type, m_bx_type, m_by_type, m_bz_type,
108  m_dx_arr, m_xyzmin_arr, m_lo, m_n_rz_azimuthal_modes,
109  m_nox, m_galerkin_interpolation);
110 
111  // Compute electric field amplitude in the particle's frame of
112  // reference (particularly important when in boosted frame).
113  amrex::ParticleReal ux = ptd.m_rdata[PIdx::ux][i];
114  amrex::ParticleReal uy = ptd.m_rdata[PIdx::uy][i];
115  amrex::ParticleReal uz = ptd.m_rdata[PIdx::uz][i];
116 
117  amrex::Real ga = static_cast<amrex::Real>(
118  std::sqrt(1. + (ux*ux + uy*uy + uz*uz) * c2_inv));
119  amrex::Real E = std::sqrt(
120  - ( ux*ex + uy*ey + uz*ez ) * ( ux*ex + uy*ey + uz*ez ) * c2_inv
121  + ( ga *ex + uy*bz - uz*by ) * ( ga *ex + uy*bz - uz*by )
122  + ( ga *ey + uz*bx - ux*bz ) * ( ga *ey + uz*bx - ux*bz )
123  + ( ga *ez + ux*by - uy*bx ) * ( ga *ez + ux*by - uy*bx )
124  );
125 
126  // Compute probability of ionization p
127  amrex::Real w_dtau = (E == 0._rt) ? 0._rt : 1._rt/ ga * m_adk_prefactor[ion_lev] *
128  std::pow(E, m_adk_power[ion_lev]) *
129  std::exp( m_adk_exp_prefactor[ion_lev]/E );
130  amrex::Real p = 1._rt - std::exp( - w_dtau );
131 
132  amrex::Real random_draw = amrex::Random(engine);
133  if (random_draw < p)
134  {
135  return true;
136  }
137  }
138  return false;
139  }
140 };
141 
143 {
144  template <typename DstData, typename SrcData>
145  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
146  void operator() (DstData& /*dst*/, SrcData& src,
147  int i_src, int /*i_dst*/,
148  amrex::RandomEngine const& /*engine*/) const noexcept
149  {
150  src.m_runtime_idata[0][i_src] += 1;
151  }
152 };
153 
154 #endif
Definition: Ionization.H:30
amrex::Array4< const amrex::Real > m_ex_arr
Definition: Ionization.H:44
int m_n_rz_azimuthal_modes
Definition: Ionization.H:63
const amrex::Real *AMREX_RESTRICT m_ionization_energies
Definition: Ionization.H:32
Definition: WarpXParticleContainer_fwd.H:28
const amrex::Real *AMREX_RESTRICT m_adk_exp_prefactor
Definition: Ionization.H:34
Definition: Ionization.H:142
int m_atomic_number
Definition: Ionization.H:38
amrex::IndexType m_ey_type
Definition: Ionization.H:52
int comp
Definition: Ionization.H:37
Definition: WarpXParticleContainer_fwd.H:28
def uz
Definition: read_lab_particles.py:29
bool m_galerkin_interpolation
Definition: Ionization.H:61
amrex::GpuArray< amrex::Real, 3 > m_xyzmin_arr
Definition: Ionization.H:59
amrex::Array4< const amrex::Real > m_ey_arr
Definition: Ionization.H:45
GetExternalBField m_get_externalB
Definition: Ionization.H:42
Functor that can be used to assign the external B field to a particle inside a ParallelFor kernel...
Definition: GetExternalFields.H:159
amrex::Array4< const amrex::Real > m_bz_arr
Definition: Ionization.H:49
Definition: WarpXParticleContainer_fwd.H:28
amrex::Array4< const amrex::Real > m_bx_arr
Definition: Ionization.H:47
i
Definition: check_interp_points_and_weights.py:171
int m_nox
Definition: Ionization.H:62
const amrex::Real *AMREX_RESTRICT m_adk_prefactor
Definition: Ionization.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool operator()(const PData &ptd, int i, amrex::RandomEngine const &engine) const noexcept
Definition: Ionization.H:85
amrex::IndexType m_bx_type
Definition: Ionization.H:54
GetParticlePosition m_get_position
Definition: Ionization.H:40
amrex::Dim3 m_lo
Definition: Ionization.H:65
IonizationFilterFunc(const WarpXParIter &a_pti, int lev, amrex::IntVect ngE, amrex::FArrayBox const &exfab, amrex::FArrayBox const &eyfab, amrex::FArrayBox const &ezfab, amrex::FArrayBox const &bxfab, amrex::FArrayBox const &byfab, amrex::FArrayBox const &bzfab, amrex::Array< amrex::Real, 3 > v_galilean, const amrex::Real *const AMREX_RESTRICT a_ionization_energies, const amrex::Real *const AMREX_RESTRICT a_adk_prefactor, const amrex::Real *const AMREX_RESTRICT a_adk_exp_prefactor, const amrex::Real *const AMREX_RESTRICT a_adk_power, int a_comp, int a_atomic_number, int a_offset=0) noexcept
Definition: Ionization.cpp:20
amrex::Array4< const amrex::Real > m_by_arr
Definition: Ionization.H:48
GetExternalEField m_get_externalE
Definition: Ionization.H:41
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void doGatherShapeN(const amrex::ParticleReal xp, const amrex::ParticleReal yp, const amrex::ParticleReal zp, amrex::ParticleReal &Exp, amrex::ParticleReal &Eyp, amrex::ParticleReal &Ezp, amrex::ParticleReal &Bxp, amrex::ParticleReal &Byp, amrex::ParticleReal &Bzp, amrex::Array4< amrex::Real const > const &ex_arr, amrex::Array4< amrex::Real const > const &ey_arr, amrex::Array4< amrex::Real const > const &ez_arr, amrex::Array4< amrex::Real const > const &bx_arr, amrex::Array4< amrex::Real const > const &by_arr, amrex::Array4< amrex::Real const > const &bz_arr, const amrex::IndexType ex_type, const amrex::IndexType ey_type, const amrex::IndexType ez_type, const amrex::IndexType bx_type, const amrex::IndexType by_type, const amrex::IndexType bz_type, const amrex::GpuArray< amrex::Real, 3 > &dx, const amrex::GpuArray< amrex::Real, 3 > &xyzmin, const amrex::Dim3 &lo, const int n_rz_azimuthal_modes)
Field gather for a single particle.
Definition: FieldGather.H:38
amrex::IndexType m_bz_type
Definition: Ionization.H:56
amrex::IndexType m_ex_type
Definition: Ionization.H:51
Functor that can be used to extract the positions of the macroparticles inside a ParallelFor kernel...
Definition: GetAndSetPosition.H:48
amrex::Array4< const amrex::Real > m_ez_arr
Definition: Ionization.H:46
def ux
Definition: read_lab_particles.py:28
amrex::IndexType m_ez_type
Definition: Ionization.H:53
Definition: WarpXParticleContainer.H:58
Functor that can be used to assign the external E field to a particle inside a ParallelFor kernel...
Definition: GetExternalFields.H:149
Definition: BreitWheelerEngineWrapper.H:35
const amrex::Real *AMREX_RESTRICT m_adk_power
Definition: Ionization.H:35
amrex::IndexType m_by_type
Definition: Ionization.H:55
amrex::GpuArray< amrex::Real, 3 > m_dx_arr
Definition: Ionization.H:58