OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
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 ()
 
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
 
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.
 
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 {
73 _projection = {_size[1], 1};
74 }
75
76 if (getNcells()-1 > std::numeric_limits<CellID>::max()) {
77 throw std::invalid_argument("Cell count must not exceed cell index space");
78 }
79 };
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 81 of file blockStructure.h.

81 :
82 BlockStructureD(1, 0)
83 { };

Member Function Documentation

◆ forCellIndices()

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

Definition at line 286 of file blockStructure.h.

287 {
288 for (CellID iCell=0; iCell < getNcells(); ++iCell) {
289 f(iCell);
290 }
291 }
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 261 of file blockStructure.h.

262 {
263 using loc = typename LatticeR<D>::value_t;
264 for (loc iX=0; iX < _core[0]; ++iX) {
265 for (loc iY=0; iY < _core[1]; ++iY) {
266 if constexpr (D == 3) {
267 for (loc iZ=0; iZ < _core[2]; ++iZ) {
268 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
269 f({iX,iY,iZ});
270 } else {
271 f(iX,iY,iZ);
272 }
273 }
274 } else {
275 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
276 f({iX,iY});
277 } else {
278 f(iX,iY);
279 }
280 }
281 }
282 }
283 };

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 183 of file blockStructure.h.

184 {
185 using loc = typename LatticeR<D>::value_t;
186 for (loc iX=-_padding; iX < _core[0] + _padding; ++iX) {
187 for (loc iY=-_padding; iY < _core[1] + _padding; ++iY) {
188 if constexpr (D == 3) {
189 for (loc iZ=-_padding; iZ < _core[2] + _padding; ++iZ) {
190 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
191 f({iX,iY,iZ});
192 } else {
193 f(iX,iY,iZ);
194 }
195 }
196 } else {
197 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
198 f({iX,iY});
199 } else {
200 f(iX,iY);
201 }
202 }
203 }
204 }
205 };

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 236 of file blockStructure.h.

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

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 208 of file blockStructure.h.

209 {
210 using loc = typename LatticeR<D>::value_t;
211 #ifdef PARALLEL_MODE_OMP
212 #pragma omp parallel for schedule(dynamic,1)
213 #endif
214 for (loc iX=-_padding; iX < _core[0] + _padding; ++iX) {
215 for (loc iY=-_padding; iY < _core[1] + _padding; ++iY) {
216 if constexpr (D == 3) {
217 for (loc iZ=-_padding; iZ < _core[2] + _padding; ++iZ) {
218 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
219 f({iX,iY,iZ});
220 } else {
221 f(iX,iY,iZ);
222 }
223 }
224 } else {
225 if constexpr (std::is_invocable_v<F, LatticeR<D>>) {
226 f({iX,iY});
227 } else {
228 f(iX,iY);
229 }
230 }
231 }
232 }
233 }

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 133 of file blockStructure.h.

134 {
135 return LatticeR<D>{latticeR+_padding...} * _projection;
136 }

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 125 of file blockStructure.h.

126 {
127 OLB_PRECONDITION(isInside(latticeR));
128 return (latticeR+_padding) * _projection;
129 }
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:

◆ getExtent()

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

Definition at line 102 of file blockStructure.h.

103 {
104 return _core;
105 }

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

◆ getNcells()

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

Get number of cells.

Definition at line 114 of file blockStructure.h.

115 {
116 if constexpr (D == 3) {
117 return _size[0] * _size[1] * _size[2];
118 } else {
119 return _size[0] * _size[1];
120 }
121 __builtin_unreachable();
122 }

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 139 of file blockStructure.h.

140 {
141 return dir * _projection;
142 }

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 170 of file blockStructure.h.

171 {
172 auto lower = latticeR + _padding;
173 auto upper = LatticeR<D>([&](unsigned iDim) -> int {
174 int x = lower[iDim] - _size[iDim] + 1;
175 return x < 0 ? -x : 0;
176 });
177 auto y = std::min(*std::min_element(lower.data(), lower.data() + D),
178 *std::min_element(upper.data(), upper.data() + D));
179 return y;
180 };

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

◆ getNx()

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

Read only access to block width.

Definition at line 86 of file blockStructure.h.

87 {
88 return _core[0];
89 };

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 91 of file blockStructure.h.

92 {
93 return _core[1];
94 };

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 96 of file blockStructure.h.

97 {
98 static_assert(D == 3, "z-component only available in 3D");
99 return _core[2];
100 };

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 108 of file blockStructure.h.

109 {
110 return _padding;
111 };

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 164 of file blockStructure.h.

165 {
166 return isInside({latticeR...});
167 };

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 145 of file blockStructure.h.

146 {
147 return latticeR >= -_padding && latticeR < _core + _padding;
148 };

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 151 of file blockStructure.h.

152 {
153 return latticeR >= 0 && latticeR < _core;
154 };

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

◆ isPadding()

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

Return whether location is valid.

Definition at line 157 of file blockStructure.h.

158 {
159 return isInside(latticeR) && !(latticeR >= 0 && latticeR < _core);
160 };

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:

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: