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 
67 // Phase
68 struct VecPhase{
69  double r[VEC_LEN];
70  double z[VEC_LEN];
71  double phi[VEC_LEN];
72  double rho[VEC_LEN];
73  double w1[VEC_LEN];
74  double w2[VEC_LEN];
75 };
76 
77 // Constants
78 struct VecConstants{
79  double mu[VEC_LEN];
80  double w0[VEC_LEN];
81  double f0[VEC_LEN];
82 };
83 
84 // SoA particle structure, with inner array of length VEC_LEN (just like the AoSoA)
85 struct VecParticles{
88  long long int gid[VEC_LEN];
89 #ifdef ESC_PTL
90  long long int flag[VEC_LEN];
91 #endif
92 };
93 
94 // Other useful ways to access particles
95 template<int T>
97  double data[T*VEC_LEN];
98 };
99 
100 template<int T>
101 struct OneParticle{
102  double data[T];
103 };
104 
105 KOKKOS_INLINE_FUNCTION void remove_particles(Simd<long long int>& gid, const Simd<bool>& deactivate);
106 
107 KOKKOS_INLINE_FUNCTION void update_phases(SimdPhase &ph_new, const SimdPhase &ph, double local_dt, const SimdPhase &dph);
108 
109 KOKKOS_INLINE_FUNCTION void simd_2_AoSoA(VecParticles *part, const SimdParticles &part_one, int a_vec, int s_vec);
110 
111 KOKKOS_INLINE_FUNCTION void AoSoA_2_simd(SimdParticles &part_one, const VecParticles *part, int a_vec, int s_vec);
112 
113 KOKKOS_INLINE_FUNCTION void update_dphm(SimdPhase &dphm,const SimdPhase &dpht);
114 
115 KOKKOS_INLINE_FUNCTION void update_dpht(SimdPhase &dpht,const SimdPhase &dph,const SimdPhase &dphm);
116 
117 template<class Device>
119  int s;
120  int a;
121 
122  KOKKOS_INLINE_FUNCTION AoSoAIndices(int idx);
123 };
124 
127 template<class Device>
128 KOKKOS_INLINE_FUNCTION AoSoAIndices<Device>::AoSoAIndices(int idx){
129  // CPU: access an array of particles
130  s = idx;
131  a = 0;
132 }
133 
134 #ifdef USE_GPU
135 
137 template<>
138 KOKKOS_INLINE_FUNCTION AoSoAIndices<DeviceType>::AoSoAIndices(int idx){
139  // GPU: access an individual particle
140  s = idx / VEC_LEN;
141  a = idx % VEC_LEN;
142 }
143 #endif
144 
147 template<class Device>
148 inline int p_range(int num_particle)
149 {
150  return divide_and_round_up(num_particle, VEC_LEN);
151 }
152 
153 #ifdef USE_GPU
154 
156 template<>
157 inline int p_range<DeviceType>(int num_particle)
158 {
159  return num_particle;
160 }
161 #endif
162 
164 inline int add_vec_buffer(int n_ptl) { return divide_and_round_up(n_ptl, VEC_LEN)*VEC_LEN;}
165 
166 #include "particles.tpp"
167 #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:179
KOKKOS_INLINE_FUNCTION void update_dphm(SimdPhase &dphm, const SimdPhase &dpht)
Definition: particles.tpp:32
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:17
KOKKOS_INLINE_FUNCTION void simd_2_AoSoA(VecParticles *part, const SimdParticles &part_one, int a_vec, int s_vec)
Definition: particles.tpp:65
double rho[VEC_LEN]
Definition: particles.hpp:72
KOKKOS_INLINE_FUNCTION AoSoAIndices(int idx)
Definition: particles.hpp:128
Simd< double > w1
Definition: particles.hpp:22
Definition: particles.hpp:78
VecConstants ct
Definition: particles.hpp:87
Definition: particles.hpp:96
int add_vec_buffer(int n_ptl)
Definition: particles.hpp:164
Definition: particles.hpp:68
int a
The index in the inner array of the AoSoA.
Definition: particles.hpp:120
Definition: particles.hpp:85
KOKKOS_INLINE_FUNCTION void update_dpht(SimdPhase &dpht, const SimdPhase &dph, const SimdPhase &dphm)
Definition: particles.tpp:48
KOKKOS_INLINE_FUNCTION void AoSoA_2_simd(SimdParticles &part_one, const VecParticles *part, int a_vec, int s_vec)
Definition: particles.tpp:91
double data[T *VEC_LEN]
Definition: particles.hpp:97
Simd< double > rho
Definition: particles.hpp:21
int p_range< DeviceType >(int num_particle)
Definition: particles.hpp:157
double w2[VEC_LEN]
Definition: particles.hpp:74
double mu[VEC_LEN]
Definition: particles.hpp:79
idx
Definition: diag_f0_df_port1.hpp:32
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:101
double w0[VEC_LEN]
Definition: particles.hpp:80
SimdPhase ph
Definition: particles.hpp:59
long long int gid[VEC_LEN]
Definition: particles.hpp:88
Simd< double > f0
Definition: particles.hpp:54
double f0[VEC_LEN]
Definition: particles.hpp:81
Definition: particles.hpp:58
VecPhase ph
Definition: particles.hpp:86
Definition: particles.hpp:51
double data[T]
Definition: particles.hpp:102
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:119
Simd< double > z
Definition: particles.hpp:19
Simd< long long int > gid
Definition: particles.hpp:61
Simd< double > w0
Definition: particles.hpp:53
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:71
Simd< double > w2
Definition: particles.hpp:23
double r[VEC_LEN]
Definition: particles.hpp:69
int p_range(int num_particle)
Definition: particles.hpp:148
Simd< double > mu
Definition: particles.hpp:52
KOKKOS_INLINE_FUNCTION void remove_particles(Simd< long long int > &gid, const Simd< bool > &deactivate)
Definition: particles.tpp:4
KOKKOS_INLINE_FUNCTION const SimdVector2D & x() const
Definition: particles.hpp:33
Definition: particles.hpp:118
double z[VEC_LEN]
Definition: particles.hpp:70
double w1[VEC_LEN]
Definition: particles.hpp:73