ImpactX
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_Array.H>
16 #include <AMReX_BLassert.H>
17 #include <AMReX_Extension.H>
18 #include <AMReX_GpuQualifiers.H>
19 #include <AMReX_REAL.H>
20 
21 #include <cmath>
22 
23 
24 namespace impactx
25 {
29  struct RefPart
30  {
31  amrex::ParticleReal s = 0.0;
32  amrex::ParticleReal x = 0.0;
33  amrex::ParticleReal y = 0.0;
34  amrex::ParticleReal z = 0.0;
35  amrex::ParticleReal t = 0.0;
36  amrex::ParticleReal px = 0.0;
37  amrex::ParticleReal py = 0.0;
38  amrex::ParticleReal pz = 0.0;
39  amrex::ParticleReal pt = 0.0;
40  amrex::ParticleReal mass = 0.0;
41  amrex::ParticleReal charge = 0.0;
42 
43  amrex::ParticleReal sedge = 0.0;
45 
51  amrex::ParticleReal
52  gamma () const
53  {
54  amrex::ParticleReal const ref_gamma = -pt;
55  return ref_gamma;
56  }
57 
63  amrex::ParticleReal
64  beta () const
65  {
66  using namespace amrex::literals;
67 
68  amrex::ParticleReal const ref_gamma = -pt;
69  amrex::ParticleReal const ref_beta = sqrt(1.0_prt - 1.0_prt/pow(ref_gamma,2));
70  return ref_beta;
71  }
72 
78  amrex::ParticleReal
79  beta_gamma () const
80  {
81  using namespace amrex::literals;
82 
83  amrex::ParticleReal const ref_gamma = -pt;
84  amrex::ParticleReal const ref_betagamma = sqrt(pow(ref_gamma, 2) - 1.0_prt);
85  return ref_betagamma;
86  }
87 
93  amrex::ParticleReal
94  mass_MeV () const
95  {
96  using namespace amrex::literals;
97 
98  constexpr amrex::ParticleReal inv_MeV_invc2 = 1.0_prt / ablastr::constant::SI::MeV_invc2;
99  return amrex::ParticleReal(mass * inv_MeV_invc2);
100  }
101 
107  RefPart &
108  set_mass_MeV (amrex::ParticleReal const massE)
109  {
110  using namespace amrex::literals;
111 
112  AMREX_ASSERT_WITH_MESSAGE(massE != 0.0_prt,
113  "set_mass_MeV: Mass cannot be zero!");
114 
116 
117  // re-scale pt and pz
118  if (pt != 0.0_prt)
119  {
120  pt = -kin_energy_MeV() / massE - 1.0_prt;
121  pz = sqrt(pow(pt, 2) - 1.0_prt);
122  }
123 
124  return *this;
125  }
126 
132  amrex::ParticleReal
133  kin_energy_MeV () const
134  {
135  using namespace amrex::literals;
136 
137  amrex::ParticleReal const ref_gamma = -pt;
138  amrex::ParticleReal const ref_kin_energy = mass_MeV() * (ref_gamma - 1.0_prt);
139  return ref_kin_energy;
140  }
141 
147  RefPart &
148  set_kin_energy_MeV (amrex::ParticleReal const kin_energy)
149  {
150  using namespace amrex::literals;
151 
152  AMREX_ASSERT_WITH_MESSAGE(mass != 0.0_prt,
153  "set_kin_energy_MeV: Set mass first!");
154 
155  px = 0.0;
156  py = 0.0;
157  pt = -kin_energy / mass_MeV() - 1.0_prt;
158  pz = sqrt(pow(pt, 2) - 1.0_prt);
159 
160  return *this;
161  }
162 
168  amrex::ParticleReal
169  rigidity_Tm () const
170  {
171  using namespace amrex::literals;
172 
173  amrex::ParticleReal const ref_gamma = -pt;
174  amrex::ParticleReal const ref_betagamma = sqrt(pow(ref_gamma, 2) - 1.0_prt);
175  //amrex::ParticleReal const ref_rigidity = mass*ref_betagamma*(ablastr::constant::SI::c)/charge; //fails due to "charge"
176  amrex::ParticleReal const ref_rigidity = mass*ref_betagamma*(ablastr::constant::SI::c)/(ablastr::constant::SI::q_e);
177  return ref_rigidity;
178  }
179 
185  amrex::ParticleReal
186  charge_qe () const
187  {
188  using namespace amrex::literals;
189 
190  constexpr amrex::ParticleReal inv_qe = 1.0_prt / ablastr::constant::SI::q_e;
191  return amrex::ParticleReal(charge * inv_qe);
192  }
193 
199  RefPart &
200  set_charge_qe (amrex::ParticleReal const charge_qe)
201  {
202  using namespace amrex::literals;
203 
204  this->charge = charge_qe * ablastr::constant::SI::q_e;
205 
206  return *this;
207  }
208 
214  amrex::ParticleReal
215  qm_qeeV () const
216  {
217  return charge / mass;
218  }
219  };
220 
221 } // namespace impactx
222 
223 #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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Definition: ImpactX.cpp:33
Definition: ReferenceParticle.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal qm_qeeV() const
Definition: ReferenceParticle.H:215
amrex::ParticleReal px
momentum in x, normalized by mass*c
Definition: ReferenceParticle.H:36
amrex::ParticleReal y
vertical position y, in meters
Definition: ReferenceParticle.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta_gamma() const
Definition: ReferenceParticle.H:79
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal kin_energy_MeV() const
Definition: ReferenceParticle.H:133
amrex::ParticleReal pt
energy, normalized by rest energy
Definition: ReferenceParticle.H:39
amrex::ParticleReal py
momentum in y, normalized by mass*c
Definition: ReferenceParticle.H:37
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_mass_MeV(amrex::ParticleReal const massE)
Definition: ReferenceParticle.H:108
amrex::ParticleReal charge
reference charge, in C
Definition: ReferenceParticle.H:41
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal rigidity_Tm() const
Definition: ReferenceParticle.H:169
amrex::ParticleReal s
integrated orbit path length, in meters
Definition: ReferenceParticle.H:31
amrex::ParticleReal z
longitudinal position z, in meters
Definition: ReferenceParticle.H:34
amrex::Array2D< amrex::ParticleReal, 1, 6, 1, 6 > map
linearized map
Definition: ReferenceParticle.H:44
amrex::ParticleReal pz
momentum in z, normalized by mass*c
Definition: ReferenceParticle.H:38
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal mass_MeV() const
Definition: ReferenceParticle.H:94
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_charge_qe(amrex::ParticleReal const charge_qe)
Definition: ReferenceParticle.H:200
amrex::ParticleReal mass
reference rest mass, in kg
Definition: ReferenceParticle.H:40
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal charge_qe() const
Definition: ReferenceParticle.H:186
amrex::ParticleReal x
horizontal position x, in meters
Definition: ReferenceParticle.H:32
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition: ReferenceParticle.H:64
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal gamma() const
Definition: ReferenceParticle.H:52
amrex::ParticleReal t
clock time * c in meters
Definition: ReferenceParticle.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_kin_energy_MeV(amrex::ParticleReal const kin_energy)
Definition: ReferenceParticle.H:148
amrex::ParticleReal sedge
value of s at entrance of the current beamline element
Definition: ReferenceParticle.H:43