VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
D3Q27GridWindingInteractor.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//
34//=======================================================================================
35
37
38#include "BC.h"
39#include "BCArray3D.h"
40#include "BCSet.h"
41#include "Block3D.h"
42#include "BoundaryConditions.h"
43#include "D3Q27System.h"
44#include "LBMKernel.h"
45#include "Grid3D.h"
46
47#include <basics/Timer/Timer.h>
52
53// #include <basics/geometry3d/winding/GeneralizedWindingNumber.h>
57
58#include <logger/Logger.h>
60#if defined(VF_MPI)
61#include <mpi.h>
62#endif
63
64#include <algorithm>
65#include <array>
66#include <cmath>
67#include <cstddef>
68#include <limits>
69#include <memory>
70#include <type_traits>
71#include <utility>
72#include <vector>
73
75{
76 auto gridPtr = grid.lock();
77 if (!gridPtr)
78 return;
79
80 setQs(timeStep);
81}
82
84
89
91
93{
94 if (!block || block->isNotActive())
95 return false;
96
97 auto kernel = block->getKernel();
98 if (!kernel)
99 return false;
100
101 auto bcSet = kernel->getBCSet();
102 if (!bcSet)
103 return false;
104
105 auto bcArray = bcSet->getBCArray();
106 if (!bcArray)
107 return false;
108
109 auto &bcNodes = bcNodeIndicesMap[block];
110 auto &solidNodes = solidNodeIndicesMap[block];
111 bcNodes.clear();
112 solidNodes.clear();
113
114 bool oneEntryGotBC = false;
115
116 const int nx1 = static_cast<int>(bcArray->getNX1());
117 const int nx2 = static_cast<int>(bcArray->getNX2());
118 const int nx3 = static_cast<int>(bcArray->getNX3());
119
120 for (int iz = 0; iz < nx3; ++iz) {
121 for (int iy = 0; iy < nx2; ++iy) {
122 for (int ix = 0; ix < nx1; ++ix) {
123 if (bcArray->isSolid(ix, iy, iz))
124 solidNodes.insert(UbTupleInt3(ix, iy, iz));
125 if (bcArray->hasBC(ix, iy, iz)) {
126 bcNodes.insert({ ix, iy, iz });
127 oneEntryGotBC = true;
128 }
129 }
130 }
131 }
132
133 return oneEntryGotBC;
134}
135
137
139{
140#if !defined(VF_HAS_FAST_WINDING)
141 UB_THROW(UbException(UB_EXARGS, "D3Q27GridWindingInteractor requires VF_HAS_FAST_WINDING"));
142#endif
143
144 auto gridPtr = grid.lock();
145 if (!gridPtr)
146 return;
147
148 auto surface = std::dynamic_pointer_cast<GbTriFaceMesh3D>(geoObject3D);
149 if (!surface) {
151 return;
152 }
153
154 auto bcSet = findBCSet(gridPtr);
155 if (!bcSet)
156 return;
157
159
161 computeBoundaryData(surface, gridPtr, bcSet, BCs, static_cast<double>(timeStep), comm, std::string(), config);
162
163 bcNodeIndicesMap.clear();
164 solidNodeIndicesMap.clear();
165 if (bcBlocks.empty())
166 rebuildNodeIndexMaps();
167 else
168 updateBlocks();
169
170 bool needTimeDependence = false;
171 for (const auto &bc : BCs) {
172 if (bc && bc->isTimeDependent())
173 needTimeDependence = true;
174 }
176 this->setTimeDependent();
177 else
178 this->unsetTimeDependent();
179}
180
182
185 const SPtr<Grid3D> &grid,
186 const SPtr<BCSet> &bcSet,
187 const std::vector<SPtr<BC>> &boundaryAdapters,
188 double timeStep,
190 const std::string &basePath,
192{
193 if (!surface || !grid || !bcSet)
194 return;
195
196 surface->calculateValues();
197
198 auto effectiveConfig = config;
199 // Let callers decide whether files are written; this helper
200 // simply forwards the configuration.
202 surface, grid, bcSet, boundaryAdapters, this, timeStep, comm, basePath, effectiveConfig);
203}
204
206
207void D3Q27GridWindingInteractor::rebuildNodeIndexMaps()
208{
209 bcNodeIndicesMap.clear();
210 solidNodeIndicesMap.clear();
211
212 auto gridPtr = grid.lock();
213 if (!gridPtr)
214 return;
215
216 const int coarsestLevel = gridPtr->getCoarsestInitializedLevel();
217 const int finestLevel = gridPtr->getFinestInitializedLevel();
218
219 for (int level = coarsestLevel; level <= finestLevel; ++level) {
220 std::vector<SPtr<Block3D>> blocks;
221 gridPtr->getBlocks(level, blocks);
222
223 for (const auto &block : blocks)
225 }
226}
227
229
230SPtr<BCSet> D3Q27GridWindingInteractor::findBCSet(const SPtr<Grid3D> &grid) const
231{
232 if (!grid)
233 return {};
234
235 const int coarsestLevel = grid->getCoarsestInitializedLevel();
236 const int finestLevel = grid->getFinestInitializedLevel();
237
238 for (int level = coarsestLevel; level <= finestLevel; ++level) {
239 std::vector<SPtr<Block3D>> blocks;
240 grid->getBlocks(level, blocks);
241
242 for (const auto &block : blocks) {
243 if (!block)
244 continue;
245 auto kernel = block->getKernel();
246 if (!kernel)
247 continue;
248 auto bcSet = kernel->getBCSet();
249 if (bcSet)
250 return bcSet;
251 }
252 }
253 return {};
254}
255
257
258namespace vf::grid_winding::cpu
259{
260static QLineCollection collectQLines(const SPtr<Grid3D> &grid,
262{
263 QLineCollection collection;
264 if (!grid)
265 return collection;
266
267 std::vector<double> coordsSend;
268 std::vector<float> qSend;
269 std::vector<float> qRawSend;
270 std::vector<float> deltaSend;
271 std::vector<int> dirSend;
272
273 const int coarsest = grid->getCoarsestInitializedLevel();
274 const int finest = grid->getFinestInitializedLevel();
275
276 for (int level = coarsest; level <= finest; ++level) {
277 std::vector<SPtr<Block3D>> blocks;
278 grid->getBlocks(level, blocks);
279 for (const auto &block : blocks) {
280 if (!block)
281 continue;
282
283 auto kernel = block->getKernel();
284 if (!kernel)
285 continue;
286
287 auto bcSet = kernel->getBCSet();
288 if (!bcSet)
289 continue;
290
291 auto bcArray = bcSet->getBCArray();
292 if (!bcArray)
293 continue;
294
295 const int nx = static_cast<int>(bcArray->getNX1());
296 const int ny = static_cast<int>(bcArray->getNX2());
297 const int nz = static_cast<int>(bcArray->getNX3());
298
299 const double dx = static_cast<double>(grid->getDeltaX(block));
300
301 for (int iz = 0; iz < nz; ++iz) {
302 for (int iy = 0; iy < ny; ++iy) {
303 for (int ix = 0; ix < nx; ++ix) {
304 if (!bcArray->hasBC(ix, iy, iz))
305 continue;
306
307 auto bc = bcArray->getBC(ix, iy, iz);
308 if (!bc)
309 continue;
310
311 GbVector3D originVec = grid->getNodeCoordinates(block, ix, iy, iz);
312 const double ox = originVec[0];
313 const double oy = originVec[1];
314 const double oz = originVec[2];
315
316 for (int dir = d3q27_system::FSTARTDIR; dir <= d3q27_system::FENDDIR; ++dir) {
317 const float rawQ = bc->getQ(dir);
318 if (ub_math::less(rawQ, 0.0f))
319 continue;
320
321 const int cx = d3q27_system::DX1[dir];
322 const int cy = d3q27_system::DX2[dir];
323 const int cz = d3q27_system::DX3[dir];
324 if (cx == 0 && cy == 0 && cz == 0)
325 continue;
326
327 const float clampedQ = std::clamp(rawQ, 0.0f, 1.0f);
328
329 const double hitX = ox + static_cast<double>(clampedQ) * dx * static_cast<double>(cx);
330 const double hitY = oy + static_cast<double>(clampedQ) * dx * static_cast<double>(cy);
331 const double hitZ = oz + static_cast<double>(clampedQ) * dx * static_cast<double>(cz);
332
333 coordsSend.push_back(ox);
334 coordsSend.push_back(oy);
335 coordsSend.push_back(oz);
336 coordsSend.push_back(hitX);
337 coordsSend.push_back(hitY);
338 coordsSend.push_back(hitZ);
339
340 dirSend.push_back(dir);
341 qSend.push_back(clampedQ);
342 qRawSend.push_back(rawQ);
343 deltaSend.push_back(static_cast<float>(dx));
344 }
345 }
346 }
347 }
348 }
349 }
350
351 std::vector<double> coordsRecv;
352 std::vector<int> dirRecv;
353 std::vector<float> qRecv;
354 std::vector<float> qRawRecv;
355 std::vector<float> deltaRecv;
356 if (comm) {
357 comm->allGather(coordsSend, coordsRecv);
358 comm->allGather(dirSend, dirRecv);
359 comm->allGather(qSend, qRecv);
360 comm->allGather(qRawSend, qRawRecv);
361 comm->allGather(deltaSend, deltaRecv);
362 } else {
365 qRecv = qSend;
368 }
369
370 if (comm && !comm->isRoot())
371 return collection;
372
373 if (coordsRecv.empty() || dirRecv.empty() || qRecv.empty())
374 return collection;
375
376 const std::size_t lineCount = qRecv.size();
377 if (coordsRecv.size() < lineCount * 6)
378 return collection;
379
381
382 return collection;
383}
384
386
387// Adapter that exposes Grid3D nodes to the shared fast-winding solid marker logic.
389{
390public:
392
393 struct Node
394 {
396 BCArray3D *bcArray{ nullptr };
397 int ix{ 0 };
398 int iy{ 0 };
399 int iz{ 0 };
400 };
401
402 CpuWindingSolidAccessor(const SPtr<Grid3D> &grid, std::array<double, 3> meshMin, std::array<double, 3> meshMax)
403 : grid_(grid), meshMin_(meshMin), meshMax_(meshMax)
404 {
405 if (grid_) {
406 const int coarsestLevel = grid_->getCoarsestInitializedLevel();
407 std::vector<SPtr<Block3D>> blocks;
408 grid_->getBlocks(coarsestLevel, blocks);
409 if (!blocks.empty())
410 cellSizeHint_ = static_cast<double>(grid_->getDeltaX(blocks.front()));
411 }
412 }
413
414 template <typename Fn>
416 {
417 const double faceEpsBase = vf::grid_winding::computeFaceEpsilon(meshMin_, meshMax_, cellSizeHint_);
418
419 if (!grid_)
420 return;
421
422 const int coarsestLevel = grid_->getCoarsestInitializedLevel();
423 const int finestLevel = grid_->getFinestInitializedLevel();
424
425 for (int level = coarsestLevel; level <= finestLevel; ++level) {
426 std::vector<SPtr<Block3D>> blocks;
427 grid_->getBlocks(level, blocks);
428 for (const auto &block : blocks) {
429 auto kernel = block->getKernel();
430 if (!kernel)
431 continue;
432
433 auto bcSet = kernel->getBCSet();
434 if (!bcSet)
435 continue;
436
437 auto bcArray = bcSet->getBCArray();
438 if (!bcArray)
439 continue;
440
441 real minX1, minX2, minX3, maxX1, maxX2, maxX3;
442
443 UbTupleDouble3 blockLengths = grid_->getBlockLengths(block);
444 UbTupleDouble3 org = grid_->getBlockWorldCoordinates(block);
445 UbTupleDouble3 nodeOffset = grid_->getNodeOffset(block);
446
447 minX1 = val<1>(org) + val<1>(nodeOffset);
448 minX2 = val<2>(org) + val<2>(nodeOffset);
449 minX3 = val<3>(org) + val<3>(nodeOffset);
453
454 const double deltaCell = static_cast<double>(grid_->getDeltaX(block));
455 const double faceEps =
456 std::max(faceEpsBase, ub_math::greater(deltaCell, 0.0) ? deltaCell * 1.0e-6 : 0.0);
457
458 if (ub_math::less(maxX1, meshMin_[0] - faceEps) ||
459 ub_math::greater(minX1, meshMax_[0] + faceEps) ||
460 ub_math::less(maxX2, meshMin_[1] - faceEps) ||
461 ub_math::greater(minX2, meshMax_[1] + faceEps) ||
462 ub_math::less(maxX3, meshMin_[2] - faceEps) ||
463 ub_math::greater(minX3, meshMax_[2] + faceEps)) {
464 continue;
465 }
466
467 const int NX = static_cast<int>(bcArray->getNX1()) - 1;
468 const int NY = static_cast<int>(bcArray->getNX2()) - 1;
469 const int NZ = static_cast<int>(bcArray->getNX3()) - 1;
470
471 for (int k = 0; k <= NZ; ++k)
472 for (int j = 0; j <= NY; ++j)
473 for (int i = 0; i <= NX; ++i) {
474 GbVector3D coord = grid_->getNodeCoordinates(block, i, j, k);
475 Node node;
476 node.position = Vec3{ coord[0], coord[1], coord[2] };
477 node.bcArray = bcArray.get();
478 node.ix = i;
479 node.iy = j;
480 node.iz = k;
481 fn(node);
482 }
483 }
484 }
485 }
486
487 void setSolid(const Node &node, float /*windingValue*/) const
488 {
489 if (!node.bcArray)
490 return;
491 if (!node.bcArray->isSolid(node.ix, node.iy, node.iz)) {
492 node.bcArray->setSolid(static_cast<std::size_t>(node.ix), static_cast<std::size_t>(node.iy),
493 static_cast<std::size_t>(node.iz));
494 }
495 }
496
497 [[nodiscard]] double cellSizeHint() const
498 {
499 return cellSizeHint_;
500 }
501
502private:
503 SPtr<Grid3D> grid_;
504 std::array<double, 3> meshMin_;
505 std::array<double, 3> meshMax_;
506 double cellSizeHint_{ 0.0 };
507};
508
509// void markSolidsWithWinding(const SPtr<Grid3D> &grid, const vf::geometry::GeneralizedWindingNumber &winding,
510// const std::array<double, 3> &meshMin, const std::array<double, 3> &meshMax,
511// double threshold, double tolerance)
512// {
513// CpuWindingSolidAccessor accessor(grid, meshMin, meshMax);
514// const double interiorBias = 2.0 * tolerance;
515// vf::grid_winding::markSolidsWithWinding(accessor, winding, meshMin, meshMax, threshold + interiorBias, 0.0);
516// }
517
518#if defined(VF_HAS_FAST_WINDING)
520 float accuracyScale, float threshold, float tolerance)
521{
522 if (!surface || !grid)
523 return;
524
525 const std::array<double, 3> meshMin{ surface->getX1Minimum(), surface->getX2Minimum(), surface->getX3Minimum() };
526 const std::array<double, 3> meshMax{ surface->getX1Maximum(), surface->getX2Maximum(), surface->getX3Maximum() };
527
528 CpuWindingSolidAccessor accessor(grid, meshMin, meshMax);
529 vf::grid_winding::markSolidsWithFastWinding(accessor, *surface, accuracyScale, threshold, tolerance);
530}
531
533
534#endif
535
536} // namespace vf::grid_winding::cpu
537
539
540namespace vf::grid_winding::cpu
541{
545
546namespace detail
547{
548inline void ensureBoundaryConditions(const SPtr<BCArray3D> &bcArray, int ix, int iy, int iz,
550{
551 outBc = bcArray->getBC(ix, iy, iz);
552 if (!outBc) {
553 outBc = std::make_shared<BoundaryConditions>();
554 bcArray->setBC(ix, iy, iz, outBc);
555 }
556}
557
559{
560 int ix{ 0 };
561 int iy{ 0 };
562 int iz{ 0 };
563 int dir{ 0 };
564 bool fluidLocal{ false };
565 bool solidLocal{ false };
566};
567
569{
570 int blockX1{ 0 };
571 int blockX2{ 0 };
572 int blockX3{ 0 };
573 int level{ 0 };
574 int dir{ 0 };
575 int ix{ 0 };
576 int iy{ 0 };
577 int iz{ 0 };
578};
579
580static_assert(std::is_trivially_copyable_v<RemoteBoundaryLinkMessage>,
581 "RemoteBoundaryLinkMessage must be trivially copyable for MPI exchange");
582
583} // namespace detail
584
586 const SPtr<BCSet> &bcSet,
587 const std::vector<SPtr<BC>> &boundaryAdapters,
588 const ::D3Q27Interactor *adapterInteractor,
589 double timeStep,
591{
592 using namespace detail;
593
594 if (!surface || !grid || !bcSet)
595 return;
596
597 auto *triangles = surface->getTriangles();
598 auto *nodes = surface->getNodes();
599 if (!nodes || !triangles || triangles->empty())
600 return;
601
602 surface->calculateValues();
603
604 const std::array<double, 3> meshMin{ surface->getX1Minimum(), surface->getX2Minimum(), surface->getX3Minimum() };
605 const std::array<double, 3> meshMax{ surface->getX1Maximum(), surface->getX2Maximum(), surface->getX3Maximum() };
606
607 std::vector<GbTriFaceMesh3D *> meshes{ surface.get() };
609
610 const bool hasAdapters = (adapterInteractor != nullptr && !boundaryAdapters.empty());
611 if (hasAdapters) {
612 for (const auto &adapter : boundaryAdapters) {
613 if (adapter)
614 adapter->init(adapterInteractor, timeStep);
615 }
616 }
617
618 auto communicator = vf::parallel::Communicator::getInstance();
619 int currentRank = communicator ? communicator->getProcessID() : 0;
620 int worldSize = communicator ? communicator->getNumberOfProcesses() : 1;
621 if (worldSize <= 0)
622 worldSize = 1;
623
624 const bool isRootRank = !communicator || communicator->isRoot();
625 if (isRootRank && meshes.size() > 0 && kdTrees.empty()) {
626 VF_LOG_WARNING("No kd-tree available for grid-winding; falling back to triangle list intersections.");
627 }
628
629#if defined(VF_MPI)
631 if (communicator) {
632 if (void *native = communicator->getNativeCommunicator()) {
633 mpiComm = *static_cast<MPI_Comm *>(native);
634 }
635 currentRank = communicator->getProcessID();
636 worldSize = communicator->getNumberOfProcesses();
637 if (worldSize <= 0)
638 worldSize = 1;
639 } else {
642 if (worldSize <= 0)
643 worldSize = 1;
644 }
645#endif
646
647 std::vector<std::vector<detail::RemoteBoundaryLinkMessage>> remoteMessages(
648 static_cast<std::size_t>(worldSize));
649
650 struct PromotedSolid
651 {
652 SPtr<Block3D> block;
653 int ix{ 0 };
654 int iy{ 0 };
655 int iz{ 0 };
656 };
657
658 std::vector<PromotedSolid> promotedSolids;
659 promotedSolids.reserve(128);
660
661 struct CpuKdAdapter
662 {
663 BCArray3D *bcArray{ nullptr };
664 const std::vector<SPtr<BC>> *boundaryAdapters{ nullptr };
665 const ::D3Q27Interactor *adapterInteractor{ nullptr };
666 bool hasAdapters{ false };
667 SubgridDistanceStats *stats{ nullptr };
669 std::vector<PromotedSolid> *promotedSolids{ nullptr };
670 int ix{ 0 };
671 int iy{ 0 };
672 int iz{ 0 };
673 int dir{ 0 };
674 bool solidLocal{ false };
675 Vec3 origin{};
676
678 {
679 if (!bcArray)
680 return false;
681 if (!bcArray->isFluid(static_cast<std::size_t>(ix),
682 static_cast<std::size_t>(iy),
683 static_cast<std::size_t>(iz)))
684 return false;
685 bcArray->setSolid(static_cast<std::size_t>(ix),
686 static_cast<std::size_t>(iy),
687 static_cast<std::size_t>(iz));
688 return true;
689 }
690
691 double existingQ(const vf::grid_winding::BoundaryLink &) const
692 {
693 if (!bcArray)
694 return -1.0;
695 auto bc = bcArray->getBC(ix, iy, iz);
696 if (!bc)
697 return -1.0;
698 return static_cast<double>(bc->getQ(dir));
699 }
700
701 void setQ(const vf::grid_winding::BoundaryLink &, double q, int) const
702 {
703 if (!bcArray)
704 return;
705 if (bcArray->isSolid(static_cast<std::size_t>(ix),
706 static_cast<std::size_t>(iy),
707 static_cast<std::size_t>(iz)))
708 return;
709
710 // if (ub_math::zero(q)) {
711 // bcArray->setSolid(static_cast<std::size_t>(ix),
712 // static_cast<std::size_t>(iy),
713 // static_cast<std::size_t>(iz));
714 // if (stats)
715 // ++stats->promotedZeroQNodes;
716 // if (promotedSolids && ownerBlock)
717 // promotedSolids->push_back(PromotedSolid{ ownerBlock, ix, iy, iz });
718 // return;
719 // }
720
721 auto bc = bcArray->getBC(ix, iy, iz);
722 if (!bc) {
723 bc = std::make_shared<BoundaryConditions>();
724 bcArray->setBC(ix, iy, iz, bc);
725 }
726 bc->setQ(static_cast<float>(q), dir);
727
729 const double ox = origin.X1();
730 const double oy = origin.X2();
731 const double oz = origin.X3();
732
733 for (auto it = boundaryAdapters->rbegin(); it != boundaryAdapters->rend(); ++it) {
734 if (*it)
735 (*it)->adaptBCForDirection(*adapterInteractor, bc, ox, oy, oz, q, dir);
736 }
737 for (auto it = boundaryAdapters->rbegin(); it != boundaryAdapters->rend(); ++it) {
738 if (*it)
739 (*it)->adaptBC(*adapterInteractor, bc, ox, oy, oz);
740 }
741 }
742 }
743
744 void markSurface(const vf::grid_winding::BoundaryLink &, double, int) const {}
745
746 std::pair<bool, double> windingNumber(const vf::grid_winding::BoundaryLink &) const
747 {
748 return { false, 0.0 };
749 }
750
753 {
754 if (!bcArray)
755 return false;
756
757 auto bc = bcArray->getBC(ix, iy, iz);
758 if (!bc) {
759 bc = std::make_shared<BoundaryConditions>();
760 bcArray->setBC(ix, iy, iz, bc);
761 }
762
764 bc->setQ(static_cast<float>(fallbackQ), dir);
765
767 const double ox = origin.X1();
768 const double oy = origin.X2();
769 const double oz = origin.X3();
770 for (auto it = boundaryAdapters->rbegin(); it != boundaryAdapters->rend(); ++it) {
771 if (*it)
772 (*it)->adaptBCForDirection(*adapterInteractor, bc, ox, oy, oz,
773 fallbackQ, dir);
774 }
775 for (auto it = boundaryAdapters->rbegin(); it != boundaryAdapters->rend(); ++it) {
776 if (*it)
777 (*it)->adaptBC(*adapterInteractor, bc, ox, oy, oz);
778 }
779 }
780 return true;
781 }
782 };
783
785
786 auto processLinkForBlock = [&](const SPtr<Block3D> &ownerBlock, int ix, int iy, int iz, int dir,
788 if (!ownerBlock)
789 return;
790
791 auto kernel = ownerBlock->getKernel();
792 if (!kernel)
793 return;
794
795 auto bcSet = kernel->getBCSet();
796 if (!bcSet)
797 return;
798
799 auto bcArray = bcSet->getBCArray();
800 if (!bcArray)
801 return;
802
803 // if (!allowGhost && !kernel->isInsideOfDomain(ix, iy, iz)) {
804 // if (linkStats)
805 // ++linkStats->skippedNonLocalLinks;
806 // return;
807 // }
808
809 if (linkStats)
810 ++linkStats->totalLinks;
811
812 if (!bcArray->isFluid(static_cast<std::size_t>(ix), static_cast<std::size_t>(iy),
813 static_cast<std::size_t>(iz))) {
814 if (bcArray->isSolid(static_cast<std::size_t>(ix), static_cast<std::size_t>(iy),
815 static_cast<std::size_t>(iz)))
816 return;
817 bcArray->setFluid(static_cast<std::size_t>(ix), static_cast<std::size_t>(iy),
818 static_cast<std::size_t>(iz));
819 }
820
821 const double dxLocal = static_cast<double>(grid->getDeltaX(ownerBlock));
822 GbVector3D originVec = grid->getNodeCoordinates(ownerBlock, ix, iy, iz);
823 Vec3 origin{ originVec[0], originVec[1], originVec[2] };
824
825 const int cx = d3q27_system::DX1[dir];
826 const int cy = d3q27_system::DX2[dir];
827 const int cz = d3q27_system::DX3[dir];
828
829 const int solidX = ix + cx;
830 const int solidY = iy + cy;
831 const int solidZ = iz + cz;
832 const bool solidLocal = kernel->isInsideOfDomain(solidX, solidY, solidZ);
833
834 adapter.bcArray = bcArray.get();
835 adapter.boundaryAdapters = &boundaryAdapters;
836 adapter.adapterInteractor = adapterInteractor;
837 adapter.hasAdapters = hasAdapters;
838 adapter.stats = linkStats;
839 adapter.ownerBlock = ownerBlock;
840 adapter.promotedSolids = &promotedSolids;
841 adapter.ix = ix;
842 adapter.iy = iy;
843 adapter.iz = iz;
844 adapter.dir = dir;
845 adapter.solidLocal = solidLocal;
846 adapter.origin = origin;
847
849 link.origin = origin;
850 link.neighbour = Vec3{ origin.X1() + dxLocal * static_cast<double>(cx),
851 origin.X2() + dxLocal * static_cast<double>(cy),
852 origin.X3() + dxLocal * static_cast<double>(cz) };
853 link.direction = dir;
854
856 auto insideGeometry = [&](const Vec3 &p) {
857 return ub_math::greaterEqual(p.X1(), meshMin[0] - faceEps) &&
858 ub_math::lessEqual(p.X1(), meshMax[0] + faceEps) &&
860 ub_math::lessEqual(p.X2(), meshMax[1] + faceEps) &&
863 };
864 if (!insideGeometry(link.origin) && !insideGeometry(link.neighbour)) {
865 return;
866 }
867
868 if (!kdTrees.empty()) {
871 } else {
872 auto promoteSolid = [&]() -> bool {
873 return adapter.promoteSolid(link);
874 };
875
876 auto existingQ = [&]() -> double {
877 return adapter.existingQ(link);
878 };
879
880 auto setQ = [&](double q, int patchIndex) {
881 adapter.setQ(link, q, patchIndex);
882 };
883
884 auto markSurface = [&](double q, int patchIndex) {
885 adapter.markSurface(link, q, patchIndex);
886 };
887
888 auto getWindingValue = [&]() -> std::pair<bool, double> {
889 return adapter.windingNumber(link);
890 };
891
892 auto handleMissing = [&](int /*missingDir*/, const Vec3 &, const Vec3 &,
893 SubgridDistanceStats::MissingLink &missing) -> bool {
894 return adapter.handleMissing(link, missing);
895 };
896
897 processBoundaryLink(meshes, origin, dxLocal, cx, cy, cz, dir, promoteSolid, existingQ,
899 }
900 };
901
902 const int coarsestLevel = grid->getCoarsestInitializedLevel();
903 const int finestLevel = grid->getFinestInitializedLevel();
904
905 for (int level = coarsestLevel; level <= finestLevel; ++level) {
906 std::vector<SPtr<Block3D>> blocks;
907 grid->getBlocks(level, blocks);
908 for (const auto &block : blocks) {
909 auto kernel = block->getKernel();
910 if (!kernel)
911 continue;
912
913 auto blockBcSet = kernel->getBCSet();
914 if (!blockBcSet)
915 continue;
916 auto bcArray = blockBcSet->getBCArray();
917 if (!bcArray)
918 continue;
919
920 const int nx = static_cast<int>(bcArray->getNX1());
921 const int ny = static_cast<int>(bcArray->getNX2());
922 const int nz = static_cast<int>(bcArray->getNX3());
923
924 std::vector<BoundaryLink> boundaryLinks;
925 boundaryLinks.reserve(static_cast<std::size_t>(nx * ny));
926
927 // Collect boundary links by scanning solid cells for adjacent fluid neighbours.
928 for (int iz = 0; iz < nz; ++iz) {
929 for (int iy = 0; iy < ny; ++iy) {
930 for (int ix = 0; ix < nx; ++ix) {
931 if (!bcArray->isSolid(ix, iy, iz))
932 continue;
933
934 // const bool solidLocal = kernel->isInsideOfDomain(ix, iy, iz);
935 bool solidLocal = true;
936
937 for (int dir = d3q27_system::FSTARTDIR; dir <= d3q27_system::FENDDIR; ++dir) {
938 const int cx = d3q27_system::DX1[dir];
939 const int cy = d3q27_system::DX2[dir];
940 const int cz = d3q27_system::DX3[dir];
941 if (cx == 0 && cy == 0 && cz == 0)
942 continue;
943
944 const int fluidX = ix + cx;
945 const int fluidY = iy + cy;
946 const int fluidZ = iz + cz;
947 if (fluidX < 0 || fluidY < 0 || fluidZ < 0 || fluidX >= nx || fluidY >= ny ||
948 fluidZ >= nz)
949 continue;
950
951 if (bcArray->isSolid(static_cast<std::size_t>(fluidX), static_cast<std::size_t>(fluidY),
952 static_cast<std::size_t>(fluidZ)))
953 continue;
954
955 // const bool fluidLocal = kernel->isInsideOfDomain(fluidX, fluidY, fluidZ);
956 bool fluidLocal = true;
957 if (!solidLocal && !fluidLocal)
958 continue;
959
960 const int fluidDir = d3q27_system::INVDIR[dir];
961 if (fluidDir < d3q27_system::FSTARTDIR || fluidDir > d3q27_system::FENDDIR)
962 continue;
963
964 boundaryLinks.push_back(
965 BoundaryLink{ fluidX, fluidY, fluidZ, fluidDir, fluidLocal, solidLocal });
966 }
967 }
968 }
969 }
970
971 for (int iz = 0; iz < nz; ++iz) {
972 for (int iy = 0; iy < ny; ++iy) {
973 for (int ix = 0; ix < nx; ++ix) {
974 // if (!kernel->isInsideOfDomain(ix, iy, iz))
975 // continue;
976 if (bcArray->isSolid(ix, iy, iz))
977 continue;
978
979 const bool originFluid = bcArray->isFluid(ix, iy, iz);
980 const bool originUndefined = bcArray->isUndefined(ix, iy, iz);
982 continue;
983
984 for (int dir = d3q27_system::FSTARTDIR; dir <= d3q27_system::FENDDIR; ++dir) {
985 const int cx = d3q27_system::DX1[dir];
986 const int cy = d3q27_system::DX2[dir];
987 const int cz = d3q27_system::DX3[dir];
988 if (cx == 0 && cy == 0 && cz == 0)
989 continue;
990
991 const int solidX = ix + cx;
992 const int solidY = iy + cy;
993 const int solidZ = iz + cz;
994 if (solidX < 0 || solidY < 0 || solidZ < 0 || solidX >= nx || solidY >= ny ||
995 solidZ >= nz)
996 continue;
997
998 if (!bcArray->isSolid(static_cast<std::size_t>(solidX), static_cast<std::size_t>(solidY),
999 static_cast<std::size_t>(solidZ)))
1000 continue;
1001
1002 // const bool solidLocal = kernel->isInsideOfDomain(solidX, solidY, solidZ);
1003 const bool solidLocal = true;
1004
1005 boundaryLinks.push_back(
1006 BoundaryLink{ ix, iy, iz, dir, true, solidLocal });
1007 }
1008 }
1009 }
1010 }
1011
1012 if (boundaryLinks.empty())
1013 continue;
1014
1015 std::sort(boundaryLinks.begin(), boundaryLinks.end(),
1016 [](const BoundaryLink &lhs, const BoundaryLink &rhs) {
1017 if (lhs.ix != rhs.ix)
1018 return lhs.ix < rhs.ix;
1019 if (lhs.iy != rhs.iy)
1020 return lhs.iy < rhs.iy;
1021 if (lhs.iz != rhs.iz)
1022 return lhs.iz < rhs.iz;
1023 return lhs.dir < rhs.dir;
1024 });
1025
1026 std::vector<BoundaryLink> uniqueLinks;
1027 uniqueLinks.reserve(boundaryLinks.size());
1028 for (const auto &link : boundaryLinks) {
1029 if (!uniqueLinks.empty() && uniqueLinks.back().ix == link.ix && uniqueLinks.back().iy == link.iy &&
1030 uniqueLinks.back().iz == link.iz && uniqueLinks.back().dir == link.dir) {
1031 auto &entry = uniqueLinks.back();
1032 entry.fluidLocal = entry.fluidLocal || link.fluidLocal;
1033 entry.solidLocal = entry.solidLocal || link.solidLocal;
1034 } else {
1035 uniqueLinks.push_back(link);
1036 }
1037 }
1039
1040 for (const auto &link : boundaryLinks) {
1041 if (link.fluidLocal) {
1042 processLinkForBlock(block, link.ix, link.iy, link.iz, link.dir, stats, false);
1043 continue;
1044 }
1045
1046 GbVector3D originVec = grid->getNodeCoordinates(block, link.ix, link.iy, link.iz);
1048 grid->getBlockIndexes(originVec[0], originVec[1], originVec[2], block->getLevel());
1050 grid->getBlock(val<1>(ownerIndices), val<2>(ownerIndices), val<3>(ownerIndices), block->getLevel());
1051 if (!ownerBlock)
1052 continue;
1053
1054 UbTupleInt3 nodeIdx = grid->getNodeIndexes(ownerBlock, originVec[0], originVec[1], originVec[2]);
1055 const int ownerRank = ownerBlock->getRank();
1056
1057 if (ownerRank == currentRank) {
1059 stats, false);
1060 } else if (ownerRank >= 0 && ownerRank < worldSize) {
1061 if (stats)
1062 ++stats->skippedNonLocalLinks;
1064 msg.blockX1 = ownerBlock->getX1();
1065 msg.blockX2 = ownerBlock->getX2();
1066 msg.blockX3 = ownerBlock->getX3();
1067 msg.level = ownerBlock->getLevel();
1068 msg.dir = link.dir;
1069 msg.ix = val<1>(nodeIdx);
1070 msg.iy = val<2>(nodeIdx);
1071 msg.iz = val<3>(nodeIdx);
1072 remoteMessages[static_cast<std::size_t>(ownerRank)].push_back(msg);
1073 }
1074 }
1075 }
1076
1077 }
1078
1079#if defined(VF_MPI)
1080 if (worldSize > 1) {
1081 std::vector<int> sendCounts(static_cast<std::size_t>(worldSize), 0);
1082 std::vector<int> sendDispls(static_cast<std::size_t>(worldSize), 0);
1083 std::vector<detail::RemoteBoundaryLinkMessage> sendBuffer;
1084 int offset = 0;
1085 for (int dest = 0; dest < worldSize; ++dest) {
1086 if (dest == currentRank) {
1087 sendDispls[static_cast<std::size_t>(dest)] = offset;
1088 continue;
1089 }
1090 auto &entries = remoteMessages[static_cast<std::size_t>(dest)];
1091 sendCounts[static_cast<std::size_t>(dest)] = static_cast<int>(entries.size());
1092 sendDispls[static_cast<std::size_t>(dest)] = offset;
1093 offset += sendCounts[static_cast<std::size_t>(dest)];
1094 sendBuffer.insert(sendBuffer.end(), entries.begin(), entries.end());
1095 }
1096
1097 std::vector<int> recvCounts(static_cast<std::size_t>(worldSize), 0);
1098 MPI_Alltoall(sendCounts.data(), 1, MPI_INT, recvCounts.data(), 1, MPI_INT, mpiComm);
1099
1100 std::vector<int> recvDispls(static_cast<std::size_t>(worldSize), 0);
1101 int totalRecv = 0;
1102 for (int i = 0; i < worldSize; ++i) {
1103 recvDispls[static_cast<std::size_t>(i)] = totalRecv;
1104 totalRecv += recvCounts[static_cast<std::size_t>(i)];
1105 }
1106 std::vector<detail::RemoteBoundaryLinkMessage> recvBuffer(static_cast<std::size_t>(totalRecv));
1107
1108 const int messageBytes = static_cast<int>(sizeof(detail::RemoteBoundaryLinkMessage));
1109 std::vector<int> sendCountsBytes(static_cast<std::size_t>(worldSize), 0);
1110 std::vector<int> sendDisplsBytes(static_cast<std::size_t>(worldSize), 0);
1111 std::vector<int> recvCountsBytes(static_cast<std::size_t>(worldSize), 0);
1112 std::vector<int> recvDisplsBytes(static_cast<std::size_t>(worldSize), 0);
1113
1114 for (int i = 0; i < worldSize; ++i) {
1115 sendCountsBytes[static_cast<std::size_t>(i)] = sendCounts[static_cast<std::size_t>(i)] * messageBytes;
1116 sendDisplsBytes[static_cast<std::size_t>(i)] = sendDispls[static_cast<std::size_t>(i)] * messageBytes;
1117 recvCountsBytes[static_cast<std::size_t>(i)] = recvCounts[static_cast<std::size_t>(i)] * messageBytes;
1118 recvDisplsBytes[static_cast<std::size_t>(i)] = recvDispls[static_cast<std::size_t>(i)] * messageBytes;
1119 }
1120
1123
1124 for (const auto &msg : recvBuffer) {
1125 SPtr<Block3D> ownerBlock = grid->getBlock(msg.blockX1, msg.blockX2, msg.blockX3, msg.level);
1126 if (!ownerBlock)
1127 continue;
1128 if (ownerBlock->getRank() != currentRank)
1129 continue;
1130 processLinkForBlock(ownerBlock, msg.ix, msg.iy, msg.iz, msg.dir, stats, false);
1131 }
1132 }
1133#else
1136#endif
1137
1138 if (!promotedSolids.empty()) {
1139 const std::size_t promotedCount = promotedSolids.size();
1140 for (std::size_t idx = 0; idx < promotedCount; ++idx) {
1141 const auto &promoted = promotedSolids[idx];
1142 auto block = promoted.block;
1143 if (!block)
1144 continue;
1145
1146 auto kernel = block->getKernel();
1147 if (!kernel)
1148 continue;
1149
1150 auto blockBcSet = kernel->getBCSet();
1151 if (!blockBcSet)
1152 continue;
1153 auto bcArray = blockBcSet->getBCArray();
1154 if (!bcArray)
1155 continue;
1156
1157 const int nx = static_cast<int>(bcArray->getNX1());
1158 const int ny = static_cast<int>(bcArray->getNX2());
1159 const int nz = static_cast<int>(bcArray->getNX3());
1160
1161 for (int dir = d3q27_system::FSTARTDIR; dir <= d3q27_system::FENDDIR; ++dir) {
1162 const int cx = d3q27_system::DX1[dir];
1163 const int cy = d3q27_system::DX2[dir];
1164 const int cz = d3q27_system::DX3[dir];
1165 if (cx == 0 && cy == 0 && cz == 0)
1166 continue;
1167
1168 const int fluidX = promoted.ix + cx;
1169 const int fluidY = promoted.iy + cy;
1170 const int fluidZ = promoted.iz + cz;
1171 if (fluidX < 0 || fluidY < 0 || fluidZ < 0 || fluidX >= nx || fluidY >= ny || fluidZ >= nz)
1172 continue;
1173
1174 if (bcArray->isSolid(static_cast<std::size_t>(fluidX), static_cast<std::size_t>(fluidY),
1175 static_cast<std::size_t>(fluidZ)))
1176 continue;
1177
1178 const int fluidDir = d3q27_system::INVDIR[dir];
1179 if (fluidDir < d3q27_system::FSTARTDIR || fluidDir > d3q27_system::FENDDIR)
1180 continue;
1181
1182 processLinkForBlock(block, fluidX, fluidY, fluidZ, fluidDir, stats, false);
1183 }
1184 }
1185 }
1186}
1187
1189
1190} // namespace vf::grid_winding::cpu
1191
1193
1194namespace vf::grid_winding::cpu
1195{
1198 const SPtr<Grid3D> &grid,
1199 const SPtr<BCSet> &bcSet,
1200 const std::vector<SPtr<BC>> &boundaryAdapters,
1201 const ::D3Q27Interactor *adapterInteractor,
1202 double timeStep,
1204 const std::string &basePath,
1205 const BoundaryProcessingConfig &config)
1206{
1208
1209 if (!surface || !grid || !bcSet)
1210 return result;
1211
1212 int rank = 0;
1213 if (comm) {
1214 rank = comm->getProcessID();
1215 }
1216
1217#if defined(VF_HAS_FAST_WINDING)
1218 {
1221 // Use shared defaults for accuracy/tolerance and keep the threshold configurable.
1222 vf::grid_winding::cpu::markSolidsWithFastWinding(
1223 surface, grid,
1225 config.fastWindingThreshold,
1227 VF_LOG_INFO("CPU fast-winding classification completed on rank {} in {} sec",
1228 rank,
1229 windingTimer.getCurrentRuntimeInSeconds());
1230 }
1231#endif
1232
1234 qTimer.start();
1235
1237 surface, grid, bcSet, boundaryAdapters, adapterInteractor, timeStep, &result.stats);
1238
1239 VF_LOG_INFO("CPU subgrid link computation finished on rank {} in {} sec "
1240 "(hits={}, total={}, promoted={}, skipped={})",
1241 rank,
1242 qTimer.getCurrentRuntimeInSeconds(),
1243 result.stats.hitLinks,
1244 result.stats.totalLinks,
1245 result.stats.promotedFluidNodes,
1246 result.stats.skippedNonLocalLinks);
1247
1248 if (comm) {
1249 std::vector<double> promotedTotals{ static_cast<double>(result.stats.promotedFluidNodes) };
1250 std::vector<double> promotedZeroQ{ static_cast<double>(result.stats.promotedZeroQNodes) };
1251 comm->allReduceSum(promotedTotals);
1252 comm->allReduceSum(promotedZeroQ);
1253 if (comm->isRoot()) {
1254 VF_LOG_INFO("CPU total promotions (solid) total: {}", static_cast<uint64_t>(promotedTotals.front()));
1255 VF_LOG_INFO("CPU zero-q promotions (solid) total: {}", static_cast<uint64_t>(promotedZeroQ.front()));
1256 }
1257 } else {
1258 VF_LOG_INFO("CPU total promotions (solid) total: {}", result.stats.promotedFluidNodes);
1259 VF_LOG_INFO("CPU zero-q promotions (solid) total: {}", result.stats.promotedZeroQNodes);
1260 }
1261
1262 const auto &stats = result.stats;
1263 if (stats.totalLinks == stats.hitLinks) {
1264 VF_LOG_INFO("All CPU boundary links intersected the geometry on rank {}.", rank);
1265 } else {
1266 VF_LOG_WARNING("Some CPU boundary links did not intersect the geometry on rank {}.", rank);
1267 if (stats.skippedNonLocalLinks > 0) {
1268 // VF_LOG_INFO("Skipped {} ghost boundary links that were not owned by rank {}.",
1269 // stats.skippedNonLocalLinks, rank);
1270 }
1271 }
1272
1273 if (config.writeMissingLinks) {
1276 result.missingLinks = vf::grid_winding::collectMissingLinks(result.stats, comm);
1277
1278 if (comm && comm->isRoot() && !basePath.empty()) {
1279 VF_LOG_INFO("CPU missing-link aggregation completed in {} sec",
1280 missingTimer.getCurrentRuntimeInSeconds());
1281 }
1282 } else if (comm && comm->isRoot()) {
1283 VF_LOG_INFO("CPU missing-link diagnostics disabled; skipping aggregation.");
1284 }
1285
1286 if (config.writeQLines) {
1289 result.qLines = vf::grid_winding::cpu::collectQLines(
1290 grid, comm);
1291
1292 if (comm && comm->isRoot() && !basePath.empty()) {
1293 VF_LOG_INFO("CPU Q-line collection completed in {} sec",
1294 qCollectTimer.getCurrentRuntimeInSeconds());
1295 }
1296 } else if (comm && comm->isRoot()) {
1297 VF_LOG_INFO("CPU Q-line diagnostics disabled; skipping collection.");
1298 }
1299
1300 return result;
1301}
1302} // namespace vf::grid_winding::cpu
1303
#define VF_LOG_INFO(...)
Definition Logger.h:50
#define VF_LOG_WARNING(...)
Definition Logger.h:51
A class implements array to store boundary conditions flags.
Definition BCArray3D.h:47
std::vector< SPtr< BC > > BCs
SolidNodeIndicesMap solidNodeIndicesMap
BcNodeIndicesMap bcNodeIndicesMap
This Class provides basic 3D vector objects.
Definition GbVector3D.h:47
WPtr< Grid3D > grid
SPtr< GbObject3D > geoObject3D
void setTimeDependent()
void unsetTimeDependent()
std::vector< SPtr< Block3D > > bcBlocks
CpuWindingSolidAccessor(const SPtr< Grid3D > &grid, std::array< double, 3 > meshMin, std::array< double, 3 > meshMax)
static std::shared_ptr< Communicator > getInstance()
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
bool isSolid(std::size_t x1, std::size_t x2, std::size_t x3) const
Definition BCArray3D.h:183
void setSolid(std::size_t x1, std::size_t x2, std::size_t x3)
Definition BCArray3D.cpp:97
void initInteractor(const real &timeStep=0) override
void initInteractor(const real &timeStep=0) override
void computeBoundaryData(const SPtr< GbTriFaceMesh3D > &surface, const SPtr< Grid3D > &grid, const SPtr< BCSet > &bcSet, const std::vector< SPtr< BC > > &boundaryAdapters, double timeStep, const SPtr< vf::parallel::Communicator > &comm, const std::string &basePath, const vf::grid_winding::cpu::BoundaryProcessingConfig &config)
Compute subgrid distances and Q-values for the current geometry/grid setup.
void updateInteractor(const real &timestep=0) override
void updateInteractor(const real &timestep=0) override
bool setDifferencesToGbObject3D(const SPtr< Block3D > block) override
double X1() const
const real dx
const uint ny
const uint nz
const uint nx
#define UB_THROW(e)
Definition UbException.h:78
#define UB_EXARGS
Definition UbException.h:73
const int INVDIR[]
const int DX1[]
const int DX3[]
const int DX2[]
bool greaterEqual(const T1 &value, const T2 &reference)
Definition UbMath.h:223
bool lessEqual(const T1 &value, const T2 &reference)
Definition UbMath.h:209
bool greater(const T1 &value, const T2 &reference)
Definition UbMath.h:216
bool less(const T1 &value, const T2 &reference)
Definition UbMath.h:202
void ensureBoundaryConditions(const SPtr< BCArray3D > &bcArray, int ix, int iy, int iz, SPtr< BoundaryConditions > &outBc)
void computeSubgridDistancesStandalone(const SPtr< GbTriFaceMesh3D > &surface, const SPtr< Grid3D > &grid, const SPtr< BCSet > &bcSet, const std::vector< SPtr< BC > > &boundaryAdapters, const ::D3Q27Interactor *adapterInteractor, double timeStep, SubgridDistanceStats *stats)
BoundaryProcessingResult processBoundaryData(const SPtr< GbTriFaceMesh3D > &surface, const SPtr< Grid3D > &grid, const SPtr< BCSet > &bcSet, const std::vector< SPtr< BC > > &boundaryAdapters, const ::D3Q27Interactor *adapterInteractor, double timeStep, const SPtr< vf::parallel::Communicator > &comm, const std::string &basePath, const BoundaryProcessingConfig &config)
constexpr float FastWindingDefaultAccuracyScale
Default fast-winding accuracy scale used in computeSolidAngle(...).
bool processBoundaryLink(const TriangleSurfaces &surfaces, const Vec3 &origin, double dx, int cx, int cy, int cz, int direction, PromoteSolidFn &&promoteSolid, ExistingQFn &&existingQ, SetQFn &&setQ, MarkSurfaceFn &&markSurface, GetWindingFn &&getWindingNumber, HandleMissingFn &&handleMissing, SubgridDistanceStats *stats)
QLineCollection buildQLineCollection(const std::vector< double > &coordsRecv, const std::vector< int > &dirRecv, const std::vector< float > &qRecv)
Build a QLineCollection from gathered coordinate / direction / q buffers.
double computeFaceEpsilon(const std::array< double, 3 > &meshMin, const std::array< double, 3 > &meshMax, double cellScale=0.0)
MissingLinkCollection collectMissingLinks(const SubgridDistanceStats &stats, const SPtr< vf::parallel::Communicator > &comm)
constexpr float FastWindingDefaultTolerance
Default comparison tolerance near the threshold.
bool processBoundaryLinkKdTree(const std::vector< kd_tree::Tree< double > * > &kdTrees, Adapter &adapter, const BoundaryLink &link, SubgridDistanceStats *stats=nullptr, const QComputationConfig &cfg={})
Compute Q for a single boundary link using kd-tree based ray casting.
std::vector< kd_tree::Tree< double > * > ensureKdTrees(const std::vector< GbTriFaceMesh3D * > &meshes)