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
21struct DefaultAssignor;
22
23// for backwards compatibility
24template <int T_NStructReal, int T_NStructInt=0, int T_NArrayReal=0, int T_NArrayInt=0,
25 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
26using ParticleContainer = ParticleContainer_impl<Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
27
28template <bool is_const, typename T_ParticleType, int NArrayReal=0, int NArrayInt=0,
29 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
31 : public MFIter
32{
33
34private:
35
37 using ContainerRef = std::conditional_t<is_const, PCType const&, PCType&>;
38 using ContainerPtr = std::conditional_t<is_const, PCType const*, PCType*>;
39 using ParticleTileRef = std::conditional_t
40 <is_const, typename PCType::ParticleTileType const&, typename PCType::ParticleTileType &>;
41 using ParticleTilePtr = std::conditional_t
42 <is_const, typename PCType::ParticleTileType const*, typename PCType::ParticleTileType *>;
43 using AoSRef = std::conditional_t
44 <is_const, typename PCType::AoS const&, typename PCType::AoS&>;
45 using SoARef = std::conditional_t
46 <is_const, typename PCType::SoA const&, typename PCType::SoA&>;
47
48public:
49
52 using AoS = typename ContainerType::AoS;
53 using SoA = typename ContainerType::SoA;
54 using ParticleType = T_ParticleType;
55 using RealVector = typename SoA::RealVector;
56 using IntVector = typename SoA::IntVector;
58 static constexpr int NStructReal = ParticleType::NReal;
59 static constexpr int NStructInt = ParticleType::NInt;
60
62
63 ParIterBase_impl (ContainerRef pc, int level, MFItInfo& info);
64
66 {
68 auto& particles = m_pc->GetParticles(m_level);
69 while (true) {
71 if (isValid()) {
72 auto key = std::make_pair(index(), LocalTileIndex());
73 auto f = particles.find(key);
74 if (f != particles.end() && f->second.numParticles() > 0) {
75 m_particle_current_tile = &(f->second);
76 break; // break if isValid() and non-empty particle tile found
77 }
78 } else {
79 break; // break if isValid() returns false
80 }
81 }
82 }
83
84 [[nodiscard]] ParticleTileRef GetParticleTile () const { return *m_particle_current_tile; }
85
86 [[nodiscard]] AoSRef GetArrayOfStructs () const { return GetParticleTile().GetArrayOfStructs(); }
87
88 [[nodiscard]] SoARef GetStructOfArrays () const { return GetParticleTile().GetStructOfArrays(); }
89
90 [[nodiscard]] int numParticles () const { return GetParticleTile().numParticles(); }
91
92 [[nodiscard]] int numRealParticles () const { return GetParticleTile().numRealParticles(); }
93
94 [[nodiscard]] int numNeighborParticles () const { return GetParticleTile().numNeighborParticles(); }
95
96 [[nodiscard]] Long capacity () const { return GetParticleTile().capacity(); }
97
98 [[nodiscard]] int GetLevel () const { return m_level; }
99
100 [[nodiscard]] std::pair<int, int> GetPairIndex () const { return std::make_pair(this->index(), this->LocalTileIndex()); }
101
102 [[nodiscard]] const Geometry& Geom (int lev) const { return m_pc->Geom(lev); }
103
104protected:
105
109};
110
111template <typename T_ParticleType, int NArrayReal=0, int NArrayInt=0,
112 template<class> class Allocator=DefaultAllocator, class T_CellAssignor=DefaultAssignor>
114 : public ParIterBase_impl<false, T_ParticleType, NArrayReal, NArrayInt, Allocator, T_CellAssignor>
115{
116public:
117
118 using ParticleType=T_ParticleType;
119 using CellAssignor=T_CellAssignor;
120 static constexpr int NStructReal = ParticleType::NReal;
121 static constexpr int NStructInt = ParticleType::NInt;
122
126 using AoS = typename ContainerType::AoS;
127 using SoA = typename ContainerType::SoA;
128 using RealVector = typename SoA::RealVector;
129 using IntVector = typename SoA::IntVector;
130
132 : ParIterBase_impl<false, T_ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>(pc,level)
133 {}
134
135 ParIter_impl (ContainerType& pc, int level, MFItInfo& info)
136 : ParIterBase_impl<false, T_ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>(pc,level,info)
137 {}
138};
139
140template <typename T_ParticleType, int NArrayReal=0, int NArrayInt=0,
141 template<class> class Allocator=DefaultAllocator, class T_CellAssignor=DefaultAssignor>
143 : public ParIterBase_impl<true,T_ParticleType, NArrayReal, NArrayInt, Allocator, T_CellAssignor>
144{
145public:
146
147 using ParticleType = T_ParticleType;
148 using CellAssignor = T_CellAssignor;
151 using AoS = typename ContainerType::AoS;
152 using SoA = typename ContainerType::SoA;
153 using RealVector = typename SoA::RealVector;
154 using IntVector = typename SoA::IntVector;
155
156 ParConstIter_impl (ContainerType const& pc, int level)
157 : ParIterBase_impl<true,ParticleType,NArrayReal,NArrayInt,Allocator,CellAssignor>(pc,level)
158 {}
159
160 ParConstIter_impl (ContainerType const& pc, int level, MFItInfo& info)
161 : ParIterBase_impl<true,ParticleType,NArrayReal,NArrayInt,Allocator, CellAssignor>(pc,level,info)
162 {}
163};
164
165template <bool is_const, typename ParticleType, int NArrayReal, int NArrayInt,
166 template<class> class Allocator, class CellAssignor>
168 (ContainerRef pc, int level, MFItInfo& info)
169 :
170 MFIter(*pc.m_dummy_mf[level], pc.do_tiling ? info.EnableTiling(pc.tile_size) : info),
171 m_level(level),
172 m_pc(&pc)
173{
174 if (isValid()) {
175 auto& particles = m_pc->GetParticles(m_level);
176 while (true) {
177 auto key = std::make_pair(index(), LocalTileIndex());
178 auto f = particles.find(key);
179 if (f != particles.end() && f->second.numParticles() > 0) {
180 m_particle_current_tile = &(f->second);
181 break; // break if isValid() and non-empty particle tile found
182 }
184 if (!isValid()) { break; } // break if isValid() returns false
185 }
186 }
187}
188
189template <bool is_const, typename T_ParticleType, int NArrayReal, int NArrayInt,
190 template<class> class Allocator, class CellAssignor>
192 (ContainerRef pc, int level)
193 :
194 MFIter(*pc.m_dummy_mf[level],
195 pc.do_tiling ? pc.tile_size : IntVect::TheZeroVector()),
196 m_level(level),
197 m_pc(&pc)
198{
199 if (isValid()) {
200 auto& particles = m_pc->GetParticles(m_level);
201 while (true) {
202 auto key = std::make_pair(index(), LocalTileIndex());
203 auto f = particles.find(key);
204 if (f != particles.end() && f->second.numParticles() > 0) {
205 m_particle_current_tile = &(f->second);
206 break;
207 }
209 if (!isValid()) { break; }
210 }
211 }
212}
213
214template <bool is_const, int T_NStructReal, int T_NStructInt, int T_NArrayReal=0, int T_NArrayInt=0,
215 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
216using ParIterBase = ParIterBase_impl<is_const, Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
217
218template <bool is_const, int T_NArrayReal=0, int T_NArrayInt=0,
219 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
220using ParIterBaseSoA = ParIterBase_impl<is_const,SoAParticle<T_NArrayReal, T_NArrayInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
221
222template <int T_NStructReal, int T_NStructInt=0, int T_NArrayReal=0, int T_NArrayInt=0,
223 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
224using ParConstIter = ParConstIter_impl<Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
225
226template <int T_NArrayReal, int T_NArrayInt, template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
227using ParConstIterSoA = ParConstIter_impl<SoAParticle<T_NArrayReal, T_NArrayInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
228
229template <int T_NStructReal, int T_NStructInt=0, int T_NArrayReal=0, int T_NArrayInt=0,
230 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
231using ParIter = ParIter_impl<Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
232
233template <int T_NArrayReal, int T_NArrayInt, template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
234using ParIterSoA = ParIter_impl<SoAParticle<T_NArrayReal, T_NArrayInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
235
236}
237
238#endif
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:73
Definition AMReX_MFIter.H:57
int LocalTileIndex() const noexcept
The current local tile index in the current grid;.
Definition AMReX_MFIter.H:150
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:141
int index() const noexcept
The index into the underlying BoxArray of the current FAB.
Definition AMReX_MFIter.H:144
void operator++() noexcept
Increment iterator to the next tile we own.
Definition AMReX_MFIter.cpp:523
Definition AMReX_ParIter.H:144
typename ContainerType::ParticleTileType ParticleTileType
Definition AMReX_ParIter.H:150
typename ContainerType::AoS AoS
Definition AMReX_ParIter.H:151
typename SoA::RealVector RealVector
Definition AMReX_ParIter.H:153
T_ParticleType ParticleType
Definition AMReX_ParIter.H:147
typename ContainerType::SoA SoA
Definition AMReX_ParIter.H:152
ParConstIter_impl(ContainerType const &pc, int level, MFItInfo &info)
Definition AMReX_ParIter.H:160
ParConstIter_impl(ContainerType const &pc, int level)
Definition AMReX_ParIter.H:156
T_CellAssignor CellAssignor
Definition AMReX_ParIter.H:148
typename SoA::IntVector IntVector
Definition AMReX_ParIter.H:154
Definition AMReX_ParIter.H:32
std::conditional_t< is_const, typename PCType::SoA const &, typename PCType::SoA & > SoARef
Definition AMReX_ParIter.H:46
std::pair< int, int > GetPairIndex() const
Definition AMReX_ParIter.H:100
ContainerPtr m_pc
Definition AMReX_ParIter.H:108
std::conditional_t< is_const, PCType const *, PCType * > ContainerPtr
Definition AMReX_ParIter.H:38
const Geometry & Geom(int lev) const
Definition AMReX_ParIter.H:102
std::conditional_t< is_const, PCType const &, PCType & > ContainerRef
Definition AMReX_ParIter.H:37
void operator++()
Definition AMReX_ParIter.H:65
T_ParticleType ParticleType
Definition AMReX_ParIter.H:54
std::conditional_t< is_const, typename PCType::AoS const &, typename PCType::AoS & > AoSRef
Definition AMReX_ParIter.H:44
static constexpr int NStructReal
Definition AMReX_ParIter.H:58
int numParticles() const
Definition AMReX_ParIter.H:90
static constexpr int NStructInt
Definition AMReX_ParIter.H:59
std::conditional_t< is_const, typename PCType::ParticleTileType const &, typename PCType::ParticleTileType & > ParticleTileRef
Definition AMReX_ParIter.H:40
AoSRef GetArrayOfStructs() const
Definition AMReX_ParIter.H:86
int numRealParticles() const
Definition AMReX_ParIter.H:92
int numNeighborParticles() const
Definition AMReX_ParIter.H:94
typename SoA::RealVector RealVector
Definition AMReX_ParIter.H:55
typename ContainerType::SoA SoA
Definition AMReX_ParIter.H:53
typename ContainerType::ParticleVector ParticleVector
Definition AMReX_ParIter.H:57
int m_level
Definition AMReX_ParIter.H:106
typename ContainerType::AoS AoS
Definition AMReX_ParIter.H:52
ParticleTilePtr m_particle_current_tile
Definition AMReX_ParIter.H:107
ParIterBase_impl(ContainerRef pc, int level, MFItInfo &info)
Definition AMReX_ParIter.H:168
typename ContainerType::ParticleTileType ParticleTileType
Definition AMReX_ParIter.H:51
ParticleTileRef GetParticleTile() const
Definition AMReX_ParIter.H:84
Long capacity() const
Definition AMReX_ParIter.H:96
typename SoA::IntVector IntVector
Definition AMReX_ParIter.H:56
SoARef GetStructOfArrays() const
Definition AMReX_ParIter.H:88
std::conditional_t< is_const, typename PCType::ParticleTileType const *, typename PCType::ParticleTileType * > ParticleTilePtr
Definition AMReX_ParIter.H:42
int GetLevel() const
Definition AMReX_ParIter.H:98
ParIterBase_impl(ContainerRef pc, int level)
Definition AMReX_ParIter.H:192
Definition AMReX_ParIter.H:115
typename ContainerType::SoA SoA
Definition AMReX_ParIter.H:127
typename ContainerType::AoS AoS
Definition AMReX_ParIter.H:126
ParIter_impl(ContainerType &pc, int level)
Definition AMReX_ParIter.H:131
typename SoA::RealVector RealVector
Definition AMReX_ParIter.H:128
T_CellAssignor CellAssignor
Definition AMReX_ParIter.H:119
T_ParticleType ParticleType
Definition AMReX_ParIter.H:118
typename ContainerType::ConstParticleType ConstParticleType
Definition AMReX_ParIter.H:124
ParIter_impl(ContainerType &pc, int level, MFItInfo &info)
Definition AMReX_ParIter.H:135
typename ContainerType::ParticleTileType ParticleTileType
Definition AMReX_ParIter.H:125
static constexpr int NStructInt
Definition AMReX_ParIter.H:121
typename SoA::IntVector IntVector
Definition AMReX_ParIter.H:129
static constexpr int NStructReal
Definition AMReX_ParIter.H:120
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:147
typename ParticleTileType::AoS AoS
Definition AMReX_ParticleContainer.H:191
typename ParticleType::ConstType ConstParticleType
Definition AMReX_ParticleContainer.H:150
typename AoS::ParticleVector ParticleVector
Definition AMReX_ParticleContainer.H:196
typename ParticleTileType::SoA SoA
Definition AMReX_ParticleContainer.H:192
ParticleTile< ParticleType, NArrayReal, NArrayInt, Allocator > ParticleTileType
Definition AMReX_ParticleContainer.H:183
Definition AMReX_Amr.cpp:49
amrex::ArenaAllocator< T > DefaultAllocator
Definition AMReX_GpuAllocators.H:193
Definition AMReX_ParticleUtil.H:394
Definition AMReX_MFIter.H:20
Definition AMReX_ParticleTile.H:720