Block-Structured AMR Software Framework
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 
8 namespace amrex
9 {
10 
11 template <typename ParticleType, int NArrayReal, int NArrayInt,
12  template<class> class Allocator, class CellAssignor>
13 class ParticleContainer_impl;
14 
15 template <int T_NReal, int T_NInt>
16 struct Particle;
17 
18 template <int NArrayReal, int NArrayInt>
19 struct SoAParticle;
20 
21 struct DefaultAssignor;
22 
23 // for backwards compatibility
24 template <int T_NStructReal, int T_NStructInt=0, int T_NArrayReal=0, int T_NArrayInt=0,
25  template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
26 using ParticleContainer = ParticleContainer_impl<Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
27 
28 template <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 
34 private:
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 
48 public:
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 
61  ParIterBase_impl (ContainerRef pc, int level);
62 
63  ParIterBase_impl (ContainerRef pc, int level, MFItInfo& info);
64 
65  void operator++ ()
66  {
67  m_particle_current_tile = nullptr;
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 
102 protected:
103 
104  int m_level;
107 };
108 
109 template <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 {
114 public:
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 
129  ParIter_impl (ContainerType& pc, int level)
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 
138 template <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 {
143 public:
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 
163 template <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 
187 template <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 
212 template <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>
214 using ParIterBase = ParIterBase_impl<is_const, Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
215 
216 template <bool is_const, int T_NArrayReal=0, int T_NArrayInt=0,
217  template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
218 using ParIterBaseSoA = ParIterBase_impl<is_const,SoAParticle<T_NArrayReal, T_NArrayInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
219 
220 template <int T_NStructReal, int T_NStructInt=0, int T_NArrayReal=0, int T_NArrayInt=0,
221  template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
222 using ParConstIter = ParConstIter_impl<Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
223 
224 template <int T_NArrayReal, int T_NArrayInt, template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
225 using ParConstIterSoA = ParConstIter_impl<SoAParticle<T_NArrayReal, T_NArrayInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
226 
227 template <int T_NStructReal, int T_NStructInt=0, int T_NArrayReal=0, int T_NArrayInt=0,
228  template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
229 using ParIter = ParIter_impl<Particle<T_NStructReal, T_NStructInt>, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor>;
230 
231 template <int T_NArrayReal, int T_NArrayInt, template<class> class Allocator=DefaultAllocator, class CellAssignor=DefaultAssignor>
232 using 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
ContainerPtr m_pc
Definition: AMReX_ParIter.H:106
std::conditional_t< is_const, PCType const *, PCType * > ContainerPtr
Definition: AMReX_ParIter.H:38
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
std::pair< int, int > GetPairIndex() const
Definition: AMReX_ParIter.H:98
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
const Geometry & Geom(int lev) const
Definition: AMReX_ParIter.H:100
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:144
typename ParticleTileType::AoS AoS
Definition: AMReX_ParticleContainer.H:186
typename ParticleType::ConstType ConstParticleType
Definition: AMReX_ParticleContainer.H:147
typename AoS::ParticleVector ParticleVector
Definition: AMReX_ParticleContainer.H:191
typename ParticleTileType::SoA SoA
Definition: AMReX_ParticleContainer.H:187
ParticleTile< ParticleType, NArrayReal, NArrayInt, Allocator > ParticleTileType
Definition: AMReX_ParticleContainer.H:180
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
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:690