88 return less(values_[a], values_[
b]);
132 label nMasterChanged = 0;
153 bitSet refinedInternalFace(nInternalFaces);
157 for (label faceI = 0; faceI < nInternalFaces; faceI++)
159 label oldOwn = map.
cellMap()[faceOwner[faceI]];
160 label oldNei = map.
cellMap()[faceNeighbour[faceI]];
164 oldOwn >= 0 && !oldRefineCell.test(oldOwn)
165 && oldNei >= 0 && !oldRefineCell.test(oldNei)
172 refinedInternalFace.
set(faceI);
185 label faceI =
pp.start();
189 label oldOwn = map.
cellMap()[faceOwner[faceI]];
191 if (oldOwn >= 0 && !oldRefineCell.test(oldOwn))
197 refinedBoundaryFace[faceI-nInternalFaces] =
true;
217 forAll(refinedInternalFace, faceI)
219 if (refinedInternalFace.test(faceI))
221 const cell& ownFaces =
cells[faceOwner[faceI]];
224 changedFace[ownFaces[ownI]] =
true;
226 const cell& neiFaces =
cells[faceNeighbour[faceI]];
229 changedFace[neiFaces[neiI]] =
true;
234 forAll(refinedBoundaryFace, i)
236 if (refinedBoundaryFace[i])
238 const cell& ownFaces =
cells[faceOwner[i+nInternalFaces]];
241 changedFace[ownFaces[ownI]] =
true;
262 forAll(changedFace, faceI)
264 if (changedFace[faceI] && isMasterFace.
test(faceI))
274 Pout<<
"getChangedFaces : Detected " 275 <<
" local:" << changedFaces.
size()
280 faceSet changedFacesSet(
mesh,
"changedFaces", changedFaces);
281 Pout<<
"getChangedFaces : Writing " << changedFaces.
size()
282 <<
" changed faces to faceSet " << changedFacesSet.
name()
284 changedFacesSet.
write();
294 bool Foam::meshRefinement::markForRefine
296 const label markValue,
297 const label nAllowRefine,
305 cellValue = markValue;
309 return nRefine <= nAllowRefine;
313 void Foam::meshRefinement::markFeatureCellLevel
335 Cloud<trackedParticle> startPointCloud
347 for (
const point& keepPoint : keepPoints)
349 const label celli = mesh_.cellTree().findInside(keepPoint);
357 const edgeMesh& featureMesh = features_[feati];
358 const label featureLevel = features_.levels()[feati][0];
363 label nRegions = featureMesh.regions(edgeRegion);
366 bitSet regionVisited(nRegions);
372 forAll(pointEdges, pointi)
374 if (pointEdges[pointi].size() != 2)
378 Pout<<
"Adding particle from point:" << pointi
379 <<
" coord:" << featureMesh.points()[pointi]
380 <<
" since number of emanating edges:" 381 << pointEdges[pointi].size()
386 startPointCloud.addParticle
393 featureMesh.points()[pointi],
402 if (pointEdges[pointi].size() > 0)
404 label e0 = pointEdges[pointi][0];
405 label regioni = edgeRegion[e0];
406 regionVisited.set(regioni);
414 forAll(featureMesh.edges(), edgei)
416 if (regionVisited.set(edgeRegion[edgei]))
418 const edge&
e = featureMesh.edges()[edgei];
419 label pointi =
e.start();
422 Pout<<
"Adding particle from point:" << pointi
423 <<
" coord:" << featureMesh.points()[pointi]
424 <<
" on circular region:" << edgeRegion[edgei]
429 startPointCloud.addParticle
436 featureMesh.points()[pointi],
451 maxFeatureLevel =
labelList(mesh_.nCells(), -1);
454 List<bitSet> featureEdgeVisited(features_.size());
458 featureEdgeVisited[featI].setSize(features_[featI].edges().size());
459 featureEdgeVisited[featI] =
false;
463 trackedParticle::trackingData
td 474 scalar maxTrackLen = 2.0*mesh_.bounds().mag();
478 Pout<<
"Tracking " << startPointCloud.size()
479 <<
" particles over distance " << maxTrackLen
480 <<
" to find the starting cell" <<
endl;
482 startPointCloud.move(startPointCloud,
td, maxTrackLen);
486 maxFeatureLevel = -1;
489 featureEdgeVisited[featI] =
false;
494 Cloud<trackedParticle> cloud(mesh_,
Foam::zero{},
"featureCloud");
498 Pout<<
"Constructing cloud for cell marking" <<
endl;
501 for (
const trackedParticle& startTp : startPointCloud)
503 const label featI = startTp.i();
504 const label pointI = startTp.j();
506 const edgeMesh& featureMesh = features_[featI];
507 const labelList& pEdges = featureMesh.pointEdges()[pointI];
512 label edgeI = pEdges[pEdgeI];
514 if (featureEdgeVisited[featI].
set(edgeI))
519 const edge&
e = featureMesh.edges()[edgeI];
520 label otherPointi =
e.otherVertex(pointI);
522 trackedParticle* tp(
new trackedParticle(startTp));
523 tp->start() = tp->position();
524 tp->end() = featureMesh.points()[otherPointi];
525 tp->j() = otherPointi;
530 Pout<<
"Adding particle for point:" << pointI
531 <<
" coord:" << tp->position()
532 <<
" feature:" << featI
533 <<
" to track to:" << tp->end()
537 cloud.addParticle(tp);
542 startPointCloud.clear();
550 Pout<<
"Tracking " << cloud.size()
551 <<
" particles over distance " << maxTrackLen
552 <<
" to mark cells" <<
endl;
554 cloud.move(cloud,
td, maxTrackLen);
557 for (trackedParticle& tp : cloud)
559 const label featI = tp.i();
560 const label pointI = tp.j();
562 const edgeMesh& featureMesh = features_[featI];
563 const labelList& pEdges = featureMesh.pointEdges()[pointI];
568 bool keepParticle =
false;
572 label edgeI = pEdges[i];
574 if (featureEdgeVisited[featI].
set(edgeI))
579 const edge&
e = featureMesh.edges()[edgeI];
580 label otherPointi =
e.otherVertex(pointI);
582 tp.start() = tp.position();
583 tp.end() = featureMesh.points()[otherPointi];
584 tp.j() = otherPointi;
595 cloud.deleteParticle(tp);
602 Pout<<
"Remaining particles " << cloud.size() <<
endl;
630 Foam::label Foam::meshRefinement::markFeatureRefinement
633 const label nAllowRefine,
641 markFeatureCellLevel(keepPoints, maxFeatureLevel);
646 const labelList& cellLevel = meshCutter_.cellLevel();
650 forAll(maxFeatureLevel, cellI)
652 if (maxFeatureLevel[cellI] > cellLevel[cellI])
678 Info<<
"Reached refinement limit." <<
endl;
686 Foam::label Foam::meshRefinement::markInternalDistanceToFeatureRefinement
688 const label nAllowRefine,
694 const labelList& cellLevel = meshCutter_.cellLevel();
695 const pointField& cellCentres = mesh_.cellCentres();
698 if (features_.maxDistance() <= 0.0)
707 labelList testLevels(cellLevel.size()-nRefine);
712 if (refineCell[cellI] == -1)
714 testCc[testI] = cellCentres[cellI];
715 testLevels[testI] = cellLevel[cellI];
722 features_.findHigherLevel(testCc, testLevels, maxLevel);
729 if (refineCell[cellI] == -1)
731 if (maxLevel[testI] > testLevels[testI])
733 bool reachedLimit = !markForRefine
745 Pout<<
"Stopped refining internal cells" 746 <<
" since reaching my cell limit of " 747 << mesh_.nCells()+7*nRefine <<
endl;
762 Info<<
"Reached refinement limit." <<
endl;
770 Foam::label Foam::meshRefinement::markInternalRefinement
772 const label nAllowRefine,
778 const labelList& cellLevel = meshCutter_.cellLevel();
779 const pointField& cellCentres = mesh_.cellCentres();
785 labelList testLevels(cellLevel.size()-nRefine);
790 if (refineCell[cellI] == -1)
792 testCc[testI] = cellCentres[cellI];
793 testLevels[testI] = cellLevel[cellI];
800 shells_.findHigherLevel(testCc, testLevels, maxLevel);
807 if (refineCell[cellI] == -1)
809 if (maxLevel[testI] > testLevels[testI])
811 bool reachedLimit = !markForRefine
823 Pout<<
"Stopped refining internal cells" 824 <<
" since reaching my cell limit of " 825 << mesh_.nCells()+7*nRefine <<
endl;
840 Info<<
"Reached refinement limit." <<
endl;
847 Foam::label Foam::meshRefinement::unmarkInternalRefinement
853 const labelList& cellLevel = meshCutter_.cellLevel();
854 const pointField& cellCentres = mesh_.cellCentres();
865 if (refineCell[cellI] >= 0)
867 testCc[testI] = cellCentres[cellI];
868 testLevels[testI] = cellLevel[cellI];
875 limitShells_.findLevel(testCc, testLevels, levelShell);
882 if (refineCell[cellI] >= 0)
884 if (levelShell[testI] != -1)
886 refineCell[cellI] = -1;
908 const labelList& surfIndex = surfaceIndex();
915 if (surfIndex[faceI] != -1)
917 label own = mesh_.faceOwner()[faceI];
919 if (mesh_.isInternalFace(faceI))
921 label nei = mesh_.faceNeighbour()[faceI];
923 if (refineCell[own] == -1 || refineCell[nei] == -1)
925 testFaces[nTest++] = faceI;
930 const label bFacei = faceI - mesh_.nInternalFaces();
931 if (refineCell[own] == -1 || boundaryRefineCell[bFacei] == -1)
933 testFaces[nTest++] = faceI;
938 testFaces.setSize(nTest);
945 Foam::label Foam::meshRefinement::markSurfaceRefinement
947 const label nAllowRefine,
955 const labelList& cellLevel = meshCutter_.cellLevel();
965 labelList testFaces(getRefineCandidateFaces(refineCell));
990 surfaces_.findHigherIntersection
1007 label faceI = testFaces[i];
1009 label surfI = surfaceHit[i];
1019 label own = mesh_.faceOwner()[faceI];
1021 if (surfaceMinLevel[i] > cellLevel[own])
1039 if (mesh_.isInternalFace(faceI))
1041 label nei = mesh_.faceNeighbour()[faceI];
1042 if (surfaceMinLevel[i] > cellLevel[nei])
1069 Info<<
"Reached refinement limit." <<
endl;
1077 Foam::label Foam::meshRefinement::countMatches
1079 const List<point>& normals1,
1080 const List<point>& normals2,
1088 const vector& n1 = normals1[i];
1092 const vector& n2 = normals2[j];
1117 bool Foam::meshRefinement::highCurvature
1119 const scalar minCosAngle,
1120 const scalar lengthScale,
1127 const scalar cosAngle = (n0&n1);
1129 if (cosAngle < minCosAngle)
1134 else if (cosAngle > 1-1
e-6)
1139 else if (lengthScale > SMALL)
1144 const plane pl0(
p0, (n0 ^ axis));
1145 const scalar r1 = pl0.normalIntersect(p1, n1);
1149 const plane pl1(p1, (n1 ^ axis));
1150 const scalar r0 = pl1.normalIntersect(
p0, n0);
1155 const scalar radius = 0.5*(
mag(r1)+
mag(r0));
1157 if (radius < lengthScale)
1175 Foam::label Foam::meshRefinement::markSurfaceCurvatureRefinement
1177 const scalar curvature,
1178 const label nAllowRefine,
1186 const labelList& cellLevel = meshCutter_.cellLevel();
1187 const pointField& cellCentres = mesh_.cellCentres();
1203 labelList testFaces(getRefineCandidateFaces(refineCell));
1213 label faceI = testFaces[i];
1215 label own = mesh_.faceOwner()[faceI];
1217 if (mesh_.isInternalFace(faceI))
1219 label nei = mesh_.faceNeighbour()[faceI];
1221 start[i] = cellCentres[own];
1222 end[i] = cellCentres[nei];
1223 minLevel[i] =
min(cellLevel[own], cellLevel[nei]);
1227 label bFaceI = faceI - mesh_.nInternalFaces();
1229 start[i] = cellCentres[own];
1230 end[i] = neiCc[bFaceI];
1232 if (!isMasterFace[faceI])
1234 std::swap(start[i],
end[i]);
1237 minLevel[i] =
min(cellLevel[own], neiLevel[bFaceI]);
1250 const bool hasCurvatureLevels = (
max(surfaces_.maxCurvatureLevel()) > 0);
1256 List<pointList> cellSurfLocations(mesh_.nCells());
1257 List<vectorList> cellSurfNormals(mesh_.nCells());
1261 List<pointList> surfaceLocation;
1263 List<vectorList> surfaceNormal;
1267 surfaces_.findAllIntersections
1274 labelList(surfaces_.maxLevel().size(), 0),
1275 surfaces_.maxLevel(),
1287 forAll(surfaceNormal, pointI)
1289 pointList& pLocations = surfaceLocation[pointI];
1290 vectorList& pNormals = surfaceNormal[pointI];
1291 labelList& pLevel = surfaceLevel[pointI];
1293 sortedOrder(pNormals, visitOrder, normalLess(pLocations));
1295 pLocations = List<point>(pLocations, visitOrder);
1296 pNormals = List<vector>(pNormals, visitOrder);
1371 label faceI = testFaces[i];
1372 label own = mesh_.faceOwner()[faceI];
1374 const pointList& fPoints = surfaceLocation[i];
1375 const vectorList& fNormals = surfaceNormal[i];
1376 const labelList& fLevels = surfaceLevel[i];
1380 if (fLevels[hitI] > cellLevel[own])
1382 cellSurfLevels[own].append(fLevels[hitI]);
1383 cellSurfLocations[own].append(fPoints[hitI]);
1384 cellSurfNormals[own].append(fNormals[hitI]);
1387 if (mesh_.isInternalFace(faceI))
1389 label nei = mesh_.faceNeighbour()[faceI];
1390 if (fLevels[hitI] > cellLevel[nei])
1392 cellSurfLevels[nei].append(fLevels[hitI]);
1393 cellSurfLocations[nei].append(fPoints[hitI]);
1394 cellSurfNormals[nei].append(fNormals[hitI]);
1408 forAll(cellSurfNormals, cellI)
1410 const vectorList& normals = cellSurfNormals[cellI];
1414 nNormals += normals.
size();
1417 reduce(nSet, sumOp<label>());
1418 reduce(nNormals, sumOp<label>());
1419 Info<<
"markSurfaceCurvatureRefinement :" 1420 <<
" cells:" << mesh_.globalData().nTotalCells()
1421 <<
" of which with normals:" << nSet
1422 <<
" ; total normals stored:" << nNormals
1428 bool reachedLimit =
false;
1437 !reachedLimit && cellI < cellSurfLocations.size();
1442 const vectorList& normals = cellSurfNormals[cellI];
1443 const labelList& levels = cellSurfLevels[cellI];
1446 const scalar cellSize =
1447 meshCutter_.level0EdgeLength()/
pow(2.0, cellLevel[cellI]);
1450 for (label i = 0; !reachedLimit && i < normals.size(); i++)
1452 for (label j = i+1; !reachedLimit && j < normals.size(); j++)
1463 (hasCurvatureLevels ? cellSize : scalar(0)),
1471 const label maxLevel =
max(levels[i], levels[j]);
1473 if (cellLevel[cellI] < maxLevel)
1488 Pout<<
"Stopped refining since reaching my cell" 1489 <<
" limit of " << mesh_.nCells()+7*nRefine
1492 reachedLimit =
true;
1512 !reachedLimit && faceI < mesh_.nInternalFaces();
1516 label own = mesh_.faceOwner()[faceI];
1517 label nei = mesh_.faceNeighbour()[faceI];
1519 const pointList& ownPoints = cellSurfLocations[own];
1520 const vectorList& ownNormals = cellSurfNormals[own];
1521 const labelList& ownLevels = cellSurfLevels[own];
1522 const pointList& neiPoints = cellSurfLocations[nei];
1523 const vectorList& neiNormals = cellSurfNormals[nei];
1524 const labelList& neiLevels = cellSurfLevels[nei];
1532 countMatches(ownNormals, neiNormals)
1533 == ownNormals.
size();
1536 countMatches(neiNormals, ownNormals)
1537 == neiNormals.size();
1540 if (!ownIsSubset && !neiIsSubset)
1543 const scalar cellSize =
1544 meshCutter_.level0EdgeLength()
1545 /
pow(2.0,
min(cellLevel[own], cellLevel[nei]));
1548 for (label i = 0; !reachedLimit && i < ownNormals.size(); i++)
1550 for (label j = 0; !reachedLimit && j < neiNormals.size(); j++)
1559 (hasCurvatureLevels ? cellSize : scalar(0)),
1568 if (cellLevel[own] < ownLevels[i])
1583 Pout<<
"Stopped refining since reaching" 1584 <<
" my cell limit of " 1585 << mesh_.nCells()+7*nRefine <<
endl;
1587 reachedLimit =
true;
1591 if (cellLevel[nei] < neiLevels[j])
1606 Pout<<
"Stopped refining since reaching" 1607 <<
" my cell limit of " 1608 << mesh_.nCells()+7*nRefine <<
endl;
1610 reachedLimit =
true;
1624 List<vectorList> neiSurfacePoints;
1626 List<vectorList> neiSurfaceNormals;
1632 label faceI = mesh_.nInternalFaces();
1633 !reachedLimit && faceI < mesh_.nFaces();
1637 label own = mesh_.faceOwner()[faceI];
1638 label bFaceI = faceI - mesh_.nInternalFaces();
1640 const pointList& ownPoints = cellSurfLocations[own];
1641 const vectorList& ownNormals = cellSurfNormals[own];
1642 const labelList& ownLevels = cellSurfLevels[own];
1644 const pointList& neiPoints = neiSurfacePoints[bFaceI];
1645 const vectorList& neiNormals = neiSurfaceNormals[bFaceI];
1653 countMatches(ownNormals, neiNormals)
1654 == ownNormals.
size();
1657 countMatches(neiNormals, ownNormals)
1658 == neiNormals.size();
1661 if (!ownIsSubset && !neiIsSubset)
1664 const scalar cellSize =
1665 meshCutter_.level0EdgeLength()
1666 /
pow(2.0,
min(cellLevel[own], neiLevel[bFaceI]));
1669 for (label i = 0; !reachedLimit && i < ownNormals.size(); i++)
1671 for (label j = 0; !reachedLimit && j < neiNormals.size(); j++)
1680 (hasCurvatureLevels ? cellSize : scalar(0)),
1688 if (cellLevel[own] < ownLevels[i])
1703 Pout<<
"Stopped refining since reaching" 1704 <<
" my cell limit of " 1705 << mesh_.nCells()+7*nRefine
1708 reachedLimit =
true;
1725 Info<<
"Reached refinement limit." <<
endl;
1734 const scalar planarCos,
1744 vector d = point1-point0;
1745 scalar magD =
mag(d);
1747 if (magD > mergeDistance())
1749 scalar cosAngle = (normal0 & normal1);
1752 if (cosAngle < (-1+planarCos))
1755 avg = 0.5*(normal0-normal1);
1757 else if (cosAngle > (1-planarCos))
1759 avg = 0.5*(normal0+normal1);
1762 if (avg != vector::zero)
1767 if (
mag(avg&d) > mergeDistance())
1781 const scalar planarCos,
1795 vector d = point1-point0;
1796 scalar magD =
mag(d);
1798 if (magD > mergeDistance())
1800 scalar cosAngle = (normal0 & normal1);
1803 if (cosAngle < (-1+planarCos))
1806 avgNormal = 0.5*(normal0-normal1);
1808 else if (cosAngle > (1-planarCos))
1810 avgNormal = 0.5*(normal0+normal1);
1813 if (avgNormal != vector::zero)
1815 avgNormal /=
mag(avgNormal);
1837 bool Foam::meshRefinement::checkProximity
1839 const scalar planarCos,
1840 const label nAllowRefine,
1842 const label surfaceLevel,
1843 const vector& surfaceLocation,
1844 const vector& surfaceNormal,
1848 label& cellMaxLevel,
1856 const labelList& cellLevel = meshCutter_.cellLevel();
1859 if (surfaceLevel > cellLevel[cellI])
1861 if (cellMaxLevel == -1)
1864 cellMaxLevel = surfaceLevel;
1865 cellMaxLocation = surfaceLocation;
1866 cellMaxNormal = surfaceNormal;
1875 bool closeSurfaces = isNormalGap
1888 if (surfaceLevel > cellMaxLevel)
1890 cellMaxLevel = surfaceLevel;
1891 cellMaxLocation = surfaceLocation;
1892 cellMaxNormal = surfaceNormal;
1906 return markForRefine
1922 Foam::label Foam::meshRefinement::markProximityRefinement
1924 const scalar planarCos,
1929 const label nAllowRefine,
1937 const labelList& cellLevel = meshCutter_.cellLevel();
1950 const labelList testFaces(getRefineCandidateFaces(refineCell));
1971 labelList cellMaxLevel(mesh_.nCells(), -1);
1977 List<vectorList> surfaceLocation;
1978 List<vectorList> surfaceNormal;
1982 surfaces_.findAllIntersections
2006 label faceI = testFaces[i];
2007 label own = mesh_.faceOwner()[faceI];
2009 const labelList& fLevels = surfaceLevel[i];
2010 const vectorList& fPoints = surfaceLocation[i];
2011 const vectorList& fNormals = surfaceNormal[i];
2026 cellMaxLocation[own],
2034 if (mesh_.isInternalFace(faceI))
2036 label nei = mesh_.faceNeighbour()[faceI];
2051 cellMaxLocation[nei],
2065 labelList neiBndMaxLevel(mesh_.nBoundaryFaces());
2066 pointField neiBndMaxLocation(mesh_.nBoundaryFaces());
2067 vectorField neiBndMaxNormal(mesh_.nBoundaryFaces());
2069 for (label faceI = mesh_.nInternalFaces(); faceI < mesh_.nFaces(); faceI++)
2071 label bFaceI = faceI-mesh_.nInternalFaces();
2072 label own = mesh_.faceOwner()[faceI];
2074 neiBndMaxLevel[bFaceI] = cellMaxLevel[own];
2075 neiBndMaxLocation[bFaceI] = cellMaxLocation[own];
2076 neiBndMaxNormal[bFaceI] = cellMaxNormal[own];
2085 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
2087 label own = mesh_.faceOwner()[faceI];
2088 label nei = mesh_.faceNeighbour()[faceI];
2090 if (cellMaxLevel[own] != -1 && cellMaxLevel[nei] != -1)
2099 cellMaxLocation[own],
2102 cellMaxLocation[nei],
2108 if (cellLevel[own] < cellMaxLevel[own])
2123 Pout<<
"Stopped refining since reaching my cell" 2124 <<
" limit of " << mesh_.nCells()+7*nRefine
2131 if (cellLevel[nei] < cellMaxLevel[nei])
2146 Pout<<
"Stopped refining since reaching my cell" 2147 <<
" limit of " << mesh_.nCells()+7*nRefine
2157 for (label faceI = mesh_.nInternalFaces(); faceI < mesh_.nFaces(); faceI++)
2159 label own = mesh_.faceOwner()[faceI];
2160 label bFaceI = faceI - mesh_.nInternalFaces();
2162 if (cellLevel[own] < cellMaxLevel[own] && neiBndMaxLevel[bFaceI] != -1)
2171 cellMaxLocation[own],
2174 neiBndMaxLocation[bFaceI],
2175 neiBndMaxNormal[bFaceI]
2192 Pout<<
"Stopped refining since reaching my cell" 2193 <<
" limit of " << mesh_.nCells()+7*nRefine
2208 Info<<
"Reached refinement limit." <<
endl;
2225 const scalar curvature,
2226 const scalar planarAngle,
2228 const bool featureRefinement,
2229 const bool featureDistanceRefinement,
2230 const bool internalRefinement,
2231 const bool surfaceRefinement,
2232 const bool curvatureRefinement,
2233 const bool smallFeatureRefinement,
2234 const bool gapRefinement,
2235 const bool bigGapRefinement,
2236 const bool spreadGapSize,
2237 const label maxGlobalCells,
2238 const label maxLocalCells
2241 label totNCells = mesh_.globalData().nTotalCells();
2245 if (totNCells >= maxGlobalCells)
2247 Info<<
"No cells marked for refinement since reached limit " 2248 << maxGlobalCells <<
'.' <<
endl;
2282 labelList neiLevel(mesh_.nBoundaryFaces());
2284 calcNeighbourData(neiLevel, neiCc);
2293 if (featureRefinement)
2295 label nFeatures = markFeatureRefinement
2304 Info<<
"Marked for refinement due to explicit features " 2305 <<
": " << nFeatures <<
" cells." <<
endl;
2311 if (featureDistanceRefinement)
2313 label nShell = markInternalDistanceToFeatureRefinement
2320 Info<<
"Marked for refinement due to distance to explicit features " 2321 ": " << nShell <<
" cells." <<
endl;
2327 if (internalRefinement)
2329 label nShell = markInternalRefinement
2336 Info<<
"Marked for refinement due to refinement shells " 2337 <<
": " << nShell <<
" cells." <<
endl;
2343 if (surfaceRefinement)
2345 label nSurf = markSurfaceRefinement
2354 Info<<
"Marked for refinement due to surface intersection " 2355 <<
": " << nSurf <<
" cells." <<
endl;
2363 &&
max(shells_.maxGapLevel()) > 0
2366 label nGapSurf = markSurfaceGapRefinement
2376 Info<<
"Marked for refinement due to surface intersection" 2378 <<
": " << nGapSurf <<
" cells." <<
endl;
2388 && (curvature >= -1 && curvature <= 1)
2389 && (surfaces_.minLevel() != surfaces_.maxLevel())
2392 label nCurv = markSurfaceCurvatureRefinement
2402 Info<<
"Marked for refinement due to curvature/regions " 2403 <<
": " << nCurv <<
" cells." <<
endl;
2410 if (smallFeatureRefinement)
2417 &&
max(shells_.maxGapLevel()) > 0
2420 nGap = markSmallFeatureRefinement
2431 Info<<
"Marked for refinement due to close opposite surfaces " 2432 <<
": " << nGap <<
" cells." <<
endl;
2435 if (
max(surfaces_.maxCurvatureLevel()) > 0)
2437 nCurv = markSurfaceFieldRefinement
2446 Info<<
"Marked for refinement" 2447 <<
" due to curvature " 2448 <<
": " << nCurv <<
" cells." <<
endl;
2456 const labelList& surfaceGapLevel = surfaces_.gapLevel();
2461 && (planarCos >= -1 && planarCos <= 1)
2462 && (
max(surfaceGapLevel) > -1)
2465 Info<<
"Specified gap level : " <<
max(surfaceGapLevel)
2466 <<
", planar angle " << planarAngle <<
endl;
2468 label nGap = markProximityRefinement
2482 Info<<
"Marked for refinement due to close opposite surfaces " 2483 <<
": " << nGap <<
" cells." <<
endl;
2493 && (planarCos >= -1 && planarCos <= 1)
2494 &&
max(shells_.maxGapLevel()) > 0
2501 label nGap = markInternalGapRefinement
2512 Info<<
"Marked for refinement due to opposite surfaces" 2514 <<
": " << nGap <<
" cells." <<
endl;
2521 if (limitShells_.shells().size())
2523 label nUnmarked = unmarkInternalRefinement(
refineCell, nRefine);
2526 Info<<
"Unmarked for refinement due to limit shells" 2527 <<
" : " << nUnmarked <<
" cells." <<
endl;
2536 cellsToRefine.
setSize(nRefine);
2543 cellsToRefine[nRefine++] = cellI;
2548 return cellsToRefine;
2561 meshCutter_.setRefinement(cellsToRefine, meshMod);
2565 mesh_.moving(
false);
2572 mesh_.updateMesh(map);
2589 updateMesh(map, getChangedFaces(map, cellsToRefine));
2599 decompositionMethod& decomposer,
2600 fvMeshDistribute& distributor,
2602 const scalar maxLoadUnbalance,
2603 const label maxCellUnbalance
2606 autoPtr<mapDistributePolyMesh> distMap;
2612 const scalar nNewCells =
2613 scalar(mesh_.nCells() + 7*cellsToRefine.size());
2614 const scalar nNewCellsAll =
returnReduce(nNewCells, sumOp<scalar>());
2618 mag(1.0-nNewCells/nIdealNewCells),
2624 const scalar nNewCellsOnly = scalar(7*cellsToRefine.size());
2626 const label maxNewCells =
2629 const label maxDeltaCells =
2639 (maxNewCells <= maxCellUnbalance)
2640 && (maxDeltaCells <= maxCellUnbalance)
2643 Info<<
"Skipping balancing since trigger value not reached:" <<
"\n" 2644 <<
" Trigger cell count: " << maxCellUnbalance <<
nl 2645 <<
" Max new cell count in proc: " << maxNewCells <<
nl 2646 <<
" Max difference between new cells and balanced: " 2647 << maxDeltaCells <<
nl 2648 <<
" Max load unbalance " << maxLoadUnbalance
2653 if (unbalance <= maxLoadUnbalance)
2655 Info<<
"Skipping balancing since max unbalance " << unbalance
2656 <<
" is less than allowable " << maxLoadUnbalance
2661 Info<<
"Balancing since max unbalance " << unbalance
2662 <<
" is larger than allowable " << maxLoadUnbalance
2668 cellWeights[cellsToRefine[i]] += 7;
2682 distMap().distributeCellIndices(cellsToRefine);
2684 Info<<
"Balanced mesh in = " 2685 << mesh_.time().cpuTimeIncrement() <<
" s" <<
endl;
2687 printMeshInfo(
debug,
"After balancing " + msg,
true);
2692 Pout<<
"Writing balanced " << msg
2697 writeType(writeLevel() | WRITEMESH),
2700 Pout<<
"Dumped debug data in = " 2701 << mesh_.time().cpuTimeIncrement() <<
" s" <<
endl;
2720 decompositionMethod& decomposer,
2721 fvMeshDistribute& distributor,
2723 const scalar maxLoadUnbalance,
2724 const label maxCellUnbalance
2730 refine(cellsToRefine);
2734 Pout<<
"Writing refined but unbalanced " << msg
2742 Pout<<
"Dumped debug data in = " 2743 << mesh_.time().cpuTimeIncrement() <<
" s" <<
endl;
2749 Info<<
"Refined mesh in = " 2750 << mesh_.time().cpuTimeIncrement() <<
" s" <<
endl;
2751 printMeshInfo(
debug,
"After refinement " + msg,
true);
2759 auto distMap = balance
2778 decompositionMethod& decomposer,
2779 fvMeshDistribute& distributor,
2781 const scalar maxLoadUnbalance,
2782 const label maxCellUnbalance
2785 labelList cellsToRefine(initCellsToRefine);
2815 auto distMap = balance
2830 refine(cellsToRefine);
2834 Pout<<
"Writing refined " << msg
2842 Pout<<
"Dumped debug data in = " 2843 << mesh_.time().cpuTimeIncrement() <<
" s" <<
endl;
2849 Info<<
"Refined mesh in = " 2850 << mesh_.time().cpuTimeIncrement() <<
" s" <<
endl;
2864 printMeshInfo(
debug,
"After refinement " + msg,
true);
2872 const label maxGlobalCells,
2873 const label maxLocalCells,
2878 const labelList& cellLevel = meshCutter_.cellLevel();
2879 const pointField& cellCentres = mesh_.cellCentres();
2881 label totNCells = mesh_.globalData().nTotalCells();
2885 if (totNCells >= maxGlobalCells)
2887 Info<<
"No cells marked for refinement since reached limit " 2888 << maxGlobalCells <<
'.' <<
endl;
2902 shells_.findDirectionalLevel
2912 forAll(insideShell, celli)
2914 if (insideShell[celli] >= 0)
2916 bool reachedLimit = !markForRefine
2928 Pout<<
"Stopped refining cells" 2929 <<
" since reaching my cell limit of " 2930 << mesh_.nCells()+nAllowRefine <<
endl;
2941 label nUnmarked = unmarkInternalRefinement(refineCell, nRefine);
2944 Info<<
"Unmarked for refinement due to limit shells" 2945 <<
" : " << nUnmarked <<
" cells." <<
endl;
2954 cellsToRefine.setSize(nRefine);
2957 forAll(refineCell, cellI)
2959 if (refineCell[cellI] != -1)
2961 cellsToRefine[nRefine++] = cellI;
2966 return cellsToRefine;
2980 List<refineCell> refCells(cellsToRefine.size());
2983 refCells[i] = refineCell(cellsToRefine[i], refDir);
2987 hexCellLooper cellWalker(mesh_);
2990 cellCuts cuts(mesh_, cellWalker, refCells);
2998 meshRefiner.setRefinement(cuts, meshMod);
3002 mesh_.moving(
false);
3007 mesh_.updateMesh(*morphMap);
3010 if (morphMap().hasMotionPoints())
3012 mesh_.movePoints(morphMap().preMotionPoints());
3024 meshRefiner.updateMesh(*morphMap);
3027 updateMesh(*morphMap, getChangedFaces(*morphMap, cellsToRefine));
void size(const label n)
Older name for setAddressableSize.
const polyMesh & mesh() const noexcept
Return polyMesh.
autoPtr< mapDistributePolyMesh > refineAndBalance(const string &msg, decompositionMethod &decomposer, fvMeshDistribute &distributor, const labelList &cellsToRefine, const scalar maxLoadUnbalance, const label maxCellUnbalance)
Refine some cells and rebalance.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
virtual const labelList & faceNeighbour() const
Return face neighbour.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
const word & name() const noexcept
Return the object name.
wallPoints::trackData td(isBlockedFace, regionToBlockSize)
bool isNormalGap(const scalar planarCos, const label level0, const vector &point0, const vector &normal0, const label level1, const vector &point1, const vector &normal1) const
Is local topology a small gap normal to the test vector.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
constexpr char nl
The newline '\n' character (0x0a)
UIndirectList< label > labelUIndList
UIndirectList of labels.
Ostream & endl(Ostream &os)
Add newline and flush stream.
A traits class, which is primarily used for primitives and vector-space.
labelList findIndices(const ListType &input, typename ListType::const_reference val, label start=0)
Linear search to find all occurrences of given element.
const cellList & cells() const
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
labelList refineCandidates(const pointField &keepPoints, const scalar curvature, const scalar planarAngle, const bool featureRefinement, const bool featureDistanceRefinement, const bool internalRefinement, const bool surfaceRefinement, const bool curvatureRefinement, const bool smallFeatureRefinement, const bool gapRefinement, const bool bigGapRefinement, const bool spreadGapSize, const label maxGlobalCells, const label maxLocalCells) const
Calculate list of cells to refine.
List< vector > vectorList
List of vector.
label nFaces() const noexcept
Number of mesh faces.
autoPtr< mapPolyMesh > directionalRefine(const string &msg, const direction cmpt, const labelList &cellsToRefine)
Directionally refine in direction cmpt.
List< labelList > labelListList
List of labelList.
Description of cuts across cells.
static bool less(const vector &x, const vector &y)
To compare normals.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const fvMesh & mesh() const
Reference to mesh.
void reduce(T &value, [[maybe_unused]] BinaryOp bop, [[maybe_unused]] const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce)
#define forAll(list, i)
Loop across all elements in list.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
vectorField pointField
pointField is a vectorField.
const dimensionedScalar e
Elementary charge.
void setSize(const label n)
Alias for resize()
dimensionedScalar cos(const dimensionedScalar &ds)
const labelList & cellMap() const noexcept
Old cell map.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
void clear()
Clear the list, i.e. set size to zero.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual const labelList & faceOwner() const
Return face owner.
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
const globalMeshData & globalData() const
Return parallel info (demand-driven)
label nInternalFaces() const noexcept
Number of internal faces.
Container with cells to refine. Refinement given as single direction.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
labelList directionalRefineCandidates(const label maxGlobalCells, const label maxLocalCells, const labelList ¤tLevel, const direction dir) const
Calculate list of cells to directionally refine.
bool test(const label pos) const
Test for True value at specified position, never auto-vivify entries.
autoPtr< mapDistributePolyMesh > balanceAndRefine(const string &msg, decompositionMethod &decomposer, fvMeshDistribute &distributor, const labelList &cellsToRefine, const scalar maxLoadUnbalance, const label maxCellUnbalance)
Balance before refining some cells.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
autoPtr< mapDistributePolyMesh > balance(const bool keepZoneFaces, const bool keepBaffles, const labelList &singleProcPoints, const scalarField &cellWeights, decompositionMethod &decomposer, fvMeshDistribute &distributor)
Redecompose according to cell count.
int debug
Static debugging option.
label nOldCells() const noexcept
Number of old cells.
bool hasMotionPoints() const noexcept
Has valid preMotionPoints?
autoPtr< mapPolyMesh > refine(const labelList &cellsToRefine)
Refine some cells.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
vector point
Point is a vector.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
A cell is defined as a list of faces with extra functionality.
Direct mesh changes based on v1.3 polyTopoChange syntax.
normalLess(const vectorList &values)
messageStream Info
Information stream (stdout output on master, null elsewhere)
label nTotalFaces() const noexcept
Total global number of mesh faces. Not compensated for duplicate faces!
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
writeType
Enumeration for what to write. Used as a bit-pattern.
Field< vector > vectorField
Specialisation of Field<T> for vector.
debugType
Enumeration for what to debug. Used as a bit-pattern.
std::enable_if_t< std::is_same_v< bool, TypeT >, bool > set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Mesh consisting of general polyhedral cells.
bool isGap(const scalar, const vector &, const vector &, const vector &, const vector &) const
Is local topology a small gap?
List< point > pointList
List of point.
List< label > labelList
A List of labels.
A patch is a list of labels that address the faces in the global face list.
label checkData(const objectRegistry &obr, const instantList &timeDirs, wordList &objectNames, const fileName &local=fileName::null)
Check if fields are good to use (available at all times)
label nBoundaryFaces() const noexcept
Number of boundary faces (== nFaces - nInternalFaces)
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
const pointField & preMotionPoints() const noexcept
Pre-motion point positions.
static const List< label > & null() noexcept
Return a null List (reference to a nullObject). Behaves like an empty List.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
const volScalarField & p0
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
bool operator()(const label a, const label b) const
static constexpr const zero Zero
Global zero (0)