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
15
16#include <AMReX_Math.H>
17#include <AMReX_Vector.H>
18
30
38
39namespace BinaryCollisionUtils{
40
41 NuclearFusionType get_nuclear_fusion_type (const std::string& collision_name,
42 MultiParticleContainer const * mypc);
43
44 void CheckFusionEnergy (NuclearFusionType fusion_type,
45 amrex::ParticleReal mass_before,
46 amrex::ParticleReal mass_after);
47
48 CollisionType get_collision_type (const std::string& collision_name,
49 MultiParticleContainer const * mypc);
50
63 amrex::Vector<ScatteringProcess>
64 parse_scattering_processes (const std::string& collision_name);
65
68 {
72 }
75 }
78 }
81 }
82 else if (fusion_type == NuclearFusionType::ProtonBoronToAlphas) {
84 }
85 else {
87 WARPX_ABORT_WITH_MESSAGE("Invalid nuclear fusion type");
88 ))
89 }
90 return collision_type;
91 }
92
101
104 {
105 const CollisionType collision_type = nuclear_fusion_type_to_collision_type(fusion_type);
106 return is_two_product_fusion_type(collision_type);
107 }
108
116 const amrex::ParticleReal& p1x, const amrex::ParticleReal& p1y,
117 const amrex::ParticleReal& p1z, const amrex::ParticleReal& p2x,
118 const amrex::ParticleReal& p2y, const amrex::ParticleReal& p2z,
119 const amrex::ParticleReal& m1, const amrex::ParticleReal& m2,
120 amrex::ParticleReal& E_kin_COM, amrex::ParticleReal& v_rel_COM,
121 amrex::ParticleReal& lab_to_COM_lorentz_factor )
122 {
123 // General notations in this function:
124 // x_sq denotes the square of x
125 // x_star denotes the value of x in the center of mass frame
126
127 using namespace amrex::literals;
128 using namespace amrex::Math;
129
130 constexpr double c = PhysConst::c;
131 constexpr auto c2 = PhysConst::c2_v<double>;
132 constexpr double inv_c = 1./PhysConst::c;
133
134 // Cast input parameters to double before computing collision properties
135 // This is needed to avoid errors when using single-precision particles
136 const auto m1_dbl = static_cast<double>(m1);
137 const auto m2_dbl = static_cast<double>(m2);
138 const auto p1x_dbl = static_cast<double>(p1x);
139 const auto p1y_dbl = static_cast<double>(p1y);
140 const auto p1z_dbl = static_cast<double>(p1z);
141 const auto p2x_dbl = static_cast<double>(p2x);
142 const auto p2y_dbl = static_cast<double>(p2y);
143 const auto p2z_dbl = static_cast<double>(p2z);
144
145 const double m1_sq = m1_dbl*m1_dbl;
146 const double m2_sq = m2_dbl*m2_dbl;
147
148 // Square norm of the total (sum between the two particles) momenta in the lab frame
149 const double p_total_sq = powi<2>(p1x_dbl + p2x_dbl) + powi<2>(p1y_dbl + p2y_dbl) + powi<2>(p1z_dbl + p2z_dbl);
150
151 // Total energy in the lab frame
152 // Note the use of `double` for energy since this calculation is prone to error with single precision.
153 const double E1_lab = std::sqrt( m1_sq * c2 + p1x_dbl*p1x_dbl + p1y_dbl*p1y_dbl + p1z_dbl*p1z_dbl ) * c;
154 const double E2_lab = std::sqrt( m2_sq * c2 + p2x_dbl*p2x_dbl + p2y_dbl*p2y_dbl + p2z_dbl*p2z_dbl ) * c;
155 const double E_lab = E1_lab + E2_lab;
156 // Total energy squared in the center of mass frame, calculated using the Lorentz invariance
157 // of the four-momentum norm
158 const double E_star_sq = E_lab*E_lab - c2*p_total_sq;
159
160 // Kinetic energy in the center of mass frame
161 const double E_star = std::sqrt(E_star_sq);
162
163 // Cast back to chosen precision for output
164 E_kin_COM = static_cast<amrex::ParticleReal>(E_star - (m1_dbl + m2_dbl)*c2);
165
166 // Find the norm of the momentum of each particles in the center of mass frame
167 // This is done by solving the following system (in the COM frame)
168 // E_1^2 = p^2 c^2 + m_1^2 c^4 (for the first particle)
169 // 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)
170 // to find the expression of the p as a function of E = E_1 + E_2.
171 // Here is an abbreviation derivation:
172 // - By summing the above equations
173 // 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
174 // - Rearranging and squaring
175 // ( 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)
176 // - By rearranging, we get:
177 // 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
178 double p_star_sq;
179 if (m1_dbl + m2_dbl == 0) {
180 p_star_sq = powi<2>( 0.5 * E_star * inv_c );
181 } else {
182 // The expression below is specifically written in a form that avoids returning
183 // small negative numbers due to machine precision errors, for low-energy particles
184 const double E_ratio = E_star/((m1_dbl + m2_dbl)*c2);
185 p_star_sq = m1_dbl*m2_dbl*c2 * ( powi<2>(E_ratio) - 1.0 )
186 + powi<2>(m1_dbl - m2_dbl)*c2/4.0 * powi<2>( E_ratio - 1.0/E_ratio);
187 }
188
189 // Energy of each particle in the center of mass frame
190 const double E1_star = std::sqrt(m1_sq*c2 + p_star_sq) * c;
191 const double E2_star = std::sqrt(m2_sq*c2 + p_star_sq) * c;
192
193 // relative velocity in the center of mass frame, cast back to chosen precision
194 v_rel_COM = PhysConst::c * static_cast<amrex::ParticleReal>(std::sqrt(p_star_sq) * c * (1.0/E1_star + 1.0/E2_star));
195
196 // Cross sections and relative velocity are computed in the center of mass frame.
197 // On the other hand, the particle densities (weight over volume) in the lab frame are used.
198 // To take this discrepancy into account, it is needed to multiply the
199 // collision probability by the ratio between the Lorentz factors in the
200 // COM frame and the Lorentz factors in the lab frame (see Perez et al.,
201 // Phys.Plasmas.19.083104 (2012)). The correction factor is calculated here.
202 lab_to_COM_lorentz_factor = static_cast<amrex::ParticleReal>(E1_star*E2_star/(E1_lab*E2_lab));
203 }
204
211 amrex::ParticleReal& weight, uint64_t& idcpu,
212 const amrex::ParticleReal reaction_weight )
213 {
214 // Remove weight from given particle
215 amrex::Gpu::Atomic::AddNoRet(&weight, -reaction_weight);
216
217 // If the colliding particle weight decreases to zero, remove particle by
218 // setting its id to invalid
219 if (weight <= std::numeric_limits<amrex::ParticleReal>::min())
220 {
221#if defined(AMREX_USE_OMP)
222#pragma omp atomic write
224#else
226 (unsigned long long *)&idcpu,
227 (unsigned long long)amrex::ParticleIdCpus::Invalid
228 );
229#endif
230 }
231 }
232}
233
234#endif // WARPX_BINARY_COLLISION_UTILS_H_
#define AMREX_INLINE
#define AMREX_IF_ON_HOST(CODE)
#define AMREX_GPU_HOST_DEVICE
CollisionType
Definition BinaryCollisionUtils.H:19
@ LinearBreitWheeler
Definition BinaryCollisionUtils.H:27
@ ProtonBoronToAlphasFusion
Definition BinaryCollisionUtils.H:23
@ Bremsstrahlung
Definition BinaryCollisionUtils.H:24
@ PairwiseCoulomb
Definition BinaryCollisionUtils.H:26
@ DSMC
Definition BinaryCollisionUtils.H:25
@ DeuteriumDeuteriumToProtonTritiumFusion
Definition BinaryCollisionUtils.H:20
@ DeuteriumDeuteriumToNeutronHeliumFusion
Definition BinaryCollisionUtils.H:21
@ DeuteriumTritiumToNeutronHeliumFusion
Definition BinaryCollisionUtils.H:19
@ LinearCompton
Definition BinaryCollisionUtils.H:28
@ DeuteriumHeliumToProtonHeliumFusion
Definition BinaryCollisionUtils.H:22
@ Undefined
Definition BinaryCollisionUtils.H:29
NuclearFusionType
Definition BinaryCollisionUtils.H:31
@ DeuteriumHeliumToProtonHelium
Definition BinaryCollisionUtils.H:35
@ ProtonBoronToAlphas
Definition BinaryCollisionUtils.H:36
@ DeuteriumDeuteriumToProtonTritium
Definition BinaryCollisionUtils.H:33
@ DeuteriumDeuteriumToNeutronHelium
Definition BinaryCollisionUtils.H:34
@ DeuteriumTritiumToNeutronHelium
Definition BinaryCollisionUtils.H:32
#define WARPX_ABORT_WITH_MESSAGE(MSG)
Definition TextMsg.H:15
amrex_particle_real ParticleReal
Definition BinaryCollisionUtils.cpp:25
void CheckFusionEnergy(const NuclearFusionType fusion_type, const amrex::ParticleReal mass_before, const amrex::ParticleReal mass_after)
Definition BinaryCollisionUtils.cpp:247
CollisionType get_collision_type(const std::string &collision_name, MultiParticleContainer const *const mypc)
Definition BinaryCollisionUtils.cpp:27
AMREX_GPU_HOST_DEVICE AMREX_INLINE CollisionType nuclear_fusion_type_to_collision_type(NuclearFusionType fusion_type)
Definition BinaryCollisionUtils.H:67
AMREX_GPU_HOST_DEVICE AMREX_INLINE bool is_two_product_fusion_type(const CollisionType collision_type)
Definition BinaryCollisionUtils.H:94
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:115
amrex::Vector< ScatteringProcess > parse_scattering_processes(const std::string &collision_name)
Parse the list of scattering processes of a dsmc or background_mcc collision and build the correspond...
Definition BinaryCollisionUtils.cpp:107
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:210
NuclearFusionType get_nuclear_fusion_type(const std::string &collision_name, MultiParticleContainer const *const mypc)
Definition BinaryCollisionUtils.cpp:145
constexpr auto c
vacuum speed of light [m/s]
Definition constant.H:160
constexpr auto c2_v
square of the vacuum speed of light [m^2/s^2] (variable template)
Definition constant.H:145
__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