Block-Structured AMR Software Framework
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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]] int GetLevel () const { return m_level; }
97
98 [[nodiscard]] std::pair<int, int> GetPairIndex () const { return std::make_pair(this->index(), this->LocalTileIndex()); }
99
100 [[nodiscard]] const Geometry& Geom (int lev) const { return m_pc->Geom(lev); }
101
102protected:
103
107};
108
109template <typename T_ParticleType, int NArrayReal=0, int NArrayInt=0,
110 template<class> class Allocator=DefaultAllocator, class T_CellAssignor=DefaultAssignor>
112 : public ParIterBase_impl<false, T_ParticleType, NArrayReal, NArrayInt, Allocator, T_CellAssignor>
113{
114public:
115
116 using ParticleType=T_ParticleType;
117 using CellAssignor=T_CellAssignor;
118 static constexpr int NStructReal = ParticleType::NReal;
119 static constexpr int NStructInt = ParticleType::NInt;
120
124 using AoS = typename ContainerType::AoS;
125 using SoA = typename ContainerType::SoA;
126 using RealVector = typename SoA::RealVector;
127 using IntVector = typename SoA::IntVector;
128
130 : ParIterBase_impl<false, T_ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>(pc,level)
131 {}
132
133 ParIter_impl (ContainerType& pc, int level, MFItInfo& info)
134 : ParIterBase_impl<false, T_ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>(pc,level,info)
135 {}
136};
137
138template <typename T_ParticleType, int NArrayReal=0, int NArrayInt=0,
139 template<class> class Allocator=DefaultAllocator, class T_CellAssignor=DefaultAssignor>
141 : public ParIterBase_impl<true,T_ParticleType, NArrayReal, NArrayInt, Allocator, T_CellAssignor>
142{
143public:
144
145 using ParticleType = T_ParticleType;
146 using CellAssignor = T_CellAssignor;
149 using AoS = typename ContainerType::AoS;
150 using SoA = typename ContainerType::SoA;
151 using RealVector = typename SoA::RealVector;
152 using IntVector = typename SoA::IntVector;
153
154 ParConstIter_impl (ContainerType const& pc, int level)
155 : ParIterBase_impl<true,ParticleType,NArrayReal,NArrayInt,Allocator,CellAssignor>(pc,level)
156 {}
157
158 ParConstIter_impl (ContainerType const& pc, int level, MFItInfo& info)
159 : ParIterBase_impl<true,ParticleType,NArrayReal,NArrayInt,Allocator, CellAssignor>(pc,level,info)
160 {}
161};
162
163template <bool is_const, typename ParticleType, int NArrayReal, int NArrayInt,
164 template<class> class Allocator, class CellAssignor>
166 (ContainerRef pc, int level, MFItInfo& info)
167 :
168 MFIter(*pc.m_dummy_mf[level], pc.do_tiling ? info.EnableTiling(pc.tile_size) : info),
169 m_level(level),
170 m_pc(&pc)
171{
172 if (isValid()) {
173 auto& particles = m_pc->GetParticles(m_level);
174 while (true) {
175 auto key = std::make_pair(index(), LocalTileIndex());
176 auto f = particles.find(key);
177 if (f != particles.end() && f->second.numParticles() > 0) {
178 m_particle_current_tile = &(f->second);
179 break; // break if isValid() and non-empty particle tile found
180 }
182 if (!isValid()) { break; } // break if isValid() returns false
183 }
184 }
185}
186
187template <bool is_const, typename T_ParticleType, int NArrayReal, int NArrayInt,
188 template<class> class Allocator, class CellAssignor>
190 (ContainerRef pc, int level)
191 :
192 MFIter(*pc.m_dummy_mf[level],
193 pc.do_tiling ? pc.tile_size : IntVect::TheZeroVector()),
194 m_level(level),
195 m_pc(&pc)
196{
197 if (isValid()) {
198 auto& particles = m_pc->GetParticles(m_level);
199 while (true) {
200 auto key = std::make_pair(index(), LocalTileIndex());
201 auto f = particles.find(key);
202 if (f != particles.end() && f->second.numParticles() > 0) {
203 m_particle_current_tile = &(f->second);
204 break;
205 }
207 if (!isValid()) { break; }
208 }
209 }
210}
211
212template <bool is_const, int T_NStructReal, int T_NStructInt, int T_NArrayReal=0, int T_NArrayInt=0,
213 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
214using ParIterBase = ParIterBase_impl<is_const, Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
215
216template <bool is_const, int T_NArrayReal=0, int T_NArrayInt=0,
217 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
218using ParIterBaseSoA = ParIterBase_impl<is_const,SoAParticle<T_NArrayReal, T_NArrayInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
219
220template <int T_NStructReal, int T_NStructInt=0, int T_NArrayReal=0, int T_NArrayInt=0,
221 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
222using ParConstIter = ParConstIter_impl<Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
223
224template <int T_NArrayReal, int T_NArrayInt, template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
225using ParConstIterSoA = ParConstIter_impl<SoAParticle<T_NArrayReal, T_NArrayInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
226
227template <int T_NStructReal, int T_NStructInt=0, int T_NArrayReal=0, int T_NArrayInt=0,
228 template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
229using ParIter = ParIter_impl<Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
230
231template <int T_NArrayReal, int T_NArrayInt, template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
232using ParIterSoA = ParIter_impl<SoAParticle<T_NArrayReal, T_NArrayInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
233
234}
235
236#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:522
Definition AMReX_ParIter.H:142
typename ContainerType::ParticleTileType ParticleTileType
Definition AMReX_ParIter.H:148
typename ContainerType::AoS AoS
Definition AMReX_ParIter.H:149
typename SoA::RealVector RealVector
Definition AMReX_ParIter.H:151
T_ParticleType ParticleType
Definition AMReX_ParIter.H:145
typename ContainerType::SoA SoA
Definition AMReX_ParIter.H:150
ParConstIter_impl(ContainerType const &pc, int level, MFItInfo &info)
Definition AMReX_ParIter.H:158
ParConstIter_impl(ContainerType const &pc, int level)
Definition AMReX_ParIter.H:154
T_CellAssignor CellAssignor
Definition AMReX_ParIter.H:146
typename SoA::IntVector IntVector
Definition AMReX_ParIter.H:152
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:98
ContainerPtr m_pc
Definition AMReX_ParIter.H:106
std::conditional_t< is_const, PCType const *, PCType * > ContainerPtr
Definition AMReX_ParIter.H:38
const Geometry & Geom(int lev) const
Definition AMReX_ParIter.H:100
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:104
typename ContainerType::AoS AoS
Definition AMReX_ParIter.H:52
ParticleTilePtr m_particle_current_tile
Definition AMReX_ParIter.H:105
ParIterBase_impl(ContainerRef pc, int level, MFItInfo &info)
Definition AMReX_ParIter.H:166
typename ContainerType::ParticleTileType ParticleTileType
Definition AMReX_ParIter.H:51
ParticleTileRef GetParticleTile() const
Definition AMReX_ParIter.H:84
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:96
ParIterBase_impl(ContainerRef pc, int level)
Definition AMReX_ParIter.H:190
Definition AMReX_ParIter.H:113
typename ContainerType::SoA SoA
Definition AMReX_ParIter.H:125
typename ContainerType::AoS AoS
Definition AMReX_ParIter.H:124
ParIter_impl(ContainerType &pc, int level)
Definition AMReX_ParIter.H:129
typename SoA::RealVector RealVector
Definition AMReX_ParIter.H:126
T_CellAssignor CellAssignor
Definition AMReX_ParIter.H:117
T_ParticleType ParticleType
Definition AMReX_ParIter.H:116
typename ContainerType::ConstParticleType ConstParticleType
Definition AMReX_ParIter.H:122
ParIter_impl(ContainerType &pc, int level, MFItInfo &info)
Definition AMReX_ParIter.H:133
typename ContainerType::ParticleTileType ParticleTileType
Definition AMReX_ParIter.H:123
static constexpr int NStructInt
Definition AMReX_ParIter.H:119
typename SoA::IntVector IntVector
Definition AMReX_ParIter.H:127
static constexpr int NStructReal
Definition AMReX_ParIter.H:118
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:146
typename ParticleTileType::AoS AoS
Definition AMReX_ParticleContainer.H:188
typename ParticleType::ConstType ConstParticleType
Definition AMReX_ParticleContainer.H:149
typename AoS::ParticleVector ParticleVector
Definition AMReX_ParticleContainer.H:193
typename ParticleTileType::SoA SoA
Definition AMReX_ParticleContainer.H:189
ParticleTile< ParticleType, NArrayReal, NArrayInt, Allocator > ParticleTileType
Definition AMReX_ParticleContainer.H:182
Definition AMReX_Amr.cpp:49
amrex::ArenaAllocator< T > DefaultAllocator
Definition AMReX_GpuAllocators.H:194
Definition AMReX_ParticleUtil.H:432
Definition AMReX_MFIter.H:20
Definition AMReX_ParticleTile.H:702