Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_ParIter.H
Go to the documentation of this file.
1#ifndef AMREX_PARITER_H_
2#define AMREX_PARITER_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_MFIter.H>
6#include <AMReX_Gpu.H>
7
8namespace amrex
9{
10
11template <typename ParticleType, int NArrayReal, int NArrayInt,
12 template<class> class Allocator, class CellAssignor>
13class ParticleContainer_impl;
14
15template <int T_NReal, int T_NInt>
16struct Particle;
17
18template <int NArrayReal, int NArrayInt>
19struct SoAParticle;
20
21template <class RType, class IType>
22struct RTSoAParticle;
23
24struct DefaultAssignor;
25
26// for backwards compatibility
27template <int T_NStructReal, int T_NStructInt=0, int T_NArrayReal=0, int T_NArrayInt=0,
28 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
29using ParticleContainer = ParticleContainer_impl<Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
30
31template <bool is_const, typename T_ParticleType, int NArrayReal=0, int NArrayInt=0,
32 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
34 : public MFIter
35{
36
37private:
38
40 using ContainerRef = std::conditional_t<is_const, PCType const&, PCType&>;
41 using ContainerPtr = std::conditional_t<is_const, PCType const*, PCType*>;
42 using ParticleTileRef = std::conditional_t
43 <is_const, typename PCType::ParticleTileType const&, typename PCType::ParticleTileType &>;
44 using ParticleTilePtr = std::conditional_t
45 <is_const, typename PCType::ParticleTileType const*, typename PCType::ParticleTileType *>;
46 using AoSRef = std::conditional_t
47 <is_const, typename PCType::AoS const&, typename PCType::AoS&>;
48 using SoARef = std::conditional_t
49 <is_const, typename PCType::SoA const&, typename PCType::SoA&>;
50
51public:
52
55 using AoS = typename ContainerType::AoS;
56 using SoA = typename ContainerType::SoA;
57 using ParticleType = T_ParticleType;
58 using RealVector = typename SoA::RealVector;
59 using IntVector = typename SoA::IntVector;
61 static constexpr int NStructReal = ParticleType::NReal;
62 static constexpr int NStructInt = ParticleType::NInt;
63
64 ParIterBase_impl (ContainerRef pc, int level);
65
66 ParIterBase_impl (ContainerRef pc, int level, MFItInfo& info);
67
69 {
71 auto& particles = m_pc->GetParticles(m_level);
72 while (true) {
74 if (isValid()) {
75 auto key = std::make_pair(index(), LocalTileIndex());
76 auto f = particles.find(key);
77 if (f != particles.end() && f->second.numParticles() > 0) {
78 m_particle_current_tile = &(f->second);
79 break; // break if isValid() and non-empty particle tile found
80 }
81 } else {
82 break; // break if isValid() returns false
83 }
84 }
85 }
86
87 [[nodiscard]] ParticleTileRef GetParticleTile () const { return *m_particle_current_tile; }
88
89 [[nodiscard]] AoSRef GetArrayOfStructs () const { return GetParticleTile().GetArrayOfStructs(); }
90
91 [[nodiscard]] SoARef GetStructOfArrays () const { return GetParticleTile().GetStructOfArrays(); }
92
93 [[nodiscard]] auto numParticles () const { return GetParticleTile().numParticles(); }
94
95 [[nodiscard]] auto numRealParticles () const { return GetParticleTile().numRealParticles(); }
96
97 [[nodiscard]] auto numNeighborParticles () const { return GetParticleTile().numNeighborParticles(); }
98
99 [[nodiscard]] Long capacity () const { return GetParticleTile().capacity(); }
100
101 [[nodiscard]] int GetLevel () const { return m_level; }
102
103 [[nodiscard]] std::pair<int, int> GetPairIndex () const { return std::make_pair(this->index(), this->LocalTileIndex()); }
104
105 [[nodiscard]] const Geometry& Geom (int lev) const { return m_pc->Geom(lev); }
106
107protected:
108
110 ParticleTilePtr m_particle_current_tile = nullptr;
111 ContainerPtr m_pc;
112};
113
114template <typename T_ParticleType, int NArrayReal=0, int NArrayInt=0,
115 template<class> class Allocator=DefaultAllocator, class T_CellAssignor=DefaultAssignor>
117 : public ParIterBase_impl<false, T_ParticleType, NArrayReal, NArrayInt, Allocator, T_CellAssignor>
118{
119public:
120
121 using ParticleType=T_ParticleType;
122 using CellAssignor=T_CellAssignor;
123 static constexpr int NStructReal = ParticleType::NReal;
124 static constexpr int NStructInt = ParticleType::NInt;
125
129 using AoS = typename ContainerType::AoS;
130 using SoA = typename ContainerType::SoA;
131 using RealVector = typename SoA::RealVector;
132 using IntVector = typename SoA::IntVector;
133
135 : ParIterBase_impl<false, T_ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>(pc,level)
136 {}
137
138 ParIter_impl (ContainerType& pc, int level, MFItInfo& info)
139 : ParIterBase_impl<false, T_ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>(pc,level,info)
140 {}
141};
142
143template <typename T_ParticleType, int NArrayReal=0, int NArrayInt=0,
144 template<class> class Allocator=DefaultAllocator, class T_CellAssignor=DefaultAssignor>
146 : public ParIterBase_impl<true,T_ParticleType, NArrayReal, NArrayInt, Allocator, T_CellAssignor>
147{
148public:
149
150 using ParticleType = T_ParticleType;
151 using CellAssignor = T_CellAssignor;
154 using AoS = typename ContainerType::AoS;
155 using SoA = typename ContainerType::SoA;
156 using RealVector = typename SoA::RealVector;
157 using IntVector = typename SoA::IntVector;
158
159 ParConstIter_impl (ContainerType const& pc, int level)
160 : ParIterBase_impl<true,ParticleType,NArrayReal,NArrayInt,Allocator,CellAssignor>(pc,level)
161 {}
162
163 ParConstIter_impl (ContainerType const& pc, int level, MFItInfo& info)
164 : ParIterBase_impl<true,ParticleType,NArrayReal,NArrayInt,Allocator, CellAssignor>(pc,level,info)
165 {}
166};
167
168template <bool is_const, typename ParticleType, int NArrayReal, int NArrayInt,
169 template<class> class Allocator, class CellAssignor>
171 (ContainerRef pc, int level, MFItInfo& info)
172 :
173 MFIter(*pc.m_dummy_mf[level], pc.do_tiling ? info.EnableTiling(pc.tile_size) : info),
174 m_level(level),
175 m_pc(&pc)
176{
177 if (isValid()) {
178 auto& particles = m_pc->GetParticles(m_level);
179 while (true) {
180 auto key = std::make_pair(index(), LocalTileIndex());
181 auto f = particles.find(key);
182 if (f != particles.end() && f->second.numParticles() > 0) {
183 m_particle_current_tile = &(f->second);
184 break; // break if isValid() and non-empty particle tile found
185 }
187 if (!isValid()) { break; } // break if isValid() returns false
188 }
189 }
190}
191
192template <bool is_const, typename T_ParticleType, int NArrayReal, int NArrayInt,
193 template<class> class Allocator, class CellAssignor>
195 (ContainerRef pc, int level)
196 :
197 MFIter(*pc.m_dummy_mf[level],
198 pc.do_tiling ? pc.tile_size : IntVect::TheZeroVector()),
199 m_level(level),
200 m_pc(&pc)
201{
202 if (isValid()) {
203 auto& particles = m_pc->GetParticles(m_level);
204 while (true) {
205 auto key = std::make_pair(index(), LocalTileIndex());
206 auto f = particles.find(key);
207 if (f != particles.end() && f->second.numParticles() > 0) {
208 m_particle_current_tile = &(f->second);
209 break;
210 }
212 if (!isValid()) { break; }
213 }
214 }
215}
216
217template <bool is_const, int T_NStructReal, int T_NStructInt, int T_NArrayReal=0, int T_NArrayInt=0,
218 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
219using ParIterBase = ParIterBase_impl<is_const, Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
220
221template <bool is_const, int T_NArrayReal=0, int T_NArrayInt=0,
222 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
223using ParIterBaseSoA = ParIterBase_impl<is_const,SoAParticle<T_NArrayReal, T_NArrayInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
224
225template <int T_NStructReal, int T_NStructInt=0, int T_NArrayReal=0, int T_NArrayInt=0,
226 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
227using ParConstIter = ParConstIter_impl<Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
228
229template <int T_NArrayReal, int T_NArrayInt, template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
230using ParConstIterSoA = ParConstIter_impl<SoAParticle<T_NArrayReal, T_NArrayInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
231
233template <class RType=ParticleReal, class IType=int, class CellAssignor=DefaultAssignor>
235
236template <int T_NStructReal, int T_NStructInt=0, int T_NArrayReal=0, int T_NArrayInt=0,
237 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
238using ParIter = ParIter_impl<Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
239
240template <int T_NArrayReal, int T_NArrayInt, template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
241using ParIterSoA = ParIter_impl<SoAParticle<T_NArrayReal, T_NArrayInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
242
243template <class RType=ParticleReal, class IType=int, class CellAssignor=DefaultAssignor>
245
246}
247
248#endif
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:74
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:85
int LocalTileIndex() const noexcept
The current local tile index in the current grid;.
Definition AMReX_MFIter.H:178
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:169
int index() const noexcept
The index into the underlying BoxArray of the current FAB.
Definition AMReX_MFIter.H:172
void operator++() noexcept
Increment iterator to the next tile we own.
Definition AMReX_MFIter.cpp:526
Definition AMReX_ParIter.H:147
typename ContainerType::ParticleTileType ParticleTileType
Definition AMReX_ParIter.H:153
typename ContainerType::AoS AoS
Definition AMReX_ParIter.H:154
typename SoA::RealVector RealVector
Definition AMReX_ParIter.H:156
T_ParticleType ParticleType
Definition AMReX_ParIter.H:150
typename ContainerType::SoA SoA
Definition AMReX_ParIter.H:155
ParConstIter_impl(ContainerType const &pc, int level, MFItInfo &info)
Definition AMReX_ParIter.H:163
ParConstIter_impl(ContainerType const &pc, int level)
Definition AMReX_ParIter.H:159
T_CellAssignor CellAssignor
Definition AMReX_ParIter.H:151
typename SoA::IntVector IntVector
Definition AMReX_ParIter.H:157
Definition AMReX_ParIter.H:35
std::pair< int, int > GetPairIndex() const
Definition AMReX_ParIter.H:103
ContainerPtr m_pc
Definition AMReX_ParIter.H:111
const Geometry & Geom(int lev) const
Definition AMReX_ParIter.H:105
void operator++()
Definition AMReX_ParIter.H:68
T_ParticleType ParticleType
Definition AMReX_ParIter.H:57
static constexpr int NStructReal
Definition AMReX_ParIter.H:61
static constexpr int NStructInt
Definition AMReX_ParIter.H:62
auto numNeighborParticles() const
Definition AMReX_ParIter.H:97
AoSRef GetArrayOfStructs() const
Definition AMReX_ParIter.H:89
typename SoA::RealVector RealVector
Definition AMReX_ParIter.H:58
auto numParticles() const
Definition AMReX_ParIter.H:93
typename ContainerType::SoA SoA
Definition AMReX_ParIter.H:56
typename ContainerType::ParticleVector ParticleVector
Definition AMReX_ParIter.H:60
int m_level
Definition AMReX_ParIter.H:109
typename ContainerType::AoS AoS
Definition AMReX_ParIter.H:55
ParticleTilePtr m_particle_current_tile
Definition AMReX_ParIter.H:110
ParIterBase_impl(ContainerRef pc, int level, MFItInfo &info)
Definition AMReX_ParIter.H:171
typename ContainerType::ParticleTileType ParticleTileType
Definition AMReX_ParIter.H:54
ParticleTileRef GetParticleTile() const
Definition AMReX_ParIter.H:87
Long capacity() const
Definition AMReX_ParIter.H:99
typename SoA::IntVector IntVector
Definition AMReX_ParIter.H:59
SoARef GetStructOfArrays() const
Definition AMReX_ParIter.H:91
int GetLevel() const
Definition AMReX_ParIter.H:101
ParIterBase_impl(ContainerRef pc, int level)
Definition AMReX_ParIter.H:195
auto numRealParticles() const
Definition AMReX_ParIter.H:95
Definition AMReX_ParIter.H:118
typename ContainerType::SoA SoA
Definition AMReX_ParIter.H:130
typename ContainerType::AoS AoS
Definition AMReX_ParIter.H:129
ParIter_impl(ContainerType &pc, int level)
Definition AMReX_ParIter.H:134
typename SoA::RealVector RealVector
Definition AMReX_ParIter.H:131
T_CellAssignor CellAssignor
Definition AMReX_ParIter.H:122
T_ParticleType ParticleType
Definition AMReX_ParIter.H:121
typename ContainerType::ConstParticleType ConstParticleType
Definition AMReX_ParIter.H:127
ParIter_impl(ContainerType &pc, int level, MFItInfo &info)
Definition AMReX_ParIter.H:138
typename ContainerType::ParticleTileType ParticleTileType
Definition AMReX_ParIter.H:128
static constexpr int NStructInt
Definition AMReX_ParIter.H:124
typename SoA::IntVector IntVector
Definition AMReX_ParIter.H:132
static constexpr int NStructReal
Definition AMReX_ParIter.H:123
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:149
typename ParticleTileType::AoS AoS
Definition AMReX_ParticleContainer.H:199
typename ParticleType::ConstType ConstParticleType
Definition AMReX_ParticleContainer.H:152
typename AoS::ParticleVector ParticleVector
Definition AMReX_ParticleContainer.H:204
typename ParticleTileType::SoA SoA
Definition AMReX_ParticleContainer.H:200
std::conditional_t< is_rtsoa_pc, ParticleTileRT< typename ParticleType::RealType, typename ParticleType::IntType >, ParticleTile< ParticleType, NArrayReal, NArrayInt, Allocator > > ParticleTileType
Definition AMReX_ParticleContainer.H:191
Definition AMReX_GpuAllocators.H:156
amrex_long Long
Definition AMReX_INT.H:30
Definition AMReX_Amr.cpp:49
amrex::ArenaAllocator< T > DefaultAllocator
Definition AMReX_GpuAllocators.H:205
Definition AMReX_ParticleUtil.H:390
Definition AMReX_MFIter.H:20