XGC1
sort.hpp
Go to the documentation of this file.
1 #ifndef SORT_HPP
2 #define SORT_HPP
3 
5 #include "grid.hpp"
6 #include "sheath.hpp"
7 
8 template<class Device>
9 struct SortViews{
10  Kokkos::View<double**,Kokkos::LayoutRight,Device> tmp_const;
11  Kokkos::View<int*,Kokkos::LayoutRight,Device> iperm;
12  Kokkos::View<int*,Kokkos::LayoutRight,Device> key;
13 
14  // Permutation
15  Kokkos::View<int*,Kokkos::LayoutRight,Device> count;
16  Kokkos::View<unsigned int*,Kokkos::LayoutRight,Device> place;
17 
18  SortViews(int n_ptl, int n_bins)
19  : tmp_const(Kokkos::ViewAllocateWithoutInitializing("tmp_const"), 4,n_ptl),
20  iperm(Kokkos::ViewAllocateWithoutInitializing("iperm"), n_ptl),
21  key(Kokkos::ViewAllocateWithoutInitializing("key"), n_ptl),
22  count(Kokkos::ViewAllocateWithoutInitializing("count"), n_bins),
23  place(Kokkos::ViewAllocateWithoutInitializing("place"), n_bins) {}
24 
25  inline void increase_key_max(int n_ptl){
26  // No-op if the new scratch value is smaller
27  if(n_ptl<iperm.extent(0)) return;
28 
29  // Resize to zero first to avoid temporary double allocation
30  Kokkos::resize(tmp_const,4,0);
31  Kokkos::resize(iperm,0);
32  Kokkos::resize(key,0);
33 
34  // Reallocate
35  Kokkos::resize(tmp_const,4,n_ptl);
36  Kokkos::resize(iperm,n_ptl);
37  Kokkos::resize(key,n_ptl);
38  }
39 
40  inline void increase_bin_max(int n_bins){
41  // No-op if the new scratch value is smaller
42  if(n_bins<count.extent(0)) return;
43 
44  // Resize to zero first to avoid temporary double allocation
45  Kokkos::resize(count,0);
46  Kokkos::resize(place,0);
47 
48  // Reallocate
49  Kokkos::resize(count,n_bins);
50  Kokkos::resize(place,n_bins);
51  }
52 };
53 
54 void sort_particles_by_triangle(SortViews<DeviceType> &sort_views, const Grid<DeviceType> &grid, const MagneticField<DeviceType> &magnetic_field, const Species<DeviceType> &species, const SheathParticles<DeviceType> &sheath_particles, bool sort_sheath_ptl);
55 
56 void sort_particles_by_pid(SortViews<DeviceType> &sort_views, const Grid<DeviceType> &grid, const MagneticField<DeviceType> &magnetic_field, const DomainDecomposition<DeviceType> &pol_decomp, const Species<DeviceType> &species, bool plane_sort_only);
57 
58 void sort_particles_by_key(SortViews<DeviceType> &sort_views, const Species<DeviceType> &species, int n_bins, Cabana::AoSoA<PhaseDataTypes,DeviceType,VEC_LEN>& phase0, Cabana::AoSoA<PhaseDataTypes,DeviceType,VEC_LEN>& dy_sum, bool sort_intermediate_values);
59 
60 int sort_particles_by_field_id(SortViews<DeviceType> &sort_views, const Grid<DeviceType> &grid, const MagneticField<DeviceType> &magnetic_field, const DomainDecomposition<DeviceType> &pol_decomp, const Species<DeviceType> &species, Cabana::AoSoA<PhaseDataTypes,DeviceType,VEC_LEN>& phase0, Cabana::AoSoA<PhaseDataTypes,DeviceType,VEC_LEN>& dy_sum, bool sort_intermediate_values);
61 #endif
Definition: magnetic_field.hpp:12
Definition: species.hpp:75
Definition: col_grid.cpp:127
Definition: magnetic_field.F90:1
void sort_particles_by_key(SortViews< DeviceType > &sort_views, const Species< DeviceType > &species, int n_bins, Cabana::AoSoA< PhaseDataTypes, DeviceType, VEC_LEN > &phase0, Cabana::AoSoA< PhaseDataTypes, DeviceType, VEC_LEN > &dy_sum, bool sort_intermediate_values)
Definition: sort.cpp:468
void sort_particles_by_pid(SortViews< DeviceType > &sort_views, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, const DomainDecomposition< DeviceType > &pol_decomp, const Species< DeviceType > &species, bool plane_sort_only)
Definition: sort.cpp:374
int sort_particles_by_field_id(SortViews< DeviceType > &sort_views, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, const DomainDecomposition< DeviceType > &pol_decomp, const Species< DeviceType > &species, Cabana::AoSoA< PhaseDataTypes, DeviceType, VEC_LEN > &phase0, Cabana::AoSoA< PhaseDataTypes, DeviceType, VEC_LEN > &dy_sum, bool sort_intermediate_values)
Definition: sort.cpp:430
void sort_particles_by_triangle(SortViews< DeviceType > &sort_views, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, const Species< DeviceType > &species, const SheathParticles< DeviceType > &sheath_particles, bool sort_sheath_ptl)
Definition: sort.cpp:305
Definition: sheath.hpp:10
Definition: sort.hpp:9
Kokkos::View< int *, Kokkos::LayoutRight, Device > count
How many particles in each bin.
Definition: sort.hpp:15
Kokkos::View< double **, Kokkos::LayoutRight, Device > tmp_const
Temporary array for sorting.
Definition: sort.hpp:10
void increase_bin_max(int n_bins)
Definition: sort.hpp:40
SortViews(int n_ptl, int n_bins)
Definition: sort.hpp:18
void increase_key_max(int n_ptl)
Definition: sort.hpp:25
Kokkos::View< int *, Kokkos::LayoutRight, Device > iperm
New order of data to be sorted.
Definition: sort.hpp:11
Kokkos::View< int *, Kokkos::LayoutRight, Device > key
Sorting key.
Definition: sort.hpp:12
Kokkos::View< unsigned int *, Kokkos::LayoutRight, Device > place
Where we are in the particle list.
Definition: sort.hpp:16