ImpactX
Loading...
Searching...
No Matches
ReferenceParticle.H
Go to the documentation of this file.
1/* Copyright 2022-2023 The Regents of the University of California, through Lawrence
2 * Berkeley National Laboratory (subject to receipt of any required
3 * approvals from the U.S. Dept. of Energy). All rights reserved.
4 *
5 * This file is part of ImpactX.
6 *
7 * Authors: Axel Huebl
8 * License: BSD-3-Clause-LBNL
9 */
10#ifndef IMPACTX_REFERENCE_PARTICLE_H
11#define IMPACTX_REFERENCE_PARTICLE_H
12
13#include <ablastr/constant.H>
14
15#include <AMReX_BLassert.H>
16#include <AMReX_Extension.H>
17#include <AMReX_GpuQualifiers.H>
18#include <AMReX_Math.H>
19#include <AMReX_REAL.H>
20#include <AMReX_SmallMatrix.H>
21
22#include <cmath>
23#include <stdexcept>
24#include <string>
25
26
27namespace impactx
28{
32 struct RefPart
33 {
46
48
55 copy () const
56 {
57 return RefPart{*this};
58 }
59
65 void
66 reset (bool keep_mass=false, bool keep_charge=false)
67 {
68 auto old_mass = mass;
69 auto old_charge = charge;
70
71 RefPart zero{};
72 *this = zero;
73
74 if (keep_mass) { mass = old_mass; }
75 if (keep_charge) { charge = old_charge; }
76 }
77
85 RefPart &
86 set_species (std::string const & species_name)
87 {
88 using namespace amrex::literals; // for _prt
89
93
96 amrex::ParticleReal g_anomaly;
97
98 // [known_species]
99 if (species_name == "electron") {
100 qe = -1.0;
101 massE = m_e / MeV_inv_c2;
102 g_anomaly = 0.00115965218062_prt;
103 } else if (species_name == "positron") {
104 qe = 1.0;
105 massE = m_e / MeV_inv_c2;
106 g_anomaly = 0.00115965218062_prt;
107 } else if (species_name == "proton") {
108 qe = 1.0;
109 massE = m_p / MeV_inv_c2;
110 g_anomaly = 1.7928473446_prt;
111 } else if (species_name == "Hminus") {
112 qe = -1.0;
113 massE = (m_p + 2.0_prt * m_e) / MeV_inv_c2; // neglect ~14 eV/c^2 binding energy
114 g_anomaly = 1.7928473446_prt;
115 }
116 // [/known_species]
117 else {
118 throw std::runtime_error(
119 "Unknown species: '" + species_name +
120 "'. Known species: electron, positron, proton, Hminus. "
121 "For other species, set charge, mass, and gyromagnetic anomaly "
122 "individually via set_charge_qe(), set_mass_MeV(), and "
123 "set_gyromagnetic_anomaly()."
124 );
125 }
126
127 set_charge_qe(qe);
128 set_mass_MeV(massE);
129 set_gyromagnetic_anomaly(g_anomaly);
130 return *this;
131 }
132
139 gamma () const
140 {
141 amrex::ParticleReal const ref_gamma = -pt;
142 return ref_gamma;
143 }
144
151 beta () const
152 {
153 using namespace amrex::literals;
154 using amrex::Math::powi;
155
156 amrex::ParticleReal const ref_gamma = -pt;
157 amrex::ParticleReal const ref_beta = std::sqrt(1.0_prt - 1.0_prt / powi<2>(ref_gamma));
158 return ref_beta;
159 }
160
167 beta_gamma () const
168 {
169 using namespace amrex::literals;
170 using amrex::Math::powi;
171
172 amrex::ParticleReal const ref_gamma = -pt;
173 amrex::ParticleReal const ref_betagamma = std::sqrt(powi<2>(ref_gamma) - 1.0_prt);
174 return ref_betagamma;
175 }
176
183 mass_MeV () const
184 {
185 using namespace amrex::literals;
186
188 return amrex::ParticleReal(mass * inv_MeV_invc2);
189 }
190
196 RefPart &
198 {
199 using namespace amrex::literals;
200 using amrex::Math::powi;
201
202 AMREX_ASSERT_WITH_MESSAGE(massE != 0.0_prt,
203 "set_mass_MeV: Mass cannot be zero!");
204
206
207 // re-scale pt and pz
208 if (pt != 0.0_prt)
209 {
210 pt = -kin_energy_MeV() / massE - 1.0_prt;
211 pz = std::sqrt(powi<2>(pt) - 1.0_prt);
212 }
213
214 return *this;
215 }
216
224 {
225 using namespace amrex::literals;
226
227 amrex::ParticleReal const ref_gamma = -pt;
228 amrex::ParticleReal const ref_kin_energy = mass_MeV() * (ref_gamma - 1.0_prt);
229 return ref_kin_energy;
230 }
231
237 RefPart &
239 {
240 using namespace amrex::literals;
241 using amrex::Math::powi;
242
244 "set_kin_energy_MeV: Set mass first!");
245
246 px = 0.0;
247 py = 0.0;
248 pt = -kin_energy / mass_MeV() - 1.0_prt;
249 pz = std::sqrt(powi<2>(pt) - 1.0_prt);
250
251 return *this;
252 }
253
260 rigidity_Tm () const
261 {
262 using namespace amrex::literals;
263 using amrex::Math::powi;
264
265 amrex::ParticleReal const ref_gamma = -pt;
266 amrex::ParticleReal const ref_betagamma = std::sqrt(powi<2>(ref_gamma) - 1.0_prt);
267 amrex::ParticleReal const ref_rigidity = mass*ref_betagamma*(ablastr::constant::SI::c)/charge;
268 return ref_rigidity;
269 }
270
277 charge_qe () const
278 {
279 using namespace amrex::literals;
280
281 constexpr amrex::ParticleReal inv_qe = 1.0_prt / ablastr::constant::SI::q_e;
282 return amrex::ParticleReal(charge * inv_qe);
283 }
284
290 RefPart &
292 {
293 using namespace amrex::literals;
294
295 this->charge = charge_qe * ablastr::constant::SI::q_e;
296
297 return *this;
298 }
299
306 qm_ratio_SI () const
307 {
308 return charge / mass;
309 }
310
317 RefPart &
318 set_gyromagnetic_anomaly (amrex::ParticleReal const gyromagnetic_anomaly_ref)
319 {
320 using namespace amrex::literals;
321
322 this->gyromagnetic_anomaly = gyromagnetic_anomaly_ref;
323
324 return *this;
325 }
326
327 };
328
329} // namespace impactx
330
331#endif // IMPACTX_REFERENCE_PARTICLE_H
#define AMREX_ASSERT_WITH_MESSAGE(EX, MSG)
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
amrex_particle_real ParticleReal
constexpr auto c
constexpr auto m_e_v
constexpr auto m_p_v
constexpr auto MeV_inv_c2_v
constexpr auto q_e
constexpr T powi(T x) noexcept
Definition CovarianceMatrixMath.H:25
Definition ReferenceParticle.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal qm_ratio_SI() const
Definition ReferenceParticle.H:306
amrex::ParticleReal px
momentum in x divided by m*c = beta_x*gamma [unitless]
Definition ReferenceParticle.H:39
amrex::ParticleReal y
vertical position y, in meters
Definition ReferenceParticle.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta_gamma() const
Definition ReferenceParticle.H:167
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_mass_MeV(amrex::ParticleReal const massE)
Definition ReferenceParticle.H:197
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal kin_energy_MeV() const
Definition ReferenceParticle.H:223
amrex::ParticleReal pt
energy, normalized by rest energy
Definition ReferenceParticle.H:42
amrex::ParticleReal py
momentum in y divided by m*c = beta_y*gamma [unitless]
Definition ReferenceParticle.H:40
amrex::ParticleReal charge
reference charge, in C
Definition ReferenceParticle.H:44
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal rigidity_Tm() const
Definition ReferenceParticle.H:260
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_kin_energy_MeV(amrex::ParticleReal const kin_energy)
Definition ReferenceParticle.H:238
amrex::ParticleReal s
integrated orbit path length, in meters
Definition ReferenceParticle.H:34
amrex::ParticleReal z
longitudinal position z, in meters
Definition ReferenceParticle.H:37
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_gyromagnetic_anomaly(amrex::ParticleReal const gyromagnetic_anomaly_ref)
Definition ReferenceParticle.H:318
amrex::ParticleReal pz
momentum in z divided by m*c = beta_z*gamma [unitless]
Definition ReferenceParticle.H:41
amrex::ParticleReal gyromagnetic_anomaly
anomalous magnetic moment [unitless]
Definition ReferenceParticle.H:45
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal mass_MeV() const
Definition ReferenceParticle.H:183
RefPart & set_species(std::string const &species_name)
Definition ReferenceParticle.H:86
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_charge_qe(amrex::ParticleReal const charge_qe)
Definition ReferenceParticle.H:291
amrex::ParticleReal mass
reference rest mass, in kg
Definition ReferenceParticle.H:43
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal charge_qe() const
Definition ReferenceParticle.H:277
amrex::ParticleReal x
horizontal position x, in meters
Definition ReferenceParticle.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition ReferenceParticle.H:151
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal gamma() const
Definition ReferenceParticle.H:139
amrex::ParticleReal t
clock time * c in meters
Definition ReferenceParticle.H:38
void reset(bool keep_mass=false, bool keep_charge=false)
Definition ReferenceParticle.H:66
amrex::ParticleReal sedge
value of s at entrance of the current beamline element
Definition ReferenceParticle.H:47
RefPart copy() const
Definition ReferenceParticle.H:55