XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
globals.hpp
Go to the documentation of this file.
1 #ifndef GLOBALS_HPP
2 #define GLOBALS_HPP
3 #include <limits.h>
4 #include <string>
5 #include "space_settings.hpp"
6 #include "array_deep_copy.hpp"
7 #include "access_add.hpp"
8 #include "simd.hpp"
9 #ifdef USE_MPI
10 #include "my_mpi.hpp"
11 #endif
12 
13 /* Return true if MPI rank is zero
14  * */
15 inline bool is_rank_zero(){
16 #ifdef USE_MPI
17  return SML_COMM_RANK==0;
18 #else
19  return true;
20 #endif
21 }
22 
23 /* Safely abort and exit the code
24  * */
25 inline void exit_XGC(std::string msg){
26  printf("%s",msg.c_str());
27  fflush(stdout);
28 #ifdef USE_MPI
29  MPI_Abort(SML_COMM_WORLD, 1);
30 #else
31  exit(1);
32 #endif
33 }
34 
35 /* Check that two integers multiplied together doesn't cause an overflow
36  * */
37 inline bool causes_multiplication_overflow(int a,int b){
38  int c = a*b;
39  if(b==0) return false; // No overflow
40  return !(c/b == a);
41 }
42 
43 /* Check that two integers added together doesn't cause an overflow
44  * */
45 inline bool causes_addition_overflow(int a,int b){
46  if ( ((b > 0) && (a > INT_MAX - b)) // a + b would overflow
47  ||((b < 0) && (a < INT_MIN - b)) ){ // a + b would underflow
48  return true;
49  } else {
50  return false;
51  }
52 }
53 
55  ELECTRON = 0,
57 };
58 
59 enum KinType{
62 };
63 
65  PIR = 0,
66  PIZ,
67  PIP,
69  PIW1,
70  PIW2,
72 };
73 
75  PIM = 0,
76  PIW0,
77  PIF0,
79 };
80 
81 const double UNIT_CHARGE = 1.6022e-19;
82 const double EV_2_J=UNIT_CHARGE;
83 const double J_2_EV=1.0/EV_2_J;
84 const double PROTON_MASS = 1.6720e-27; //< proton mass (MKS)
85 const double PI = 3.1415926535897932; //< pi
86 const double TWOPI = 6.2831853071795862; //< 2 pi
87 
88 // Divide two integers, then round up
89 KOKKOS_INLINE_FUNCTION int divide_and_round_up(int a, int b){
90  return (a+b-1)/b;
91 }
92 
93 // Diagnostics
94 const int DIAG_HEAT_NVAR = 5;
95 const int N_VF_DIAG = 9;
96 #ifdef XGC1
97  const int D1D_NPV1 = 16;
98 #else
99  const int D1D_NPV1 = 18;
100 #endif
101 
102 /*** SIMD structures (probably temporary) ****/
103 
104 
108 };
109 
110 struct SimdVector{
114 
115  // Vector operation, sets SimdVector to 0.0
116  KOKKOS_INLINE_FUNCTION void zero(){
117  for (int i_simd = 0; i_simd<SIMD_SIZE; i_simd++){
118  r[i_simd] = 0.0;
119  z[i_simd] = 0.0;
120  phi[i_simd] = 0.0;
121  }
122  }
123 };
124 
125 /* Fortran pointers */
126 // This type is used to refer to fortran pointers that we never plan on using (i.e. dereferencing) inside the C++ code.
127 // The reason we don't use them in the C++ code is that the objects being referred to (spall, grid, psn), are very complicated.
128 // In order to use them, we would need to carefully create the equivalent object in C++, and since developers tend to add members
129 // to those Fortran objects on the fly, using them in C++ would be prone to bugs.
130 // Here we tell C++ that the pointer is to an integer, i.e. int *. This could be anything, but int works.
131 typedef int* FortranPtr;
132 
133 #endif
Definition: globals.hpp:55
Simd< double > r
Definition: globals.hpp:111
Magnetic moment mu.
Definition: globals.hpp:75
KOKKOS_INLINE_FUNCTION int divide_and_round_up(int a, int b)
Definition: globals.hpp:89
Definition: globals.hpp:110
bool is_rank_zero()
Definition: globals.hpp:15
gyroradius
Definition: globals.hpp:68
MPI_Comm SML_COMM_WORLD
Definition: my_mpi.cpp:4
int * FortranPtr
Definition: globals.hpp:131
const double EV_2_J
Conversion rate ev to J.
Definition: globals.hpp:82
Definition: globals.hpp:60
W0.
Definition: globals.hpp:76
bool causes_multiplication_overflow(int a, int b)
Definition: globals.hpp:37
Definition: globals.hpp:71
const double TWOPI
Definition: globals.hpp:86
const double UNIT_CHARGE
Charge of an electron (C)
Definition: globals.hpp:81
const int DIAG_HEAT_NVAR
Definition: globals.hpp:94
r coordinate
Definition: globals.hpp:65
const int N_VF_DIAG
Definition: globals.hpp:95
Simd< double > z
Definition: globals.hpp:107
Definition: globals.hpp:78
Definition: globals.hpp:61
const int D1D_NPV1
Definition: globals.hpp:99
Simd< double > phi
Definition: globals.hpp:113
ParticlePhase
Definition: globals.hpp:64
Simd< double > z
Definition: globals.hpp:112
2nd weight
Definition: globals.hpp:70
int SML_COMM_RANK
Definition: my_mpi.cpp:5
KinType
Definition: globals.hpp:59
Simd< double > r
Definition: globals.hpp:106
Definition: globals.hpp:56
void exit_XGC(std::string msg)
Definition: globals.hpp:25
F0.
Definition: globals.hpp:77
Definition: globals.hpp:105
KOKKOS_INLINE_FUNCTION void zero()
Definition: globals.hpp:116
phi coordinate
Definition: globals.hpp:67
const double PROTON_MASS
Definition: globals.hpp:84
const double J_2_EV
Conversion rate J to ev.
Definition: globals.hpp:83
1st weight
Definition: globals.hpp:69
const double PI
Definition: globals.hpp:85
ParticleConsts
Definition: globals.hpp:74
z coordinate
Definition: globals.hpp:66
SpeciesType
Definition: globals.hpp:54
bool causes_addition_overflow(int a, int b)
Definition: globals.hpp:45