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
49
56 copy () const
57 {
58 return RefPart{*this};
59 }
60
66 void
67 reset (bool keep_mass=false, bool keep_charge=false)
68 {
69 auto old_mass = mass;
70 auto old_charge = charge;
71
72 RefPart zero{};
73 *this = zero;
74
75 if (keep_mass) { mass = old_mass; }
76 if (keep_charge) { charge = old_charge; }
77 }
78
86 RefPart &
87 set_species (std::string const & species_name)
88 {
92
95 amrex::ParticleReal g_anomaly;
96
97 // [known_species]
98 if (species_name == "electron") {
99 qe = -1.0;
100 massE = m_e / MeV_inv_c2;
101 g_anomaly = 0.00115965218062;
102 } else if (species_name == "positron") {
103 qe = 1.0;
104 massE = m_e / MeV_inv_c2;
105 g_anomaly = 0.00115965218062;
106 } else if (species_name == "proton") {
107 qe = 1.0;
108 massE = m_p / MeV_inv_c2;
109 g_anomaly = 1.7928473446;
110 } else if (species_name == "Hminus") {
111 qe = -1.0;
112 massE = (m_p + 2.0 * m_e) / MeV_inv_c2; // neglect ~14 eV/c^2 binding energy
113 g_anomaly = 1.7928473446;
114 }
115 // [/known_species]
116 else {
117 throw std::runtime_error(
118 "Unknown species: '" + species_name +
119 "'. Known species: electron, positron, proton, Hminus. "
120 "For other species, set charge, mass, and gyromagnetic anomaly "
121 "individually via set_charge_qe(), set_mass_MeV(), and "
122 "set_gyromagnetic_anomaly()."
123 );
124 }
125
126 set_charge_qe(qe);
127 set_mass_MeV(massE);
128 set_gyromagnetic_anomaly(g_anomaly);
129 return *this;
130 }
131
138 gamma () const
139 {
140 amrex::ParticleReal const ref_gamma = -pt;
141 return ref_gamma;
142 }
143
150 beta () const
151 {
152 using namespace amrex::literals;
153 using amrex::Math::powi;
154
155 amrex::ParticleReal const ref_gamma = -pt;
156 amrex::ParticleReal const ref_beta = std::sqrt(1.0_prt - 1.0_prt / powi<2>(ref_gamma));
157 return ref_beta;
158 }
159
166 beta_gamma () const
167 {
168 using namespace amrex::literals;
169 using amrex::Math::powi;
170
171 amrex::ParticleReal const ref_gamma = -pt;
172 amrex::ParticleReal const ref_betagamma = std::sqrt(powi<2>(ref_gamma) - 1.0_prt);
173 return ref_betagamma;
174 }
175
182 mass_MeV () const
183 {
184 using namespace amrex::literals;
185
187 return amrex::ParticleReal(mass * inv_MeV_invc2);
188 }
189
195 RefPart &
197 {
198 using namespace amrex::literals;
199 using amrex::Math::powi;
200
201 AMREX_ASSERT_WITH_MESSAGE(massE != 0.0_prt,
202 "set_mass_MeV: Mass cannot be zero!");
203
205
206 // re-scale pt and pz
207 if (pt != 0.0_prt)
208 {
209 pt = -kin_energy_MeV() / massE - 1.0_prt;
210 pz = std::sqrt(powi<2>(pt) - 1.0_prt);
211 }
212
213 return *this;
214 }
215
223 {
224 using namespace amrex::literals;
225
226 amrex::ParticleReal const ref_gamma = -pt;
227 amrex::ParticleReal const ref_kin_energy = mass_MeV() * (ref_gamma - 1.0_prt);
228 return ref_kin_energy;
229 }
230
236 RefPart &
238 {
239 using namespace amrex::literals;
240 using amrex::Math::powi;
241
243 "set_kin_energy_MeV: Set mass first!");
244
245 px = 0.0;
246 py = 0.0;
247 pt = -kin_energy / mass_MeV() - 1.0_prt;
248 pz = std::sqrt(powi<2>(pt) - 1.0_prt);
249
250 return *this;
251 }
252
259 rigidity_Tm () const
260 {
261 using namespace amrex::literals;
262 using amrex::Math::powi;
263
264 amrex::ParticleReal const ref_gamma = -pt;
265 amrex::ParticleReal const ref_betagamma = std::sqrt(powi<2>(ref_gamma) - 1.0_prt);
266 amrex::ParticleReal const ref_rigidity = mass*ref_betagamma*(ablastr::constant::SI::c)/charge;
267 return ref_rigidity;
268 }
269
276 charge_qe () const
277 {
278 using namespace amrex::literals;
279
280 constexpr amrex::ParticleReal inv_qe = 1.0_prt / ablastr::constant::SI::q_e;
281 return amrex::ParticleReal(charge * inv_qe);
282 }
283
289 RefPart &
291 {
292 using namespace amrex::literals;
293
294 this->charge = charge_qe * ablastr::constant::SI::q_e;
295
296 return *this;
297 }
298
305 qm_ratio_SI () const
306 {
307 return charge / mass;
308 }
309
316 RefPart &
317 set_gyromagnetic_anomaly (amrex::ParticleReal const gyromagnetic_anomaly_ref)
318 {
319 using namespace amrex::literals;
320
321 this->gyromagnetic_anomaly = gyromagnetic_anomaly_ref;
322
323 return *this;
324 }
325
326 };
327
328} // namespace impactx
329
330#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:305
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:166
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_mass_MeV(amrex::ParticleReal const massE)
Definition ReferenceParticle.H:196
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal kin_energy_MeV() const
Definition ReferenceParticle.H:222
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::SmallMatrix< amrex::ParticleReal, 6, 6, amrex::Order::F, 1 > map
linearized map
Definition ReferenceParticle.H:48
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:259
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_kin_energy_MeV(amrex::ParticleReal const kin_energy)
Definition ReferenceParticle.H:237
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:317
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:182
RefPart & set_species(std::string const &species_name)
Definition ReferenceParticle.H:87
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_charge_qe(amrex::ParticleReal const charge_qe)
Definition ReferenceParticle.H:290
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:276
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:150
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal gamma() const
Definition ReferenceParticle.H:138
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:67
amrex::ParticleReal sedge
value of s at entrance of the current beamline element
Definition ReferenceParticle.H:47
RefPart copy() const
Definition ReferenceParticle.H:56