WarpX
Loading...
Searching...
No Matches
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 WARPX_PARTICLES_KINETIC_ENERGY_H_
9#define WARPX_PARTICLES_KINETIC_ENERGY_H_
10
11#include "Utils/WarpXConst.H"
12
13#include "AMReX_Extension.H"
14#include "AMReX_GpuQualifiers.H"
15#include "AMReX_Math.H"
16#include "AMReX_REAL.H"
17
18#include <cmath>
19
20namespace Algorithms{
21
34 template <typename T = amrex::ParticleReal>
37 const amrex::ParticleReal ux, const amrex::ParticleReal uy, const amrex::ParticleReal uz, const amrex::ParticleReal mass)
38 {
39 using namespace amrex;
40
41 constexpr auto one = static_cast<T>(1.0);
42 constexpr auto inv_c2 = one/Math::powi<2>(static_cast<T>(PhysConst::c));
43
44 // The expression used is derived by reducing the expression
45 // (gamma - 1)*(gamma + 1)/(gamma + 1)
46
47 const auto u2 = static_cast<T>(ux*ux + uy*uy + uz*uz);
48 const auto gamma = std::sqrt(one + u2*inv_c2);
49 return one/(one + gamma)*static_cast<T>(mass)*u2;
50 }
51
62 amrex::ParticleReal KineticEnergyPhotons(
63 const amrex::ParticleReal ux, const amrex::ParticleReal uy, const amrex::ParticleReal uz)
64 {
65 // Photons have zero mass, but ux, uy and uz are calculated assuming a mass equal to the
66 // electron mass. Hence, photons need a special treatment to calculate the total energy.
67 constexpr auto me_c = PhysConst::m_e * PhysConst::c;
68
69 return me_c * std::sqrt(ux*ux + uy*uy + uz*uz);
70 }
71
72}
73
74#endif // WARPX_PARTICLES_KINETIC_ENERGY_H_
#define AMREX_INLINE
#define AMREX_GPU_HOST_DEVICE
Definition KineticEnergy.H:20
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:62
AMREX_GPU_HOST_DEVICE AMREX_INLINE T KineticEnergy(const amrex::ParticleReal ux, const amrex::ParticleReal uy, const amrex::ParticleReal uz, const amrex::ParticleReal mass)
Computes the kinetic energy of a particle. This method should not be used with photons.
Definition KineticEnergy.H:36
static constexpr auto c
vacuum speed of light [m/s]
Definition constant.H:44
static constexpr auto m_e
electron mass [kg]
Definition constant.H:54
constexpr T powi(T x) noexcept