XGC1
basic_physics.hpp
Go to the documentation of this file.
1 #ifndef BASIC_PHYSICS_HPP
2 #define BASIC_PHYSICS_HPP
3 #include "space_settings.hpp"
4 #include "constants.hpp"
5
6 // Kinetic energy
7 // E = (1/2) m v^2
8 KOKKOS_INLINE_FUNCTION double kinetic_energy(double mass, double v){
9  return 0.5*mass*v*v;
10 }
11
12 // Return equilibrium distribution function
13 // f = (n / sqrt(T^3)) * exp(-E/T)
14 KOKKOS_INLINE_FUNCTION double maxwellian_dist(double den, double temp, double energy){
15  const double EXP_LIM = 64.0;
16  return den/(temp*sqrt(temp))*exp(-min(EXP_LIM,energy/temp));
17 }
18
19 // Return adiabatic exponential factor
20 // Should be the same as get_ad of f0module.F90
21 // When the modified adiabatic function is used, the adiabatic response becomes
22 // linear function in (-a,a) --> exp_ad(x) = 1+x
23 // exponential decay to zero in x<-a --> exp_ad(x)=exp(-|x|+a)*(1-a)
24 // This satisfies continuous condition
25 // mirror symmetry (0,1) --> x-> -x, y-> 2-y
26 // for (x>a), exp_ad(x)=2 - exp(-|x|+a)*(1-a)
29  constexpr bool use_linear = true;
30 #else
31  constexpr bool use_linear = false;
32 #endif
33
36 #else
37  constexpr double lim=0.7;
38 #endif
39  if constexpr(use_linear){
40  double tmp = exp(-abs(x)+lim)*(1-lim);
41  double tmp2 = (x<-lim ? tmp : 1.0+x);
42  return (x>lim ? 2.0-tmp : tmp2);
43  } else {
44  return exp(x);
45  }
46 }
47
49 KOKKOS_INLINE_FUNCTION double gyro_radius(double B, double mu, double c2_2m){
50  return sqrt(mu/(B*c2_2m));
51 }
52
53 /* Returns thermal velocity
54  * @param[in] mass species mass
55  * @param[in] temp_ev reference temperature
56  * return thermal velocity
57  */
58 KOKKOS_INLINE_FUNCTION double thermal_velocity(double mass, double temp_ev){
59  return sqrt((temp_ev*EV_2_J)/mass);
60 }
61
62 /* Returns velocity normalized by thermal velocity
63  * @param[in] mass species mass
64  * @param[in] temp_ev reference temperature
65  * @param[in] v input velocity
66  * return normalized velocity
67  */
68 KOKKOS_INLINE_FUNCTION double normalize_to_vth(double mass, double temp_ev, double v){
69  return v*sqrt(mass/(temp_ev*EV_2_J));
70 }
71
72 /* Returns normalized parallel velocity
73  * @param[in] c_m species charge over mass
74  * @param[in] mass species mass
75  * @param[in] B magnetic field magnitude
76  * @param[in] temp_ev reference temperature
78  * return normalized parallel velocity
79  */
80 KOKKOS_INLINE_FUNCTION double normalized_v_para(double c_m, double mass, double B, double temp_ev, double rho){
81  return c_m*rho*B*sqrt(mass/(temp_ev*EV_2_J));
82 }
83
84 /* Returns normalized sqrt(mu)
85  * @param[in] B magnetic field magnitude
86  * @param[in] temp_ev particle/reference temperature
87  * @param[out] mu mu
88  * return normalized sqrt(mu)
89 */
90 KOKKOS_INLINE_FUNCTION double normalized_sqrt_mu(double B, double temp_ev, double mu){
91  return sqrt(mu*2.0*B/(temp_ev*EV_2_J));
92 }
93
94 // Convert from {rho, mu} to {energy, pitch}
95 KOKKOS_INLINE_FUNCTION void rho_mu_to_en_pitch(double B, double c_m, double c2_2m, double mass, double rho, double mu, double& en, double& pitch){
96  en = mu*B + c2_2m*(rho*rho*B*B);
97  double v_para = c_m*rho*B;
98  double v_perp2 = 2.0*mu*B/mass;
99  pitch=v_para/sqrt(v_para*v_para + v_perp2);
100 }
101
102 // Convert from {energy, pitch} to {rho, mu}
103 KOKKOS_INLINE_FUNCTION void en_pitch_to_rho_mu(double B, double c_m, double mass, double en, double pitch, double& rho, double& mu){
104  rho = pitch*sqrt(2.0*en/mass)/(B*c_m);
105  mu = max(0.0,(1.0-pitch*pitch)*en/B);
106 }
107
108 #endif
KOKKOS_INLINE_FUNCTION double normalized_v_para(double c_m, double mass, double B, double temp_ev, double rho)
Definition: basic_physics.hpp:80
constexpr double EV_2_J
Conversion rate ev to J.
Definition: constants.hpp:5
KOKKOS_INLINE_FUNCTION double thermal_velocity(double mass, double temp_ev)
Definition: basic_physics.hpp:58
Definition: poisson_extra.F90:74
KOKKOS_INLINE_FUNCTION void en_pitch_to_rho_mu(double B, double c_m, double mass, double en, double pitch, double &rho, double &mu)
Definition: basic_physics.hpp:103
KOKKOS_INLINE_FUNCTION double maxwellian_dist(double den, double temp, double energy)
Definition: basic_physics.hpp:14
KOKKOS_INLINE_FUNCTION double kinetic_energy(double mass, double v)
Definition: basic_physics.hpp:8
KOKKOS_INLINE_FUNCTION void rho_mu_to_en_pitch(double B, double c_m, double c2_2m, double mass, double rho, double mu, double &en, double &pitch)
Definition: basic_physics.hpp:95
KOKKOS_INLINE_FUNCTION double normalize_to_vth(double mass, double temp_ev, double v)
Definition: basic_physics.hpp:68
KOKKOS_INLINE_FUNCTION double normalized_sqrt_mu(double B, double temp_ev, double mu)
Definition: basic_physics.hpp:90