46 : _weight(std::numeric_limits<size_t>::max()), clout(std::cout,
"Cuboid2D")
48 init(globPosX, globPosY, delta, nX, nY);
53 : _weight(std::numeric_limits<size_t>::max()), clout(std::cout,
"Cuboid2D")
55 this->
init(origin[0], origin[1], delta, extend[0], extend[1]);
62 this->
init(rhs._globPosX - rhs._delta*overlap, rhs._globPosY - rhs._delta*overlap,
63 rhs._delta, rhs._nX + 2*overlap, rhs._nY + 2*overlap);
64 _weight = rhs._weight;
71 this->init(rhs._globPosX, rhs._globPosY, rhs._delta, rhs._nX, rhs._nY);
72 _weight = rhs._weight;
132 return _nY*_nX*_delta*_delta;
138 return static_cast<size_t>(_nY)*
static_cast<size_t>(_nX);
144 return 2*_nY*_delta + 2*_nX*_delta;
150 return 2*_nY + 2*_nX -4;
156 clout <<
"--------Cuboid Details----------" << std::endl;
157 clout <<
" Left Corner (x/y): " <<
"\t" <<
"(" << this->get_globPosX() <<
"/" << this->get_globPosY() <<
")" << std::endl;
158 clout <<
" Delta: " <<
"\t" <<
"\t" << this->getDeltaR() << std::endl;
159 clout <<
" Perimeter: " <<
"\t" <<
"\t" << this->getPhysPerimeter() << std::endl;
160 clout <<
" Volume: " <<
"\t" <<
"\t" << this->getPhysVolume() << std::endl;
161 clout <<
" Extent (x/y): " <<
"\t" <<
"\t" <<
"(" << this->getNx() <<
"/" << this->getNy() <<
")" << std::endl;
162 clout <<
" Nodes at Perimeter: " <<
"\t" << this->getLatticePerimeter() << std::endl;
163 clout <<
" Nodes in Volume: " <<
"\t" << this->getLatticeVolume() << std::endl;
164 clout <<
"--------------------------------" << std::endl;
170 physR[0] = _globPosX + latticeR[0]*_delta;
171 physR[1] = _globPosY + latticeR[1]*_delta;
177 physR[0] = _globPosX + iX*_delta;
178 physR[1] = _globPosY + iY*_delta;
184 physR[0] = _globPosX + latticeR[0]*_delta;
185 physR[1] = _globPosY + latticeR[1]*_delta;
191 latticeR[0] = (int)
util::floor( (physR[0] - _globPosX )/_delta +.5);
192 latticeR[1] = (int)
util::floor( (physR[1] - _globPosY )/_delta +.5);
198 latticeR[0] = (int)
util::floor( (physR[0] - _globPosX )/_delta +.5);
199 latticeR[1] = (int)
util::floor( (physR[1] - _globPosY )/_delta +.5);
206 if (_globPosX <= globX + T(0.5 + overlap)*_delta &&
207 _globPosX + T(_nX+overlap)*_delta > globX + 0.5*_delta &&
208 _globPosY <= globY + T(0.5 + overlap)*_delta &&
209 _globPosY + T(_nY+overlap)*_delta > globY + 0.5*_delta ) {
220 return checkPoint(globXY[0], globXY[1], overlap);
227 Cuboid2D tmp(_globPosX - overlap*_delta, _globPosY - overlap*_delta, _delta, _nX + overlap*2, _nY + overlap*2);
228 return tmp.
checkPoint(globX, globY, locX, locY);
230 else if (!checkPoint(globX, globY)) {
234 locX = (int)
util::floor((globX - (T)_globPosX)/_delta + .5);
235 locY = (int)
util::floor((globY - (T)_globPosY)/_delta + .5);
244 T locX0d =
util::max(_globPosX-overlap*_delta,globX0);
245 T locY0d =
util::max(_globPosY-overlap*_delta,globY0);
246 T locX1d =
util::min(_globPosX+(_nX+overlap-1)*_delta,globX1);
247 T locY1d =
util::min(_globPosY+(_nY+overlap-1)*_delta,globY1);
249 if (!(locX1d>=locX0d && locY1d>=locY0d)) {
258 return checkInters(globX, globX, globY, globY, overlap);
263 int &locX0,
int &locX1,
int &locY0,
int &locY1,
int overlap)
const
266 Cuboid2D tmp(_globPosX - overlap*_delta, _globPosY - overlap*_delta, _delta, _nX + overlap*2, _nY + overlap*2);
267 return tmp.
checkInters(globX0, globX1, globY0, globY1, locX0, locX1, locY0, locY1);
269 else if (!checkInters(globX0, globX1, globY0, globY1)) {
278 for (
int i=0; _globPosX + i*_delta < globX0; i++) {
282 for (
int i=_nX-1; _globPosX + i*_delta > globX1; i--) {
286 for (
int i=0; _globPosY + i*_delta < globY0; i++) {
290 for (
int i=_nY-1; _globPosY + i*_delta > globY1; i--) {
300 T globPosX_child, globPosY_child;
304 globPosX_child = _globPosX;
305 globPosY_child = _globPosY;
307 for (
int iX=0; iX<nX; iX++) {
308 for (
int iY=0; iY<nY; iY++) {
309 xN_child = (_nX+nX-iX-1)/nX;
310 yN_child = (_nY+nY-iY-1)/nY;
311 Cuboid2D<T> child(globPosX_child, globPosY_child, _delta, xN_child, yN_child);
312 childrenC.push_back(child);
313 globPosY_child += yN_child*_delta;
315 globPosY_child = _globPosY;
316 globPosX_child += xN_child*_delta;
328 T bestRatio = (T)_nX/(T)_nY;
330 for (
int i=1; i<= p; i++) {
333 if (
util::fabs(bestRatio - (T)i/(T)j) <= difRatio) {
342 int rest = p - nX*nY;
345 divide(nX,nY,childrenC);
349 if (ratio < bestRatio && (nY-rest) >= 0) {
350 int n_QNoInsertions = nX*(nY-rest);
351 T bestVolume_QNoInsertions = (T)_nX*_nY * n_QNoInsertions/(T)p;
352 int yN_QNoInsertions = (int)(bestVolume_QNoInsertions / (T)_nX);
353 int xN_QNoInsertions = _nX;
354 int yN_QInsertions = _nY-yN_QNoInsertions;
355 int xN_QInsertions = _nX;
356 Cuboid2D<T> firstChildQ(_globPosX, _globPosY, _delta, xN_QNoInsertions, yN_QNoInsertions);
357 Cuboid2D<T> secondChildQ(_globPosX, _globPosY+yN_QNoInsertions*_delta, _delta, xN_QInsertions, yN_QInsertions);
358 firstChildQ.
divide(nX, nY-rest, childrenC);
359 secondChildQ.
divide(nX+1,rest, childrenC);
362 int n_QNoInsertions = nY*(nX-rest);
363 T bestVolume_QNoInsertions = (T)_nX*_nY * n_QNoInsertions/(T)p;
364 int xN_QNoInsertions = (int)(bestVolume_QNoInsertions / (T)_nY + 0.9999);
365 int yN_QNoInsertions = _nY;
366 int xN_QInsertions = _nX-xN_QNoInsertions;
367 int yN_QInsertions = _nY;
368 Cuboid2D<T> firstChildQ(_globPosX, _globPosY, _delta, xN_QNoInsertions, yN_QNoInsertions);
369 Cuboid2D<T> secondChildQ(_globPosX+xN_QNoInsertions*_delta, _globPosY, _delta, xN_QInsertions, yN_QInsertions);
370 firstChildQ.
divide(nX-rest, nY, childrenC);
371 secondChildQ.
divide(rest,nY+1, childrenC);
379 _globPosX = _globPosX+iX*_delta;
380 _globPosY = _globPosY+iY*_delta;
388 if (_weight == std::numeric_limits<size_t>::max()) {
389 return getLatticeVolume();
A regular single 2D cuboid is the basic component of a 2D cuboid structure which defines the grid.
size_t getLatticeVolume() const
Returns the number of Nodes in the volume.
void print() const
Prints cuboid details.
T getPhysVolume() const
Returns the volume of the cuboid.
int getLatticePerimeter() const
Returns the number of Nodes at the perimeter.
Cuboid2D(T globPosX, T globPosY, T delta, int nX, int nY)
Construction of a cuboid.
void setWeight(size_t fullCells)
Sets the number of full cells.
void getLatticeR(int latticeR[2], const T physR[2]) const
bool checkInters(T globX0, T globX1, T globY0, T globY1, int overlap=0) const
Checks whether there is an intersection with the cuboid extended with an layer of size overlap*delta.
size_t getWeight() const
Returns the number of full cells.
void divide(int p, int q, std::vector< Cuboid2D< T > > &childrenC) const
Divides the cuboid in p*q cuboids and adds them to the given vector.
Vector< int, 2 > const getExtent() const
Read only access to the number of voxels in every dimension.
T getDeltaR() const
Read access to the distance of cuboid nodes.
bool checkPoint(T globX, T globY, int overlap=0) const
Checks whether a point (globX/globY) is contained in the cuboid extended with an layer of size overla...
void resize(int X, int Y, int nX, int nY)
resize the cuboid to the passed size
void getPhysR(T physR[2], const int latticeR[2]) const
Vector< T, 2 > const getOrigin() const
Read only access to left lower corner coordinates.
int getNx() const
Read access to cuboid width.
int getNy() const
Read access to cuboid height.
T get_globPosX() const
Read access to left lower corner coordinates.
T getPhysPerimeter() const
Returns the perimeter of the cuboid.
Cuboid2D & operator=(Cuboid2D const &rhs)
Copy assignment.
void init(T globPosX, T globPosY, T delta, int nX, int nY)
Initializes the cuboid.
The description of a single 2D cuboid – header file.
ADf< T, DIM > floor(const ADf< T, DIM > &a)
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
cpu::simd::Pack< T > fabs(cpu::simd::Pack< T > value)
Top level namespace for all of OpenLB.
#define OLB_PRECONDITION(COND)