OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::BlockStructureD< D > Class Template Reference

Base of a regular block. More...

#include <blockStructure.h>

+ Inheritance diagram for olb::BlockStructureD< D >:
+ Collaboration diagram for olb::BlockStructureD< D >:

Public Member Functions

 BlockStructureD (Vector< int, D > size, int padding=0)
 
 BlockStructureD ()
 
void resize (Vector< int, D > size)
 
auto getCore () const
 
int getNx () const
 Read only access to block width.
 
int getNy () const
 Read only access to block height.
 
int getNz () const
 Read only access to block height.
 
LatticeR< D > getExtent () const
 
int getPadding () const
 Read only access to padding.
 
std::size_t getNcells () const
 Get number of cells.
 
CellID getCellId (LatticeR< D > latticeR) const
 Get 1D cell ID.
 
template<typename... L>
std::enable_if_t< sizeof...(L)==D, CellIDgetCellId (L... latticeR) const
 
LatticeR< D > getLatticeR (CellID iCell) const
 
CellDistance getNeighborDistance (LatticeR< D > dir) const
 Get 1D neighbor distance.
 
bool isInside (LatticeR< D > latticeR) const
 Return whether location is valid.
 
bool isInsideCore (LatticeR< D > latticeR) const
 Return whether location is inside core.
 
bool isPadding (LatticeR< D > latticeR) const
 Return whether location is valid.
 
bool isPadding (LatticeR< D > latticeR, int overlap) const
 
bool isPadding (CellID iCell) const
 
template<typename... L>
std::enable_if_t< sizeof...(L)==D, bool > isInside (L... latticeR) const
 
CellDistance getNeighborhoodRadius (LatticeR< D > latticeR) const
 Return maximum valid neighborhood sphere radius w.r.t. latticeR.
 
template<typename F >
void forSpatialLocations (F f) const
 
template<typename F >
void forSpatialLocationsParallel (F f) const
 
template<typename F >
void forSpatialLocations (LatticeR< D > min, LatticeR< D > max, F f) const
 
template<typename F >
void forCoreSpatialLocations (F f) const
 
template<typename F >
void forCellIndices (F f) const
 

Protected Attributes

LatticeR< D > _core
 
LatticeR< D > _size
 
LatticeR< D > _projection
 
int _padding
 

Detailed Description

template<unsigned D>
class olb::BlockStructureD< D >

Base of a regular block.

With extent, optional padding and memory bijection for spatial locations

Definition at line 54 of file blockStructure.h.

Constructor & Destructor Documentation

◆ BlockStructureD() [1/2]

template<unsigned D>
olb::BlockStructureD< D >::BlockStructureD ( Vector< int, D > size,
int padding = 0 )
inline

Definition at line 65 of file blockStructure.h.

65 :
66 _core(size),
67 _size(size + 2*padding),
68 _padding(padding)
69 {
70 if constexpr (D == 3) {
71 _projection = {_size[1]*_size[2], _size[2], 1};
72 } else if constexpr (D == 2) {
73 _projection = {_size[1], 1};
74 } else if constexpr (D == 1) {
75 _projection = {1};
76 } else {
77 static_assert(D >= 1 && D <= 3, "Invalid D");
78 }
79
80 if (getNcells() > 0 && getNcells()-1 > std::numeric_limits<CellID>::max()) {
81 throw std::invalid_argument("Cell count must not exceed cell index space");
82 }
83 };
std::size_t getNcells() const
Get number of cells.
LatticeR< D > _projection

References olb::BlockStructureD< D >::_projection, olb::BlockStructureD< D >::_size, and olb::BlockStructureD< D >::getNcells().

+ Here is the call graph for this function:

◆ BlockStructureD() [2/2]

template<unsigned D>
olb::BlockStructureD< D >::BlockStructureD ( )
inline

Definition at line 85 of file blockStructure.h.

85 :
86 BlockStructureD(1, 0)
87 { };

Member Function Documentation

◆ forCellIndices()

template<unsigned D>
template<typename F >
void olb::BlockStructureD< D >::forCellIndices ( F f) const
inline

Definition at line 376 of file blockStructure.h.

377 {
378 for (CellID iCell=0; iCell < getNcells(); ++iCell) {
379 f(iCell);
380 }
381 }
std::uint32_t CellID
Type for sequential block-local cell indices.

References olb::BlockStructureD< D >::getNcells().

+ Here is the call graph for this function:

◆ forCoreSpatialLocations()

template<unsigned D>
template<typename F >
void olb::BlockStructureD< D >::forCoreSpatialLocations ( F f) const
inline

Definition at line 343 of file blockStructure.h.

344 {
345 using loc = typename LatticeR<D>::value_t;
346 for (loc iX=0; iX < _core[0]; ++iX) {
347 if constexpr (D > 1) {
348 for (loc iY=0; iY < _core[1]; ++iY) {
349 if constexpr (D == 3) {
350 for (loc iZ=0; iZ < _core[2]; ++iZ) {
351 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
352 f({iX,iY,iZ});
353 } else {
354 f(iX,iY,iZ);
355 }
356 }
357 } else {
358 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
359 f({iX,iY});
360 } else {
361 f(iX,iY);
362 }
363 }
364 }
365 } else {
366 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
367 f({iX});
368 } else {
369 f(iX);
370 }
371 }
372 }
373 };

References olb::BlockStructureD< D >::_core.

+ Here is the caller graph for this function:

◆ forSpatialLocations() [1/2]

template<unsigned D>
template<typename F >
void olb::BlockStructureD< D >::forSpatialLocations ( F f) const
inline

Definition at line 236 of file blockStructure.h.

237 {
238 using loc = typename LatticeR<D>::value_t;
239 for (loc iX=-_padding; iX < _core[0] + _padding; ++iX) {
240 if constexpr (D > 1) {
241 for (loc iY=-_padding; iY < _core[1] + _padding; ++iY) {
242 if constexpr (D == 3) {
243 for (loc iZ=-_padding; iZ < _core[2] + _padding; ++iZ) {
244 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
245 f({iX,iY,iZ});
246 } else {
247 f(iX,iY,iZ);
248 }
249 }
250 } else {
251 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
252 f({iX,iY});
253 } else {
254 f(iX,iY);
255 }
256 }
257 }
258 } else {
259 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
260 f({iX});
261 } else {
262 f(iX);
263 }
264 }
265 }
266 };

References olb::BlockStructureD< D >::_core, and olb::BlockStructureD< D >::_padding.

+ Here is the caller graph for this function:

◆ forSpatialLocations() [2/2]

template<unsigned D>
template<typename F >
void olb::BlockStructureD< D >::forSpatialLocations ( LatticeR< D > min,
LatticeR< D > max,
F f ) const
inline

Definition at line 310 of file blockStructure.h.

311 {
312 using loc = typename LatticeR<D>::value_t;
313 for (loc iX=std::max(-_padding, min[0]); iX < std::min(_core[0] + _padding, max[0]+1); ++iX) {
314 if constexpr (D > 1) {
315 for (loc iY=std::max(-_padding, min[1]); iY < std::min(_core[1] + _padding, max[1]+1); ++iY) {
316 if constexpr (D == 3) {
317 for (loc iZ=std::max(-_padding, min[2]); iZ < std::min(_core[2] + _padding, max[2]+1); ++iZ) {
318 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
319 f({iX,iY,iZ});
320 } else {
321 f(iX,iY,iZ);
322 }
323 }
324 } else {
325 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
326 f({iX,iY});
327 } else {
328 f(iX,iY);
329 }
330 }
331 }
332 } else {
333 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
334 f({iX});
335 } else {
336 f(iX);
337 }
338 }
339 }
340 };

References olb::BlockStructureD< D >::_core, and olb::BlockStructureD< D >::_padding.

◆ forSpatialLocationsParallel()

template<unsigned D>
template<typename F >
void olb::BlockStructureD< D >::forSpatialLocationsParallel ( F f) const
inline

Definition at line 269 of file blockStructure.h.

270 {
271 using loc = typename LatticeR<D>::value_t;
272 if constexpr (D > 1) {
273 #ifdef PARALLEL_MODE_OMP
274 #pragma omp parallel for schedule(dynamic,1)
275 #endif
276 for (loc iX=-_padding; iX < _core[0] + _padding; ++iX) {
277 for (loc iY=-_padding; iY < _core[1] + _padding; ++iY) {
278 if constexpr (D == 3) {
279 for (loc iZ=-_padding; iZ < _core[2] + _padding; ++iZ) {
280 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
281 f({iX,iY,iZ});
282 } else {
283 f(iX,iY,iZ);
284 }
285 }
286 } else {
287 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
288 f({iX,iY});
289 } else {
290 f(iX,iY);
291 }
292 }
293 }
294 }
295 } else {
296 #ifdef PARALLEL_MODE_OMP
297 #pragma omp parallel for schedule(static)
298 #endif
299 for (loc iX=-_padding; iX < _core[0] + _padding; ++iX) {
300 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
301 f({iX});
302 } else {
303 f(iX);
304 }
305 }
306 }
307 }

References olb::BlockStructureD< D >::_core, and olb::BlockStructureD< D >::_padding.

◆ getCellId() [1/2]

template<unsigned D>
template<typename... L>
std::enable_if_t< sizeof...(L)==D, CellID > olb::BlockStructureD< D >::getCellId ( L... latticeR) const
inline

Definition at line 158 of file blockStructure.h.

159 {
160 return LatticeR<D>{latticeR+_padding...} * _projection;
161 }
Vector< std::int32_t, D > LatticeR
Type for spatial block-local lattice coordinates.

References olb::BlockStructureD< D >::_padding, and olb::BlockStructureD< D >::_projection.

◆ getCellId() [2/2]

template<unsigned D>
CellID olb::BlockStructureD< D >::getCellId ( LatticeR< D > latticeR) const
inline

Get 1D cell ID.

Definition at line 150 of file blockStructure.h.

151 {
152 OLB_PRECONDITION(isInside(latticeR));
153 return (latticeR+_padding) * _projection;
154 }
bool isInside(LatticeR< D > latticeR) const
Return whether location is valid.
#define OLB_PRECONDITION(COND)
Definition olbDebug.h:46

References olb::BlockStructureD< D >::_padding, olb::BlockStructureD< D >::_projection, olb::BlockStructureD< D >::isInside(), and OLB_PRECONDITION.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCore()

template<unsigned D>
auto olb::BlockStructureD< D >::getCore ( ) const
inline

Definition at line 102 of file blockStructure.h.

103 {
104 return _core;
105 }

References olb::BlockStructureD< D >::_core.

+ Here is the caller graph for this function:

◆ getExtent()

template<unsigned D>
LatticeR< D > olb::BlockStructureD< D >::getExtent ( ) const
inline

Definition at line 125 of file blockStructure.h.

126 {
127 return _core;
128 }

References olb::BlockStructureD< D >::_core.

◆ getLatticeR()

template<unsigned D>
LatticeR< D > olb::BlockStructureD< D >::getLatticeR ( CellID iCell) const
inline

Definition at line 163 of file blockStructure.h.

164 {
165 if constexpr (D == 3) {
166 const std::int32_t iX = iCell / _projection[0];
167 const std::int32_t remainder = iCell % _projection[0];
168 const std::int32_t iY = remainder / _projection[1];
169 const std::int32_t iZ = remainder % _projection[1];
170 return LatticeR<D>{iX - _padding, iY - _padding, iZ - _padding};
171 } else {
172 const std::int32_t iX = iCell / _projection[0];
173 const std::int32_t iY = iCell % _projection[0];
174 return LatticeR<D>{iX - _padding, iY - _padding};
175 }
176 };

References olb::BlockStructureD< D >::_padding, and olb::BlockStructureD< D >::_projection.

+ Here is the caller graph for this function:

◆ getNcells()

template<unsigned D>
std::size_t olb::BlockStructureD< D >::getNcells ( ) const
inline

Get number of cells.

Definition at line 137 of file blockStructure.h.

138 {
139 if constexpr (D == 3) {
140 return _size[0] * _size[1] * _size[2];
141 } else if constexpr (D == 2) {
142 return _size[0] * _size[1];
143 } else if constexpr (D == 1) {
144 return _size[0];
145 }
146 __builtin_unreachable();
147 }

References olb::BlockStructureD< D >::_size.

+ Here is the caller graph for this function:

◆ getNeighborDistance()

template<unsigned D>
CellDistance olb::BlockStructureD< D >::getNeighborDistance ( LatticeR< D > dir) const
inline

Get 1D neighbor distance.

Definition at line 179 of file blockStructure.h.

180 {
181 return dir * _projection;
182 }

References olb::BlockStructureD< D >::_projection.

+ Here is the caller graph for this function:

◆ getNeighborhoodRadius()

template<unsigned D>
CellDistance olb::BlockStructureD< D >::getNeighborhoodRadius ( LatticeR< D > latticeR) const
inline

Return maximum valid neighborhood sphere radius w.r.t. latticeR.

Definition at line 223 of file blockStructure.h.

224 {
225 auto lower = latticeR + _padding;
226 auto upper = LatticeR<D>([&](unsigned iDim) -> int {
227 int x = lower[iDim] - _size[iDim] + 1;
228 return x < 0 ? -x : 0;
229 });
230 auto y = std::min(*std::min_element(lower.data(), lower.data() + D),
231 *std::min_element(upper.data(), upper.data() + D));
232 return y;
233 };

References olb::BlockStructureD< D >::_padding, and olb::BlockStructureD< D >::_size.

+ Here is the caller graph for this function:

◆ getNx()

template<unsigned D>
int olb::BlockStructureD< D >::getNx ( ) const
inline

Read only access to block width.

Definition at line 108 of file blockStructure.h.

109 {
110 return _core[0];
111 };

References olb::BlockStructureD< D >::_core.

+ Here is the caller graph for this function:

◆ getNy()

template<unsigned D>
int olb::BlockStructureD< D >::getNy ( ) const
inline

Read only access to block height.

Definition at line 113 of file blockStructure.h.

114 {
115 static_assert(D >= 2, "y-component only available in 2D or higher");
116 return _core[1];
117 };

References olb::BlockStructureD< D >::_core.

+ Here is the caller graph for this function:

◆ getNz()

template<unsigned D>
int olb::BlockStructureD< D >::getNz ( ) const
inline

Read only access to block height.

Definition at line 119 of file blockStructure.h.

120 {
121 static_assert(D >= 3, "z-component only available in 3D or higher");
122 return _core[2];
123 };

References olb::BlockStructureD< D >::_core.

+ Here is the caller graph for this function:

◆ getPadding()

template<unsigned D>
int olb::BlockStructureD< D >::getPadding ( ) const
inline

Read only access to padding.

Definition at line 131 of file blockStructure.h.

132 {
133 return _padding;
134 };

References olb::BlockStructureD< D >::_padding.

+ Here is the caller graph for this function:

◆ isInside() [1/2]

template<unsigned D>
template<typename... L>
std::enable_if_t< sizeof...(L)==D, bool > olb::BlockStructureD< D >::isInside ( L... latticeR) const
inline

Definition at line 217 of file blockStructure.h.

218 {
219 return isInside({latticeR...});
220 };

References olb::BlockStructureD< D >::isInside().

+ Here is the call graph for this function:

◆ isInside() [2/2]

template<unsigned D>
bool olb::BlockStructureD< D >::isInside ( LatticeR< D > latticeR) const
inline

Return whether location is valid.

Definition at line 185 of file blockStructure.h.

186 {
187 return latticeR >= -_padding && latticeR < _core + _padding;
188 };

References olb::BlockStructureD< D >::_core, and olb::BlockStructureD< D >::_padding.

+ Here is the caller graph for this function:

◆ isInsideCore()

template<unsigned D>
bool olb::BlockStructureD< D >::isInsideCore ( LatticeR< D > latticeR) const
inline

Return whether location is inside core.

Definition at line 191 of file blockStructure.h.

192 {
193 return latticeR >= 0 && latticeR < _core;
194 };

References olb::BlockStructureD< D >::_core.

+ Here is the caller graph for this function:

◆ isPadding() [1/3]

template<unsigned D>
bool olb::BlockStructureD< D >::isPadding ( CellID iCell) const
inline

Definition at line 210 of file blockStructure.h.

211 {
212 return isPadding(getLatticeR(iCell));
213 };
LatticeR< D > getLatticeR(CellID iCell) const
bool isPadding(LatticeR< D > latticeR) const
Return whether location is valid.

References olb::BlockStructureD< D >::getLatticeR(), and olb::BlockStructureD< D >::isPadding().

+ Here is the call graph for this function:

◆ isPadding() [2/3]

template<unsigned D>
bool olb::BlockStructureD< D >::isPadding ( LatticeR< D > latticeR) const
inline

Return whether location is valid.

Definition at line 197 of file blockStructure.h.

198 {
199 return isInside(latticeR) && !(latticeR >= 0 && latticeR < _core);
200 };

References olb::BlockStructureD< D >::_core, and olb::BlockStructureD< D >::isInside().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isPadding() [3/3]

template<unsigned D>
bool olb::BlockStructureD< D >::isPadding ( LatticeR< D > latticeR,
int overlap ) const
inline

Definition at line 202 of file blockStructure.h.

203 {
204 return isInside(latticeR)
205 && !isInsideCore(latticeR)
206 && latticeR >= -overlap
207 && latticeR < _core+overlap;
208 };
bool isInsideCore(LatticeR< D > latticeR) const
Return whether location is inside core.

References olb::BlockStructureD< D >::_core, olb::BlockStructureD< D >::isInside(), and olb::BlockStructureD< D >::isInsideCore().

+ Here is the call graph for this function:

◆ resize()

template<unsigned D>
void olb::BlockStructureD< D >::resize ( Vector< int, D > size)
inline

Definition at line 89 of file blockStructure.h.

90 {
91 _core = size;
92 _size = size + 2*_padding;
93 if constexpr (D == 3) {
94 _projection = {_size[1]*_size[2], _size[2], 1};
95 } else if constexpr (D == 2) {
96 _projection = {_size[1], 1};
97 } else if constexpr (D == 1) {
98 _projection = {1};
99 }
100 }

References olb::BlockStructureD< D >::_core, olb::BlockStructureD< D >::_padding, olb::BlockStructureD< D >::_projection, and olb::BlockStructureD< D >::_size.

Member Data Documentation

◆ _core

template<unsigned D>
LatticeR<D> olb::BlockStructureD< D >::_core
protected

Definition at line 56 of file blockStructure.h.

◆ _padding

template<unsigned D>
int olb::BlockStructureD< D >::_padding
protected

Definition at line 60 of file blockStructure.h.

◆ _projection

template<unsigned D>
LatticeR<D> olb::BlockStructureD< D >::_projection
protected

Definition at line 58 of file blockStructure.h.

◆ _size

template<unsigned D>
LatticeR<D> olb::BlockStructureD< D >::_size
protected

Definition at line 57 of file blockStructure.h.


The documentation for this class was generated from the following file: