Hipace
ComputeTemperature.H
Go to the documentation of this file.
1 /* Copyright 2019-2020 Andrew Myers, Yinjian Zhao, Maxence Thevenet, Severin Diederichs
2  *
3  * This file is part of HiPACE++ and WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 
8 #ifndef HIPACE_COMPUTE_TEMPERATURE_H_
9 #define HIPACE_COMPUTE_TEMPERATURE_H_
10 
11 template <typename T_index, typename T_R>
14  T_index const Is, T_index const Ie, T_index const * AMREX_RESTRICT I,
15  T_R const * AMREX_RESTRICT ux, T_R const * AMREX_RESTRICT uy, T_R const * AMREX_RESTRICT psi,
16  T_R const m, T_R const clight, T_R const inv_c2, bool is_beam_coll )
17 {
18  using namespace amrex::literals;
19 
20  const int N = Ie - Is;
21  if ( N == 0 ) { return T_R(0.0); }
22 
23  T_R vx = T_R(0.0); T_R vy = T_R(0.0);
24  T_R vz = T_R(0.0); T_R vs = T_R(0.0);
25  T_R gm = T_R(0.0); T_R us = T_R(0.0);
26 
27  for (int i = Is; i < (int) Ie; ++i)
28  {
29  // particle's Lorentz factor
30  gm = is_beam_coll ? std::sqrt( 1._rt + (ux[I[i]]*ux[I[i]] + uy[I[i]]*uy[I[i]]
31  + psi[I[i]]*psi[I[i]])*inv_c2 )
32  : (1.0_rt + (ux[I[i]]*ux[I[i]] + uy[I[i]]*uy[I[i]])*inv_c2
33  + psi[I[i]]*psi[I[i]]) / (2.0_rt * psi[I[i]] );
34  const amrex::Real uz = is_beam_coll ? psi[I[i]] : clight * (gm - psi[I[i]]);
35  us = ( ux[ I[i] ] * ux[ I[i] ] +
36  uy[ I[i] ] * uy[ I[i] ] +
37  uz * uz);
38  vx += ux[ I[i] ] / gm;
39  vy += uy[ I[i] ] / gm;
40  vz += uz / gm;
41  vs += us / gm / gm;
42  }
43 
44  vx = vx / N; vy = vy / N;
45  vz = vz / N; vs = vs / N;
46 
47  return m/T_R(3.0)*(vs-(vx*vx+vy*vy+vz*vz));
48 }
49 
50 #endif // HIPACE_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 psi, T_R const m, T_R const clight, T_R const inv_c2, bool is_beam_coll)
Definition: ComputeTemperature.H:13
int i
Definition: MakeOpenBoundary.py:152
@ N
Definition: MultiLaser.H:92
const int[]