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
24
25namespace impactx
26{
30 struct RefPart
31 {
32 amrex::ParticleReal s = 0.0;
33 amrex::ParticleReal x = 0.0;
34 amrex::ParticleReal y = 0.0;
35 amrex::ParticleReal z = 0.0;
36 amrex::ParticleReal t = 0.0;
37 amrex::ParticleReal px = 0.0;
38 amrex::ParticleReal py = 0.0;
39 amrex::ParticleReal pz = 0.0;
40 amrex::ParticleReal pt = 0.0;
41 amrex::ParticleReal mass = 0.0;
42 amrex::ParticleReal charge = 0.0;
43
44 amrex::ParticleReal sedge = 0.0;
46
53 copy () const
54 {
55 return RefPart{*this};
56 }
57
63 void
64 reset (bool keep_mass=false, bool keep_charge=false)
65 {
66 auto old_mass = mass;
67 auto old_charge = charge;
68
69 RefPart zero{};
70 *this = zero;
71
72 if (keep_mass) { mass = old_mass; }
73 if (keep_charge) { charge = old_charge; }
74 }
75
81 amrex::ParticleReal
82 gamma () const
83 {
84 amrex::ParticleReal const ref_gamma = -pt;
85 return ref_gamma;
86 }
87
93 amrex::ParticleReal
94 beta () const
95 {
96 using namespace amrex::literals;
98
99 amrex::ParticleReal const ref_gamma = -pt;
100 amrex::ParticleReal const ref_beta = std::sqrt(1.0_prt - 1.0_prt / powi<2>(ref_gamma));
101 return ref_beta;
102 }
103
109 amrex::ParticleReal
110 beta_gamma () const
111 {
112 using namespace amrex::literals;
113 using amrex::Math::powi;
114
115 amrex::ParticleReal const ref_gamma = -pt;
116 amrex::ParticleReal const ref_betagamma = std::sqrt(powi<2>(ref_gamma) - 1.0_prt);
117 return ref_betagamma;
118 }
119
125 amrex::ParticleReal
126 mass_MeV () const
127 {
128 using namespace amrex::literals;
129
130 constexpr amrex::ParticleReal inv_MeV_invc2 = 1.0_prt / ablastr::constant::SI::MeV_invc2;
131 return amrex::ParticleReal(mass * inv_MeV_invc2);
132 }
133
139 RefPart &
140 set_mass_MeV (amrex::ParticleReal const massE)
141 {
142 using namespace amrex::literals;
143 using amrex::Math::powi;
144
145 AMREX_ASSERT_WITH_MESSAGE(massE != 0.0_prt,
146 "set_mass_MeV: Mass cannot be zero!");
147
149
150 // re-scale pt and pz
151 if (pt != 0.0_prt)
152 {
153 pt = -kin_energy_MeV() / massE - 1.0_prt;
154 pz = std::sqrt(powi<2>(pt) - 1.0_prt);
155 }
156
157 return *this;
158 }
159
165 amrex::ParticleReal
167 {
168 using namespace amrex::literals;
169
170 amrex::ParticleReal const ref_gamma = -pt;
171 amrex::ParticleReal const ref_kin_energy = mass_MeV() * (ref_gamma - 1.0_prt);
172 return ref_kin_energy;
173 }
174
180 RefPart &
181 set_kin_energy_MeV (amrex::ParticleReal const kin_energy)
182 {
183 using namespace amrex::literals;
184 using amrex::Math::powi;
185
187 "set_kin_energy_MeV: Set mass first!");
188
189 px = 0.0;
190 py = 0.0;
191 pt = -kin_energy / mass_MeV() - 1.0_prt;
192 pz = std::sqrt(powi<2>(pt) - 1.0_prt);
193
194 return *this;
195 }
196
202 amrex::ParticleReal
203 rigidity_Tm () const
204 {
205 using namespace amrex::literals;
206 using amrex::Math::powi;
207
208 amrex::ParticleReal const ref_gamma = -pt;
209 amrex::ParticleReal const ref_betagamma = std::sqrt(powi<2>(ref_gamma) - 1.0_prt);
210 amrex::ParticleReal const ref_rigidity = mass*ref_betagamma*(ablastr::constant::SI::c)/charge;
211 return ref_rigidity;
212 }
213
219 amrex::ParticleReal
220 charge_qe () const
221 {
222 using namespace amrex::literals;
223
224 constexpr amrex::ParticleReal inv_qe = 1.0_prt / ablastr::constant::SI::q_e;
225 return amrex::ParticleReal(charge * inv_qe);
226 }
227
233 RefPart &
234 set_charge_qe (amrex::ParticleReal const charge_qe)
235 {
236 using namespace amrex::literals;
237
238 this->charge = charge_qe * ablastr::constant::SI::q_e;
239
240 return *this;
241 }
242
248 amrex::ParticleReal
249 qm_ratio_SI () const
250 {
251 return charge / mass;
252 }
253 };
254
255} // namespace impactx
256
257#endif // IMPACTX_REFERENCE_PARTICLE_H
#define AMREX_ASSERT_WITH_MESSAGE(EX, MSG)
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
static constexpr auto c
static constexpr auto MeV_invc2
static constexpr auto q_e
constexpr T powi(T x) noexcept
Definition CovarianceMatrixMath.H:25
Definition ReferenceParticle.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal qm_ratio_SI() const
Definition ReferenceParticle.H:249
amrex::ParticleReal px
momentum in x divided by m*c = beta_x*gamma [unitless]
Definition ReferenceParticle.H:37
amrex::ParticleReal y
vertical position y, in meters
Definition ReferenceParticle.H:34
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta_gamma() const
Definition ReferenceParticle.H:110
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_mass_MeV(amrex::ParticleReal const massE)
Definition ReferenceParticle.H:140
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal kin_energy_MeV() const
Definition ReferenceParticle.H:166
amrex::ParticleReal pt
energy, normalized by rest energy
Definition ReferenceParticle.H:40
amrex::ParticleReal py
momentum in y divided by m*c = beta_y*gamma [unitless]
Definition ReferenceParticle.H:38
amrex::SmallMatrix< amrex::ParticleReal, 6, 6, amrex::Order::F, 1 > map
linearized map
Definition ReferenceParticle.H:45
amrex::ParticleReal charge
reference charge, in C
Definition ReferenceParticle.H:42
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal rigidity_Tm() const
Definition ReferenceParticle.H:203
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_kin_energy_MeV(amrex::ParticleReal const kin_energy)
Definition ReferenceParticle.H:181
amrex::ParticleReal s
integrated orbit path length, in meters
Definition ReferenceParticle.H:32
amrex::ParticleReal z
longitudinal position z, in meters
Definition ReferenceParticle.H:35
amrex::ParticleReal pz
momentum in z divided by m*c = beta_z*gamma [unitless]
Definition ReferenceParticle.H:39
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal mass_MeV() const
Definition ReferenceParticle.H:126
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_charge_qe(amrex::ParticleReal const charge_qe)
Definition ReferenceParticle.H:234
amrex::ParticleReal mass
reference rest mass, in kg
Definition ReferenceParticle.H:41
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal charge_qe() const
Definition ReferenceParticle.H:220
amrex::ParticleReal x
horizontal position x, in meters
Definition ReferenceParticle.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition ReferenceParticle.H:94
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal gamma() const
Definition ReferenceParticle.H:82
amrex::ParticleReal t
clock time * c in meters
Definition ReferenceParticle.H:36
void reset(bool keep_mass=false, bool keep_charge=false)
Definition ReferenceParticle.H:64
amrex::ParticleReal sedge
value of s at entrance of the current beamline element
Definition ReferenceParticle.H:44
RefPart copy() const
Definition ReferenceParticle.H:53