OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::Cuboid< T, D > Class Template Referencefinal

#include <cuboid.h>

+ Inheritance diagram for olb::Cuboid< T, D >:
+ Collaboration diagram for olb::Cuboid< T, D >:

Public Member Functions

 Cuboid ()=default
 
 Cuboid (Vector< T, D > origin, T delta, Vector< int, D > extent)
 
 Cuboid (const Cuboid &rhs)
 
 Cuboid (IndicatorF< T, D > &indicatorF, T delta)
 
Cuboidoperator= (const Cuboid &rhs)
 
bool operator== (const Cuboid &rhs) const
 
Vector< T, D > getOrigin () const
 Returns lower left corner coordinates.
 
getDeltaR () const
 Returns spacing of cuboid nodes.
 
Vector< int, D > getExtent () const
 Returns extent in number of voxels.
 
int getNx () const
 
int getNy () const
 
int getNz () const
 
getPhysVolume () const
 Returns the volume of the cuboid.
 
std::size_t getWeight () const
 
void setWeight (std::size_t weight)
 
Vector< T, D > getPhysR (LatticeR< D > latticeR) const
 
LatticeR< D > getLatticeR (Vector< T, D > physR) const
 
LatticeR< D > getFloorLatticeR (Vector< T, D > physR) const
 
std::optional< LatticeR< D > > getCloseLatticeR (Vector< T, D > physR, T eps=1e-5) const
 Returns closest latticeR within eps of physR if it exists.
 
std::size_t getLatticeVolume () const
 Returns the number of Nodes in the volume.
 
getPhysPerimeter () const
 Returns the perimeter of the cuboid.
 
getPhysPerimeter () const
 Returns the perimeter of the cuboid.
 
std::size_t getLatticePerimeter () const
 Returns the number of Nodes at the perimeter.
 
std::size_t getLatticePerimeter () const
 Returns the number of Nodes at the perimeter.
 
bool isInside (Vector< T, D > pos, int overlap=0) const
 Checks whether pos is contained in the cuboid extended with an layer of size overlap*delta.
 
bool intersects (Vector< T, D > globMin, Vector< T, D > globMax, int overlap=0) const
 Checks whether there is an intersection with the cuboid extended by a layer of size overlap*delta.
 
bool intersects (const Cuboid< T, D > &cuboid) const
 Returns true iff self intersects cuboid.
 
void divide (Vector< int, D > division, std::vector< Cuboid< T, D > > &childrenC) const
 Divides the cuboid in p*q*r cuboids of equal volume and add them to the given vector.
 
void divide (Vector< int, D > division, std::vector< Cuboid< T, D > > &childrenC) const
 Divides the cuboid in p*q cuboids of equal volume and add them to the given vector.
 
void divideP (int p, std::vector< Cuboid< T, D > > &childrenC) const
 Divides the cuboid in p cuboids and add them to the given vector.
 
void divideP (int p, std::vector< Cuboid< T, D > > &childrenC) const
 Divides the cuboid in p cuboids and add them to the given vector.
 
void divideFractional (int iD, std::vector< T > fractions, std::vector< Cuboid< T, D > > &childrenC) const
 Divides the cuboid into fractions along the iDth dimension.
 
void resize (Vector< int, D > offset, Vector< int, D > extent)
 
void refine (int factor)
 
void write (std::ostream &cout) const
 
void print () const
 
void writeAsXML (std::ostream &) const
 

Detailed Description

template<typename T, unsigned D>
class olb::Cuboid< T, D >

Definition at line 38 of file cuboid.h.

Constructor & Destructor Documentation

◆ Cuboid() [1/4]

template<typename T , unsigned D>
olb::Cuboid< T, D >::Cuboid ( )
default

◆ Cuboid() [2/4]

template<typename T , unsigned D>
olb::Cuboid< T, D >::Cuboid ( Vector< T, D > origin,
T delta,
Vector< int, D > extent )
inline

Definition at line 54 of file cuboid.h.

54 :
55 _origin(origin),
56 _extent(extent),
57 _delta(delta),
58 _weight(getLatticeVolume()) { }
std::size_t getLatticeVolume() const
Returns the number of Nodes in the volume.
Definition cuboid.hh:62

◆ Cuboid() [3/4]

template<typename T , unsigned D>
olb::Cuboid< T, D >::Cuboid ( const Cuboid< T, D > & rhs)
inline

Definition at line 59 of file cuboid.h.

59 :
60 _origin(rhs._origin),
61 _extent(rhs._extent),
62 _delta(rhs._delta),
63 _weight(rhs._weight) { }

◆ Cuboid() [4/4]

template<typename T , unsigned D>
olb::Cuboid< T, D >::Cuboid ( IndicatorF< T, D > & indicatorF,
T delta )
inline

Definition at line 64 of file cuboid.h.

64 :
65 _origin(indicatorF.getMin()),
66 _extent((indicatorF.getMax() - indicatorF.getMin()) / delta + 1.5),
67 _delta(delta),
68 _weight(getLatticeVolume()) { }

Member Function Documentation

◆ divide() [1/2]

template<typename T , unsigned D>
requires (D == 3)
void olb::Cuboid< T, D >::divide ( Vector< int, D > division,
std::vector< Cuboid< T, D > > & childrenC ) const

Divides the cuboid in p*q*r cuboids of equal volume and add them to the given vector.

Definition at line 161 of file cuboid.hh.

162{
163 T globPosX_child, globPosY_child;
164 int xN_child = 0;
165 int yN_child = 0;
166
167 globPosX_child = _origin[0];
168 globPosY_child = _origin[1];
169
170 for (int iX=0; iX < division[0]; iX++) {
171 for (int iY=0; iY < division[1]; iY++) {
172 xN_child = (_extent[0]+division[0]-iX-1)/division[0];
173 yN_child = (_extent[1]+division[1]-iY-1)/division[1];
174 Cuboid2D<T> child({globPosX_child, globPosY_child}, _delta, {xN_child, yN_child});
175 childrenC.push_back(child);
176 globPosY_child += yN_child*_delta;
177 }
178 globPosY_child = _origin[1];
179 globPosX_child += xN_child*_delta;
180 }
181}
Cuboid< T, 2 > Cuboid2D
Definition cuboid.h:149
+ Here is the caller graph for this function:

◆ divide() [2/2]

template<typename T , unsigned D>
void olb::Cuboid< T, D >::divide ( Vector< int, D > division,
std::vector< Cuboid< T, D > > & childrenC ) const

Divides the cuboid in p*q cuboids of equal volume and add them to the given vector.

◆ divideFractional()

template<typename T , unsigned D>
void olb::Cuboid< T, D >::divideFractional ( int iD,
std::vector< T > fractions,
std::vector< Cuboid< T, D > > & childrenC ) const

Divides the cuboid into fractions along the iDth dimension.

Definition at line 546 of file cuboid.hh.

547{
548 auto delta = Vector<T,D>([&](int i) -> T {
549 return i == iD ? _delta : 0;
550 });
551 auto base = Vector<int,D>([&](int i) -> T {
552 return i == iD ? 1 : 0;
553 });
554
555 std::vector<int> fractionWidths;
556 int totalWidth = 0;
557 for (T f : fractions) {
558 fractionWidths.emplace_back(f * (getExtent()*base));
559 totalWidth += fractionWidths.back();
560 }
561 fractionWidths.back() += getExtent()*base - totalWidth;
562
563 auto origin = getOrigin();
564 auto extent = Vector<int,D>([&](int i) -> T {
565 return i == iD ? 0 : getExtent()[i];
566 });
567
568 for (int width : fractionWidths) {
569 Cuboid<T,D> child(origin, _delta, extent + (width)*base);
570 child.print();
571 origin += width*delta;
572 childrenC.push_back(child);
573 }
574}
Vector< T, D > getOrigin() const
Returns lower left corner coordinates.
Definition cuboid.h:74
Vector< int, D > getExtent() const
Returns extent in number of voxels.
Definition cuboid.h:78
Cuboid()=default

References olb::Cuboid< T, D >::print().

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

◆ divideP() [1/2]

template<typename T , unsigned D>
requires (D == 2)
void olb::Cuboid< T, D >::divideP ( int p,
std::vector< Cuboid< T, D > > & childrenC ) const

Divides the cuboid in p cuboids and add them to the given vector.

Definition at line 214 of file cuboid.hh.

215{
216 int nX = 0;
217 int nY = 0;
218 T ratio;
219 T bestRatio = (T)_extent[0]/(T)_extent[1];
220 T difRatio = util::fabs(bestRatio - 1) + 1;
221 for (int i=1; i<= p; i++) {
222 int j = p / i;
223 if (i*j<=p) {
224 if ( util::fabs(bestRatio - (T)i/(T)j) <= difRatio) {
225 difRatio = util::fabs(bestRatio - (T)i/(T)j);
226 nX = i;
227 nY = j;
228 }
229 }
230 }
231
232 ratio = T(nX)/(T)nY;
233 int rest = p - nX*nY;
234
235 if (rest==0) {
236 divide({nX,nY},childrenC);
237 return;
238 }
239
240 if (ratio < bestRatio && (nY-rest) >= 0) {
241 int n_QNoInsertions = nX*(nY-rest);
242 T bestVolume_QNoInsertions = (T)_extent[0]*_extent[1] * n_QNoInsertions/(T)p;
243 int yN_QNoInsertions = (int)(bestVolume_QNoInsertions / (T)_extent[0]);
244 int xN_QNoInsertions = _extent[0];
245 int yN_QInsertions = _extent[1]-yN_QNoInsertions;
246 int xN_QInsertions = _extent[0];
247 Cuboid2D<T> firstChildQ({_origin[0], _origin[1]}, _delta, {xN_QNoInsertions, yN_QNoInsertions});
248 Cuboid2D<T> secondChildQ({_origin[0], _origin[1]+yN_QNoInsertions*_delta}, _delta, {xN_QInsertions, yN_QInsertions});
249 firstChildQ.divide({nX, nY-rest}, childrenC);
250 secondChildQ.divide({nX+1,rest}, childrenC);
251 }
252 else {
253 int n_QNoInsertions = nY*(nX-rest);
254 T bestVolume_QNoInsertions = (T)_extent[0]*_extent[1] * n_QNoInsertions/(T)p;
255 int xN_QNoInsertions = (int)(bestVolume_QNoInsertions / (T)_extent[1] + 0.9999);
256 int yN_QNoInsertions = _extent[1];
257 int xN_QInsertions = _extent[0]-xN_QNoInsertions;
258 int yN_QInsertions = _extent[1];
259 Cuboid2D<T> firstChildQ({_origin[0], _origin[1]}, _delta, {xN_QNoInsertions, yN_QNoInsertions});
260 Cuboid2D<T> secondChildQ({_origin[0]+xN_QNoInsertions*_delta, _origin[1]}, _delta, {xN_QInsertions, yN_QInsertions});
261 firstChildQ.divide({nX-rest, nY}, childrenC);
262 secondChildQ.divide({rest,nY+1}, childrenC);
263 }
264}
void divide(Vector< int, D > division, std::vector< Cuboid< T, D > > &childrenC) const
Divides the cuboid in p*q*r cuboids of equal volume and add them to the given vector.
Definition cuboid.hh:161
Expr fabs(Expr x)
Definition expr.cpp:230

References olb::Cuboid< T, D >::divide(), and olb::util::fabs().

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

◆ divideP() [2/2]

template<typename T , unsigned D>
void olb::Cuboid< T, D >::divideP ( int p,
std::vector< Cuboid< T, D > > & childrenC ) const

Divides the cuboid in p cuboids and add them to the given vector.

◆ getCloseLatticeR()

template<typename T , unsigned D>
std::optional< LatticeR< D > > olb::Cuboid< T, D >::getCloseLatticeR ( Vector< T, D > physR,
T eps = 1e-5 ) const

Returns closest latticeR within eps of physR if it exists.

Definition at line 42 of file cuboid.hh.

42 {
43 auto globR = _origin;
44 auto physLatticeR = (physR - globR) / _delta;
45 if (util::abs(util::round(physLatticeR) - physLatticeR) <= eps) {
46 return LatticeR<D>(util::round(physLatticeR));
47 } else {
48 return std::nullopt;
49 }
50}
ADf< T, DIM > abs(const ADf< T, DIM > &a)
Definition aDiff.h:1019
ADf< T, DIM > round(const ADf< T, DIM > &a)
Definition aDiff.h:928
Vector< std::int32_t, D > LatticeR
Type for spatial block-local lattice coordinates.

References olb::util::abs(), and olb::util::round().

+ Here is the call graph for this function:

◆ getDeltaR()

template<typename T , unsigned D>
T olb::Cuboid< T, D >::getDeltaR ( ) const
inline

Returns spacing of cuboid nodes.

Definition at line 76 of file cuboid.h.

76{ return _delta; }
+ Here is the caller graph for this function:

◆ getExtent()

template<typename T , unsigned D>
Vector< int, D > olb::Cuboid< T, D >::getExtent ( ) const
inline

Returns extent in number of voxels.

Definition at line 78 of file cuboid.h.

78{ return _extent; }
+ Here is the caller graph for this function:

◆ getFloorLatticeR()

template<typename T , unsigned D>
LatticeR< D > olb::Cuboid< T, D >::getFloorLatticeR ( Vector< T, D > physR) const
inline

Definition at line 98 of file cuboid.h.

98 {
99 return util::floor((physR - _origin) / _delta);
100 }
ADf< T, DIM > floor(const ADf< T, DIM > &a)
Definition aDiff.h:869

References olb::util::floor().

+ Here is the call graph for this function:

◆ getLatticePerimeter() [1/2]

template<typename T , unsigned D>
requires (D == 2)
std::size_t olb::Cuboid< T, D >::getLatticePerimeter ( ) const

Returns the number of Nodes at the perimeter.

Definition at line 82 of file cuboid.hh.

82 {
83 return 2*_extent[1] + 2*_extent[0] - 4;
84}

◆ getLatticePerimeter() [2/2]

template<typename T , unsigned D>
std::size_t olb::Cuboid< T, D >::getLatticePerimeter ( ) const

Returns the number of Nodes at the perimeter.

◆ getLatticeR()

template<typename T , unsigned D>
LatticeR< D > olb::Cuboid< T, D >::getLatticeR ( Vector< T, D > physR) const
inline

Definition at line 94 of file cuboid.h.

94 {
95 return util::floor((physR - _origin) / _delta + 0.5);
96 }

References olb::util::floor().

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

◆ getLatticeVolume()

template<typename T , unsigned D>
std::size_t olb::Cuboid< T, D >::getLatticeVolume ( ) const

Returns the number of Nodes in the volume.

Definition at line 62 of file cuboid.hh.

62 {
63 std::size_t latticeVolume = _extent[0];
64 for (unsigned iD=1; iD < D; ++iD) {
65 latticeVolume *= _extent[iD];
66 }
67 return latticeVolume;
68}
+ Here is the caller graph for this function:

◆ getNx()

template<typename T , unsigned D>
int olb::Cuboid< T, D >::getNx ( ) const
inline

Definition at line 80 of file cuboid.h.

80{ return _extent[0]; }
+ Here is the caller graph for this function:

◆ getNy()

template<typename T , unsigned D>
int olb::Cuboid< T, D >::getNy ( ) const
inline

Definition at line 81 of file cuboid.h.

81{ return _extent[1]; }
+ Here is the caller graph for this function:

◆ getNz()

template<typename T , unsigned D>
int olb::Cuboid< T, D >::getNz ( ) const
inline

Definition at line 82 of file cuboid.h.

82{ return _extent[2]; }
+ Here is the caller graph for this function:

◆ getOrigin()

template<typename T , unsigned D>
Vector< T, D > olb::Cuboid< T, D >::getOrigin ( ) const
inline

Returns lower left corner coordinates.

Definition at line 74 of file cuboid.h.

74{ return _origin; }
+ Here is the caller graph for this function:

◆ getPhysPerimeter() [1/2]

template<typename T , unsigned D>
requires (D == 2)
T olb::Cuboid< T, D >::getPhysPerimeter ( ) const

Returns the perimeter of the cuboid.

Definition at line 71 of file cuboid.hh.

71 {
72 return 2*_extent[1]*_delta + 2*_extent[0]*_delta;
73}

◆ getPhysPerimeter() [2/2]

template<typename T , unsigned D>
T olb::Cuboid< T, D >::getPhysPerimeter ( ) const

Returns the perimeter of the cuboid.

◆ getPhysR()

template<typename T , unsigned D>
Vector< T, D > olb::Cuboid< T, D >::getPhysR ( LatticeR< D > latticeR) const
inline

Definition at line 90 of file cuboid.h.

90 {
91 return _origin + latticeR*_delta;
92 }
+ Here is the caller graph for this function:

◆ getPhysVolume()

template<typename T , unsigned D>
T olb::Cuboid< T, D >::getPhysVolume ( ) const

Returns the volume of the cuboid.

Definition at line 53 of file cuboid.hh.

53 {
54 T physVolume = util::pow(_delta,D);
55 for (unsigned iD=0; iD < D; ++iD) {
56 physVolume *= _extent[iD];
57 }
58 return physVolume;
59}
Expr pow(Expr base, Expr exp)
Definition expr.cpp:235

References olb::util::pow().

+ Here is the call graph for this function:

◆ getWeight()

template<typename T , unsigned D>
std::size_t olb::Cuboid< T, D >::getWeight ( ) const
inline

Definition at line 87 of file cuboid.h.

87{ return _weight; }

◆ intersects() [1/2]

template<typename T , unsigned D>
bool olb::Cuboid< T, D >::intersects ( const Cuboid< T, D > & cuboid) const

Returns true iff self intersects cuboid.

Definition at line 153 of file cuboid.hh.

154{
155 return intersects(cuboid.getOrigin(),
156 cuboid.getOrigin() + cuboid.getDeltaR()*(cuboid.getExtent()-1),
157 0);
158}
bool intersects(Vector< T, D > globMin, Vector< T, D > globMax, int overlap=0) const
Checks whether there is an intersection with the cuboid extended by a layer of size overlap*delta.
Definition cuboid.hh:144

References olb::Cuboid< T, D >::getDeltaR(), olb::Cuboid< T, D >::getExtent(), and olb::Cuboid< T, D >::getOrigin().

+ Here is the call graph for this function:

◆ intersects() [2/2]

template<typename T , unsigned D>
bool olb::Cuboid< T, D >::intersects ( Vector< T, D > globMin,
Vector< T, D > globMax,
int overlap = 0 ) const

Checks whether there is an intersection with the cuboid extended by a layer of size overlap*delta.

Definition at line 144 of file cuboid.hh.

145{
146 auto loc0 = maxv(_origin-overlap*_delta, min);
147 auto loc1 = minv(_origin+(_extent+overlap-1)*_delta, max);
148 return loc1 >= loc0;
149
150}
constexpr Vector< T, D > minv(const ScalarVector< T, D, IMPL > &v, const ScalarVector< T, D, IMPL_ > &w)
Definition vector.h:448
constexpr Vector< T, D > maxv(const ScalarVector< T, D, IMPL > &v, const ScalarVector< T, D, IMPL_ > &w)
Definition vector.h:457

References olb::maxv(), and olb::minv().

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

◆ isInside()

template<typename T , unsigned D>
bool olb::Cuboid< T, D >::isInside ( Vector< T, D > pos,
int overlap = 0 ) const

Checks whether pos is contained in the cuboid extended with an layer of size overlap*delta.

Definition at line 137 of file cuboid.hh.

138{
139 return _origin <= pos + overlap*_delta + _delta / 2
140 && _origin + (_extent+overlap) * _delta > pos + _delta / 2;
141}

◆ operator=()

template<typename T , unsigned D>
Cuboid< T, D > & olb::Cuboid< T, D >::operator= ( const Cuboid< T, D > & rhs)

Definition at line 33 of file cuboid.hh.

33 {
34 _origin = rhs._origin;
35 _extent = rhs._extent;
36 _delta = rhs._delta;
37 _weight = rhs._weight;
38 return *this;
39}

◆ operator==()

template<typename T , unsigned D>
bool olb::Cuboid< T, D >::operator== ( const Cuboid< T, D > & rhs) const

Definition at line 129 of file cuboid.hh.

130{
131 return util::nearZero(_origin - rhs._origin)
132 && _extent == rhs._extent
133 && _weight == rhs._weight;
134}
bool nearZero(T a) any_platform
return true if a is close to zero
Definition util.h:402

◆ print()

template<typename T , unsigned D>
void olb::Cuboid< T, D >::print ( ) const

Definition at line 122 of file cuboid.hh.

123{
124 OstreamManager clout(std::cout, "cuboid");
125 write(clout);
126}
void write(std::ostream &cout) const
Definition cuboid.hh:106
+ Here is the caller graph for this function:

◆ refine()

template<typename T , unsigned D>
void olb::Cuboid< T, D >::refine ( int factor)

Definition at line 92 of file cuboid.hh.

92 {
93 if (factor < 1) {
94 throw std::invalid_argument("refinement factor must be >= 1");
95 } else if (factor == 2) {
96 _delta /= factor;
97 _extent *= factor;
98 _extent -= 1;
99 _weight *= util::pow(factor,D);
100 } else if (factor != 1) {
101 throw std::invalid_argument("TBD refinement factor must be == 2");
102 }
103}

References olb::util::pow().

+ Here is the call graph for this function:

◆ resize()

template<typename T , unsigned D>
void olb::Cuboid< T, D >::resize ( Vector< int, D > offset,
Vector< int, D > extent )

Definition at line 540 of file cuboid.hh.

540 {
541 _origin += offset*_delta;
542 _extent = extent;
543}

◆ setWeight()

template<typename T , unsigned D>
void olb::Cuboid< T, D >::setWeight ( std::size_t weight)
inline

Definition at line 88 of file cuboid.h.

88{ _weight = weight; }

◆ write()

template<typename T , unsigned D>
void olb::Cuboid< T, D >::write ( std::ostream & cout) const

Definition at line 106 of file cuboid.hh.

107{
108 cout << "--------Cuboid Details----------" << std::endl;
109 cout << " Corner: " << "\t" << _origin << std::endl;
110 cout << " Delta: " << "\t" << "\t" << getDeltaR() << std::endl;
111 cout << " Perimeter: " << "\t" << "\t" << getPhysPerimeter() << std::endl;
112 cout << " Volume: " << "\t" << "\t" << getPhysVolume() << std::endl;
113 cout << " Extent: " << "\t" << _extent << std::endl;
114 cout << " Nodes at Perimeter: " << "\t" << getLatticePerimeter() << std::endl;
115 cout << " Nodes in Volume: " << "\t" << getLatticeVolume() << std::endl;
116 cout << " Nodes in Indicator: " << "\t" << getWeight() << std::endl;
117 cout << " Other Corner: " << "\t"<< _origin + (_extent-0.5)*_delta << std::endl;
118 cout << "--------------------------------" << std::endl;
119}
T getPhysPerimeter() const
Returns the perimeter of the cuboid.
Definition cuboid.hh:71
T getDeltaR() const
Returns spacing of cuboid nodes.
Definition cuboid.h:76
std::size_t getWeight() const
Definition cuboid.h:87
T getPhysVolume() const
Returns the volume of the cuboid.
Definition cuboid.hh:53
std::size_t getLatticePerimeter() const
Returns the number of Nodes at the perimeter.
Definition cuboid.hh:82

◆ writeAsXML()

template<typename T , unsigned D>
void olb::Cuboid< T, D >::writeAsXML ( std::ostream & ss) const

Definition at line 577 of file cuboid.hh.

577 {
578 ss << " extent=\"";
579 for (int i = 0; i<3; i++) {
580 ss << getExtent()[i] << " ";
581 }
582
583 ss << "\" origin=\"";
584 for (int i = 0; i<3; i++) {
585 ss << getOrigin()[i] << " ";
586 }
587
588 ss << "\" deltaR=\"" << getDeltaR();
589 ss << "\" weight=\"" << getWeight();
590}

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