45 Foam::shellSurfaces::refineModeNames_
47 { refineMode::INSIDE,
"inside" },
48 { refineMode::OUTSIDE,
"outside" },
49 { refineMode::DISTANCE,
"distance" },
55 void Foam::shellSurfaces::setAndCheckLevels
58 const List<Tuple2<scalar, label>>& distLevels
61 const searchableSurface& shell = allGeometry_[shells_[shellI]];
63 if (modes_[shellI] !=
DISTANCE && distLevels.size() != 1)
66 <<
"For refinement mode "
67 << refineModeNames_[modes_[shellI]]
68 <<
" specify only one distance+level."
69 <<
" (its distance gets discarded)"
73 distances_[shellI].
setSize(distLevels.size());
74 levels_[shellI].
setSize(distLevels.size());
78 distances_[shellI][j] = distLevels[j].first();
79 levels_[shellI][j] = distLevels[j].second();
81 if (levels_[shellI][j] < -1)
84 <<
"Shell " << shell.name()
85 <<
" has illegal refinement level "
96 (distances_[shellI][j] <= distances_[shellI][j-1])
97 || (levels_[shellI][j] > levels_[shellI][j-1])
101 <<
"For refinement mode "
102 << refineModeNames_[modes_[shellI]]
103 <<
" : Refinement should be specified in order"
104 <<
" of increasing distance"
105 <<
" (and decreasing refinement level)." <<
endl
106 <<
"Distance:" << distances_[shellI][j]
107 <<
" refinementLevel:" << levels_[shellI][j]
117 Info<<
"Refinement level according to distance to "
118 << shell.name() <<
endl;
119 forAll(levels_[shellI], j)
121 Info<<
" level " << levels_[shellI][j]
122 <<
" for all cells within " << distances_[shellI][j]
123 <<
" metre." <<
endl;
129 if (!shell.hasVolumeType())
132 <<
"Shell " << shell.name()
133 <<
" does not support testing for "
134 << refineModeNames_[modes_[shellI]] <<
endl
135 <<
"Probably it is not closed."
141 if (modes_[shellI] ==
INSIDE)
143 Info<<
"Refinement level " << levels_[shellI][0]
144 <<
" for all cells inside " << shell.name() <<
endl;
148 Info<<
"Refinement level " << levels_[shellI][0]
149 <<
" for all cells outside " << shell.name() <<
endl;
159 void Foam::shellSurfaces::orient()
164 bool hasSurface =
false;
168 const searchableSurface&
s = allGeometry_[shells_[shellI]];
170 if (modes_[shellI] != DISTANCE && isA<triSurfaceMesh>(
s))
172 const triSurfaceMesh& shell = refCast<const triSurfaceMesh>(
s);
174 if (shell.triSurface::size())
178 overallBb.add(shell.points());
185 const point outsidePt = overallBb.
max() + overallBb.span();
191 const searchableSurface&
s = allGeometry_[shells_[shellI]];
193 if (modes_[shellI] != DISTANCE && isA<triSurfaceMesh>(
s))
195 triSurfaceMesh& shell =
const_cast<triSurfaceMesh&
>
197 refCast<const triSurfaceMesh>(
s)
208 if (anyFlipped && !dryRun_)
217 Info<<
"shellSurfaces : Flipped orientation of surface "
219 <<
" so point " << outsidePt <<
" is outside." <<
endl;
228 void Foam::shellSurfaces::findHigherLevel
235 const labelList& levels = levels_[shellI];
237 if (modes_[shellI] == DISTANCE)
249 label candidateI = 0;
255 if (levels[levelI] > maxLevel[pointi])
257 candidateMap[candidateI] = pointi;
258 candidateDistSqr[candidateI] =
sqr(distances[levelI]);
264 candidateMap.setSize(candidateI);
265 candidateDistSqr.setSize(candidateI);
268 List<pointIndexHit> nearInfo;
269 allGeometry_[shells_[shellI]].findNearest
279 if (nearInfo[i].hit())
281 const label pointi = candidateMap[i];
287 mag(nearInfo[i].hitPoint()-pt[pointi])
291 maxLevel[pointi] = levels[minDistI+1];
304 label candidateI = 0;
308 if (levels[0] > maxLevel[pointi])
310 candidates[candidateI] = pt[pointi];
311 candidateMap[candidateI] = pointi;
315 candidates.setSize(candidateI);
316 candidateMap.setSize(candidateI);
319 List<volumeType> volType;
320 allGeometry_[shells_[shellI]].getVolumeType(candidates, volType);
324 label pointi = candidateMap[i];
329 modes_[shellI] == INSIDE
333 modes_[shellI] == OUTSIDE
338 maxLevel[pointi] = levels[0];
345 void Foam::shellSurfaces::findHigherGapLevel
351 List<FixedList<label, 3>>& gapInfo,
352 List<volumeType>& gapMode
356 const FixedList<label, 3>& info = extendedGapLevel_[shellI][0];
357 const volumeType
mode = extendedGapMode_[shellI][0];
364 if (modes_[shellI] == DISTANCE)
367 const scalar
distance = distances_[shellI][0];
371 label candidateI = 0;
375 if (ptLevel[pointI] >= info[1] && ptLevel[pointI] < info[2])
377 candidateMap[candidateI] = pointI;
382 candidateMap.setSize(candidateI);
383 candidateDistSqr.setSize(candidateI);
386 List<pointIndexHit> nearInfo;
387 allGeometry_[shells_[shellI]].findNearest
397 if (nearInfo[i].hit())
399 const label pointI = candidateMap[i];
400 gapShell[pointI] = shellI;
401 gapInfo[pointI] = info;
402 gapMode[pointI] =
mode;
412 label candidateI = 0;
416 if (ptLevel[pointI] >= info[1] && ptLevel[pointI] < info[2])
418 candidateMap[candidateI++] = pointI;
421 candidateMap.setSize(candidateI);
424 List<volumeType> volType;
425 allGeometry_[shells_[shellI]].getVolumeType
433 const label pointI = candidateMap[i];
439 (modes_[shellI] == INSIDE && isInside)
440 || (modes_[shellI] == OUTSIDE && !isInside)
442 && info[2] > gapInfo[pointI][2]
445 gapShell[pointI] = shellI;
446 gapInfo[pointI] = info;
447 gapMode[pointI] =
mode;
454 void Foam::shellSurfaces::findLevel
462 const labelList& levels = levels_[shellI];
464 if (modes_[shellI] == DISTANCE)
477 label candidateI = 0;
481 if (shell[pointI] == -1)
485 if (levels[levelI] <= minLevel[pointI])
487 candidates[candidateI] = pt[pointI];
488 candidateMap[candidateI] = pointI;
489 candidateDistSqr[candidateI] =
sqr(distances[levelI]);
496 candidates.setSize(candidateI);
497 candidateMap.setSize(candidateI);
498 candidateDistSqr.setSize(candidateI);
501 List<pointIndexHit> nearInfo;
502 allGeometry_[shells_[shellI]].findNearest
512 if (nearInfo[i].hit())
518 mag(nearInfo[i].hitPoint()-candidates[i])
521 label pointI = candidateMap[i];
524 shell[pointI] = shellI;
525 minLevel[pointI] = levels[minDistI+1];
538 label candidateI = 0;
542 if (shell[pointI] == -1 && levels[0] <= minLevel[pointI])
544 candidates[candidateI] = pt[pointI];
545 candidateMap[candidateI] = pointI;
549 candidates.setSize(candidateI);
550 candidateMap.setSize(candidateI);
553 List<volumeType> volType;
554 allGeometry_[shells_[shellI]].getVolumeType(candidates, volType);
561 modes_[shellI] == INSIDE
565 modes_[shellI] == OUTSIDE
570 label pointI = candidateMap[i];
571 shell[pointI] = shellI;
572 minLevel[pointI] = levels[0];
588 allGeometry_(allGeometry),
595 for (
const word& geomName : allGeometry_.names())
597 if (shellsDict.
found(geomName))
605 shells_.setSize(shellI);
606 modes_.setSize(shellI);
607 distances_.setSize(shellI);
608 levels_.setSize(shellI);
609 dirLevels_.setSize(shellI);
610 smoothDirection_.setSize(shellI);
611 nSmoothExpansion_.setSize(shellI);
612 nSmoothPosition_.setSize(shellI);
614 extendedGapLevel_.setSize(shellI);
615 extendedGapMode_.setSize(shellI);
616 selfProximity_.setSize(shellI);
623 forAll(allGeometry_.names(), geomI)
625 const word& geomName = allGeometry_.names()[geomI];
634 shells_[shellI] = geomI;
635 modes_[shellI] = refineModeNames_.get(
"mode",
dict);
638 setAndCheckLevels(shellI,
dict.
lookup(
"levels"));
649 const entry* levelPtr =
659 is >> dirLevels_[shellI].first().first()
660 >> dirLevels_[shellI].first().second()
661 >> dirLevels_[shellI].second();
664 if (modes_[shellI] == INSIDE)
668 Info<<
"Additional directional refinement level"
669 <<
" for all cells inside " << geomName <<
endl;
672 else if (modes_[shellI] == OUTSIDE)
676 Info<<
"Additional directional refinement level"
677 <<
" for all cells outside " << geomName <<
endl;
683 <<
"Unsupported mode "
684 << refineModeNames_[modes_[shellI]]
692 nSmoothExpansion_[shellI] = 0;
693 nSmoothPosition_[shellI] = 0;
694 smoothDirection_[shellI] =
699 dict.
readEntry(
"nSmoothExpansion", nSmoothExpansion_[shellI]);
721 extendedGapLevel_[shellI] = gapSpec;
723 extendedGapMode_[shellI].setSize(
regionNames.size());
724 extendedGapMode_[shellI] =
728 selfProximity_[shellI].setSize
757 extendedGapLevel_[shellI][regionI] = gapSpec;
759 extendedGapMode_[shellI][regionI] =
767 selfProximity_[shellI][regionI] =
777 if (extendedGapLevel_[shellI][0][0] > 0)
779 Info<<
"Refinement level up to "
780 << extendedGapLevel_[shellI][0][2]
781 <<
" for all cells in gaps for shell "
784 if (distances_[shellI].size() > 1)
787 << distances_[shellI] <<
" to detect gaps for shell "
796 if (unmatchedKeys.size() > 0)
799 <<
"Not all entries in refinementRegions dictionary were used."
800 <<
" The following entries were not used : "
801 << unmatchedKeys.sortedToc()
817 label overallMax = 0;
820 overallMax =
max(overallMax,
max(levels_[shellI]));
830 forAll(extendedGapLevel_, shelli)
835 surfaceMax[shelli] =
max(surfaceMax[shelli], levels[i][2]);
845 forAll(dirLevels_, shelli)
847 levels[shelli] = dirLevels_[shelli].first();
855 return nSmoothExpansion_;
861 return smoothDirection_;
867 return nSmoothPosition_;
871 void Foam::shellSurfaces::findHigherLevel
883 findHigherLevel(pt, shelli, maxLevel);
888 void Foam::shellSurfaces::findHigherGapLevel
908 findHigherGapLevel(pt, ptLevel, shelli, gapShell, gapInfo, gapMode);
913 void Foam::shellSurfaces::findHigherGapLevel
922 findHigherGapLevel(pt, ptLevel, gapShell, gapInfo, gapMode);
926 void Foam::shellSurfaces::findLevel
940 findLevel(pt, shelli, minLevel, shell);
964 if (modes_[shelli] == INSIDE || modes_[shelli] == OUTSIDE)
966 const labelPair& selectLevels = dirLevels_[shelli].first();
967 const label addLevel = dirLevels_[shelli].
second()[dir];
970 candidateMap.clear();
973 label level = ptLevel[celli];
977 level >= selectLevels.first()
978 && level <= selectLevels.
second()
979 && dirLevel[celli] < level+addLevel
982 candidateMap.
append(celli);
988 allGeometry_[shells_[shelli]].getVolumeType(candidatePt, volType);
996 modes_[shelli] == INSIDE
1000 modes_[shelli] == OUTSIDE
1005 shell[candidateMap[i]] = shelli;