WarpX
SingleNuclearFusionEvent.H
Go to the documentation of this file.
1 /* Copyright 2021 Neil Zaim
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 
8 #ifndef SINGLE_NUCLEAR_FUSION_EVENT_H_
9 #define SINGLE_NUCLEAR_FUSION_EVENT_H_
10 
13 
15 #include "Utils/WarpXConst.H"
16 
17 #include <AMReX_Algorithm.H>
18 #include <AMReX_Random.H>
19 #include <AMReX_REAL.H>
20 
21 #include <cmath>
22 
23 
52 template <typename index_type>
54 void SingleNuclearFusionEvent (const amrex::ParticleReal& u1x, const amrex::ParticleReal& u1y,
55  const amrex::ParticleReal& u1z, const amrex::ParticleReal& u2x,
56  const amrex::ParticleReal& u2y, const amrex::ParticleReal& u2z,
57  const amrex::ParticleReal& m1, const amrex::ParticleReal& m2,
58  amrex::ParticleReal w1, amrex::ParticleReal w2,
59  const amrex::Real& dt, const amrex::ParticleReal& dV, const int& pair_index,
60  index_type* AMREX_RESTRICT p_mask,
61  amrex::ParticleReal* AMREX_RESTRICT p_pair_reaction_weight,
62  const amrex::ParticleReal& fusion_multiplier,
63  const int& multiplier_ratio,
64  const amrex::ParticleReal& probability_threshold,
65  const amrex::ParticleReal& probability_target_value,
66  const NuclearFusionType& fusion_type,
67  const amrex::RandomEngine& engine)
68 {
69  // General notations in this function:
70  // x_sq denotes the square of x
71  // x_star denotes the value of x in the center of mass frame
72 
73  using namespace amrex::literals;
74 
75  const amrex::ParticleReal w_min = amrex::min(w1, w2);
76  const amrex::ParticleReal w_max = amrex::max(w1, w2);
77 
78  constexpr auto one_pr = amrex::ParticleReal(1.);
79  constexpr auto inv_four_pr = amrex::ParticleReal(1./4.);
80  constexpr amrex::ParticleReal c_sq = PhysConst::c * PhysConst::c;
81  constexpr amrex::ParticleReal inv_csq = one_pr / ( c_sq );
82 
83  const amrex::ParticleReal m1_sq = m1*m1;
84  const amrex::ParticleReal m2_sq = m2*m2;
85 
86  // Compute Lorentz factor gamma in the lab frame
87  const amrex::ParticleReal g1 = std::sqrt( one_pr + (u1x*u1x+u1y*u1y+u1z*u1z)*inv_csq );
88  const amrex::ParticleReal g2 = std::sqrt( one_pr + (u2x*u2x+u2y*u2y+u2z*u2z)*inv_csq );
89 
90  // Compute momenta
91  const amrex::ParticleReal p1x = u1x * m1;
92  const amrex::ParticleReal p1y = u1y * m1;
93  const amrex::ParticleReal p1z = u1z * m1;
94  const amrex::ParticleReal p2x = u2x * m2;
95  const amrex::ParticleReal p2y = u2y * m2;
96  const amrex::ParticleReal p2z = u2z * m2;
97  // Square norm of the total (sum between the two particles) momenta in the lab frame
98  auto constexpr pow2 = [](double const x) { return x*x; };
99  const amrex::ParticleReal p_total_sq = pow2(p1x + p2x) +
100  pow2(p1y+p2y) +
101  pow2(p1z+p2z);
102 
103  // Total energy in the lab frame
104  const amrex::ParticleReal E_lab = (m1 * g1 + m2 * g2) * c_sq;
105  // Total energy squared in the center of mass frame, calculated using the Lorentz invariance
106  // of the four-momentum norm
107  const amrex::ParticleReal E_star_sq = E_lab*E_lab - c_sq*p_total_sq;
108 
109  // Kinetic energy in the center of mass frame
110  const amrex::ParticleReal E_star = std::sqrt(E_star_sq);
111  const amrex::ParticleReal E_kin_star = E_star - (m1 + m2)*c_sq;
112 
113  // Compute fusion cross section as a function of kinetic energy in the center of mass frame
114  auto fusion_cross_section = amrex::ParticleReal(0.);
115  if (fusion_type == NuclearFusionType::ProtonBoronToAlphas)
116  {
117  fusion_cross_section = ProtonBoronFusionCrossSection(E_kin_star);
118  }
122  {
123  fusion_cross_section = BoschHaleFusionCrossSection(E_kin_star, fusion_type, m1, m2);
124  }
125 
126  // Square of the norm of the momentum of one of the particles in the center of mass frame
127  // Formula obtained by inverting E^2 = p^2*c^2 + m^2*c^4 in the COM frame for each particle
128  // The expression below is specifically written in a form that avoids returning
129  // small negative numbers due to machine precision errors, for low-energy particles
130  const amrex::ParticleReal E_ratio = E_star/((m1 + m2)*c_sq);
131  const amrex::ParticleReal p_star_sq = m1*m2*c_sq * ( pow2(E_ratio) - one_pr )
132  + pow2(m1 - m2)*c_sq*inv_four_pr * pow2( E_ratio - 1._prt/E_ratio );
133 
134  // Lorentz factors in the center of mass frame
135  const amrex::ParticleReal g1_star = std::sqrt(one_pr + p_star_sq / (m1_sq*c_sq));
136  const amrex::ParticleReal g2_star = std::sqrt(one_pr + p_star_sq / (m2_sq*c_sq));
137 
138  // relative velocity in the center of mass frame
139  const amrex::ParticleReal v_rel = std::sqrt(p_star_sq) * (one_pr/(m1*g1_star) +
140  one_pr/(m2*g2_star));
141 
142  // Fusion cross section and relative velocity are computed in the center of mass frame.
143  // On the other hand, the particle densities (weight over volume) in the lab frame are used. To
144  // take into account this discrepancy, we need to multiply the fusion probability by the ratio
145  // between the Lorentz factors in the COM frame and the Lorentz factors in the lab frame
146  // (see Perez et al., Phys.Plasmas.19.083104 (2012))
147  const amrex::ParticleReal lab_to_COM_factor = g1_star*g2_star/(g1*g2);
148 
149  // First estimate of probability to have fusion reaction
150  amrex::ParticleReal probability_estimate = multiplier_ratio * fusion_multiplier *
151  lab_to_COM_factor * w_max * fusion_cross_section * v_rel * dt / dV;
152 
153  // Effective fusion multiplier
154  amrex::ParticleReal fusion_multiplier_eff = fusion_multiplier;
155 
156  // If the fusion probability is too high and the fusion multiplier greater than one, we risk to
157  // systematically underestimate the fusion yield. In this case, we reduce the fusion multiplier
158  // to reduce the fusion probability
159  if (probability_estimate > probability_threshold)
160  {
161  // We aim for a fusion probability of probability_target_value but take into account
162  // the constraint that the fusion_multiplier cannot be smaller than one
163  fusion_multiplier_eff = amrex::max(fusion_multiplier *
164  probability_target_value / probability_estimate , one_pr);
165  probability_estimate *= fusion_multiplier_eff/fusion_multiplier;
166  }
167 
168  // Compute actual fusion probability that is always between zero and one
169  // In principle this is obtained by computing 1 - exp(-probability_estimate)
170  // However, the computation of this quantity can fail numerically when probability_estimate is
171  // too small (e.g. exp(-probability_estimate) returns 1 and the computation returns 0).
172  // In this case, we simply use "probability_estimate" instead of 1 - exp(-probability_estimate)
173  // The threshold exp_threshold at which we switch between the two formulas is determined by the
174  // fact that computing the exponential is only useful if it can resolve the x^2/2 term of its
175  // Taylor expansion, i.e. the square of probability_estimate should be greater than the
176  // machine epsilon.
177 #ifdef AMREX_SINGLE_PRECISION_PARTICLES
178  constexpr auto exp_threshold = amrex::ParticleReal(1.e-3);
179 #else
180  constexpr auto exp_threshold = amrex::ParticleReal(5.e-8);
181 #endif
182  const amrex::ParticleReal probability = (probability_estimate < exp_threshold) ?
183  probability_estimate: one_pr - std::exp(-probability_estimate);
184 
185  // Get a random number
186  amrex::ParticleReal random_number = amrex::Random(engine);
187 
188  // If we have a fusion event, set the mask the true and fill the product weight array
189  if (random_number < probability)
190  {
191  p_mask[pair_index] = true;
192  p_pair_reaction_weight[pair_index] = w_min/fusion_multiplier_eff;
193  }
194  else
195  {
196  p_mask[pair_index] = false;
197  }
198 
199 }
200 
201 
202 #endif // SINGLE_NUCLEAR_FUSION_EVENT_H_
AMREX_GPU_HOST_DEVICE AMREX_INLINE amrex::ParticleReal ProtonBoronFusionCrossSection(const amrex::ParticleReal &E_kin_star)
Computes the total proton-boron fusion cross section. When E_kin_star < 3.5 MeV, we use the analytica...
Definition: ProtonBoronFusionCrossSection.H:136
AMREX_GPU_HOST_DEVICE constexpr const AMREX_FORCE_INLINE T & max(const T &a, const T &b) noexcept
Real Random()
def x
Definition: read_lab_particles.py:26
static constexpr auto c
vacuum speed of light [m/s]
Definition: constant.H:44
AMREX_GPU_HOST_DEVICE AMREX_INLINE void SingleNuclearFusionEvent(const amrex::ParticleReal &u1x, const amrex::ParticleReal &u1y, const amrex::ParticleReal &u1z, const amrex::ParticleReal &u2x, const amrex::ParticleReal &u2y, const amrex::ParticleReal &u2z, const amrex::ParticleReal &m1, const amrex::ParticleReal &m2, amrex::ParticleReal w1, amrex::ParticleReal w2, const amrex::Real &dt, const amrex::ParticleReal &dV, const int &pair_index, index_type *AMREX_RESTRICT p_mask, amrex::ParticleReal *AMREX_RESTRICT p_pair_reaction_weight, const amrex::ParticleReal &fusion_multiplier, const int &multiplier_ratio, const amrex::ParticleReal &probability_threshold, const amrex::ParticleReal &probability_target_value, const NuclearFusionType &fusion_type, const amrex::RandomEngine &engine)
This function computes whether the collision between two particles result in a nuclear fusion event...
Definition: SingleNuclearFusionEvent.H:54
AMREX_GPU_HOST_DEVICE AMREX_INLINE amrex::ParticleReal BoschHaleFusionCrossSection(const amrex::ParticleReal &E_kin_star, const NuclearFusionType &fusion_type, const amrex::ParticleReal &m1, const amrex::ParticleReal &m2)
Computes the fusion cross section, using the analytical fits given in H.-S. Bosch and G...
Definition: BoschHaleFusionCrossSection.H:27
int dt
Definition: Stencil.py:468
#define AMREX_GPU_HOST_DEVICE
ParticleBins::index_type index_type
Definition: ParticleUtils.cpp:32
#define AMREX_INLINE
AMREX_GPU_HOST_DEVICE constexpr const AMREX_FORCE_INLINE T & min(const T &a, const T &b) noexcept
NuclearFusionType
Definition: BinaryCollisionUtils.H:22