IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
ParticleSpatialOverlapLayout.h
Go to the documentation of this file.
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
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
55
56 using index_t = typename hash_type::value_type;
58 using typename Base::particle_position_type;
59
61 using typename Base::region_view_type;
63 using typename Base::region_type;
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
106
107 public:
113 ParticleSpatialOverlapLayout(FieldLayout<Dim>& fl, Mesh& mesh, const T& rcutoff);
114
116 : ParticleSpatialLayout<T, Dim, PositionProperties...>() {}
117
119
121
127 template <class ParticleContainer>
128 void update(ParticleContainer& pc);
129
137 template <typename ExecutionSpace, typename Functor>
138 void forEachPair(Functor&& f) const;
139
144
153 index_t particleIndex, const ParticleNeighborData& particleNeighborData);
154
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:
243 static constexpr size_type numGhostCellsPerDim_m = 1;
260
263
264 public:
268 void initializeCells();
269
275 template <class ParticleContainer>
277
283 template <class ParticleContainer>
285
291 template <class ParticleContainer>
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 Vector<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
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
371
372#endif // IPPL_PARTICLE_SPATIAL_OVERLAP_LAYOUT_H
constexpr unsigned Dim
Definition Archive.h:20
std::size_t size_type
Definition IpplTypes.h:13
KOKKOS_INLINE_FUNCTION constexpr unsigned int countHypercubes(unsigned int dim)
Definition FieldLayout.h:44
std::array< rank_list, detail::countHypercubes(Dim) - 1 > neighbor_list
typename particle_position_type::memory_space position_memory_space
ParticleAttrib< vector_type, PositionProperties... > particle_position_type
typename particle_position_type::execution_space position_execution_space
typename detail::ViewType< bool, 1, position_memory_space >::view_type bool_type
typename detail::RegionLayout< T, Dim, Mesh, position_memory_space >::uniform_type RegionLayout_t
ParticleSpatialLayout(FieldLayout< Dim > &, Mesh &)
typename detail::ViewType< int, 1, position_memory_space >::view_type locate_type
Vector< size_type, Dim > numCells_m
! number of cells in each dimension
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
Kokkos::View< index_t *[1<< Dim], position_memory_space > locate_type_nd
Vector< size_type, Dim > cellStrides_m
! strides to compute cell indices
static constexpr size_type numGhostCellsPerDim_m
! number of ghost cells
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
void updateLayout(FieldLayout< Dim > &, Mesh &)
size_type numGhostCells_m
! the number of interior cells
KOKKOS_INLINE_FUNCTION static constexpr CellIndex_t toCellIndex(FlatCellIndex_t nonPermutedIndex, const Vector< size_type, Dim > &numCells)
size_type numberOfSends(int rank, const locate_type &ranks)
utility function to compute how many particles to sent to a given rank
locate_type getNonNeighborRanks(const locate_type &neighbors_view) const
utility function to get a view of all non-neighboring ranks
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
ParticleSpatialLayout< T, Dim, Mesh, PositionProperties... > Base
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
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...
const T rcutoff_m
! overlap in each dimension
void particleExchange(ParticleContainer &pc)
exchange particles by scanning neighbor ranks first, only scan other ranks if needed....
hash_type cellPermutationBackward_m
! the inverse of cellPermutationForward_m
size_type numLocalParticles_m
! the number of local particles (particles in local cells)
hash_type cellParticleCount_m
! view of number of particles in each cell
hash_type cellStartingIdx_m
! cell i contains particles cellStartingIdx_m(i), ..., cellStartingIdx_m(i + 1) - 1
typename FieldLayout_t::neighbor_list neighbor_list
Array of N rank lists, where N = number of hypercubes for the dimension Dim.
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....
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
void createPeriodicGhostParticles(ParticleContainer &pc)
copies particles close to the boundary and offsets them to their closest periodic image
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
KOKKOS_INLINE_FUNCTION static constexpr bool isCloseToBoundary(const std::index_sequence< Idx... > &, const vector_type &pos, const region_type &region, Vector< bool, Dim > periodic, T overlap)
determines whether a position is within overlap to the boundary of a region
void update(ParticleContainer &pc)
updates particles by exchanging them across ranks according to their positions. then constructs the p...
typename CellIndex_t::value_type FlatCellIndex_t
ParticleSpatialOverlapLayout(FieldLayout< Dim > &fl, Mesh &mesh, const T &rcutoff)
void forEachPair(Functor &&f) const
call functor for each combination i, j. make sure to call update first
size_type numLocalCells_m
! the number of ghost cells
void buildCells(ParticleContainer &pc)
builds the cell structure, sorts the particles according to the cells and makes sure only local parti...
locate_type getFlatNeighbors(const neighbor_list &neighbors) const
utility function to get a flat view of all neighbor processes
void initializeCells()
initializes all data necessary for the cells
Kokkos::Array< size_type, detail::countHypercubes(Dim)> cell_particle_neighbor_list_type
Vector< T, Dim > cellWidth_m
! width of cells in each dimension
ParticleNeighborData(size_type numLocalParticles, Vector< size_type, Dim > cellStrides, Vector< size_type, Dim > numCells, Vector< T, Dim > cellWidth, region_type region, hash_type cellStartingIdx, hash_type cellIndex, hash_type cellParticleCount, hash_type cellPermutationForward, hash_type cellPermutationBackward)