ImpactX
ReferenceParticle.H
Go to the documentation of this file.
1 /* Copyright 2022 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_REAL.H>
19 
20 #include <cmath>
21 
22 
23 namespace impactx
24 {
28  struct RefPart
29  {
30  amrex::ParticleReal s = 0.0;
31  amrex::ParticleReal x = 0.0;
32  amrex::ParticleReal y = 0.0;
33  amrex::ParticleReal z = 0.0;
34  amrex::ParticleReal t = 0.0;
35  amrex::ParticleReal px = 0.0;
36  amrex::ParticleReal py = 0.0;
37  amrex::ParticleReal pz = 0.0;
38  amrex::ParticleReal pt = 0.0;
39  amrex::ParticleReal mass = 0.0;
40  amrex::ParticleReal charge = 0.0;
41 
47  amrex::ParticleReal
48  gamma () const
49  {
50  amrex::ParticleReal const ref_gamma = -pt;
51  return ref_gamma;
52  }
53 
59  amrex::ParticleReal
60  beta () const
61  {
62  using namespace amrex::literals;
63 
64  amrex::ParticleReal const ref_gamma = -pt;
65  amrex::ParticleReal const ref_beta = sqrt(1.0_prt - 1.0_prt/pow(ref_gamma,2));
66  return ref_beta;
67  }
68 
74  amrex::ParticleReal
75  beta_gamma () const
76  {
77  using namespace amrex::literals;
78 
79  amrex::ParticleReal const ref_gamma = -pt;
80  amrex::ParticleReal const ref_betagamma = sqrt(pow(ref_gamma, 2) - 1.0_prt);
81  return ref_betagamma;
82  }
83 
89  amrex::ParticleReal
90  mass_MeV () const
91  {
92  using namespace amrex::literals;
93 
94  constexpr amrex::ParticleReal inv_MeV_invc2 = 1.0_prt / ablastr::constant::SI::MeV_invc2;
95  return amrex::ParticleReal(mass * inv_MeV_invc2);
96  }
97 
103  RefPart &
104  set_mass_MeV (amrex::ParticleReal const massE)
105  {
106  using namespace amrex::literals;
107 
108  AMREX_ASSERT_WITH_MESSAGE(massE != 0.0_prt,
109  "set_mass_MeV: Mass cannot be zero!");
110 
111  mass = massE * ablastr::constant::SI::MeV_invc2;
112 
113  // re-scale pt and pz
114  if (pt != 0.0_prt)
115  {
116  pt = -energy_MeV() / massE - 1.0_prt;
117  pz = sqrt(pow(pt, 2) - 1.0_prt);
118  }
119 
120  return *this;
121  }
122 
128  amrex::ParticleReal
129  energy_MeV () const
130  {
131  using namespace amrex::literals;
132 
133  amrex::ParticleReal const ref_gamma = -pt;
134  amrex::ParticleReal const ref_energy = mass_MeV() * (ref_gamma - 1.0_prt);
135  return ref_energy;
136  }
137 
143  RefPart &
144  set_energy_MeV (amrex::ParticleReal const energy)
145  {
146  using namespace amrex::literals;
147 
148  AMREX_ASSERT_WITH_MESSAGE(mass != 0.0_prt,
149  "set_energy_MeV: Set mass first!");
150 
151  px = 0.0;
152  py = 0.0;
153  pt = -energy / mass_MeV() - 1.0_prt;
154  pz = sqrt(pow(pt, 2) - 1.0_prt);
155 
156  return *this;
157  }
158 
164  amrex::ParticleReal
165  charge_qe () const
166  {
167  using namespace amrex::literals;
168 
169  constexpr amrex::ParticleReal inv_qe = 1.0_prt / ablastr::constant::SI::q_e;
170  return amrex::ParticleReal(charge * inv_qe);
171  }
172 
178  RefPart &
179  set_charge_qe (amrex::ParticleReal const charge_qe)
180  {
181  using namespace amrex::literals;
182 
183  this->charge = charge_qe * ablastr::constant::SI::q_e;
184 
185  return *this;
186  }
187 
193  amrex::ParticleReal
194  qm_qeeV () const
195  {
196  return charge / mass;
197  }
198  };
199 
200 } // namespace impactx
201 
202 #endif // IMPACTX_REFERENCE_PARTICLE_H
amrex::ParticleReal x
horizontal position x, in meters
Definition: ReferenceParticle.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal energy_MeV() const
Definition: ReferenceParticle.H:129
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal mass_MeV() const
Definition: ReferenceParticle.H:90
amrex::ParticleReal pz
momentum in z, normalized to proper velocity
Definition: ReferenceParticle.H:37
static constexpr auto q_e
amrex::ParticleReal z
longitudinal position y, in meters
Definition: ReferenceParticle.H:33
amrex::ParticleReal py
momentum in y, normalized to proper velocity
Definition: ReferenceParticle.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal charge_qe() const
Definition: ReferenceParticle.H:165
Definition: ImpactX.cpp:31
amrex::ParticleReal px
momentum in x, normalized to proper velocity
Definition: ReferenceParticle.H:35
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal qm_qeeV() const
Definition: ReferenceParticle.H:194
amrex::ParticleReal pt
energy deviation, normalized by rest energy
Definition: ReferenceParticle.H:38
#define AMREX_ASSERT_WITH_MESSAGE(EX, MSG)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_charge_qe(amrex::ParticleReal const charge_qe)
Definition: ReferenceParticle.H:179
static constexpr auto MeV_invc2
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
amrex::ParticleReal t
clock time * c in meters
Definition: ReferenceParticle.H:34
amrex::ParticleReal s
integrated orbit path length, in meters
Definition: ReferenceParticle.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_mass_MeV(amrex::ParticleReal const massE)
Definition: ReferenceParticle.H:104
Definition: ReferenceParticle.H:28
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
amrex::ParticleReal mass
reference rest mass, in kg
Definition: ReferenceParticle.H:39
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RefPart & set_energy_MeV(amrex::ParticleReal const energy)
Definition: ReferenceParticle.H:144
amrex::ParticleReal charge
reference charge, in C
Definition: ReferenceParticle.H:40
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta_gamma() const
Definition: ReferenceParticle.H:75
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition: ReferenceParticle.H:60
amrex::ParticleReal y
vertical position y, in meters
Definition: ReferenceParticle.H:32
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal gamma() const
Definition: ReferenceParticle.H:48