65 Foam::label Foam::meshRefinement::createBaffle
70 polyTopoChange& meshMod
73 const face&
f = mesh_.
faces()[faceI];
75 bool zoneFlip =
false;
79 const faceZone& fZone = mesh_.
faceZones()[zoneID];
80 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
107 <<
"No neighbour patch for internal face " << faceI
112 bool reverseFlip =
false;
115 reverseFlip = !zoneFlip;
118 dupFaceI = meshMod.setAction
178 void Foam::meshRefinement::getIntersections
188 autoPtr<OBJstream> str;
189 if (
debug&OBJINTERSECTIONS)
196 mesh_.time().path()/
timeName()/
"intersections.obj" 200 Pout<<
"getIntersections : Writing surface intersections to file " 205 globalRegion1.setSize(mesh_.nFaces());
207 globalRegion2.setSize(mesh_.nFaces());
235 List<pointIndexHit> hit1;
238 List<pointIndexHit> hit2;
240 surfaces_.findNearestIntersection
258 label faceI = testFaces[i];
260 if (hit1[i].hit() && hit2[i].hit())
264 str().writeLine(start[i], hit1[i].
point());
265 str().writeLine(hit1[i].
point(), hit2[i].
point());
266 str().writeLine(hit2[i].
point(),
end[i]);
270 globalRegion1[faceI] =
271 surfaces_.globalRegion(surface1[i], region1[i]);
272 globalRegion2[faceI] =
273 surfaces_.globalRegion(surface2[i], region2[i]);
275 if (globalRegion1[faceI] == -1 || globalRegion2[faceI] == -1)
285 void Foam::meshRefinement::getBafflePatches
287 const label nErodeCellZones,
292 const bool exitIfLeakPath,
293 const refPtr<coordSetWriter>& leakPathFormatter,
294 refPtr<surfaceWriter>& surfFormatter,
319 bitSet posOrientation;
327 locationsOutsideMesh,
350 ownPatch.setSize(mesh_.nFaces());
352 neiPatch.setSize(mesh_.nFaces());
357 if (unnamedRegion1[faceI] != -1 || unnamedRegion2[faceI] != -1)
359 label ownMasterPatch = -1;
360 if (unnamedRegion1[faceI] != -1)
362 ownMasterPatch = globalToMasterPatch[unnamedRegion1[faceI]];
364 label neiMasterPatch = -1;
365 if (unnamedRegion2[faceI] != -1)
367 neiMasterPatch = globalToMasterPatch[unnamedRegion2[faceI]];
374 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
377 if (mesh_.isInternalFace(faceI))
379 neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
383 neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
391 (ownZone >= 0 && neiZone != -2)
392 || (neiZone >= 0 && ownZone != -2)
395 namedSurfaceRegion.size() == 0
396 || namedSurfaceRegion[faceI] == -1
407 ownPatch[faceI] = ownMasterPatch;
408 neiPatch[faceI] = neiMasterPatch;
428 const bool allowBoundary,
433 Map<labelPair> bafflePatch(mesh_.nFaces()/1000);
435 const PtrList<surfaceZonesInfo>& surfZones = surfaces_.surfZones();
440 const wordList& faceZoneNames = surfZones[surfI].faceZoneNames();
442 forAll(faceZoneNames, fzi)
445 const word& faceZoneName = faceZoneNames[fzi];
446 label zoneI = fZones.findZoneID(faceZoneName);
447 const faceZone& fZone = fZones[zoneI];
450 label globalRegionI = surfaces_.globalRegion(surfI, fzi);
453 globalToMasterPatch[globalRegionI],
454 globalToSlavePatch[globalRegionI]
457 Info<<
"For zone " << fZone.name() <<
" found patches " 458 << mesh_.boundaryMesh()[zPatches[0]].name() <<
" and " 459 << mesh_.boundaryMesh()[zPatches[1]].name()
464 label faceI = fZone[i];
466 if (allowBoundary || mesh_.isInternalFace(faceI))
469 if (fZone.flipMap()[i])
474 if (!bafflePatch.insert(faceI,
patches))
478 <<
" fc:" << mesh_.faceCentres()[faceI]
479 <<
" in zone " << fZone.name()
480 <<
" is in multiple zones!" 499 ownPatch.size() != mesh_.nFaces()
500 || neiPatch.size() != mesh_.nFaces()
505 <<
" ownPatch:" << ownPatch.size()
506 <<
" neiPatch:" << neiPatch.size()
507 <<
". Should be number of faces:" << mesh_.nFaces()
518 forAll(syncedOwnPatch, faceI)
522 (ownPatch[faceI] == -1 && syncedOwnPatch[faceI] != -1)
523 || (neiPatch[faceI] == -1 && syncedNeiPatch[faceI] != -1)
527 <<
"Non synchronised at face:" << faceI
528 <<
" on patch:" << mesh_.boundaryMesh().whichPatch(faceI)
529 <<
" fc:" << mesh_.faceCentres()[faceI] <<
endl 530 <<
"ownPatch:" << ownPatch[faceI]
531 <<
" syncedOwnPatch:" << syncedOwnPatch[faceI]
532 <<
" neiPatch:" << neiPatch[faceI]
533 <<
" syncedNeiPatch:" << syncedNeiPatch[faceI]
540 polyTopoChange meshMod(mesh_);
544 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
546 if (ownPatch[faceI] != -1)
560 const polyBoundaryMesh&
pbm = mesh_.boundaryMesh();
564 const polyPatch&
pp =
pbm[patchI];
566 label coupledPatchI = -1;
570 && !refCast<const coupledPolyPatch>(
pp).separated()
573 coupledPatchI = patchI;
578 label faceI =
pp.start()+i;
580 if (ownPatch[faceI] != -1)
590 if (coupledPatchI != -1)
592 faceToCoupledPatch_.insert(faceI, coupledPatchI);
601 autoPtr<mapPolyMesh> mapPtr;
609 mapPtr = meshMod.changeMesh(mesh_,
false,
true);
610 mapPolyMesh& map = *mapPtr;
613 mesh_.updateMesh(map);
616 if (map.hasMotionPoints())
618 mesh_.movePoints(map.preMotionPoints());
632 faceSet baffledFacesSet(mesh_,
"baffledFacesSet", 2*nBaffles);
634 const labelList& reverseFaceMap = map.reverseFaceMap();
638 forAll(ownPatch, oldFaceI)
640 label faceI = reverseFaceMap[oldFaceI];
642 if (ownPatch[oldFaceI] != -1 && faceI >= 0)
644 const cell& ownFaces = mesh_.cells()[mesh_.faceOwner()[faceI]];
646 baffledFacesSet.insert(ownFaces);
652 label oldFaceI =
faceMap[faceI];
654 if (oldFaceI >= 0 && reverseFaceMap[oldFaceI] != faceI)
656 const cell& ownFaces = mesh_.cells()[mesh_.faceOwner()[faceI]];
658 baffledFacesSet.insert(ownFaces);
661 baffledFacesSet.sync(mesh_);
663 updateMesh(map, baffledFacesSet.toc());
681 const faceZone& fZone = faceZones[zoneI];
685 bool hasInfo = getFaceZoneInfo(fZone.
name(), mpI, spI, fzType);
687 if (hasInfo && fzTypes.
found(fzType))
709 for (
const label zoneID :
zoneIDs)
720 if (faceToZone[
p[0]] != -1 && (faceToZone[
p[0]] == faceToZone[
p[1]]))
747 label oldFacei =
faceMap[facei];
750 reverseFaceMap[oldFacei] = facei;
755 DynamicList<labelPair> newBaffles(baffles.
size());
761 reverseFaceMap[
p[0]],
764 if (newBaffle[0] != -1 && newBaffle[1] != -1)
766 newBaffles.append(newBaffle);
769 baffles = std::move(newBaffles);
785 ownPatch.
setSize(mesh_.nFaces());
787 neiPatch.
setSize(mesh_.nFaces());
796 const bitSet isInternalOrCoupled
804 const faceZone& fz = faceZones[zoneI];
805 const word& masterName = faceZoneToMasterPatch_[fz.
name()];
806 label masterPatchI = mesh_.boundaryMesh().findPatchID(masterName);
807 const word& slaveName = faceZoneToSlavePatch_[fz.
name()];
808 label slavePatchI = mesh_.boundaryMesh().findPatchID(slaveName);
810 if (masterPatchI == -1 || slavePatchI == -1)
813 <<
"Problem: masterPatchI:" << masterPatchI
820 if (isInternalOrCoupled[faceI])
824 ownPatch[faceI] = slavePatchI;
825 neiPatch[faceI] = masterPatchI;
829 ownPatch[faceI] = masterPatchI;
830 neiPatch[faceI] = slavePatchI;
855 Info<<
"Converting zoned faces into baffles ..." <<
endl;
864 label nLocalBaffles =
sum(nBaffles);
868 if (nTotalBaffles > 0)
873 <<
setf(ios_base::left)
874 <<
setw(30) <<
"FaceZone" 875 <<
setw(10) <<
"FaceType" 876 <<
setw(10) <<
"nBaffles" 878 <<
setw(30) <<
"--------" 879 <<
setw(10) <<
"--------" 880 <<
setw(10) <<
"--------" 886 const faceZone& fz = faceZones[zoneI];
890 bool hasInfo = getFaceZoneInfo(fz.
name(), mpI, spI, fzType);
898 <<
setw(10) << nBaffles[j]
905 map = createBaffles(ownPatch, neiPatch);
911 baffles.
setSize(nLocalBaffles);
912 originatingFaceZone.
setSize(nLocalBaffles);
916 const labelList& reverseFaceMap = map().reverseFaceMap();
920 label faceI = mesh_.nInternalFaces();
921 faceI < mesh_.nFaces();
925 label oldFaceI =
faceMap[faceI];
926 label masterFaceI = reverseFaceMap[oldFaceI];
927 if (masterFaceI != faceI && ownPatch[oldFaceI] != -1)
929 baffles[baffleI] =
labelPair(masterFaceI, faceI);
930 originatingFaceZone[baffleI] =
faceZoneID[oldFaceI];
935 if (baffleI != baffles.
size())
938 <<
"Had " << baffles.
size() <<
" baffles to create " 939 <<
" but encountered " << baffleI
940 <<
" slave faces originating from patcheable faces." 946 const_cast<Time&
>(mesh_.time())++;
947 Pout<<
"Writing zone-baffled mesh to time " <<
timeName()
953 mesh_.time().path()/
"baffles" 957 Info<<
"Created " << nTotalBaffles <<
" baffles in = " 958 << mesh_.time().cpuTimeIncrement() <<
" s\n" <<
nl <<
endl;
963 originatingFaceZone.
clear();
973 const scalar planarAngle,
1001 const label baffleValue = 1000000;
1016 label faceI =
pp.start();
1020 const labelList& fEdges = mesh_.faceEdges(faceI);
1024 nBafflesPerEdge[fEdges[fEdgeI]]++;
1032 DynamicList<label> fe0;
1033 DynamicList<label> fe1;
1042 label f0 = couples[i].
first();
1043 const labelList& fEdges0 = mesh_.faceEdges(f0, fe0);
1046 nBafflesPerEdge[fEdges0[fEdgeI]] += baffleValue;
1051 label f1 = couples[i].second();
1052 const labelList& fEdges1 = mesh_.faceEdges(f1, fe1);
1055 nBafflesPerEdge[fEdges1[fEdgeI]] += baffleValue;
1074 List<labelPair> filteredCouples(couples.
size());
1090 const labelList& fEdges = mesh_.faceEdges(couple.first());
1094 label edgeI = fEdges[fEdgeI];
1096 if (nBafflesPerEdge[edgeI] == 2*baffleValue+2*1)
1098 filteredCouples[filterI++] = couple;
1104 filteredCouples.setSize(filterI);
1107 label nFiltered =
returnReduce(filteredCouples.size(), sumOp<label>());
1109 Info<<
"freeStandingBaffles : detected " 1111 <<
" free-standing baffles out of " 1124 const pointField& cellCentres = mesh_.cellCentres();
1126 forAll(filteredCouples, i)
1128 const labelPair& couple = filteredCouples[i];
1129 start[i] = cellCentres[mesh_.faceOwner()[couple.first()]];
1130 end[i] = cellCentres[mesh_.faceOwner()[couple.second()]];
1144 List<pointIndexHit> hit1;
1149 List<pointIndexHit> hit2;
1153 surfaces_.findNearestIntersection
1155 identity(surfaces_.surfaces().size()),
1179 forAll(filteredCouples, i)
1181 const labelPair& couple = filteredCouples[i];
1195 && hit1[i].
point().dist(hit2[i].
point()) > mergeDistance_
1206 if ((normal1[i]&normal2[i]) > planarAngleCos)
1210 scalar magN =
mag(
n);
1213 filteredCouples[filterI++] = couple;
1217 else if (hit1[i].hit() || hit2[i].hit())
1223 filteredCouples.setSize(filterI);
1225 Info<<
"freeStandingBaffles : detected " 1227 <<
" planar (within " << planarAngle
1228 <<
" degrees) free-standing baffles out of " 1233 return filteredCouples;
1250 const faceList& faces = mesh_.faces();
1251 const labelList& faceOwner = mesh_.faceOwner();
1256 label face0 = couples[i].
first();
1257 label face1 = couples[i].second();
1262 label own0 = faceOwner[face0];
1263 label own1 = faceOwner[face1];
1265 if (face1 < 0 || own0 < own1)
1268 label zoneID = faceZones.
whichZone(face0);
1269 bool zoneFlip =
false;
1273 const faceZone& fZone = faceZones[zoneID];
1277 label nei = (face1 < 0 ? -1 : own1);
1299 label zoneID = faceZones.
whichZone(face1);
1300 bool zoneFlip =
false;
1304 const faceZone& fZone = faceZones[zoneID];
1329 const label faceI = iter.key();
1330 const label patchI = iter.val();
1332 if (!mesh_.isInternalFace(faceI))
1335 <<
"problem: face:" << faceI
1336 <<
" at:" << mesh_.faceCentres()[faceI]
1337 <<
"(wanted patch:" << patchI
1341 label zoneID = faceZones.
whichZone(faceI);
1342 bool zoneFlip =
false;
1346 const faceZone& fZone = faceZones[zoneID];
1370 mesh_.moving(
false);
1373 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
1377 mesh_.updateMesh(map);
1404 newExposedFaces[newI++] = newFace0;
1407 const label newFace1 = map.
reverseFaceMap()[couples[i].second()];
1410 newExposedFaces[newI++] = newFace1;
1413 newExposedFaces.
setSize(newI);
1414 updateMesh(map, newExposedFaces);
1423 const bool doInternalZones,
1424 const bool doBaffleZones
1430 if (doInternalZones)
1454 mapPtr = mergeBaffles(zoneBaffles,
Map<label>(0));
1461 void Foam::meshRefinement::findCellZoneGeometric
1471 const pointField& cellCentres = mesh_.cellCentres();
1472 const labelList& faceOwner = mesh_.faceOwner();
1473 const labelList& faceNeighbour = mesh_.faceNeighbour();
1477 surfaces_.findInside
1479 closedNamedSurfaces,
1484 forAll(insideSurfaces, cellI)
1486 label surfI = insideSurfaces[cellI];
1490 if (cellToZone[cellI] == -2)
1492 cellToZone[cellI] = surfaceToCellZone[surfI];
1494 else if (cellToZone[cellI] == -1)
1499 cellToZone[cellI] = surfaceToCellZone[surfI];
1512 label nCandidates = 0;
1513 forAll(namedSurfaceRegion, faceI)
1515 if (namedSurfaceRegion[faceI] != -1)
1517 if (mesh_.isInternalFace(faceI))
1531 forAll(namedSurfaceRegion, faceI)
1533 if (namedSurfaceRegion[faceI] != -1)
1535 label own = faceOwner[faceI];
1536 const point& ownCc = cellCentres[own];
1538 if (mesh_.isInternalFace(faceI))
1540 label nei = faceNeighbour[faceI];
1541 const point& neiCc = cellCentres[nei];
1543 const vector d = 1
e-4*(neiCc - ownCc);
1544 candidatePoints[nCandidates++] = ownCc-d;
1545 candidatePoints[nCandidates++] = neiCc+d;
1550 const point& neiFc = neiCc[faceI-mesh_.nInternalFaces()];
1553 const vector d = 1
e-4*(neiFc - ownCc);
1554 candidatePoints[nCandidates++] = ownCc-d;
1562 surfaces_.findInside
1564 closedNamedSurfaces,
1573 forAll(namedSurfaceRegion, faceI)
1575 if (namedSurfaceRegion[faceI] != -1)
1577 label own = faceOwner[faceI];
1579 if (mesh_.isInternalFace(faceI))
1581 label ownSurfI = insideSurfaces[nCandidates++];
1584 cellToZone[own] = surfaceToCellZone[ownSurfI];
1587 label neiSurfI = insideSurfaces[nCandidates++];
1590 label nei = faceNeighbour[faceI];
1592 cellToZone[nei] = surfaceToCellZone[neiSurfI];
1597 label ownSurfI = insideSurfaces[nCandidates++];
1600 cellToZone[own] = surfaceToCellZone[ownSurfI];
1611 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
1613 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
1614 label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
1616 if (namedSurfaceRegion[faceI] == -1 && (ownZone != neiZone))
1626 else if (neiZone == -1)
1632 minZone =
min(ownZone, neiZone);
1637 label geomSurfI = surfaceToCellZone.
find(minZone);
1639 if (geomSurfI != -1)
1641 namedSurfaceRegion[faceI] =
1642 surfaces_.globalRegion(geomSurfI, 0);
1650 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
1660 label faceI =
pp.start()+i;
1661 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
1662 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
1664 if (namedSurfaceRegion[faceI] == -1 && (ownZone != neiZone))
1672 else if (neiZone == -1)
1678 minZone =
min(ownZone, neiZone);
1683 label geomSurfI = surfaceToCellZone.
find(minZone);
1685 if (geomSurfI != -1)
1687 namedSurfaceRegion[faceI] =
1688 surfaces_.globalRegion(geomSurfI, 0);
1700 void Foam::meshRefinement::findCellZoneInsideWalk
1710 boolList blockedFace(mesh_.nFaces());
1713 forAll(blockedFace, faceI)
1715 if (faceToZone[faceI] == -1)
1717 blockedFace[faceI] =
false;
1721 blockedFace[faceI] =
true;
1727 regionSplit cellRegion(mesh_, blockedFace);
1728 blockedFace.clear();
1731 (void)mesh_.tetBasePtIs();
1734 forAll(locationsInMesh, i)
1737 const point& insidePoint = locationsInMesh[i];
1738 label zoneID = zonesInMesh[i];
1741 label keepRegionI = findRegion
1745 vector::uniform(mergeDistance_),
1749 Info<<
"For cellZone " 1753 : mesh_.cellZones()[zoneID].name()
1755 <<
" found point " << insidePoint
1756 <<
" in global region " << keepRegionI
1757 <<
" out of " << cellRegion.nRegions() <<
" regions." <<
endl;
1759 if (keepRegionI == -1)
1762 <<
"Point " << insidePoint
1763 <<
" is not inside the mesh." <<
nl 1764 <<
"Bounding box of the mesh:" << mesh_.bounds()
1773 label nWarnings = 0;
1775 forAll(cellRegion, cellI)
1777 if (cellRegion[cellI] == keepRegionI)
1779 if (cellToZone[cellI] == -2)
1782 cellToZone[cellI] = zoneID;
1784 else if (cellToZone[cellI] != zoneID)
1786 if (cellToZone[cellI] != -1 && nWarnings < 10)
1790 <<
" at " << mesh_.cellCentres()[cellI]
1791 <<
" is inside cellZone " 1795 : mesh_.cellZones()[zoneID].name()
1797 <<
" from locationInMesh " << insidePoint
1798 <<
" but already marked as being in zone " 1799 << mesh_.cellZones()[cellToZone[cellI]].name()
1801 <<
"This can happen if your surfaces are not" 1802 <<
" (sufficiently) closed." 1808 cellToZone[cellI] = zoneID;
1816 void Foam::meshRefinement::findCellZoneInsideWalk
1828 forAll(zoneNamesInMesh, i)
1830 zoneIDs[i] = czs.findZoneID(zoneNamesInMesh[i]);
1832 findCellZoneInsideWalk
1842 bool Foam::meshRefinement::calcRegionToZone
1844 const label backgroundZoneID,
1845 const label surfZoneI,
1846 const label ownRegion,
1847 const label neiRegion,
1852 bool changed =
false;
1855 if (ownRegion != neiRegion)
1862 if (regionToCellZone[ownRegion] == -2)
1864 if (surfZoneI == -1)
1869 if (regionToCellZone[neiRegion] != -2)
1871 regionToCellZone[ownRegion] = regionToCellZone[neiRegion];
1875 else if (regionToCellZone[neiRegion] == surfZoneI)
1880 if (backgroundZoneID != -2)
1882 regionToCellZone[ownRegion] = backgroundZoneID;
1886 else if (regionToCellZone[neiRegion] != -2)
1890 regionToCellZone[ownRegion] = surfZoneI;
1894 else if (regionToCellZone[neiRegion] == -2)
1896 if (surfZoneI == -1)
1901 regionToCellZone[neiRegion] = regionToCellZone[ownRegion];
1904 else if (regionToCellZone[ownRegion] == surfZoneI)
1908 if (backgroundZoneID != -2)
1910 regionToCellZone[neiRegion] = backgroundZoneID;
1914 else if (regionToCellZone[ownRegion] != -2)
1918 regionToCellZone[neiRegion] = surfZoneI;
1927 void Foam::meshRefinement::findCellZoneTopo
1929 const label backgroundZoneID,
1958 boolList blockedFace(mesh_.nFaces());
1960 forAll(unnamedSurfaceRegion, faceI)
1964 unnamedSurfaceRegion[faceI] == -1
1965 && namedSurfaceRegion[faceI] == -1
1968 blockedFace[faceI] =
false;
1972 blockedFace[faceI] =
true;
1978 regionSplit cellRegion(mesh_, blockedFace);
1979 blockedFace.clear();
1985 labelList regionToCellZone(cellRegion.nRegions(), -2);
1990 forAll(cellToZone, cellI)
1992 label regionI = cellRegion[cellI];
1993 if (cellToZone[cellI] != -2 && regionToCellZone[regionI] == -2)
1995 regionToCellZone[regionI] = cellToZone[cellI];
2008 forAll(locationsInMesh, i)
2010 const point& keepPoint = locationsInMesh[i];
2011 label keepRegionI = findRegion
2015 vector::uniform(mergeDistance_),
2019 Info<<
"Found point " << keepPoint
2020 <<
" in global region " << keepRegionI
2021 <<
" out of " << cellRegion.nRegions() <<
" regions." <<
endl;
2023 if (keepRegionI == -1)
2026 <<
"Point " << keepPoint
2027 <<
" is not inside the mesh." <<
nl 2028 <<
"Bounding box of the mesh:" << mesh_.bounds()
2036 if (regionToCellZone[keepRegionI] == -2)
2038 regionToCellZone[keepRegionI] = -1;
2057 bool changed =
false;
2061 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
2063 label regionI = namedSurfaceRegion[faceI];
2066 if (unnamedSurfaceRegion[faceI] == -1 && regionI != -1)
2071 label surfI = surfaces_.whichSurface(regionI).first();
2073 bool changedCell = calcRegionToZone
2076 surfaceToCellZone[surfI],
2077 cellRegion[mesh_.faceOwner()[faceI]],
2078 cellRegion[mesh_.faceNeighbour()[faceI]],
2082 changed = changed | changedCell;
2088 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2104 label faceI =
pp.start()+i;
2106 label regionI = namedSurfaceRegion[faceI];
2109 if (unnamedSurfaceRegion[faceI] == -1 && regionI != -1)
2111 label surfI = surfaces_.whichSurface(regionI).first();
2113 bool changedCell = calcRegionToZone
2116 surfaceToCellZone[surfI],
2117 cellRegion[mesh_.faceOwner()[faceI]],
2118 neiCellRegion[faceI-mesh_.nInternalFaces()],
2122 changed = changed | changedCell;
2137 Pout<<
"meshRefinement::findCellZoneTopo :" 2138 <<
" nRegions:" << regionToCellZone.size()
2139 <<
" of which visited (-1 = background, >= 0 : cellZone) :" 2142 forAll(regionToCellZone, regionI)
2144 if (regionToCellZone[regionI] != -2)
2146 Pout<<
"Region " << regionI
2147 <<
" becomes cellZone:" << regionToCellZone[regionI]
2154 forAll(cellToZone, cellI)
2156 label regionI = cellRegion[cellI];
2157 if (cellToZone[cellI] == -2 && regionToCellZone[regionI] != -2)
2159 cellToZone[cellI] = regionToCellZone[regionI];
2165 void Foam::meshRefinement::erodeCellZone
2167 const label nErodeCellZones,
2168 const label backgroundZoneID,
2185 for (label iter = 0; iter < nErodeCellZones; iter++)
2192 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
2196 unnamedSurfaceRegion[facei] == -1
2197 && namedSurfaceRegion[facei] == -1
2200 label own = mesh_.faceOwner()[facei];
2201 label nei = mesh_.faceNeighbour()[facei];
2202 if (cellToZone[own] == -2 && cellToZone[nei] >= -1)
2204 erodedCellToZone[nei] = backgroundZoneID;
2207 else if (cellToZone[nei] == -2 && cellToZone[own] >= -1)
2209 erodedCellToZone[own] = backgroundZoneID;
2217 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2233 label facei =
pp.start()+i;
2236 unnamedSurfaceRegion[facei] == -1
2237 && namedSurfaceRegion[facei] == -1
2240 label own = mesh_.faceOwner()[facei];
2241 label bFacei = facei-mesh_.nInternalFaces();
2242 if (neiCellZone[bFacei] == -2 && cellToZone[own] >= -1)
2244 erodedCellToZone[own] = backgroundZoneID;
2252 cellToZone.transfer(erodedCellToZone);
2254 reduce(nChanged, sumOp<label>());
2257 Pout<<
"erodeCellZone : eroded " << nChanged
2258 <<
" cells (moved from cellZone to background zone " 2259 << backgroundZoneID <<
endl;
2270 void Foam::meshRefinement::growCellZone
2272 const label nGrowCellZones,
2273 const label backgroundZoneID,
2280 if (nGrowCellZones != 1)
2283 <<
"Growing currently only supported for single layer." 2284 <<
" Exiting zone growing" <<
endl;
2301 const FixedList<label, 3> wallTag
2311 List<FixedList<label, 3>> surfaces(1);
2332 forAll(cellToZone, celli)
2334 if (cellToZone[celli] >= 0)
2336 const FixedList<label, 3> zoneTag
2343 origins[0] = mesh_.cellCentres()[celli];
2345 surfaces[0] = zoneTag;
2346 allCellInfo[celli] = wallPoints(origins, distSqrs, surfaces);
2351 DynamicList<wallPoints> faceDist(mesh_.nFaces()/128);
2352 DynamicList<label> changedFaces(mesh_.nFaces()/128);
2354 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
2356 const label own = mesh_.faceOwner()[facei];
2357 const label nei = mesh_.faceNeighbour()[facei];
2358 if (cellToZone[own] >= 0 && cellToZone[nei] < 0)
2362 origins[0] = mesh_.faceCentres()[facei];
2364 surfaces[0] = FixedList<label, 3>
2370 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2371 changedFaces.append(facei);
2373 else if (cellToZone[own] < 0 && cellToZone[nei] >= 0)
2377 origins[0] = mesh_.faceCentres()[facei];
2379 surfaces[0] = FixedList<label, 3>
2385 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2386 changedFaces.append(facei);
2390 unnamedSurfaceRegion1[facei] != -1
2391 || unnamedSurfaceRegion2[facei] != -1
2396 origins[0] = mesh_.faceCentres()[facei];
2398 surfaces[0] = wallTag;
2399 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2400 changedFaces.append(facei);
2408 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2421 label facei =
pp.start()+i;
2422 label own = mesh_.faceOwner()[facei];
2423 label bFacei = facei-mesh_.nInternalFaces();
2424 if (cellToZone[own] >= 0 && neiCellZone[bFacei] < 0)
2428 surfaces[0] = FixedList<label, 3>
2434 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2435 changedFaces.append(facei);
2437 else if (cellToZone[own] < 0 && neiCellZone[bFacei] >= 0)
2443 unnamedSurfaceRegion1[facei] != -1
2444 || unnamedSurfaceRegion2[facei] != -1
2448 origins[0] = mesh_.faceCentres()[facei];
2450 surfaces[0] = wallTag;
2451 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2452 changedFaces.append(facei);
2461 label facei =
pp.start()+i;
2462 label own = mesh_.faceOwner()[facei];
2463 if (cellToZone[own] < 0)
2467 surfaces[0] = wallTag;
2468 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2469 changedFaces.append(facei);
2493 const auto& czs = mesh_.cellZones();
2494 List<scalarList> regionToBlockSize(czs.size());
2495 for (
auto& blockSizes : regionToBlockSize)
2502 FaceCellWave<wallPoints, wallPoints::trackData>
wallDistCalc 2519 bitSet isChangedCell(mesh_.nCells());
2525 const List<FixedList<label, 3>>& surfaces =
2528 if (surfaces.size())
2532 isChangedCell.set(celli);
2535 if (surfaces.size() > 1)
2541 for (label i = 0; i < surfaces.size(); i++)
2543 const label zonei = surfaces[i][0];
2544 const scalar d2 =
allCellInfo[celli].distSqr()[i];
2545 if (zonei != cellToZone[celli] && d2 < minDistSqr)
2554 if (minZone != cellToZone[celli] && minZone != wallTag[0])
2556 cellToZone[celli] = minZone;
2557 isChangedCell.set(celli);
2565 if (backgroundZoneID != -2)
2567 forAll(cellToZone, celli)
2569 if (cellToZone[celli] == -2)
2571 cellToZone[celli] = backgroundZoneID;
2584 for (
const label celli : isChangedCell)
2586 const cell& cFaces = mesh_.cells()[celli];
2587 for (
const label facei : cFaces)
2589 const label own = mesh_.faceOwner()[facei];
2590 const label ownZone = cellToZone[own];
2593 if (mesh_.isInternalFace(facei))
2595 const label neiZone = cellToZone[mesh_.faceNeighbour()[facei]];
2596 nbrZone = (own != celli ? ownZone : neiZone);
2600 nbrZone = neiCellZone[facei-mesh_.nInternalFaces()];
2603 if (nbrZone == cellToZone[celli])
2607 unnamedSurfaceRegion1[facei] != -1
2608 || unnamedSurfaceRegion2[facei] != -1
2611 unnamedSurfaceRegion1[facei] = -1;
2612 unnamedSurfaceRegion2[facei] = -1;
2617 namedSurfaceRegion.size()
2618 && namedSurfaceRegion[facei] != -1
2621 namedSurfaceRegion[facei] = -1;
2628 reduce(nUnnamed, sumOp<label>());
2629 reduce(nNamed, sumOp<label>());
2635 unnamedSurfaceRegion1,
2641 unnamedSurfaceRegion2,
2644 if (namedSurfaceRegion.size())
2656 Pout<<
"growCellZone : grown cellZones by " 2658 <<
" cells (moved from background to nearest cellZone)" 2660 Pout<<
"growCellZone : unmarked " << nUnnamed
2661 <<
" unzoned intersections; " << nNamed <<
" zoned intersections; " 2667 void Foam::meshRefinement::makeConsistentFaceIndex
2682 const labelList& faceOwner = mesh_.faceOwner();
2683 const labelList& faceNeighbour = mesh_.faceNeighbour();
2685 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
2687 label ownZone = cellToZone[faceOwner[faceI]];
2688 label neiZone = cellToZone[faceNeighbour[faceI]];
2689 label globalI = namedSurfaceRegion[faceI];
2695 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2698 namedSurfaceRegion[faceI] = -1;
2702 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2717 label faceI =
pp.start()+i;
2719 label ownZone = cellToZone[faceOwner[faceI]];
2720 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
2721 label globalI = namedSurfaceRegion[faceI];
2727 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2730 namedSurfaceRegion[faceI] = -1;
2739 label faceI =
pp.start()+i;
2740 label globalI = namedSurfaceRegion[faceI];
2745 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2748 namedSurfaceRegion[faceI] = -1;
2756 void Foam::meshRefinement::getIntersections
2763 bitSet& posOrientation
2766 namedSurfaceRegion.setSize(mesh_.nFaces());
2767 namedSurfaceRegion = -1;
2769 posOrientation.setSize(mesh_.nFaces());
2770 posOrientation =
false;
2801 List<pointIndexHit> hit1;
2805 List<pointIndexHit> hit2;
2808 surfaces_.findNearestIntersection
2827 label faceI = testFaces[i];
2828 const vector&
area = mesh_.faceAreas()[faceI];
2830 if (surface1[i] != -1)
2837 magSqr(hit2[i].hitPoint())
2838 <
magSqr(hit1[i].hitPoint())
2842 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2847 posOrientation.
set(faceI, ((
area&normal2[i]) > 0));
2848 nSurfFaces[surface2[i]]++;
2852 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2857 posOrientation.set(faceI, ((
area&normal1[i]) > 0));
2858 nSurfFaces[surface1[i]]++;
2861 else if (surface2[i] != -1)
2863 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2868 posOrientation.set(faceI, ((
area&normal2[i]) > 0));
2869 nSurfFaces[surface2[i]]++;
2888 forAll(nSurfFaces, surfI)
2891 << surfaces_.names()[surfI]
2892 <<
" nZoneFaces:" << nSurfFaces[surfI] <<
nl;
2899 void Foam::meshRefinement::zonify
2901 const bool allowFreeStandingZoneFaces,
2902 const label nErodeCellZones,
2903 const label backgroundZoneID,
2907 const bool exitIfLeakPath,
2908 const refPtr<coordSetWriter>& leakPathFormatter,
2909 refPtr<surfaceWriter>& surfFormatter,
2915 bitSet& posOrientation
2928 const PtrList<surfaceZonesInfo>& surfZones = surfaces_.surfZones();
2931 const List<pointField> allLocations
2937 locationsOutsideMesh
2942 labelList neiLevel(mesh_.nBoundaryFaces());
2944 calcNeighbourData(neiLevel, neiCc);
2952 if (namedSurfaces.size())
2964 cellToZone.setSize(mesh_.nCells());
2967 namedSurfaceRegion.clear();
2968 posOrientation.clear();
2988 autoPtr<mapDistribute> unnamedMapPtr;
2989 if (locationsOutsideMesh.size())
2994 [](
const label
x){
return x != -1;}
2997 const globalIndex globalUnnamedFaces(unnamedFaces.size());
3007 unnamedClosureFaces,
3013 Pout<<
"meshRefinement::zonify : found wall closure faces:" 3014 << unnamedClosureFaces.size()
3015 <<
" map:" << bool(unnamedMapPtr) <<
endl;
3023 if (leakPathFormatter)
3025 boolList blockedFace(mesh_.nFaces(),
false);
3026 UIndirectList<bool>(blockedFace, unnamedFaces) =
true;
3027 const fileName fName
3033 locationsOutsideMesh,
3035 leakPathFormatter.constCast()
3038 Info<<
"Dumped leak path to " << fName <<
endl;
3048 err <<
"Locations in mesh " << locationsInMesh
3049 <<
" connect to one of the locations outside mesh " 3050 << locationsOutsideMesh <<
endl;
3060 UIndirectList<label>(unnamedRegion1, unnamedFaces)
3062 unnamedMapPtr->distribute(packedRegion1);
3065 UIndirectList<label>(unnamedRegion2, unnamedFaces)
3067 unnamedMapPtr->distribute(packedRegion2);
3068 forAll(unnamedClosureFaces, i)
3070 const label sloti = unnamedToClosure[i];
3074 const label facei = unnamedClosureFaces[i];
3075 const label region1 = unnamedRegion1[facei];
3076 const label slotRegion1 = packedRegion1[sloti];
3077 const label region2 = unnamedRegion2[facei];
3078 const label slotRegion2 = packedRegion2[sloti];
3080 if (slotRegion1 != region1 || slotRegion2 != region2)
3082 unnamedRegion1[facei] = slotRegion1;
3083 unnamedRegion2[facei] = slotRegion2;
3095 autoPtr<mapDistribute> namedMapPtr;
3096 if (namedSurfaces.size())
3225 bitSet isClosureFace(mesh_.nFaces());
3226 isClosureFace.set(unnamedClosureFaces);
3227 isClosureFace.set(namedClosureFaces);
3228 const labelList closureFaces(isClosureFace.sortedToc());
3232 UIndirectList<face>(mesh_.faces(), closureFaces),
3240 bitSet isFrozenPoint(mesh_.nPoints());
3241 forAll(nEdgeFaces, edgei)
3243 if (nEdgeFaces[edgei] != 1)
3255 const_cast<meshRefinement&
>(*this).addPointZone(
"frozenPoints");
3256 const bitSet oldSet(mesh_.nPoints(), pointZones[zonei]);
3257 isFrozenPoint.
set(oldSet);
3263 orEqOp<unsigned int>(),
3268 pointZones.clearAddressing();
3269 pointZones[zonei] = isFrozenPoint.sortedToc();
3273 mkDir(mesh_.time().timePath());
3274 const pointZone& pz = pointZones[zonei];
3275 OBJstream str(mesh_.time().timePath()/pz.name()+
".obj");
3276 Pout<<
"Writing " << pz.size() <<
" frozen points to " 3278 for (
const label pointi : pz)
3280 str.
write(mesh_.points()[pointi]);
3288 mesh_.time().globalPath()
3290 / mesh_.pointsInstance()
3291 /
"unnamedClosureFaces" 3296 <<
returnReduce(unnamedClosureFaces.size(), sumOp<label>())
3301 IndirectList<face>(mesh_.faces(), unnamedClosureFaces),
3307 setPatch.localPoints(),
3308 setPatch.localFaces(),
3311 surfFormatter->write();
3312 surfFormatter->clear();
3318 mesh_.time().globalPath()
3320 / mesh_.pointsInstance()
3321 /
"namedClosureFaces" 3326 <<
returnReduce(namedClosureFaces.size(), sumOp<label>())
3331 IndirectList<face>(mesh_.faces(), namedClosureFaces),
3337 setPatch.localPoints(),
3338 setPatch.localFaces(),
3341 surfFormatter->write();
3342 surfFormatter->clear();
3351 if (locationsInMesh.size())
3353 Info<<
"Setting cellZones according to locationsInMesh:" <<
endl;
3355 labelList locationsZoneIDs(zonesInMesh.size(), -1);
3356 forAll(locationsInMesh, i)
3358 const word&
name = zonesInMesh[i];
3360 Info<<
"Location : " << locationsInMesh[i] <<
nl 3365 label zoneID = mesh_.cellZones().findZoneID(
name);
3370 locationsZoneIDs[i] = zoneID;
3377 findCellZoneInsideWalk
3394 if (locationSurfaces.size())
3396 Info<<
"Found " << locationSurfaces.size()
3397 <<
" named surfaces with a provided inside point." 3398 <<
" Assigning cells inside these surfaces" 3399 <<
" to the corresponding cellZone." 3405 DynamicField<point>
insidePoints(locationSurfaces.size());
3406 DynamicList<label> insidePointCellZoneIDs(locationSurfaces.size());
3407 forAll(locationSurfaces, i)
3409 const label surfI = locationSurfaces[i];
3410 const auto& surfInsidePoints = surfZones[surfI].zoneInsidePoints();
3412 const word&
name = surfZones[surfI].cellZoneName();
3416 zoneID = mesh_.cellZones().findZoneID(
name);
3420 <<
"Specified non-existing cellZone " <<
name 3421 <<
" for surface " << surfaces_.names()[surfI]
3426 for (
const auto& pt : surfInsidePoints)
3429 insidePointCellZoneIDs.append(zoneID);
3435 labelList allRegion1(mesh_.nFaces(), -1);
3436 forAll(namedSurfaceRegion, faceI)
3438 allRegion1[faceI] =
max 3440 unnamedRegion1[faceI],
3441 namedSurfaceRegion[faceI]
3445 findCellZoneInsideWalk
3448 insidePointCellZoneIDs,
3464 surfaces_.geometry(),
3465 surfaces_.surfaces()
3469 if (closedNamedSurfaces.
size())
3471 Info<<
"Found " << closedNamedSurfaces.
size()
3472 <<
" closed, named surfaces. Assigning cells in/outside" 3473 <<
" these surfaces to the corresponding cellZone." 3476 findCellZoneGeometric
3479 closedNamedSurfaces,
3490 if (namedSurfaces.size())
3492 if (nErodeCellZones == 0)
3494 Info<<
"Walking from known cellZones; crossing a faceZone " 3495 <<
"face changes cellZone" <<
nl <<
endl;
3508 else if (nErodeCellZones < 0)
3510 Info<<
"Growing cellZones by " << -nErodeCellZones
3511 <<
" layers" <<
nl <<
endl;
3525 Info<<
"Eroding cellZone cells to make these consistent with" 3526 <<
" faceZone faces" <<
nl <<
endl;
3542 if (!allowFreeStandingZoneFaces)
3544 Info<<
"Only keeping zone faces inbetween different cellZones." 3558 labelList surfaceMap(surfZones.size(), -1);
3559 forAll(standaloneNamedSurfaces, i)
3561 surfaceMap[standaloneNamedSurfaces[i]] = i;
3564 makeConsistentFaceIndex
3572 else if (nErodeCellZones < 0 &&
gMax(cellToZone) >= 0)
3577 Info<<
"Growing cellZones by " << -nErodeCellZones
3578 <<
" layers" <<
nl <<
endl;
3591 if (!allowFreeStandingZoneFaces && namedSurfaceRegion.size())
3593 Info<<
"Only keeping zone faces inbetween different cellZones." 3607 labelList surfaceMap(surfZones.size(), -1);
3608 forAll(standaloneNamedSurfaces, i)
3610 surfaceMap[standaloneNamedSurfaces[i]] = i;
3613 makeConsistentFaceIndex
3626 label nZones =
gMax(cellToZone)+1;
3628 label nUnvisited = 0;
3629 label nBackgroundCells = 0;
3631 forAll(cellToZone, cellI)
3633 label zoneI = cellToZone[cellI];
3636 nZoneCells[zoneI]++;
3638 else if (zoneI == -1)
3642 else if (zoneI == -2)
3652 reduce(nUnvisited, sumOp<label>());
3653 reduce(nBackgroundCells, sumOp<label>());
3654 forAll(nZoneCells, zoneI)
3656 reduce(nZoneCells[zoneI], sumOp<label>());
3658 Info<<
"nUnvisited :" << nUnvisited <<
endl;
3659 Info<<
"nBackgroundCells:" << nBackgroundCells <<
endl;
3660 Info<<
"nZoneCells :" << nZoneCells <<
endl;
3664 const_cast<Time&
>(mesh_.time())++;
3665 Pout<<
"Writing cell zone allocation on mesh to time " 3670 writeType(writeLevel() | WRITEMESH),
3671 mesh_.time().path()/
"cell2Zone" 3689 forAll(cellToZone, cellI)
3691 volCellToZone[cellI] = cellToZone[cellI];
3693 volCellToZone.write();
3795 void Foam::meshRefinement::handleSnapProblems
3797 const snapParameters& snapParams,
3798 const bool useTopologicalSnapDetection,
3799 const bool removeEdgeConnectedCells,
3801 const dictionary& motionDict,
3808 <<
"Introducing baffles to block off problem cells" <<
nl 3809 <<
"----------------------------------------------" <<
nl 3814 if (useTopologicalSnapDetection)
3816 markFacesOnProblemCells
3819 removeEdgeConnectedCells,
3821 globalToMasterPatch,
3829 markFacesOnProblemCellsGeometric
3833 globalToMasterPatch,
3840 Info<<
"Analyzed problem cells in = " 3845 faceSet problemFaces(mesh_,
"problemFaces", mesh_.nFaces()/100);
3849 if (facePatch[faceI] != -1)
3851 problemFaces.insert(faceI);
3854 problemFaces.instance() =
timeName();
3855 Pout<<
"Dumping " << problemFaces.size()
3856 <<
" problem faces to " << problemFaces.objectPath() <<
endl;
3857 problemFaces.
write();
3860 Info<<
"Introducing baffles to delete problem cells." <<
nl <<
endl;
3871 List<DynamicList<label>> zoneToFaces(fzs.size());
3872 List<DynamicList<bool>> zoneToFlip(fzs.size());
3877 zoneToFaces[zonei].append(fzs[zonei]);
3878 zoneToFlip[zonei].append(fzs[zonei].flipMap());
3884 if (facePatch[facei] != -1)
3886 label zonei = faceZone[facei];
3889 zoneToFaces[zonei].append(facei);
3890 zoneToFlip[zonei].append(
false);
3895 forAll(zoneToFaces, zonei)
3909 createBaffles(facePatch, facePatch);
3916 Info<<
"Created baffles in = " 3919 printMeshInfo(
debug,
"After introducing baffles",
true);
3923 const_cast<Time&
>(mesh_.time())++;
3924 Pout<<
"Writing extra baffled mesh to time " 3929 writeType(writeLevel() | WRITEMESH),
3932 Pout<<
"Dumped debug data in = " 3945 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
3946 const labelList& faceOwner = mesh_.faceOwner();
3947 const labelList& faceNeighbour = mesh_.faceNeighbour();
3964 DynamicList<label>
faceLabels(mesh_.nFaces()/100);
3966 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
3968 if (faceToZone[faceI] != -1)
3971 label ownZone = cellToZone[faceOwner[faceI]];
3972 label neiZone = cellToZone[faceNeighbour[faceI]];
3973 if (ownZone == neiZone)
3985 label faceI =
pp.start()+i;
3986 if (faceToZone[faceI] != -1)
3989 label ownZone = cellToZone[faceOwner[faceI]];
3990 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
3991 if (ownZone == neiZone)
4003 void Foam::meshRefinement::calcPatchNumMasterFaces
4005 const bitSet& isMasterFace,
4011 nMasterFacesPerEdge.setSize(
patch.nEdges());
4012 nMasterFacesPerEdge = 0;
4016 const label meshFaceI =
patch.addressing()[faceI];
4018 if (isMasterFace.test(meshFaceI))
4023 nMasterFacesPerEdge[fEdges[fEdgeI]]++;
4031 patch.meshEdges(mesh_.edges(), mesh_.pointEdges()),
4032 nMasterFacesPerEdge,
4039 Foam::label Foam::meshRefinement::markPatchZones
4046 List<edgeTopoDistanceData<label>> allEdgeInfo(
patch.nEdges());
4054 forAll(nMasterFacesPerEdge, edgeI)
4056 if (nMasterFacesPerEdge[edgeI] > 2)
4058 allEdgeInfo[edgeI] = edgeTopoDistanceData<label>(0, -2);
4070 DynamicList<label> changedEdges;
4071 DynamicList<edgeTopoDistanceData<label>> changedInfo;
4073 const scalar tol = PatchEdgeFaceWave
4076 edgeTopoDistanceData<label>
4077 >::propagationTol();
4081 const globalIndex globalFaces(
patch.size());
4085 label currentZoneI = 0;
4095 globalSeed = globalFaces.toGlobal(faceI);
4100 reduce(globalSeed, minOp<label>());
4107 if (globalFaces.isLocal(globalSeed))
4109 const label seedFaceI = globalFaces.toLocal(globalSeed);
4111 edgeTopoDistanceData<label>& faceInfo =
allFaceInfo[seedFaceI];
4114 faceInfo = edgeTopoDistanceData<label>(0, currentZoneI);
4120 label edgeI = fEdges[fEdgeI];
4122 edgeTopoDistanceData<label>& edgeInfo = allEdgeInfo[edgeI];
4126 edgeInfo.updateEdge<
int>
4138 changedEdges.append(edgeI);
4139 changedInfo.append(edgeInfo);
4155 edgeTopoDistanceData<label>
4171 faceToZone.setSize(
patch.size());
4177 <<
"Problem: unvisited face " << faceI
4178 <<
" at " <<
patch.faceCentres()[faceI]
4184 return currentZoneI;
4188 void Foam::meshRefinement::consistentOrientation
4190 const bitSet& isMasterFace,
4194 const Map<label>& zoneToOrientation,
4198 const polyBoundaryMesh& bm = mesh_.boundaryMesh();
4201 List<patchFaceOrientation> allEdgeInfo(
patch.nEdges());
4212 const label meshFaceI =
patch.addressing()[faceI];
4213 const label patchI = bm.whichPatch(meshFaceI);
4219 && !isMasterFace.test(meshFaceI)
4232 label nProtected = 0;
4234 forAll(nMasterFacesPerEdge, edgeI)
4236 if (nMasterFacesPerEdge[edgeI] > 2)
4243 Info<<
"Protected from visiting " 4245 <<
" non-manifold edges" <<
nl <<
endl;
4250 DynamicList<label> changedEdges;
4251 DynamicList<patchFaceOrientation> changedInfo;
4253 const scalar tol = PatchEdgeFaceWave
4256 patchFaceOrientation
4257 >::propagationTol();
4261 globalIndex globalFaces(
patch.size());
4271 globalSeed = globalFaces.toGlobal(faceI);
4276 reduce(globalSeed, minOp<label>());
4283 if (globalFaces.isLocal(globalSeed))
4285 const label seedFaceI = globalFaces.toLocal(globalSeed);
4289 patchFaceOrientation& faceInfo =
allFaceInfo[seedFaceI];
4294 if (zoneToOrientation[faceToZone[seedFaceI]] < 0)
4303 label edgeI = fEdges[fEdgeI];
4305 patchFaceOrientation& edgeInfo = allEdgeInfo[edgeI];
4309 edgeInfo.updateEdge<
int>
4321 changedEdges.append(edgeI);
4322 changedInfo.append(edgeInfo);
4339 patchFaceOrientation
4357 mesh_.nBoundaryFaces(),
4363 const label meshFaceI =
patch.addressing()[i];
4364 if (!mesh_.isInternalFace(meshFaceI))
4366 neiStatus[meshFaceI-mesh_.nInternalFaces()] =
4374 const label meshFaceI =
patch.addressing()[i];
4375 const label patchI = bm.whichPatch(meshFaceI);
4381 && !isMasterFace.test(meshFaceI)
4385 label bFaceI = meshFaceI-mesh_.nInternalFaces();
4398 <<
"Incorrect status for face " << meshFaceI
4408 meshFlipMap.setSize(mesh_.nFaces());
4409 meshFlipMap =
false;
4413 label meshFaceI =
patch.addressing()[faceI];
4417 meshFlipMap.unset(meshFaceI);
4421 meshFlipMap.set(meshFaceI);
4426 <<
"Problem : unvisited face " << faceI
4427 <<
" centre:" << mesh_.faceCentres()[meshFaceI]
4434 void Foam::meshRefinement::zonify
4437 const bitSet& isMasterFace,
4441 const bitSet& meshFlipMap,
4442 polyTopoChange& meshMod
4445 const labelList& faceOwner = mesh_.faceOwner();
4446 const labelList& faceNeighbour = mesh_.faceNeighbour();
4448 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
4450 label faceZoneI = faceToZone[faceI];
4452 if (faceZoneI != -1)
4458 label ownZone = cellToZone[faceOwner[faceI]];
4459 label neiZone = cellToZone[faceNeighbour[faceI]];
4463 if (ownZone == neiZone)
4466 flip = meshFlipMap.
test(faceI);
4473 || (neiZone != -1 && ownZone > neiZone)
4481 mesh_.faces()[faceI],
4484 faceNeighbour[faceI],
4496 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
4503 label faceI =
pp.start();
4507 label faceZoneI = faceToZone[faceI];
4509 if (faceZoneI != -1)
4511 label ownZone = cellToZone[faceOwner[faceI]];
4512 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
4516 if (ownZone == neiZone)
4519 flip = meshFlipMap.test(faceI);
4526 || (neiZone != -1 && ownZone > neiZone)
4534 mesh_.faces()[faceI],
4554 forAll(cellToZone, cellI)
4556 label zoneI = cellToZone[cellI];
4574 void Foam::meshRefinement::allocateInterRegionFaceZone
4576 const label ownZone,
4577 const label neiZone,
4579 LabelPairMap<word>& zoneIDsToFaceZone
4584 if (ownZone != neiZone)
4591 || (neiZone != -1 && ownZone > neiZone)
4601 if (!zoneIDsToFaceZone.found(
key))
4604 const word ownZoneName =
4607 ? cellZones[ownZone].name()
4610 const word neiZoneName =
4613 ? cellZones[neiZone].name()
4618 Pair<word> wordKey(ownZoneName, neiZoneName);
4624 word fzName = wordKey.first() +
"_to_" + wordKey.second();
4626 zoneIDsToFaceZone.insert(
key, fzName);
4627 zonesToFaceZone.insert(wordKey, fzName);
4637 const bool doHandleSnapProblems,
4639 const bool useTopologicalSnapDetection,
4640 const bool removeEdgeConnectedCells,
4642 const label nErodeCellZones,
4651 const bool exitIfLeakPath,
4662 Info<<
"Introducing baffles for " 4664 <<
" faces that are intersected by the surface." <<
nl <<
endl;
4667 labelList neiLevel(mesh_.nBoundaryFaces());
4669 calcNeighbourData(neiLevel, neiCc);
4677 globalToMasterPatch,
4681 locationsOutsideMesh,
4693 createBaffles(ownPatch, neiPatch);
4701 Info<<
"Created baffles in = " 4704 printMeshInfo(
debug,
"After introducing baffles",
true);
4708 const_cast<Time&
>(mesh_.time())++;
4717 Pout<<
"Dumped debug data in = " 4727 if (doHandleSnapProblems)
4732 useTopologicalSnapDetection,
4733 removeEdgeConnectedCells,
4737 globalToMasterPatch,
4745 neiLevel.setSize(mesh_.nBoundaryFaces());
4746 neiCc.setSize(mesh_.nBoundaryFaces());
4747 calcNeighbourData(neiLevel, neiCc);
4754 globalToMasterPatch,
4758 locationsOutsideMesh,
4770 createBaffles(ownPatch, neiPatch);
4785 <<
"Remove unreachable sections of mesh" <<
nl 4786 <<
"-----------------------------------" <<
nl 4796 globalToMasterPatch,
4799 locationsOutsideMesh,
4809 Info<<
"Split mesh in = " 4812 printMeshInfo(
debug,
"After subsetting",
true);
4825 Pout<<
"Dumped debug data in = " 4833 const bool samePatch,
4835 const bool useTopologicalSnapDetection,
4836 const bool removeEdgeConnectedCells,
4838 const scalar planarAngle,
4851 <<
"Merge free-standing baffles" <<
nl 4852 <<
"---------------------------" <<
nl 4869 Info<<
"Detected free-standing baffles : " << nCouples <<
endl;
4883 useTopologicalSnapDetection,
4884 removeEdgeConnectedCells,
4888 globalToMasterPatch,
4896 <<
"Remove unreachable sections of mesh" <<
nl 4897 <<
"-----------------------------------" <<
nl 4907 globalToMasterPatch,
4910 locationsOutsideMesh,
4922 Info<<
"Merged free-standing baffles in = " 4929 const label nBufferLayers,
4930 const label nErodeCellZones,
4937 const bool exitIfLeakPath,
4947 labelList neiLevel(mesh_.nBoundaryFaces());
4949 calcNeighbourData(neiLevel, neiCc);
4956 globalToMasterPatch,
4960 locationsOutsideMesh,
4973 boolList blockedFace(mesh_.nFaces(),
false);
4977 if (ownPatch[faceI] != -1 || neiPatch[faceI] != -1)
4979 blockedFace[faceI] =
true;
4991 vector::uniform(mergeDistance_),
4993 locationsOutsideMesh,
5005 globalToMasterPatch,
5016 const label nBufferLayers,
5031 const labelList& faceOwner = mesh_.faceOwner();
5032 const labelList& faceNeighbour = mesh_.faceNeighbour();
5036 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
5038 if (ownPatch[facei] == -1 && neiPatch[facei] != -1)
5041 <<
" at:" << mesh_.faceCentres()[facei]
5042 <<
" ownPatch:" << ownPatch[facei]
5043 <<
" neiPatch:" << neiPatch[facei]
5049 const label ownRegion = cellRegion[faceOwner[facei]];
5050 const label neiRegion = cellRegion[faceNeighbour[facei]];
5051 if (ownRegion != neiRegion)
5053 if (ownPatch[facei] == -1)
5056 <<
" at:" << mesh_.faceCentres()[facei]
5057 <<
" ownPatch:" << ownPatch[facei]
5058 <<
" ownRegion:" << ownRegion
5059 <<
" neiPatch:" << neiPatch[facei]
5060 <<
" neiRegion:" << neiRegion
5072 DynamicList<label> startFaces;
5075 if (ownPatch[facei] != -1)
5077 startFaces.append(facei);
5083 autoPtr<mapDistribute> mapPtr;
5087 bitSet(mesh_.nFaces()),
5095 labelList startOwnPatch(ownPatch, startFaces);
5096 mapPtr().distribute(startOwnPatch);
5098 nearestOwnPatch.setSize(mesh_.nFaces());
5099 nearestOwnPatch = -1;
5100 forAll(faceToStart, facei)
5102 const label sloti = faceToStart[facei];
5105 nearestOwnPatch[facei] = startOwnPatch[sloti];
5119 bitSet isFrozenPoint(mesh_.nPoints());
5120 bitSet isFrozenFace(mesh_.nFaces());
5126 const label pointZonei = pzs.
findZoneID(
"frozenPoints");
5127 if (pointZonei != -1)
5129 const pointZone& pz = pzs[pointZonei];
5130 isFrozenPoint.set(pz);
5131 for (
const label pointi : pz)
5133 isFrozenFace.set(pointFaces[pointi]);
5138 const label faceZonei = fzs.
findZoneID(
"frozenFaces");
5139 if (faceZonei != -1)
5141 const faceZone& fz = fzs[faceZonei];
5142 isFrozenFace.set(fz);
5143 for (
const label facei : fz)
5145 isFrozenPoint.set(mesh_.faces()[facei]);
5151 label defaultPatch = 0;
5152 if (globalToMasterPatch.
size())
5154 defaultPatch = globalToMasterPatch[0];
5157 for (label i = 0; i < nBufferLayers; i++)
5161 labelList pointBaffle(mesh_.nPoints(), -1);
5163 forAll(faceNeighbour, facei)
5165 if (!isFrozenFace[facei])
5167 const face&
f = mesh_.faces()[facei];
5169 const label ownRegion = cellRegion[faceOwner[facei]];
5170 const label neiRegion = cellRegion[faceNeighbour[facei]];
5172 if (ownRegion == -1 && neiRegion != -1)
5179 if (!isFrozenPoint[
f[fp]])
5181 pointBaffle[
f[fp]] =
5182 max(defaultPatch, ownPatch[facei]);
5186 else if (ownRegion != -1 && neiRegion == -1)
5188 label newPatchi = neiPatch[facei];
5189 if (newPatchi == -1)
5191 newPatchi =
max(defaultPatch, ownPatch[facei]);
5195 if (!isFrozenPoint[
f[fp]])
5197 pointBaffle[
f[fp]] = newPatchi;
5236 const auto&
patches = mesh_.boundaryMesh();
5248 const label facei =
pp.start()+i;
5249 if (!isFrozenFace[facei])
5251 const face&
f = mesh_.faces()[facei];
5252 const label ownRegion = cellRegion[faceOwner[facei]];
5253 const label neiRegion =
5254 neiCellRegion[facei-mesh_.nInternalFaces()];
5258 if (ownRegion == -1 && neiRegion != -1)
5262 if (!isFrozenPoint[
f[fp]])
5264 pointBaffle[
f[fp]] =
5265 max(defaultPatch, ownPatch[facei]);
5269 else if (ownRegion != -1 && neiRegion == -1)
5271 label newPatchI = neiPatch[facei];
5272 if (newPatchI == -1)
5274 newPatchI =
max(defaultPatch, ownPatch[facei]);
5278 if (!isFrozenPoint[
f[fp]])
5280 pointBaffle[
f[fp]] = newPatchI;
5291 const label facei =
pp.start()+i;
5292 if (!isFrozenFace[facei])
5294 const face&
f = mesh_.faces()[facei];
5295 const label ownRegion = cellRegion[faceOwner[facei]];
5297 if (ownRegion != -1)
5301 if (!isFrozenPoint[
f[fp]])
5303 pointBaffle[
f[fp]] =
5304 max(defaultPatch, ownPatch[facei]);
5328 forAll(pointFaces, pointi)
5330 if (pointBaffle[pointi] != -1)
5336 const label facei =
pFaces[pFacei];
5338 if (!isFrozenFace[facei] && ownPatch[facei] == -1)
5340 ownPatch[facei] = pointBaffle[pointi];
5354 if (!isFrozenFace[facei] && ownPatch[facei] != -1)
5356 const label own = faceOwner[facei];
5358 if (cellRegion[own] == -1)
5362 const cell& ownFaces = mesh_.cells()[own];
5365 const label ownFacei = ownFaces[j];
5366 if (!isFrozenFace[ownFacei] && ownPatch[ownFacei] == -1)
5368 newOwnPatch[ownFacei] = ownPatch[facei];
5372 if (mesh_.isInternalFace(facei))
5374 const label nei = faceNeighbour[facei];
5376 if (cellRegion[nei] == -1)
5380 const cell& neiFaces = mesh_.cells()[nei];
5383 const label neiFacei = neiFaces[j];
5384 const bool isFrozen = isFrozenFace[neiFacei];
5385 if (!isFrozen && ownPatch[neiFacei] == -1)
5387 newOwnPatch[neiFacei] = ownPatch[facei];
5405 DynamicList<label> cellsToRemove(mesh_.nCells());
5406 forAll(cellRegion, celli)
5408 if (cellRegion[celli] == -1)
5410 cellsToRemove.append(celli);
5413 cellsToRemove.shrink();
5417 mesh_.nCells() - cellsToRemove.size(),
5421 Info<<
"Keeping all cells containing inside points" <<
endl 5422 <<
"Selected for keeping : " << nCellsToKeep <<
" cells." <<
endl;
5426 removeCells cellRemover(mesh_);
5429 const labelList exposedFaces(cellRemover.getExposedFaces(cellsToRemove));
5430 labelList exposedPatches(exposedFaces.size());
5432 label nUnpatched = 0;
5436 label facei = exposedFaces[i];
5438 if (ownPatch[facei] != -1)
5440 exposedPatches[i] = ownPatch[facei];
5444 const label fallbackPatch =
5446 nearestOwnPatch.size()
5447 ? nearestOwnPatch[facei]
5450 if (nUnpatched == 0)
5453 <<
"For exposed face " << facei
5454 <<
" fc:" << mesh_.faceCentres()[facei]
5455 <<
" found no patch." <<
endl 5456 <<
" Taking patch " << fallbackPatch
5457 <<
" instead. Suppressing future warnings" <<
endl;
5461 exposedPatches[i] = fallbackPatch;
5465 reduce(nUnpatched, sumOp<label>());
5468 Info<<
"Detected " << nUnpatched <<
" faces out of " 5470 <<
" for which the default patch " << defaultPatch
5471 <<
" will be used" <<
endl;
5474 return doRemoveCells
5486 const label nBufferLayers,
5487 const label nErodeCellZones,
5499 labelList neiLevel(mesh_.nBoundaryFaces());
5501 calcNeighbourData(neiLevel, neiCc);
5509 globalToMasterPatch,
5513 locationsOutsideMesh,
5529 limitShells_.findLevel
5531 mesh_.cellCentres(),
5535 forAll(levelShell, celli)
5537 if (levelShell[celli] != -1)
5540 cellRegion[celli] = -1;
5547 globalToMasterPatch,
5556 const_cast<Time&
>(mesh_.time())++;
5557 Pout<<
"Writing mesh after removing limitShells" 5588 Info<<
"dupNonManifoldPoints : Found : " << nNonManifPoints
5589 <<
" non-manifold points (out of " 5590 << mesh_.globalData().nTotalPoints()
5596 if (nNonManifPoints)
5606 mesh_.moving(
false);
5609 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
5613 mesh_.updateMesh(map);
5652 label nPointPairs = 0;
5653 forAll(pointToDuplicate, pointI)
5655 label otherPointI = pointToDuplicate[pointI];
5656 if (otherPointI != -1)
5667 forAll(pointToDuplicate, pointI)
5669 label otherPointI = pointToDuplicate[pointI];
5670 if (otherPointI != -1)
5673 pointToMaster.
insert(pointI, otherPointI);
5685 mesh_.moving(
false);
5688 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
5692 mesh_.updateMesh(map);
5739 internalOrBaffleFaceZones = getZones(fzTypes);
5749 forAll(boundaryFaceZones, j)
5751 const faceZone& fZone = mesh_.faceZones()[boundaryFaceZones[j]];
5754 const face&
f = mesh_.faces()[fZone[i]];
5757 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 1u);
5761 forAll(internalOrBaffleFaceZones, j)
5763 const faceZone& fZone = mesh_.faceZones()[internalOrBaffleFaceZones[j]];
5766 const face&
f = mesh_.faces()[fZone[i]];
5769 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 2u);
5784 forAll(pointStatus, pointI)
5786 if (pointStatus[pointI] == 1u)
5793 Info<<
"Duplicating " << globalNPoints <<
" points on" 5794 <<
" faceZones of type " 5804 forAll(pointStatus, pointI)
5806 if (pointStatus[pointI] == 1u)
5808 candidatePoints[
n++] = pointI;
5821 const bool allowFreeStandingZoneFaces,
5822 const label nErodeCellZones,
5826 const bool exitIfLeakPath,
5832 if (locationsInMesh.
size() != zonesInMesh.
size())
5842 labelList neiLevel(mesh_.nBoundaryFaces());
5844 calcNeighbourData(neiLevel, neiCc);
5853 if (namedSurfaces.
size())
5855 Info<<
"Setting cellZones according to named surfaces:" <<
endl;
5858 label surfI = namedSurfaces[i];
5860 Info<<
"Surface : " << surfaces_.names()[surfI] <<
nl 5861 <<
" faceZones : " << surfZones[surfI].faceZoneNames() <<
nl 5862 <<
" cellZone : " << surfZones[surfI].cellZoneName()
5903 allowFreeStandingZoneFaces,
5908 locationsOutsideMesh,
5926 labelList faceToZone(mesh_.nFaces(), -1);
5928 forAll(namedSurfaceRegion, faceI)
5931 label globalI = namedSurfaceRegion[faceI];
5934 const labelPair spr = surfaces_.whichSurface(globalI);
5935 faceToZone[faceI] = surfaceToFaceZones[spr.
first()][spr.
second()];
5949 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
5951 if (faceToZone[faceI] == -1)
5956 allocateInterRegionFaceZone
5958 cellToZone[mesh_.faceOwner()[faceI]],
5959 cellToZone[mesh_.faceNeighbour()[faceI]],
5969 forAll(neiCellZone, bFaceI)
5971 label faceI = bFaceI + mesh_.nInternalFaces();
5972 if (faceToZone[faceI] == -1)
5974 allocateInterRegionFaceZone
5976 cellToZone[mesh_.faceOwner()[faceI]],
5977 neiCellZone[bFaceI],
5995 Info<<
"Setting faceZones according to neighbouring cellZones:" 6009 const word& fzName = zonesToFaceZone[cz];
6012 << cz[0] <<
' ' << cz[1] <<
nl 6013 <<
" faceZone : " << fzName <<
endl;
6023 label cz0 = cellZones.findZoneID(cz[0]);
6024 label cz1 = cellZones.findZoneID(cz[1]);
6034 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
6036 if (faceToZone[faceI] == -1)
6042 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
6043 label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
6044 if (ownZone != neiZone)
6049 || (neiZone != -1 && ownZone > neiZone)
6056 faceToZone[faceI] = fZoneLookup[
key];
6060 forAll(neiCellZone, bFaceI)
6062 label faceI = bFaceI + mesh_.nInternalFaces();
6063 if (faceToZone[faceI] == -1)
6065 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
6066 label neiZone = neiCellZone[bFaceI];
6067 if (ownZone != neiZone)
6072 || (neiZone != -1 && ownZone > neiZone)
6079 faceToZone[faceI] = fZoneLookup[
key];
6098 label bFaceI =
pp.start()-mesh_.nInternalFaces();
6101 neiCellZone[bFaceI++] = -1;
6122 bitSet meshFlipMap(mesh_.nFaces(),
false);
6130 freeStandingBaffleFaces
6141 if (nFreeStanding > 0)
6143 Info<<
"Detected " << nFreeStanding <<
" free-standing zone faces" 6148 OBJstream str(mesh_.time().path()/
"freeStanding.obj");
6149 Pout<<
"meshRefinement::zonify : dumping faceZone faces to " 6157 calcPatchNumMasterFaces(isMasterFace,
patch, nMasterFacesPerEdge);
6162 const label nZones = markPatchZones
6165 nMasterFacesPerEdge,
6170 for (label zoneI = 0; zoneI < nZones; zoneI++)
6172 nPosOrientation.
insert(zoneI, 0);
6178 consistentOrientation
6182 nMasterFacesPerEdge,
6183 faceToConnectedZone,
6193 label meshFaceI =
patch.addressing()[faceI];
6195 if (isMasterFace.
test(meshFaceI))
6200 posOrientation.
test(meshFaceI)
6201 == meshFlipMap.test(meshFaceI)
6207 nPosOrientation.
find(faceToConnectedZone[faceI])() +=
n;
6213 Info<<
"Split " << nFreeStanding <<
" free-standing zone faces" 6214 <<
" into " << nZones <<
" disconnected regions with size" 6215 <<
" (negative denotes wrong orientation) :" 6218 for (label zoneI = 0; zoneI < nZones; zoneI++)
6220 Info<<
" " << zoneI <<
"\t" << nPosOrientation[zoneI]
6228 consistentOrientation
6232 nMasterFacesPerEdge,
6233 faceToConnectedZone,
6260 mesh_.moving(
false);
6266 mesh_.updateMesh(map());
6269 if (map().hasMotionPoints())
6271 mesh_.movePoints(map().preMotionPoints());
6283 if (mesh_.cellZones().size() > 0)
6286 forAll(mesh_.cellZones(), zoneI)
6288 const cellZone& cz = mesh_.cellZones()[zoneI];
6295 if (mesh_.faceZones().size() > 0)
6298 forAll(mesh_.faceZones(), zoneI)
6300 const faceZone& fz = mesh_.faceZones()[zoneI];
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
Class containing data for face removal.
const polyBoundaryMesh & pbm
const T & first() const noexcept
Access the first element.
void size(const label n)
Older name for setAddressableSize.
ZoneMesh< faceZone, polyMesh > faceZoneMesh
A ZoneMesh with the type faceZone.
const labelIOList & zoneIDs
fileName path() const
Return path = rootPath/caseName. Same as TimePaths::path()
labelList findIndices(const ListType &input, const UnaryPredicate &pred, label start=0)
Linear search to find all occurences of given element.
Ostream & indent(Ostream &os)
Indent stream.
static void mapBaffles(const polyMesh &mesh, const labelList &faceMap, List< labelPair > &baffles)
Map baffles after layer addition. Gets new-to-old face map.
List< wallPoints > allCellInfo(mesh_.nCells())
autoPtr< mapPolyMesh > mergePoints(const labelList &pointToDuplicate)
Merge duplicate points.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Class describing modification of a face.
A face is a list of labels corresponding to mesh vertices.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void append(const T &val)
Append an element at the end of the list.
virtual const labelList & faceNeighbour() const
Return face neighbour.
const bitSet isBlockedFace(intersectedFaces())
wallPoints::trackData td(isBlockedFace, regionToBlockSize)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Unit conversion functions.
constexpr char nl
The newline '\n' character (0x0a)
static labelListList addFaceZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
void setSize(const label n, unsigned int val=0u)
Alias for resize()
UIndirectList< label > labelUIndList
UIndirectList of labels.
T & first()
Access first element of the list, position [0].
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool found(const T &val, label pos=0) const
Same as contains()
autoPtr< mapPolyMesh > createBaffles(const labelList &ownPatch, const labelList &neiPatch)
Create baffle for every internal face where ownPatch != -1.
void baffleAndSplitMesh(const bool handleSnapProblems, const snapParameters &snapParams, const bool useTopologicalSnapDetection, const bool removeEdgeConnectedCells, const scalarField &perpendicularAngle, const label nErodeCellZones, const dictionary &motionDict, Time &runTime, const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const wordList ®ionsInMesh, const pointField &locationsOutsideMesh, const bool exitIfLeakPath, const refPtr< coordSetWriter > &leakPathFormatter, refPtr< surfaceWriter > &surfFormatter)
Split off unreachable areas of mesh.
static labelList addCellZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
static const Enum< faceZoneType > faceZoneTypeNames
label whichFace(const label globalCellID) const
Helper function to re-direct to zone::localID(...)
labelList getZones(const List< surfaceZonesInfo::faceZoneType > &fzTypes) const
Get zones of given type.
static List< labelPair > subsetBaffles(const polyMesh &mesh, const labelList &zoneIDs, const List< labelPair > &baffles)
Subset baffles according to zones.
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
label nFaces() const noexcept
Number of mesh faces.
static labelList getStandaloneNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces without a cellZone.
std::enable_if_t< std::is_same_v< bool, TypeT >, bool > test(const label i) const
Test bool value at specified position, always false for out-of-range access.
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field...
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.
virtual const fileName & name() const override
Get the name of the output serial stream. (eg, the name of the Fstream file name) ...
labelList faceLabels(nFaceLabels)
List< labelList > labelListList
List of labelList.
DynamicID< faceZoneMesh > faceZoneID
Foam::faceZoneID.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1, const label comm)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A class for managing references or pointers (no reference counting)
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
bool isInternalFace(const label faceIndex) const noexcept
Return true if given face label is internal to the mesh.
const labelList & meshPoints() const
Return labelList of mesh points in patch.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Takes mesh with 'baffles' (= boundary faces sharing points). Determines for selected points on bounda...
static labelPairList findDuplicateFacePairs(const polyMesh &)
Helper routine to find all baffles (two boundary faces.
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.
const labelList & reverseFaceMap() const noexcept
Reverse face map.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
label size() const noexcept
The number of elements in table.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
A list of faces which address into the list of points.
Determines the 'side' for every face and connected to a singly-connected (through edges) region of fa...
word outputName("finiteArea-edges.obj")
vectorField pointField
pointField is a vectorField.
const dimensionedScalar e
Elementary charge.
void setSize(const label n)
Alias for resize()
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
dimensionedScalar cos(const dimensionedScalar &ds)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
static void mergePoints(const polyMesh &, const Map< label > &pointToMaster, polyTopoChange &meshMod)
Helper: Merge points.
const wordList area
Standard area field types (scalar, vector, tensor, etc)
void clear()
Clear the list, i.e. set size to zero.
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
Simple container to keep together snap specific information.
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
label size() const noexcept
The number of entries in the list.
const Field< point_type > & faceCentres() const
Return face centres for patch.
static void mapCombineReduce(Container &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Forwards to Pstream::mapReduce with an in-place cop.
autoPtr< mapPolyMesh > mergeZoneBaffles(const bool doInternalZones, const bool doBaffleZones)
Merge all baffles on faceZones.
virtual const labelList & faceOwner() const
Return face owner.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=cellModel::ref(cellModel::HEX);labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){ pointMap[i]=i;}for(label i=0;i< nPoints;i++){ if(f[i] > 0.0) { hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells].reset(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei) { if(edges[ei].mag(points)< SMALL) { label start=pointMap[edges[ei].start()];while(start !=pointMap[start]) { start=pointMap[start];} label end=pointMap[edges[ei].end()];while(end !=pointMap[end]) { end=pointMap[end];} pointMap[start]=pointMap[end]=Foam::min(start, end);} } cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){ cellShape &cs=cellShapes[celli];forAll(cs, i) { cs[i]=pointMap[cs[i]];} cs.collapse();}label bcIDs[11]={-1, 0, 2, 4, -1, 5, -1, 6, 7, 8, 9};constexpr label nBCs=12;const word *kivaPatchTypes[nBCs]={ &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &symmetryPolyPatch::typeName, &wedgePolyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &symmetryPolyPatch::typeName, &oldCyclicPolyPatch::typeName};enum patchTypeNames{ PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={ "piston", "valve", "liner", "cylinderHead", "axis", "wedge", "inflow", "outflow", "presin", "presout", "symmetryPlane", "cyclic"};List< DynamicList< face > > pFaces[nBCs]
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.
autoPtr< mapPolyMesh > removeLimitShells(const label nBufferLayers, const label nErodeCellZones, const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const wordList ®ionsInMesh, const pointField &locationsOutsideMesh)
Remove cells from limitRegions if level -1.
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
label nInternalFaces() const noexcept
Number of internal faces.
void reverse(UList< T > &list, const label n)
Reverse the first n elements of the list.
auto key(const Type &t) -> std::enable_if_t< std::is_enum_v< Type >, std::underlying_type_t< Type > >
ZoneMesh< pointZone, polyMesh > pointZoneMesh
A ZoneMesh with the type pointZone.
void append(const T &val)
Copy append an element to the end of this list.
virtual const faceList & faces() const
Return raw faces.
label whichPatch(const label meshFacei) const
Return patch index for a given mesh face index. Uses binary search.
static labelList getInsidePointNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of surfaces with a cellZone that have 'insidePoint'.
FaceCellWave< wallPoints, wallPoints::trackData > wallDistCalc(mesh_, changedFaces, faceDist, allFaceInfo, allCellInfo, 0, td)
A HashTable similar to std::unordered_map.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
static labelList getUnnamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of unnamed surfaces (surfaces without faceZoneName)
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
errorManip< error > abort(error &err)
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
bool test(const label pos) const
Test for True value at specified position, never auto-vivify entries.
label find(const T &val) const
Find index of the first occurrence of the value.
void mergeFreeStandingBaffles(const bool samePatch, const snapParameters &snapParams, const bool useTopologicalSnapDetection, const bool removeEdgeConnectedCells, const scalarField &perpendicularAngle, const scalar planarAngle, const dictionary &motionDict, Time &runTime, const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const pointField &locationsOutsideMesh)
Merge free-standing baffles.
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh...
Istream and Ostream manipulators taking arguments.
An OFstream that keeps track of vertices and provides convenience output methods for OBJ files...
Smanip< std::ios_base::fmtflags > setf(std::ios_base::fmtflags flags)
int debug
Static debugging option.
Pair< label > labelPair
A pair of labels.
Type gMax(const FieldField< Field, Type > &f)
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
double cpuTimeIncrement() const
Return CPU time [seconds] since last call to cpuTimeIncrement(), resetCpuTimeIncrement().
bool hasMotionPoints() const noexcept
Has valid preMotionPoints?
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
autoPtr< mapPolyMesh > createZoneBaffles(const labelList &zoneIDs, List< labelPair > &baffles, labelList &originatingFaceZone)
Create baffles for faces on faceZones. Return created baffles.
const vectorField & faceCentres() const
List< word > wordList
List of word.
PrimitivePatch< UIndirectList< face >, const pointField & > uindirectPrimitivePatch
A PrimitivePatch with UIndirectList for the faces, const reference for the point field.
autoPtr< mapPolyMesh > dupNonManifoldPoints()
Find boundary points that connect to more than one cell.
vector point
Point is a vector.
autoPtr< mapPolyMesh > dupNonManifoldBoundaryPoints()
Find boundary points that are on faceZones of type boundary.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
#define WarningInFunction
Report a warning using Foam::Warning.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Direct mesh changes based on v1.3 polyTopoChange syntax.
const polyBoundaryMesh & patches
const word & name() const noexcept
The zone name.
void getZoneFaces(const labelList &zoneIDs, labelList &faceZoneID, labelList &ownPatch, labelList &neiPatch, labelList &nBaffles) const
Get per-face information (faceZone, master/slave patch)
static word outputPrefix
Directory prefix.
const std::string patch
OpenFOAM patch number as a std::string.
void setRefinement(const localPointRegion ®ionSide, polyTopoChange &)
Play commands into polyTopoChange to duplicate points. Gets.
label nRegions() const
Return total number of regions.
static List< pointField > zonePoints(const pointField &locationsInMesh, const wordList &zonesInMesh, const pointField &locationsOutsideMesh)
Helper: per zone (entry in zonesInMesh) the locations with.
autoPtr< mapPolyMesh > mergeBaffles(const List< labelPair > &, const Map< label > &faceToPatch)
Merge baffles. Gets pairs of faces and boundary faces to move.
static labelList getClosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are closed and.
const boolList & flipMap() const noexcept
Return face flip map.
static labelList getNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces (surfaces with faceZoneName)
messageStream Info
Information stream (stdout output on master, null elsewhere)
writeType
Enumeration for what to write. Used as a bit-pattern.
Field< vector > vectorField
Specialisation of Field<T> for vector.
static autoPtr< mapDistribute > calcClosure(const polyMesh &mesh, const List< pointField > &zonePoints, const labelList &blockedFaces, const globalIndex &globalBlockedFaces, const bool erode, labelList &closureFaces, labelList &closureToBlocked)
Optional direct use to generate the set of faces and the method to.
faceZoneType
What to do with faceZone faces.
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.
Omanip< int > setw(const int i)
A subset of mesh faces organised as a primitive patch.
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)
const T & second() const noexcept
Access the second element.
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
static void listReduce(UList< T > &values, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce list elements (list must be equal size on all ranks), applying bop to each list element...
List< bool > boolList
A List of bools.
A List with indirect addressing.
const pointField & preMotionPoints() const noexcept
Pre-motion point positions.
List< wallPoints > allFaceInfo(mesh_.nFaces())
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Do not request registration (bool: false)
HashTable< word, wordPair, Foam::Hash< wordPair > > wordPairHashTable
HashTable of wordPair.
ZoneMesh< cellZone, polyMesh > cellZoneMesh
A ZoneMesh with the type cellZone.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
static label addFaceZone(const word &name, const labelList &addressing, const boolList &flipMap, polyMesh &mesh)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
forAllConstIters(mixture.phases(), phase)
A HashTable to objects of type <T> with a label key.
label setAction(const topoAction &action)
For compatibility with polyTopoChange: set topological action.
static constexpr const zero Zero
Global zero (0)