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
51
58 copy () const
59 {
60 return RefPart{*this};
61 }
62
68 void
69 reset (bool keep_mass=false, bool keep_charge=false)
70 {
71 auto old_mass = mass;
72 auto old_charge = charge;
73
74 RefPart zero{};
75 *this = zero;
76
77 if (keep_mass) { mass = old_mass; }
78 if (keep_charge) { charge = old_charge; }
79 }
80
88 RefPart &
89 set_species (std::string const & species_name)
90 {
94
97 amrex::ParticleReal g_anomaly;
98
99 // [known_species]
100 if (species_name == "electron") {
101 qe = -1.0;
102 massE = m_e / MeV_inv_c2;
103 g_anomaly = 0.00115965218062;
104 } else if (species_name == "positron") {
105 qe = 1.0;
106 massE = m_e / MeV_inv_c2;
107 g_anomaly = 0.00115965218062;
108 } else if (species_name == "proton") {
109 qe = 1.0;
110 massE = m_p / MeV_inv_c2;
111 g_anomaly = 1.7928473446;
112 } else if (species_name == "Hminus") {
113 qe = -1.0;
114 massE = (m_p + 2.0 * m_e) / MeV_inv_c2; // neglect ~14 eV/c^2 binding energy
115 g_anomaly = 1.7928473446;
116 }
117 // [/known_species]
118 else {
119 throw std::runtime_error(
120 "Unknown species: '" + species_name +
121 "'. Known species: electron, positron, proton, Hminus. "
122 "For other species, set charge, mass, and gyromagnetic anomaly "
123 "individually via set_charge_qe(), set_mass_MeV(), and "
124 "set_gyromagnetic_anomaly()."
125 );
126 }
127
128 set_charge_qe(qe);
129 set_mass_MeV(massE);
130 set_gyromagnetic_anomaly(g_anomaly);
131 return *this;
132 }
133
140 gamma () const
141 {
142 amrex::ParticleReal const ref_gamma = -pt;
143 return ref_gamma;
144 }
145
152 beta () const
153 {
154 using namespace amrex::literals;
155 using amrex::Math::powi;
156
157 amrex::ParticleReal const ref_gamma = -pt;
158 amrex::ParticleReal const ref_beta = std::sqrt(1.0_prt - 1.0_prt / powi<2>(ref_gamma));
159 return ref_beta;
160 }
161
168 beta_gamma () const
169 {
170 using namespace amrex::literals;
171 using amrex::Math::powi;
172
173 amrex::ParticleReal const ref_gamma = -pt;
174 amrex::ParticleReal const ref_betagamma = std::sqrt(powi<2>(ref_gamma) - 1.0_prt);
175 return ref_betagamma;
176 }
177
184 mass_MeV () const
185 {
186 using namespace amrex::literals;
187
189 return amrex::ParticleReal(mass * inv_MeV_invc2);
190 }
191
197 RefPart &
199 {
200 using namespace amrex::literals;
201 using amrex::Math::powi;
202
203 AMREX_ASSERT_WITH_MESSAGE(massE != 0.0_prt,
204 "set_mass_MeV: Mass cannot be zero!");
205
207
208 // re-scale pt and pz
209 if (pt != 0.0_prt)
210 {
211 pt = -kin_energy_MeV() / massE - 1.0_prt;
212 pz = std::sqrt(powi<2>(pt) - 1.0_prt);
213 }
214
215 return *this;
216 }
217
225 {
226 using namespace amrex::literals;
227
228 amrex::ParticleReal const ref_gamma = -pt;
229 amrex::ParticleReal const ref_kin_energy = mass_MeV() * (ref_gamma - 1.0_prt);
230 return ref_kin_energy;
231 }
232
238 RefPart &
240 {
241 using namespace amrex::literals;
242 using amrex::Math::powi;
243
245 "set_kin_energy_MeV: Set mass first!");
246
247 px = 0.0;
248 py = 0.0;
249 pt = -kin_energy / mass_MeV() - 1.0_prt;
250 pz = std::sqrt(powi<2>(pt) - 1.0_prt);
251
252 return *this;
253 }
254
261 rigidity_Tm () const
262 {
263 using namespace amrex::literals;
264 using amrex::Math::powi;
265
266 amrex::ParticleReal const ref_gamma = -pt;
267 amrex::ParticleReal const ref_betagamma = std::sqrt(powi<2>(ref_gamma) - 1.0_prt);
268 amrex::ParticleReal const ref_rigidity = mass*ref_betagamma*(ablastr::constant::SI::c)/charge;
269 return ref_rigidity;
270 }
271
278 charge_qe () const
279 {
280 using namespace amrex::literals;
281
282 constexpr amrex::ParticleReal inv_qe = 1.0_prt / ablastr::constant::SI::q_e;
283 return amrex::ParticleReal(charge * inv_qe);
284 }
285
291 RefPart &
293 {
294 using namespace amrex::literals;
295
296 this->charge = charge_qe * ablastr::constant::SI::q_e;
297
298 return *this;
299 }
300
307 qm_ratio_SI () const
308 {
309 return charge / mass;
310 }
311
318 RefPart &
319 set_gyromagnetic_anomaly (amrex::ParticleReal const gyromagnetic_anomaly_ref)
320 {
321 using namespace amrex::literals;
322
323 this->gyromagnetic_anomaly = gyromagnetic_anomaly_ref;
324
325 return *this;
326 }
327
328 };
329
330} // namespace impactx
331
332#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:307
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:168
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_mass_MeV(amrex::ParticleReal const massE)
Definition ReferenceParticle.H:198
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal kin_energy_MeV() const
Definition ReferenceParticle.H:224
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:261
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_kin_energy_MeV(amrex::ParticleReal const kin_energy)
Definition ReferenceParticle.H:239
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:319
amrex::SmallMatrix< amrex::ParticleReal, 3, 6, amrex::Order::F, 1 > spin_coupling
linearized spin-orbit coupling matrix
Definition ReferenceParticle.H:49
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:184
RefPart & set_species(std::string const &species_name)
Definition ReferenceParticle.H:89
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_charge_qe(amrex::ParticleReal const charge_qe)
Definition ReferenceParticle.H:292
amrex::SmallMatrix< amrex::ParticleReal, 3, 1, amrex::Order::F, 1 > spin_rotation_vector
reference spin rotation vector
Definition ReferenceParticle.H:50
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:278
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:152
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal gamma() const
Definition ReferenceParticle.H:140
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:69
amrex::ParticleReal sedge
value of s at entrance of the current beamline element
Definition ReferenceParticle.H:47
RefPart copy() const
Definition ReferenceParticle.H:58