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 // Other useful ways to access particles
62 template<int T>
64  double data[T*VEC_LEN];
65 };
66 
67 template<int T>
68 struct OneParticle{
69  double data[T];
70 };
71 
72 KOKKOS_INLINE_FUNCTION void remove_particles(Simd<long long int>& gid, const Simd<bool>& deactivate);
73 
74 KOKKOS_INLINE_FUNCTION void update_phases(SimdPhase &ph_new, const SimdPhase &ph, double local_dt, const SimdPhase &dph);
75 
76 KOKKOS_INLINE_FUNCTION void simd_2_AoSoA(VecParticles *part, const SimdParticles &part_one, int a_vec, int s_vec);
77 
78 KOKKOS_INLINE_FUNCTION void AoSoA_2_simd(SimdParticles &part_one, const VecParticles *part, int a_vec, int s_vec);
79 
80 KOKKOS_INLINE_FUNCTION void update_dphm(SimdPhase &dphm,const SimdPhase &dpht);
81 
82 KOKKOS_INLINE_FUNCTION void update_dpht(SimdPhase &dpht,const SimdPhase &dph,const SimdPhase &dphm);
83 
84 template<class Device>
85 struct AoSoAIndices{
86  int s;
87  int a;
88 
89  KOKKOS_INLINE_FUNCTION AoSoAIndices(int idx);
90 };
91 
94 template<class Device>
95 KOKKOS_INLINE_FUNCTION AoSoAIndices<Device>::AoSoAIndices(int idx){
96  // CPU: access an array of particles
97  s = idx;
98  a = 0;
99 }
100 
101 #ifdef USE_GPU
102 
104 template<>
105 KOKKOS_INLINE_FUNCTION AoSoAIndices<DeviceType>::AoSoAIndices(int idx){
106  // GPU: access an individual particle
107  s = idx / VEC_LEN;
108  a = idx % VEC_LEN;
109 }
110 #endif
111 
114 template<class Device>
115 inline int p_range(int num_particle)
116 {
117  return divide_and_round_up(num_particle, VEC_LEN);
118 }
119 
120 #ifdef USE_GPU
121 
123 template<>
124 inline int p_range<DeviceType>(int num_particle)
125 {
126  return num_particle;
127 }
128 #endif
129 
131 inline int add_vec_buffer(int n_ptl) { return divide_and_round_up(n_ptl, VEC_LEN)*VEC_LEN;}
132 
133 #include "particles.tpp"
134 #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:101
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:95
Simd< double > w1
Definition: particles.hpp:19
Definition: particles.hpp:48
VecConstants ct
Definition: particles.hpp:57
Definition: particles.hpp:63
int add_vec_buffer(int n_ptl)
Definition: particles.hpp:131
Definition: particles.hpp:38
int a
The index in the inner array of the AoSoA.
Definition: particles.hpp:87
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
double data[T *VEC_LEN]
Definition: particles.hpp:64
Simd< double > rho
Definition: particles.hpp:18
int p_range< DeviceType >(int num_particle)
Definition: particles.hpp:124
double w2[VEC_LEN]
Definition: particles.hpp:44
double mu[VEC_LEN]
Definition: particles.hpp:49
idx
Definition: diag_f0_df_port1.hpp:28
Simd< double > r
Definition: particles.hpp:15
Definition: particles.hpp:68
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
double data[T]
Definition: particles.hpp:69
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:86
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:115
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:85
double z[VEC_LEN]
Definition: particles.hpp:40
double w1[VEC_LEN]
Definition: particles.hpp:43