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)
4002 void Foam::meshRefinement::calcPatchNumMasterFaces
4004 const bitSet& isMasterFace,
4010 nMasterFacesPerEdge.setSize(
patch.nEdges());
4011 nMasterFacesPerEdge = 0;
4015 const label meshFaceI =
patch.addressing()[faceI];
4017 if (isMasterFace.test(meshFaceI))
4022 nMasterFacesPerEdge[fEdges[fEdgeI]]++;
4030 patch.meshEdges(mesh_.edges(), mesh_.pointEdges()),
4031 nMasterFacesPerEdge,
4038 Foam::label Foam::meshRefinement::markPatchZones
4045 List<edgeTopoDistanceData<label>> allEdgeInfo(
patch.nEdges());
4053 forAll(nMasterFacesPerEdge, edgeI)
4055 if (nMasterFacesPerEdge[edgeI] > 2)
4057 allEdgeInfo[edgeI] = edgeTopoDistanceData<label>(0, -2);
4069 DynamicList<label> changedEdges;
4070 DynamicList<edgeTopoDistanceData<label>> changedInfo;
4072 const scalar tol = PatchEdgeFaceWave
4075 edgeTopoDistanceData<label>
4076 >::propagationTol();
4080 const globalIndex globalFaces(
patch.size());
4084 label currentZoneI = 0;
4094 globalSeed = globalFaces.toGlobal(faceI);
4099 reduce(globalSeed, minOp<label>());
4106 if (globalFaces.isLocal(globalSeed))
4108 const label seedFaceI = globalFaces.toLocal(globalSeed);
4110 edgeTopoDistanceData<label>& faceInfo =
allFaceInfo[seedFaceI];
4113 faceInfo = edgeTopoDistanceData<label>(0, currentZoneI);
4119 label edgeI = fEdges[fEdgeI];
4121 edgeTopoDistanceData<label>& edgeInfo = allEdgeInfo[edgeI];
4125 edgeInfo.updateEdge<
int>
4137 changedEdges.append(edgeI);
4138 changedInfo.append(edgeInfo);
4154 edgeTopoDistanceData<label>
4170 faceToZone.setSize(
patch.size());
4176 <<
"Problem: unvisited face " << faceI
4177 <<
" at " <<
patch.faceCentres()[faceI]
4183 return currentZoneI;
4187 void Foam::meshRefinement::consistentOrientation
4189 const bitSet& isMasterFace,
4193 const Map<label>& zoneToOrientation,
4197 const polyBoundaryMesh& bm = mesh_.boundaryMesh();
4200 List<patchFaceOrientation> allEdgeInfo(
patch.nEdges());
4211 const label meshFaceI =
patch.addressing()[faceI];
4212 const label patchI = bm.whichPatch(meshFaceI);
4218 && !isMasterFace.test(meshFaceI)
4231 label nProtected = 0;
4233 forAll(nMasterFacesPerEdge, edgeI)
4235 if (nMasterFacesPerEdge[edgeI] > 2)
4242 Info<<
"Protected from visiting " 4244 <<
" non-manifold edges" <<
nl <<
endl;
4249 DynamicList<label> changedEdges;
4250 DynamicList<patchFaceOrientation> changedInfo;
4252 const scalar tol = PatchEdgeFaceWave
4255 patchFaceOrientation
4256 >::propagationTol();
4260 globalIndex globalFaces(
patch.size());
4270 globalSeed = globalFaces.toGlobal(faceI);
4275 reduce(globalSeed, minOp<label>());
4282 if (globalFaces.isLocal(globalSeed))
4284 const label seedFaceI = globalFaces.toLocal(globalSeed);
4288 patchFaceOrientation& faceInfo =
allFaceInfo[seedFaceI];
4293 if (zoneToOrientation[faceToZone[seedFaceI]] < 0)
4302 label edgeI = fEdges[fEdgeI];
4304 patchFaceOrientation& edgeInfo = allEdgeInfo[edgeI];
4308 edgeInfo.updateEdge<
int>
4320 changedEdges.append(edgeI);
4321 changedInfo.append(edgeInfo);
4338 patchFaceOrientation
4356 mesh_.nBoundaryFaces(),
4362 const label meshFaceI =
patch.addressing()[i];
4363 if (!mesh_.isInternalFace(meshFaceI))
4365 neiStatus[meshFaceI-mesh_.nInternalFaces()] =
4373 const label meshFaceI =
patch.addressing()[i];
4374 const label patchI = bm.whichPatch(meshFaceI);
4380 && !isMasterFace.test(meshFaceI)
4384 label bFaceI = meshFaceI-mesh_.nInternalFaces();
4397 <<
"Incorrect status for face " << meshFaceI
4407 meshFlipMap.setSize(mesh_.nFaces());
4408 meshFlipMap =
false;
4412 label meshFaceI =
patch.addressing()[faceI];
4416 meshFlipMap.unset(meshFaceI);
4420 meshFlipMap.set(meshFaceI);
4425 <<
"Problem : unvisited face " << faceI
4426 <<
" centre:" << mesh_.faceCentres()[meshFaceI]
4433 void Foam::meshRefinement::zonify
4436 const bitSet& isMasterFace,
4440 const bitSet& meshFlipMap,
4441 polyTopoChange& meshMod
4444 const labelList& faceOwner = mesh_.faceOwner();
4445 const labelList& faceNeighbour = mesh_.faceNeighbour();
4447 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
4449 label faceZoneI = faceToZone[faceI];
4451 if (faceZoneI != -1)
4457 label ownZone = cellToZone[faceOwner[faceI]];
4458 label neiZone = cellToZone[faceNeighbour[faceI]];
4462 if (ownZone == neiZone)
4465 flip = meshFlipMap.
test(faceI);
4472 || (neiZone != -1 && ownZone > neiZone)
4480 mesh_.faces()[faceI],
4483 faceNeighbour[faceI],
4495 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
4502 label faceI =
pp.start();
4506 label faceZoneI = faceToZone[faceI];
4508 if (faceZoneI != -1)
4510 label ownZone = cellToZone[faceOwner[faceI]];
4511 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
4515 if (ownZone == neiZone)
4518 flip = meshFlipMap.test(faceI);
4525 || (neiZone != -1 && ownZone > neiZone)
4533 mesh_.faces()[faceI],
4553 forAll(cellToZone, cellI)
4555 label zoneI = cellToZone[cellI];
4573 void Foam::meshRefinement::allocateInterRegionFaceZone
4575 const label ownZone,
4576 const label neiZone,
4578 LabelPairMap<word>& zoneIDsToFaceZone
4583 if (ownZone != neiZone)
4590 || (neiZone != -1 && ownZone > neiZone)
4600 if (!zoneIDsToFaceZone.found(
key))
4603 const word ownZoneName =
4606 ? cellZones[ownZone].name()
4609 const word neiZoneName =
4612 ? cellZones[neiZone].name()
4617 Pair<word> wordKey(ownZoneName, neiZoneName);
4623 word fzName = wordKey.first() +
"_to_" + wordKey.second();
4625 zoneIDsToFaceZone.insert(
key, fzName);
4626 zonesToFaceZone.insert(wordKey, fzName);
4636 const bool doHandleSnapProblems,
4638 const bool useTopologicalSnapDetection,
4639 const bool removeEdgeConnectedCells,
4641 const label nErodeCellZones,
4650 const bool exitIfLeakPath,
4661 Info<<
"Introducing baffles for " 4663 <<
" faces that are intersected by the surface." <<
nl <<
endl;
4666 labelList neiLevel(mesh_.nBoundaryFaces());
4668 calcNeighbourData(neiLevel, neiCc);
4676 globalToMasterPatch,
4680 locationsOutsideMesh,
4692 createBaffles(ownPatch, neiPatch);
4700 Info<<
"Created baffles in = " 4703 printMeshInfo(
debug,
"After introducing baffles",
true);
4707 const_cast<Time&
>(mesh_.time())++;
4716 Pout<<
"Dumped debug data in = " 4726 if (doHandleSnapProblems)
4731 useTopologicalSnapDetection,
4732 removeEdgeConnectedCells,
4736 globalToMasterPatch,
4744 neiLevel.setSize(mesh_.nBoundaryFaces());
4745 neiCc.setSize(mesh_.nBoundaryFaces());
4746 calcNeighbourData(neiLevel, neiCc);
4753 globalToMasterPatch,
4757 locationsOutsideMesh,
4769 createBaffles(ownPatch, neiPatch);
4784 <<
"Remove unreachable sections of mesh" <<
nl 4785 <<
"-----------------------------------" <<
nl 4795 globalToMasterPatch,
4798 locationsOutsideMesh,
4808 Info<<
"Split mesh in = " 4811 printMeshInfo(
debug,
"After subsetting",
true);
4824 Pout<<
"Dumped debug data in = " 4832 const bool samePatch,
4834 const bool useTopologicalSnapDetection,
4835 const bool removeEdgeConnectedCells,
4837 const scalar planarAngle,
4850 <<
"Merge free-standing baffles" <<
nl 4851 <<
"---------------------------" <<
nl 4868 Info<<
"Detected free-standing baffles : " << nCouples <<
endl;
4882 useTopologicalSnapDetection,
4883 removeEdgeConnectedCells,
4887 globalToMasterPatch,
4895 <<
"Remove unreachable sections of mesh" <<
nl 4896 <<
"-----------------------------------" <<
nl 4906 globalToMasterPatch,
4909 locationsOutsideMesh,
4921 Info<<
"Merged free-standing baffles in = " 4928 const label nBufferLayers,
4929 const label nErodeCellZones,
4936 const bool exitIfLeakPath,
4946 labelList neiLevel(mesh_.nBoundaryFaces());
4948 calcNeighbourData(neiLevel, neiCc);
4955 globalToMasterPatch,
4959 locationsOutsideMesh,
4972 boolList blockedFace(mesh_.nFaces(),
false);
4976 if (ownPatch[faceI] != -1 || neiPatch[faceI] != -1)
4978 blockedFace[faceI] =
true;
4990 vector::uniform(mergeDistance_),
4992 locationsOutsideMesh,
5004 globalToMasterPatch,
5015 const label nBufferLayers,
5030 const labelList& faceOwner = mesh_.faceOwner();
5031 const labelList& faceNeighbour = mesh_.faceNeighbour();
5035 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
5037 if (ownPatch[facei] == -1 && neiPatch[facei] != -1)
5040 <<
" at:" << mesh_.faceCentres()[facei]
5041 <<
" ownPatch:" << ownPatch[facei]
5042 <<
" neiPatch:" << neiPatch[facei]
5048 const label ownRegion = cellRegion[faceOwner[facei]];
5049 const label neiRegion = cellRegion[faceNeighbour[facei]];
5050 if (ownRegion != neiRegion)
5052 if (ownPatch[facei] == -1)
5055 <<
" at:" << mesh_.faceCentres()[facei]
5056 <<
" ownPatch:" << ownPatch[facei]
5057 <<
" ownRegion:" << ownRegion
5058 <<
" neiPatch:" << neiPatch[facei]
5059 <<
" neiRegion:" << neiRegion
5071 DynamicList<label> startFaces;
5074 if (ownPatch[facei] != -1)
5076 startFaces.append(facei);
5082 autoPtr<mapDistribute> mapPtr;
5086 bitSet(mesh_.nFaces()),
5094 labelList startOwnPatch(ownPatch, startFaces);
5095 mapPtr().distribute(startOwnPatch);
5097 nearestOwnPatch.setSize(mesh_.nFaces());
5098 nearestOwnPatch = -1;
5099 forAll(faceToStart, facei)
5101 const label sloti = faceToStart[facei];
5104 nearestOwnPatch[facei] = startOwnPatch[sloti];
5118 bitSet isFrozenPoint(mesh_.nPoints());
5119 bitSet isFrozenFace(mesh_.nFaces());
5125 const label pointZonei = pzs.
findZoneID(
"frozenPoints");
5126 if (pointZonei != -1)
5128 const pointZone& pz = pzs[pointZonei];
5129 isFrozenPoint.set(pz);
5130 for (
const label pointi : pz)
5132 isFrozenFace.set(pointFaces[pointi]);
5137 const label faceZonei = fzs.
findZoneID(
"frozenFaces");
5138 if (faceZonei != -1)
5140 const faceZone& fz = fzs[faceZonei];
5141 isFrozenFace.set(fz);
5142 for (
const label facei : fz)
5144 isFrozenPoint.set(mesh_.faces()[facei]);
5150 label defaultPatch = 0;
5151 if (globalToMasterPatch.
size())
5153 defaultPatch = globalToMasterPatch[0];
5156 for (label i = 0; i < nBufferLayers; i++)
5160 labelList pointBaffle(mesh_.nPoints(), -1);
5162 forAll(faceNeighbour, facei)
5164 if (!isFrozenFace[facei])
5166 const face&
f = mesh_.faces()[facei];
5168 const label ownRegion = cellRegion[faceOwner[facei]];
5169 const label neiRegion = cellRegion[faceNeighbour[facei]];
5171 if (ownRegion == -1 && neiRegion != -1)
5178 if (!isFrozenPoint[
f[fp]])
5180 pointBaffle[
f[fp]] =
5181 max(defaultPatch, ownPatch[facei]);
5185 else if (ownRegion != -1 && neiRegion == -1)
5187 label newPatchi = neiPatch[facei];
5188 if (newPatchi == -1)
5190 newPatchi =
max(defaultPatch, ownPatch[facei]);
5194 if (!isFrozenPoint[
f[fp]])
5196 pointBaffle[
f[fp]] = newPatchi;
5235 const auto&
patches = mesh_.boundaryMesh();
5247 const label facei =
pp.start()+i;
5248 if (!isFrozenFace[facei])
5250 const face&
f = mesh_.faces()[facei];
5251 const label ownRegion = cellRegion[faceOwner[facei]];
5252 const label neiRegion =
5253 neiCellRegion[facei-mesh_.nInternalFaces()];
5257 if (ownRegion == -1 && neiRegion != -1)
5261 if (!isFrozenPoint[
f[fp]])
5263 pointBaffle[
f[fp]] =
5264 max(defaultPatch, ownPatch[facei]);
5268 else if (ownRegion != -1 && neiRegion == -1)
5270 label newPatchI = neiPatch[facei];
5271 if (newPatchI == -1)
5273 newPatchI =
max(defaultPatch, ownPatch[facei]);
5277 if (!isFrozenPoint[
f[fp]])
5279 pointBaffle[
f[fp]] = newPatchI;
5290 const label facei =
pp.start()+i;
5291 if (!isFrozenFace[facei])
5293 const face&
f = mesh_.faces()[facei];
5294 const label ownRegion = cellRegion[faceOwner[facei]];
5296 if (ownRegion != -1)
5300 if (!isFrozenPoint[
f[fp]])
5302 pointBaffle[
f[fp]] =
5303 max(defaultPatch, ownPatch[facei]);
5327 forAll(pointFaces, pointi)
5329 if (pointBaffle[pointi] != -1)
5335 const label facei =
pFaces[pFacei];
5337 if (!isFrozenFace[facei] && ownPatch[facei] == -1)
5339 ownPatch[facei] = pointBaffle[pointi];
5353 if (!isFrozenFace[facei] && ownPatch[facei] != -1)
5355 const label own = faceOwner[facei];
5357 if (cellRegion[own] == -1)
5361 const cell& ownFaces = mesh_.cells()[own];
5364 const label ownFacei = ownFaces[j];
5365 if (!isFrozenFace[ownFacei] && ownPatch[ownFacei] == -1)
5367 newOwnPatch[ownFacei] = ownPatch[facei];
5371 if (mesh_.isInternalFace(facei))
5373 const label nei = faceNeighbour[facei];
5375 if (cellRegion[nei] == -1)
5379 const cell& neiFaces = mesh_.cells()[nei];
5382 const label neiFacei = neiFaces[j];
5383 const bool isFrozen = isFrozenFace[neiFacei];
5384 if (!isFrozen && ownPatch[neiFacei] == -1)
5386 newOwnPatch[neiFacei] = ownPatch[facei];
5404 DynamicList<label> cellsToRemove(mesh_.nCells());
5405 forAll(cellRegion, celli)
5407 if (cellRegion[celli] == -1)
5409 cellsToRemove.append(celli);
5412 cellsToRemove.shrink();
5416 mesh_.nCells() - cellsToRemove.size(),
5420 Info<<
"Keeping all cells containing inside points" <<
endl 5421 <<
"Selected for keeping : " << nCellsToKeep <<
" cells." <<
endl;
5425 removeCells cellRemover(mesh_);
5428 const labelList exposedFaces(cellRemover.getExposedFaces(cellsToRemove));
5429 labelList exposedPatches(exposedFaces.size());
5431 label nUnpatched = 0;
5435 label facei = exposedFaces[i];
5437 if (ownPatch[facei] != -1)
5439 exposedPatches[i] = ownPatch[facei];
5443 const label fallbackPatch =
5445 nearestOwnPatch.size()
5446 ? nearestOwnPatch[facei]
5449 if (nUnpatched == 0)
5452 <<
"For exposed face " << facei
5453 <<
" fc:" << mesh_.faceCentres()[facei]
5454 <<
" found no patch." <<
endl 5455 <<
" Taking patch " << fallbackPatch
5456 <<
" instead. Suppressing future warnings" <<
endl;
5460 exposedPatches[i] = fallbackPatch;
5464 reduce(nUnpatched, sumOp<label>());
5467 Info<<
"Detected " << nUnpatched <<
" faces out of " 5469 <<
" for which the default patch " << defaultPatch
5470 <<
" will be used" <<
endl;
5473 return doRemoveCells
5485 const label nBufferLayers,
5486 const label nErodeCellZones,
5498 labelList neiLevel(mesh_.nBoundaryFaces());
5500 calcNeighbourData(neiLevel, neiCc);
5508 globalToMasterPatch,
5512 locationsOutsideMesh,
5528 limitShells_.findLevel
5530 mesh_.cellCentres(),
5534 forAll(levelShell, celli)
5536 if (levelShell[celli] != -1)
5539 cellRegion[celli] = -1;
5546 globalToMasterPatch,
5555 const_cast<Time&
>(mesh_.time())++;
5556 Pout<<
"Writing mesh after removing limitShells" 5587 Info<<
"dupNonManifoldPoints : Found : " << nNonManifPoints
5588 <<
" non-manifold points (out of " 5589 << mesh_.globalData().nTotalPoints()
5595 if (nNonManifPoints)
5605 mesh_.moving(
false);
5608 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
5612 mesh_.updateMesh(map);
5651 label nPointPairs = 0;
5652 forAll(pointToDuplicate, pointI)
5654 label otherPointI = pointToDuplicate[pointI];
5655 if (otherPointI != -1)
5666 forAll(pointToDuplicate, pointI)
5668 label otherPointI = pointToDuplicate[pointI];
5669 if (otherPointI != -1)
5672 pointToMaster.
insert(pointI, otherPointI);
5684 mesh_.moving(
false);
5687 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
5691 mesh_.updateMesh(map);
5738 internalOrBaffleFaceZones = getZones(fzTypes);
5748 forAll(boundaryFaceZones, j)
5750 const faceZone& fZone = mesh_.faceZones()[boundaryFaceZones[j]];
5753 const face&
f = mesh_.faces()[fZone[i]];
5756 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 1u);
5760 forAll(internalOrBaffleFaceZones, j)
5762 const faceZone& fZone = mesh_.faceZones()[internalOrBaffleFaceZones[j]];
5765 const face&
f = mesh_.faces()[fZone[i]];
5768 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 2u);
5783 forAll(pointStatus, pointI)
5785 if (pointStatus[pointI] == 1u)
5792 Info<<
"Duplicating " << globalNPoints <<
" points on" 5793 <<
" faceZones of type " 5803 forAll(pointStatus, pointI)
5805 if (pointStatus[pointI] == 1u)
5807 candidatePoints[
n++] = pointI;
5820 const bool allowFreeStandingZoneFaces,
5821 const label nErodeCellZones,
5825 const bool exitIfLeakPath,
5831 if (locationsInMesh.
size() != zonesInMesh.
size())
5841 labelList neiLevel(mesh_.nBoundaryFaces());
5843 calcNeighbourData(neiLevel, neiCc);
5852 if (namedSurfaces.
size())
5854 Info<<
"Setting cellZones according to named surfaces:" <<
endl;
5857 label surfI = namedSurfaces[i];
5859 Info<<
"Surface : " << surfaces_.names()[surfI] <<
nl 5860 <<
" faceZones : " << surfZones[surfI].faceZoneNames() <<
nl 5861 <<
" cellZone : " << surfZones[surfI].cellZoneName()
5902 allowFreeStandingZoneFaces,
5907 locationsOutsideMesh,
5925 labelList faceToZone(mesh_.nFaces(), -1);
5927 forAll(namedSurfaceRegion, faceI)
5930 label globalI = namedSurfaceRegion[faceI];
5933 const labelPair spr = surfaces_.whichSurface(globalI);
5934 faceToZone[faceI] = surfaceToFaceZones[spr.
first()][spr.
second()];
5948 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
5950 if (faceToZone[faceI] == -1)
5955 allocateInterRegionFaceZone
5957 cellToZone[mesh_.faceOwner()[faceI]],
5958 cellToZone[mesh_.faceNeighbour()[faceI]],
5968 forAll(neiCellZone, bFaceI)
5970 label faceI = bFaceI + mesh_.nInternalFaces();
5971 if (faceToZone[faceI] == -1)
5973 allocateInterRegionFaceZone
5975 cellToZone[mesh_.faceOwner()[faceI]],
5976 neiCellZone[bFaceI],
5994 Info<<
"Setting faceZones according to neighbouring cellZones:" 6008 const word& fzName = zonesToFaceZone[cz];
6011 << cz[0] <<
' ' << cz[1] <<
nl 6012 <<
" faceZone : " << fzName <<
endl;
6022 label cz0 = cellZones.findZoneID(cz[0]);
6023 label cz1 = cellZones.findZoneID(cz[1]);
6033 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
6035 if (faceToZone[faceI] == -1)
6041 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
6042 label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
6043 if (ownZone != neiZone)
6048 || (neiZone != -1 && ownZone > neiZone)
6055 faceToZone[faceI] = fZoneLookup[
key];
6059 forAll(neiCellZone, bFaceI)
6061 label faceI = bFaceI + mesh_.nInternalFaces();
6062 if (faceToZone[faceI] == -1)
6064 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
6065 label neiZone = neiCellZone[bFaceI];
6066 if (ownZone != neiZone)
6071 || (neiZone != -1 && ownZone > neiZone)
6078 faceToZone[faceI] = fZoneLookup[
key];
6097 label bFaceI =
pp.start()-mesh_.nInternalFaces();
6100 neiCellZone[bFaceI++] = -1;
6121 bitSet meshFlipMap(mesh_.nFaces(),
false);
6129 freeStandingBaffleFaces
6140 if (nFreeStanding > 0)
6142 Info<<
"Detected " << nFreeStanding <<
" free-standing zone faces" 6147 OBJstream str(mesh_.time().path()/
"freeStanding.obj");
6148 Pout<<
"meshRefinement::zonify : dumping faceZone faces to " 6156 calcPatchNumMasterFaces(isMasterFace,
patch, nMasterFacesPerEdge);
6161 const label nZones = markPatchZones
6164 nMasterFacesPerEdge,
6169 for (label zoneI = 0; zoneI < nZones; zoneI++)
6171 nPosOrientation.
insert(zoneI, 0);
6177 consistentOrientation
6181 nMasterFacesPerEdge,
6182 faceToConnectedZone,
6192 label meshFaceI =
patch.addressing()[faceI];
6194 if (isMasterFace.
test(meshFaceI))
6199 posOrientation.
test(meshFaceI)
6200 == meshFlipMap.test(meshFaceI)
6206 nPosOrientation.
find(faceToConnectedZone[faceI])() +=
n;
6212 Info<<
"Split " << nFreeStanding <<
" free-standing zone faces" 6213 <<
" into " << nZones <<
" disconnected regions with size" 6214 <<
" (negative denotes wrong orientation) :" 6217 for (label zoneI = 0; zoneI < nZones; zoneI++)
6219 Info<<
" " << zoneI <<
"\t" << nPosOrientation[zoneI]
6227 consistentOrientation
6231 nMasterFacesPerEdge,
6232 faceToConnectedZone,
6259 mesh_.moving(
false);
6265 mesh_.updateMesh(map());
6268 if (map().hasMotionPoints())
6270 mesh_.movePoints(map().preMotionPoints());
6282 if (mesh_.cellZones().size() > 0)
6285 forAll(mesh_.cellZones(), zoneI)
6287 const cellZone& cz = mesh_.cellZones()[zoneI];
6294 if (mesh_.faceZones().size() > 0)
6297 forAll(mesh_.faceZones(), zoneI)
6299 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
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1)
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.
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
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.
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)
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
List< labelList > labelListList
List of labelList.
DynamicID< faceZoneMesh > faceZoneID
Foam::faceZoneID.
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.
#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...
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
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.
label size() const noexcept
The number of entries in the list.
const Field< point_type > & faceCentres() const
Return face centres for patch.
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.
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.
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)
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 additional search methods and registered IO...
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.
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type test(const label i) const
Test bool value at specified position, always false for out-of-range access.
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];} label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;} } 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};const 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< SLList< face > > pFaces[nBCs]
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.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::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.
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.
static void mapCombineReduce(Container &values, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine map values from different processo...
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
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.
void reduce(T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) using linear/tree communication schedule.
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)
static void listCombineReduce(List< T > &values, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Combines List elements. After completion all processors have the same data.
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)