WarpX
ComputeTemperature.H
Go to the documentation of this file.
1 /* Copyright 2019-2020 Andrew Myers, Yinjian Zhao
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef WARPX_PARTICLES_COLLISION_COMPUTE_TEMPERATURE_H_
8 #define WARPX_PARTICLES_COLLISION_COMPUTE_TEMPERATURE_H_
9 
10 #include "Utils/WarpXConst.H"
11 
12 
13 template <typename T_index, typename T_R>
16  T_index const Is, T_index const Ie, T_index const * AMREX_RESTRICT I,
17  T_R const * AMREX_RESTRICT ux, T_R const * AMREX_RESTRICT uy, T_R const * AMREX_RESTRICT uz,
18  T_R const m )
19 {
20 
21  T_R constexpr inv_c2 = T_R(1.0) / ( PhysConst::c * PhysConst::c );
22 
23  const int N = Ie - Is;
24  if ( N == 0 ) { return T_R(0.0); }
25 
26  T_R vx = T_R(0.0); T_R vy = T_R(0.0);
27  T_R vz = T_R(0.0); T_R vs = T_R(0.0);
28  T_R gm = T_R(0.0); T_R us = T_R(0.0);
29 
30  for (int i = Is; i < static_cast<int>(Ie); ++i)
31  {
32  us = ( ux[ I[i] ] * ux[ I[i] ] +
33  uy[ I[i] ] * uy[ I[i] ] +
34  uz[ I[i] ] * uz[ I[i] ] );
35  gm = std::sqrt( T_R(1.0) + us*inv_c2 );
36  vx += ux[ I[i] ] / gm;
37  vy += uy[ I[i] ] / gm;
38  vz += uz[ I[i] ] / gm;
39  vs += us / gm / gm;
40  }
41 
42  vx = vx / N; vy = vy / N;
43  vz = vz / N; vs = vs / N;
44 
45  return m/T_R(3.0)*(vs-(vx*vx+vy*vy+vz*vz));
46 }
47 
48 #endif // WARPX_PARTICLES_COLLISION_COMPUTE_TEMPERATURE_H_
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE T_R ComputeTemperature(T_index const Is, T_index const Ie, T_index const *AMREX_RESTRICT I, T_R const *AMREX_RESTRICT ux, T_R const *AMREX_RESTRICT uy, T_R const *AMREX_RESTRICT uz, T_R const m)
Definition: ComputeTemperature.H:15
static constexpr auto c
vacuum speed of light [m/s]
Definition: constant.H:44
i
Definition: check_interp_points_and_weights.py:174