88 return less(values_[a], values_[
b]);
132 label nMasterChanged = 0;
147 const label nInternalFaces =
mesh.nInternalFaces();
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);
179 boolList refinedBoundaryFace(
mesh.nBoundaryFaces(),
false);
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()
277 <<
" changed faces out of " <<
mesh.globalData().nTotalFaces()
280 faceSet changedFacesSet(
mesh,
"changedFaces", changedFaces);
281 Pout<<
"getChangedFaces : Writing " << changedFaces.
size()
282 <<
" changed faces to faceSet " << changedFacesSet.
name()
284 changedFacesSet.
write();
294bool Foam::meshRefinement::markForRefine
296 const label markValue,
297 const label nAllowRefine,
305 cellValue = markValue;
309 return nRefine <= nAllowRefine;
313void Foam::meshRefinement::markFeatureCellLevel
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);
458 featureEdgeVisited[featI].setSize(features_[featI].edges().size());
459 featureEdgeVisited[featI] =
false;
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;
498 Pout<<
"Constructing cloud for cell marking" <<
endl;
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);
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();
551 <<
" particles over distance " << maxTrackLen
552 <<
" to mark cells" <<
endl;
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);
630Foam::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;
686Foam::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);
714 testCc[testI] = cellCentres[cellI];
715 testLevels[testI] = cellLevel[cellI];
722 features_.findHigherLevel(testCc, testLevels, maxLevel);
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;
770Foam::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);
792 testCc[testI] = cellCentres[cellI];
793 testLevels[testI] = cellLevel[cellI];
800 shells_.findHigherLevel(testCc, testLevels, maxLevel);
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;
847Foam::label Foam::meshRefinement::unmarkInternalRefinement
853 const labelList& cellLevel = meshCutter_.cellLevel();
854 const pointField& cellCentres = mesh_.cellCentres();
867 testCc[testI] = cellCentres[cellI];
868 testLevels[testI] = cellLevel[cellI];
875 limitShells_.findLevel(testCc, testLevels, levelShell);
884 if (levelShell[testI] != -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];
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);
945Foam::label Foam::meshRefinement::markSurfaceRefinement
947 const label nAllowRefine,
955 const labelList& cellLevel = meshCutter_.cellLevel();
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;
1077Foam::label Foam::meshRefinement::countMatches
1088 const vector& n1 = normals1[i];
1092 const vector& n2 = normals2[j];
1117bool 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)
1175Foam::label Foam::meshRefinement::markSurfaceCurvatureRefinement
1177 const scalar curvature,
1178 const label nAllowRefine,
1186 const labelList& cellLevel = meshCutter_.cellLevel();
1187 const pointField& cellCentres = mesh_.cellCentres();
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]);
1243 const vectorField smallVec(ROOTSMALL*(end-start));
1250 const bool hasCurvatureLevels = (
max(surfaces_.maxCurvatureLevel()) > 0);
1267 surfaces_.findAllIntersections
1274 labelList(surfaces_.maxLevel().size(), 0),
1275 surfaces_.maxLevel(),
1287 forAll(surfaceNormal, pointI)
1290 vectorList& pNormals = surfaceNormal[pointI];
1291 labelList& pLevel = surfaceLevel[pointI];
1371 label faceI = testFaces[i];
1372 label own = mesh_.faceOwner()[faceI];
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();
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;
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);
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);
1767 if (
mag(avg&d) > mergeDistance())
1781 const scalar planarCos,
1795 vector d = point1-point0;
1796 scalar magD =
mag(d);
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);
1815 avgNormal /=
mag(avgNormal);
1837bool Foam::meshRefinement::checkProximity
1839 const scalar planarCos,
1840 const label nAllowRefine,
1842 const label surfaceLevel,
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;
1866 cellMaxNormal = surfaceNormal;
1875 bool closeSurfaces = isNormalGap
1888 if (surfaceLevel > cellMaxLevel)
1890 cellMaxLevel = surfaceLevel;
1892 cellMaxNormal = surfaceNormal;
1906 return markForRefine
1922Foam::label Foam::meshRefinement::markProximityRefinement
1924 const scalar planarCos,
1929 const label nAllowRefine,
1937 const labelList& cellLevel = meshCutter_.cellLevel();
1971 labelList cellMaxLevel(mesh_.nCells(), -1);
1982 surfaces_.findAllIntersections
2006 label faceI = testFaces[i];
2007 label own = mesh_.faceOwner()[faceI];
2009 const labelList& fLevels = surfaceLevel[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));
2602 const scalar maxLoadUnbalance,
2603 const label maxCellUnbalance
2612 const scalar nNewCells =
2613 scalar(mesh_.nCells() + 7*cellsToRefine.size());
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;
2716Foam::autoPtr<Foam::mapDistributePolyMesh>
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);
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 "
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);
2961 cellsToRefine[nRefine++] = cellI;
2966 return cellsToRefine;
2983 refCells[i] =
refineCell(cellsToRefine[i], refDir);
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));
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Base cloud calls templated on particle type.
label size() const noexcept
The number of elements in table.
const word & name() const noexcept
Return the object name.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void setSize(label n)
Alias for resize().
static const List< label > & null() noexcept
virtual const fileName & name() const override
Get the name of the output serial stream. (eg, the name of the Fstream file name).
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
iterator end() noexcept
Return an iterator to end traversing the UList.
void size(const label n)
Older name for setAddressableSize.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
static constexpr direction nComponents
Number of components in this vector space.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
void set(const bitSet &bitset)
Set specified bits from another bitset.
bool test(const label pos) const
Test for True value at specified position, never auto-vivify entries.
Description of cuts across cells.
A cell is defined as a list of faces with extra functionality.
A cloud is a registry collection of lagrangian particles.
Abstract base class for domain decomposition.
Mesh data needed to do the Finite Area discretisation.
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
Implementation of cellLooper.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const pointField & preMotionPoints() const noexcept
Pre-motion point positions.
label nOldCells() const noexcept
Number of old cells.
bool hasMotionPoints() const noexcept
Has valid preMotionPoints?
const polyMesh & mesh() const noexcept
Return polyMesh.
const labelList & cellMap() const noexcept
Old cell map.
void updateMesh(const mapPolyMesh &)
Force recalculation of locally stored data on topological change.
void setRefinement(const cellCuts &cuts, polyTopoChange &meshMod)
Do actual cutting with cut description. Inserts mesh changes.
void printMeshInfo(const bool debug, const string &msg, const bool printCellLevel) const
Print some mesh stats.
void updateMesh(const mapPolyMesh &, const labelList &changedFaces)
Update for external change to mesh. changedFaces are in new mesh.
writeType
Enumeration for what to write. Used as a bit-pattern.
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.
word timeName() const
Replacement for Time::timeName() that returns oldInstance (if overwrite_).
debugType
Enumeration for what to debug. Used as a bit-pattern.
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.
autoPtr< mapDistributePolyMesh > refineAndBalance(const string &msg, decompositionMethod &decomposer, fvMeshDistribute &distributor, const labelList &cellsToRefine, const scalar maxLoadUnbalance, const label maxCellUnbalance)
Refine some cells and rebalance.
const fvMesh & mesh() const
Reference to mesh.
bool isGap(const scalar, const vector &, const vector &, const vector &, const vector &) const
Is local topology a small gap?
scalar mergeDistance() const
autoPtr< mapPolyMesh > directionalRefine(const string &msg, const direction cmpt, const labelList &cellsToRefine)
Directionally refine in direction cmpt.
autoPtr< mapPolyMesh > refine(const labelList &cellsToRefine)
Refine some cells.
labelList directionalRefineCandidates(const label maxGlobalCells, const label maxLocalCells, const labelList ¤tLevel, const direction dir) const
Calculate list of cells to directionally refine.
autoPtr< mapDistributePolyMesh > balance(const bool keepZoneFaces, const bool keepBaffles, const labelList &singleProcPoints, const scalarField &cellWeights, decompositionMethod &decomposer, fvMeshDistribute &distributor)
Redecompose according to cell count.
autoPtr< mapDistributePolyMesh > balanceAndRefine(const string &msg, decompositionMethod &decomposer, fvMeshDistribute &distributor, const labelList &cellsToRefine, const scalar maxLoadUnbalance, const label maxCellUnbalance)
Balance before refining some cells.
static writeType writeLevel()
Get/set write level.
normalLess(const vectorList &values)
bool operator()(const label a, const label b) const
void clear()
Clear all entries from the registry.
labelList cmptType
Component type.
vectorList cmptType
Component type.
A traits class, which is primarily used for primitives and vector-space.
pTraits(const labelList &obj)
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Mesh consisting of general polyhedral cells.
A patch is a list of labels that address the faces in the global face list.
Direct mesh changes based on v1.3 polyTopoChange syntax.
autoPtr< mapPolyMesh > changeMesh(polyMesh &mesh, const labelUList &patchMap, const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Inplace changes mesh without change of patches.
Container with cells to refine. Refinement given as single direction.
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
Contains information about location on a triSurface.
Class used to pass tracking data to the trackToFace function.
Particle class that marks cells it passes through. Used to mark cells visited by feature edges.
const volScalarField & p0
wallPoints::trackData td(isBlockedFace, regionToBlockSize)
void set(List< bool > &bools, const labelUList &locations)
Set the listed locations (assign 'true').
Namespace for handling debugging switches.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
List< labelList > labelListList
List of labelList.
List< label > labelList
A List of labels.
UIndirectList< label > labelUIndList
UIndirectList of labels.
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< vector > vectorList
List of vector.
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).
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
constexpr scalar degToRad() noexcept
Multiplication factor for degrees to radians conversion.
List< cell > cellList
List of cell.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static bool less(const vector &x, const vector &y)
To compare normals.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
List< point > pointList
List of point.
Field< vector > vectorField
Specialisation of Field<T> for vector.
vector point
Point is a vector.
List< bool > boolList
A List of bools.
static constexpr const zero Zero
Global zero (0).
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
vectorField pointField
pointField is a vectorField.
labelList findIndices(const ListType &input, typename ListType::const_reference val, label start=0)
Linear search to find all occurrences of given element.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
dimensionedScalar cos(const dimensionedScalar &ds)
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.