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 {
78  amrex::ParticleReal getCrossSection (amrex::ParticleReal E_coll) const
79  {
80  if (E_coll < m_energy_lo) {
81  return m_sigma_lo;
82  } else if (E_coll > m_energy_hi) {
83  return m_sigma_hi;
84  } else {
85  using amrex::Math::floor;
86  using amrex::Math::ceil;
87  // calculate index of bounding energy pairs
88  amrex::ParticleReal temp = (E_coll - m_energy_lo) / m_dE;
89  const int idx_1 = static_cast<int>(floor(temp));
90  const int idx_2 = static_cast<int>(ceil(temp));
91 
92  // linearly interpolate to the given energy value
93  temp -= idx_1;
94  return m_sigmas_data[idx_1] + (m_sigmas_data[idx_2] - m_sigmas_data[idx_1]) * temp;
95  }
96  }
97 
98  amrex::ParticleReal* m_sigmas_data = nullptr;
100  amrex::ParticleReal m_energy_penalty;
102  };
103 
104  Executor const& executor () const {
105 #ifdef AMREX_USE_GPU
106  return m_exe_d;
107 #else
108  return m_exe_h;
109 #endif
110  }
111 
112  amrex::ParticleReal getCrossSection (amrex::ParticleReal E_coll) const
113  {
114  return m_exe_h.getCrossSection(E_coll);
115  }
116 
117  amrex::ParticleReal getEnergyPenalty () const { return m_exe_h.m_energy_penalty; }
118  amrex::ParticleReal getMinEnergyInput () const { return m_exe_h.m_energy_lo; }
119  amrex::ParticleReal getMaxEnergyInput () const { return m_exe_h.m_energy_hi; }
120  amrex::ParticleReal getEnergyInputStep () const { return m_exe_h.m_dE; }
121 
122  MCCProcessType type () const { return m_exe_h.m_type; }
123 
124 private:
125 
126  static
127  MCCProcessType parseProcessType(const std::string& process);
128 
129  void init (const std::string& scattering_process, amrex::ParticleReal energy);
130 
132 
133 #ifdef AMREX_USE_GPU
135  Executor m_exe_d;
136 #endif
139 
141 };
142 
143 #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:120
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:119
int m_grid_size
Definition: MCCProcess.H:140
~MCCProcess()=default
amrex::ParticleReal getCrossSection(amrex::ParticleReal E_coll) const
Definition: MCCProcess.H:112
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:122
Executor m_exe_h
Definition: MCCProcess.H:138
amrex::Vector< amrex::ParticleReal > m_energies
Definition: MCCProcess.H:131
static MCCProcessType parseProcessType(const std::string &process)
Definition: MCCProcess.cpp:76
amrex::Gpu::HostVector< amrex::ParticleReal > m_sigmas_h
Definition: MCCProcess.H:137
MCCProcess & operator=(MCCProcess const &)=delete
Executor const & executor() const
Definition: MCCProcess.H:104
void init(const std::string &scattering_process, amrex::ParticleReal energy)
Definition: MCCProcess.cpp:37
amrex::ParticleReal getMinEnergyInput() const
Definition: MCCProcess.H:118
MCCProcess(MCCProcess &&)=default
amrex::ParticleReal getEnergyPenalty() const
Definition: MCCProcess.H:117
Definition: MCCProcess.H:69
amrex::ParticleReal m_energy_hi
Definition: MCCProcess.H:99
amrex::ParticleReal m_sigma_hi
Definition: MCCProcess.H:99
amrex::ParticleReal m_energy_lo
Definition: MCCProcess.H:99
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal getCrossSection(amrex::ParticleReal E_coll) const
Definition: MCCProcess.H:78
amrex::ParticleReal * m_sigmas_data
Definition: MCCProcess.H:98
amrex::ParticleReal m_sigma_lo
Definition: MCCProcess.H:99
amrex::ParticleReal m_energy_penalty
Definition: MCCProcess.H:100
MCCProcessType m_type
Definition: MCCProcess.H:101
amrex::ParticleReal m_dE
Definition: MCCProcess.H:99