XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // T and E are EV units for XGC normalization-particle.
15 KOKKOS_INLINE_FUNCTION double maxwellian_dist(double den, double temp, double energy){
16  return den/(temp*sqrt(temp))*exp(-min(EXP_LIM,energy/temp));
17 }
18 
19 // Maxwellian distribution of 1D velocity part
20 // sqrt(m/TWOPI e) is missing when temp and energy are in eV unit.
21 // sqrt(m/TWOPI) is missing when temp and energy are in Joule.
22 // (1.0 - exp(-maxe)) is correction factor since the energy is finite
23 KOKKOS_INLINE_FUNCTION double maxwellian_dist_1d_v(double temp, double energy, double maxe){
24  return 1.0/sqrt(temp)*exp(-min(EXP_LIM,energy/temp)) / (1.0-exp(-maxe));
25 }
26 
27 // Maxwellian distribution of 2D velocity part
28 // m/(TWOPI e) is missing when temp and energy are in eV unit.
29 // m/TWOPI is missing when temp and energy are in Joule.
30 // (1.0 - exp(-maxe)) is correction factor since the energy is finite
31 KOKKOS_INLINE_FUNCTION double maxwellian_dist_2d_v(double temp, double energy, double maxe){
32  return 1.0/temp*exp(-min(EXP_LIM,energy/temp)) / (1.0-exp(-maxe));
33 }
34 
35 // Return adiabatic exponential factor
36 // Should be the same as get_ad of f0module.F90
37 // When the modified adiabatic function is used, the adiabatic response becomes
38 // linear function in (-a,a) --> exp_ad(x) = 1+x
39 // exponential decay to zero in x<-a --> exp_ad(x)=exp(-|x|+a)*(1-a)
40 // This satisfies continuous condition
41 // mirror symmetry (0,1) --> x-> -x, y-> 2-y
42 // for (x>a), exp_ad(x)=2 - exp(-|x|+a)*(1-a)
43 KOKKOS_INLINE_FUNCTION double exp_ad(double x){
44 #ifdef USE_LINEAR_ADIABATIC_RESPONSE
45  constexpr bool use_linear = true;
46 #else
47  constexpr bool use_linear = false;
48 #endif
49 
50 #ifdef LINEAR_ADIABATIC_RESPONSE_BD
51  constexpr double lim=LINEAR_ADIABATIC_RESPONSE_BD;
52 #else
53  constexpr double lim=0.7;
54 #endif
55  if constexpr(use_linear){
56  double tmp = exp(-abs(x)+lim)*(1-lim);
57  double tmp2 = (x<-lim ? tmp : 1.0+x);
58  return (x>lim ? 2.0-tmp : tmp2);
59  } else {
60  return exp(x);
61  }
62 }
63 
64 // gyro_radius
65 KOKKOS_INLINE_FUNCTION double gyro_radius(double B, double mu, double c2_2m){
66  return sqrt(mu/(B*c2_2m));
67 }
68 
69 /* Returns thermal velocity
70  * @param[in] mass species mass
71  * @param[in] temp_ev reference temperature
72  * return thermal velocity
73  */
74 KOKKOS_INLINE_FUNCTION double thermal_velocity(double mass, double temp_ev){
75  return sqrt((temp_ev*EV_2_J)/mass);
76 }
77 
78 /* Returns velocity normalized by thermal velocity
79  * @param[in] mass species mass
80  * @param[in] temp_ev reference temperature
81  * @param[in] v input velocity
82  * return normalized velocity
83  */
84 KOKKOS_INLINE_FUNCTION double normalize_to_vth(double mass, double temp_ev, double v){
85  return v*sqrt(mass/(temp_ev*EV_2_J));
86 }
87 
88 /* Returns normalized parallel velocity
89  * @param[in] c_m species charge over mass
90  * @param[in] mass species mass
91  * @param[in] B magnetic field magnitude
92  * @param[in] temp_ev reference temperature
93  * @param[in] rho gyroradius
94  * return normalized parallel velocity
95  */
96 KOKKOS_INLINE_FUNCTION double normalized_v_para(double c_m, double mass, double B, double temp_ev, double rho){
97  return c_m*rho*B*sqrt(mass/(temp_ev*EV_2_J));
98 }
99 
100 /* Returns normalized sqrt(mu)
101  * @param[in] B magnetic field magnitude
102  * @param[in] temp_ev particle/reference temperature
103  * @param[out] mu mu
104  * return normalized sqrt(mu)
105 */
106 KOKKOS_INLINE_FUNCTION double normalized_sqrt_mu(double B, double temp_ev, double mu){
107  return sqrt(mu*2.0*B/(temp_ev*EV_2_J));
108 }
109 
110 // Convert from {rho, mu} to {energy, pitch}
111 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){
112  en = mu*B + c2_2m*(rho*rho*B*B);
113  double v_para = c_m*rho*B;
114  double v_perp2 = 2.0*mu*B/mass;
115  pitch=v_para/sqrt(v_para*v_para + v_perp2);
116 }
117 
118 // Convert from {energy, pitch} to {rho, mu}
119 KOKKOS_INLINE_FUNCTION void en_pitch_to_rho_mu(double B, double c_m, double mass, double en, double pitch, double& rho, double& mu){
120  rho = pitch*sqrt(2.0*en/mass)/(B*c_m);
121  mu = max(0.0,(1.0-pitch*pitch)*en/B);
122 }
123 
124 #endif
KOKKOS_INLINE_FUNCTION double normalized_v_para(double c_m, double mass, double B, double temp_ev, double rho)
Definition: basic_physics.hpp:96
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:74
real(kind=8) function gyro_radius(x, mu, isp)
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:119
KOKKOS_INLINE_FUNCTION double maxwellian_dist(double den, double temp, double energy)
Definition: basic_physics.hpp:15
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:111
KOKKOS_INLINE_FUNCTION double maxwellian_dist_1d_v(double temp, double energy, double maxe)
Definition: basic_physics.hpp:23
KOKKOS_INLINE_FUNCTION double normalize_to_vth(double mass, double temp_ev, double v)
Definition: basic_physics.hpp:84
KOKKOS_INLINE_FUNCTION double normalized_sqrt_mu(double B, double temp_ev, double mu)
Definition: basic_physics.hpp:106
KOKKOS_INLINE_FUNCTION double maxwellian_dist_2d_v(double temp, double energy, double maxe)
Definition: basic_physics.hpp:31
KOKKOS_INLINE_FUNCTION double exp_ad(double x)
Definition: basic_physics.hpp:43
const double EXP_LIM
Limit of exponents.
Definition: constants.hpp:14