XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
particles.hpp
Go to the documentation of this file.
1 #ifndef PARTICLES_HPP
2 #define PARTICLES_HPP
3 #include <Cabana_AoSoA.hpp>
4 #include <Kokkos_Core.hpp>
5 #include "globals.hpp"
6 
7 // Set the type for the particle AoSoA.
8 #ifdef ESC_PTL
9 using ParticleDataTypes = Cabana::MemberTypes<double[PTL_NPHASE],double[PTL_NCONST],long long int, long long int>;
10 #else
11 using ParticleDataTypes = Cabana::MemberTypes<double[PTL_NPHASE],double[PTL_NCONST],long long int>;
12 #endif
13 // Just the phase
14 using PhaseDataTypes = Cabana::MemberTypes<double[PTL_NPHASE]>;
15 
16 // Phase
17 struct SimdPhase{
24 
25  /* Returns a SimdVector2D alias to r and z
26  * */
27  KOKKOS_INLINE_FUNCTION SimdVector2D& x() {
28  return *(reinterpret_cast<SimdVector2D*>(this));
29  }
30 
31  /* Returns a SimdVector2D alias to r and z
32  * */
33  KOKKOS_INLINE_FUNCTION const SimdVector2D& x() const {
34  return *(reinterpret_cast<const SimdVector2D*>(this));
35  }
36 
37  /* Returns a SimdVector alias to r, z, and phi
38  * */
39  KOKKOS_INLINE_FUNCTION SimdVector& v() {
40  return *(reinterpret_cast<SimdVector*>(this));
41  }
42 
43  /* Returns a SimdVector alias to r, z, and phi
44  * */
45  KOKKOS_INLINE_FUNCTION const SimdVector& v() const {
46  return *(reinterpret_cast<const SimdVector*>(this));
47  }
48 };
49 
50 // Constants
55 #ifdef PTL_G2
56  Simd<double> g2;
57 #endif
58 };
59 
60 // SoA particle structure, with inner array of length SIMD_SIZE (generally, VEC_LEN on CPU, 1 on GPU)
65 #ifdef ESC_PTL
66  Simd<long long int> flag;
67 #endif
68 
69  KOKKOS_INLINE_FUNCTION bool is_active(int i_simd) const{
70  return (gid[i_simd]>0);
71  }
72 
73  KOKKOS_INLINE_FUNCTION bool is_inactive(int i_simd) const{
74  return (gid[i_simd]<=0);
75  }
76 
79  KOKKOS_INLINE_FUNCTION void deactivate(const Simd<bool>& mask){
80  for (int i_simd = 0; i_simd<SIMD_SIZE; i_simd++){
81  // Don't reactivate particle
82  gid[i_simd] = (mask[i_simd] && is_active(i_simd)) ? -gid[i_simd] : gid[i_simd];
83  }
84  }
85 
88  KOKKOS_INLINE_FUNCTION void deactivate(int i_simd){
89  // Don't reactivate particle
90  gid[i_simd] = is_active(i_simd) ? -gid[i_simd] : gid[i_simd];
91  }
92 };
93 
94 // Phase
95 struct VecPhase{
96  double r[VEC_LEN];
97  double z[VEC_LEN];
98  double phi[VEC_LEN];
99  double rho[VEC_LEN];
100  double w1[VEC_LEN];
101  double w2[VEC_LEN];
102 };
103 
104 // Constants
106  double mu[VEC_LEN];
107  double w0[VEC_LEN];
108  double f0[VEC_LEN];
109 #ifdef PTL_G2
110  double g2[VEC_LEN];
111 #endif
112 };
113 
114 // SoA particle structure, with inner array of length VEC_LEN (just like the AoSoA)
118  long long int gid[VEC_LEN];
119 #ifdef ESC_PTL
120  long long int flag[VEC_LEN];
121 #endif
122 
123  KOKKOS_INLINE_FUNCTION bool is_active(int i_vec) const{
124  return (gid[i_vec]>0);
125  }
126 
127  KOKKOS_INLINE_FUNCTION bool is_inactive(int i_vec) const{
128  return (gid[i_vec]<=0);
129  }
130 };
131 
132 // Other useful ways to access particles
133 template<int T>
135  double data[T*VEC_LEN];
136 };
137 
138 template<int T>
139 struct OneParticle{
140  double data[T];
141 };
142 
143 KOKKOS_INLINE_FUNCTION void update_phases(SimdPhase &ph_new, const SimdPhase &ph, double local_dt, const SimdPhase &dph);
144 
145 KOKKOS_INLINE_FUNCTION void simd_2_AoSoA(VecParticles *part, const SimdParticles &part_one, int a_vec, int s_vec);
146 
147 KOKKOS_INLINE_FUNCTION void AoSoA_2_simd(SimdParticles &part_one, const VecParticles *part, int a_vec, int s_vec);
148 
149 KOKKOS_INLINE_FUNCTION void update_dphm(SimdPhase &dphm,const SimdPhase &dpht);
150 
151 KOKKOS_INLINE_FUNCTION void update_dpht(SimdPhase &dpht,const SimdPhase &dph,const SimdPhase &dphm);
152 
153 template<class Device>
155  int s;
156  int a;
157 
158  KOKKOS_INLINE_FUNCTION AoSoAIndices(int idx);
159 };
160 
163 template<class Device>
164 KOKKOS_INLINE_FUNCTION AoSoAIndices<Device>::AoSoAIndices(int idx){
165  // CPU: access an array of particles
166  s = idx;
167  a = 0;
168 }
169 
170 #ifdef USE_GPU
171 
173 template<>
174 KOKKOS_INLINE_FUNCTION AoSoAIndices<DeviceType>::AoSoAIndices(int idx){
175  // GPU: access an individual particle
176  s = idx / VEC_LEN;
177  a = idx % VEC_LEN;
178 }
179 #endif
180 
183 template<class Device>
184 inline int p_range(int num_particle)
185 {
186  return divide_and_round_up(num_particle, VEC_LEN);
187 }
188 
189 #ifdef USE_GPU
190 
192 template<>
193 inline int p_range<DeviceType>(int num_particle)
194 {
195  return num_particle;
196 }
197 #endif
198 
200 inline int add_vec_buffer(int n_ptl) { return divide_and_round_up(n_ptl, VEC_LEN)*VEC_LEN;}
201 
202 #include "particles.tpp"
203 #endif
KOKKOS_INLINE_FUNCTION int divide_and_round_up(int a, int b)
Definition: globals.hpp:206
KOKKOS_INLINE_FUNCTION void update_dphm(SimdPhase &dphm, const SimdPhase &dpht)
Definition: particles.tpp:21
Definition: simd.hpp:149
KOKKOS_INLINE_FUNCTION const SimdVector & v() const
Definition: particles.hpp:45
KOKKOS_INLINE_FUNCTION void update_phases(SimdPhase &ph_new, const SimdPhase &ph, double local_dt, const SimdPhase &dph)
Definition: particles.tpp:6
KOKKOS_INLINE_FUNCTION void simd_2_AoSoA(VecParticles *part, const SimdParticles &part_one, int a_vec, int s_vec)
Definition: particles.tpp:54
double rho[VEC_LEN]
Definition: particles.hpp:99
KOKKOS_INLINE_FUNCTION AoSoAIndices(int idx)
Definition: particles.hpp:164
Simd< double > w1
Definition: particles.hpp:22
Definition: particles.hpp:105
VecConstants ct
Definition: particles.hpp:117
Definition: particles.hpp:134
int add_vec_buffer(int n_ptl)
Definition: particles.hpp:200
Definition: particles.hpp:95
int a
The index in the inner array of the AoSoA.
Definition: particles.hpp:156
Definition: particles.hpp:115
KOKKOS_INLINE_FUNCTION bool is_active(int i_vec) const
Definition: particles.hpp:123
KOKKOS_INLINE_FUNCTION void update_dpht(SimdPhase &dpht, const SimdPhase &dph, const SimdPhase &dphm)
Definition: particles.tpp:37
KOKKOS_INLINE_FUNCTION bool is_active(int i_simd) const
Definition: particles.hpp:69
KOKKOS_INLINE_FUNCTION void AoSoA_2_simd(SimdParticles &part_one, const VecParticles *part, int a_vec, int s_vec)
Definition: particles.tpp:83
double data[T *VEC_LEN]
Definition: particles.hpp:135
Simd< double > rho
Definition: particles.hpp:21
int p_range< DeviceType >(int num_particle)
Definition: particles.hpp:193
KOKKOS_INLINE_FUNCTION bool is_inactive(int i_vec) const
Definition: particles.hpp:127
double w2[VEC_LEN]
Definition: particles.hpp:101
double mu[VEC_LEN]
Definition: particles.hpp:106
Simd< double > r
Definition: particles.hpp:18
KOKKOS_INLINE_FUNCTION SimdVector2D & x()
Definition: particles.hpp:27
KOKKOS_INLINE_FUNCTION SimdVector & v()
Definition: particles.hpp:39
Definition: particles.hpp:139
double w0[VEC_LEN]
Definition: particles.hpp:107
SimdPhase ph
Definition: particles.hpp:62
long long int gid[VEC_LEN]
Definition: particles.hpp:118
Simd< double > f0
Definition: particles.hpp:54
double f0[VEC_LEN]
Definition: particles.hpp:108
Definition: particles.hpp:61
VecPhase ph
Definition: particles.hpp:116
Definition: particles.hpp:51
double data[T]
Definition: particles.hpp:140
int s
The index in the outer array of the AoSoA.
Definition: particles.hpp:155
Simd< double > z
Definition: particles.hpp:19
Simd< long long int > gid
Definition: particles.hpp:64
Simd< double > w0
Definition: particles.hpp:53
KOKKOS_INLINE_FUNCTION void deactivate(int i_simd)
Definition: particles.hpp:88
Simd< double > phi
Definition: particles.hpp:20
Definition: particles.hpp:17
Definition: simd.hpp:139
SimdConstants ct
Definition: particles.hpp:63
double phi[VEC_LEN]
Definition: particles.hpp:98
Simd< double > w2
Definition: particles.hpp:23
double r[VEC_LEN]
Definition: particles.hpp:96
int p_range(int num_particle)
Definition: particles.hpp:184
Simd< double > mu
Definition: particles.hpp:52
Cabana::MemberTypes< double[PTL_NPHASE], double[PTL_NCONST], long long int > ParticleDataTypes
Definition: particles.hpp:11
KOKKOS_INLINE_FUNCTION const SimdVector2D & x() const
Definition: particles.hpp:33
Definition: particles.hpp:154
double z[VEC_LEN]
Definition: particles.hpp:97
Cabana::MemberTypes< double[PTL_NPHASE]> PhaseDataTypes
Definition: particles.hpp:14
KOKKOS_INLINE_FUNCTION void deactivate(const Simd< bool > &mask)
Definition: particles.hpp:79
KOKKOS_INLINE_FUNCTION bool is_inactive(int i_simd) const
Definition: particles.hpp:73
double w1[VEC_LEN]
Definition: particles.hpp:100