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 <cassert>
6 #include "space_settings.hpp"
7 #include "array_deep_copy.hpp"
8 #include "access_add.hpp"
9 #include "simd.hpp"
10 #ifdef USE_MPI
11 #include "my_mpi.hpp"
12 #endif
13 
14 /* Return true if MPI rank is zero
15  * */
16 inline bool is_rank_zero(){
17 #ifdef USE_MPI
18  return SML_COMM_RANK==0;
19 #else
20  return true;
21 #endif
22 }
23 
24 /* Safely abort and exit the code
25  * */
26 inline void exit_XGC(std::string msg){
27  printf("%s",msg.c_str());
28  fflush(stdout);
29 #ifdef USE_MPI
30  MPI_Abort(SML_COMM_WORLD, 1);
31 #else
32  exit(1);
33 #endif
34 }
35 
36 /* Asserts condition
37  * (Callable from Device)
38  * (C++ has no standardized assert with a message)
39  * */
40 KOKKOS_INLINE_FUNCTION void assert_XGC(bool cond, const char* msg){
41  if(!cond){
42  DEVICE_PRINTF("%s",msg);
43  assert(false);
44  }
45 }
46 
47 /* Check that two integers multiplied together doesn't cause an overflow
48  * */
49 inline bool causes_multiplication_overflow(int a,int b){
50  int c = a*b;
51  if(b==0) return false; // No overflow
52  return !(c/b == a);
53 }
54 
55 /* Check that two integers added together doesn't cause an overflow
56  * */
57 inline bool causes_addition_overflow(int a,int b){
58  if ( ((b > 0) && (a > INT_MAX - b)) // a + b would overflow
59  ||((b < 0) && (a < INT_MIN - b)) ){ // a + b would underflow
60  return true;
61  } else {
62  return false;
63  }
64 }
65 
67  ELECTRON = 0,
69 };
70 
71 enum KinType{
74 };
75 
77  PIR = 0,
78  PIZ,
79  PIP,
81  PIW1,
82  PIW2,
84 };
85 
87  PIM = 0,
88  PIW0,
89  PIF0,
91 };
92 
93 const double UNIT_CHARGE = 1.6022e-19;
94 const double EV_2_J=UNIT_CHARGE;
95 const double J_2_EV=1.0/EV_2_J;
96 const double PROTON_MASS = 1.6720e-27; //< proton mass (MKS)
97 const double PI = 3.1415926535897932; //< pi
98 const double TWOPI = 6.2831853071795862; //< 2 pi
99 
100 // Divide two integers, then round up
101 KOKKOS_INLINE_FUNCTION int divide_and_round_up(int a, int b){
102  return (a+b-1)/b;
103 }
104 
105 /*** SIMD structures (probably temporary) ****/
106 
107 
111 };
112 
113 struct SimdVector{
117 
118  // Vector operation, sets SimdVector to 0.0
119  KOKKOS_INLINE_FUNCTION void zero(){
120  for (int i_simd = 0; i_simd<SIMD_SIZE; i_simd++){
121  r[i_simd] = 0.0;
122  z[i_simd] = 0.0;
123  phi[i_simd] = 0.0;
124  }
125  }
126 };
127 
128 #endif
Definition: globals.hpp:67
Simd< double > r
Definition: globals.hpp:114
Magnetic moment mu.
Definition: globals.hpp:87
KOKKOS_INLINE_FUNCTION int divide_and_round_up(int a, int b)
Definition: globals.hpp:101
Definition: globals.hpp:113
bool is_rank_zero()
Definition: globals.hpp:16
gyroradius
Definition: globals.hpp:80
MPI_Comm SML_COMM_WORLD
Definition: my_mpi.cpp:4
#define DEVICE_PRINTF(...)
Definition: space_settings.hpp:68
const double EV_2_J
Conversion rate ev to J.
Definition: globals.hpp:94
Definition: globals.hpp:72
W0.
Definition: globals.hpp:88
bool causes_multiplication_overflow(int a, int b)
Definition: globals.hpp:49
Definition: globals.hpp:83
const double TWOPI
Definition: globals.hpp:98
const double UNIT_CHARGE
Charge of an electron (C)
Definition: globals.hpp:93
r coordinate
Definition: globals.hpp:77
Simd< double > z
Definition: globals.hpp:110
Definition: globals.hpp:90
Definition: globals.hpp:73
Simd< double > phi
Definition: globals.hpp:116
ParticlePhase
Definition: globals.hpp:76
Simd< double > z
Definition: globals.hpp:115
2nd weight
Definition: globals.hpp:82
int SML_COMM_RANK
Definition: my_mpi.cpp:5
KinType
Definition: globals.hpp:71
Simd< double > r
Definition: globals.hpp:109
Definition: globals.hpp:68
void exit_XGC(std::string msg)
Definition: globals.hpp:26
F0.
Definition: globals.hpp:89
Definition: globals.hpp:108
KOKKOS_INLINE_FUNCTION void zero()
Definition: globals.hpp:119
phi coordinate
Definition: globals.hpp:79
const double PROTON_MASS
Definition: globals.hpp:96
const double J_2_EV
Conversion rate J to ev.
Definition: globals.hpp:95
1st weight
Definition: globals.hpp:81
const double PI
Definition: globals.hpp:97
ParticleConsts
Definition: globals.hpp:86
z coordinate
Definition: globals.hpp:78
SpeciesType
Definition: globals.hpp:66
bool causes_addition_overflow(int a, int b)
Definition: globals.hpp:57
KOKKOS_INLINE_FUNCTION void assert_XGC(bool cond, const char *msg)
Definition: globals.hpp:40