WarpX
Loading...
Searching...
No Matches
BinaryCollisionUtils.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 WARPX_BINARY_COLLISION_UTILS_H_
9#define WARPX_BINARY_COLLISION_UTILS_H_
10
11#include <string>
12
14
15#include <AMReX_Math.H>
16
28
36
37namespace BinaryCollisionUtils{
38
39 NuclearFusionType get_nuclear_fusion_type (const std::string& collision_name,
40 MultiParticleContainer const * mypc);
41
42 CollisionType get_collision_type (const std::string& collision_name,
43 MultiParticleContainer const * mypc);
44
46
54 const amrex::ParticleReal& p1x, const amrex::ParticleReal& p1y,
55 const amrex::ParticleReal& p1z, const amrex::ParticleReal& p2x,
56 const amrex::ParticleReal& p2y, const amrex::ParticleReal& p2z,
57 const amrex::ParticleReal& m1, const amrex::ParticleReal& m2,
58 amrex::ParticleReal& E_kin_COM, amrex::ParticleReal& v_rel_COM,
59 amrex::ParticleReal& lab_to_COM_lorentz_factor )
60 {
61 // General notations in this function:
62 // x_sq denotes the square of x
63 // x_star denotes the value of x in the center of mass frame
64
65 using namespace amrex::literals;
66 using namespace amrex::Math;
67
68 constexpr double c = PhysConst::c;
69 constexpr double c_sq = PhysConst::c * PhysConst::c;
70 constexpr double inv_c = 1./PhysConst::c;
71
72 // Cast input parameters to double before computing collision properties
73 // This is needed to avoid errors when using single-precision particles
74 const auto m1_dbl = static_cast<double>(m1);
75 const auto m2_dbl = static_cast<double>(m2);
76 const auto p1x_dbl = static_cast<double>(p1x);
77 const auto p1y_dbl = static_cast<double>(p1y);
78 const auto p1z_dbl = static_cast<double>(p1z);
79 const auto p2x_dbl = static_cast<double>(p2x);
80 const auto p2y_dbl = static_cast<double>(p2y);
81 const auto p2z_dbl = static_cast<double>(p2z);
82
83 const double m1_sq = m1_dbl*m1_dbl;
84 const double m2_sq = m2_dbl*m2_dbl;
85
86 // Square norm of the total (sum between the two particles) momenta in the lab frame
87 const double p_total_sq = powi<2>(p1x_dbl + p2x_dbl) + powi<2>(p1y_dbl + p2y_dbl) + powi<2>(p1z_dbl + p2z_dbl);
88
89 // Total energy in the lab frame
90 // Note the use of `double` for energy since this calculation is prone to error with single precision.
91 const double E1_lab = std::sqrt( m1_sq * c_sq + p1x_dbl*p1x_dbl + p1y_dbl*p1y_dbl + p1z_dbl*p1z_dbl ) * c;
92 const double E2_lab = std::sqrt( m2_sq * c_sq + p2x_dbl*p2x_dbl + p2y_dbl*p2y_dbl + p2z_dbl*p2z_dbl ) * c;
93 const double E_lab = E1_lab + E2_lab;
94 // Total energy squared in the center of mass frame, calculated using the Lorentz invariance
95 // of the four-momentum norm
96 const double E_star_sq = E_lab*E_lab - c_sq*p_total_sq;
97
98 // Kinetic energy in the center of mass frame
99 const double E_star = std::sqrt(E_star_sq);
100
101 // Cast back to chosen precision for output
102 E_kin_COM = static_cast<amrex::ParticleReal>(E_star - (m1_dbl + m2_dbl)*c_sq);
103
104 // Find the norm of the momentum of each particles in the center of mass frame
105 // This is done by solving the following system (in the COM frame)
106 // E_1^2 = p^2 c^2 + m_1^2 c^4 (for the first particle)
107 // E_2^2 = p^2 c^2 + m_2^2 c^4 (for the second particle ; same p since we are in the COM frame)
108 // to find the expression of the p as a function of E = E_1 + E_2.
109 // Here is an abbreviation derivation:
110 // - By summing the above equations
111 // E^2 = E_1^2 + E_2^2 + 2 E_1 E_2 = 2 p^2 c^2 + (m_1^2 + m_2^2) c^4 + 2 E_1 E_2
112 // - Rearranging and squaring
113 // ( E^2 - 2 p^2 c^2 - (m_1^2 + m_2^2) c^4 )^2 = 4 E_1^2 E_2^2 = 4 (p^2 c^2 + m_1^2 c^4) (p^2 c^2 + m_2^2 c^4)
114 // - By rearranging, we get:
115 // p^2 = E^2/4c^2 - (m_1^2 + m_2^2)c^2/2 + (m_1^2-m_2^2)^2 c^6/4E^2
116 double p_star_sq;
117 if (m1_dbl + m2_dbl == 0) {
118 p_star_sq = powi<2>( 0.5 * E_star * inv_c );
119 } else {
120 // The expression below is specifically written in a form that avoids returning
121 // small negative numbers due to machine precision errors, for low-energy particles
122 const double E_ratio = E_star/((m1_dbl + m2_dbl)*c_sq);
123 p_star_sq = m1_dbl*m2_dbl*c_sq * ( powi<2>(E_ratio) - 1.0 )
124 + powi<2>(m1_dbl - m2_dbl)*c_sq/4.0 * powi<2>( E_ratio - 1.0/E_ratio);
125 }
126
127 // Energy of each particle in the center of mass frame
128 const double E1_star = std::sqrt(m1_sq*c_sq + p_star_sq) * c;
129 const double E2_star = std::sqrt(m2_sq*c_sq + p_star_sq) * c;
130
131 // relative velocity in the center of mass frame, cast back to chosen precision
132 v_rel_COM = PhysConst::c * static_cast<amrex::ParticleReal>(std::sqrt(p_star_sq) * c * (1.0/E1_star + 1.0/E2_star));
133
134 // Cross sections and relative velocity are computed in the center of mass frame.
135 // On the other hand, the particle densities (weight over volume) in the lab frame are used.
136 // To take this discrepancy into account, it is needed to multiply the
137 // collision probability by the ratio between the Lorentz factors in the
138 // COM frame and the Lorentz factors in the lab frame (see Perez et al.,
139 // Phys.Plasmas.19.083104 (2012)). The correction factor is calculated here.
140 lab_to_COM_lorentz_factor = static_cast<amrex::ParticleReal>(E1_star*E2_star/(E1_lab*E2_lab));
141 }
142
149 amrex::ParticleReal& weight, uint64_t& idcpu,
150 const amrex::ParticleReal reaction_weight )
151 {
152 // Remove weight from given particle
153 amrex::Gpu::Atomic::AddNoRet(&weight, -reaction_weight);
154
155 // If the colliding particle weight decreases to zero, remove particle by
156 // setting its id to invalid
157 if (weight <= std::numeric_limits<amrex::ParticleReal>::min())
158 {
159#if defined(AMREX_USE_OMP)
160#pragma omp atomic write
162#else
164 (unsigned long long *)&idcpu,
165 (unsigned long long)amrex::ParticleIdCpus::Invalid
166 );
167#endif
168 }
169 }
170}
171
172#endif // WARPX_BINARY_COLLISION_UTILS_H_
#define AMREX_INLINE
#define AMREX_GPU_HOST_DEVICE
CollisionType
Definition BinaryCollisionUtils.H:17
@ LinearBreitWheeler
Definition BinaryCollisionUtils.H:25
@ ProtonBoronToAlphasFusion
Definition BinaryCollisionUtils.H:21
@ Bremsstrahlung
Definition BinaryCollisionUtils.H:22
@ PairwiseCoulomb
Definition BinaryCollisionUtils.H:24
@ DSMC
Definition BinaryCollisionUtils.H:23
@ DeuteriumDeuteriumToProtonTritiumFusion
Definition BinaryCollisionUtils.H:18
@ DeuteriumDeuteriumToNeutronHeliumFusion
Definition BinaryCollisionUtils.H:19
@ DeuteriumTritiumToNeutronHeliumFusion
Definition BinaryCollisionUtils.H:17
@ LinearCompton
Definition BinaryCollisionUtils.H:26
@ DeuteriumHeliumToProtonHeliumFusion
Definition BinaryCollisionUtils.H:20
@ Undefined
Definition BinaryCollisionUtils.H:27
NuclearFusionType
Definition BinaryCollisionUtils.H:29
@ DeuteriumHeliumToProtonHelium
Definition BinaryCollisionUtils.H:33
@ ProtonBoronToAlphas
Definition BinaryCollisionUtils.H:34
@ DeuteriumDeuteriumToProtonTritium
Definition BinaryCollisionUtils.H:31
@ DeuteriumDeuteriumToNeutronHelium
Definition BinaryCollisionUtils.H:32
@ DeuteriumTritiumToNeutronHelium
Definition BinaryCollisionUtils.H:30
Definition BinaryCollisionUtils.cpp:20
CollisionType get_collision_type(const std::string &collision_name, MultiParticleContainer const *const mypc)
Definition BinaryCollisionUtils.cpp:22
CollisionType nuclear_fusion_type_to_collision_type(const NuclearFusionType fusion_type)
Definition BinaryCollisionUtils.cpp:186
AMREX_GPU_HOST_DEVICE AMREX_INLINE void get_collision_parameters(const amrex::ParticleReal &p1x, const amrex::ParticleReal &p1y, const amrex::ParticleReal &p1z, const amrex::ParticleReal &p2x, const amrex::ParticleReal &p2y, const amrex::ParticleReal &p2z, const amrex::ParticleReal &m1, const amrex::ParticleReal &m2, amrex::ParticleReal &E_kin_COM, amrex::ParticleReal &v_rel_COM, amrex::ParticleReal &lab_to_COM_lorentz_factor)
Return (relativistic) collision energy, collision speed and Lorentz factor for transforming between t...
Definition BinaryCollisionUtils.H:53
AMREX_GPU_HOST_DEVICE AMREX_INLINE void remove_weight_from_colliding_particle(amrex::ParticleReal &weight, uint64_t &idcpu, const amrex::ParticleReal reaction_weight)
Subtract given weight from particle and set its ID to invalid if the weight reaches zero.
Definition BinaryCollisionUtils.H:148
NuclearFusionType get_nuclear_fusion_type(const std::string &collision_name, MultiParticleContainer const *const mypc)
Definition BinaryCollisionUtils.cpp:101
constexpr auto c
vacuum speed of light [m/s]
Definition constant.H:149
__host__ __device__ AMREX_FORCE_INLINE T Exch(T *address, T val) noexcept
__host__ __device__ AMREX_FORCE_INLINE void AddNoRet(T *sum, T value) noexcept
constexpr T powi(T x) noexcept
constexpr std::uint64_t Invalid