17#ifndef IPPL_PARTICLE_SPATIAL_OVERLAP_LAYOUT_H
18#define IPPL_PARTICLE_SPATIAL_OVERLAP_LAYOUT_H
20#include "Types/IpplTypes.h"
22#include "FieldLayout/FieldLayout.h"
23#include "Particle/ParticleBase.h"
24#include "Particle/ParticleLayout.h"
25#include "Region/RegionLayout.h"
37 template <
typename T,
unsigned Dim,
class Mesh = UniformCartesian<T, Dim>,
38 typename... PositionProperties>
43 using typename Base::position_execution_space;
44 using typename Base::position_memory_space;
46 using typename Base::bool_type;
47 using typename Base::hash_type;
48 using typename Base::locate_type;
50 using typename Base::FieldLayout_t;
51 using typename Base::RegionLayout_t;
52 using typename Base::vector_type;
54 using size_type = detail::size_type;
56 using index_t =
typename hash_type::value_type;
57 using particle_neighbor_list_type = hash_type;
69 using locate_type_nd = Kokkos::View<index_t * [1 << Dim], position_memory_space>;
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)
87 , cellWidth(cellWidth)
89 , cellStartingIdx(cellStartingIdx)
90 , cellIndex(cellIndex)
91 , cellParticleCount(cellParticleCount)
92 , cellPermutationForward(cellPermutationForward)
93 , cellPermutationBackward(cellPermutationBackward) {}
95 size_type numLocalParticles;
100 hash_type cellStartingIdx;
102 hash_type cellParticleCount;
103 hash_type cellPermutationForward;
104 hash_type cellPermutationBackward;
127 template <
class ParticleContainer>
128 void update(ParticleContainer& pc);
137 template <
typename ExecutionSpace,
typename Functor>
153 index_t particleIndex,
const ParticleNeighborData& particleNeighborData);
163 const vector_type& pos,
const ParticleNeighborData& particleNeighborData);
180 void fillHash(
int rank,
const locate_type& ranks,
const locate_type& offsets,
206 template <
typename ParticleContainer>
208 const ParticleContainer& pc, locate_type& ranks, locate_type& rankOffsets,
209 bool_type& invalid, locate_type& nSends_dview, locate_type& sends_dview)
const;
262 using FlatCellIndex_t =
typename CellIndex_t::value_type;
275 template <
class ParticleContainer>
283 template <
class ParticleContainer>
291 template <
class ParticleContainer>
302 template <std::size_t... Idx>
304 const std::index_sequence<Idx...>&,
const vector_type& pos,
const region_type& region,
305 Kokkos::Array<bool, Dim> periodic, T overlap);
313 KOKKOS_INLINE_FUNCTION
constexpr static FlatCellIndex_t
toFlatCellIndex(
315 hash_type cellPermutationForward);
330 template <std::size_t... Idx>
332 const std::index_sequence<Idx...>&,
const CellIndex_t& index,
341 template <std::size_t... Idx>
343 const std::index_sequence<Idx...>&,
const vector_type& pos,
const region_type& region,
355 using cell_particle_neighbor_list_type =
356 Kokkos::Array<size_type, detail::countHypercubes(Dim)>;
364 KOKKOS_INLINE_FUNCTION
constexpr static cell_particle_neighbor_list_type
getCellNeighbors(
366 const hash_type& cellPermutationForward);
370#include "Particle/ParticleSpatialOverlapLayout.hpp"
Definition FieldLayout.h:166
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 ®ion, 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 ®ion, 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 ®ion, 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