WarpX
Loading...
Searching...
No Matches
UpdateMomentumPerezElastic.H
Go to the documentation of this file.
1/* Copyright 2019 Yinjian Zhao
2 *
3 * This file is part of WarpX.
4 *
5 * License: BSD-3-Clause-LBNL
6 */
7#ifndef WARPX_PARTICLES_COLLISION_UPDATE_MOMENTUM_PEREZ_ELASTIC_H_
8#define WARPX_PARTICLES_COLLISION_UPDATE_MOMENTUM_PEREZ_ELASTIC_H_
9
10#include "Utils/WarpXConst.H"
11
12#include <AMReX_Math.H>
13#include <AMReX_Random.H>
14
15#include <cmath> // isnan() isinf()
16#include <limits> // numeric_limits<float>::min()
17
18/* \brief Update particle velocities according to
19 * F. Perez et al., Phys.Plasmas.19.083104 (2012),
20 * which is based on Nanbu's method, PhysRevE.55.4642 (1997).
21 * @param[in] bmax is max(Debye length, minimal interparticle distance).
22 * @param[in] L is the Coulomb log. A fixed L will be used if L > 0,
23 * otherwise L will be calculated based on the algorithm.
24 * @param[in] n12 = max(w1,w2)*min(N1,N2)/dV is the effective density used for s12
25 * @param[in] sigma_max is the maximum cross section based on mfp = atomic spacing
26 * used for the normalized scattering length s12 (see Sec. II.C of Perez et al.)
27 * To see if there are nan or inf updated velocities,
28 * compile with USE_ASSERTION=TRUE.
29 *
30 * Updates and corrections to the original publication are documented in
31 * https://github.com/BLAST-WarpX/warpx/issues/429
32 * https://github.com/BLAST-WarpX/warpx/files/3799803/main.pdf
33 */
34
35template <typename T_PR, typename T_R>
38 T_PR& u1x, T_PR& u1y, T_PR& u1z, T_PR& u2x, T_PR& u2y, T_PR& u2z,
39 T_PR const q1, T_PR const m1, T_PR const w1,
40 T_PR const q2, T_PR const m2, T_PR const w2,
41 T_PR const n12, T_PR const sigma_max,
42 T_PR const L, T_PR const bmax,
43 T_R const dt, amrex::RandomEngine const& engine )
44{
45
46 T_PR constexpr inv_c2 = T_PR(1.0) / ( PhysConst::c * PhysConst::c );
47
48 // Compute Lorentz factor gamma
49 T_PR const gb1sq = (u1x*u1x + u1y*u1y + u1z*u1z)*inv_c2;
50 T_PR const gb2sq = (u2x*u2x + u2y*u2y + u2z*u2z)*inv_c2;
51 T_PR const g1 = std::sqrt( T_PR(1.0) + gb1sq );
52 T_PR const g2 = std::sqrt( T_PR(1.0) + gb2sq );
53
54 T_PR const diffx = u1x-u2x;
55 T_PR const diffy = u1y-u2y;
56 T_PR const diffz = u1z-u2z;
57 T_PR const diffm = std::sqrt((diffx*diffx+diffy*diffy+diffz*diffz)*inv_c2);
58 T_PR const summm = std::sqrt(gb1sq) + std::sqrt(gb2sq);
59 // If g = u1 - u2 = 0, do not collide.
60 // Or if the relative difference is less than 1.0e-10.
61 if ( diffm < std::numeric_limits<T_PR>::min() || diffm/summm < 1.0e-10 ) { return; }
62
63 // Compute momenta
64 T_PR const p1x = u1x * m1;
65 T_PR const p1y = u1y * m1;
66 T_PR const p1z = u1z * m1;
67 T_PR const p2x = u2x * m2;
68 T_PR const p2y = u2y * m2;
69 T_PR const p2z = u2z * m2;
70
71 // Compute center-of-momentum (COM) velocity and gamma
72 T_PR const mass_g = m1 * g1 + m2 * g2;
73 T_PR const vcx = (p1x+p2x) / mass_g;
74 T_PR const vcy = (p1y+p2y) / mass_g;
75 T_PR const vcz = (p1z+p2z) / mass_g;
76 T_PR const vcms = vcx*vcx + vcy*vcy + vcz*vcz;
77 T_PR const gc = T_PR(1.0) / std::sqrt( T_PR(1.0) - vcms*inv_c2 );
78
79 // Compute vc dot v1 and v2
80 T_PR const vcDv1 = (vcx*u1x + vcy*u1y + vcz*u1z) / g1;
81 T_PR const vcDv2 = (vcx*u2x + vcy*u2y + vcz*u2z) / g2;
82
83 // Compute p1 star
84 // lorentz_transform_factor = ( (gc-1.0)/vcms*vcDv1 - gc )*m1*g1
85 // Rewrite by multiplying and dividing first term by (gc+1) to
86 // avoid loss of precision when gc is close to 1
87 T_PR const lorentz_transform_factor =
88 ( gc*gc*vcDv1*inv_c2/(T_PR(1.0) + gc) - gc )*m1*g1;
89 T_PR const p1sx = p1x + vcx*lorentz_transform_factor;
90 T_PR const p1sy = p1y + vcy*lorentz_transform_factor;
91 T_PR const p1sz = p1z + vcz*lorentz_transform_factor;
92 T_PR const p1sm = std::sqrt( p1sx*p1sx + p1sy*p1sy + p1sz*p1sz );
93
94 // Compute gamma star
95 T_PR const g1s = ( T_PR(1.0) - vcDv1*inv_c2 )*gc*g1;
96 T_PR const g2s = ( T_PR(1.0) - vcDv2*inv_c2 )*gc*g2;
97
98 // Compute relative velocity in center-of-momentum frame
99 // (not a Lorentz invariant quantity)
100 T_PR const muRst = g1s*m1*g2s*m2/(g1s*m1 + g2s*m2);
101 T_PR const vrelst = p1sm/muRst; // |v1s - v2s|
102
103 // Compute invariant relative velocity in center-of-momentum frame
104 // (Lorentz invariant quantity)
105 T_PR const denom = T_PR(1.0) + p1sm*p1sm/(m1*g1s*m2*g2s)*inv_c2; // (1.0 - v1s*v2s/c^2)
106 T_PR const vrelst_invar = vrelst/denom; // |v1s - v2s|/(1.0 - v1s*v2s/c^2)
107
108 // Compute s12
109 T_PR s12 = 0;
110 if (p1sm > std::numeric_limits<T_PR>::min()) {
111
112 // Writing b0 in a form that is directly analagous to the well-known non-relativistic form.
113 // See Eq. 3.3.2 in Principles of Plasma Discharges and Material Processing by
114 // M. A. Lieberman and A. J. Lichtenberg.
115 // Note that b0 on Eq. 22 of Perez POP 19 (2012) is bmin = b0/2,
116 // Note: there is a typo in Eq 22 of Perez, the last square is incorrect!
117 // See the SMILEI documentation: https://smileipic.github.io/Smilei/Understand/collisions.html
118 // and https://github.com/BLAST-WarpX/warpx/files/3799803/main.pdf from GitHub #429
119 T_PR const b0 = amrex::Math::abs(q1*q2) /
120 (T_PR(2.0)*MathConst::pi*PhysConst::ep0*muRst*vrelst*vrelst_invar);
121
122
123 // Compute the Coulomb log lnLmd first
124 T_PR lnLmd;
125 if ( L > T_PR(0.0) ) { lnLmd = L; }
126 else
127 {
128
129 // Compute the minimum impact parameter from quantum: bqm = lDB/(4*pi) = hbar/(2*p1sm)
130 // See NRL formulary. Also see "An introduction to the physics of the Coulomb logarithm,
131 // with emphasis on quantum-mechanical effects", J. Plasma Phys. vol. 85 (2019). by J.A. Krommes.
132 // Note: The formula in Perez 2012 and in Lee and More 1984 uses h rather than
133 // hbar for bqm. If this is used, then the transition energy where bmin goes from classical
134 // to quantum is only 2.5 eV for electrons; compared to 100 eV when using hbar.
135 const T_PR bmin_qm = static_cast<T_PR>(PhysConst::hbar*0.5/p1sm);
136
137 // Set the minimum impact parameter
138 const T_PR bmin = amrex::max(bmin_qm, T_PR(0.5)*b0);
139
140 // Compute the Coulomb log lnLmd
141 lnLmd = amrex::max( T_PR(2.0),
142 T_PR(0.5)*std::log(T_PR(1.0) + bmax*bmax/(bmin*bmin)) );
143 }
144
145 // Compute s12 with sigma limited by sigma_max where mfp = atomic spacing
146 // See https://github.com/user-attachments/files/16555064/CoulombScattering_s12.pdf
147 // for a proof that this expression for s12 is the same as Eq. 9 of Perez 2012 when
148 // sigma_eff = pi*b0^2*lnLmd
149 const T_PR sigma_eff = amrex::min(T_PR(MathConst::pi)*b0*b0*lnLmd,sigma_max);
150 s12 = sigma_eff * n12 * dt * vrelst * g1s*g2s/(g1*g2);
151
152 }
153
154 // Only modify momenta if s12 is non-zero
155 if (s12 > std::numeric_limits<T_PR>::min()) {
156
157 // Get random numbers
158 T_PR r = amrex::Random(engine);
159
160 // Compute scattering angle
161 T_PR cosXs;
162 T_PR sinXs;
163 if ( s12 <= T_PR(0.1) )
164 {
165 while ( true )
166 {
167 cosXs = T_PR(1.0) + s12 * std::log(r);
168 // Avoid the bug when r is too small such that cosXs < -1
169 if ( cosXs >= T_PR(-1.0) ) { break; }
170 r = amrex::Random(engine);
171 }
172 }
173 else if ( s12 > T_PR(0.1) && s12 <= T_PR(3.0) )
174 {
175 T_PR const Ainv = static_cast<T_PR>(
176 0.0056958 + 0.9560202*s12 - 0.508139*s12*s12 +
177 0.47913906*s12*s12*s12 - 0.12788975*s12*s12*s12*s12 + 0.02389567*s12*s12*s12*s12*s12);
178 cosXs = Ainv * std::log( std::exp(T_PR(-1.0)/Ainv) +
179 T_PR(2.0) * r * std::sinh(T_PR(1.0)/Ainv) );
180 }
181 else if ( s12 > T_PR(3.0) && s12 <= T_PR(6.0) )
182 {
183 T_PR const A = T_PR(3.0) * std::exp(-s12);
184 cosXs = T_PR(1.0)/A * std::log( std::exp(-A) +
185 T_PR(2.0) * r * std::sinh(A) );
186 }
187 else
188 {
189 cosXs = T_PR(2.0) * r - T_PR(1.0);
190 }
191 sinXs = std::sqrt(T_PR(1.0) - cosXs*cosXs);
192
193 // Get random azimuthal angle
194 T_PR const phis = amrex::Random(engine) * T_PR(2.0) * MathConst::pi;
195 T_PR const cosphis = std::cos(phis);
196 T_PR const sinphis = std::sin(phis);
197
198 // Compute post-collision momenta pfs in COM
199 T_PR p1fsx;
200 T_PR p1fsy;
201 T_PR p1fsz;
202 // p1sp is the p1s perpendicular
203 T_PR p1sp = std::sqrt( p1sx*p1sx + p1sy*p1sy );
204 // Make sure p1sp is not almost zero
205 if ( p1sp > std::numeric_limits<T_PR>::min() )
206 {
207 p1fsx = ( p1sx*p1sz/p1sp ) * sinXs*cosphis +
208 ( p1sy*p1sm/p1sp ) * sinXs*sinphis +
209 ( p1sx ) * cosXs;
210 p1fsy = ( p1sy*p1sz/p1sp ) * sinXs*cosphis +
211 (-p1sx*p1sm/p1sp ) * sinXs*sinphis +
212 ( p1sy ) * cosXs;
213 p1fsz = (-p1sp ) * sinXs*cosphis +
214 ( T_PR(0.0) ) * sinXs*sinphis +
215 ( p1sz ) * cosXs;
216 // Note a negative sign is different from
217 // Eq. (12) in Perez's paper,
218 // but they are the same due to the random nature of phis.
219 }
220 else
221 {
222 // If the previous p1sp is almost zero
223 // x->y y->z z->x
224 // This set is equivalent to the one in Nanbu's paper
225 p1sp = std::sqrt( p1sy*p1sy + p1sz*p1sz );
226 p1fsy = ( p1sy*p1sx/p1sp ) * sinXs*cosphis +
227 ( p1sz*p1sm/p1sp ) * sinXs*sinphis +
228 ( p1sy ) * cosXs;
229 p1fsz = ( p1sz*p1sx/p1sp ) * sinXs*cosphis +
230 (-p1sy*p1sm/p1sp ) * sinXs*sinphis +
231 ( p1sz ) * cosXs;
232 p1fsx = (-p1sp ) * sinXs*cosphis +
233 ( T_PR(0.0) ) * sinXs*sinphis +
234 ( p1sx ) * cosXs;
235 }
236
237 T_PR const p2fsx = -p1fsx;
238 T_PR const p2fsy = -p1fsy;
239 T_PR const p2fsz = -p1fsz;
240
241 // Transform from COM to lab frame
242 T_PR const vcDp1fs = vcx*p1fsx + vcy*p1fsy + vcz*p1fsz;
243 T_PR const vcDp2fs = vcx*p2fsx + vcy*p2fsy + vcz*p2fsz;
244 /* factor = (gc-1.0)/vcms; Rewrite to avoid subtraction losing precision when gc is close to 1 */
245 T_PR const factor = gc*gc*inv_c2/(gc+T_PR(1.0));
246 T_PR const factor1 = factor*vcDp1fs + m1*g1s*gc;
247 T_PR const factor2 = factor*vcDp2fs + m2*g2s*gc;
248 T_PR const p1fx = p1fsx + vcx * factor1;
249 T_PR const p1fy = p1fsy + vcy * factor1;
250 T_PR const p1fz = p1fsz + vcz * factor1;
251 T_PR const p2fx = p2fsx + vcx * factor2;
252 T_PR const p2fy = p2fsy + vcy * factor2;
253 T_PR const p2fz = p2fsz + vcz * factor2;
254
255 // Rejection method
256 r = amrex::Random(engine);
257 if ( w2 > r*amrex::max(w1, w2) )
258 {
259 u1x = p1fx / m1;
260 u1y = p1fy / m1;
261 u1z = p1fz / m1;
262 }
263 r = amrex::Random(engine);
264 if ( w1 > r*amrex::max(w1, w2) )
265 {
266 u2x = p2fx / m2;
267 u2y = p2fy / m2;
268 u2z = p2fz / m2;
269 }
270#ifndef AMREX_USE_DPCPP
271 AMREX_ASSERT(!std::isnan(u1x+u1y+u1z+u2x+u2y+u2z));
272 AMREX_ASSERT(!std::isinf(u1x+u1y+u1z+u2x+u2y+u2z));
273#endif
274
275 } // if s > std::numeric_limits<T_PR>::min()
276
277}
278
279#endif // WARPX_PARTICLES_COLLISION_UPDATE_MOMENTUM_PEREZ_ELASTIC_H_
#define AMREX_ASSERT(EX)
#define AMREX_INLINE
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_INLINE void UpdateMomentumPerezElastic(T_PR &u1x, T_PR &u1y, T_PR &u1z, T_PR &u2x, T_PR &u2y, T_PR &u2z, T_PR const q1, T_PR const m1, T_PR const w1, T_PR const q2, T_PR const m2, T_PR const w2, T_PR const n12, T_PR const sigma_max, T_PR const L, T_PR const bmax, T_R const dt, amrex::RandomEngine const &engine)
Definition UpdateMomentumPerezElastic.H:37
static constexpr auto c
vacuum speed of light [m/s]
Definition constant.H:44
static constexpr auto ep0
vacuum permittivity: dielectric permittivity of vacuum [F/m]
Definition constant.H:46
static constexpr auto hbar
reduced Planck Constant = h / tau [J*s]
Definition constant.H:61
static constexpr amrex::Real pi
ratio of a circle's circumference to its diameter
Definition constant.H:23
Real Random()
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept