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 
11 #include "Utils/WarpXConst.H"
16 
18 {
19  const amrex::Real* AMREX_RESTRICT m_ionization_energies;
20  const amrex::Real* AMREX_RESTRICT m_adk_prefactor;
21  const amrex::Real* AMREX_RESTRICT m_adk_exp_prefactor;
22  const amrex::Real* AMREX_RESTRICT m_adk_power;
23 
24  int comp;
26 
30 
31  amrex::Array4<const amrex::Real> m_ex_arr;
32  amrex::Array4<const amrex::Real> m_ey_arr;
33  amrex::Array4<const amrex::Real> m_ez_arr;
34  amrex::Array4<const amrex::Real> m_bx_arr;
35  amrex::Array4<const amrex::Real> m_by_arr;
36  amrex::Array4<const amrex::Real> m_bz_arr;
37 
38  amrex::IndexType m_ex_type;
39  amrex::IndexType m_ey_type;
40  amrex::IndexType m_ez_type;
41  amrex::IndexType m_bx_type;
42  amrex::IndexType m_by_type;
43  amrex::IndexType m_bz_type;
44 
45  amrex::GpuArray<amrex::Real, 3> m_dx_arr;
46  amrex::GpuArray<amrex::Real, 3> m_xyzmin_arr;
47 
49  int m_nox;
51 
52  amrex::Dim3 m_lo;
53 
54  IonizationFilterFunc (const WarpXParIter& a_pti, int lev, int ngE,
55  amrex::FArrayBox const& exfab,
56  amrex::FArrayBox const& eyfab,
57  amrex::FArrayBox const& ezfab,
58  amrex::FArrayBox const& bxfab,
59  amrex::FArrayBox const& byfab,
60  amrex::FArrayBox const& bzfab,
61  amrex::Array<amrex::Real,3> v_galilean,
62  const amrex::Real* const AMREX_RESTRICT a_ionization_energies,
63  const amrex::Real* const AMREX_RESTRICT a_adk_prefactor,
64  const amrex::Real* const AMREX_RESTRICT a_adk_exp_prefactor,
65  const amrex::Real* const AMREX_RESTRICT a_adk_power,
66  int a_comp,
67  int a_atomic_number,
68  int a_offset = 0) noexcept;
69 
70  template <typename PData>
71  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
72  bool operator() (const PData& ptd, int i, amrex::RandomEngine const& engine) const noexcept
73  {
74  using namespace amrex::literals;
75 
76  const int ion_lev = ptd.m_runtime_idata[comp][i];
77  if (ion_lev < m_atomic_number)
78  {
79  constexpr amrex::Real c = PhysConst::c;
80  constexpr amrex::Real c2_inv = 1./c/c;
81 
82  // gather E and B
83  amrex::ParticleReal xp, yp, zp;
84  m_get_position(i, xp, yp, zp);
85 
86  amrex::ParticleReal ex = 0._rt, ey = 0._rt, ez = 0._rt;
87  m_get_externalE(i, ex, ey, ez);
88 
89  amrex::ParticleReal bx = 0._rt, by = 0._rt, bz = 0._rt;
90  m_get_externalB(i, bx, by, bz);
91 
92  doGatherShapeN(xp, yp, zp, ex, ey, ez, bx, by, bz,
93  m_ex_arr, m_ey_arr, m_ez_arr, m_bx_arr, m_by_arr, m_bz_arr,
94  m_ex_type, m_ey_type, m_ez_type, m_bx_type, m_by_type, m_bz_type,
95  m_dx_arr, m_xyzmin_arr, m_lo, m_n_rz_azimuthal_modes,
96  m_nox, m_galerkin_interpolation);
97 
98  // Compute electric field amplitude in the particle's frame of
99  // reference (particularly important when in boosted frame).
100  amrex::ParticleReal ux = ptd.m_rdata[PIdx::ux][i];
101  amrex::ParticleReal uy = ptd.m_rdata[PIdx::uy][i];
102  amrex::ParticleReal uz = ptd.m_rdata[PIdx::uz][i];
103 
104  amrex::Real ga = std::sqrt(1. + (ux*ux + uy*uy + uz*uz) * c2_inv);
105  amrex::Real E = std::sqrt(
106  - ( ux*ex + uy*ey + uz*ez ) * ( ux*ex + uy*ey + uz*ez ) * c2_inv
107  + ( ga *ex + uy*bz - uz*by ) * ( ga *ex + uy*bz - uz*by )
108  + ( ga *ey + uz*bx - ux*bz ) * ( ga *ey + uz*bx - ux*bz )
109  + ( ga *ez + ux*by - uy*bx ) * ( ga *ez + ux*by - uy*bx )
110  );
111 
112  // Compute probability of ionization p
113  amrex::Real w_dtau = 1./ ga * m_adk_prefactor[ion_lev] *
114  std::pow(E, m_adk_power[ion_lev]) *
115  std::exp( m_adk_exp_prefactor[ion_lev]/E );
116  amrex::Real p = 1. - std::exp( - w_dtau );
117 
118  amrex::Real random_draw = amrex::Random(engine);
119  if (random_draw < p)
120  {
121  return true;
122  }
123  }
124  return false;
125  }
126 };
127 
129 {
130  template <typename DstData, typename SrcData>
131  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
132  void operator() (DstData& /*dst*/, SrcData& src, int i_src, int /*i_dst*/) const noexcept
133  {
134  src.m_runtime_idata[0][i_src] += 1;
135  }
136 };
137 
138 #endif
Definition: Ionization.H:17
amrex::Array4< const amrex::Real > m_ex_arr
Definition: Ionization.H:31
int m_n_rz_azimuthal_modes
Definition: Ionization.H:50
const amrex::Real *AMREX_RESTRICT m_ionization_energies
Definition: Ionization.H:19
const amrex::Real *AMREX_RESTRICT m_adk_exp_prefactor
Definition: Ionization.H:21
Definition: Ionization.H:128
int m_atomic_number
Definition: Ionization.H:25
amrex::IndexType m_ey_type
Definition: Ionization.H:39
int comp
Definition: Ionization.H:24
def uz
Definition: read_lab_particles.py:29
bool m_galerkin_interpolation
Definition: Ionization.H:48
amrex::GpuArray< amrex::Real, 3 > m_xyzmin_arr
Definition: Ionization.H:46
amrex::Array4< const amrex::Real > m_ey_arr
Definition: Ionization.H:32
GetExternalBField m_get_externalB
Definition: Ionization.H:29
Functor that can be used to assign the external B field to a particle inside a ParallelFor kernel...
Definition: GetExternalFields.H:68
amrex::Array4< const amrex::Real > m_bz_arr
Definition: Ionization.H:36
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 long n_rz_azimuthal_modes)
Field gather for a single particle.
Definition: FieldGather.H:38
amrex::Array4< const amrex::Real > m_bx_arr
Definition: Ionization.H:34
i
Definition: check_interp_points_and_weights.py:171
int m_nox
Definition: Ionization.H:49
const amrex::Real *AMREX_RESTRICT m_adk_prefactor
Definition: Ionization.H:20
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool operator()(const PData &ptd, int i, amrex::RandomEngine const &engine) const noexcept
Definition: Ionization.H:72
amrex::IndexType m_bx_type
Definition: Ionization.H:41
Definition: WarpXParticleContainer.H:37
Definition: WarpXParticleContainer.H:37
GetParticlePosition m_get_position
Definition: Ionization.H:27
amrex::Dim3 m_lo
Definition: Ionization.H:52
Definition: WarpXParticleContainer.H:37
amrex::Array4< const amrex::Real > m_by_arr
Definition: Ionization.H:35
GetExternalEField m_get_externalE
Definition: Ionization.H:28
amrex::IndexType m_bz_type
Definition: Ionization.H:43
IonizationFilterFunc(const WarpXParIter &a_pti, int lev, int 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:12
amrex::IndexType m_ex_type
Definition: Ionization.H:38
Functor that can be used to extract the positions of the macroparticles inside a ParallelFor kernel...
Definition: GetAndSetPosition.H:25
amrex::Array4< const amrex::Real > m_ez_arr
Definition: Ionization.H:33
def ux
Definition: read_lab_particles.py:28
amrex::IndexType m_ez_type
Definition: Ionization.H:40
Definition: WarpXParticleContainer.H:76
Functor that can be used to assign the external E field to a particle inside a ParallelFor kernel...
Definition: GetExternalFields.H:58
Definition: PML.H:52
const amrex::Real *AMREX_RESTRICT m_adk_power
Definition: Ionization.H:22
amrex::IndexType m_by_type
Definition: Ionization.H:42
amrex::GpuArray< amrex::Real, 3 > m_dx_arr
Definition: Ionization.H:45