OpenLB 1.7
Loading...
Searching...
No Matches
cuboid3D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2007, 2014 Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
29#ifndef CUBOID_3D_HH
30#define CUBOID_3D_HH
31
32
33#include <vector>
35#include "cuboid3D.h"
36#include "dynamics/lbm.h"
38
39
40namespace olb {
41
43
44/*template<typename T>
45Cuboid3D<T>::Cuboid3D() : clout(std::cout,"Cuboid3D") {
46 _weight = -1;
47}*/
48
49template<typename T>
50Cuboid3D<T>::Cuboid3D() : Cuboid3D<T>(0, 0, 0, 0, 0, 0, 0)
51{
52}
53
54template<typename T>
55Cuboid3D<T>::Cuboid3D(T globPosX, T globPosY, T globPosZ, T delta, int nX, int nY,
56 int nZ)
57 : _weight(std::numeric_limits<size_t>::max()), clout(std::cout,"Cuboid3D")
58{
59 init(globPosX, globPosY, globPosZ, delta, nX, nY, nZ);
60}
61
62template<typename T>
63Cuboid3D<T>::Cuboid3D(std::vector<T> origin, T delta, std::vector<int> extend)
64 : clout(std::cout,"Cuboid3D")
65{
66 _weight = std::numeric_limits<size_t>::max();
67 init(origin[0], origin[1], origin[2], delta, extend[0], extend[1], extend[2]);
68}
69
70template<typename T>
72 : clout(std::cout,"Cuboid3D")
73{
74 _weight = std::numeric_limits<size_t>::max();
75 init(origin[0], origin[1], origin[2], delta, extend[0], extend[1], extend[2]);
76}
78template<typename T>
79Cuboid3D<T>::Cuboid3D(IndicatorF3D<T>& indicatorF, T voxelSize)
80 : clout(std::cout,"Cuboid3D")
82 _weight = std::numeric_limits<size_t>::max();
83 init(indicatorF.getMin()[0], indicatorF.getMin()[1], indicatorF.getMin()[2], voxelSize,
84 (int)((indicatorF.getMax()[0]-indicatorF.getMin()[0])/voxelSize+1.5),
85 (int)((indicatorF.getMax()[1]-indicatorF.getMin()[1])/voxelSize+1.5),
86 (int)((indicatorF.getMax()[2]-indicatorF.getMin()[2])/voxelSize+1.5));
87}
89// copy constructor
90template<typename T>
91Cuboid3D<T>::Cuboid3D(Cuboid3D<T> const& rhs, int overlap) : clout(std::cout,"Cuboid3D")
92{
93 init( rhs._globPosX-rhs._delta*overlap, rhs._globPosY-rhs._delta*overlap,
94 rhs._globPosZ-rhs._delta*overlap, rhs._delta, rhs._nX+2*overlap,
95 rhs._nY+2*overlap, rhs._nZ+2*overlap);
96 _weight = rhs._weight;
98
100// copy assignment
101template<typename T>
104 init( rhs._globPosX, rhs._globPosY, rhs._globPosZ, rhs._delta, rhs._nX,
105 rhs._nY, rhs._nZ);
106 _weight = rhs._weight;
107 return *this;
108}
110template<typename T>
111void Cuboid3D<T>::init(T globPosX, T globPosY, T globPosZ, T delta, int nX, int nY, int nZ)
112{
113 _globPosX = globPosX;
114 _globPosY = globPosY;
115 _globPosZ = globPosZ;
116 _delta = delta;
117 _nX = nX;
118 _nY = nY;
119 _nZ = nZ;
120}
122template<typename T>
123std::size_t Cuboid3D<T>::getNblock() const
124{
125 return 9;
127
128template<typename T>
130{
131 return ( 4 * sizeof(T) ) + ( 5 * sizeof(int) );
132}
133
134template<typename T>
136{
137 return Vector<T,3> (_globPosX, _globPosY, _globPosZ);
138}
139
140template<typename T>
142{
143 return _delta;
145
146template<typename T>
148{
149 return _nX;
150}
152template<typename T>
155 return _nY;
158template<typename T>
161 return _nZ;
162}
164template<typename T>
166{
167 return Vector<int,3> (_nX, _nY, _nZ);
170template<typename T>
172{
173 return _nY*_nX*_nZ*_delta*_delta*_delta;
174}
175
176template<typename T>
178{
179 return _weight;
180}
181
182template<typename T>
184{
185 if (_weight == std::numeric_limits<size_t>::max()) {
186 return getLatticeVolume();
188 else {
189 return _weight;
190 }
192
193template<typename T>
194std::size_t Cuboid3D<T>::getWeightIn(IndicatorF3D<T>& indicatorF) const
196 std::size_t weight = 0;
197 T physR[3] { };
198 int latticeR[3] { };
199 for (latticeR[0] = 0; latticeR[0] < getNx(); ++latticeR[0]) {
200 for (latticeR[1] = 0; latticeR[1] < getNy(); ++latticeR[1]) {
201 for (latticeR[2] = 0; latticeR[2] < getNz(); ++latticeR[2]) {
202 getPhysR(physR, latticeR);
203 bool inside;
204 indicatorF(&inside, physR);
205 if (inside) {
206 weight += 1;
207 }
208 }
209 }
210 }
211 return weight;
212}
213
214template<typename T>
215void Cuboid3D<T>::setWeight(size_t fullCells)
216{
217 _weight = fullCells;
218}
219
220template<typename T>
222{
223 return static_cast<size_t>(_nY)*static_cast<size_t>(_nX)*static_cast<size_t>(_nZ);
224}
225
226template<typename T>
228{
229 return 2*_delta*_delta*(_nX*_nY + _nY*_nZ + _nZ*_nX);
230}
231
232template<typename T>
234{
235 return 2*((_nX-1)*(_nY-1) + (_nY-1)*(_nZ-1) + (_nZ-1)*(_nX-1));
236}
237
238template<typename T>
239void Cuboid3D<T>::refine(int factor) {
240 if (factor < 1) {
241 throw std::invalid_argument("refinement factor must be >= 1");
242 } else if (factor > 1) {
243 _delta /= factor;
244 _nX *= factor;
245 _nY *= factor;
246 _nZ *= factor;
247 _weight *= factor*factor*factor;
248 }
249}
250
251template<typename T>
253{
254 return util::nearZero<T>(_globPosX - rhs._globPosX) &&
255 util::nearZero<T>(_globPosY - rhs._globPosY) &&
256 util::nearZero<T>(_globPosZ - rhs._globPosZ) &&
257 util::nearZero<T>(_delta - rhs._delta) &&
258 _nX == rhs._nX &&
259 _nY == rhs._nY &&
260 _nZ == rhs._nZ &&
261 _weight == rhs._weight;
262}
263
264
265template<typename T>
266bool* Cuboid3D<T>::getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode)
267{
268 std::size_t currentBlock = 0;
269 bool* dataPtr = nullptr;
270
271 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _globPosX);
272 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _globPosY);
273 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _globPosZ);
274 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _delta);
275 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _nX);
276 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _nY);
277 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _nZ);
278 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _weight);
279
280 return dataPtr;
281}
282
283template<typename T>
285{
286 clout << "--------Cuboid Details----------" << std::endl;
287 clout << " Corner (x/y/z): " << "\t" << "("
288 << _globPosX-_delta/2. << "/" << _globPosY - _delta/2.
289 << "/" << _globPosZ - _delta/2. << ")" << std::endl;
290 clout << " Delta: " << "\t" << "\t" << getDeltaR() << std::endl;
291 clout << " Perimeter: " << "\t" << "\t" << getPhysPerimeter() << std::endl;
292 clout << " Volume: " << "\t" << "\t" << getPhysVolume() << std::endl;
293 clout << " Extent (x/y/z): " << "\t" << "("
294 << getNx() << "/" << getNy() << "/"
295 << getNz() << ")" << std::endl;
296 clout << " Nodes at Perimeter: " << "\t" << getLatticePerimeter() << std::endl;
297 clout << " Nodes in Volume: " << "\t" << getLatticeVolume() << std::endl;
298 clout << " Nodes in Indicator: " << "\t" << getWeight() << std::endl;
299 clout << " Other Corner: " << "\t"<< "(" << _globPosX + T(_nX-0.5)*_delta << "/"
300 << _globPosY + T(_nY-0.5)*_delta << "/"
301 << _globPosZ + T(_nZ-0.5)*_delta << ")" << std::endl;
302 clout << "--------------------------------" << std::endl;
303
304}
305
306template<typename T>
307void Cuboid3D<T>::getPhysR(T physR[3], const int latticeR[3]) const
308{
309 physR[0] = _globPosX + latticeR[0]*_delta;
310 physR[1] = _globPosY + latticeR[1]*_delta;
311 physR[2] = _globPosZ + latticeR[2]*_delta;
312}
313
314template<typename T>
315void Cuboid3D<T>::getPhysR(T physR[3], LatticeR<3> latticeR) const
316{
317 physR[0] = _globPosX + latticeR[0]*_delta;
318 physR[1] = _globPosY + latticeR[1]*_delta;
319 physR[2] = _globPosZ + latticeR[2]*_delta;
320}
321
322template<typename T>
323void Cuboid3D<T>::getPhysR(T physR[3], const int& iX, const int& iY, const int& iZ) const
324{
325 physR[0] = _globPosX + iX*_delta;
326 physR[1] = _globPosY + iY*_delta;
327 physR[2] = _globPosZ + iZ*_delta;
328}
329
330template<typename T>
331void Cuboid3D<T>::getLatticeR(int latticeR[3], const T physR[3]) const
332{
333 latticeR[0] = (int)util::floor( (physR[0] - _globPosX )/_delta +.5);
334 latticeR[1] = (int)util::floor( (physR[1] - _globPosY )/_delta +.5);
335 latticeR[2] = (int)util::floor( (physR[2] - _globPosZ )/_delta +.5);
336}
337
338template<typename T>
339void Cuboid3D<T>::getLatticeR(int latticeR[3], const Vector<T,3>& physR) const
340{
341 latticeR[0] = (int)util::floor( (physR[0] - _globPosX )/_delta +.5);
342 latticeR[1] = (int)util::floor( (physR[1] - _globPosY )/_delta +.5);
343 latticeR[2] = (int)util::floor( (physR[2] - _globPosZ )/_delta +.5);
344}
345
346template<typename T>
347void Cuboid3D<T>::getFloorLatticeR(const std::vector<T>& physR, std::vector<int>& latticeR) const
348{
349 getFloorLatticeR(&latticeR[0], &physR[0]);
350}
351
352template<typename T>
353void Cuboid3D<T>::getFloorLatticeR(int latticeR[3], const T physR[3]) const
354{
355 latticeR[0] = (int)util::floor( (physR[0] - _globPosX)/_delta);
356 latticeR[1] = (int)util::floor( (physR[1] - _globPosY)/_delta);
357 latticeR[2] = (int)util::floor( (physR[2] - _globPosZ)/_delta);
358}
359
360template<typename T>
361bool Cuboid3D<T>::checkPoint(T globX, T globY, T globZ, int overlap) const
362{
363 return _globPosX <= globX + overlap * _delta + _delta / 2. &&
364 _globPosX + T(_nX+overlap) * _delta > globX + _delta / 2. &&
365 _globPosY <= globY + overlap * _delta + _delta/2. &&
366 _globPosY + T(_nY+overlap) * _delta > globY + _delta / 2. &&
367 _globPosZ <= globZ + overlap * _delta + _delta/2. &&
368 _globPosZ + T(_nZ+overlap) * _delta > globZ + _delta / 2.;
369}
370
371template<typename T>
372bool Cuboid3D<T>::checkPoint(Vector<T,3>& globXYZ, int overlap) const
373{
374 return checkPoint(globXYZ[0], globXYZ[1], globXYZ[2], overlap);
375}
376
377template<typename T>
378bool Cuboid3D<T>::physCheckPoint(T globX, T globY, T globZ, double overlap) const
379{
380 return _globPosX <= globX + T(0.5 + overlap) * _delta &&
381 _globPosX + T(_nX+overlap)*_delta > globX + _delta / 2. &&
382 _globPosY <= globY + T(0.5 + overlap)*_delta &&
383 _globPosY + T(_nY+overlap)*_delta > globY + _delta / 2. &&
384 _globPosZ <= globZ + T(0.5 + overlap)*_delta &&
385 _globPosZ + T(_nZ+overlap)*_delta > globZ + _delta / 2.;
386}
387
388template<typename T>
389bool Cuboid3D<T>::checkPoint(T globX, T globY, T globZ, int &locX, int &locY,
390 int &locZ, int overlap) const
391{
392 if (overlap!=0) {
393 Cuboid3D tmp(_globPosX - overlap*_delta, _globPosY - overlap*_delta, _globPosZ - overlap*_delta,
394 _delta, _nX + overlap*2, _nY + overlap*2, _nZ + overlap*2);
395 return tmp.checkPoint(globX, globY, globZ, locX, locY, locZ);
396 }
397 else if (!checkPoint(globX, globY, globZ)) {
398 return false;
399 }
400 else {
401 locX = (int)util::floor((globX - (T)_globPosX)/_delta + .5);
402 locY = (int)util::floor((globY - (T)_globPosY)/_delta + .5);
403 locZ = (int)util::floor((globZ - (T)_globPosZ)/_delta + .5);
404 return true;
405 }
406}
407
408template<typename T>
409bool Cuboid3D<T>::checkInters(T globX0, T globX1, T globY0, T globY1, T globZ0,
410 T globZ1, int overlap) const
411{
412 T locX0d = util::max(_globPosX-overlap*_delta,globX0);
413 T locY0d = util::max(_globPosY-overlap*_delta,globY0);
414 T locZ0d = util::max(_globPosZ-overlap*_delta,globZ0);
415 T locX1d = util::min(_globPosX+(_nX+overlap-1)*_delta,globX1);
416 T locY1d = util::min(_globPosY+(_nY+overlap-1)*_delta,globY1);
417 T locZ1d = util::min(_globPosZ+(_nZ+overlap-1)*_delta,globZ1);
418
419 return locX1d >= locX0d
420 && locY1d >= locY0d
421 && locZ1d >= locZ0d;
422}
423
424template<typename T>
425bool Cuboid3D<T>::checkInters(T globX, T globY, T globZ, int overlap) const
426{
427 return checkInters(globX, globX, globY, globY, globZ, globZ, overlap);
428}
429
430template <typename T>
432{
433 return checkInters(child.getOrigin()[0], child.getOrigin()[0] + child.getDeltaR()*(child.getExtent()[0]-1),
434 child.getOrigin()[1], child.getOrigin()[1] + child.getDeltaR()*(child.getExtent()[1]-1),
435 child.getOrigin()[2], child.getOrigin()[2] + child.getDeltaR()*(child.getExtent()[2]-1),
436 0);
437}
438
439template<typename T>
440bool Cuboid3D<T>::checkInters(T globX0, T globX1, T globY0, T globY1, T globZ0, T globZ1,
441 int &locX0, int &locX1, int &locY0, int &locY1, int &locZ0, int &locZ1, int overlap) const
442{
443 if (overlap!=0) {
444 Cuboid3D tmp(_globPosX - overlap*_delta, _globPosY - overlap*_delta, _globPosZ - overlap*_delta,
445 _delta, _nX + overlap*2, _nY + overlap*2, _nZ + overlap*2);
446 return tmp.checkInters(globX0, globX1, globY0, globY1, globZ0, globZ1,
447 locX0, locX1, locY0, locY1, locZ0, locZ1);
448 }
449 else if (!checkInters(globX0, globX1, globY0, globY1, globZ0, globZ1)) {
450 locX0 = 1;
451 locX1 = 0;
452 locY0 = 1;
453 locY1 = 0;
454 locZ0 = 1;
455 locZ1 = 0;
456 return false;
457 }
458 else {
459 locX0 = 0;
460 for (int i=0; _globPosX + i*_delta < globX0; i++) {
461 locX0 = i+1;
462 }
463 locX1 = _nX-1;
464 for (int i=_nX-1; _globPosX + i*_delta > globX1; i--) {
465 locX1 = i-1;
466 }
467 locY0 = 0;
468 for (int i=0; _globPosY + i*_delta < globY0; i++) {
469 locY0 = i+1;
470 }
471 locY1 = _nY-1;
472 for (int i=_nY-1; _globPosY + i*_delta > globY1; i--) {
473 locY1 = i-1;
474 }
475 locZ0 = 0;
476 for (int i=0; _globPosZ + i*_delta < globZ0; i++) {
477 locZ0 = i+1;
478 }
479 locZ1 = _nZ-1;
480 for (int i=_nZ-1; _globPosZ + i*_delta > globZ1; i--) {
481 locZ1 = i-1;
482 }
483 return true;
484 }
485}
486
487template<typename T>
488void Cuboid3D<T>::divide(int nX, int nY, int nZ, std::vector<Cuboid3D<T> > &childrenC) const
489{
490 int xN_child = 0;
491 int yN_child = 0;
492 int zN_child = 0;
493
494 T globPosX_child = _globPosX;
495 T globPosY_child = _globPosY;
496 T globPosZ_child = _globPosZ;
497
498 for (int iX=0; iX<nX; iX++) {
499 for (int iY=0; iY<nY; iY++) {
500 for (int iZ=0; iZ<nZ; iZ++) {
501 xN_child = (_nX+nX-iX-1)/nX;
502 yN_child = (_nY+nY-iY-1)/nY;
503 zN_child = (_nZ+nZ-iZ-1)/nZ;
504 Cuboid3D<T> child(globPosX_child, globPosY_child, globPosZ_child,
505 _delta, xN_child, yN_child, zN_child);
506 childrenC.push_back(child);
507 globPosZ_child += zN_child*_delta;
508 }
509 globPosZ_child = _globPosZ;
510 globPosY_child += yN_child*_delta;
511 }
512 globPosY_child = _globPosY;
513 globPosX_child += xN_child*_delta;
514 }
515}
516
517template<typename T>
518void Cuboid3D<T>::resize(int iX, int iY, int iZ, int nX, int nY, int nZ)
519{
520 _globPosX = _globPosX+iX*_delta;
521 _globPosY = _globPosY+iY*_delta;
522 _globPosZ = _globPosZ+iZ*_delta;
523
524 _nX = nX;
525 _nY = nY;
526 _nZ = nZ;
527}
528
529template<typename T>
530void Cuboid3D<T>::divideFractional(int iD, std::vector<T> fractions, std::vector<Cuboid3D<T>>& childrenC) const
531{
532 auto delta = Vector<T,3>([&](int i) -> T {
533 return i == iD ? _delta : 0;
534 });
535 auto base = Vector<int,3>([&](int i) -> T {
536 return i == iD ? 1 : 0;
537 });
538
539 std::vector<int> fractionWidths;
540 int totalWidth = 0;
541 for (T f : fractions) {
542 fractionWidths.emplace_back(f * (getExtent()*base));
543 totalWidth += fractionWidths.back();
544 }
545 fractionWidths.back() += getExtent()*base - totalWidth;
546
547 auto origin = getOrigin();
548 auto extent = Vector<int,3>([&](int i) -> T {
549 return i == iD ? 0 : getExtent()[i];
550 });
551
552 for (int width : fractionWidths) {
553 Cuboid3D<T> child(origin, _delta, extent + (width)*base);
554 child.print();
555 origin += width*delta;
556 childrenC.push_back(child);
557 }
558}
559
560template<typename T>
561void Cuboid3D<T>::divide(int p, std::vector<Cuboid3D<T> > &childrenC) const
562{
563
564 OLB_PRECONDITION(p>0);
565
566 int iXX = 1;
567 int iYY = 1;
568 int iZZ = p;
569 int nX = _nX/iXX;
570 int bestIx = iXX;
571 int nY = _nY/iYY;
572 int bestIy = iYY;
573 int nZ = _nZ/iZZ;
574 int bestIz = iZZ;
575 T bestRatio = ((T)(_nX/iXX)/(T)(_nY/iYY)-1)*((T)(_nX/iXX)/(T)(_nY/iYY)-1)
576 + ((T)(_nY/iYY)/(T)(_nZ/iZZ)-1)*((T)(_nY/iYY)/(T)(_nZ/iZZ)-1)
577 + ((T)(_nZ/iZZ)/(T)(_nX/iXX)-1)*((T)(_nZ/iZZ)/(T)(_nX/iXX)-1);
578
579 for (int iX=1; iX<=p; iX++) {
580 for (int iY=1; iY*iX<=p; iY++) {
581 for (int iZ=p/(iX*iY); iZ*iY*iX<=p; iZ++) {
582 if ((iX+1)*iY*iZ>p && iX*(iY+1)*iZ>p ) {
583 T ratio = ((T)(_nX/iX)/(T)(_nY/iY)-1)*((T)(_nX/iX)/(T)(_nY/iY)-1)
584 + ((T)(_nY/iY)/(T)(_nZ/iZ)-1)*((T)(_nY/iY)/(T)(_nZ/iZ)-1)
585 + ((T)(_nZ/iZ)/(T)(_nX/iX)-1)*((T)(_nZ/iZ)/(T)(_nX/iX)-1);
586 if (ratio<bestRatio) {
587 bestRatio = ratio;
588 bestIx = iX;
589 bestIy = iY;
590 bestIz = iZ;
591 nX = _nX/iX;
592 nY = _nY/iY;
593 nZ = _nZ/iZ;
594 }
595 }
596 }
597 }
598 }
599
600 int rest = p - bestIx*bestIy*bestIz;
601
602 // split in one cuboid
603 if (rest==0) {
604 divide(bestIx, bestIy, bestIz, childrenC);
605 return;
606 }
607 else {
608
609 // add in z than in y direction
610 if (nZ>nY && nZ>nX) {
611
612 int restY = rest%bestIy;
613 // split in two cuboid
614 if (restY==0) {
615 int restX = rest/bestIy;
616 CuboidGeometry2D<T> helpG(_globPosX, _globPosZ, _delta, _nX, _nZ, bestIx*bestIz+restX);
617
618 int yN_child = 0;
619 T globPosY_child = _globPosY;
620
621 for (int iY=0; iY<bestIy; iY++) {
622 yN_child = (_nY+bestIy-iY-1)/bestIy;
623 for (int iC=0; iC<helpG.getNc(); iC++) {
624 int xN_child = helpG.get(iC).getNx();
625 int zN_child = helpG.get(iC).getNy();
626 T globPosX_child = helpG.get(iC).get_globPosX();
627 T globPosZ_child = helpG.get(iC).get_globPosY();
628
629 Cuboid3D<T> child(globPosX_child, globPosY_child, globPosZ_child,
630 _delta, xN_child, yN_child, zN_child);
631 childrenC.push_back(child);
632
633 }
634 globPosY_child += yN_child*_delta;
635 }
636 return;
637 }
638
639 // split in four cuboid
640
641 int restX = rest/bestIy+1;
642 int yN_child = 0;
643 T globPosY_child = _globPosY;
644 int splited_nY = (int) (_nY * (T)((bestIx*bestIz+restX)*restY)/(T)p);
645 CuboidGeometry2D<T> helpG0(_globPosX, _globPosZ, _delta, _nX, _nZ, bestIx*bestIz+restX);
646
647 for (int iY=0; iY<restY; iY++) {
648 yN_child = (splited_nY+restY-iY-1)/restY;
649 for (int iC=0; iC<helpG0.getNc(); iC++) {
650 int xN_child = helpG0.get(iC).getNx();
651 int zN_child = helpG0.get(iC).getNy();
652 T globPosX_child = helpG0.get(iC).get_globPosX();
653 T globPosZ_child = helpG0.get(iC).get_globPosY();
654
655 Cuboid3D<T> child(globPosX_child, globPosY_child, globPosZ_child,
656 _delta, xN_child, yN_child, zN_child);
657 childrenC.push_back(child);
658 }
659 globPosY_child += yN_child*_delta;
660 }
661
662 splited_nY = _nY - splited_nY;
663 restX = rest/bestIy;
664 CuboidGeometry2D<T> helpG1(_globPosX, _globPosZ, _delta, _nX, _nZ, bestIx*bestIz+restX);
665 yN_child = 0;
666
667 for (int iY=0; iY<bestIy-restY; iY++) {
668 yN_child = (splited_nY+bestIy-restY-iY-1)/(bestIy-restY);
669 for (int iC=0; iC<helpG1.getNc(); iC++) {
670 int xN_child = helpG1.get(iC).getNx();
671 int zN_child = helpG1.get(iC).getNy();
672 T globPosX_child = helpG1.get(iC).get_globPosX();
673 T globPosZ_child = helpG1.get(iC).get_globPosY();
674
675 Cuboid3D<T> child(globPosX_child, globPosY_child, globPosZ_child,
676 _delta, xN_child, yN_child, zN_child);
677 childrenC.push_back(child);
678 }
679 globPosY_child += yN_child*_delta;
680 }
681 return;
682 }
683
684 // add in x than in y direction
685 else if (nX>nY && nX>nZ) {
686 int restY = rest%bestIy;
687 // split in two cuboid
688 if (restY==0) {
689 int restZ = rest/bestIy;
690 CuboidGeometry2D<T> helpG(_globPosX, _globPosZ, _delta, _nX, _nZ, bestIx*bestIz+restZ);
691
692 int yN_child = 0;
693 T globPosY_child = _globPosY;
694
695 for (int iY=0; iY<bestIy; iY++) {
696 yN_child = (_nY+bestIy-iY-1)/bestIy;
697 for (int iC=0; iC<helpG.getNc(); iC++) {
698 int xN_child = helpG.get(iC).getNx();
699 int zN_child = helpG.get(iC).getNy();
700 T globPosX_child = helpG.get(iC).get_globPosX();
701 T globPosZ_child = helpG.get(iC).get_globPosY();
702
703 Cuboid3D<T> child(globPosX_child, globPosY_child, globPosZ_child,
704 _delta, xN_child, yN_child, zN_child);
705 childrenC.push_back(child);
706
707 }
708 globPosY_child += yN_child*_delta;
709 }
710 return;
711 }
712
713 // split in four cuboid
714
715 int restZ = rest/bestIy+1;
716
717 int yN_child = 0;
718 T globPosY_child = _globPosY;
719 int splited_nY = (int) (_nY * (T)((bestIx*bestIz+restZ)*restY)/(T)p);
720 CuboidGeometry2D<T> helpG0(_globPosX, _globPosZ, _delta, _nX, _nZ, bestIx*bestIz+restZ);
721
722 for (int iY=0; iY<restY; iY++) {
723 yN_child = (splited_nY+restY-iY-1)/restY;
724 for (int iC=0; iC<helpG0.getNc(); iC++) {
725 int xN_child = helpG0.get(iC).getNx();
726 int zN_child = helpG0.get(iC).getNy();
727 T globPosX_child = helpG0.get(iC).get_globPosX();
728 T globPosZ_child = helpG0.get(iC).get_globPosY();
729
730 Cuboid3D<T> child(globPosX_child, globPosY_child, globPosZ_child,
731 _delta, xN_child, yN_child, zN_child);
732 childrenC.push_back(child);
733 }
734 globPosY_child += yN_child*_delta;
735 }
736
737 splited_nY = _nY - splited_nY;
738 restZ = rest/bestIy;
739
740 CuboidGeometry2D<T> helpG1(_globPosX, _globPosZ, _delta, _nX, _nZ, bestIx*bestIz+restZ);
741 yN_child = 0;
742
743 for (int iY=0; iY<bestIy-restY; iY++) {
744 yN_child = (splited_nY+bestIy-restY-iY-1)/(bestIy-restY);
745 for (int iC=0; iC<helpG1.getNc(); iC++) {
746 int xN_child = helpG1.get(iC).getNx();
747 int zN_child = helpG1.get(iC).getNy();
748 T globPosX_child = helpG1.get(iC).get_globPosX();
749 T globPosZ_child = helpG1.get(iC).get_globPosY();
750
751 Cuboid3D<T> child(globPosX_child, globPosY_child, globPosZ_child,
752 _delta, xN_child, yN_child, zN_child);
753 childrenC.push_back(child);
754 }
755 globPosY_child += yN_child*_delta;
756 }
757 return;
758 }
759
760 // add in y than in x direction
761 else {
762 int restX = rest%bestIx;
763 // split in two cuboid
764 if (restX==0) {
765 int restZ = rest/bestIx;
766 CuboidGeometry2D<T> helpG(_globPosZ, _globPosY, _delta, _nZ, _nY, bestIz*bestIy+restZ);
767
768
769 int xN_child = 0;
770 T globPosX_child = _globPosX;
771
772 for (int iX=0; iX<bestIx; iX++) {
773 xN_child = (_nX+bestIx-iX-1)/bestIx;
774 for (int iC=0; iC<helpG.getNc(); iC++) {
775 int zN_child = helpG.get(iC).getNx();
776 int yN_child = helpG.get(iC).getNy();
777 T globPosZ_child = helpG.get(iC).get_globPosX();
778 T globPosY_child = helpG.get(iC).get_globPosY();
779
780 Cuboid3D<T> child(globPosX_child, globPosY_child, globPosZ_child,
781 _delta, xN_child, yN_child, zN_child);
782 childrenC.push_back(child);
783 }
784 globPosX_child += xN_child*_delta;
785 }
786 return;
787 }
788
789 // split in four cuboid
790
791 int restZ = rest/bestIx+1;
792 int xN_child = 0;
793 T globPosX_child = _globPosX;
794 int splited_nX = (int) (_nX * (T)((bestIz*bestIy+restZ)*restX)/(T)p);
795 CuboidGeometry2D<T> helpG0(_globPosZ, _globPosY, _delta, _nZ, _nY, bestIz*bestIy+restZ);
796
797 for (int iX=0; iX<restX; iX++) {
798 xN_child = (splited_nX+restX-iX-1)/restX;
799 for (int iC=0; iC<helpG0.getNc(); iC++) {
800 int zN_child = helpG0.get(iC).getNx();
801 int yN_child = helpG0.get(iC).getNy();
802 T globPosZ_child = helpG0.get(iC).get_globPosX();
803 T globPosY_child = helpG0.get(iC).get_globPosY();
804
805 Cuboid3D<T> child(globPosX_child, globPosY_child, globPosZ_child,
806 _delta, xN_child, yN_child, zN_child);
807 childrenC.push_back(child);
808 }
809 globPosX_child += xN_child*_delta;
810 }
811
812 splited_nX = _nX - splited_nX;
813 restZ = rest/bestIx;
814 CuboidGeometry2D<T> helpG1(_globPosZ, _globPosY, _delta, _nZ, _nY, bestIz*bestIy+restZ);
815 xN_child = 0;
816
817 for (int iX=0; iX<bestIx-restX; iX++) {
818 xN_child = (splited_nX+bestIx-restX-iX-1)/(bestIx-restX);
819 for (int iC=0; iC<helpG1.getNc(); iC++) {
820 int zN_child = helpG1.get(iC).getNx();
821 int yN_child = helpG1.get(iC).getNy();
822 T globPosZ_child = helpG1.get(iC).get_globPosX();
823 T globPosY_child = helpG1.get(iC).get_globPosY();
824
825 Cuboid3D<T> child(globPosX_child, globPosY_child, globPosZ_child,
826 _delta, xN_child, yN_child, zN_child);
827 childrenC.push_back(child);
828 }
829 globPosX_child += xN_child*_delta;
830 }
831 return;
832 }
833 }
834}
835
836} // namespace olb
837
838#endif
A regular single 3D cuboid is the basic component of a 3D cuboid structure which defines the grid.
Definition cuboid3D.h:58
void divideFractional(int iD, std::vector< T > fractions, std::vector< Cuboid3D< T > > &childrenC) const
Divides the cuboid into fractions along the iDth dimension.
Definition cuboid3D.hh:530
std::size_t getWeightIn(IndicatorF3D< T > &indicator) const
Returns the number of full cells w.r.t. indicator.
Definition cuboid3D.hh:194
size_t getLatticeVolume() const
Returns the number of Nodes in the volume.
Definition cuboid3D.hh:221
std::size_t getNblock() const override
Number of data blocks for the serializable interface.
Definition cuboid3D.hh:123
Cuboid3D & operator=(Cuboid3D const &rhs)
Copy assignment.
Definition cuboid3D.hh:102
Vector< T, 3 > getOrigin() const
Read only access to left lower corner coordinates.
Definition cuboid3D.hh:135
Vector< int, 3 > const getExtent() const
Read only access to the number of voxels in every dimension.
Definition cuboid3D.hh:165
T getPhysVolume() const
Returns the volume of the cuboid.
Definition cuboid3D.hh:171
Cuboid3D()
Construction of an empty cuboid at position 0, 0, 0 with delta 0 and nX = nY = nZ = 0.
Definition cuboid3D.hh:50
int getWeightValue() const
Returns the actual value of weight (-1 for getLatticeVolume())
Definition cuboid3D.hh:177
bool checkInters(T globX0, T globX1, T globY0, T globY1, T globZ0, T globZ1, int overlap=0) const
Checks whether there is an intersection with the cuboid extended with an layer of size overlap*delta.
Definition cuboid3D.hh:409
T getDeltaR() const
Read only access to the distance of cuboid nodes.
Definition cuboid3D.hh:141
bool physCheckPoint(T globX, T globY, T globZ, double overlap=0) const
Same for physical overlap.
Definition cuboid3D.hh:378
bool * getBlock(std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
Definition cuboid3D.hh:266
void divide(int p, int q, int r, std::vector< Cuboid3D< T > > &childrenC) const
Divides the cuboid in p*q*r cuboids of equal volume and add them to the given vector.
Definition cuboid3D.hh:488
void init(T globPosX, T globPosY, T globPosZ, T delta, int nX, int nY, int nZ)
Initializes the cuboid.
Definition cuboid3D.hh:111
void getFloorLatticeR(const std::vector< T > &physR, std::vector< int > &latticeR) const
Definition cuboid3D.hh:347
int getLatticePerimeter() const
Returns the number of Nodes at the perimeter.
Definition cuboid3D.hh:233
int getNz() const
Read access to cuboid depth.
Definition cuboid3D.hh:159
int getNy() const
Read access to cuboid height.
Definition cuboid3D.hh:153
bool operator==(const Cuboid3D< T > &rhs) const
equal operator
Definition cuboid3D.hh:252
void setWeight(size_t fullCells)
Sets the number of full cells.
Definition cuboid3D.hh:215
T getPhysPerimeter() const
Returns the perimeter of the cuboid.
Definition cuboid3D.hh:227
int getNx() const
Read access to cuboid width.
Definition cuboid3D.hh:147
void print() const
Prints cuboid details.
Definition cuboid3D.hh:284
bool getLatticeR(Vector< T, 3 > physR, Vector< int, 3 > &latticeR, T eps=1e-5)
Definition cuboid3D.h:128
bool checkPoint(T globX, T globY, T globZ, int overlap=0) const
Checks whether a point (globX/gloxY/globZ) is contained in the cuboid extended with an layer of size ...
Definition cuboid3D.hh:361
void getPhysR(T physR[3], const int latticeR[3]) const
Definition cuboid3D.hh:307
std::size_t getSerializableSize() const override
Binary size for the serializer interface.
Definition cuboid3D.hh:129
std::size_t getWeight() const
Returns the number of full cells.
Definition cuboid3D.hh:183
void refine(int factor)
Refines by splitting each cell into factor^3 cells.
Definition cuboid3D.hh:239
void resize(int X, int Y, int Z, int nX, int nY, int nZ)
resize the cuboid to the passed size
Definition cuboid3D.hh:518
A cuboid structure represents the grid of a considered domain.
int getNc() const
Returns the number of cuboids in t < 2he structure.
Cuboid2D< T > & get(int i)
Read and write access to the cuboids.
IndicatorF3D is an application from .
virtual Vector< S, 3 > & getMax()
virtual Vector< S, 3 > & getMin()
Plain old scalar vector.
Definition vector.h:47
The description of a single 3D cuboid – header file.
The description of a vector of 2D cuboid – header file.
ADf< T, DIM > floor(const ADf< T, DIM > &a)
Definition aDiff.h:869
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:124
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:130
Top level namespace for all of OpenLB.
#define OLB_PRECONDITION(COND)
Definition olbDebug.h:46