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;
156 void Foam::shellSurfaces::checkGapLevels
158 const dictionary& shellDict,
160 const List<FixedList<label, 3>>& levels
163 const searchableSurface& shell = allGeometry_[shells_[shellI]];
167 const FixedList<label, 3>& info = levels[regionI];
171 if (modes_[shellI] == DISTANCE)
174 <<
"'gapLevel' specification cannot be used with mode "
175 << refineModeNames_[DISTANCE]
176 <<
" for shell " << shell.name()
183 if (levels[0][0] > 0)
185 Info<<
"Refinement level up to " << levels[0][2]
186 <<
" for all cells in gaps for shell "
187 << shell.name() <<
endl;
196 void Foam::shellSurfaces::orient()
201 bool hasSurface =
false;
205 const searchableSurface&
s = allGeometry_[shells_[shellI]];
207 if (modes_[shellI] != DISTANCE && isA<triSurfaceMesh>(
s))
209 const triSurfaceMesh& shell = refCast<const triSurfaceMesh>(
s);
211 if (shell.triSurface::size())
215 overallBb.add(shell.points());
222 const point outsidePt = overallBb.
max() + overallBb.span();
228 const searchableSurface&
s = allGeometry_[shells_[shellI]];
230 if (modes_[shellI] != DISTANCE && isA<triSurfaceMesh>(
s))
232 triSurfaceMesh& shell =
const_cast<triSurfaceMesh&
>
234 refCast<const triSurfaceMesh>(
s)
245 if (anyFlipped && !dryRun_)
254 Info<<
"shellSurfaces : Flipped orientation of surface "
256 <<
" so point " << outsidePt <<
" is outside." <<
endl;
265 void Foam::shellSurfaces::findHigherLevel
272 const labelList& levels = levels_[shellI];
274 if (modes_[shellI] == DISTANCE)
287 label candidateI = 0;
293 if (levels[levelI] > maxLevel[pointi])
295 candidates[candidateI] = pt[pointi];
296 candidateMap[candidateI] = pointi;
297 candidateDistSqr[candidateI] =
sqr(distances[levelI]);
303 candidates.setSize(candidateI);
304 candidateMap.setSize(candidateI);
305 candidateDistSqr.setSize(candidateI);
309 allGeometry_[shells_[shellI]].findNearest
328 label pointi = candidateMap[i];
331 maxLevel[pointi] = levels[minDistI+1];
344 label candidateI = 0;
348 if (levels[0] > maxLevel[pointi])
350 candidates[candidateI] = pt[pointi];
351 candidateMap[candidateI] = pointi;
355 candidates.setSize(candidateI);
356 candidateMap.setSize(candidateI);
359 List<volumeType> volType;
360 allGeometry_[shells_[shellI]].getVolumeType(candidates, volType);
364 label pointi = candidateMap[i];
369 modes_[shellI] == INSIDE
373 modes_[shellI] == OUTSIDE
378 maxLevel[pointi] = levels[0];
385 void Foam::shellSurfaces::findHigherGapLevel
391 List<FixedList<label, 3>>& gapInfo,
392 List<volumeType>& gapMode
396 const FixedList<label, 3>& info = extendedGapLevel_[shellI][0];
397 volumeType
mode = extendedGapMode_[shellI][0];
409 label candidateI = 0;
413 if (ptLevel[pointI] >= info[1] && ptLevel[pointI] < info[2])
415 candidateMap[candidateI++] = pointI;
418 candidateMap.setSize(candidateI);
421 List<volumeType> volType;
422 allGeometry_[shells_[shellI]].getVolumeType
430 label pointI = candidateMap[i];
437 (modes_[shellI] == INSIDE && isInside)
438 || (modes_[shellI] == OUTSIDE && !isInside)
440 && info[2] > gapInfo[pointI][2]
443 gapShell[pointI] = shellI;
444 gapInfo[pointI] = info;
445 gapMode[pointI] =
mode;
451 void Foam::shellSurfaces::findLevel
459 const labelList& levels = levels_[shellI];
461 if (modes_[shellI] == DISTANCE)
474 label candidateI = 0;
478 if (shell[pointI] == -1)
482 if (levels[levelI] <= minLevel[pointI])
484 candidates[candidateI] = pt[pointI];
485 candidateMap[candidateI] = pointI;
486 candidateDistSqr[candidateI] =
sqr(distances[levelI]);
493 candidates.setSize(candidateI);
494 candidateMap.setSize(candidateI);
495 candidateDistSqr.setSize(candidateI);
499 allGeometry_[shells_[shellI]].findNearest
518 label pointI = candidateMap[i];
521 shell[pointI] = shellI;
522 minLevel[pointI] = levels[minDistI+1];
535 label candidateI = 0;
539 if (shell[pointI] == -1 && levels[0] <= minLevel[pointI])
541 candidates[candidateI] = pt[pointI];
542 candidateMap[candidateI] = pointI;
546 candidates.setSize(candidateI);
547 candidateMap.setSize(candidateI);
550 List<volumeType> volType;
551 allGeometry_[shells_[shellI]].getVolumeType(candidates, volType);
558 modes_[shellI] == INSIDE
562 modes_[shellI] == OUTSIDE
567 label pointI = candidateMap[i];
568 shell[pointI] = shellI;
569 minLevel[pointI] = levels[0];
585 allGeometry_(allGeometry),
592 for (
const word& geomName : allGeometry_.names())
594 if (shellsDict.
found(geomName))
602 shells_.setSize(shellI);
603 modes_.setSize(shellI);
604 distances_.setSize(shellI);
605 levels_.setSize(shellI);
606 dirLevels_.setSize(shellI);
607 smoothDirection_.setSize(shellI);
608 nSmoothExpansion_.setSize(shellI);
609 nSmoothPosition_.setSize(shellI);
611 extendedGapLevel_.setSize(shellI);
612 extendedGapMode_.setSize(shellI);
613 selfProximity_.setSize(shellI);
624 forAll(allGeometry_.names(), geomI)
626 const word& geomName = allGeometry_.names()[geomI];
635 shells_[shellI] = geomI;
636 modes_[shellI] = refineModeNames_.get(
"mode",
dict);
639 setAndCheckLevels(shellI,
dict.
lookup(
"levels"));
650 const entry* levelPtr =
660 is >> dirLevels_[shellI].first().first()
661 >> dirLevels_[shellI].first().second()
662 >> dirLevels_[shellI].second();
665 if (modes_[shellI] == INSIDE)
669 Info<<
"Additional directional refinement level"
670 <<
" for all cells inside " << geomName <<
endl;
673 else if (modes_[shellI] == OUTSIDE)
677 Info<<
"Additional directional refinement level"
678 <<
" for all cells outside " << geomName <<
endl;
684 <<
"Unsupported mode "
685 << refineModeNames_[modes_[shellI]]
693 nSmoothExpansion_[shellI] = 0;
694 nSmoothPosition_[shellI] = 0;
695 smoothDirection_[shellI] =
700 dict.
readEntry(
"nSmoothExpansion", nSmoothExpansion_[shellI]);
721 extendedGapLevel_[shellI].
setSize(regionNames.size());
722 extendedGapLevel_[shellI] = gapSpec;
724 extendedGapMode_[shellI].setSize(regionNames.size());
725 extendedGapMode_[shellI] =
729 selfProximity_[shellI].setSize
741 forAll(regionNames, regionI)
743 if (regionsDict.
found(regionNames[regionI]))
758 extendedGapLevel_[shellI][regionI] = gapSpec;
760 extendedGapMode_[shellI][regionI] =
768 selfProximity_[shellI][regionI] =
778 checkGapLevels(
dict, shellI, extendedGapLevel_[shellI]);
784 if (unmatchedKeys.size() > 0)
787 <<
"Not all entries in refinementRegions dictionary were used."
788 <<
" The following entries were not used : "
789 << unmatchedKeys.sortedToc()
805 label overallMax = 0;
808 overallMax =
max(overallMax,
max(levels_[shellI]));
818 forAll(extendedGapLevel_, shelli)
823 surfaceMax[shelli] =
max(surfaceMax[shelli], levels[i][2]);
833 forAll(dirLevels_, shelli)
835 levels[shelli] = dirLevels_[shelli].first();
843 return nSmoothExpansion_;
849 return smoothDirection_;
855 return nSmoothPosition_;
859 void Foam::shellSurfaces::findHigherLevel
871 findHigherLevel(pt, shelli, maxLevel);
876 void Foam::shellSurfaces::findHigherGapLevel
894 gapInfo = nullGapLevel;
901 findHigherGapLevel(pt, ptLevel, shelli, gapShell, gapInfo, gapMode);
906 void Foam::shellSurfaces::findHigherGapLevel
915 findHigherGapLevel(pt, ptLevel, gapShell, gapInfo, gapMode);
919 void Foam::shellSurfaces::findLevel
933 findLevel(pt, shelli, minLevel, shell);
957 if (modes_[shelli] == INSIDE || modes_[shelli] == OUTSIDE)
959 const labelPair& selectLevels = dirLevels_[shelli].first();
960 const label addLevel = dirLevels_[shelli].
second()[dir];
963 candidateMap.clear();
966 label level = ptLevel[celli];
970 level >= selectLevels.first()
971 && level <= selectLevels.
second()
972 && dirLevel[celli] < level+addLevel
975 candidateMap.
append(celli);
981 allGeometry_[shells_[shelli]].getVolumeType(candidatePt, volType);
989 modes_[shelli] == INSIDE
993 modes_[shelli] == OUTSIDE
998 shell[candidateMap[i]] = shelli;