XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 using ParticleDataTypes = Cabana::MemberTypes<double[6],double[3],long long int>;
9 
10 // Just the phase
11 using PhaseDataTypes = Cabana::MemberTypes<double[6]>;
12 
13 // Phase
14 struct SimdPhase{
21 };
22 
23 // Constants
28 };
29 
30 // SoA particle structure, with inner array of length SIMD_SIZE (generally, VEC_LEN on CPU, 1 on GPU)
35 };
36 
37 // Phase
38 struct VecPhase{
39  double r[VEC_LEN];
40  double z[VEC_LEN];
41  double phi[VEC_LEN];
42  double rho[VEC_LEN];
43  double w1[VEC_LEN];
44  double w2[VEC_LEN];
45 };
46 
47 // Constants
48 struct VecConstants{
49  double mu[VEC_LEN];
50  double w0[VEC_LEN];
51  double f0[VEC_LEN];
52 };
53 
54 // SoA particle structure, with inner array of length VEC_LEN (just like the AoSoA)
55 struct VecParticles{
58  long long int gid[VEC_LEN];
59 };
60 
61 KOKKOS_INLINE_FUNCTION void remove_particles(Simd<long long int>& gid, const Simd<bool>& deactivate);
62 
63 KOKKOS_INLINE_FUNCTION void update_phases(SimdPhase &ph_new, const SimdPhase &ph, double local_dt, const SimdPhase &dph);
64 
65 KOKKOS_INLINE_FUNCTION void simd_2_AoSoA(VecParticles *part, const SimdParticles &part_one, int a_vec, int s_vec);
66 
67 KOKKOS_INLINE_FUNCTION void AoSoA_2_simd(SimdParticles &part_one, const VecParticles *part, int a_vec, int s_vec);
68 
69 KOKKOS_INLINE_FUNCTION void update_dphm(SimdPhase &dphm,const SimdPhase &dpht);
70 
71 KOKKOS_INLINE_FUNCTION void update_dpht(SimdPhase &dpht,const SimdPhase &dph,const SimdPhase &dphm);
72 
73 template<class Device>
74 struct AoSoAIndices{
75  int s;
76  int a;
77 
78  KOKKOS_INLINE_FUNCTION AoSoAIndices(int idx);
79 };
80 
83 template<class Device>
84 KOKKOS_INLINE_FUNCTION AoSoAIndices<Device>::AoSoAIndices(int idx){
85  // CPU: access an array of particles
86  s = idx;
87  a = 0;
88 }
89 
90 #ifdef USE_GPU
91 
93 template<>
94 KOKKOS_INLINE_FUNCTION AoSoAIndices<DeviceType>::AoSoAIndices(int idx){
95  // GPU: access an individual particle
96  s = idx / VEC_LEN;
97  a = idx % VEC_LEN;
98 }
99 #endif
100 
103 template<class Device>
104 inline int p_range(int num_particle)
105 {
106  return divide_and_round_up(num_particle, VEC_LEN);
107 }
108 
109 #ifdef USE_GPU
110 
112 template<>
113 inline int p_range<DeviceType>(int num_particle)
114 {
115  return num_particle;
116 }
117 #endif
118 
120 inline int add_vec_buffer(int n_ptl) { return divide_and_round_up(n_ptl, VEC_LEN)*VEC_LEN;}
121 
122 #include "particles.tpp"
123 #endif
Cabana::MemberTypes< double[6]> PhaseDataTypes
Definition: particles.hpp:11
KOKKOS_INLINE_FUNCTION int divide_and_round_up(int a, int b)
Definition: globals.hpp:43
KOKKOS_INLINE_FUNCTION void update_dphm(SimdPhase &dphm, const SimdPhase &dpht)
Definition: particles.tpp:32
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:42
KOKKOS_INLINE_FUNCTION AoSoAIndices(int idx)
Definition: particles.hpp:84
Simd< double > w1
Definition: particles.hpp:19
Definition: particles.hpp:48
VecConstants ct
Definition: particles.hpp:57
int add_vec_buffer(int n_ptl)
Definition: particles.hpp:120
Definition: particles.hpp:38
int a
The index in the inner array of the AoSoA.
Definition: particles.hpp:76
Definition: particles.hpp:55
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:88
Simd< double > rho
Definition: particles.hpp:18
int p_range< DeviceType >(int num_particle)
Definition: particles.hpp:113
double w2[VEC_LEN]
Definition: particles.hpp:44
double mu[VEC_LEN]
Definition: particles.hpp:49
Simd< double > r
Definition: particles.hpp:15
double w0[VEC_LEN]
Definition: particles.hpp:50
SimdPhase ph
Definition: particles.hpp:32
long long int gid[VEC_LEN]
Definition: particles.hpp:58
Simd< double > f0
Definition: particles.hpp:27
double f0[VEC_LEN]
Definition: particles.hpp:51
Definition: particles.hpp:31
VecPhase ph
Definition: particles.hpp:56
Definition: particles.hpp:24
Cabana::MemberTypes< double[6], double[3], long long int > ParticleDataTypes
Definition: particles.hpp:8
int s
The index in the outer array of the AoSoA.
Definition: particles.hpp:75
Simd< double > z
Definition: particles.hpp:16
Simd< long long int > gid
Definition: particles.hpp:34
Simd< double > w0
Definition: particles.hpp:26
Simd< double > phi
Definition: particles.hpp:17
Definition: particles.hpp:14
SimdConstants ct
Definition: particles.hpp:33
double phi[VEC_LEN]
Definition: particles.hpp:41
Simd< double > w2
Definition: particles.hpp:20
double r[VEC_LEN]
Definition: particles.hpp:39
int p_range(int num_particle)
Definition: particles.hpp:104
Simd< double > mu
Definition: particles.hpp:25
KOKKOS_INLINE_FUNCTION void remove_particles(Simd< long long int > &gid, const Simd< bool > &deactivate)
Definition: particles.tpp:4
Definition: particles.hpp:74
double z[VEC_LEN]
Definition: particles.hpp:40
double w1[VEC_LEN]
Definition: particles.hpp:43