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  amrex::ParticleReal energy
31  );
32 
33  template <typename InputVector>
34  MCCProcess (
35  const std::string& scattering_process,
36  const InputVector&& energies,
37  const InputVector&& sigmas,
38  amrex::ParticleReal energy
39  );
40 
41  ~MCCProcess() = default;
42 
43  MCCProcess (MCCProcess const&) = delete;
44  MCCProcess& operator= (MCCProcess const&) = delete;
45  MCCProcess (MCCProcess &&) = default;
47 
56  static
58  std::string cross_section_file,
61  );
62 
63  static
65  const amrex::Vector<amrex::ParticleReal>& energies,
66  amrex::ParticleReal dE
67  );
68 
69  struct Executor {
77  [[nodiscard]]
79  amrex::ParticleReal getCrossSection (amrex::ParticleReal E_coll) const
80  {
81  if (E_coll < m_energy_lo) {
82  return m_sigma_lo;
83  } else if (E_coll > m_energy_hi) {
84  return m_sigma_hi;
85  } else {
86  using amrex::Math::floor;
87  using amrex::Math::ceil;
88  // calculate index of bounding energy pairs
89  amrex::ParticleReal temp = (E_coll - m_energy_lo) / m_dE;
90  const int idx_1 = static_cast<int>(floor(temp));
91  const int idx_2 = static_cast<int>(ceil(temp));
92 
93  // linearly interpolate to the given energy value
94  temp -= idx_1;
95  return m_sigmas_data[idx_1] + (m_sigmas_data[idx_2] - m_sigmas_data[idx_1]) * temp;
96  }
97  }
98 
99  amrex::ParticleReal* m_sigmas_data = nullptr;
101  amrex::ParticleReal m_energy_penalty;
103  };
104 
105  [[nodiscard]]
106  Executor const& executor () const {
107 #ifdef AMREX_USE_GPU
108  return m_exe_d;
109 #else
110  return m_exe_h;
111 #endif
112  }
113 
114  [[nodiscard]] amrex::ParticleReal getCrossSection (amrex::ParticleReal E_coll) const
115  {
116  return m_exe_h.getCrossSection(E_coll);
117  }
118 
119  [[nodiscard]] amrex::ParticleReal getEnergyPenalty () const { return m_exe_h.m_energy_penalty; }
120  [[nodiscard]] amrex::ParticleReal getMinEnergyInput () const { return m_exe_h.m_energy_lo; }
121  [[nodiscard]] amrex::ParticleReal getMaxEnergyInput () const { return m_exe_h.m_energy_hi; }
122  [[nodiscard]] amrex::ParticleReal getEnergyInputStep () const { return m_exe_h.m_dE; }
123 
124  [[nodiscard]] MCCProcessType type () const { return m_exe_h.m_type; }
125 
126 private:
127 
128  static
129  MCCProcessType parseProcessType(const std::string& process);
130 
131  void init (const std::string& scattering_process, amrex::ParticleReal energy);
132 
134 
135 #ifdef AMREX_USE_GPU
137  Executor m_exe_d;
138 #endif
141 
143 };
144 
145 #endif // WARPX_PARTICLES_COLLISION_MCCPROCESS_H_
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
MCCProcessType
Definition: MCCProcess.H:15
Definition: MCCProcess.H:25
static void sanityCheckEnergyGrid(const amrex::Vector< amrex::ParticleReal > &energies, amrex::ParticleReal dE)
Definition: MCCProcess.cpp:112
amrex::ParticleReal getEnergyInputStep() const
Definition: MCCProcess.H:122
static void readCrossSectionFile(std::string cross_section_file, amrex::Vector< amrex::ParticleReal > &energies, amrex::Gpu::HostVector< amrex::ParticleReal > &sigmas)
Definition: MCCProcess.cpp:94
MCCProcess(MCCProcess const &)=delete
amrex::ParticleReal getMaxEnergyInput() const
Definition: MCCProcess.H:121
int m_grid_size
Definition: MCCProcess.H:142
~MCCProcess()=default
amrex::ParticleReal getCrossSection(amrex::ParticleReal E_coll) const
Definition: MCCProcess.H:114
MCCProcess(const std::string &scattering_process, const std::string &cross_section_file, amrex::ParticleReal energy)
Definition: MCCProcess.cpp:12
MCCProcessType type() const
Definition: MCCProcess.H:124
Executor m_exe_h
Definition: MCCProcess.H:140
amrex::Vector< amrex::ParticleReal > m_energies
Definition: MCCProcess.H:133
static MCCProcessType parseProcessType(const std::string &process)
Definition: MCCProcess.cpp:76
amrex::Gpu::HostVector< amrex::ParticleReal > m_sigmas_h
Definition: MCCProcess.H:139
MCCProcess & operator=(MCCProcess const &)=delete
Executor const & executor() const
Definition: MCCProcess.H:106
void init(const std::string &scattering_process, amrex::ParticleReal energy)
Definition: MCCProcess.cpp:37
amrex::ParticleReal getMinEnergyInput() const
Definition: MCCProcess.H:120
MCCProcess(MCCProcess &&)=default
amrex::ParticleReal getEnergyPenalty() const
Definition: MCCProcess.H:119
Definition: MCCProcess.H:69
amrex::ParticleReal m_energy_hi
Definition: MCCProcess.H:100
amrex::ParticleReal m_sigma_hi
Definition: MCCProcess.H:100
amrex::ParticleReal m_energy_lo
Definition: MCCProcess.H:100
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal getCrossSection(amrex::ParticleReal E_coll) const
Definition: MCCProcess.H:79
amrex::ParticleReal * m_sigmas_data
Definition: MCCProcess.H:99
amrex::ParticleReal m_sigma_lo
Definition: MCCProcess.H:100
amrex::ParticleReal m_energy_penalty
Definition: MCCProcess.H:101
MCCProcessType m_type
Definition: MCCProcess.H:102
amrex::ParticleReal m_dE
Definition: MCCProcess.H:100