OpenLB 1.8.1
Loading...
Searching...
No Matches
cuboid.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 * 2025 Adrian Kummerlaender
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23*/
24
25#ifndef CUBOID_3D_HH
26#define CUBOID_3D_HH
27
28#include "cuboid.h"
29
30namespace olb {
31
32template <typename T, unsigned D>
34 _origin = rhs._origin;
35 _extent = rhs._extent;
36 _delta = rhs._delta;
37 _weight = rhs._weight;
38 return *this;
39}
40
41template <typename T, unsigned D>
42std::optional<LatticeR<D>> Cuboid<T,D>::getCloseLatticeR(Vector<T,D> physR, T eps) const {
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}
51
52template <typename T, unsigned D>
54 T physVolume = util::pow(_delta,D);
55 for (unsigned iD=0; iD < D; ++iD) {
56 physVolume *= _extent[iD];
57 }
58 return physVolume;
59}
60
61template <typename T, unsigned D>
62std::size_t Cuboid<T,D>::getLatticeVolume() const {
63 std::size_t latticeVolume = _extent[0];
64 for (unsigned iD=1; iD < D; ++iD) {
65 latticeVolume *= _extent[iD];
66 }
67 return latticeVolume;
68}
69
70template <typename T, unsigned D>
71T Cuboid<T,D>::getPhysPerimeter() const requires (D == 2) {
72 return 2*_extent[1]*_delta + 2*_extent[0]*_delta;
73}
74
75template <typename T, unsigned D>
76T Cuboid<T,D>::getPhysPerimeter() const requires (D == 3) {
77 const T area = util::pow(_delta,2);
78 return 2*area*(_extent[0]*_extent[1] + _extent[1]*_extent[2] + _extent[2]*_extent[0]);
79}
80
81template <typename T, unsigned D>
82std::size_t Cuboid<T,D>::getLatticePerimeter() const requires (D == 2) {
83 return 2*_extent[1] + 2*_extent[0] - 4;
84}
86template <typename T, unsigned D>
87std::size_t Cuboid<T,D>::getLatticePerimeter() const requires (D == 3) {
88 return 2*((_extent[0]-1)*(_extent[1]-1) + (_extent[1]-1)*(_extent[2]-1) + (_extent[2]-1)*(_extent[0]-1));
89}
90
91template <typename T, unsigned D>
92void Cuboid<T,D>::refine(int factor) {
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 }
104
105template <typename T, unsigned D>
106void Cuboid<T,D>::write(std::ostream& cout) const
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}
121template <typename T, unsigned D>
123{
124 OstreamManager clout(std::cout, "cuboid");
125 write(clout);
126}
127
128template <typename T, unsigned D>
131 return util::nearZero(_origin - rhs._origin)
132 && _extent == rhs._extent
133 && _weight == rhs._weight;
134}
136template <typename T, unsigned D>
137bool Cuboid<T,D>::isInside(Vector<T,D> pos, int overlap) const
138{
139 return _origin <= pos + overlap*_delta + _delta / 2
140 && _origin + (_extent+overlap) * _delta > pos + _delta / 2;
143template <typename T, unsigned D>
144bool Cuboid<T,D>::intersects(Vector<T,D> min, Vector<T,D> max, int overlap) const
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}
151
152template <typename T, unsigned D>
153bool Cuboid<T,D>::intersects(const Cuboid<T,D>& cuboid) const
154{
155 return intersects(cuboid.getOrigin(),
156 cuboid.getOrigin() + cuboid.getDeltaR()*(cuboid.getExtent()-1),
157 0);
158}
159
160template <typename T, unsigned D>
161void Cuboid<T,D>::divide(Vector<int,D> division, std::vector<Cuboid<T,D>>& childrenC) const requires (D == 2)
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}
182
183template <typename T, unsigned D>
184void Cuboid<T,D>::divide(Vector<int,D> division, std::vector<Cuboid<T,D>>& childrenC) const requires (D == 3)
185{
186 int xN_child = 0;
187 int yN_child = 0;
188 int zN_child = 0;
189
190 T globPosX_child = _origin[0];
191 T globPosY_child = _origin[1];
192 T globPosZ_child = _origin[2];
193
194 for (int iX=0; iX < division[0]; iX++) {
195 for (int iY=0; iY < division[1]; iY++) {
196 for (int iZ=0; iZ < division[2]; iZ++) {
197 xN_child = (_extent[0]+division[0]-iX-1)/division[0];
198 yN_child = (_extent[1]+division[1]-iY-1)/division[1];
199 zN_child = (_extent[2]+division[2]-iZ-1)/division[2];
200 Cuboid3D<T> child({globPosX_child, globPosY_child, globPosZ_child},
201 _delta, {xN_child, yN_child, zN_child});
202 childrenC.push_back(child);
203 globPosZ_child += zN_child*_delta;
204 }
205 globPosZ_child = _origin[2];
206 globPosY_child += yN_child*_delta;
207 }
208 globPosY_child = _origin[1];
209 globPosX_child += xN_child*_delta;
210 }
211}
212
213template <typename T, unsigned D>
214void Cuboid<T,D>::divideP(int p, std::vector<Cuboid<T,D>>& childrenC) const requires (D == 2)
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}
265
266template <typename T, unsigned D>
267void Cuboid<T,D>::divideP(int p, std::vector<Cuboid<T,D>>& childrenC) const requires (D == 3)
268{
269 int iXX = 1;
270 int iYY = 1;
271 int iZZ = p;
272 int nX = _extent[0]/iXX;
273 int bestIx = iXX;
274 int nY = _extent[1]/iYY;
275 int bestIy = iYY;
276 int nZ = _extent[2]/iZZ;
277 int bestIz = iZZ;
278 T bestRatio = ((T)(_extent[0]/iXX)/(T)(_extent[1]/iYY)-1)*((T)(_extent[0]/iXX)/(T)(_extent[1]/iYY)-1)
279 + ((T)(_extent[1]/iYY)/(T)(_extent[2]/iZZ)-1)*((T)(_extent[1]/iYY)/(T)(_extent[2]/iZZ)-1)
280 + ((T)(_extent[2]/iZZ)/(T)(_extent[0]/iXX)-1)*((T)(_extent[2]/iZZ)/(T)(_extent[0]/iXX)-1);
281
282 for (int iX=1; iX<=p; iX++) {
283 for (int iY=1; iY*iX<=p; iY++) {
284 for (int iZ=p/(iX*iY); iZ*iY*iX<=p; iZ++) {
285 if ((iX+1)*iY*iZ>p && iX*(iY+1)*iZ>p ) {
286 T ratio = ((T)(_extent[0]/iX)/(T)(_extent[1]/iY)-1)*((T)(_extent[0]/iX)/(T)(_extent[1]/iY)-1)
287 + ((T)(_extent[1]/iY)/(T)(_extent[2]/iZ)-1)*((T)(_extent[1]/iY)/(T)(_extent[2]/iZ)-1)
288 + ((T)(_extent[2]/iZ)/(T)(_extent[0]/iX)-1)*((T)(_extent[2]/iZ)/(T)(_extent[0]/iX)-1);
289 if (ratio<bestRatio) {
290 bestRatio = ratio;
291 bestIx = iX;
292 bestIy = iY;
293 bestIz = iZ;
294 nX = _extent[0]/iX;
295 nY = _extent[1]/iY;
296 nZ = _extent[2]/iZ;
297 }
298 }
299 }
300 }
301 }
302
303 int rest = p - bestIx*bestIy*bestIz;
304
305 // split in one cuboid
306 if (rest==0) {
307 divide({bestIx, bestIy, bestIz}, childrenC);
308 return;
309 }
310 else {
311
312 // add in z than in y direction
313 if (nZ>nY && nZ>nX) {
314
315 int restY = rest%bestIy;
316 // split in two cuboid
317 if (restY==0) {
318 int restX = rest/bestIy;
319 CuboidDecomposition<T,2> helpG({_origin[0], _origin[2]}, _delta, {_extent[0], _extent[2]}, bestIx*bestIz+restX);
320
321 int yN_child = 0;
322 T globPosY_child = _origin[1];
323
324 for (int iY=0; iY<bestIy; iY++) {
325 yN_child = (_extent[1]+bestIy-iY-1)/bestIy;
326 for (int iC=0; iC<helpG.size(); iC++) {
327 int xN_child = helpG.get(iC).getNx();
328 int zN_child = helpG.get(iC).getNy();
329 T globPosX_child = helpG.get(iC).getOrigin()[0];
330 T globPosZ_child = helpG.get(iC).getOrigin()[1];
331
332 Cuboid3D<T> child({globPosX_child, globPosY_child, globPosZ_child},
333 _delta, {xN_child, yN_child, zN_child});
334 childrenC.push_back(child);
335
336 }
337 globPosY_child += yN_child*_delta;
338 }
339 return;
340 }
341
342 // split in four cuboid
343
344 int restX = rest/bestIy+1;
345 int yN_child = 0;
346 T globPosY_child = _origin[1];
347 int splited_nY = (int) (_extent[1] * (T)((bestIx*bestIz+restX)*restY)/(T)p);
348 CuboidDecomposition<T,2> helpG0({_origin[0], _origin[2]}, _delta, {_extent[0], _extent[2]}, bestIx*bestIz+restX);
349
350 for (int iY=0; iY<restY; iY++) {
351 yN_child = (splited_nY+restY-iY-1)/restY;
352 for (int iC=0; iC<helpG0.size(); iC++) {
353 int xN_child = helpG0.get(iC).getNx();
354 int zN_child = helpG0.get(iC).getNy();
355 T globPosX_child = helpG0.get(iC).getOrigin()[0];
356 T globPosZ_child = helpG0.get(iC).getOrigin()[1];
357
358 Cuboid3D<T> child({globPosX_child, globPosY_child, globPosZ_child},
359 _delta, {xN_child, yN_child, zN_child});
360 childrenC.push_back(child);
361 }
362 globPosY_child += yN_child*_delta;
363 }
364
365 splited_nY = _extent[1] - splited_nY;
366 restX = rest/bestIy;
367 CuboidDecomposition<T,2> helpG1({_origin[0], _origin[2]}, _delta, {_extent[0], _extent[2]}, bestIx*bestIz+restX);
368 yN_child = 0;
369
370 for (int iY=0; iY<bestIy-restY; iY++) {
371 yN_child = (splited_nY+bestIy-restY-iY-1)/(bestIy-restY);
372 for (int iC=0; iC<helpG1.size(); iC++) {
373 int xN_child = helpG1.get(iC).getNx();
374 int zN_child = helpG1.get(iC).getNy();
375 T globPosX_child = helpG1.get(iC).getOrigin()[0];
376 T globPosZ_child = helpG1.get(iC).getOrigin()[1];
377
378 Cuboid3D<T> child({globPosX_child, globPosY_child, globPosZ_child},
379 _delta, {xN_child, yN_child, zN_child});
380 childrenC.push_back(child);
381 }
382 globPosY_child += yN_child*_delta;
383 }
384 return;
385 }
386
387 // add in x than in y direction
388 else if (nX>nY && nX>nZ) {
389 int restY = rest%bestIy;
390 // split in two cuboid
391 if (restY==0) {
392 int restZ = rest/bestIy;
393 CuboidDecomposition<T,2> helpG({_origin[0], _origin[2]}, _delta, {_extent[0], _extent[2]}, bestIx*bestIz+restZ);
394
395 int yN_child = 0;
396 T globPosY_child = _origin[1];
397
398 for (int iY=0; iY<bestIy; iY++) {
399 yN_child = (_extent[1]+bestIy-iY-1)/bestIy;
400 for (int iC=0; iC<helpG.size(); iC++) {
401 int xN_child = helpG.get(iC).getNx();
402 int zN_child = helpG.get(iC).getNy();
403 T globPosX_child = helpG.get(iC).getOrigin()[0];
404 T globPosZ_child = helpG.get(iC).getOrigin()[1];
405
406 Cuboid3D<T> child({globPosX_child, globPosY_child, globPosZ_child},
407 _delta, {xN_child, yN_child, zN_child});
408 childrenC.push_back(child);
409
410 }
411 globPosY_child += yN_child*_delta;
412 }
413 return;
414 }
415
416 // split in four cuboid
417
418 int restZ = rest/bestIy+1;
419
420 int yN_child = 0;
421 T globPosY_child = _origin[1];
422 int splited_nY = (int) (_extent[1] * (T)((bestIx*bestIz+restZ)*restY)/(T)p);
423 CuboidDecomposition<T,2> helpG0({_origin[0], _origin[2]}, _delta, {_extent[0], _extent[2]}, bestIx*bestIz+restZ);
424
425 for (int iY=0; iY<restY; iY++) {
426 yN_child = (splited_nY+restY-iY-1)/restY;
427 for (int iC=0; iC<helpG0.size(); iC++) {
428 int xN_child = helpG0.get(iC).getNx();
429 int zN_child = helpG0.get(iC).getNy();
430 T globPosX_child = helpG0.get(iC).getOrigin()[0];
431 T globPosZ_child = helpG0.get(iC).getOrigin()[1];
432
433 Cuboid3D<T> child({globPosX_child, globPosY_child, globPosZ_child},
434 _delta, {xN_child, yN_child, zN_child});
435 childrenC.push_back(child);
436 }
437 globPosY_child += yN_child*_delta;
438 }
439
440 splited_nY = _extent[1] - splited_nY;
441 restZ = rest/bestIy;
442
443 CuboidDecomposition<T,2> helpG1({_origin[0], _origin[2]}, _delta, {_extent[0], _extent[2]}, bestIx*bestIz+restZ);
444 yN_child = 0;
445
446 for (int iY=0; iY<bestIy-restY; iY++) {
447 yN_child = (splited_nY+bestIy-restY-iY-1)/(bestIy-restY);
448 for (int iC=0; iC<helpG1.size(); iC++) {
449 int xN_child = helpG1.get(iC).getNx();
450 int zN_child = helpG1.get(iC).getNy();
451 T globPosX_child = helpG1.get(iC).getOrigin()[0];
452 T globPosZ_child = helpG1.get(iC).getOrigin()[1];
453
454 Cuboid3D<T> child({globPosX_child, globPosY_child, globPosZ_child},
455 _delta, {xN_child, yN_child, zN_child});
456 childrenC.push_back(child);
457 }
458 globPosY_child += yN_child*_delta;
459 }
460 return;
461 }
462
463 // add in y than in x direction
464 else {
465 int restX = rest%bestIx;
466 // split in two cuboid
467 if (restX==0) {
468 int restZ = rest/bestIx;
469 CuboidDecomposition<T,2> helpG({_origin[2], _origin[1]}, _delta, {_extent[2], _extent[1]}, bestIz*bestIy+restZ);
470
471
472 int xN_child = 0;
473 T globPosX_child = _origin[0];
474
475 for (int iX=0; iX<bestIx; iX++) {
476 xN_child = (_extent[0]+bestIx-iX-1)/bestIx;
477 for (int iC=0; iC<helpG.size(); iC++) {
478 int zN_child = helpG.get(iC).getNx();
479 int yN_child = helpG.get(iC).getNy();
480 T globPosZ_child = helpG.get(iC).getOrigin()[0];
481 T globPosY_child = helpG.get(iC).getOrigin()[1];
482
483 Cuboid3D<T> child({globPosX_child, globPosY_child, globPosZ_child},
484 _delta, {xN_child, yN_child, zN_child});
485 childrenC.push_back(child);
486 }
487 globPosX_child += xN_child*_delta;
488 }
489 return;
490 }
491
492 // split in four cuboid
493
494 int restZ = rest/bestIx+1;
495 int xN_child = 0;
496 T globPosX_child = _origin[0];
497 int splited_nX = (int) (_extent[0] * (T)((bestIz*bestIy+restZ)*restX)/(T)p);
498 CuboidDecomposition<T,2> helpG0({_origin[2], _origin[1]}, _delta, {_extent[2], _extent[1]}, bestIz*bestIy+restZ);
499
500 for (int iX=0; iX<restX; iX++) {
501 xN_child = (splited_nX+restX-iX-1)/restX;
502 for (int iC=0; iC<helpG0.size(); iC++) {
503 int zN_child = helpG0.get(iC).getNx();
504 int yN_child = helpG0.get(iC).getNy();
505 T globPosZ_child = helpG0.get(iC).getOrigin()[0];
506 T globPosY_child = helpG0.get(iC).getOrigin()[1];
507
508 Cuboid3D<T> child({globPosX_child, globPosY_child, globPosZ_child},
509 _delta, {xN_child, yN_child, zN_child});
510 childrenC.push_back(child);
511 }
512 globPosX_child += xN_child*_delta;
513 }
514
515 splited_nX = _extent[0] - splited_nX;
516 restZ = rest/bestIx;
517 CuboidDecomposition<T,2> helpG1({_origin[2], _origin[1]}, _delta, {_extent[2], _extent[1]}, bestIz*bestIy+restZ);
518 xN_child = 0;
519
520 for (int iX=0; iX<bestIx-restX; iX++) {
521 xN_child = (splited_nX+bestIx-restX-iX-1)/(bestIx-restX);
522 for (int iC=0; iC<helpG1.size(); iC++) {
523 int zN_child = helpG1.get(iC).getNx();
524 int yN_child = helpG1.get(iC).getNy();
525 T globPosZ_child = helpG1.get(iC).getOrigin()[0];
526 T globPosY_child = helpG1.get(iC).getOrigin()[1];
527
528 Cuboid3D<T> child({globPosX_child, globPosY_child, globPosZ_child},
529 _delta, {xN_child, yN_child, zN_child});
530 childrenC.push_back(child);
531 }
532 globPosX_child += xN_child*_delta;
533 }
534 return;
535 }
536 }
537}
538
539template <typename T, unsigned D>
541 _origin += offset*_delta;
542 _extent = extent;
543}
544
545template <typename T, unsigned D>
546void Cuboid<T,D>::divideFractional(int iD, std::vector<T> fractions, std::vector<Cuboid<T,D>>& childrenC) const
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}
575
576template <typename T, unsigned D>
577void Cuboid<T,D>::writeAsXML(std::ostream& ss) const {
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}
591
592}
593
594#endif
T getPhysPerimeter() const
Returns the perimeter of the cuboid.
Definition cuboid.hh:71
Vector< T, D > getOrigin() const
Returns lower left corner coordinates.
Definition cuboid.h:74
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
std::size_t getLatticeVolume() const
Returns the number of Nodes in the volume.
Definition cuboid.hh:62
Vector< int, D > getExtent() const
Returns extent in number of voxels.
Definition cuboid.h:78
Cuboid & operator=(const Cuboid &rhs)
Definition cuboid.hh:33
std::optional< LatticeR< D > > getCloseLatticeR(Vector< T, D > physR, T eps=1e-5) const
Returns closest latticeR within eps of physR if it exists.
Definition cuboid.hh:42
void print() const
Definition cuboid.hh:122
bool operator==(const Cuboid &rhs) const
Definition cuboid.hh:129
T getDeltaR() const
Returns spacing of cuboid nodes.
Definition cuboid.h:76
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.
Definition cuboid.hh:137
void resize(Vector< int, D > offset, Vector< int, D > extent)
Definition cuboid.hh:540
void refine(int factor)
Definition cuboid.hh:92
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
void divideP(int p, std::vector< Cuboid< T, D > > &childrenC) const
Divides the cuboid in p cuboids and add them to the given vector.
Definition cuboid.hh:214
void divideFractional(int iD, std::vector< T > fractions, std::vector< Cuboid< T, D > > &childrenC) const
Divides the cuboid into fractions along the iDth dimension.
Definition cuboid.hh:546
void writeAsXML(std::ostream &) const
Definition cuboid.hh:577
void write(std::ostream &cout) const
Definition cuboid.hh:106
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
class for marking output with some text
Plain old scalar vector.
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
Expr pow(Expr base, Expr exp)
Definition expr.cpp:235
Expr fabs(Expr x)
Definition expr.cpp:230
bool nearZero(T a) any_platform
return true if a is close to zero
Definition util.h:402
Top level namespace for all of OpenLB.
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
Vector< std::int32_t, D > LatticeR
Type for spatial block-local lattice coordinates.
Cuboid< T, 3 > Cuboid3D
Definition cuboid.h:151