WarpX
KineticEnergy.H
Go to the documentation of this file.
1 /* Copyright 2021 Luca Fedeli
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 
8 #ifndef PARTICLES_KINETIC_ENERGY_H_
9 #define PARTICLES_KINETIC_ENERGY_H_
10 
11 #include "Utils/WarpXConst.H"
12 
13 #include "AMReX_Extension.H"
14 #include "AMReX_GpuQualifiers.H"
15 #include "AMReX_REAL.H"
16 
17 #include <cmath>
18 
19 namespace Algorithms{
20 
21  // This marks the gamma threshold to switch between the full relativistic expression
22  // for particle kinetic energy and a Taylor expansion.
23  static constexpr auto gamma_relativistic_threshold =
24  static_cast<amrex::ParticleReal>(1.005);
25 
39  amrex::ParticleReal KineticEnergy(
40  const amrex::ParticleReal ux, const amrex::ParticleReal uy, const amrex::ParticleReal uz,
41  const amrex::ParticleReal mass)
42  {
43  using namespace amrex;
44 
45  constexpr auto c2 = PhysConst::c * PhysConst::c;
46  constexpr auto inv_c2 = 1.0_prt/c2;
47 
48  const auto u2 = (ux*ux + uy*uy + uz*uz)*inv_c2;
49  const auto gamma = std::sqrt(1.0_prt + u2);
50 
51  const auto kk = (gamma > gamma_relativistic_threshold)?
52  (gamma-1.0_prt):
53  (u2*0.5_prt - u2*u2*(1.0_prt/8.0_prt) + u2*u2*u2*(1.0_prt/16.0_prt)-
54  u2*u2*u2*u2*(5.0_prt/128.0_prt) + (7.0_prt/256_prt)*u2*u2*u2*u2*u2); //Taylor expansion
55 
56  return kk*mass*c2;
57  }
58 
69  amrex::ParticleReal KineticEnergyPhotons(
70  const amrex::ParticleReal ux, const amrex::ParticleReal uy, const amrex::ParticleReal uz)
71  {
72  // Photons have zero mass, but ux, uy and uz are calculated assuming a mass equal to the
73  // electron mass. Hence, photons need a special treatment to calculate the total energy.
74  constexpr auto me_c = PhysConst::m_e * PhysConst::c;
75 
76  return me_c * std::sqrt(ux*ux + uy*uy + uz*uz);
77  }
78 
79 }
80 
81 #endif // PARTICLES_ALGORITHMS_H_
AMREX_GPU_HOST_DEVICE AMREX_INLINE amrex::ParticleReal KineticEnergy(const amrex::ParticleReal ux, const amrex::ParticleReal uy, const amrex::ParticleReal uz, const amrex::ParticleReal mass)
Computes the kinetic energy of a particle. Below a threshold for the Lorentz factor (gamma_relativist...
Definition: KineticEnergy.H:39
int gamma
Definition: Stencil.py:474
static constexpr auto c
vacuum speed of light [m/s]
Definition: constant.H:44
def uz
Definition: read_lab_particles.py:30
#define AMREX_GPU_HOST_DEVICE
static constexpr auto gamma_relativistic_threshold
Definition: KineticEnergy.H:23
#define AMREX_INLINE
Definition: KineticEnergy.H:19
def ux
Definition: read_lab_particles.py:29
static constexpr auto m_e
electron mass [kg]
Definition: constant.H:52
AMREX_GPU_HOST_DEVICE AMREX_INLINE amrex::ParticleReal KineticEnergyPhotons(const amrex::ParticleReal ux, const amrex::ParticleReal uy, const amrex::ParticleReal uz)
Computes the kinetic energy of a photon.
Definition: KineticEnergy.H:69