63 Foam::snappyRefineDriver::snappyRefineDriver
74 meshRefiner_(meshRefiner),
75 decomposer_(decomposer),
76 distributor_(distributor),
77 globalToMasterPatch_(globalToMasterPatch),
78 globalToSlavePatch_(globalToSlavePatch),
79 setFormatter_(setFormatter),
86 Foam::label Foam::snappyRefineDriver::featureEdgeRefine
106 const fvMesh&
mesh = meshRefiner_.
mesh();
110 if (meshRefiner_.
features().size() && maxIter > 0)
112 for (; iter < maxIter; iter++)
115 <<
"Feature refinement iteration " << iter <<
nl
116 <<
"------------------------------" <<
nl
148 Info<<
"Determined cells to refine in = "
149 <<
mesh.time().cpuTimeIncrement() <<
" s" <<
endl;
153 label nCellsToRefine = cellsToRefine.size();
154 reduce(nCellsToRefine, sumOp<label>());
156 Info<<
"Selected for feature refinement : " << nCellsToRefine
157 <<
" cells (out of " <<
mesh.globalData().nTotalCells()
160 if (nCellsToRefine <= minRefine)
162 Info<<
"Stopping refining since too few cells selected."
170 const_cast<Time&
>(
mesh.time())++;
185 "feature refinement iteration " +
name(iter),
196 "feature refinement iteration " +
name(iter),
209 Foam::label Foam::snappyRefineDriver::smallFeatureRefine
211 const refinementParameters& refineParams,
220 if (refineParams.minRefineCells() == -1)
227 addProfiling(feature,
"snappyHexMesh::refine::smallFeature");
228 const fvMesh&
mesh = meshRefiner_.mesh();
233 labelList surfaceMaxLevel(meshRefiner_.surfaces().maxGapLevel());
234 labelList shellMaxLevel(meshRefiner_.shells().maxGapLevel());
236 if (
max(surfaceMaxLevel) == 0 &&
max(shellMaxLevel) == 0)
241 for (; iter < maxIter; iter++)
244 <<
"Small surface feature refinement iteration " << iter <<
nl
245 <<
"--------------------------------------------" <<
nl
254 meshRefiner_.refineCandidates
256 refineParams.locationsInMesh(),
257 refineParams.curvature(),
258 refineParams.planarAngle(),
269 refineParams.maxGlobalCells(),
270 refineParams.maxLocalCells()
276 meshRefiner_.meshCutter().consistentRefinement
282 Info<<
"Determined cells to refine in = "
286 label nCellsToRefine = cellsToRefine.size();
287 reduce(nCellsToRefine, sumOp<label>());
289 Info<<
"Selected for refinement : " << nCellsToRefine
295 if (nCellsToRefine == 0)
297 Info<<
"Stopping refining since too few cells selected."
313 (
mesh.
nCells() >= refineParams.maxLocalCells()),
318 meshRefiner_.balanceAndRefine
320 "small feature refinement iteration " +
name(iter),
324 refineParams.maxLoadUnbalance()
329 meshRefiner_.refineAndBalance
331 "small feature refinement iteration " +
name(iter),
335 refineParams.maxLoadUnbalance()
343 Foam::label Foam::snappyRefineDriver::surfaceOnlyRefine
345 const refinementParameters& refineParams,
354 if (refineParams.minRefineCells() == -1)
361 addProfiling(surface,
"snappyHexMesh::refine::surface");
362 const fvMesh&
mesh = meshRefiner_.mesh();
366 label overallMaxLevel =
max(meshRefiner_.surfaces().maxLevel());
369 for (iter = 0; iter < maxIter; iter++)
372 <<
"Surface refinement iteration " << iter <<
nl
373 <<
"------------------------------" <<
nl
384 meshRefiner_.refineCandidates
386 refineParams.locationsInMesh(),
387 refineParams.curvature(),
388 refineParams.planarAngle(),
399 refineParams.maxGlobalCells(),
400 refineParams.maxLocalCells()
405 meshRefiner_.meshCutter().consistentRefinement
411 Info<<
"Determined cells to refine in = "
415 label nCellsToRefine = cellsToRefine.size();
416 reduce(nCellsToRefine, sumOp<label>());
418 Info<<
"Selected for refinement : " << nCellsToRefine
428 iter >= overallMaxLevel
429 && nCellsToRefine <= refineParams.minRefineCells()
433 Info<<
"Stopping refining since too few cells selected."
449 (
mesh.
nCells() >= refineParams.maxLocalCells()),
454 meshRefiner_.balanceAndRefine
456 "surface refinement iteration " +
name(iter),
460 refineParams.maxLoadUnbalance()
465 meshRefiner_.refineAndBalance
467 "surface refinement iteration " +
name(iter),
471 refineParams.maxLoadUnbalance()
479 Foam::label Foam::snappyRefineDriver::gapOnlyRefine
481 const refinementParameters& refineParams,
490 if (refineParams.minRefineCells() == -1)
497 const fvMesh&
mesh = meshRefiner_.mesh();
502 label maxIncrement = 0;
503 const labelList& maxLevel = meshRefiner_.surfaces().maxLevel();
504 const labelList& gapLevel = meshRefiner_.surfaces().gapLevel();
508 maxIncrement =
max(maxIncrement, gapLevel[i]-maxLevel[i]);
513 if (maxIncrement == 0)
518 for (iter = 0; iter < maxIter; iter++)
521 <<
"Gap refinement iteration " << iter <<
nl
522 <<
"--------------------------" <<
nl
533 meshRefiner_.refineCandidates
535 refineParams.locationsInMesh(),
536 refineParams.curvature(),
537 refineParams.planarAngle(),
548 refineParams.maxGlobalCells(),
549 refineParams.maxLocalCells()
555 Pout<<
"Writing current mesh to time "
556 << meshRefiner_.timeName() <<
endl;
567 Pout<<
"Dumped mesh in = "
571 Pout<<
"Dumping " << candidateCells.size()
572 <<
" cells to cellSet candidateCellsFromGap." <<
endl;
573 cellSet
c(
mesh,
"candidateCellsFromGap", candidateCells);
574 c.instance() = meshRefiner_.timeName();
583 isCandidateCell[candidateCells[i]] =
true;
586 for (label i=0; i<1; i++)
588 boolList newIsCandidateCell(isCandidateCell);
596 if (isCandidateCell[own] != isCandidateCell[nei])
598 newIsCandidateCell[own] =
true;
599 newIsCandidateCell[nei] =
true;
623 if (isCandidateCell[own] != neiIsCandidateCell[bFacei])
625 newIsCandidateCell[own] =
true;
629 isCandidateCell.transfer(newIsCandidateCell);
633 forAll(isCandidateCell, celli)
635 if (isCandidateCell[celli])
640 candidateCells.setSize(
n);
642 forAll(isCandidateCell, celli)
644 if (isCandidateCell[celli])
646 candidateCells[
n++] = celli;
654 Pout<<
"Dumping " << candidateCells.size()
655 <<
" cells to cellSet candidateCellsFromGapPlusBuffer." <<
endl;
656 cellSet
c(
mesh,
"candidateCellsFromGapPlusBuffer", candidateCells);
657 c.instance() = meshRefiner_.timeName();
664 meshRefiner_.meshCutter().consistentRefinement
670 Info<<
"Determined cells to refine in = "
674 label nCellsToRefine = cellsToRefine.size();
675 reduce(nCellsToRefine, sumOp<label>());
677 Info<<
"Selected for refinement : " << nCellsToRefine
688 && nCellsToRefine <= refineParams.minRefineCells()
692 Info<<
"Stopping refining since too few cells selected."
708 (
mesh.
nCells() >= refineParams.maxLocalCells()),
713 meshRefiner_.balanceAndRefine
715 "gap refinement iteration " +
name(iter),
719 refineParams.maxLoadUnbalance()
724 meshRefiner_.refineAndBalance
726 "gap refinement iteration " +
name(iter),
730 refineParams.maxLoadUnbalance()
738 Foam::label Foam::snappyRefineDriver::surfaceProximityBlock
740 const refinementParameters& refineParams,
744 if (refineParams.minRefineCells() == -1)
751 fvMesh&
mesh = meshRefiner_.mesh();
753 if (
min(meshRefiner_.surfaces().blockLevel()) ==
labelMax)
760 for (iter = 0; iter < maxIter; iter++)
763 <<
"Gap blocking iteration " << iter <<
nl
764 <<
"------------------------" <<
nl
771 meshRefiner_.removeGapCells
773 refineParams.planarAngle(),
774 meshRefiner_.surfaces().blockLevel(),
775 globalToMasterPatch_,
776 refineParams.nFilterIter()
782 Pout<<
"Writing gap blocking iteration "
783 << iter <<
" mesh to time " << meshRefiner_.timeName()
801 Foam::label Foam::snappyRefineDriver::bigGapOnlyRefine
803 const refinementParameters& refineParams,
804 const bool spreadGapSize,
808 if (refineParams.minRefineCells() == -1)
820 const fvMesh&
mesh = meshRefiner_.mesh();
825 labelList surfaceMaxLevel(meshRefiner_.surfaces().maxGapLevel());
826 labelList shellMaxLevel(meshRefiner_.shells().maxGapLevel());
828 label overallMaxLevel(
max(
max(surfaceMaxLevel),
max(shellMaxLevel)));
830 if (overallMaxLevel == 0)
836 for (; iter < maxIter; iter++)
839 <<
"Big gap refinement iteration " << iter <<
nl
840 <<
"------------------------------" <<
nl
849 meshRefiner_.refineCandidates
851 refineParams.locationsInMesh(),
852 refineParams.curvature(),
853 refineParams.planarAngle(),
864 refineParams.maxGlobalCells(),
865 refineParams.maxLocalCells()
872 Pout<<
"Writing current mesh to time "
873 << meshRefiner_.timeName() <<
endl;
884 Pout<<
"Dumped mesh in = "
887 Pout<<
"Dumping " << candidateCells.size()
888 <<
" cells to cellSet candidateCellsFromBigGap." <<
endl;
889 cellSet
c(
mesh,
"candidateCellsFromBigGap", candidateCells);
890 c.instance() = meshRefiner_.timeName();
896 meshRefiner_.meshCutter().consistentRefinement
902 Info<<
"Determined cells to refine in = "
906 label nCellsToRefine = cellsToRefine.size();
907 reduce(nCellsToRefine, sumOp<label>());
909 Info<<
"Selected for refinement : " << nCellsToRefine
919 iter >= overallMaxLevel
920 && nCellsToRefine <= refineParams.minRefineCells()
924 Info<<
"Stopping refining since too few cells selected."
940 (
mesh.
nCells() >= refineParams.maxLocalCells()),
945 meshRefiner_.balanceAndRefine
947 "big gap refinement iteration " +
name(iter),
951 refineParams.maxLoadUnbalance()
956 meshRefiner_.refineAndBalance
958 "big gap refinement iteration " +
name(iter),
962 refineParams.maxLoadUnbalance()
970 Foam::label Foam::snappyRefineDriver::danglingCellRefine
972 const refinementParameters& refineParams,
977 if (refineParams.minRefineCells() == -1)
989 addProfiling(dangling,
"snappyHexMesh::refine::danglingCell");
990 const fvMesh&
mesh = meshRefiner_.mesh();
993 for (iter = 0; iter < maxIter; iter++)
996 <<
"Dangling coarse cells refinement iteration " << iter <<
nl
997 <<
"--------------------------------------------" <<
nl
1009 cellSet candidateCellSet(
mesh,
"candidateCells",
cells.size()/1000);
1013 const cell& cFaces =
cells[celli];
1015 label nIntFaces = 0;
1025 label patchi = pbm.patchID()[bFacei];
1033 if (nIntFaces == nFaces)
1035 candidateCellSet.insert(celli);
1041 Pout<<
"Dumping " << candidateCellSet.size()
1042 <<
" cells to cellSet candidateCellSet." <<
endl;
1043 candidateCellSet.instance() = meshRefiner_.timeName();
1044 candidateCellSet.
write();
1046 candidateCells = candidateCellSet.toc();
1053 meshRefiner_.meshCutter().consistentRefinement
1059 Info<<
"Determined cells to refine in = "
1063 label nCellsToRefine = cellsToRefine.size();
1064 reduce(nCellsToRefine, sumOp<label>());
1066 Info<<
"Selected for refinement : " << nCellsToRefine
1077 && nCellsToRefine <= refineParams.minRefineCells()
1081 Info<<
"Stopping refining since too few cells selected."
1097 (
mesh.
nCells() >= refineParams.maxLocalCells()),
1102 meshRefiner_.balanceAndRefine
1104 "coarse cell refinement iteration " +
name(iter),
1108 refineParams.maxLoadUnbalance()
1113 meshRefiner_.refineAndBalance
1115 "coarse cell refinement iteration " +
name(iter),
1119 refineParams.maxLoadUnbalance()
1129 Foam::label Foam::snappyRefineDriver::refinementInterfaceRefine
1131 const refinementParameters& refineParams,
1135 if (refineParams.minRefineCells() == -1)
1148 const fvMesh&
mesh = meshRefiner_.mesh();
1152 if (refineParams.interfaceRefine())
1154 for (;iter < maxIter; iter++)
1157 <<
"Refinement transition refinement iteration " << iter <<
nl
1158 <<
"--------------------------------------------" <<
nl
1161 const labelList& surfaceIndex = meshRefiner_.surfaceIndex();
1162 const hexRef8& cutter = meshRefiner_.meshCutter();
1176 cellSet transitionCells
1185 const cell& cFaces =
cells[celli];
1186 label cLevel = cutter.cellLevel()[celli];
1190 label facei = cFaces[cFacei];
1192 if (surfaceIndex[facei] != -1)
1194 label fLevel = cutter.faceLevel(facei);
1195 if (fLevel != cLevel)
1197 transitionCells.insert(celli);
1204 cellSet candidateCellSet
1325 for (
const label celli : transitionCells)
1327 const cell& cFaces =
cells[celli];
1328 label cLevel = cutter.cellLevel()[celli];
1331 bool foundOpposite =
false;
1335 label facei = cFaces[cFacei];
1339 surfaceIndex[facei] != -1
1340 && cutter.faceLevel(facei) > cLevel
1345 if (faceOwner[facei] != celli)
1353 label face2i = cFaces[cFaceI2];
1358 && surfaceIndex[face2i] != -1
1363 if (faceOwner[face2i] != celli)
1369 if ((
n&n2) < oppositeCos)
1371 foundOpposite =
true;
1387 candidateCellSet.insert(celli);
1393 Pout<<
"Dumping " << candidateCellSet.size()
1394 <<
" cells to cellSet candidateCellSet." <<
endl;
1395 candidateCellSet.instance() = meshRefiner_.timeName();
1396 candidateCellSet.
write();
1398 candidateCells = candidateCellSet.toc();
1405 meshRefiner_.meshCutter().consistentRefinement
1411 Info<<
"Determined cells to refine in = "
1415 label nCellsToRefine = cellsToRefine.size();
1416 reduce(nCellsToRefine, sumOp<label>());
1418 Info<<
"Selected for refinement : " << nCellsToRefine
1429 && nCellsToRefine <= refineParams.minRefineCells()
1433 Info<<
"Stopping refining since too few cells selected."
1449 (
mesh.
nCells() >= refineParams.maxLocalCells()),
1454 meshRefiner_.balanceAndRefine
1456 "interface cell refinement iteration " +
name(iter),
1460 refineParams.maxLoadUnbalance()
1465 meshRefiner_.refineAndBalance
1467 "interface cell refinement iteration " +
name(iter),
1471 refineParams.maxLoadUnbalance()
1479 bool Foam::snappyRefineDriver::usesHigherLevel
1486 for (
const label pointi :
f)
1488 if (boundaryPointLevel[pointi] > cLevel)
1497 Foam::label Foam::snappyRefineDriver::boundaryRefinementInterfaceRefine
1499 const refinementParameters& refineParams,
1503 if (refineParams.minRefineCells() == -1)
1516 const fvMesh&
mesh = meshRefiner_.mesh();
1520 if (refineParams.interfaceRefine())
1522 for (;iter < maxIter; iter++)
1525 <<
"Boundary refinement iteration " << iter <<
nl
1526 <<
"-------------------------------" <<
nl
1529 const labelList& surfaceIndex = meshRefiner_.surfaceIndex();
1530 const hexRef8& cutter = meshRefiner_.meshCutter();
1531 const labelList& cellLevel = cutter.cellLevel();
1543 forAll(surfaceIndex, facei)
1545 if (surfaceIndex[facei] != -1)
1547 isBoundaryFace.set(facei);
1548 isBoundaryPoint.set(faces[facei]);
1551 const labelList meshPatchIDs(meshRefiner_.meshedPatches());
1552 for (
const label patchi : meshPatchIDs)
1557 isBoundaryFace.set(pp.start()+i);
1558 isBoundaryPoint.set(pp[i]);
1566 orEqOp<unsigned int>(),
1577 const cell& cFaces =
cells[celli];
1578 const label cLevel = cellLevel[celli];
1580 for (
const label facei : cFaces)
1582 if (isBoundaryFace(facei))
1584 const face&
f = faces[facei];
1585 for (
const label pointi :
f)
1587 boundaryPointLevel[pointi] =
1590 boundaryPointLevel[pointi],
1613 cellSet candidateCellSet
1622 const cell& cFaces =
cells[celli];
1623 const label cLevel = cellLevel[celli];
1625 bool isBoundaryCell =
false;
1626 for (
const label facei : cFaces)
1628 if (isBoundaryFace(facei))
1630 isBoundaryCell =
true;
1635 if (!isBoundaryCell)
1637 for (
const label facei : cFaces)
1640 if (usesHigherLevel(boundaryPointLevel,
f, cLevel))
1642 candidateCellSet.insert(celli);
1650 Pout<<
"Dumping " << candidateCellSet.size()
1651 <<
" cells to cellSet candidateCellSet." <<
endl;
1652 candidateCellSet.instance() = meshRefiner_.timeName();
1653 candidateCellSet.
write();
1655 candidateCells = candidateCellSet.toc();
1660 meshRefiner_.meshCutter().consistentRefinement
1666 Info<<
"Determined cells to refine in = "
1670 label nCellsToRefine = cellsToRefine.size();
1671 reduce(nCellsToRefine, sumOp<label>());
1673 Info<<
"Selected for refinement : " << nCellsToRefine
1688 Info<<
"Stopping refining since too few cells selected."
1704 (
mesh.
nCells() >= refineParams.maxLocalCells()),
1709 meshRefiner_.balanceAndRefine
1711 "boundary cell refinement iteration " +
name(iter),
1715 refineParams.maxLoadUnbalance()
1720 meshRefiner_.refineAndBalance
1722 "boundary cell refinement iteration " +
name(iter),
1726 refineParams.maxLoadUnbalance()
1735 void Foam::snappyRefineDriver::removeInsideCells
1737 const refinementParameters& refineParams,
1738 const label nBufferLayers
1742 if (meshRefiner_.limitShells().shells().size() == 0 && nBufferLayers == 0)
1753 <<
"Removing mesh beyond surface intersections" <<
nl
1754 <<
"------------------------------------------" <<
nl
1757 const fvMesh&
mesh = meshRefiner_.mesh();
1765 meshRefiner_.removeLimitShells
1769 globalToMasterPatch_,
1770 globalToSlavePatch_,
1771 refineParams.locationsInMesh(),
1772 refineParams.zonesInMesh()
1777 meshRefiner_.splitMesh
1780 refineParams.nErodeCellZone(),
1781 globalToMasterPatch_,
1782 globalToSlavePatch_,
1783 refineParams.locationsInMesh(),
1784 refineParams.zonesInMesh(),
1785 refineParams.locationsOutsideMesh(),
1793 Pout<<
"Writing subsetted mesh to time "
1794 << meshRefiner_.timeName() <<
endl;
1805 Pout<<
"Dumped mesh in = "
1811 Foam::label Foam::snappyRefineDriver::shellRefine
1813 const refinementParameters& refineParams,
1822 if (refineParams.minRefineCells() == -1)
1830 const fvMesh&
mesh = meshRefiner_.mesh();
1833 meshRefiner_.userFaceData().setSize(1);
1837 meshRefiner_.userFaceData()[0].second() = ListOps::createWithValue<label>
1840 meshRefiner_.intersectedFaces(),
1848 label overallMaxShellLevel = meshRefiner_.shells().maxLevel();
1851 for (iter = 0; iter < maxIter; iter++)
1854 <<
"Shell refinement iteration " << iter <<
nl
1855 <<
"----------------------------" <<
nl
1860 meshRefiner_.refineCandidates
1862 refineParams.locationsInMesh(),
1863 refineParams.curvature(),
1864 refineParams.planarAngle(),
1875 refineParams.maxGlobalCells(),
1876 refineParams.maxLocalCells()
1882 Pout<<
"Dumping " << candidateCells.size()
1883 <<
" cells to cellSet candidateCellsFromShells." <<
endl;
1885 cellSet
c(
mesh,
"candidateCellsFromShells", candidateCells);
1886 c.instance() = meshRefiner_.timeName();
1899 findIndices(meshRefiner_.userFaceData()[0].second(), 0)
1907 if (refineParams.nBufferLayers() <= 2)
1909 cellsToRefine = meshRefiner_.meshCutter().consistentSlowRefinement
1911 refineParams.nBufferLayers(),
1915 meshRefiner_.intersectedPoints()
1920 cellsToRefine = meshRefiner_.meshCutter().consistentSlowRefinement2
1922 refineParams.nBufferLayers(),
1928 Info<<
"Determined cells to refine in = "
1932 label nCellsToRefine = cellsToRefine.size();
1933 reduce(nCellsToRefine, sumOp<label>());
1935 Info<<
"Selected for internal refinement : " << nCellsToRefine
1945 iter >= overallMaxShellLevel
1946 && nCellsToRefine <= refineParams.minRefineCells()
1950 Info<<
"Stopping refining since too few cells selected."
1965 (
mesh.
nCells() >= refineParams.maxLocalCells()),
1970 meshRefiner_.balanceAndRefine
1972 "shell refinement iteration " +
name(iter),
1976 refineParams.maxLoadUnbalance()
1981 meshRefiner_.refineAndBalance
1983 "shell refinement iteration " +
name(iter),
1987 refineParams.maxLoadUnbalance()
1991 meshRefiner_.userFaceData().clear();
1997 Foam::label Foam::snappyRefineDriver::directionalShellRefine
1999 const refinementParameters& refineParams,
2008 addProfiling(shell,
"snappyHexMesh::refine::directionalShell");
2009 const fvMesh&
mesh = meshRefiner_.mesh();
2010 const shellSurfaces& shells = meshRefiner_.shells();
2013 const_cast<labelIOList&
>(meshRefiner_.meshCutter().cellLevel());
2015 const_cast<labelIOList&
>(meshRefiner_.meshCutter().pointLevel());
2020 const labelPairList dirSelect(shells.directionalSelectLevel());
2023 forAll(dirSelect, shelli)
2025 overallMinLevel =
min(dirSelect[shelli].first(), overallMinLevel);
2026 overallMaxLevel =
max(dirSelect[shelli].second(), overallMaxLevel);
2029 if (overallMinLevel > overallMaxLevel)
2035 List<labelVector> dirCellLevel(cellLevel.size());
2042 for (iter = 0; iter < maxIter; iter++)
2045 <<
"Directional shell refinement iteration " << iter <<
nl
2046 <<
"----------------------------------------" <<
nl
2049 label nAllRefine = 0;
2060 labelList currentLevel(dirCellLevel.size());
2061 forAll(dirCellLevel, celli)
2063 currentLevel[celli] = dirCellLevel[celli][dir];
2068 meshRefiner_.directionalRefineCandidates
2070 refineParams.maxGlobalCells(),
2071 refineParams.maxLocalCells(),
2080 meshRefiner_.meshCutter().consistentRefinement
2088 Info<<
"Determined cells to refine in = "
2091 label nCellsToRefine = cellsToRefine.size();
2092 reduce(nCellsToRefine, sumOp<label>());
2095 <<
" refinement : " << nCellsToRefine
2099 nAllRefine += nCellsToRefine;
2103 if (nCellsToRefine > 0)
2110 const bitSet isRefineCell(
mesh.
nCells(), cellsToRefine);
2112 autoPtr<mapPolyMesh> map
2114 meshRefiner_.directionalRefine
2116 "directional refinement iteration " +
name(iter),
2122 Info<<
"Refined mesh in = "
2143 forAll(map().cellMap(), celli)
2145 if (isRefineCell[map().cellMap()[celli]])
2147 dirCellLevel[celli][dir]++;
2153 forAll(map().pointMap(), pointi)
2155 label oldPointi = map().pointMap()[pointi];
2156 if (map().reversePointMap()[oldPointi] != pointi)
2159 pointLevel[pointi]++;
2166 if (nAllRefine == 0)
2168 Info<<
"Stopping refining since no cells selected."
2173 meshRefiner_.printMeshInfo
2176 "After directional refinement iteration " +
name(iter)
2181 Pout<<
"Writing directional refinement iteration "
2182 << iter <<
" mesh to time " << meshRefiner_.timeName() <<
endl;
2204 cellLevel[celli] =
cmptMax(dirCellLevel[celli]);
2211 void Foam::snappyRefineDriver::mergeAndSmoothRatio
2214 const label nSmoothExpansion,
2215 List<Tuple2<scalar, scalar>>& keyAndValue
2220 SortableList<scalar> unmergedDist(allSeedPointDist);
2221 DynamicList<scalar> mergedDist;
2223 scalar prevDist = GREAT;
2226 scalar curDist = unmergedDist[i];
2227 scalar difference =
mag(curDist - prevDist);
2228 if (difference > meshRefiner_.mergeDistance())
2231 mergedDist.append(curDist);
2237 SortableList<scalar> sortedDist(mergedDist);
2238 labelList indexSet = sortedDist.indices();
2241 scalarList seedPointsNewLocation = sortedDist;
2243 scalar initResidual = 0.0;
2244 scalar prevIterResidual = GREAT;
2246 for (label iter = 0; iter < nSmoothExpansion; iter++)
2260 for(label i = 2; i<mergedDist.size()-1; i++)
2262 scalar oldX00 = sortedDist[i-2];
2263 scalar oldX1 = sortedDist[i+1];
2264 scalar curX0 = seedPointsNewLocation[i-1];
2265 seedPointsNewLocation[i] = curX0 + (oldX1 - oldX00)/3;
2268 const scalarField residual(seedPointsNewLocation-sortedDist);
2270 scalar res(
sumMag(residual));
2276 res /= initResidual;
2278 if (
mag(prevIterResidual - res) < SMALL)
2282 Pout<<
"Converged with iteration " << iter
2283 <<
" initResidual: " << initResidual
2284 <<
" final residual : " << res <<
endl;
2290 prevIterResidual = res;
2295 sortedDist = seedPointsNewLocation;
2299 keyAndValue.setSize(mergedDist.size());
2303 keyAndValue[i].first() = mergedDist[i];
2304 label index = indexSet[i];
2305 keyAndValue[i].second() = seedPointsNewLocation[index];
2310 Foam::label Foam::snappyRefineDriver::directionalSmooth
2312 const refinementParameters& refineParams
2317 <<
"Directional expansion ratio smoothing" <<
nl
2318 <<
"-------------------------------------" <<
nl
2321 fvMesh& baseMesh = meshRefiner_.mesh();
2322 const searchableSurfaces& geometry = meshRefiner_.surfaces().geometry();
2323 const shellSurfaces& shells = meshRefiner_.shells();
2327 forAll(shells.nSmoothExpansion(), shellI)
2331 shells.nSmoothExpansion()[shellI] > 0
2332 || shells.nSmoothPosition()[shellI] > 0
2335 label surfi = shells.shells()[shellI];
2336 const vector& userDirection = shells.smoothDirection()[shellI];
2343 List<volumeType> volType;
2344 geometry[surfi].getVolumeType(baseMesh.points(), volType);
2376 bitSet isXEdge(baseMesh.edges().size());
2378 const edgeList& edges = baseMesh.edges();
2381 const edge&
e = edges[edgei];
2382 vector eVec(
e.vec(baseMesh.points()));
2384 if (
mag(eVec&userDirection) > 0.9)
2393 const scalar totalLength =
2394 geometry[surfi].bounds().span()
2396 const scalar startPosition =
2397 geometry[surfi].bounds().min()
2404 normalizedPosition[i] =
2406 ((baseMesh.points()[pointi]&userDirection) - startPosition)
2414 DynamicList<scalar> seedPointDist;
2417 scalar prevDist = GREAT;
2420 label pointi = order[i];
2421 scalar curDist = normalizedPosition[pointi];
2422 if (
mag(curDist - prevDist) > meshRefiner_.mergeDistance())
2424 seedPointDist.append(curDist);
2438 ListListOps::combine<scalarList>
2440 gatheredDist, accessOp<scalarList>()
2445 bitSet isFrozenPoint(baseMesh.nPoints(),
true);
2448 scalar minSeed =
min(allSeedPointDist);
2450 scalar maxSeed =
max(allSeedPointDist);
2453 forAll(normalizedPosition, posI)
2455 const scalar
pos = normalizedPosition[posI];
2458 (
mag(
pos-minSeed) < meshRefiner_.mergeDistance())
2459 || (
mag(
pos-maxSeed) < meshRefiner_.mergeDistance())
2473 Info<<
"Smoothing " << geometry[surfi].name() <<
':' <<
nl
2474 <<
" Direction : " << userDirection <<
nl
2475 <<
" Number of points : "
2477 <<
" (out of " << baseMesh.globalData().nTotalPoints()
2479 <<
" Smooth expansion iterations : "
2480 << shells.nSmoothExpansion()[shellI] <<
nl
2481 <<
" Smooth position iterations : "
2482 << shells.nSmoothPosition()[shellI] <<
nl
2483 <<
" Number of planes : "
2484 << allSeedPointDist.size()
2488 List<Tuple2<scalar, scalar>> keyAndValue(allSeedPointDist.size());
2497 shells.nSmoothExpansion()[shellI],
2507 const interpolationTable<scalar> table
2519 const point& curPoint = baseMesh.points()[pointi];
2520 scalar curDist = normalizedPosition[i];
2521 scalar newDist = table(curDist);
2522 scalar newPosition = startPosition + newDist*totalLength;
2523 baseNewPoints[pointi] +=
2524 userDirection * (newPosition - (curPoint &userDirection));
2528 vectorField disp(baseNewPoints-baseMesh.points());
2533 maxMagSqrEqOp<vector>(),
2536 baseMesh.movePoints(baseMesh.points()+disp);
2540 const_cast<Time&
>(baseMesh.time())++;
2542 Pout<<
"Writing directional expansion ratio smoothed"
2543 <<
" mesh to time " << meshRefiner_.timeName() <<
endl;
2553 baseMesh.time().path()/meshRefiner_.timeName()
2560 pointField baseMeshPoints(baseMesh.points());
2561 scalar initResidual = 0.0;
2562 scalar prevIterResidual = GREAT;
2563 for (iter = 0; iter < shells.nSmoothPosition()[shellI]; iter++)
2566 const edgeList& edges = baseMesh.edges();
2576 const edge&
e = edges[edgei];
2578 (unsmoothedPoints[
e[1]]&userDirection);
2581 (unsmoothedPoints[
e[0]]&userDirection);
2602 if (nSumXEdges[pointi] < 2)
2606 const labelList& pEdges = pointEdges[pointi];
2609 label edgei = pEdges[pE];
2612 const edge&
e = edges[edgei];
2613 label otherPt =
e.otherVertex(pointi);
2614 nSumOther[pointi]--;
2617 unsmoothedPoints[otherPt]
2644 if ((nSumOther[pointi] >= 2) && !isFrozenPoint[pointi])
2649 (unsmoothedPoints[pointi]&userDirection)
2650 +sumOther[pointi]/nSumOther[pointi]
2653 vector& v = baseNewPoints[pointi];
2654 v += (smoothPos-(v&userDirection))*userDirection;
2658 const vectorField residual(baseNewPoints - baseMeshPoints);
2660 scalar res(
gSum(
mag(residual)));
2666 res /= initResidual;
2668 if (
mag(prevIterResidual - res) < SMALL)
2670 Info<<
"Converged smoothing in iteration " << iter
2671 <<
" initResidual: " << initResidual
2672 <<
" final residual : " << res <<
endl;
2677 prevIterResidual = res;
2682 baseMeshPoints = baseNewPoints;
2687 vectorField dispSmooth(baseMeshPoints-baseMesh.points());
2692 maxMagSqrEqOp<vector>(),
2695 baseMesh.movePoints(baseMesh.points()+dispSmooth);
2699 const_cast<Time&
>(baseMesh.time())++;
2701 Pout<<
"Writing positional smoothing iteration "
2702 << iter <<
" mesh to time " << meshRefiner_.timeName()
2712 baseMesh.time().path()/meshRefiner_.timeName()
2721 void Foam::snappyRefineDriver::baffleAndSplitMesh
2723 const refinementParameters& refineParams,
2724 const snapParameters& snapParams,
2725 const bool handleSnapProblems,
2726 const dictionary& motionDict
2736 <<
"Splitting mesh at surface intersections" <<
nl
2737 <<
"---------------------------------------" <<
nl
2740 const fvMesh&
mesh = meshRefiner_.mesh();
2750 meshRefiner_.baffleAndSplitMesh
2756 refineParams.useTopologicalSnapDetection(),
2759 refineParams.nErodeCellZone(),
2763 globalToMasterPatch_,
2764 globalToSlavePatch_,
2765 refineParams.locationsInMesh(),
2766 refineParams.zonesInMesh(),
2767 refineParams.locationsOutsideMesh(),
2772 if (!handleSnapProblems)
2774 meshRefiner_.mergeFreeStandingBaffles
2777 refineParams.useTopologicalSnapDetection(),
2780 refineParams.planarAngle(),
2783 globalToMasterPatch_,
2784 globalToSlavePatch_,
2785 refineParams.locationsInMesh(),
2786 refineParams.locationsOutsideMesh(),
2793 void Foam::snappyRefineDriver::zonify
2795 const refinementParameters& refineParams,
2810 namedSurfaces.size()
2811 || refineParams.zonesInMesh().size()
2815 <<
"Introducing zones for interfaces" <<
nl
2816 <<
"--------------------------------" <<
nl
2819 const fvMesh&
mesh = meshRefiner_.mesh();
2828 refineParams.allowFreeStandingZoneFaces(),
2829 refineParams.nErodeCellZone(),
2830 refineParams.locationsInMesh(),
2831 refineParams.zonesInMesh(),
2837 Pout<<
"Writing zoned mesh to time "
2838 << meshRefiner_.timeName() <<
endl;
2857 void Foam::snappyRefineDriver::splitAndMergeBaffles
2859 const refinementParameters& refineParams,
2860 const snapParameters& snapParams,
2861 const bool handleSnapProblems,
2862 const dictionary& motionDict
2871 <<
"Handling cells with snap problems" <<
nl
2872 <<
"---------------------------------" <<
nl
2875 const fvMesh&
mesh = meshRefiner_.mesh();
2883 const scalarField& perpAngle = meshRefiner_.surfaces().perpendicularAngle();
2885 meshRefiner_.baffleAndSplitMesh
2891 refineParams.useTopologicalSnapDetection(),
2894 refineParams.nErodeCellZone(),
2898 globalToMasterPatch_,
2899 globalToSlavePatch_,
2900 refineParams.locationsInMesh(),
2901 refineParams.zonesInMesh(),
2902 refineParams.locationsOutsideMesh(),
2907 meshRefiner_.mergeFreeStandingBaffles
2910 refineParams.useTopologicalSnapDetection(),
2913 refineParams.planarAngle(),
2916 globalToMasterPatch_,
2917 globalToSlavePatch_,
2918 refineParams.locationsInMesh(),
2919 refineParams.locationsOutsideMesh(),
2930 meshRefiner_.dupNonManifoldPoints();
2936 label nCouples =
returnReduce(couples.size(), sumOp<label>());
2938 Info<<
"Detected unsplittable baffles : " << nCouples <<
endl;
2945 meshRefiner_.mergeBaffles(couples, Map<label>(0));
2950 meshRefiner_.checkData();
2954 meshRefiner_.splitMeshRegions
2956 globalToMasterPatch_,
2957 globalToSlavePatch_,
2958 refineParams.locationsInMesh(),
2959 refineParams.locationsOutsideMesh(),
2967 meshRefiner_.checkData();
2970 Info<<
"Merged free-standing baffles in = "
2976 Pout<<
"Writing handleProblemCells mesh to time "
2977 << meshRefiner_.timeName() <<
endl;
2999 if (faceZoneToPatches.size())
3002 <<
"Adding patches for face zones" <<
nl
3003 <<
"-----------------------------" <<
nl
3007 <<
setw(6) <<
"Patch"
3008 <<
setw(20) <<
"Type"
3009 <<
setw(30) <<
"Name"
3010 <<
setw(30) <<
"FaceZone"
3011 <<
setw(10) <<
"FaceType"
3013 <<
setw(6) <<
"-----"
3014 <<
setw(20) <<
"----"
3015 <<
setw(30) <<
"----"
3016 <<
setw(30) <<
"--------"
3017 <<
setw(10) <<
"--------"
3025 const word& fzName = iter.key();
3032 const word& masterName = fzName;
3042 <<
setw(30) << masterName
3043 <<
setw(30) << fzName
3053 <<
setw(30) << slaveName
3054 <<
setw(30) << fzName
3058 meshRefiner.
addFaceZone(fzName, masterName, slaveName, fzType);
3066 void Foam::snappyRefineDriver::mergePatchFaces
3080 <<
"Merge refined boundary faces" <<
nl
3081 <<
"----------------------------" <<
nl
3084 const fvMesh&
mesh = meshRefiner_.mesh();
3088 mergeType == meshRefinement::FaceMergeType::GEOMETRIC
3089 || mergeType == meshRefinement::FaceMergeType::IGNOREPATCH
3092 meshRefiner_.mergePatchFacesUndo
3096 meshRefiner_.meshedPatches(),
3105 meshRefiner_.mergePatchFaces
3110 meshRefiner_.meshedPatches(),
3111 meshRefinement::FaceMergeType::GEOMETRIC
3117 meshRefiner_.checkData();
3124 meshRefiner_.checkData();
3129 void Foam::snappyRefineDriver::deleteSmallRegions
3131 const refinementParameters& refineParams
3134 const fvMesh&
mesh = meshRefiner_.mesh();
3162 meshRefiner_.selectSeparatedCoupledFaces(isBlockedFace);
3166 if (ownPatch[facei] != -1)
3168 isBlockedFace[facei] =
true;
3175 for (
const auto& cz : czm)
3177 UIndirectList<label>(cellToZone, cz) = cz.index();
3181 const regionSplit cellRegion(
mesh, isBlockedFace);
3184 labelList nCellsPerRegion(cellRegion.nRegions(), 0);
3185 labelList regionToZone(cellRegion.nRegions(), -2);
3187 forAll(cellRegion, celli)
3189 const label regioni = cellRegion[celli];
3190 const label zonei = cellToZone[celli];
3193 regionToZone[regioni] = zonei;
3195 nCellsPerRegion[regioni]++;
3209 forAll(nCellsPerRegion, regioni)
3211 const label zonei = regionToZone[regioni];
3215 nCellsPerRegion[regioni]
3219 Info<<
"Deleting region " << regioni
3220 <<
" (size " << nCellsPerRegion[regioni]
3226 nCellsPerRegion[regioni] = 0;
3230 DynamicList<label> cellsToRemove(
mesh.
nCells()/128);
3231 forAll(cellRegion, celli)
3233 if (nCellsPerRegion[cellRegion[celli]] == 0)
3235 cellsToRemove.append(celli);
3240 cellsToRemove.size(),
3243 if (nTotCellsToRemove > 0)
3245 Info<<
"Deleting " << nTotCellsToRemove
3246 <<
" cells in small regions" <<
endl;
3248 removeCells cellRemover(
mesh);
3250 cellsToRemove.shrink();
3253 cellRemover.getExposedFaces(cellsToRemove)
3257 UIndirectList<label>(ownPatch, exposedFaces)
3259 (void)meshRefiner_.doRemoveCells
3275 const bool prepareForSnapping,
3282 <<
"Refinement phase" <<
nl
3283 <<
"----------------" <<
nl
3304 globalToMasterPatch_,
3307 voxelDriver.
doRefine(refineParams);
3323 max(meshRefiner_.surfaces().maxGapLevel()) > 0
3324 ||
max(meshRefiner_.shells().maxGapLevel()) > 0
3362 surfaceProximityBlock
3413 refinementInterfaceRefine
3420 directionalShellRefine
3440 max(meshRefiner_.shells().nSmoothExpansion()) > 0
3441 ||
max(meshRefiner_.shells().nSmoothPosition()) > 0
3444 directionalSmooth(refineParams);
3472 zonify(refineParams, zonesToFaceZone);
3486 const word& fzName = zonesToFaceZone[czNames];
3488 const word& masterName = fzName;
3489 const word slaveName = czNames.
second() +
"_to_" + czNames.first();
3491 faceZoneToPatches.insert(fzName,
patches);
3493 addFaceZones(meshRefiner_, refineParams, faceZoneToPatches);
3497 splitAndMergeBaffles
3506 if (prepareForSnapping)
3508 mergePatchFaces(mergeType, refineParams, motionDict);
3519 deleteSmallRegions(refineParams);
3526 <<
"Doing final balancing" <<
nl
3527 <<
"---------------------" <<
nl
3533 meshRefiner_.balance