WarpX
BreitWheelerEngineWrapper.H
Go to the documentation of this file.
1 /* Copyright 2019 Luca Fedeli
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef WARPX_breit_wheeler_engine_wrapper_h_
8 #define WARPX_breit_wheeler_engine_wrapper_h_
9 
10 #include "QedWrapperCommons.H"
11 #include "QedChiFunctions.H"
12 #include "Utils/WarpXConst.H"
13 
14 #include <AMReX_Array.H>
15 #include <AMReX_Vector.H>
16 #include <AMReX_Gpu.H>
17 
18 #include <physics/breit_wheeler/breit_wheeler_engine_tables.hpp>
19 #include <physics/breit_wheeler/breit_wheeler_engine_core.hpp>
20 
21 #include <string>
22 #include <vector>
23 
24 // Aliases =============================
26  picsar::multi_physics::phys::breit_wheeler::
27  dndt_lookup_table_params<amrex::Real>;
28 
29 using BW_dndt_table =
30  picsar::multi_physics::phys::breit_wheeler::
31  dndt_lookup_table<
32  amrex::Real,
33  amrex::Gpu::DeviceVector<amrex::Real>>;
34 
35 using BW_dndt_table_view = BW_dndt_table::view_type;
36 
38  picsar::multi_physics::phys::breit_wheeler::
39  pair_prod_lookup_table_params<amrex::Real>;
40 
41 using BW_pair_prod_table =
42  picsar::multi_physics::phys::breit_wheeler::
43  pair_prod_lookup_table<
44  amrex::Real,
45  amrex::Gpu::DeviceVector<amrex::Real>>;
46 
47 using BW_pair_prod_table_view = BW_pair_prod_table::view_type;
48 
50 {
53 };
54 
55 // Functors ==================================
56 
57 // These functors allow using the core elementary functions of the library.
58 // They are generated by a factory class (BreitWheelerEngine, see below).
59 // They can be included in GPU kernels.
60 
66 {
67 public:
73  {};
74 
79  AMREX_GPU_HOST_DEVICE
80  AMREX_FORCE_INLINE
81  amrex::Real operator() (amrex::RandomEngine const& engine) const noexcept
82  {
83  namespace pxr_bw = picsar::multi_physics::phys::breit_wheeler;
84 
85  //A random number in [0,1) should be provided as an argument.
86  return pxr_bw::get_optical_depth(amrex::Random(engine));
87  }
88 };
89 //____________________________________________
90 
96 {
97 public:
98 
103 
104 
112  const BW_dndt_table_view table_view,
113  const amrex::ParticleReal bw_minimum_chi_phot):
114  m_table_view{table_view}, m_bw_minimum_chi_phot{bw_minimum_chi_phot}{};
115 
130  AMREX_GPU_DEVICE
131  AMREX_FORCE_INLINE
133  const amrex::Real ux, const amrex::Real uy, const amrex::Real uz,
134  const amrex::Real ex, const amrex::Real ey, const amrex::Real ez,
135  const amrex::Real bx, const amrex::Real by, const amrex::Real bz,
136  const amrex::Real dt, amrex::Real& opt_depth) const noexcept
137  {
138  namespace pxr_m = picsar::multi_physics::math;
139  namespace pxr_p = picsar::multi_physics::phys;
140  namespace pxr_bw = picsar::multi_physics::phys::breit_wheeler;
141 
142  constexpr amrex::Real m_e = PhysConst::m_e;
143  const auto u_norm = std::sqrt(ux*ux + uy*uy + uz*uz);
144  const auto energy = u_norm*m_e*PhysConst::c;
145 
146  const auto chi_phot = QedUtils::chi_photon(
147  m_e*ux, m_e*uy, m_e*uz, ex, ey, ez, bx, by, bz);
148 
149  //Optical depth is not evolved for photons having less energy than what is
150  //required to generate a pair or a quantum parameter smaller than
151  //m_bw_minimum_chi_phot
152  const auto gamma_photon = u_norm/PhysConst::c;
153  if (gamma_photon < pxr_m::two<amrex::Real> ||
154  chi_phot < m_bw_minimum_chi_phot)
155  return 0;
156 
157  const auto is_out = pxr_bw::evolve_optical_depth<
158  amrex::Real,
160  pxr_p::unit_system::SI>(
161  energy, chi_phot, dt, opt_depth, m_table_view);
162 
163  return is_out;
164  }
165 
166 private:
168  amrex::ParticleReal m_bw_minimum_chi_phot;
169 };
170 
176 {
177 public:
178 
183 
193  m_table_view{table_view}{};
194 
208  AMREX_GPU_DEVICE
209  AMREX_FORCE_INLINE
211  const amrex::Real ux, const amrex::Real uy, const amrex::Real uz,
212  const amrex::Real ex, const amrex::Real ey, const amrex::Real ez,
213  const amrex::Real bx, const amrex::Real by, const amrex::Real bz,
214  amrex::Real& e_ux, amrex::Real& e_uy, amrex::Real& e_uz,
215  amrex::Real& p_ux, amrex::Real& p_uy, amrex::Real& p_uz) const noexcept
216  {
217  using namespace amrex;
218  namespace pxr_m = picsar::multi_physics::math;
219  namespace pxr_p = picsar::multi_physics::phys;
220  namespace pxr_bw = picsar::multi_physics::phys::breit_wheeler;
221 
222  const auto rand_zero_one_minus_epsi = amrex::Random();
223 
224  constexpr ParticleReal me = PhysConst::m_e;
225  constexpr ParticleReal one_over_me = 1._prt/me;
226 
227  // Particle momentum is stored as gamma * velocity.
228  // Convert to m * gamma * velocity
229  auto px = ux*me;
230  auto py = uy*me;
231  auto pz = uz*me;
232 
233  const auto chi_photon = QedUtils::chi_photon(
234  px, py, pz, ex, ey, ez, bx, by, bz);
235 
236  const auto momentum_photon = pxr_m::vec3<amrex::Real>{px, py, pz};
237  auto momentum_ele = pxr_m::vec3<amrex::Real>();
238  auto momentum_pos = pxr_m::vec3<amrex::Real>();
239 
240  const auto is_out = pxr_bw::generate_breit_wheeler_pairs<
241  amrex::Real,
243  pxr_p::unit_system::SI>(
244  chi_photon, momentum_photon,
245  rand_zero_one_minus_epsi,
246  m_table_view,
247  momentum_ele, momentum_pos);
248 
249  e_ux = momentum_ele[0]*one_over_me;
250  e_uy = momentum_ele[1]*one_over_me;
251  e_uz = momentum_ele[2]*one_over_me;
252  p_ux = momentum_pos[0]*one_over_me;
253  p_uy = momentum_pos[1]*one_over_me;
254  p_uz = momentum_pos[2]*one_over_me;
255 
256  return is_out;
257  }
258 
259 private:
261 };
262 
263 // Factory class =============================
264 
269 {
270 public:
275 
279  BreitWheelerGetOpticalDepth build_optical_depth_functor () const;
280 
284  BreitWheelerEvolveOpticalDepth build_evolve_functor () const;
285 
289  BreitWheelerGeneratePairs build_pair_functor () const;
290 
294  bool are_lookup_tables_initialized () const;
295 
302  std::vector<char> export_lookup_tables_data () const;
303 
311  bool init_lookup_tables_from_raw_data (
312  const std::vector<char>& raw_data,
313  const amrex::Real bw_minimum_chi_phot);
314 
320  void init_builtin_tables(const amrex::Real bw_minimum_chi_phot);
321 
328  void compute_lookup_tables (const PicsarBreitWheelerCtrl ctrl,
329  const amrex::Real bw_minimum_chi_phot);
330 
336  PicsarBreitWheelerCtrl get_default_ctrl() const;
337 
338  amrex::Real get_minimum_chi_phot() const;
339 
340 private:
341  bool m_lookup_tables_initialized = false;
342 
343  //Variables to store the minimum chi parameters to enable
344  //Quantum Synchrotron process
346 
349 
350  void init_builtin_dndt_table();
351  void init_builtin_pair_prod_table();
352 
353 
354 };
355 
356 //============================================
357 
358 #endif //WARPX_breit_wheeler_engine_wrapper_H_
BW_pair_prod_table m_pair_prod_table
Definition: BreitWheelerEngineWrapper.H:348
picsar::multi_physics::phys::breit_wheeler::dndt_lookup_table< amrex::Real, amrex::Gpu::DeviceVector< amrex::Real > > BW_dndt_table
Definition: BreitWheelerEngineWrapper.H:33
BreitWheelerEvolveOpticalDepth(const BW_dndt_table_view table_view, const amrex::ParticleReal bw_minimum_chi_phot)
Definition: BreitWheelerEngineWrapper.H:111
BW_pair_prod_table_view m_table_view
Definition: BreitWheelerEngineWrapper.H:260
BW_dndt_table_params dndt_params
Definition: BreitWheelerEngineWrapper.H:51
BreitWheelerEvolveOpticalDepth()
Definition: BreitWheelerEngineWrapper.H:102
me
Definition: yt3d_mpi.py:139
def uz
Definition: read_lab_particles.py:29
Definition: BreitWheelerEngineWrapper.H:49
BW_dndt_table::view_type BW_dndt_table_view
Definition: BreitWheelerEngineWrapper.H:35
BreitWheelerGetOpticalDepth()
Definition: BreitWheelerEngineWrapper.H:72
Definition: BreitWheelerEngineWrapper.H:95
BW_dndt_table m_dndt_table
Definition: BreitWheelerEngineWrapper.H:347
Definition: BreitWheelerEngineWrapper.H:65
amrex::ParticleReal m_bw_minimum_chi_phot
Definition: BreitWheelerEngineWrapper.H:168
BW_dndt_table_view m_table_view
Definition: BreitWheelerEngineWrapper.H:167
BW_pair_prod_table_params pair_prod_params
Definition: BreitWheelerEngineWrapper.H:52
picsar::multi_physics::phys::breit_wheeler::pair_prod_lookup_table< amrex::Real, amrex::Gpu::DeviceVector< amrex::Real > > BW_pair_prod_table
Definition: BreitWheelerEngineWrapper.H:45
AMREX_GPU_DEVICE AMREX_FORCE_INLINE int operator()(const amrex::Real ux, const amrex::Real uy, const amrex::Real uz, const amrex::Real ex, const amrex::Real ey, const amrex::Real ez, const amrex::Real bx, const amrex::Real by, const amrex::Real bz, const amrex::Real dt, amrex::Real &opt_depth) const noexcept
Definition: BreitWheelerEngineWrapper.H:132
AMREX_GPU_DEVICE AMREX_FORCE_INLINE int operator()(const amrex::Real ux, const amrex::Real uy, const amrex::Real uz, const amrex::Real ex, const amrex::Real ey, const amrex::Real ez, const amrex::Real bx, const amrex::Real by, const amrex::Real bz, amrex::Real &e_ux, amrex::Real &e_uy, amrex::Real &e_uz, amrex::Real &p_ux, amrex::Real &p_uy, amrex::Real &p_uz) const noexcept
Definition: BreitWheelerEngineWrapper.H:210
picsar::multi_physics::phys::breit_wheeler::dndt_lookup_table_params< amrex::Real > BW_dndt_table_params
Definition: BreitWheelerEngineWrapper.H:27
Definition: BreitWheelerEngineWrapper.H:175
def ux
Definition: read_lab_particles.py:28
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real chi_photon(const amrex::Real px, const amrex::Real py, const amrex::Real pz, const amrex::Real ex, const amrex::Real ey, const amrex::Real ez, const amrex::Real bx, const amrex::Real by, const amrex::Real bz)
Definition: QedChiFunctions.H:31
amrex::Real m_bw_minimum_chi_phot
Definition: BreitWheelerEngineWrapper.H:345
Definition: BreitWheelerEngineWrapper.H:268
Definition: PML.H:52
BreitWheelerGeneratePairs(const BW_pair_prod_table_view table_view)
Definition: BreitWheelerEngineWrapper.H:192
picsar::multi_physics::phys::breit_wheeler::pair_prod_lookup_table_params< amrex::Real > BW_pair_prod_table_params
Definition: BreitWheelerEngineWrapper.H:39
BreitWheelerGeneratePairs()
Definition: BreitWheelerEngineWrapper.H:182
BW_pair_prod_table::view_type BW_pair_prod_table_view
Definition: BreitWheelerEngineWrapper.H:47