VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
D3Q27TriFaceMeshInteractor.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
36//=======================================================================================
37
41
46
47#include <basics/Timer/Timer.h>
48
49#include "BCArray3D.h"
50#include "BCSet.h"
51#include "Block3D.h"
52#include "BoundaryConditions.h"
53#include "Grid3D.h"
54#include "LBMKernel.h"
55#include "VelocityBC.h"
60
62
63//#include <omp.h>
64
66#include <stack>
67
68using namespace std;
69
94{
95 updateBlocks();
96 setQs(timeStep);
97}
100{
101 if (!block)
102 return false;
103
104 // UBLOG(logINFO, "D3Q27TriFaceMeshInteractor::setDifferencesToGbObject3D()");
105
107 // set< std::vector<int> >& transNodeIndices = bcNodeIndicesMap[block];
110
111 bool oneEntryGotBC = false;
113
114 SPtr<LBMKernel> kernel = block->getKernel();
115 SPtr<BCArray3D> bcArray = kernel->getBCSet()->getBCArray();
116
117 double internX1, internX2, internX3;
118
119 int startIX1 = 0, startIX2 = 0, startIX3 = 0;
120 int stopIX1 = (int)bcArray->getNX1(), stopIX2 = (int)bcArray->getNX2(), stopIX3 = (int)bcArray->getNX3();
121
122 bool pointOnBoundary = false;
123
124 for (int ix3 = startIX3; ix3 < stopIX3; ix3++) {
125 for (int ix2 = startIX2; ix2 < stopIX2; ix2++) {
126 for (int ix1 = startIX1; ix1 < stopIX1; ix1++) {
127 GbVector3D coords = grid.lock()->getNodeCoordinates(block, ix1, ix2, ix3);
128 internX1 = coords[0];
129 internX2 = coords[1];
130 internX3 = coords[2];
131
132 if (this->isSolid()) {
133 if (this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3)) {
134 if (bcArray->isFluid(ix1, ix2, ix3)) {
135 solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3));
136 bcArray->setSolid(ix1, ix2, ix3);
137 }
138 }
139 } else if (this->isInverseSolid()) {
140 // with inverse solid all nodes are OUTSIDE and on the boundary SOLID
141 if (!this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3, pointOnBoundary) ||
142 pointOnBoundary == true) {
143 if (bcArray->isFluid(ix1, ix2, ix3)) {
144 solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3));
145 bcArray->setSolid(ix1, ix2, ix3);
146 }
147 }
148 }
149 }
150 }
151 }
152
153 return oneEntryGotBC;
154}
156// E.F. /4/16/2013
158{
159 using namespace vf::lbm::dir;
160 using namespace vf::basics::constant;
161
162 UBLOGML(logDEBUG1, "\nLBMTriFaceMeshInteractor - setQs start ");
163 if (!this->grid.lock())
164 throw UbException(UB_EXARGS, "ups, no grid.lock()!!");
165
166 if (this->reinitWithStoredQsFlag && !bcNodeIndicesAndQsMap.empty()) {
167 this->reinitWithStoredQs(timeStep);
168 return;
169 }
170
171 GbTriFaceMesh3D *mesh = dynamic_cast<GbTriFaceMesh3D *>(this->geoObject3D.get());
172
174 // init bcs
176 int nofAdapter = (int)this->BCs.size();
177 if (nofAdapter == 0)
178 std::cout
179 << "WARNING - D3Q27TriFaceMeshInteractor::initInteractor Warning - no nodeAdapter available for " /*<<this->getName()*/
180 << std::endl;
181 bool needTimeDependence = false;
182 for (int pos = 0; pos < nofAdapter; ++pos) {
183 this->BCs[pos]->init(this, timeStep);
184 if (this->BCs[pos]->isTimeDependent())
185 needTimeDependence = true;
186 }
188 this->setTimeDependent();
189 else
190 this->unsetTimeDependent();
191
193 // grid.lock() info
195 int coarsestInitLevel = grid.lock()->getCoarsestInitializedLevel();
196 int finestInitLevel = grid.lock()->getFinestInitializedLevel();
197
198 UbTupleInt3 blocknx = grid.lock()->getBlockNX();
199 int blocknx1 = val<1>(blocknx); // applies to all levels
200 int blocknx2 = val<2>(blocknx); // applies to all levels
201 int blocknx3 = val<3>(blocknx); // applies to all levels
202
203 // grobe Blocklaengen
204 SPtr<CoordinateTransformation3D> trafo = grid.lock()->getCoordinateTransformator();
207 if (trafo) {
208 cblockDeltaX1 = trafo->getX1CoordinateScaling() * delta;
209 cblockDeltaX2 = trafo->getX2CoordinateScaling() * delta;
210 cblockDeltaX3 = trafo->getX3CoordinateScaling() * delta;
211 }
212 // Level-specific block lengths and node spacing
213 std::vector<std::vector<double>> nodeDeltaToNeigh(finestInitLevel + 1);
214 std::vector<float> deltaMinX1(finestInitLevel + 1), deltaMinX2(finestInitLevel + 1),
216 std::vector<float> deltaMaxX1(finestInitLevel + 1), deltaMaxX2(finestInitLevel + 1),
218
219 // In the Boltzman context, dx1==dx2==dx3 must be!!
222
223 for (int level = coarsestInitLevel; level <= finestInitLevel; level++) {
227
228 std::vector<real> distNeigh(d3q27_system::FENDDIR + 1, 0.0);
229 d3q27_system::calcDistanceToNeighbors(distNeigh, nodeDeltaX1, nodeDeltaX2, nodeDeltaX3);
230
231 nodeDeltaToNeigh[level].resize(d3q27_system::ENDDIR + 1, 0.0);
232 for (int fdir = d3q27_system::FSTARTDIR; fdir <= d3q27_system::FENDDIR; fdir++) {
234 }
235
236 // TODO: set 5.0 as variable parameter in constructor, default 2.0
237 deltaMinX1[level] = (float)(c5o1 * nodeDeltaX1); // no minus down there -deltaMin
238 deltaMinX2[level] = (float)(c5o1 * nodeDeltaX2);
239 deltaMinX3[level] = (float)(c5o1 * nodeDeltaX3);
240 deltaMaxX1[level] = (float)(c5o1 * nodeDeltaX1);
241 deltaMaxX2[level] = (float)(c5o1 * nodeDeltaX2);
242 deltaMaxX3[level] = (float)(c5o1 * nodeDeltaX3);
243 }
244
246 // TRIANGLES: q-determination
248
249 // initialize necessary variables (including blockDeltas of the coarse level)
250 float triPoints[3][3];
251 float vx1 = 0.0, vx2 = 0.0, vx3 = 0.0;
252 std::vector<GbTriFaceMesh3D::TriFace> &triangles = *mesh->getTriangles();
253 std::vector<GbTriFaceMesh3D::Vertex> &nodes = *mesh->getNodes();
254 std::map<SPtr<Block3D>, std::set<UbTupleInt3>> tmpSolidNodesFromOtherInteractors;
255
256 int onePercent = ub_math::integerRounding(triangles.size() * c1o100);
257 if (onePercent == 0)
258 onePercent = 1;
261 UBLOG(logDEBUG3, " - setQs for " << (int)triangles.size() << " triangles");
262
263
264 float blockMinX[3], blockMaxX[3], boxCenter[3], halfBoxSize[3];
265
266 for (size_t t = 0; t < triangles.size(); t++) {
268 // Generate halfspace for the triangle and determine the min/max of the triangle
270 GbTriFaceMesh3D::TriFace &triangle = triangles[t];
271
272 GbTriFaceMesh3D::Vertex &v1 = nodes[triangle.v1];
273 GbTriFaceMesh3D::Vertex &v2 = nodes[triangle.v2];
274 GbTriFaceMesh3D::Vertex &v3 = nodes[triangle.v3];
275
276 if (this->isInverseSolid()) {
277 triangle.nx *= (-1);
278 triangle.ny *= (-1);
279 triangle.nz *= (-1);
280 }
281 GbHalfSpace3D halfSpace(v1.x, v1.y, v1.z, triangle.nx, triangle.ny, triangle.nz);
282
284 // for gb_mesh_tools_3d::triBoxOverlap
286 triPoints[0][0] = v1.x;
287 triPoints[0][1] = v1.y;
288 triPoints[0][2] = v1.z;
289 triPoints[1][0] = v2.x;
290 triPoints[1][1] = v2.y;
291 triPoints[1][2] = v2.z;
292 triPoints[2][0] = v3.x;
293 triPoints[2][1] = v3.y;
294 triPoints[2][2] = v3.z;
295
296 double minX1 = triangle.getMinX(nodes);
297 double maxX1 = triangle.getMaxX(nodes);
298 double minX2 = triangle.getMinY(nodes);
299 double maxX2 = triangle.getMaxY(nodes);
300 double minX3 = triangle.getMinZ(nodes);
301 double maxX3 = triangle.getMaxZ(nodes);
302
304 // Loop through all levels
306 double e1x1, e1x2, e1x3, e2x1, e2x2, e2x3, px1, px2, px3, a, f, sx1, sx2, sx3, u, qx1, qx2, qx3, v;
307 bool gotQs = false;
309
310 for (int level = coarsestInitLevel; level <= finestInitLevel; level++) {
312 // Determine the level-specific BoundCube of the triangle and obtain the associated blocks
314 double boundCubeTriangleMinX1 = minX1 - deltaMinX1[level];
315 double boundCubeTriangleMaxX1 = maxX1 + deltaMaxX1[level];
316 double boundCubeTriangleMinX2 = minX2 - deltaMinX2[level];
317 double boundCubeTriangleMaxX2 = maxX2 + deltaMaxX2[level];
318 double boundCubeTriangleMinX3 = minX3 - deltaMinX3[level];
319 double boundCubeTriangleMaxX3 = maxX3 + deltaMaxX3[level];
320
323
324 std::vector<SPtr<Block3D>> triBlocks;
325 grid.lock()->getBlocksByCuboid(level, boundCubeTriangleMinX1, boundCubeTriangleMinX2,
328
330 // Loop over blocks of the level that contain the triangle
332 for (std::size_t b = 0; b < triBlocks.size(); b++) {
333 SPtr<Block3D> block = triBlocks[b];
334
338 UbTupleDouble3 coords = grid.lock()->getBlockWorldCoordinates(block);
339 UbTupleDouble3 deltas = grid.lock()->getBlockLengths(block);
340
341 blockMinX[0] = (float)(val<1>(coords) - deltaMinX1[level]);
342 blockMinX[1] = (float)(val<2>(coords) - deltaMinX2[level]);
343 blockMinX[2] = (float)(val<3>(coords) - deltaMinX3[level]);
344
345 blockMaxX[0] = (float)(val<1>(coords) + val<1>(deltas) + deltaMaxX1[level]);
346 blockMaxX[1] = (float)(val<2>(coords) + val<2>(deltas) + deltaMaxX2[level]);
347 blockMaxX[2] = (float)(val<3>(coords) + val<3>(deltas) + deltaMaxX3[level]);
348
349 boxCenter[0] = (float)(c1o2 * (blockMaxX[0] + blockMinX[0]));
350 boxCenter[1] = (float)(c1o2 * (blockMaxX[1] + blockMinX[1]));
351 boxCenter[2] = (float)(c1o2 * (blockMaxX[2] + blockMinX[2]));
352
353 halfBoxSize[0] = (float)(c1o2 * (blockMaxX[0] - blockMinX[0]));
354 halfBoxSize[1] = (float)(c1o2 * (blockMaxX[1] - blockMinX[1]));
355 halfBoxSize[2] = (float)(c1o2 * (blockMaxX[2] - blockMinX[2]));
356
357 // if triangle "enlarged cube" does not intersect/touch -> no BC possible -> continue
359 continue;
360 }
361
363 // Examination of the individual nodes
365 bool blockGotBCs = false;
366
367 SPtr<LBMKernel> kernel = block->getKernel();
368 SPtr<BCArray3D> bcMatrix = kernel->getBCSet()->getBCArray();
369
370 int indexMinX1 = 0;
371 int indexMinX2 = 0;
372 int indexMinX3 = 0;
373
374 int indexMaxX1 = (int)bcMatrix->getNX1();
375 int indexMaxX2 = (int)bcMatrix->getNX2();
376 int indexMaxX3 = (int)bcMatrix->getNX3();
377
378 std::set<std::vector<int>> &bcNodeIndices = this->bcNodeIndicesMap[block];
379 double q, distance;
380
381 double &nodeDx1 = nodeDeltaToNeigh[level][dP00];
382 double &nodeDx2 = nodeDeltaToNeigh[level][d0P0];
383 double &nodeDx3 = nodeDeltaToNeigh[level][d00P];
384
385 // fuer OBB-Test
387
388 for (int ix3 = indexMinX3; ix3 < indexMaxX3; ix3++) {
389 for (int ix2 = indexMinX2; ix2 < indexMaxX2; ix2++) {
390 for (int ix1 = indexMinX1; ix1 < indexMaxX1; ix1++) {
391 GbVector3D pointplane1 = grid.lock()->getNodeCoordinates(block, ix1, ix2, ix3);
392 double internX1 = pointplane1[0];
393 double internX2 = pointplane1[1];
394 double internX3 = pointplane1[2];
395
396 if (bcMatrix->isSolid(ix1, ix2, ix3) || bcMatrix->isUndefined(ix1, ix2, ix3)) {
397 continue;
398 }
399
401 // Point in AABB of triangle?
403 // Ehsan changed
404 bool pointIsOnBoundary = true;
405 if (!boundingCubeTriangle.isPointInGbObject3D(internX1, internX2, internX3,
407 continue;
408 }
409 // std::cout<<"internX3 "<<internX3<<" internX2"<<internX2<<" internX1 "<<internX1<<"\n";
411 // Half-plane tests
414 // Point in half plane? (no, if distance<0)
415 if (useHalfSpace &&
416 ub_math::less(distance, 0.0)) //== !halfSpace.ptInside(internX1,internX2,internX3) )
417 {
418 continue;
419 }
420
421 // CheapOBB test: if distance > qInfluenceDelta -> no q
423 continue;
424 }
425
427 // Ray tracing for discrete Boltzmann directions
429 gotQs = false;
431
432 // RAYTRACING - diskrete LB-dir zu Dreick
433 // e1 = v1 - v0
434 e1x1 = v2.x - v1.x;
435 e1x2 = v2.y - v1.y;
436 e1x3 = v2.z - v1.z;
437
438 // e2 = v2 - v0
439 e2x1 = v3.x - v1.x;
440 e2x2 = v3.y - v1.y;
441 e2x3 = v3.z - v1.z;
442
443 // s = o - v0
444 sx1 = internX1 - v1.x;
445 sx2 = internX2 - v1.y;
446 sx3 = internX3 - v1.z;
447
448 for (int fdir = d3q27_system::FSTARTDIR; fdir <= d3q27_system::FENDDIR; fdir++) {
449 // p = d x e2
450 px1 = this->rayX2[fdir] * e2x3 - this->rayX3[fdir] * e2x2;
451 px2 = this->rayX3[fdir] * e2x1 - this->rayX1[fdir] * e2x3;
452 px3 = this->rayX1[fdir] * e2x2 - this->rayX2[fdir] * e2x1;
453
454 // a = e1 dot p
455 a = e1x1 * px1 + e1x2 * px2 + e1x3 * px3;
456 if (fabs(a) < 1.E-10)
457 continue;
458 f = c1o1 / a;
459
460 // u = f * ( s dot p)
461 u = f * (sx1 * px1 + sx2 * px2 + sx3 * px3);
462 if (u < -1.E-10 || u > c1o1 + 1.E-10)
463 continue;
464
465 // q = s x e1
466 qx1 = sx2 * e1x3 - sx3 * e1x2;
467 qx2 = sx3 * e1x1 - sx1 * e1x3;
468 qx3 = sx1 * e1x2 - sx2 * e1x1;
469
470 // v = f*(e2 dot q)
471 v = f * (this->rayX1[fdir] * qx1 + this->rayX2[fdir] * qx2 + this->rayX3[fdir] * qx3);
472 if (v < -1.E-10 || (u + v) > c1o1 + 1.E-10)
473 continue;
474
475 // t = f * (e2 dot q)
476 q = f * (e2x1 * qx1 + e2x2 * qx2 + e2x3 * qx3);
477 q /= nodeDeltaToNeigh[level][fdir];
479 double det = triangle.nx * this->rayX1[fdir] + triangle.ny * this->rayX2[fdir] +
480 triangle.nz * this->rayX3[fdir];
481
482 if (det > -1.E-10)
483 continue;
484 double d = triangle.nx * v1.x + triangle.ny * v1.y + triangle.nz * v1.z;
485 double x1 = -((-d * this->rayX1[fdir] - triangle.ny * this->rayX2[fdir] * internX1 -
486 triangle.nz * this->rayX3[fdir] * internX1 +
487 triangle.ny * this->rayX1[fdir] * internX2 +
488 triangle.nz * this->rayX1[fdir] * internX3)) /
489 det;
490 double y1 = -((-d * this->rayX2[fdir] + triangle.nx * this->rayX2[fdir] * internX1 -
491 triangle.nx * this->rayX1[fdir] * internX2 -
492 triangle.nz * this->rayX3[fdir] * internX2 +
493 triangle.nz * this->rayX2[fdir] * internX3)) /
494 det;
495 double z1 = -((-d * this->rayX3[fdir] + triangle.nx * this->rayX3[fdir] * internX1 +
496 triangle.ny * this->rayX3[fdir] * internX2 -
497 triangle.nx * this->rayX1[fdir] * internX3 -
498 triangle.ny * this->rayX2[fdir] * internX3)) /
499 det;
500 double q_ehsan =
501 sqrt((x1 - internX1) * (x1 - internX1) + (y1 - internX2) * (y1 - internX2) +
502 (z1 - internX3) * (z1 - internX3));
503 q_ehsan /= nodeDeltaToNeigh[level][fdir];
504 q = q_ehsan;
505 if (ub_math::greater(q, c1o1) || ub_math::lessEqual(q, 0.0))
506 continue;
507
508 //Check found q for validity
509 if (ub_math::zero(q)) {
510 // new (05/18/2010)
511 // It can happen that with thin-walled geos there are points on a triangle
512 // lie, get qs that go through the geo. these points will come later
513 // but no longer tested for solidity because they didn't get a BC
514 //--> there is at least a q==0.0 for one of the triangles -> put it solid there
515 this->solidNodeIndicesMap[block].insert(UbTupleInt3(ix1, ix2, ix3));
516 bcMatrix->setSolid(ix1, ix2, ix3);
517 continue;
518 }
519
520 if (ub_math::inClosedInterval(q, c1o1, c1o1))
521 q = c1o1;
522 if (ub_math::greater(q, 0.0) && ub_math::lessEqual(q, c1o1)) {
523 gotQs = blockGotBCs = true;
524
525 bc = bcMatrix->getBC(ix1, ix2, ix3);
526
527 // SG 26.08.2010 if(!bc && !bcMatrix->isSolid())
528 if (!bc) {
530 ;
531 bcMatrix->setBC(ix1, ix2, ix3, bc);
532 } else if (ub_math::less(bc->getQ(fdir), q) &&
533 ub_math::equal(-999.0, q)) // schon ein kuerzeres q voehanden?
534 {
535 // new:: May 18, 2010
536 // to avoid incorrect qs that might go through the "wall".
537 // only reset q if new q is smaller than existing one!
538 // Also: especially on corners with two BC geos, that's all
539 // more details valid
540 continue;
541 }
542
543 bc->setBoundaryVelocityX1(vx1);
544 bc->setBoundaryVelocityX2(vx2);
545 bc->setBoundaryVelocityX3(vx3);
546
547 for (int index = (int)this->BCs.size() - 1; index >= 0; --index)
548 this->BCs[index]->adaptBCForDirection(*this, bc, internX1, internX2,
549 internX3, q, fdir);
550
551 // for accelerated rereading
552 if (this->reinitWithStoredQsFlag) {
553 bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)].resize(
554 d3q27_system::FENDDIR + 1 + 3, -1.0f);
555 bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)][fdir] = float(q);
556 bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)]
557 [d3q27_system::FENDDIR + 1 + 0] = float(internX1);
558 bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)]
559 [d3q27_system::FENDDIR + 1 + 1] = float(internX2);
560 bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)]
561 [d3q27_system::FENDDIR + 1 + 2] = float(internX3);
562 }
563 }
564 }
565
566 if (gotQs) {
567 std::vector<int> p(3);
568 p[0] = ix1;
569 p[1] = ix2;
570 p[2] = ix3;
571 bcNodeIndices.insert(p);
572
573 for (int index = (int)this->BCs.size() - 1; index >= 0; --index)
574 this->BCs[index]->adaptBC(*this, bc, internX1, internX2, internX3);
575 }
576 }
577 }
578 }
579 }
580 // Unfortunately, dynamic points of the GbCuboids have to be deleted manually :-(
581 boundingCubeTriangle.finalize();
582 }
583 }
584 UBLOGML(logDEBUG1, "\nLBMTriFaceMeshInteractor - setQs end ");
585}
587// Procedure
588// A – Determination of the q's
589// 1. The blocks of the block grid are determined for each bounding cube of a triangle in the network
590// 2. using a triangle/block intersection test, further irrelevant blocks are sorted out
591// (for long triangles that are crooked in space and where the bounding cube is suboptimal)
592// 3. Each node of these blocks is tested against the bound cube of the triangle
593// 4. Nodes that are within the cube but “within” the network are sorted out using a half-plane test
594// 5. For the remaining nodes, the q determination is carried out using efficient ray tracing algorithms
595// for the discrete Boltzmann directions
596// B – Setting the inactive blocks and solid nodes
597// all blocks of the bounding cube of the network that received at least one BC were marked in A
598// 1. for unmarked blocks, ONE pointInObject (triangular network) test is sufficient for the entire block if successful
599// mark “not active”.
600// 2. a recursive filling algorithm is carried out for marked blocks
602void D3Q27TriFaceMeshInteractor::refineBlockGridToLevel(int level, real startDistance, real stopDistance)
603{
604 using namespace vf::basics::constant;
605
606 UBLOG(logDEBUG1, "D3Q27TriFaceMeshInteractor::refineBlockGridToLevel - start");
607
608 // ToDo: maybe check whether you can install a half-space check for StopDistance
609 // or whether you're faster if you don't do a half-space test at all...
610 if (!grid.lock())
611 throw UbException(UB_EXARGS, "Grid isn't exist!");
612 if (ub_math::greater(startDistance, 0.0))
613 throw UbException(UB_EXARGS, "startDistance>0.0 not supported by this interactor");
614 if (ub_math::less(stopDistance, 0.0))
615 throw UbException(UB_EXARGS, "stopDistance<0.0 not supported by this interactor");
616
617 SPtr<Grid3D> bgrid = this->grid.lock();
618 GbTriFaceMesh3D &mesh = dynamic_cast<GbTriFaceMesh3D &>(*this->geoObject3D.get());
619
620 int coarsestLevel = bgrid->getCoarsestInitializedLevel();
621
622 std::vector<GbTriFaceMesh3D::TriFace> &triangles = *mesh.getTriangles();
623 std::vector<GbTriFaceMesh3D::Vertex> &nodes = *mesh.getNodes();
624
625 double minX1, minX2, minX3, maxX1, maxX2, maxX3;
626 float blockMinX[3], blockMaxX[3], boxCenter[3], halfBoxSize[3];
627 float triPoints[3][3];
628
629 size_t nofTriangles = (int)triangles.size();
630
631 //#pragma omp parallel
632 //#pragma omp for
633 for (size_t i = 0; i < nofTriangles; i++)
634 // for(int i=0; i<nofTriangles; i++)
635 {
636 //#pragma omp master
637 //{
638 // printf_s("num_threads=%d\n", omp_get_num_threads( ));
639 //}
640
641 GbTriFaceMesh3D::TriFace &triangle = triangles[i];
642
643 GbTriFaceMesh3D::Vertex &v1 = nodes[triangle.v1];
644 GbTriFaceMesh3D::Vertex &v2 = nodes[triangle.v2];
645 GbTriFaceMesh3D::Vertex &v3 = nodes[triangle.v3];
646
647 // dreick muss normal besitzen!
649 // Normale muss normiert sein!
650 assert((fabs(std::sqrt(triangle.nx * triangle.nx + triangle.ny * triangle.ny + triangle.nz * triangle.nz)) -
651 1.0f) < 1.0E-6);
652
653 // Move halfspace around startDistance to normal, otherwise we will do it later
654 // blocks to be tested on the back of the triangle not tested!!!
656 v1.x + startDistance * triangle.nx, v1.y + startDistance * triangle.ny, v1.z + startDistance * triangle.nz,
657 v2.x + startDistance * triangle.nx, v2.y + startDistance * triangle.ny, v2.z + startDistance * triangle.nz,
658 v3.x + startDistance * triangle.nx, v3.y + startDistance * triangle.ny, v3.z + startDistance * triangle.nz);
659
660 // Expand the bounding box with relevant dx -> to determine the blocks to be tested
661 if (triangle.nx > 1.0E-8) {
662 minX1 = triangle.getMinX(nodes) + c21o20 * triangle.nx * startDistance;
663 maxX1 = triangle.getMaxX(nodes) + c21o20 * triangle.nx * stopDistance;
664 } else {
665 minX1 = triangle.getMinX(nodes) + c21o20 * triangle.nx * stopDistance;
666 maxX1 = triangle.getMaxX(nodes) + c21o20 * triangle.nx * startDistance;
667 }
668
669 if (triangle.ny > 1.0E-8) {
670 minX2 = triangle.getMinY(nodes) + c21o20 * triangle.ny * startDistance;
671 maxX2 = triangle.getMaxY(nodes) + c21o20 * triangle.ny * stopDistance;
672 } else {
673 minX2 = triangle.getMinY(nodes) + c21o20 * triangle.ny * stopDistance;
674 maxX2 = triangle.getMaxY(nodes) + c21o20 * triangle.ny * startDistance;
675 }
676
677 if (triangle.nz > 1.0E-8) {
678 minX3 = triangle.getMinZ(nodes) + c21o20 * triangle.nz * startDistance;
679 maxX3 = triangle.getMaxZ(nodes) + c21o20 * triangle.nz * stopDistance;
680 } else {
681 minX3 = triangle.getMinZ(nodes) + c21o20 * triangle.nz * stopDistance;
682 maxX3 = triangle.getMaxZ(nodes) + c21o20 * triangle.nz * startDistance;
683 }
684
685 int flag = 0;
686 // Get all the blocks that intersect extended BB level by level
687 // and edit
688 for (int l = coarsestLevel; l < level; l++) {
689 std::vector<SPtr<Block3D>> consideredBlocks;
690 bgrid->getBlocksByCuboid(l, minX1, minX2, minX3, maxX1, maxX2, maxX3, consideredBlocks);
691 double x1a, x2a, x3a, x1b, x2b, x3b;
692
693 for (size_t b = 0; b < consideredBlocks.size(); b++) {
695 if (block->getLevel() >= level)
696 continue;
697
698 // Determine the start coordinates of the block
699 UbTupleDouble3 coords = bgrid->getBlockWorldCoordinates(block);
700 UbTupleDouble3 deltas = bgrid->getBlockLengths(block);
701
702 // Check whether the block is completely in the half space
703 x1a = val<1>(coords);
705 x2a = val<2>(coords);
707 x3a = val<3>(coords);
709
710 flag = 0;
711 if (!halfSpace.ptInside(x1a, x2a, x3a))
712 flag |= (1 << 0); // 1
713 if (!halfSpace.ptInside(x1b, x2a, x3a))
714 flag |= (1 << 1); // 2
715 if (!halfSpace.ptInside(x1b, x2b, x3a))
716 flag |= (1 << 2); // 4
717 if (!halfSpace.ptInside(x1a, x2b, x3a))
718 flag |= (1 << 3); // 8
719 if (!halfSpace.ptInside(x1a, x2a, x3b))
720 flag |= (1 << 4); // 16
721 if (!halfSpace.ptInside(x1b, x2a, x3b))
722 flag |= (1 << 5); // 32
723 if (!halfSpace.ptInside(x1b, x2b, x3b))
724 flag |= (1 << 6); // 64
725 if (!halfSpace.ptInside(x1a, x2b, x3b))
726 flag |= (1 << 7); // 128
727
728 if (true && flag != 255) {
729 // determine block side (scalar product triangle-normal, vector (midTri->midCub) )
730 // depending on this, start or stopdistance must be used for the relevant block
731 // block is on the pos side -> stopdistance otherwise startdistance
732 double skalarprod = triangle.nx * (c1o2 * (x1a + x1b) - triangle.getX1Centroid(nodes)) +
733 triangle.ny * (c1o2 * (x2a + x2b) - triangle.getX2Centroid(nodes)) +
734 triangle.nz * (c1o2 * (x3a + x3b) - triangle.getX3Centroid(nodes));
735
736 double blockdelta = c21o20 * stopDistance;
737 if (skalarprod < 1.E-8)
738 blockdelta = -c21o20 * startDistance; // startDistance<0!!
739 else if (fabs(skalarprod) < 1.E-8)
740 blockdelta = c21o20 * ub_math::max(-startDistance, stopDistance);
741
742 // adjust block
746
750
751 boxCenter[0] = (float)(c1o2 * (blockMaxX[0] + blockMinX[0]));
752 boxCenter[1] = (float)(c1o2 * (blockMaxX[1] + blockMinX[1]));
753 boxCenter[2] = (float)(c1o2 * (blockMaxX[2] + blockMinX[2]));
754
755 halfBoxSize[0] = (float)(c1o2 * (blockMaxX[0] - blockMinX[0]));
756 halfBoxSize[1] = (float)(c1o2 * (blockMaxX[1] - blockMinX[1]));
757 halfBoxSize[2] = (float)(c1o2 * (blockMaxX[2] - blockMinX[2]));
758
762
763 triPoints[0][0] = v1_.x;
764 triPoints[0][1] = v1_.y;
765 triPoints[0][2] = v1_.z;
766 triPoints[1][0] = v2_.x;
767 triPoints[1][1] = v2_.y;
768 triPoints[1][2] = v2_.z;
769 triPoints[2][0] = v3_.x;
770 triPoints[2][1] = v3_.y;
771 triPoints[2][2] = v3_.z;
772
773 // if block triangle cuts, then it needs to be refined
775 bgrid->expandBlock(block->getX1(), block->getX2(), block->getX3(), block->getLevel());
776 }
777 }
778 }
779 }
780 }
781 UBLOG(logDEBUG1, " - refine done");
782}
787 const short &zs, const FLAGS &type)
788{
789 // Algorithmus zum Füllen eines Polyeders, ausgehend vom Saatpunkt xs,ys,zs
790
791 // Saatknoten einfärben
792 if (flagfield(xs, ys, zs) == UNDEF_FLAG) {
793 flagfield(xs, ys, zs) = type;
794
795 if (flagfield.indicesInRange(xs + 1, ys, zs))
796 this->recursiveGridFill(flagfield, xs + 1, ys, zs, type);
797 if (flagfield.indicesInRange(xs, ys + 1, zs))
798 this->recursiveGridFill(flagfield, xs, ys + 1, zs, type);
799 if (flagfield.indicesInRange(xs, ys, zs + 1))
800 this->recursiveGridFill(flagfield, xs, ys, zs + 1, type);
801 if (flagfield.indicesInRange(xs - 1, ys, zs))
802 this->recursiveGridFill(flagfield, xs - 1, ys, zs, type);
803 if (flagfield.indicesInRange(xs, ys - 1, zs))
804 this->recursiveGridFill(flagfield, xs, ys - 1, zs, type);
805 if (flagfield.indicesInRange(xs, ys, zs - 1))
806 this->recursiveGridFill(flagfield, xs, ys, zs - 1, type);
807 }
808}
811 const short &zs, const FLAGS &type)
812{
813 std::stack<UbTupleInt3> stck;
814 stck.push(UbTupleInt3(xs, ys, zs));
815
816 int x, y, z;
817
818 while (!stck.empty()) {
819 x = val<1>(stck.top());
820 y = val<2>(stck.top());
821 z = val<3>(stck.top());
822 stck.pop();
823
824 FLAGS &flagType = flagfield(x, y, z);
825
826 if (flagType == UNDEF_FLAG) {
827 flagType = type;
828
829 if (flagfield.indicesInRange(x + 1, y, z))
830 stck.push(UbTupleInt3(x + 1, y, z));
831 if (flagfield.indicesInRange(x, y + 1, z))
832 stck.push(UbTupleInt3(x, y + 1, z));
833 if (flagfield.indicesInRange(x, y, z + 1))
834 stck.push(UbTupleInt3(x, y, z + 1));
835 if (flagfield.indicesInRange(x - 1, y, z))
836 stck.push(UbTupleInt3(x - 1, y, z));
837 if (flagfield.indicesInRange(x, y - 1, z))
838 stck.push(UbTupleInt3(x, y - 1, z));
839 if (flagfield.indicesInRange(x, y, z - 1))
840 stck.push(UbTupleInt3(x, y, z - 1));
841 }
842 }
843 return;
844}
847{
849 ss << "D3Q27TriFaceMeshInteractor[label=D3Q27TriFaceMeshInteractor";
850 if (this->isSolid())
851 ss << ", solid";
852 if (this->isInverseSolid())
853 ss << ", inversesolid";
854 if (this->isTimeDependent())
855 ss << ", timedependent";
856 if (geoObject3D != NULL)
857 ss << ", D3Q27TriFaceMeshInteractor: " << geoObject3D->toString();
858 ss << "]";
859
860 return ss.str();
861}
864{
865 using namespace vf::basics::constant;
866
867 // alle solid Bloecke wieder solid setzen
868 std::vector<SPtr<Block3D>> &solidBlocks = this->getSolidBlockSet();
869 for (size_t i = 0; i < solidBlocks.size(); i++) {
870 solidBlocks[i]->setActive(false); //<- quick n dirty
871 }
872
873 // alle solid-nodes wieder solid setzen (solids die quasi in den TransBloecken liegen)
874 std::map<SPtr<Block3D>, std::set<UbTupleInt3>>::iterator it1;
875 for (it1 = this->solidNodeIndicesMap.begin(); it1 != this->solidNodeIndicesMap.end(); ++it1) {
876 SPtr<Block3D> block = it1->first;
877
878 SPtr<LBMKernel> kernel = block->getKernel();
879 SPtr<BCArray3D> bcMatrix = kernel->getBCSet()->getBCArray();
880 std::set<UbTupleInt3> &indicesSet = it1->second;
881
882 for (std::set<UbTupleInt3>::iterator setIt = indicesSet.begin(); setIt != indicesSet.end(); ++setIt) {
883 bcMatrix->setSolid(val<1>(*setIt), val<2>(*setIt), val<3>(*setIt));
884 }
885 }
886
887 // BCS WIEDERHERSTELLEN
888 std::map<SPtr<Block3D>, std::map<UbTupleInt3, std::vector<float>>>::iterator it;
889 for (it = bcNodeIndicesAndQsMap.begin(); it != bcNodeIndicesAndQsMap.end(); ++it) {
890 SPtr<Block3D> block = it->first;
891 SPtr<LBMKernel> kernel = block->getKernel();
892 SPtr<BCArray3D> bcMatrix = kernel->getBCSet()->getBCArray();
893
894 std::map<UbTupleInt3, std::vector<float>>::iterator it2;
895 for (it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
896 const UbTupleInt3 &pos = it2->first;
897 std::vector<float> qs = it2->second;
898
899 // SG_27.08.2010
900 if (bcMatrix->isSolid(val<1>(pos), val<2>(pos), val<3>(pos)))
901 continue;
902
904 if (!bc) {
906 bcMatrix->setBC(val<1>(pos), val<2>(pos), val<3>(pos), bc);
907 }
908
909 double x1w = qs[d3q27_system::FENDDIR + 1 + 0];
910 double x2w = qs[d3q27_system::FENDDIR + 1 + 1];
911 double x3w = qs[d3q27_system::FENDDIR + 1 + 2];
912
913 // TODO: HACK DOES NOT BELONG HERE!!! - begin
914 // it is a static object and the propeller is there
915 // there are difficulties at the wing tips, that can come from
916 // that there are too many bc flags and at speed this results in quite large values
917 bc->setBoundaryVelocityX1(c0o1);
918 bc->setBoundaryVelocityX2(c0o1);
919 bc->setBoundaryVelocityX3(c0o1);
920 // TODO: HACK DOES NOT BELONG HERE!!! - end
921
922 bool gotQs = false;
923 for (int fdir = d3q27_system::FSTARTDIR; fdir <= d3q27_system::FENDDIR; fdir++) {
924 if (ub_math::greater(qs[fdir], -1.0) && ub_math::less(qs[fdir], bc->getQ(fdir))) {
925 gotQs = true;
926 for (size_t index = 0; index < this->BCs.size(); index++)
927 this->BCs[index]->adaptBCForDirection(*this, bc, x1w, x2w, x3w, qs[fdir], fdir);
928 }
929 }
930
931 if (gotQs)
932 for (size_t index = 0; index < this->BCs.size(); index++)
933 this->BCs[index]->adaptBC(*this, bc, x1w, x2w, x3w);
934 }
935 }
936}
942
Abstract class of baundary conditions adapter.
Definition BC.h:48
Definition of boundary conditions in grid generation.
A specialized class for grid generation.
real rayX3[d3q27_system::FENDDIR+1]
std::vector< SPtr< BC > > BCs
SolidNodeIndicesMap solidNodeIndicesMap
BcNodeIndicesMap bcNodeIndicesMap
real rayX2[d3q27_system::FENDDIR+1]
real rayX1[d3q27_system::FENDDIR+1]
std::map< SPtr< Block3D >, std::map< UbTupleInt3, std::vector< float > > > bcNodeIndicesAndQsMap
This Class provides basic 3D box objects.
Definition GbCuboid3D.h:53
This Class provides basic 3D vector objects.
Definition GbVector3D.h:47
WPtr< Grid3D > grid
SPtr< GbObject3D > geoObject3D
bool isTimeDependent()
void setTimeDependent()
std::vector< SPtr< Block3D > > solidBlocks
virtual std::vector< SPtr< Block3D > > & getSolidBlockSet()
bool isInverseSolid()
void unsetTimeDependent()
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
void initInteractor(const real &timeStep=0) override
bool setDifferencesToGbObject3D(const SPtr< Block3D > block) override
void iterativeGridFill(CbArray3D< FLAGS > &flagfield, const short &xs, const short &ys, const short &zs, const FLAGS &type)
void refineBlockGridToLevel(int level, real startDistance, real stopDistance)
void reinitWithStoredQs(const real &timeStep)
void updateInteractor(const real &timestep=0) override
void recursiveGridFill(CbArray3D< FLAGS > &flagfield, const short &xs, const short &ys, const short &zs, const FLAGS &type)
~D3Q27TriFaceMeshInteractor() override
void updateMovedGeometry(const real &timeStep=0)
void updateInteractor(const real &timestep=0) override
std::vector< Vertex > * getNodes()
std::vector< TriFace > * getTriangles()
@ z
Definition Axis.h:44
@ x
Definition Axis.h:42
@ y
Definition Axis.h:43
#define UBLOG(level, logtext)
Definition UbLogger.h:327
#define UB_EXARGS
Definition UbException.h:73
UbTuple< int, int, int > UbTupleInt3
Definition UbTuple.h:626
#define UBLOGML(level, multiline)
Definition UbLogger.h:337
@ logDEBUG1
Definition UbLogger.h:54
@ logDEBUG3
Definition UbLogger.h:54
int triBoxOverlap(float boxcenter[3], float boxhalfsize[3], float triverts[3][3])
int integerRounding(const T &value)
Definition UbMath.h:236
bool lessEqual(const T1 &value, const T2 &reference)
Definition UbMath.h:209
bool equal(const T1 &value, const T2 &reference)
Definition UbMath.h:189
const T & max(const T &a1, const T &a2)
Definition UbMath.h:371
bool greater(const T1 &value, const T2 &reference)
Definition UbMath.h:216
bool inClosedInterval(const T1 &value, const T2 &threshold1, const T3 &threshold2)
Definition UbMath.h:309
bool zero(const T &value)
Definition UbMath.h:139
bool less(const T1 &value, const T2 &reference)
Definition UbMath.h:202