WarpX
Loading...
Searching...
No Matches
LinearBreitWheelerUtil.H
Go to the documentation of this file.
1/* Copyright 2023 Arianna Formenti
2 *
3 * This file is part of WarpX.
4 *
5 * License: BSD-3-Clause-LBNL
6 */
7
8#ifndef LINEAR_BREIT_WHEELER_UTIL_H
9#define LINEAR_BREIT_WHEELER_UTIL_H
10
11#include "Utils/ParticleUtils.H"
12#include "Utils/WarpXConst.H"
13
14#include <AMReX_Random.H>
15#include <AMReX_REAL.H>
16
17#include <cmath>
18#include <limits>
19
20namespace {
43 void LinearBreitWheelerComputeProductMomenta (
44 const amrex::ParticleReal& u1x_in,
45 const amrex::ParticleReal& u1y_in,
46 const amrex::ParticleReal& u1z_in,
47 const amrex::ParticleReal& u2x_in,
48 const amrex::ParticleReal& u2y_in,
49 const amrex::ParticleReal& u2z_in,
50 amrex::ParticleReal& u1x_out,
51 amrex::ParticleReal& u1y_out,
52 amrex::ParticleReal& u1z_out,
53 amrex::ParticleReal& u2x_out,
54 amrex::ParticleReal& u2y_out,
55 amrex::ParticleReal& u2z_out,
56 const amrex::RandomEngine& engine )
57 {
58 using namespace amrex::literals;
59
60 constexpr amrex::ParticleReal c_sq = PhysConst::c * PhysConst::c;
61 constexpr amrex::ParticleReal inv_csq = 1._prt / ( c_sq );
62 constexpr amrex::ParticleReal me = PhysConst::m_e;
63 auto constexpr pow2 = [](double const x) { return x*x; };
64 constexpr auto one_half_pr = amrex::ParticleReal(1./2.);
65 constexpr auto one_pr = amrex::ParticleReal(1.);
66
67 // Compute momenta
68 const amrex::ParticleReal p1x_in = u1x_in * me;
69 const amrex::ParticleReal p1y_in = u1y_in * me;
70 const amrex::ParticleReal p1z_in = u1z_in * me;
71 const amrex::ParticleReal p2x_in = u2x_in * me;
72 const amrex::ParticleReal p2y_in = u2y_in * me;
73 const amrex::ParticleReal p2z_in = u2z_in * me;
74 const amrex::ParticleReal p1_in = std::sqrt(pow2(p1x_in)+pow2(p1y_in)+pow2(p1z_in));
75 const amrex::ParticleReal p2_in = std::sqrt(pow2(p2x_in)+pow2(p2y_in)+pow2(p2z_in));
76
77 // Compute cosine of the angle between the two photon momenta in the lab frame
78 const amrex::ParticleReal cos_ang = (p1x_in*p2x_in+p1y_in*p2y_in+p1z_in*p2z_in)/(p1_in*p2_in);
79
80 // Energy squared of each of the two colliding photons in the center of momentum frame,
81 // calculated using the Lorentz invariance of the total four-momentum norm
82 const amrex::ParticleReal E_star_sq = one_half_pr*c_sq*p1_in*p2_in*(one_pr - cos_ang);
83
84 // Square of the norm of the momentum of the products in the center of mass frame
85 // Formula obtained by inverting E^2 = p^2*c^2 + m^2*c^4 in the COM frame for each particle:
86 // p_star_sq = E_star_sq/c_sq - me*me*c_sq;
87 // The expression below is specifically written in a form that avoids returning
88 // small negative numbers due to machine precision errors, for low-energy particles
89 const amrex::ParticleReal E_ratio = std::sqrt(E_star_sq)/(2._prt*me*c_sq);
90 const amrex::ParticleReal p_star_sq = me*me*c_sq * ( pow2(2._prt*E_ratio) - 1._prt );
91
92 // Compute momentum of first product in the center of mass frame, assuming isotropic
93 // distribution
94 amrex::ParticleReal px_star, py_star, pz_star;
95 ParticleUtils::RandomizeVelocity(px_star, py_star, pz_star, std::sqrt(p_star_sq),
96 engine);
97
98 // Next step is to convert momenta to lab frame
99 amrex::ParticleReal p1x_out, p1y_out, p1z_out;
100 // Preliminary calculation: compute velocity of the center of momentum frame:
101 // v = (p1 + p2) / | p1 + p2 | * c
102 const amrex::ParticleReal vcx = (p1x_in+p2x_in) * PhysConst::c / (p1_in + p2_in);
103 const amrex::ParticleReal vcy = (p1y_in+p2y_in) * PhysConst::c / (p1_in + p2_in);
104 const amrex::ParticleReal vcz = (p1z_in+p2z_in) * PhysConst::c / (p1_in + p2_in);
105 const amrex::ParticleReal vc_sq = vcx*vcx + vcy*vcy + vcz*vcz;
106
107 // Convert momentum of first product to lab frame, using equation (13) of F. Perez et al.,
108 // Phys.Plasmas.19.083104 (2012) (which is a regular Lorentz transformation)
109 if ( vc_sq > std::numeric_limits<amrex::ParticleReal>::min() )
110 {
111 const amrex::ParticleReal gc = 1._prt / std::sqrt( 1._prt - vc_sq*inv_csq );
112 const amrex::ParticleReal g_star = std::sqrt(1._prt + p_star_sq / (me*me*c_sq));
113 const amrex::ParticleReal vcDps = vcx*px_star + vcy*py_star + vcz*pz_star;
114 const amrex::ParticleReal factor0 = (gc-1._prt)/vc_sq;
115 const amrex::ParticleReal factor = factor0*vcDps + me*g_star*gc;
116 p1x_out = px_star + vcx * factor;
117 p1y_out = py_star + vcy * factor;
118 p1z_out = pz_star + vcz * factor;
119 }
120 else // If center of mass velocity is zero, we are already in the lab frame
121 {
122 p1x_out = px_star;
123 p1y_out = py_star;
124 p1z_out = pz_star;
125 }
126
127 // Compute momentum of electron/positron in lab frame, using total momentum conservation
128 const amrex::ParticleReal p2x_out = p1x_in + p2x_in - p1x_out;
129 const amrex::ParticleReal p2y_out = p1y_in + p2y_in - p1y_out;
130 const amrex::ParticleReal p2z_out = p1z_in + p2z_in - p1z_out;
131
132 // Compute the momentum of the product macroparticles
133 u1x_out = p1x_out/me;
134 u1y_out = p1y_out/me;
135 u1z_out = p1z_out/me;
136 u2x_out = p2x_out/me;
137 u2y_out = p2y_out/me;
138 u2z_out = p2z_out/me;
139 }
140}
141
142#endif // LINEAR_BREIT_WHEELER_UTIL_H
#define AMREX_INLINE
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_INLINE void RandomizeVelocity(amrex::ParticleReal &ux, amrex::ParticleReal &uy, amrex::ParticleReal &uz, const amrex::ParticleReal vp, amrex::RandomEngine const &engine)
Function to perform scattering of a particle that results in a random velocity vector with given magn...
Definition ParticleUtils.H:218
constexpr auto c
vacuum speed of light [m/s]
Definition constant.H:149
constexpr auto m_e
electron mass [kg]
Definition constant.H:161