ARTEMIS
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::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  const amrex::ParticleReal energy
39  );
40 
41  MCCProcess (MCCProcess const&) = delete;
42  MCCProcess& operator= (MCCProcess const&) = delete;
43 
44  MCCProcess (MCCProcess &&) = default;
46 
55  static
57  const std::string cross_section_file,
60  );
61 
62  static
64  const amrex::Vector<amrex::ParticleReal>& energies,
65  amrex::ParticleReal dE
66  );
67 
68  struct Executor {
77  amrex::ParticleReal getCrossSection (amrex::ParticleReal 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::ParticleReal 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::ParticleReal* m_sigmas_data = nullptr;
99  amrex::ParticleReal 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::ParticleReal getCrossSection (amrex::ParticleReal E_coll) const
112  {
113  return m_exe_h.getCrossSection(E_coll);
114  }
115 
116  amrex::ParticleReal getEnergyPenalty () const { return m_exe_h.m_energy_penalty; }
117  amrex::ParticleReal getMinEnergyInput () const { return m_exe_h.m_energy_lo; }
118  amrex::ParticleReal getMaxEnergyInput () const { return m_exe_h.m_energy_hi; }
119  amrex::ParticleReal getEnergyInputStep () const { return m_exe_h.m_dE; }
120 
121  MCCProcessType type () const { return m_exe_h.m_type; }
122 
123 private:
124 
125  static
126  MCCProcessType parseProcessType(const std::string& process);
127 
128  void init (const std::string& scattering_process, const amrex::ParticleReal energy);
129 
131 
132 #ifdef AMREX_USE_GPU
134  Executor m_exe_d;
135 #endif
138 
140 };
141 
142 #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:119
MCCProcess(MCCProcess const &)=delete
amrex::ParticleReal getMaxEnergyInput() const
Definition: MCCProcess.H:118
int m_grid_size
Definition: MCCProcess.H:139
amrex::ParticleReal getCrossSection(amrex::ParticleReal E_coll) const
Definition: MCCProcess.H:111
MCCProcessType type() const
Definition: MCCProcess.H:121
Executor m_exe_h
Definition: MCCProcess.H:137
void init(const std::string &scattering_process, const amrex::ParticleReal energy)
Definition: MCCProcess.cpp:37
amrex::Vector< amrex::ParticleReal > m_energies
Definition: MCCProcess.H:130
static MCCProcessType parseProcessType(const std::string &process)
Definition: MCCProcess.cpp:76
amrex::Gpu::HostVector< amrex::ParticleReal > m_sigmas_h
Definition: MCCProcess.H:136
MCCProcess & operator=(MCCProcess const &)=delete
Executor const & executor() const
Definition: MCCProcess.H:103
MCCProcess(const std::string &scattering_process, const std::string &cross_section_file, const amrex::ParticleReal energy)
Definition: MCCProcess.cpp:12
amrex::ParticleReal getMinEnergyInput() const
Definition: MCCProcess.H:117
static void readCrossSectionFile(const std::string cross_section_file, amrex::Vector< amrex::ParticleReal > &energies, amrex::Gpu::HostVector< amrex::ParticleReal > &sigmas)
Definition: MCCProcess.cpp:94
MCCProcess(MCCProcess &&)=default
amrex::ParticleReal getEnergyPenalty() const
Definition: MCCProcess.H:116
Definition: MCCProcess.H:68
amrex::ParticleReal m_energy_hi
Definition: MCCProcess.H:98
amrex::ParticleReal m_sigma_hi
Definition: MCCProcess.H:98
amrex::ParticleReal m_energy_lo
Definition: MCCProcess.H:98
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal getCrossSection(amrex::ParticleReal E_coll) const
Definition: MCCProcess.H:77
amrex::ParticleReal * m_sigmas_data
Definition: MCCProcess.H:97
amrex::ParticleReal m_sigma_lo
Definition: MCCProcess.H:98
amrex::ParticleReal m_energy_penalty
Definition: MCCProcess.H:99
MCCProcessType m_type
Definition: MCCProcess.H:100
amrex::ParticleReal m_dE
Definition: MCCProcess.H:98