IPPL API Reference
Independent Parallel Particle Layer C++ API
Loading...
Searching...
No Matches
ParticleSpatialLayout.h
1
2//
3// Class ParticleSpatialLayout
4// Particle layout based on spatial decomposition.
5//
6// This is a specialized version of ParticleLayout, which places particles
7// on processors based on their spatial location relative to a fixed grid.
8// In particular, this can maintain particles on processors based on a
9// specified FieldLayout or RegionLayout, so that particles are always on
10// the same node as the node containing the Field region to which they are
11// local. This may also be used if there is no associated Field at all,
12// in which case a grid is selected based on an even distribution of
13// particles among processors.
14//
15// After each 'time step' in a calculation, which is defined as a period
16// in which the particle positions may change enough to affect the global
17// layout, the user must call the 'update' routine, which will move
18// particles between processors, etc. After the Nth call to update, a
19// load balancing routine will be called instead. The user may set the
20// frequency of load balancing (N), or may supply a function to
21// determine if load balancing should be done or not.
22//
23#ifndef IPPL_PARTICLE_SPATIAL_LAYOUT_H
24#define IPPL_PARTICLE_SPATIAL_LAYOUT_H
25
26#include <vector>
27
28#include "Types/IpplTypes.h"
29
30#include "Communicate/Window.h"
31#include "FieldLayout/FieldLayout.h"
32#include "Particle/ParticleBase.h"
33#include "Particle/ParticleLayout.h"
34#include "Region/RegionLayout.h"
35
36namespace ippl {
37
44 template <typename T, unsigned Dim, class Mesh = UniformCartesian<T, Dim>,
45 typename... PositionProperties>
46 class ParticleSpatialLayout : public detail::ParticleLayout<T, Dim, PositionProperties...> {
47 public:
48 using Base = detail::ParticleLayout<T, Dim, PositionProperties...>;
49 using typename Base::position_memory_space, typename Base::position_execution_space;
50
51 using hash_type = detail::hash_type<position_memory_space>;
52 using locate_type = typename detail::ViewType<int, 1, position_memory_space>::view_type;
53 using bool_type = typename detail::ViewType<bool, 1, position_memory_space>::view_type;
54
55 using vector_type = typename Base::vector_type;
56 using RegionLayout_t =
57 typename detail::RegionLayout<T, Dim, Mesh, position_memory_space>::uniform_type;
58 using FieldLayout_t = typename ippl::FieldLayout<Dim>;
59
60 using size_type = detail::size_type;
61
62 public:
63 // constructor: this one also takes a Mesh
64 ParticleSpatialLayout(FieldLayout<Dim>&, Mesh&, bool fem = false);
65
67 : detail::ParticleLayout<T, Dim, PositionProperties...>() {}
68
69 ~ParticleSpatialLayout() = default;
70
71 void updateLayout(FieldLayout<Dim>&, Mesh&);
72
73 template <class ParticleContainer>
74 void update(ParticleContainer& pc);
75
76 const RegionLayout_t& getRegionLayout() const { return rlayout_m; }
77
78 protected:
80 RegionLayout_t rlayout_m;
81
83 FieldLayout_t& flayout_m;
84
85 // Vector keeping track of the recieves from all ranks
86 std::vector<size_type> nRecvs_m;
87
88 // MPI RMA window for one-sided communication
90
92 using region_view_type = typename RegionLayout_t::view_type;
94 using region_type = typename region_view_type::value_type;
96 using neighbor_list = typename FieldLayout_t::neighbor_list;
97
98 template <size_t... Idx>
99 KOKKOS_INLINE_FUNCTION constexpr static bool positionInRegion(
100 const std::index_sequence<Idx...>&, const vector_type& pos, const region_type& region);
101
108 size_type getNeighborSize(const neighbor_list& neighbors) const;
109
110 public:
123 template <typename ParticleContainer>
124 std::pair<size_type, size_type> locateParticles(const ParticleContainer& pc,
125 locate_type& ranks, bool_type& invalid,
126 locate_type& nSends_dview,
127 locate_type& sends_dview) const;
128
134 void fillHash(int rank, const locate_type& ranks, hash_type& hash);
135
140 size_t numberOfSends(int rank, const locate_type& ranks);
141 };
142} // namespace ippl
143
144#include "Particle/ParticleSpatialLayout.hpp"
145
146#endif
Definition FieldLayout.h:166
Definition Mesh.h:15
Definition ParticleSpatialLayout.h:46
RegionLayout_t rlayout_m
The RegionLayout which determines where our particles go.
Definition ParticleSpatialLayout.h:80
size_t numberOfSends(int rank, const locate_type &ranks)
Definition ParticleSpatialLayout.hpp:455
size_type getNeighborSize(const neighbor_list &neighbors) const
Definition ParticleSpatialLayout.hpp:240
typename region_view_type::value_type region_type
Type of a single Region object.
Definition ParticleSpatialLayout.h:94
void fillHash(int rank, const locate_type &ranks, hash_type &hash)
Definition ParticleSpatialLayout.hpp:432
typename RegionLayout_t::view_type region_view_type
Type of the Kokkos view containing the local regions.
Definition ParticleSpatialLayout.h:92
std::pair< size_type, size_type > locateParticles(const ParticleContainer &pc, locate_type &ranks, bool_type &invalid, locate_type &nSends_dview, locate_type &sends_dview) const
typename FieldLayout_t::neighbor_list neighbor_list
Array of N rank lists, where N = number of hypercubes for the dimension Dim.
Definition ParticleSpatialLayout.h:96
FieldLayout_t & flayout_m
The FieldLayout containing information on nearest neighbors.
Definition ParticleSpatialLayout.h:83
Definition ParticleLayout.h:44
Definition Window.h:33
Definition Archive.h:20