WarpX
MCCProcess.H
Go to the documentation of this file.
1 /* Copyright 2021 Modern Electron
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef WARPX_PARTICLES_COLLISION_MCCPROCESS_H_
8 #define WARPX_PARTICLES_COLLISION_MCCPROCESS_H_
9 
10 #include <AMReX_Math.H>
11 #include <AMReX_Vector.H>
12 #include <AMReX_RandomEngine.H>
13 #include <AMReX_GpuContainers.H>
14 
15 enum class MCCProcessType {
16  INVALID,
17  ELASTIC,
18  BACK,
20  EXCITATION,
21  IONIZATION,
22 };
23 
25 {
26 public:
27  MCCProcess (
28  const std::string& scattering_process,
29  const std::string& cross_section_file,
30  const amrex::Real energy
31  );
32 
33  template <typename InputVector>
34  MCCProcess (
35  const std::string& scattering_process,
36  const InputVector&& energies,
37  const InputVector&& sigmas,
38  const amrex::Real energy
39  );
40 
41  MCCProcess (MCCProcess const&) = delete;
42  MCCProcess& operator= (MCCProcess const&) = delete;
43 
44  MCCProcess (MCCProcess &&) = default;
45  MCCProcess& operator= (MCCProcess &&) = default;
46 
55  static
56  void readCrossSectionFile (
57  const std::string cross_section_file,
58  amrex::Vector<amrex::Real>& energies,
59  amrex::Gpu::HostVector<amrex::Real>& sigmas
60  );
61 
62  static
63  void sanityCheckEnergyGrid (
64  const amrex::Vector<amrex::Real>& energies,
65  amrex::Real dE
66  );
67 
68  struct Executor {
76  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
77  amrex::Real getCrossSection (amrex::Real E_coll) const
78  {
79  if (E_coll < m_energy_lo) {
80  return m_sigma_lo;
81  } else if (E_coll > m_energy_hi) {
82  return m_sigma_hi;
83  } else {
84  using amrex::Math::floor;
85  using amrex::Math::ceil;
86  // calculate index of bounding energy pairs
87  amrex::Real temp = (E_coll - m_energy_lo) / m_dE;
88  int idx_1 = static_cast<int>(floor(temp));
89  int idx_2 = static_cast<int>(ceil(temp));
90 
91  // linearly interpolate to the given energy value
92  temp -= idx_1;
93  return m_sigmas_data[idx_1] + (m_sigmas_data[idx_2] - m_sigmas_data[idx_1]) * temp;
94  }
95  }
96 
97  amrex::Real* m_sigmas_data = nullptr;
98  amrex::Real m_energy_lo, m_energy_hi, m_sigma_lo, m_sigma_hi, m_dE;
99  amrex::Real m_energy_penalty;
101  };
102 
103  Executor const& executor () const {
104 #ifdef AMREX_USE_GPU
105  return m_exe_d;
106 #else
107  return m_exe_h;
108 #endif
109  }
110 
111  amrex::Real getCrossSection (amrex::Real E_coll) const
112  {
113  return m_exe_h.getCrossSection(E_coll);
114  }
115 
116  amrex::Real getEnergyPenalty () const { return m_exe_h.m_energy_penalty; }
117 
118  MCCProcessType type () const { return m_exe_h.m_type; }
119 
120 private:
121 
122  static
123  MCCProcessType parseProcessType(const std::string& process);
124 
125  void init (const std::string& scattering_process, const amrex::Real energy);
126 
127  amrex::Vector<amrex::Real> m_energies;
128 
129 #ifdef AMREX_USE_GPU
130  amrex::Gpu::DeviceVector<amrex::Real> m_sigmas_d;
131  Executor m_exe_d;
132 #endif
133  amrex::Gpu::HostVector<amrex::Real> m_sigmas_h;
135 
137 };
138 
139 #endif // WARPX_PARTICLES_COLLISION_MCCPROCESS_H_
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getCrossSection(amrex::Real E_coll) const
Definition: MCCProcess.H:77
MCCProcessType m_type
Definition: MCCProcess.H:100
amrex::Real getCrossSection(amrex::Real E_coll) const
Definition: MCCProcess.H:111
Executor m_exe_h
Definition: MCCProcess.H:134
Definition: MCCProcess.H:24
amrex::Vector< amrex::Real > m_energies
Definition: MCCProcess.H:127
Executor const & executor() const
Definition: MCCProcess.H:103
MCCProcessType type() const
Definition: MCCProcess.H:118
MCCProcessType
Definition: MCCProcess.H:15
amrex::Gpu::HostVector< amrex::Real > m_sigmas_h
Definition: MCCProcess.H:133
amrex::Real m_energy_penalty
Definition: MCCProcess.H:99
Definition: MCCProcess.H:68
amrex::Real getEnergyPenalty() const
Definition: MCCProcess.H:116
int m_grid_size
Definition: MCCProcess.H:136
amrex::Real m_sigma_lo
Definition: MCCProcess.H:98