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
43 // The expression used is derived by reducing the expression
44 // (gamma - 1)*(gamma + 1)/(gamma + 1)
45
46 const auto u2 = static_cast<T>(ux*ux + uy*uy + uz*uz);
47 const auto gamma = std::sqrt(one + u2*PhysConst::inv_c2_v<T>);
48 return one/(one + gamma)*static_cast<T>(mass)*u2;
49 }
50
61 amrex::ParticleReal KineticEnergyPhotons(
62 const amrex::ParticleReal ux, const amrex::ParticleReal uy, const amrex::ParticleReal uz)
63 {
64 // Photons have zero mass, but ux, uy and uz are calculated assuming a mass equal to the
65 // electron mass. Hence, photons need a special treatment to calculate the total energy.
66 constexpr auto me_c = PhysConst::m_e * PhysConst::c;
67
68 return me_c * std::sqrt(ux*ux + uy*uy + uz*uz);
69 }
70
71}
72
73#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:61
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
constexpr auto c
vacuum speed of light [m/s]
Definition constant.H:149
constexpr auto inv_c2_v
inverse of the square of the vacuum speed of light [s^2/m^2] (variable template)
Definition constant.H:146
constexpr auto m_e
electron mass [kg]
Definition constant.H:161