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[6],double[3],long long int, long long int>;
10 #else
11 using ParticleDataTypes = Cabana::MemberTypes<double[6],double[3],long long int>;
12 #endif
13 // Just the phase
14 using PhaseDataTypes = Cabana::MemberTypes<double[6]>;
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 };
56 
57 // SoA particle structure, with inner array of length SIMD_SIZE (generally, VEC_LEN on CPU, 1 on GPU)
62 #ifdef ESC_PTL
63  Simd<long long int> flag;
64 #endif
65 
66  KOKKOS_INLINE_FUNCTION bool is_active(int i_simd) const{
67  return (gid[i_simd]>0);
68  }
69 
70  KOKKOS_INLINE_FUNCTION bool is_inactive(int i_simd) const{
71  return (gid[i_simd]<=0);
72  }
73 
76  KOKKOS_INLINE_FUNCTION void deactivate(const Simd<bool>& mask){
77  for (int i_simd = 0; i_simd<SIMD_SIZE; i_simd++){
78  // Don't reactivate particle
79  gid[i_simd] = (mask[i_simd] && is_active(i_simd)) ? -gid[i_simd] : gid[i_simd];
80  }
81  }
82 
85  KOKKOS_INLINE_FUNCTION void deactivate(int i_simd){
86  // Don't reactivate particle
87  gid[i_simd] = is_active(i_simd) ? -gid[i_simd] : gid[i_simd];
88  }
89 };
90 
91 // Phase
92 struct VecPhase{
93  double r[VEC_LEN];
94  double z[VEC_LEN];
95  double phi[VEC_LEN];
96  double rho[VEC_LEN];
97  double w1[VEC_LEN];
98  double w2[VEC_LEN];
99 };
100 
101 // Constants
103  double mu[VEC_LEN];
104  double w0[VEC_LEN];
105  double f0[VEC_LEN];
106 };
107 
108 // SoA particle structure, with inner array of length VEC_LEN (just like the AoSoA)
112  long long int gid[VEC_LEN];
113 #ifdef ESC_PTL
114  long long int flag[VEC_LEN];
115 #endif
116 
117  KOKKOS_INLINE_FUNCTION bool is_active(int i_vec) const{
118  return (gid[i_vec]>0);
119  }
120 
121  KOKKOS_INLINE_FUNCTION bool is_inactive(int i_vec) const{
122  return (gid[i_vec]<=0);
123  }
124 };
125 
126 // Other useful ways to access particles
127 template<int T>
129  double data[T*VEC_LEN];
130 };
131 
132 template<int T>
133 struct OneParticle{
134  double data[T];
135 };
136 
137 KOKKOS_INLINE_FUNCTION void update_phases(SimdPhase &ph_new, const SimdPhase &ph, double local_dt, const SimdPhase &dph);
138 
139 KOKKOS_INLINE_FUNCTION void simd_2_AoSoA(VecParticles *part, const SimdParticles &part_one, int a_vec, int s_vec);
140 
141 KOKKOS_INLINE_FUNCTION void AoSoA_2_simd(SimdParticles &part_one, const VecParticles *part, int a_vec, int s_vec);
142 
143 KOKKOS_INLINE_FUNCTION void update_dphm(SimdPhase &dphm,const SimdPhase &dpht);
144 
145 KOKKOS_INLINE_FUNCTION void update_dpht(SimdPhase &dpht,const SimdPhase &dph,const SimdPhase &dphm);
146 
147 template<class Device>
149  int s;
150  int a;
151 
152  KOKKOS_INLINE_FUNCTION AoSoAIndices(int idx);
153 };
154 
157 template<class Device>
158 KOKKOS_INLINE_FUNCTION AoSoAIndices<Device>::AoSoAIndices(int idx){
159  // CPU: access an array of particles
160  s = idx;
161  a = 0;
162 }
163 
164 #ifdef USE_GPU
165 
167 template<>
168 KOKKOS_INLINE_FUNCTION AoSoAIndices<DeviceType>::AoSoAIndices(int idx){
169  // GPU: access an individual particle
170  s = idx / VEC_LEN;
171  a = idx % VEC_LEN;
172 }
173 #endif
174 
177 template<class Device>
178 inline int p_range(int num_particle)
179 {
180  return divide_and_round_up(num_particle, VEC_LEN);
181 }
182 
183 #ifdef USE_GPU
184 
186 template<>
187 inline int p_range<DeviceType>(int num_particle)
188 {
189  return num_particle;
190 }
191 #endif
192 
194 inline int add_vec_buffer(int n_ptl) { return divide_and_round_up(n_ptl, VEC_LEN)*VEC_LEN;}
195 
196 #include "particles.tpp"
197 #endif
Cabana::MemberTypes< double[6]> PhaseDataTypes
Definition: particles.hpp:14
KOKKOS_INLINE_FUNCTION int divide_and_round_up(int a, int b)
Definition: globals.hpp:203
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:96
KOKKOS_INLINE_FUNCTION AoSoAIndices(int idx)
Definition: particles.hpp:158
Simd< double > w1
Definition: particles.hpp:22
Definition: particles.hpp:102
VecConstants ct
Definition: particles.hpp:111
Definition: particles.hpp:128
int add_vec_buffer(int n_ptl)
Definition: particles.hpp:194
Definition: particles.hpp:92
int a
The index in the inner array of the AoSoA.
Definition: particles.hpp:150
Definition: particles.hpp:109
KOKKOS_INLINE_FUNCTION bool is_active(int i_vec) const
Definition: particles.hpp:117
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:66
KOKKOS_INLINE_FUNCTION void AoSoA_2_simd(SimdParticles &part_one, const VecParticles *part, int a_vec, int s_vec)
Definition: particles.tpp:80
double data[T *VEC_LEN]
Definition: particles.hpp:129
Simd< double > rho
Definition: particles.hpp:21
int p_range< DeviceType >(int num_particle)
Definition: particles.hpp:187
KOKKOS_INLINE_FUNCTION bool is_inactive(int i_vec) const
Definition: particles.hpp:121
double w2[VEC_LEN]
Definition: particles.hpp:98
double mu[VEC_LEN]
Definition: particles.hpp:103
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:133
double w0[VEC_LEN]
Definition: particles.hpp:104
SimdPhase ph
Definition: particles.hpp:59
long long int gid[VEC_LEN]
Definition: particles.hpp:112
Simd< double > f0
Definition: particles.hpp:54
double f0[VEC_LEN]
Definition: particles.hpp:105
Definition: particles.hpp:58
VecPhase ph
Definition: particles.hpp:110
Definition: particles.hpp:51
double data[T]
Definition: particles.hpp:134
Cabana::MemberTypes< double[6], double[3], long long int > ParticleDataTypes
Definition: particles.hpp:11
int s
The index in the outer array of the AoSoA.
Definition: particles.hpp:149
Simd< double > z
Definition: particles.hpp:19
Simd< long long int > gid
Definition: particles.hpp:61
Simd< double > w0
Definition: particles.hpp:53
KOKKOS_INLINE_FUNCTION void deactivate(int i_simd)
Definition: particles.hpp:85
Simd< double > phi
Definition: particles.hpp:20
Definition: particles.hpp:17
Definition: simd.hpp:139
SimdConstants ct
Definition: particles.hpp:60
double phi[VEC_LEN]
Definition: particles.hpp:95
Simd< double > w2
Definition: particles.hpp:23
double r[VEC_LEN]
Definition: particles.hpp:93
int p_range(int num_particle)
Definition: particles.hpp:178
Simd< double > mu
Definition: particles.hpp:52
KOKKOS_INLINE_FUNCTION const SimdVector2D & x() const
Definition: particles.hpp:33
Definition: particles.hpp:148
double z[VEC_LEN]
Definition: particles.hpp:94
KOKKOS_INLINE_FUNCTION void deactivate(const Simd< bool > &mask)
Definition: particles.hpp:76
KOKKOS_INLINE_FUNCTION bool is_inactive(int i_simd) const
Definition: particles.hpp:70
double w1[VEC_LEN]
Definition: particles.hpp:97