IPPL API Reference
Independent Parallel Particle Layer C++ API
Loading...
Searching...
No Matches
ParticleSpatialOverlapLayout.h
1//
2// Class ParticleSpatialOverlapLayout
3// Particle layout based on spatial decomposition.
4//
5// This is a specialized version of ParticleSpatialLayout, which allows
6// particles to be on multiple processes if they are close to the respective
7// region.
8//
9// After each 'time step' in a calculation, which is defined as a period
10// in which the particle positions may change enough to affect the global
11// layout, the user must call the 'update' routine, which will move
12// particles between processors, etc. After the Nth call to update, a
13// load balancing routine will be called instead. The user may set the
14// frequency of load balancing (N), or may supply a function to
15// determine if load balancing should be done or not.
16//
17#ifndef IPPL_PARTICLE_SPATIAL_OVERLAP_LAYOUT_H
18#define IPPL_PARTICLE_SPATIAL_OVERLAP_LAYOUT_H
19
20#include "Types/IpplTypes.h"
21
22#include "FieldLayout/FieldLayout.h"
23#include "Particle/ParticleBase.h"
24#include "Particle/ParticleLayout.h"
25#include "Region/RegionLayout.h"
26
27namespace ippl {
28 // This additional namespace is needed to allow for Mesh to have default argument
29 // UniformCartesian<T, Dim> via typedef at the end of the file. Compiling for cuda led to error
30 // when trying to do so directly...
37 template <typename T, unsigned Dim, class Mesh = UniformCartesian<T, Dim>,
38 typename... PositionProperties>
40 : public ParticleSpatialLayout<T, Dim, Mesh, PositionProperties...> {
41 public:
42 using Base = ParticleSpatialLayout<T, Dim, Mesh, PositionProperties...>;
43 using typename Base::position_execution_space;
44 using typename Base::position_memory_space;
45
46 using typename Base::bool_type;
47 using typename Base::hash_type;
48 using typename Base::locate_type;
49
50 using typename Base::FieldLayout_t;
51 using typename Base::RegionLayout_t;
52 using typename Base::vector_type;
53
54 using size_type = detail::size_type;
55
56 using index_t = typename hash_type::value_type;
57 using particle_neighbor_list_type = hash_type;
58 using typename Base::particle_position_type;
59
61 using typename Base::region_view_type;
63 using typename Base::region_type;
65 using neighbor_list = typename FieldLayout_t::neighbor_list;
66
67 public:
68 // the maximum number of overlapping ranks
69 using locate_type_nd = Kokkos::View<index_t * [1 << Dim], position_memory_space>;
70
76 private:
78
79 ParticleNeighborData(size_type numLocalParticles, Vector<size_type, Dim> cellStrides,
80 Vector<size_type, Dim> numCells, Vector<T, Dim> cellWidth,
81 region_type region, hash_type cellStartingIdx, hash_type cellIndex,
82 hash_type cellParticleCount, hash_type cellPermutationForward,
83 hash_type cellPermutationBackward)
84 : numLocalParticles(numLocalParticles)
85 , cellStrides(cellStrides)
86 , numCells(numCells)
87 , cellWidth(cellWidth)
88 , region(region)
89 , cellStartingIdx(cellStartingIdx)
90 , cellIndex(cellIndex)
91 , cellParticleCount(cellParticleCount)
92 , cellPermutationForward(cellPermutationForward)
93 , cellPermutationBackward(cellPermutationBackward) {}
94
95 size_type numLocalParticles;
96 Vector<size_type, Dim> cellStrides;
98 Vector<T, Dim> cellWidth;
99 region_type region;
100 hash_type cellStartingIdx;
101 hash_type cellIndex;
102 hash_type cellParticleCount;
103 hash_type cellPermutationForward;
104 hash_type cellPermutationBackward;
105 };
106
107 public:
113 ParticleSpatialOverlapLayout(FieldLayout<Dim>& fl, Mesh& mesh, const T& rcutoff);
114
116 : ParticleSpatialLayout<T, Dim, PositionProperties...>() {}
117
119
120 void updateLayout(FieldLayout<Dim>&, Mesh&);
121
127 template <class ParticleContainer>
128 void update(ParticleContainer& pc);
129
137 template <typename ExecutionSpace, typename Functor>
138 void forEachPair(Functor&& f) const;
139
143 ParticleNeighborData getParticleNeighborData() const;
144
152 KOKKOS_FUNCTION static particle_neighbor_list_type getParticleNeighbors(
153 index_t particleIndex, const ParticleNeighborData& particleNeighborData);
154
162 KOKKOS_FUNCTION static particle_neighbor_list_type getParticleNeighbors(
163 const vector_type& pos, const ParticleNeighborData& particleNeighborData);
164
171 size_type numberOfSends(int rank, const locate_type& ranks);
172
180 void fillHash(int rank, const locate_type& ranks, const locate_type& offsets,
181 hash_type& hash);
182
206 template <typename ParticleContainer>
207 std::pair<detail::size_type, detail::size_type> locateParticles(
208 const ParticleContainer& pc, locate_type& ranks, locate_type& rankOffsets,
209 bool_type& invalid, locate_type& nSends_dview, locate_type& sends_dview) const;
210
216 locate_type getFlatNeighbors(const neighbor_list& neighbors) const;
217
223 locate_type getNonNeighborRanks(const locate_type& neighbors_view) const;
224
225 protected:
227 const T rcutoff_m;
235 size_type totalCells_m;
243 static constexpr size_type numGhostCellsPerDim_m = 1;
257 hash_type cellIndex_m;
260
262 using FlatCellIndex_t = typename CellIndex_t::value_type;
263
264 public:
268 void initializeCells();
269
275 template <class ParticleContainer>
276 void particleExchange(ParticleContainer& pc);
277
283 template <class ParticleContainer>
284 void buildCells(ParticleContainer& pc);
285
291 template <class ParticleContainer>
292 void createPeriodicGhostParticles(ParticleContainer& pc);
293
294 protected:
302 template <std::size_t... Idx>
303 KOKKOS_INLINE_FUNCTION constexpr static bool isCloseToBoundary(
304 const std::index_sequence<Idx...>&, const vector_type& pos, const region_type& region,
305 Kokkos::Array<bool, Dim> periodic, T overlap);
306
313 KOKKOS_INLINE_FUNCTION constexpr static FlatCellIndex_t toFlatCellIndex(
314 const CellIndex_t& cellIndex, const Vector<size_type, Dim>& cellStrides,
315 hash_type cellPermutationForward);
316
322 KOKKOS_INLINE_FUNCTION constexpr static CellIndex_t toCellIndex(
323 FlatCellIndex_t nonPermutedIndex, const Vector<size_type, Dim>& numCells);
324
330 template <std::size_t... Idx>
331 KOKKOS_INLINE_FUNCTION constexpr static bool isLocalCellIndex(
332 const std::index_sequence<Idx...>&, const CellIndex_t& index,
333 const Vector<size_type, Dim>& numCells);
334
341 template <std::size_t... Idx>
342 KOKKOS_INLINE_FUNCTION constexpr static bool positionInRegion(
343 const std::index_sequence<Idx...>&, const vector_type& pos, const region_type& region,
344 T overlap);
345
352 KOKKOS_INLINE_FUNCTION constexpr static CellIndex_t getCellIndex(
353 const vector_type& pos, const region_type& region, const Vector<T, Dim>& cellWidth);
354
355 using cell_particle_neighbor_list_type =
356 Kokkos::Array<size_type, detail::countHypercubes(Dim)>;
357
364 KOKKOS_INLINE_FUNCTION constexpr static cell_particle_neighbor_list_type getCellNeighbors(
365 const CellIndex_t& cellIndex, const Vector<size_type, Dim>& cellStrides,
366 const hash_type& cellPermutationForward);
367 };
368} // namespace ippl
369
370#include "Particle/ParticleSpatialOverlapLayout.hpp"
371
372#endif // IPPL_PARTICLE_SPATIAL_OVERLAP_LAYOUT_H
Definition FieldLayout.h:166
Definition Mesh.h:15
Definition ParticleAttrib.h:33
Definition ParticleSpatialLayout.h:46
typename region_view_type::value_type region_type
Type of a single Region object.
Definition ParticleSpatialLayout.h:94
typename RegionLayout_t::view_type region_view_type
Type of the Kokkos view containing the local regions.
Definition ParticleSpatialLayout.h:92
Definition ParticleSpatialOverlapLayout.h:75
Definition ParticleSpatialOverlapLayout.h:40
Vector< size_type, Dim > numCells_m
! number of cells in each dimension
Definition ParticleSpatialOverlapLayout.h:229
ParticleNeighborData getParticleNeighborData() const
Definition ParticleSpatialOverlapLayout.hpp:961
void fillHash(int rank, const locate_type &ranks, const locate_type &offsets, hash_type &hash)
utility function to collect all indices of particles to send to given rank
Definition ParticleSpatialOverlapLayout.hpp:438
Vector< size_type, Dim > cellStrides_m
! strides to compute cell indices
Definition ParticleSpatialOverlapLayout.h:231
static constexpr size_type numGhostCellsPerDim_m
! number of ghost cells
Definition ParticleSpatialOverlapLayout.h:243
KOKKOS_INLINE_FUNCTION static constexpr cell_particle_neighbor_list_type getCellNeighbors(const CellIndex_t &cellIndex, const Vector< size_type, Dim > &cellStrides, const hash_type &cellPermutationForward)
get all indices of cell neighbors of a given nd-cell-index
Definition ParticleSpatialOverlapLayout.hpp:934
size_type numGhostCells_m
! the number of interior cells
Definition ParticleSpatialOverlapLayout.h:237
KOKKOS_INLINE_FUNCTION static constexpr CellIndex_t toCellIndex(FlatCellIndex_t nonPermutedIndex, const Vector< size_type, Dim > &numCells)
compute the nd-cell-index from a flattened (non-permuted) index
Definition ParticleSpatialOverlapLayout.hpp:780
size_type numberOfSends(int rank, const locate_type &ranks)
utility function to compute how many particles to sent to a given rank
Definition ParticleSpatialOverlapLayout.hpp:420
locate_type getNonNeighborRanks(const locate_type &neighbors_view) const
utility function to get a view of all non-neighboring ranks
Definition ParticleSpatialOverlapLayout.hpp:506
KOKKOS_INLINE_FUNCTION static constexpr bool isLocalCellIndex(const std::index_sequence< Idx... > &, const CellIndex_t &index, const Vector< size_type, Dim > &numCells)
determines whether cell index is local cell index
KOKKOS_INLINE_FUNCTION static constexpr FlatCellIndex_t toFlatCellIndex(const CellIndex_t &cellIndex, const Vector< size_type, Dim > &cellStrides, hash_type cellPermutationForward)
convert a nd-cell-index to flat cell index
Definition ParticleSpatialOverlapLayout.hpp:771
static KOKKOS_FUNCTION particle_neighbor_list_type getParticleNeighbors(index_t particleIndex, const ParticleNeighborData &particleNeighborData)
Function to get particle neighbors depending on index (possible inside Kokkos parallel region) make s...
Definition ParticleSpatialOverlapLayout.hpp:1020
const T rcutoff_m
! overlap in each dimension
Definition ParticleSpatialOverlapLayout.h:227
void particleExchange(ParticleContainer &pc)
exchange particles by scanning neighbor ranks first, only scan other ranks if needed....
Definition ParticleSpatialOverlapLayout.hpp:257
hash_type cellPermutationBackward_m
! the inverse of cellPermutationForward_m
Definition ParticleSpatialOverlapLayout.h:252
size_type numLocalParticles_m
! the number of local particles (particles in local cells)
Definition ParticleSpatialOverlapLayout.h:241
typename region_view_type::value_type region_type
Type of a single Region object.
Definition ParticleSpatialLayout.h:94
hash_type cellParticleCount_m
! view of number of particles in each cell
Definition ParticleSpatialOverlapLayout.h:259
hash_type cellStartingIdx_m
! cell i contains particles cellStartingIdx_m(i), ..., cellStartingIdx_m(i + 1) - 1
Definition ParticleSpatialOverlapLayout.h:254
typename FieldLayout_t::neighbor_list neighbor_list
Array of N rank lists, where N = number of hypercubes for the dimension Dim.
Definition ParticleSpatialOverlapLayout.h:65
hash_type cellIndex_m
Definition ParticleSpatialOverlapLayout.h:257
std::pair< detail::size_type, detail::size_type > locateParticles(const ParticleContainer &pc, locate_type &ranks, locate_type &rankOffsets, bool_type &invalid, locate_type &nSends_dview, locate_type &sends_dview) const
This function determines to which rank particles need to be sent after the iteration step....
Definition ParticleSpatialOverlapLayout.hpp:548
KOKKOS_INLINE_FUNCTION static constexpr CellIndex_t getCellIndex(const vector_type &pos, const region_type &region, const Vector< T, Dim > &cellWidth)
get the nd-cell-index of a position
Definition ParticleSpatialOverlapLayout.hpp:794
void createPeriodicGhostParticles(ParticleContainer &pc)
copies particles close to the boundary and offsets them to their closest periodic image
Definition ParticleSpatialOverlapLayout.hpp:177
KOKKOS_INLINE_FUNCTION static constexpr bool positionInRegion(const std::index_sequence< Idx... > &, const vector_type &pos, const region_type &region, T overlap)
determines whether a position is in a region including its overlap
size_type totalCells_m
! the number of total cells
Definition ParticleSpatialOverlapLayout.h:235
void update(ParticleContainer &pc)
updates particles by exchanging them across ranks according to their positions. then constructs the p...
Definition ParticleSpatialOverlapLayout.hpp:414
void forEachPair(Functor &&f) const
call functor for each combination i, j. make sure to call update first
Definition ParticleSpatialOverlapLayout.hpp:1071
KOKKOS_INLINE_FUNCTION static constexpr bool isCloseToBoundary(const std::index_sequence< Idx... > &, const vector_type &pos, const region_type &region, Kokkos::Array< bool, Dim > periodic, T overlap)
determines whether a position is within overlap to the boundary of a region
size_type numLocalCells_m
! the number of ghost cells
Definition ParticleSpatialOverlapLayout.h:239
hash_type cellPermutationForward_m
Definition ParticleSpatialOverlapLayout.h:250
void buildCells(ParticleContainer &pc)
builds the cell structure, sorts the particles according to the cells and makes sure only local parti...
Definition ParticleSpatialOverlapLayout.hpp:836
locate_type getFlatNeighbors(const neighbor_list &neighbors) const
utility function to get a flat view of all neighbor processes
Definition ParticleSpatialOverlapLayout.hpp:475
void initializeCells()
initializes all data necessary for the cells
Definition ParticleSpatialOverlapLayout.hpp:45
Vector< T, Dim > cellWidth_m
! width of cells in each dimension
Definition ParticleSpatialOverlapLayout.h:233
Definition Vector.h:23
Definition Archive.h:20