63 Foam::label Foam::meshRefinement::createBaffle
68 polyTopoChange& meshMod
71 const face&
f = mesh_.
faces()[faceI];
73 bool zoneFlip =
false;
78 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
105 <<
"No neighbour patch for internal face " << faceI
110 bool reverseFlip =
false;
113 reverseFlip = !zoneFlip;
116 dupFaceI = meshMod.setAction
176 void Foam::meshRefinement::getIntersections
186 autoPtr<OBJstream> str;
187 if (
debug&OBJINTERSECTIONS)
194 mesh_.time().path()/
timeName()/
"intersections.obj"
198 Pout<<
"getIntersections : Writing surface intersections to file "
203 globalRegion1.setSize(mesh_.nFaces());
205 globalRegion2.setSize(mesh_.nFaces());
233 List<pointIndexHit> hit1;
236 List<pointIndexHit> hit2;
238 surfaces_.findNearestIntersection
256 label faceI = testFaces[i];
258 if (hit1[i].hit() && hit2[i].hit())
262 str().write(
linePointRef(start[i], hit1[i].rawPoint()));
271 globalRegion1[faceI] =
272 surfaces_.globalRegion(surface1[i], region1[i]);
273 globalRegion2[faceI] =
274 surfaces_.globalRegion(surface2[i], region2[i]);
276 if (globalRegion1[faceI] == -1 || globalRegion2[faceI] == -1)
286 void Foam::meshRefinement::getBafflePatches
288 const label nErodeCellZones,
315 bitSet posOrientation;
342 ownPatch.setSize(mesh_.nFaces());
344 neiPatch.setSize(mesh_.nFaces());
349 if (unnamedRegion1[faceI] != -1 || unnamedRegion2[faceI] != -1)
351 label ownMasterPatch = -1;
352 if (unnamedRegion1[faceI] != -1)
354 ownMasterPatch = globalToMasterPatch[unnamedRegion1[faceI]];
356 label neiMasterPatch = -1;
357 if (unnamedRegion2[faceI] != -1)
359 neiMasterPatch = globalToMasterPatch[unnamedRegion2[faceI]];
366 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
369 if (mesh_.isInternalFace(faceI))
371 neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
375 neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
383 (ownZone >= 0 && neiZone != -2)
384 || (neiZone >= 0 && ownZone != -2)
387 namedSurfaceRegion.size() == 0
388 || namedSurfaceRegion[faceI] == -1
399 ownPatch[faceI] = ownMasterPatch;
400 neiPatch[faceI] = neiMasterPatch;
420 const bool allowBoundary,
425 Map<labelPair> bafflePatch(mesh_.nFaces()/1000);
427 const PtrList<surfaceZonesInfo>& surfZones = surfaces_.surfZones();
432 const wordList& faceZoneNames = surfZones[surfI].faceZoneNames();
434 forAll(faceZoneNames, fzi)
437 const word& faceZoneName = faceZoneNames[fzi];
438 label zoneI = fZones.findZoneID(faceZoneName);
439 const faceZone& fZone = fZones[zoneI];
442 label globalRegionI = surfaces_.globalRegion(surfI, fzi);
445 globalToMasterPatch[globalRegionI],
446 globalToSlavePatch[globalRegionI]
449 Info<<
"For zone " << fZone.name() <<
" found patches "
450 << mesh_.boundaryMesh()[zPatches[0]].name() <<
" and "
451 << mesh_.boundaryMesh()[zPatches[1]].name()
456 label faceI = fZone[i];
458 if (allowBoundary || mesh_.isInternalFace(faceI))
461 if (fZone.flipMap()[i])
466 if (!bafflePatch.insert(faceI,
patches))
470 <<
" fc:" << mesh_.faceCentres()[faceI]
471 <<
" in zone " << fZone.name()
472 <<
" is in multiple zones!"
491 ownPatch.size() != mesh_.nFaces()
492 || neiPatch.size() != mesh_.nFaces()
497 <<
" ownPatch:" << ownPatch.size()
498 <<
" neiPatch:" << neiPatch.size()
499 <<
". Should be number of faces:" << mesh_.nFaces()
510 forAll(syncedOwnPatch, faceI)
514 (ownPatch[faceI] == -1 && syncedOwnPatch[faceI] != -1)
515 || (neiPatch[faceI] == -1 && syncedNeiPatch[faceI] != -1)
519 <<
"Non synchronised at face:" << faceI
520 <<
" on patch:" << mesh_.boundaryMesh().whichPatch(faceI)
521 <<
" fc:" << mesh_.faceCentres()[faceI] <<
endl
522 <<
"ownPatch:" << ownPatch[faceI]
523 <<
" syncedOwnPatch:" << syncedOwnPatch[faceI]
524 <<
" neiPatch:" << neiPatch[faceI]
525 <<
" syncedNeiPatch:" << syncedNeiPatch[faceI]
536 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
538 if (ownPatch[faceI] != -1)
558 label coupledPatchI = -1;
562 && !refCast<const coupledPolyPatch>(pp).separated()
565 coupledPatchI = patchI;
570 label faceI = pp.
start()+i;
572 if (ownPatch[faceI] != -1)
582 if (coupledPatchI != -1)
584 faceToCoupledPatch_.insert(faceI, coupledPatchI);
597 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
601 mesh_.updateMesh(map);
620 faceSet baffledFacesSet(mesh_,
"baffledFacesSet", 2*nBaffles);
626 forAll(ownPatch, oldFaceI)
628 label faceI = reverseFaceMap[oldFaceI];
630 if (ownPatch[oldFaceI] != -1 && faceI >= 0)
632 const cell& ownFaces = mesh_.cells()[mesh_.faceOwner()[faceI]];
634 baffledFacesSet.
insert(ownFaces);
640 label oldFaceI =
faceMap[faceI];
642 if (oldFaceI >= 0 && reverseFaceMap[oldFaceI] != faceI)
644 const cell& ownFaces = mesh_.cells()[mesh_.faceOwner()[faceI]];
646 baffledFacesSet.
insert(ownFaces);
649 baffledFacesSet.
sync(mesh_);
651 updateMesh(map, baffledFacesSet.toc());
669 const faceZone& fZone = faceZones[zoneI];
673 bool hasInfo = getFaceZoneInfo(fZone.
name(), mpI, spI, fzType);
675 if (hasInfo && fzTypes.found(fzType))
708 if (faceToZone[
p[0]] != -1 && (faceToZone[
p[0]] == faceToZone[
p[1]]))
730 ownPatch.
setSize(mesh_.nFaces());
732 neiPatch.
setSize(mesh_.nFaces());
742 const faceZone& fz = faceZones[zoneI];
743 const word& masterName = faceZoneToMasterPatch_[fz.
name()];
744 label masterPatchI = mesh_.boundaryMesh().findPatchID(masterName);
745 const word& slaveName = faceZoneToSlavePatch_[fz.
name()];
746 label slavePatchI = mesh_.boundaryMesh().findPatchID(slaveName);
748 if (masterPatchI == -1 || slavePatchI == -1)
751 <<
"Problem: masterPatchI:" << masterPatchI
758 if (mesh_.isInternalFace(faceI))
762 ownPatch[faceI] = slavePatchI;
763 neiPatch[faceI] = masterPatchI;
767 ownPatch[faceI] = masterPatchI;
768 neiPatch[faceI] = slavePatchI;
793 Info<<
"Converting zoned faces into baffles ..." <<
endl;
802 label nLocalBaffles =
sum(nBaffles);
807 if (nTotalBaffles > 0)
813 <<
setf(ios_base::left)
814 <<
setw(30) <<
"FaceZone"
815 <<
setw(10) <<
"FaceType"
816 <<
setw(10) <<
"nBaffles"
818 <<
setw(30) <<
"--------"
819 <<
setw(10) <<
"--------"
820 <<
setw(10) <<
"--------"
826 const faceZone& fz = faceZones[zoneI];
830 bool hasInfo = getFaceZoneInfo(fz.
name(), mpI, spI, fzType);
838 <<
setw(10) << nBaffles[j]
845 map = createBaffles(ownPatch, neiPatch);
851 baffles.
setSize(nLocalBaffles);
852 originatingFaceZone.
setSize(nLocalBaffles);
856 const labelList& reverseFaceMap = map().reverseFaceMap();
860 label faceI = mesh_.nInternalFaces();
861 faceI < mesh_.nFaces();
865 label oldFaceI =
faceMap[faceI];
866 label masterFaceI = reverseFaceMap[oldFaceI];
867 if (masterFaceI != faceI && ownPatch[oldFaceI] != -1)
869 baffles[baffleI] =
labelPair(masterFaceI, faceI);
870 originatingFaceZone[baffleI] =
faceZoneID[oldFaceI];
875 if (baffleI != baffles.size())
878 <<
"Had " << baffles.size() <<
" baffles to create "
879 <<
" but encountered " << baffleI
880 <<
" slave faces originating from patcheable faces."
886 const_cast<Time&
>(mesh_.time())++;
887 Pout<<
"Writing zone-baffled mesh to time " <<
timeName()
893 mesh_.time().path()/
"baffles"
897 Info<<
"Created " << nTotalBaffles <<
" baffles in = "
898 << mesh_.time().cpuTimeIncrement() <<
" s\n" <<
nl <<
endl;
903 originatingFaceZone.
clear();
913 const scalar planarAngle
940 const label baffleValue = 1000000;
955 label faceI = pp.
start();
959 const labelList& fEdges = mesh_.faceEdges(faceI);
963 nBafflesPerEdge[fEdges[fEdgeI]]++;
971 DynamicList<label> fe0;
972 DynamicList<label> fe1;
981 label f0 = couples[i].first();
982 const labelList& fEdges0 = mesh_.faceEdges(f0, fe0);
985 nBafflesPerEdge[fEdges0[fEdgeI]] += baffleValue;
990 label f1 = couples[i].second();
991 const labelList& fEdges1 = mesh_.faceEdges(f1, fe1);
994 nBafflesPerEdge[fEdges1[fEdgeI]] += baffleValue;
1013 List<labelPair> filteredCouples(couples.size());
1026 const labelList& fEdges = mesh_.faceEdges(couple.first());
1030 label edgeI = fEdges[fEdgeI];
1032 if (nBafflesPerEdge[edgeI] == 2*baffleValue+2*1)
1034 filteredCouples[filterI++] = couple;
1040 filteredCouples.setSize(filterI);
1043 label nFiltered =
returnReduce(filteredCouples.size(), sumOp<label>());
1045 Info<<
"freeStandingBaffles : detected "
1047 <<
" free-standing baffles out of "
1060 const pointField& cellCentres = mesh_.cellCentres();
1062 forAll(filteredCouples, i)
1064 const labelPair& couple = filteredCouples[i];
1065 start[i] = cellCentres[mesh_.faceOwner()[couple.first()]];
1066 end[i] = cellCentres[mesh_.faceOwner()[couple.second()]];
1080 List<pointIndexHit> hit1;
1085 List<pointIndexHit> hit2;
1089 surfaces_.findNearestIntersection
1091 identity(surfaces_.surfaces().size()),
1115 forAll(filteredCouples, i)
1117 const labelPair& couple = filteredCouples[i];
1131 &&
mag(hit1[i].hitPoint()-hit2[i].hitPoint()) > mergeDistance_
1142 if ((normal1[i]&normal2[i]) > planarAngleCos)
1146 scalar magN =
mag(
n);
1149 filteredCouples[filterI++] = couple;
1153 else if (hit1[i].hit() || hit2[i].hit())
1159 filteredCouples.setSize(filterI);
1161 Info<<
"freeStandingBaffles : detected "
1163 <<
" planar (within " << planarAngle
1164 <<
" degrees) free-standing baffles out of "
1169 return filteredCouples;
1186 const faceList& faces = mesh_.faces();
1187 const labelList& faceOwner = mesh_.faceOwner();
1192 label face0 = couples[i].first();
1193 label face1 = couples[i].second();
1198 label own0 = faceOwner[face0];
1199 label own1 = faceOwner[face1];
1201 if (face1 < 0 || own0 < own1)
1205 bool zoneFlip =
false;
1213 label nei = (face1 < 0 ? -1 : own1);
1236 bool zoneFlip =
false;
1265 const label faceI = iter.key();
1266 const label patchI = iter.val();
1268 if (!mesh_.isInternalFace(faceI))
1271 <<
"problem: face:" << faceI
1272 <<
" at:" << mesh_.faceCentres()[faceI]
1273 <<
"(wanted patch:" << patchI
1278 bool zoneFlip =
false;
1305 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
1309 mesh_.updateMesh(map);
1328 labelList newExposedFaces(2*couples.size());
1336 newExposedFaces[newI++] = newFace0;
1339 const label newFace1 = map.
reverseFaceMap()[couples[i].second()];
1342 newExposedFaces[newI++] = newFace1;
1345 newExposedFaces.
setSize(newI);
1346 updateMesh(map, newExposedFaces);
1355 const bool doInternalZones,
1356 const bool doBaffleZones
1362 if (doInternalZones)
1386 mapPtr = mergeBaffles(zoneBaffles,
Map<label>(0));
1393 void Foam::meshRefinement::findCellZoneGeometric
1403 const pointField& cellCentres = mesh_.cellCentres();
1404 const labelList& faceOwner = mesh_.faceOwner();
1405 const labelList& faceNeighbour = mesh_.faceNeighbour();
1409 surfaces_.findInside
1411 closedNamedSurfaces,
1416 forAll(insideSurfaces, cellI)
1418 label surfI = insideSurfaces[cellI];
1422 if (cellToZone[cellI] == -2)
1424 cellToZone[cellI] = surfaceToCellZone[surfI];
1426 else if (cellToZone[cellI] == -1)
1431 cellToZone[cellI] = surfaceToCellZone[surfI];
1444 label nCandidates = 0;
1445 forAll(namedSurfaceRegion, faceI)
1447 if (namedSurfaceRegion[faceI] != -1)
1449 if (mesh_.isInternalFace(faceI))
1463 forAll(namedSurfaceRegion, faceI)
1465 if (namedSurfaceRegion[faceI] != -1)
1467 label own = faceOwner[faceI];
1468 const point& ownCc = cellCentres[own];
1470 if (mesh_.isInternalFace(faceI))
1472 label nei = faceNeighbour[faceI];
1473 const point& neiCc = cellCentres[nei];
1475 const vector d = 1
e-4*(neiCc - ownCc);
1476 candidatePoints[nCandidates++] = ownCc-d;
1477 candidatePoints[nCandidates++] = neiCc+d;
1482 const point& neiFc = neiCc[faceI-mesh_.nInternalFaces()];
1485 const vector d = 1
e-4*(neiFc - ownCc);
1486 candidatePoints[nCandidates++] = ownCc-d;
1494 surfaces_.findInside
1496 closedNamedSurfaces,
1505 forAll(namedSurfaceRegion, faceI)
1507 if (namedSurfaceRegion[faceI] != -1)
1509 label own = faceOwner[faceI];
1511 if (mesh_.isInternalFace(faceI))
1513 label ownSurfI = insideSurfaces[nCandidates++];
1516 cellToZone[own] = surfaceToCellZone[ownSurfI];
1519 label neiSurfI = insideSurfaces[nCandidates++];
1522 label nei = faceNeighbour[faceI];
1524 cellToZone[nei] = surfaceToCellZone[neiSurfI];
1529 label ownSurfI = insideSurfaces[nCandidates++];
1532 cellToZone[own] = surfaceToCellZone[ownSurfI];
1543 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
1545 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
1546 label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
1548 if (namedSurfaceRegion[faceI] == -1 && (ownZone != neiZone))
1558 else if (neiZone == -1)
1564 minZone =
min(ownZone, neiZone);
1569 label geomSurfI = surfaceToCellZone.find(minZone);
1571 if (geomSurfI != -1)
1573 namedSurfaceRegion[faceI] =
1574 surfaces_.globalRegion(geomSurfI, 0);
1582 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
1586 const polyPatch& pp =
patches[patchI];
1592 label faceI = pp.start()+i;
1593 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
1594 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
1596 if (namedSurfaceRegion[faceI] == -1 && (ownZone != neiZone))
1604 else if (neiZone == -1)
1610 minZone =
min(ownZone, neiZone);
1615 label geomSurfI = surfaceToCellZone.find(minZone);
1617 if (geomSurfI != -1)
1619 namedSurfaceRegion[faceI] =
1620 surfaces_.globalRegion(geomSurfI, 0);
1632 void Foam::meshRefinement::findCellZoneInsideWalk
1642 boolList blockedFace(mesh_.nFaces());
1645 forAll(blockedFace, faceI)
1647 if (faceToZone[faceI] == -1)
1649 blockedFace[faceI] =
false;
1653 blockedFace[faceI] =
true;
1659 regionSplit cellRegion(mesh_, blockedFace);
1660 blockedFace.clear();
1663 (void)mesh_.tetBasePtIs();
1666 forAll(locationsInMesh, i)
1669 const point& insidePoint = locationsInMesh[i];
1670 label
zoneID = zonesInMesh[i];
1673 label keepRegionI = findRegion
1681 Info<<
"For cellZone "
1687 <<
" found point " << insidePoint
1688 <<
" in global region " << keepRegionI
1689 <<
" out of " << cellRegion.nRegions() <<
" regions." <<
endl;
1691 if (keepRegionI == -1)
1694 <<
"Point " << insidePoint
1695 <<
" is not inside the mesh." <<
nl
1696 <<
"Bounding box of the mesh:" << mesh_.bounds()
1705 label nWarnings = 0;
1707 forAll(cellRegion, cellI)
1709 if (cellRegion[cellI] == keepRegionI)
1711 if (cellToZone[cellI] == -2)
1714 cellToZone[cellI] =
zoneID;
1716 else if (cellToZone[cellI] !=
zoneID)
1718 if (cellToZone[cellI] != -1 && nWarnings < 10)
1722 <<
" at " << mesh_.cellCentres()[cellI]
1723 <<
" is inside cellZone "
1729 <<
" from locationInMesh " << insidePoint
1730 <<
" but already marked as being in zone "
1731 << mesh_.cellZones()[cellToZone[cellI]].name()
1733 <<
"This can happen if your surfaces are not"
1734 <<
" (sufficiently) closed."
1740 cellToZone[cellI] =
zoneID;
1748 void Foam::meshRefinement::findCellZoneInsideWalk
1760 forAll(zoneNamesInMesh, i)
1762 zoneIDs[i] = czs.findZoneID(zoneNamesInMesh[i]);
1764 findCellZoneInsideWalk
1774 bool Foam::meshRefinement::calcRegionToZone
1776 const label backgroundZoneID,
1777 const label surfZoneI,
1778 const label ownRegion,
1779 const label neiRegion,
1784 bool changed =
false;
1787 if (ownRegion != neiRegion)
1794 if (regionToCellZone[ownRegion] == -2)
1796 if (surfZoneI == -1)
1801 if (regionToCellZone[neiRegion] != -2)
1803 regionToCellZone[ownRegion] = regionToCellZone[neiRegion];
1807 else if (regionToCellZone[neiRegion] == surfZoneI)
1812 if (backgroundZoneID != -2)
1814 regionToCellZone[ownRegion] = backgroundZoneID;
1818 else if (regionToCellZone[neiRegion] != -2)
1822 regionToCellZone[ownRegion] = surfZoneI;
1826 else if (regionToCellZone[neiRegion] == -2)
1828 if (surfZoneI == -1)
1833 regionToCellZone[neiRegion] = regionToCellZone[ownRegion];
1836 else if (regionToCellZone[ownRegion] == surfZoneI)
1840 if (backgroundZoneID != -2)
1842 regionToCellZone[neiRegion] = backgroundZoneID;
1846 else if (regionToCellZone[ownRegion] != -2)
1850 regionToCellZone[neiRegion] = surfZoneI;
1859 void Foam::meshRefinement::findCellZoneTopo
1861 const label backgroundZoneID,
1890 boolList blockedFace(mesh_.nFaces());
1892 forAll(unnamedSurfaceRegion, faceI)
1896 unnamedSurfaceRegion[faceI] == -1
1897 && namedSurfaceRegion[faceI] == -1
1900 blockedFace[faceI] =
false;
1904 blockedFace[faceI] =
true;
1910 regionSplit cellRegion(mesh_, blockedFace);
1911 blockedFace.clear();
1917 labelList regionToCellZone(cellRegion.nRegions(), -2);
1922 forAll(cellToZone, cellI)
1924 label regionI = cellRegion[cellI];
1925 if (cellToZone[cellI] != -2 && regionToCellZone[regionI] == -2)
1927 regionToCellZone[regionI] = cellToZone[cellI];
1941 forAll(locationsInMesh, i)
1943 const point& keepPoint = locationsInMesh[i];
1944 label keepRegionI = findRegion
1952 Info<<
"Found point " << keepPoint
1953 <<
" in global region " << keepRegionI
1954 <<
" out of " << cellRegion.nRegions() <<
" regions." <<
endl;
1956 if (keepRegionI == -1)
1959 <<
"Point " << keepPoint
1960 <<
" is not inside the mesh." <<
nl
1961 <<
"Bounding box of the mesh:" << mesh_.bounds()
1969 if (regionToCellZone[keepRegionI] == -2)
1971 regionToCellZone[keepRegionI] = -1;
1991 bool changed =
false;
1995 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
1997 label regionI = namedSurfaceRegion[faceI];
2000 if (unnamedSurfaceRegion[faceI] == -1 && regionI != -1)
2005 label surfI = surfaces_.whichSurface(regionI).first();
2007 bool changedCell = calcRegionToZone
2010 surfaceToCellZone[surfI],
2011 cellRegion[mesh_.faceOwner()[faceI]],
2012 cellRegion[mesh_.faceNeighbour()[faceI]],
2016 changed = changed | changedCell;
2022 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2032 const polyPatch& pp =
patches[patchI];
2038 label faceI = pp.start()+i;
2040 label regionI = namedSurfaceRegion[faceI];
2043 if (unnamedSurfaceRegion[faceI] == -1 && regionI != -1)
2045 label surfI = surfaces_.whichSurface(regionI).first();
2047 bool changedCell = calcRegionToZone
2050 surfaceToCellZone[surfI],
2051 cellRegion[mesh_.faceOwner()[faceI]],
2052 neiCellRegion[faceI-mesh_.nInternalFaces()],
2056 changed = changed | changedCell;
2071 Pout<<
"meshRefinement::findCellZoneTopo :"
2072 <<
" nRegions:" << regionToCellZone.size()
2073 <<
" of which visited (-1 = background, >= 0 : cellZone) :"
2076 forAll(regionToCellZone, regionI)
2078 if (regionToCellZone[regionI] != -2)
2080 Pout<<
"Region " << regionI
2081 <<
" becomes cellZone:" << regionToCellZone[regionI]
2088 forAll(cellToZone, cellI)
2090 label regionI = cellRegion[cellI];
2091 if (cellToZone[cellI] == -2 && regionToCellZone[regionI] != -2)
2093 cellToZone[cellI] = regionToCellZone[regionI];
2099 void Foam::meshRefinement::erodeCellZone
2101 const label nErodeCellZones,
2102 const label backgroundZoneID,
2119 for (label iter = 0; iter < nErodeCellZones; iter++)
2126 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
2130 unnamedSurfaceRegion[facei] == -1
2131 && namedSurfaceRegion[facei] == -1
2134 label own = mesh_.faceOwner()[facei];
2135 label nei = mesh_.faceNeighbour()[facei];
2136 if (cellToZone[own] == -2 && cellToZone[nei] >= -1)
2138 erodedCellToZone[nei] = backgroundZoneID;
2141 else if (cellToZone[nei] == -2 && cellToZone[own] >= -1)
2143 erodedCellToZone[own] = backgroundZoneID;
2151 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2161 const polyPatch& pp =
patches[patchi];
2167 label facei = pp.start()+i;
2170 unnamedSurfaceRegion[facei] == -1
2171 && namedSurfaceRegion[facei] == -1
2174 label own = mesh_.faceOwner()[facei];
2175 label bFacei = facei-mesh_.nInternalFaces();
2176 if (neiCellZone[bFacei] == -2 && cellToZone[own] >= -1)
2178 erodedCellToZone[own] = backgroundZoneID;
2186 cellToZone.transfer(erodedCellToZone);
2188 reduce(nChanged, sumOp<label>());
2191 Pout<<
"erodeCellZone : eroded " << nChanged
2192 <<
" cells (moved from cellZone to background zone "
2193 << backgroundZoneID <<
endl;
2204 void Foam::meshRefinement::growCellZone
2206 const label nGrowCellZones,
2207 const label backgroundZoneID,
2214 if (nGrowCellZones != 1)
2217 <<
"Growing currently only supported for single layer."
2218 <<
" Exiting zone growing" <<
endl;
2235 const FixedList<label, 3> wallTag
2245 List<FixedList<label, 3>> surfaces(1);
2265 List<wallPoints> allCellInfo(mesh_.nCells());
2266 forAll(cellToZone, celli)
2268 if (cellToZone[celli] >= 0)
2270 const FixedList<label, 3> zoneTag
2277 origins[0] = mesh_.cellCentres()[celli];
2279 surfaces[0] = zoneTag;
2280 allCellInfo[celli] = wallPoints(origins, distSqrs, surfaces);
2285 DynamicList<wallPoints> faceDist(mesh_.nFaces()/128);
2286 DynamicList<label> changedFaces(mesh_.nFaces()/128);
2288 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
2290 const label own = mesh_.faceOwner()[facei];
2291 const label nei = mesh_.faceNeighbour()[facei];
2292 if (cellToZone[own] >= 0 && cellToZone[nei] < 0)
2296 origins[0] = mesh_.faceCentres()[facei];
2298 surfaces[0] = FixedList<label, 3>
2304 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2305 changedFaces.append(facei);
2307 else if (cellToZone[own] < 0 && cellToZone[nei] >= 0)
2311 origins[0] = mesh_.faceCentres()[facei];
2313 surfaces[0] = FixedList<label, 3>
2319 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2320 changedFaces.append(facei);
2324 unnamedSurfaceRegion1[facei] != -1
2325 || unnamedSurfaceRegion2[facei] != -1
2330 origins[0] = mesh_.faceCentres()[facei];
2332 surfaces[0] = wallTag;
2333 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2334 changedFaces.append(facei);
2342 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2348 const polyPatch& pp =
patches[patchi];
2355 label facei = pp.start()+i;
2356 label own = mesh_.faceOwner()[facei];
2357 label bFacei = facei-mesh_.nInternalFaces();
2358 if (cellToZone[own] >= 0 && neiCellZone[bFacei] < 0)
2360 origins[0] = mesh_.faceCentres()[facei];
2362 surfaces[0] = FixedList<label, 3>
2368 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2369 changedFaces.append(facei);
2371 else if (cellToZone[own] < 0 && neiCellZone[bFacei] >= 0)
2377 unnamedSurfaceRegion1[facei] != -1
2378 || unnamedSurfaceRegion2[facei] != -1
2382 origins[0] = mesh_.faceCentres()[facei];
2384 surfaces[0] = wallTag;
2385 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2386 changedFaces.append(facei);
2395 label facei = pp.start()+i;
2396 label own = mesh_.faceOwner()[facei];
2397 if (cellToZone[own] < 0)
2399 origins[0] = mesh_.faceCentres()[facei];
2401 surfaces[0] = wallTag;
2402 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2403 changedFaces.append(facei);
2410 List<wallPoints> allFaceInfo(mesh_.nFaces());
2412 const bitSet isBlockedFace(mesh_.nFaces());
2413 wallPoints::trackData td(isBlockedFace);
2414 FaceCellWave<wallPoints, wallPoints::trackData> wallDistCalc
2424 wallDistCalc.iterate(nGrowCellZones);
2431 bitSet isChangedCell(mesh_.nCells());
2433 forAll(allCellInfo, celli)
2435 if (allCellInfo[celli].valid(wallDistCalc.data()))
2437 const List<FixedList<label, 3>>& surfaces =
2438 allCellInfo[celli].surface();
2440 if (surfaces.size())
2444 isChangedCell.set(celli);
2447 if (surfaces.size() > 1)
2453 for (label i = 0; i < surfaces.size(); i++)
2455 const label zonei = surfaces[i][0];
2456 const scalar d2 = allCellInfo[celli].distSqr()[i];
2457 if (zonei != cellToZone[celli] && d2 < minDistSqr)
2466 if (minZone != cellToZone[celli] && minZone != wallTag[0])
2468 cellToZone[celli] = minZone;
2469 isChangedCell.set(celli);
2477 if (backgroundZoneID != -2)
2479 forAll(cellToZone, celli)
2481 if (cellToZone[celli] == -2)
2483 cellToZone[celli] = backgroundZoneID;
2496 for (
const label celli : isChangedCell)
2498 const cell& cFaces = mesh_.cells()[celli];
2499 for (
const label facei : cFaces)
2501 const label own = mesh_.faceOwner()[facei];
2502 const label ownZone = cellToZone[own];
2505 if (mesh_.isInternalFace(facei))
2507 const label neiZone = cellToZone[mesh_.faceNeighbour()[facei]];
2508 nbrZone = (own != celli ? ownZone : neiZone);
2512 nbrZone = neiCellZone[facei-mesh_.nInternalFaces()];
2515 if (nbrZone == cellToZone[celli])
2519 unnamedSurfaceRegion1[facei] != -1
2520 || unnamedSurfaceRegion2[facei] != -1
2523 unnamedSurfaceRegion1[facei] = -1;
2524 unnamedSurfaceRegion2[facei] = -1;
2529 namedSurfaceRegion.size()
2530 && namedSurfaceRegion[facei] != -1
2533 namedSurfaceRegion[facei] = -1;
2540 reduce(nUnnamed, sumOp<label>());
2541 reduce(nNamed, sumOp<label>());
2547 unnamedSurfaceRegion1,
2553 unnamedSurfaceRegion2,
2556 if (namedSurfaceRegion.size())
2568 Pout<<
"growCellZone : grown cellZones by "
2570 <<
" cells (moved from background to nearest cellZone)"
2572 Pout<<
"growCellZone : unmarked " << nUnnamed
2573 <<
" unzoned intersections; " << nNamed <<
" zoned intersections; "
2579 void Foam::meshRefinement::makeConsistentFaceIndex
2594 const labelList& faceOwner = mesh_.faceOwner();
2595 const labelList& faceNeighbour = mesh_.faceNeighbour();
2597 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
2599 label ownZone = cellToZone[faceOwner[faceI]];
2600 label neiZone = cellToZone[faceNeighbour[faceI]];
2601 label globalI = namedSurfaceRegion[faceI];
2607 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2610 namedSurfaceRegion[faceI] = -1;
2614 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2623 const polyPatch& pp =
patches[patchI];
2629 label faceI = pp.start()+i;
2631 label ownZone = cellToZone[faceOwner[faceI]];
2632 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
2633 label globalI = namedSurfaceRegion[faceI];
2639 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2642 namedSurfaceRegion[faceI] = -1;
2651 label faceI = pp.start()+i;
2652 label globalI = namedSurfaceRegion[faceI];
2657 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2660 namedSurfaceRegion[faceI] = -1;
2668 void Foam::meshRefinement::getIntersections
2675 bitSet& posOrientation
2678 namedSurfaceRegion.setSize(mesh_.nFaces());
2679 namedSurfaceRegion = -1;
2681 posOrientation.setSize(mesh_.nFaces());
2682 posOrientation =
false;
2713 List<pointIndexHit> hit1;
2717 List<pointIndexHit> hit2;
2720 surfaces_.findNearestIntersection
2739 label faceI = testFaces[i];
2740 const vector&
area = mesh_.faceAreas()[faceI];
2742 if (surface1[i] != -1)
2749 magSqr(hit2[i].hitPoint())
2750 <
magSqr(hit1[i].hitPoint())
2754 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2759 posOrientation.
set(faceI, ((
area&normal2[i]) > 0));
2760 nSurfFaces[surface2[i]]++;
2764 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2769 posOrientation.set(faceI, ((
area&normal1[i]) > 0));
2770 nSurfFaces[surface1[i]]++;
2773 else if (surface2[i] != -1)
2775 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2780 posOrientation.set(faceI, ((
area&normal2[i]) > 0));
2781 nSurfFaces[surface2[i]]++;
2800 forAll(nSurfFaces, surfI)
2803 << surfaces_.names()[surfI]
2804 <<
" nZoneFaces:" << nSurfFaces[surfI] <<
nl;
2811 void Foam::meshRefinement::zonify
2813 const bool allowFreeStandingZoneFaces,
2814 const label nErodeCellZones,
2815 const label backgroundZoneID,
2823 bitSet& posOrientation
2836 const PtrList<surfaceZonesInfo>& surfZones = surfaces_.surfZones();
2839 labelList neiLevel(mesh_.nBoundaryFaces());
2841 calcNeighbourData(neiLevel, neiCc);
2849 if (namedSurfaces.size())
2861 cellToZone.setSize(mesh_.nCells());
2864 namedSurfaceRegion.clear();
2865 posOrientation.clear();
2882 if (namedSurfaces.size())
2898 if (locationsInMesh.size())
2900 Info<<
"Setting cellZones according to locationsInMesh:" <<
endl;
2902 labelList locationsZoneIDs(zonesInMesh.size(), -1);
2903 forAll(locationsInMesh, i)
2905 const word&
name = zonesInMesh[i];
2907 Info<<
"Location : " << locationsInMesh[i] <<
nl
2912 label
zoneID = mesh_.cellZones().findZoneID(
name);
2917 locationsZoneIDs[i] =
zoneID;
2924 findCellZoneInsideWalk
2941 if (locationSurfaces.size())
2943 Info<<
"Found " << locationSurfaces.size()
2944 <<
" named surfaces with a provided inside point."
2945 <<
" Assigning cells inside these surfaces"
2946 <<
" to the corresponding cellZone."
2951 labelList insidePointCellZoneIDs(locationSurfaces.size(), -1);
2952 forAll(locationSurfaces, i)
2954 label surfI = locationSurfaces[i];
2957 const word&
name = surfZones[surfI].cellZoneName();
2960 label
zoneID = mesh_.cellZones().findZoneID(
name);
2967 insidePointCellZoneIDs[i] =
zoneID;
2973 labelList allRegion1(mesh_.nFaces(), -1);
2974 forAll(namedSurfaceRegion, faceI)
2976 allRegion1[faceI] =
max
2978 unnamedRegion1[faceI],
2979 namedSurfaceRegion[faceI]
2983 findCellZoneInsideWalk
2986 insidePointCellZoneIDs,
3002 surfaces_.geometry(),
3003 surfaces_.surfaces()
3007 if (closedNamedSurfaces.size())
3009 Info<<
"Found " << closedNamedSurfaces.size()
3010 <<
" closed, named surfaces. Assigning cells in/outside"
3011 <<
" these surfaces to the corresponding cellZone."
3014 findCellZoneGeometric
3017 closedNamedSurfaces,
3028 if (namedSurfaces.size())
3030 if (nErodeCellZones == 0)
3032 Info<<
"Walking from known cellZones; crossing a faceZone "
3033 <<
"face changes cellZone" <<
nl <<
endl;
3046 else if (nErodeCellZones < 0)
3048 Info<<
"Growing cellZones by " << -nErodeCellZones
3049 <<
" layers" <<
nl <<
endl;
3063 Info<<
"Eroding cellZone cells to make these consistent with"
3064 <<
" faceZone faces" <<
nl <<
endl;
3080 if (!allowFreeStandingZoneFaces)
3082 Info<<
"Only keeping zone faces inbetween different cellZones."
3096 labelList surfaceMap(surfZones.size(), -1);
3097 forAll(standaloneNamedSurfaces, i)
3099 surfaceMap[standaloneNamedSurfaces[i]] = i;
3102 makeConsistentFaceIndex
3110 else if (nErodeCellZones < 0 &&
gMax(cellToZone) >= 0)
3115 Info<<
"Growing cellZones by " << -nErodeCellZones
3116 <<
" layers" <<
nl <<
endl;
3129 if (!allowFreeStandingZoneFaces && namedSurfaceRegion.size())
3131 Info<<
"Only keeping zone faces inbetween different cellZones."
3145 labelList surfaceMap(surfZones.size(), -1);
3146 forAll(standaloneNamedSurfaces, i)
3148 surfaceMap[standaloneNamedSurfaces[i]] = i;
3151 makeConsistentFaceIndex
3166 label nUnvisited = 0;
3167 label nBackgroundCells = 0;
3169 forAll(cellToZone, cellI)
3171 label zoneI = cellToZone[cellI];
3174 nZoneCells[zoneI]++;
3176 else if (zoneI == -1)
3180 else if (zoneI == -2)
3190 reduce(nUnvisited, sumOp<label>());
3191 reduce(nBackgroundCells, sumOp<label>());
3192 forAll(nZoneCells, zoneI)
3194 reduce(nZoneCells[zoneI], sumOp<label>());
3196 Info<<
"nUnvisited :" << nUnvisited <<
endl;
3197 Info<<
"nBackgroundCells:" << nBackgroundCells <<
endl;
3198 Info<<
"nZoneCells :" << nZoneCells <<
endl;
3202 const_cast<Time&
>(mesh_.time())++;
3203 Pout<<
"Writing cell zone allocation on mesh to time "
3208 writeType(writeLevel() | WRITEMESH),
3209 mesh_.time().path()/
"cell2Zone"
3224 zeroGradientFvPatchScalarField::typeName
3227 forAll(cellToZone, cellI)
3229 volCellToZone[cellI] = cellToZone[cellI];
3231 volCellToZone.write();
3333 void Foam::meshRefinement::handleSnapProblems
3335 const snapParameters& snapParams,
3336 const bool useTopologicalSnapDetection,
3337 const bool removeEdgeConnectedCells,
3339 const dictionary& motionDict,
3346 <<
"Introducing baffles to block off problem cells" <<
nl
3347 <<
"----------------------------------------------" <<
nl
3351 if (useTopologicalSnapDetection)
3353 facePatch = markFacesOnProblemCells
3356 removeEdgeConnectedCells,
3363 facePatch = markFacesOnProblemCellsGeometric
3367 globalToMasterPatch,
3371 Info<<
"Analyzed problem cells in = "
3376 faceSet problemFaces(mesh_,
"problemFaces", mesh_.nFaces()/100);
3380 if (facePatch[faceI] != -1)
3382 problemFaces.insert(faceI);
3385 problemFaces.instance() =
timeName();
3386 Pout<<
"Dumping " << problemFaces.size()
3387 <<
" problem faces to " << problemFaces.objectPath() <<
endl;
3388 problemFaces.
write();
3391 Info<<
"Introducing baffles to delete problem cells." <<
nl <<
endl;
3399 createBaffles(facePatch, facePatch);
3406 Info<<
"Created baffles in = "
3409 printMeshInfo(
debug,
"After introducing baffles");
3413 const_cast<Time&
>(mesh_.time())++;
3414 Pout<<
"Writing extra baffled mesh to time "
3419 writeType(writeLevel() | WRITEMESH),
3422 Pout<<
"Dumped debug data in = "
3435 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
3436 const labelList& faceOwner = mesh_.faceOwner();
3437 const labelList& faceNeighbour = mesh_.faceNeighbour();
3454 DynamicList<label> faceLabels(mesh_.nFaces()/100);
3456 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
3458 if (faceToZone[faceI] != -1)
3461 label ownZone = cellToZone[faceOwner[faceI]];
3462 label neiZone = cellToZone[faceNeighbour[faceI]];
3463 if (ownZone == neiZone)
3465 faceLabels.
append(faceI);
3471 const polyPatch& pp =
patches[patchI];
3475 label faceI = pp.start()+i;
3476 if (faceToZone[faceI] != -1)
3479 label ownZone = cellToZone[faceOwner[faceI]];
3480 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
3481 if (ownZone == neiZone)
3483 faceLabels.append(faceI);
3488 return faceLabels.shrink();
3492 void Foam::meshRefinement::calcPatchNumMasterFaces
3494 const bitSet& isMasterFace,
3500 nMasterFacesPerEdge.setSize(
patch.nEdges());
3501 nMasterFacesPerEdge = 0;
3505 const label meshFaceI =
patch.addressing()[faceI];
3507 if (isMasterFace.test(meshFaceI))
3512 nMasterFacesPerEdge[fEdges[fEdgeI]]++;
3520 patch.meshEdges(mesh_.edges(), mesh_.pointEdges()),
3521 nMasterFacesPerEdge,
3528 Foam::label Foam::meshRefinement::markPatchZones
3535 List<edgeTopoDistanceData<label>> allEdgeInfo(
patch.nEdges());
3536 List<edgeTopoDistanceData<label>> allFaceInfo(
patch.size());
3541 label nProtected = 0;
3543 forAll(nMasterFacesPerEdge, edgeI)
3545 if (nMasterFacesPerEdge[edgeI] > 2)
3547 allEdgeInfo[edgeI] = edgeTopoDistanceData<label>(0, -2);
3559 DynamicList<label> changedEdges;
3560 DynamicList<edgeTopoDistanceData<label>> changedInfo;
3562 const scalar tol = PatchEdgeFaceWave
3565 edgeTopoDistanceData<label>
3566 >::propagationTol();
3570 const globalIndex globalFaces(
patch.size());
3574 label currentZoneI = 0;
3580 for (; faceI < allFaceInfo.size(); faceI++)
3582 if (!allFaceInfo[faceI].valid(dummyTrackData))
3584 globalSeed = globalFaces.toGlobal(faceI);
3589 reduce(globalSeed, minOp<label>());
3596 label procI = globalFaces.whichProcID(globalSeed);
3597 label seedFaceI = globalFaces.toLocal(procI, globalSeed);
3605 edgeTopoDistanceData<label>& faceInfo = allFaceInfo[seedFaceI];
3609 faceInfo = edgeTopoDistanceData<label>(0, currentZoneI);
3615 label edgeI = fEdges[fEdgeI];
3617 edgeTopoDistanceData<label>& edgeInfo = allEdgeInfo[edgeI];
3621 edgeInfo.updateEdge<
int>
3633 changedEdges.append(edgeI);
3634 changedInfo.append(edgeInfo);
3640 if (
returnReduce(changedEdges.size(), sumOp<label>()) == 0)
3650 edgeTopoDistanceData<label>
3666 faceToZone.setSize(
patch.size());
3667 forAll(allFaceInfo, faceI)
3669 if (!allFaceInfo[faceI].valid(dummyTrackData))
3672 <<
"Problem: unvisited face " << faceI
3673 <<
" at " <<
patch.faceCentres()[faceI]
3676 faceToZone[faceI] = allFaceInfo[faceI].data();
3679 return currentZoneI;
3683 void Foam::meshRefinement::consistentOrientation
3685 const bitSet& isMasterFace,
3689 const Map<label>& zoneToOrientation,
3693 const polyBoundaryMesh& bm = mesh_.boundaryMesh();
3696 List<patchFaceOrientation> allEdgeInfo(
patch.nEdges());
3697 List<patchFaceOrientation> allFaceInfo(
patch.size());
3703 label nProtected = 0;
3707 const label meshFaceI =
patch.addressing()[faceI];
3708 const label patchI = bm.whichPatch(meshFaceI);
3714 && !isMasterFace.test(meshFaceI)
3727 label nProtected = 0;
3729 forAll(nMasterFacesPerEdge, edgeI)
3731 if (nMasterFacesPerEdge[edgeI] > 2)
3738 Info<<
"Protected from visiting "
3740 <<
" non-manifold edges" <<
nl <<
endl;
3745 DynamicList<label> changedEdges;
3746 DynamicList<patchFaceOrientation> changedInfo;
3748 const scalar tol = PatchEdgeFaceWave
3751 patchFaceOrientation
3752 >::propagationTol();
3756 globalIndex globalFaces(
patch.size());
3762 forAll(allFaceInfo, faceI)
3766 globalSeed = globalFaces.toGlobal(faceI);
3771 reduce(globalSeed, minOp<label>());
3778 label procI = globalFaces.whichProcID(globalSeed);
3779 label seedFaceI = globalFaces.toLocal(procI, globalSeed);
3788 patchFaceOrientation& faceInfo = allFaceInfo[seedFaceI];
3793 if (zoneToOrientation[faceToZone[seedFaceI]] < 0)
3802 label edgeI = fEdges[fEdgeI];
3804 patchFaceOrientation& edgeInfo = allEdgeInfo[edgeI];
3808 edgeInfo.updateEdge<
int>
3820 changedEdges.append(edgeI);
3821 changedInfo.append(edgeInfo);
3827 if (
returnReduce(changedEdges.size(), sumOp<label>()) == 0)
3838 patchFaceOrientation
3856 mesh_.nBoundaryFaces(),
3862 const label meshFaceI =
patch.addressing()[i];
3863 if (!mesh_.isInternalFace(meshFaceI))
3865 neiStatus[meshFaceI-mesh_.nInternalFaces()] =
3866 allFaceInfo[i].flipStatus();
3873 const label meshFaceI =
patch.addressing()[i];
3874 const label patchI = bm.whichPatch(meshFaceI);
3880 && !isMasterFace.test(meshFaceI)
3884 label bFaceI = meshFaceI-mesh_.nInternalFaces();
3897 <<
"Incorrect status for face " << meshFaceI
3907 meshFlipMap.setSize(mesh_.nFaces());
3908 meshFlipMap =
false;
3910 forAll(allFaceInfo, faceI)
3912 label meshFaceI =
patch.addressing()[faceI];
3916 meshFlipMap.unset(meshFaceI);
3920 meshFlipMap.set(meshFaceI);
3925 <<
"Problem : unvisited face " << faceI
3926 <<
" centre:" << mesh_.faceCentres()[meshFaceI]
3933 void Foam::meshRefinement::zonify
3936 const bitSet& isMasterFace,
3940 const bitSet& meshFlipMap,
3941 polyTopoChange& meshMod
3944 const labelList& faceOwner = mesh_.faceOwner();
3945 const labelList& faceNeighbour = mesh_.faceNeighbour();
3947 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
3949 label faceZoneI = faceToZone[faceI];
3951 if (faceZoneI != -1)
3957 label ownZone = cellToZone[faceOwner[faceI]];
3958 label neiZone = cellToZone[faceNeighbour[faceI]];
3962 if (ownZone == neiZone)
3965 flip = meshFlipMap.test(faceI);
3972 || (neiZone != -1 && ownZone > neiZone)
3980 mesh_.faces()[faceI],
3983 faceNeighbour[faceI],
3995 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
4000 const polyPatch& pp =
patches[patchI];
4002 label faceI = pp.
start();
4006 label faceZoneI = faceToZone[faceI];
4008 if (faceZoneI != -1)
4010 label ownZone = cellToZone[faceOwner[faceI]];
4011 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
4015 if (ownZone == neiZone)
4018 flip = meshFlipMap.test(faceI);
4025 || (neiZone != -1 && ownZone > neiZone)
4033 mesh_.faces()[faceI],
4053 forAll(cellToZone, cellI)
4055 label zoneI = cellToZone[cellI];
4073 void Foam::meshRefinement::allocateInterRegionFaceZone
4075 const label ownZone,
4076 const label neiZone,
4078 LabelPairMap<word>& zoneIDsToFaceZone
4083 if (ownZone != neiZone)
4090 || (neiZone != -1 && ownZone > neiZone)
4100 if (!zoneIDsToFaceZone.found(
key))
4103 const word ownZoneName =
4106 ? cellZones[ownZone].name()
4109 const word neiZoneName =
4112 ? cellZones[neiZone].name()
4117 Pair<word> wordKey(ownZoneName, neiZoneName);
4123 word fzName = wordKey.first() +
"_to_" + wordKey.second();
4125 zoneIDsToFaceZone.insert(
key, fzName);
4126 zonesToFaceZone.insert(wordKey, fzName);
4136 const bool doHandleSnapProblems,
4138 const bool useTopologicalSnapDetection,
4139 const bool removeEdgeConnectedCells,
4141 const label nErodeCellZones,
4159 Info<<
"Introducing baffles for "
4161 <<
" faces that are intersected by the surface." <<
nl <<
endl;
4164 labelList neiLevel(mesh_.nBoundaryFaces());
4166 calcNeighbourData(neiLevel, neiCc);
4172 globalToMasterPatch,
4184 createBaffles(ownPatch, neiPatch);
4192 Info<<
"Created baffles in = "
4195 printMeshInfo(
debug,
"After introducing baffles");
4199 const_cast<Time&
>(mesh_.time())++;
4208 Pout<<
"Dumped debug data in = "
4218 if (doHandleSnapProblems)
4223 useTopologicalSnapDetection,
4224 removeEdgeConnectedCells,
4228 globalToMasterPatch,
4236 neiLevel.setSize(mesh_.nBoundaryFaces());
4237 neiCc.setSize(mesh_.nBoundaryFaces());
4238 calcNeighbourData(neiLevel, neiCc);
4244 globalToMasterPatch,
4256 createBaffles(ownPatch, neiPatch);
4271 <<
"Remove unreachable sections of mesh" <<
nl
4272 <<
"-----------------------------------" <<
nl
4282 globalToMasterPatch,
4285 locationsOutsideMesh,
4295 Info<<
"Split mesh in = "
4298 printMeshInfo(
debug,
"After subsetting");
4311 Pout<<
"Dumped debug data in = "
4320 const bool useTopologicalSnapDetection,
4321 const bool removeEdgeConnectedCells,
4323 const scalar planarAngle,
4337 <<
"Merge free-standing baffles" <<
nl
4338 <<
"---------------------------" <<
nl
4352 label nCouples = couples.size();
4355 Info<<
"Detected free-standing baffles : " << nCouples <<
endl;
4369 useTopologicalSnapDetection,
4370 removeEdgeConnectedCells,
4374 globalToMasterPatch,
4382 <<
"Remove unreachable sections of mesh" <<
nl
4383 <<
"-----------------------------------" <<
nl
4393 globalToMasterPatch,
4396 locationsOutsideMesh,
4408 Info<<
"Merged free-standing baffles in = "
4415 const label nBufferLayers,
4416 const label nErodeCellZones,
4430 labelList neiLevel(mesh_.nBoundaryFaces());
4432 calcNeighbourData(neiLevel, neiCc);
4439 globalToMasterPatch,
4452 boolList blockedFace(mesh_.nFaces(),
false);
4456 if (ownPatch[faceI] != -1 || neiPatch[faceI] != -1)
4458 blockedFace[faceI] =
true;
4472 locationsOutsideMesh,
4483 globalToMasterPatch,
4493 const label nBufferLayers,
4508 const labelList& faceOwner = mesh_.faceOwner();
4509 const labelList& faceNeighbour = mesh_.faceNeighbour();
4512 label defaultPatch = 0;
4513 if (globalToMasterPatch.size())
4515 defaultPatch = globalToMasterPatch[0];
4518 for (label i = 0; i < nBufferLayers; i++)
4522 labelList pointBaffle(mesh_.nPoints(), -1);
4524 forAll(faceNeighbour, faceI)
4526 const face&
f = mesh_.faces()[faceI];
4528 const label ownRegion = cellRegion[faceOwner[faceI]];
4529 const label neiRegion = cellRegion[faceNeighbour[faceI]];
4531 if (ownRegion == -1 && neiRegion != -1)
4538 pointBaffle[
f[fp]] =
max(defaultPatch, ownPatch[faceI]);
4541 else if (ownRegion != -1 && neiRegion == -1)
4543 label newPatchI = neiPatch[faceI];
4544 if (newPatchI == -1)
4546 newPatchI =
max(defaultPatch, ownPatch[faceI]);
4550 pointBaffle[
f[fp]] = newPatchI;
4559 label faceI = mesh_.nInternalFaces();
4560 faceI < mesh_.nFaces();
4564 const face&
f = mesh_.faces()[faceI];
4566 const label ownRegion = cellRegion[faceOwner[faceI]];
4567 const label neiRegion = neiCellRegion[faceI-mesh_.nInternalFaces()];
4569 if (ownRegion == -1 && neiRegion != -1)
4573 pointBaffle[
f[fp]] =
max(defaultPatch, ownPatch[faceI]);
4592 forAll(pointFaces, pointI)
4594 if (pointBaffle[pointI] != -1)
4600 label faceI =
pFaces[pFaceI];
4602 if (ownPatch[faceI] == -1)
4604 ownPatch[faceI] = pointBaffle[pointI];
4618 if (ownPatch[faceI] != -1)
4620 label own = faceOwner[faceI];
4622 if (cellRegion[own] == -1)
4626 const cell& ownFaces = mesh_.cells()[own];
4629 if (ownPatch[ownFaces[j]] == -1)
4631 newOwnPatch[ownFaces[j]] = ownPatch[faceI];
4635 if (mesh_.isInternalFace(faceI))
4637 label nei = faceNeighbour[faceI];
4639 if (cellRegion[nei] == -1)
4643 const cell& neiFaces = mesh_.cells()[nei];
4646 if (ownPatch[neiFaces[j]] == -1)
4648 newOwnPatch[neiFaces[j]] = ownPatch[faceI];
4667 DynamicList<label> cellsToRemove(mesh_.nCells());
4668 forAll(cellRegion, cellI)
4670 if (cellRegion[cellI] == -1)
4672 cellsToRemove.append(cellI);
4675 cellsToRemove.shrink();
4677 label nCellsToKeep = mesh_.nCells() - cellsToRemove.size();
4678 reduce(nCellsToKeep, sumOp<label>());
4680 Info<<
"Keeping all cells containing inside points" <<
endl
4681 <<
"Selected for keeping : " << nCellsToKeep <<
" cells." <<
endl;
4685 removeCells cellRemover(mesh_);
4688 labelList exposedFaces(cellRemover.getExposedFaces(cellsToRemove));
4689 labelList exposedPatches(exposedFaces.size());
4693 label faceI = exposedFaces[i];
4695 if (ownPatch[faceI] != -1)
4697 exposedPatches[i] = ownPatch[faceI];
4702 <<
"For exposed face " << faceI
4703 <<
" fc:" << mesh_.faceCentres()[faceI]
4704 <<
" found no patch." <<
endl
4705 <<
" Taking patch " << defaultPatch
4706 <<
" instead." <<
endl;
4707 exposedPatches[i] = defaultPatch;
4711 return doRemoveCells
4723 const label nBufferLayers,
4724 const label nErodeCellZones,
4735 labelList neiLevel(mesh_.nBoundaryFaces());
4737 calcNeighbourData(neiLevel, neiCc);
4744 globalToMasterPatch,
4760 limitShells_.findLevel
4762 mesh_.cellCentres(),
4766 forAll(levelShell, celli)
4768 if (levelShell[celli] != -1)
4771 cellRegion[celli] = -1;
4778 globalToMasterPatch,
4787 const_cast<Time&
>(mesh_.time())++;
4788 Pout<<
"Writing mesh after removing limitShells"
4819 Info<<
"dupNonManifoldPoints : Found : " << nNonManifPoints
4820 <<
" non-manifold points (out of "
4821 << mesh_.globalData().nTotalPoints()
4827 if (nNonManifPoints)
4836 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
4840 mesh_.updateMesh(map);
4879 label nPointPairs = 0;
4880 forAll(pointToDuplicate, pointI)
4882 label otherPointI = pointToDuplicate[pointI];
4883 if (otherPointI != -1)
4894 forAll(pointToDuplicate, pointI)
4896 label otherPointI = pointToDuplicate[pointI];
4897 if (otherPointI != -1)
4900 pointToMaster.insert(pointI, otherPointI);
4911 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
4915 mesh_.updateMesh(map);
4962 internalOrBaffleFaceZones = getZones(fzTypes);
4972 forAll(boundaryFaceZones, j)
4974 const faceZone& fZone = mesh_.faceZones()[boundaryFaceZones[j]];
4977 const face&
f = mesh_.faces()[fZone[i]];
4980 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 1u);
4984 forAll(internalOrBaffleFaceZones, j)
4986 const faceZone& fZone = mesh_.faceZones()[internalOrBaffleFaceZones[j]];
4989 const face&
f = mesh_.faces()[fZone[i]];
4992 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 2u);
5007 forAll(pointStatus, pointI)
5009 if (pointStatus[pointI] == 1u)
5016 Info<<
"Duplicating " << globalNPoints <<
" points on"
5017 <<
" faceZones of type "
5027 forAll(pointStatus, pointI)
5029 if (pointStatus[pointI] == 1u)
5031 candidatePoints[
n++] = pointI;
5044 const bool allowFreeStandingZoneFaces,
5045 const label nErodeCellZones,
5051 if (locationsInMesh.size() != zonesInMesh.size())
5061 labelList neiLevel(mesh_.nBoundaryFaces());
5063 calcNeighbourData(neiLevel, neiCc);
5072 if (namedSurfaces.size())
5074 Info<<
"Setting cellZones according to named surfaces:" <<
endl;
5077 label surfI = namedSurfaces[i];
5079 Info<<
"Surface : " << surfaces_.names()[surfI] <<
nl
5080 <<
" faceZones : " << surfZones[surfI].faceZoneNames() <<
nl
5081 <<
" cellZone : " << surfZones[surfI].cellZoneName()
5122 allowFreeStandingZoneFaces,
5141 labelList faceToZone(mesh_.nFaces(), -1);
5143 forAll(namedSurfaceRegion, faceI)
5146 label globalI = namedSurfaceRegion[faceI];
5149 const labelPair spr = surfaces_.whichSurface(globalI);
5150 faceToZone[faceI] = surfaceToFaceZones[spr.first()][spr.
second()];
5164 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
5166 if (faceToZone[faceI] == -1)
5171 allocateInterRegionFaceZone
5173 cellToZone[mesh_.faceOwner()[faceI]],
5174 cellToZone[mesh_.faceNeighbour()[faceI]],
5184 forAll(neiCellZone, bFaceI)
5186 label faceI = bFaceI + mesh_.nInternalFaces();
5187 if (faceToZone[faceI] == -1)
5189 allocateInterRegionFaceZone
5191 cellToZone[mesh_.faceOwner()[faceI]],
5192 neiCellZone[bFaceI],
5211 Info<<
"Setting faceZones according to neighbouring cellZones:"
5225 const word& fzName = zonesToFaceZone[cz];
5228 << cz[0] <<
' ' << cz[1] <<
nl
5229 <<
" faceZone : " << fzName <<
endl;
5239 label cz0 = cellZones.findZoneID(cz[0]);
5240 label cz1 = cellZones.findZoneID(cz[1]);
5250 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
5252 if (faceToZone[faceI] == -1)
5258 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
5259 label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
5260 if (ownZone != neiZone)
5265 || (neiZone != -1 && ownZone > neiZone)
5272 faceToZone[faceI] = fZoneLookup[
key];
5276 forAll(neiCellZone, bFaceI)
5278 label faceI = bFaceI + mesh_.nInternalFaces();
5279 if (faceToZone[faceI] == -1)
5281 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
5282 label neiZone = neiCellZone[bFaceI];
5283 if (ownZone != neiZone)
5288 || (neiZone != -1 && ownZone > neiZone)
5295 faceToZone[faceI] = fZoneLookup[
key];
5314 label bFaceI = pp.
start()-mesh_.nInternalFaces();
5317 neiCellZone[bFaceI++] = -1;
5338 bitSet meshFlipMap(mesh_.nFaces(),
false);
5346 freeStandingBaffleFaces
5357 if (nFreeStanding > 0)
5359 Info<<
"Detected " << nFreeStanding <<
" free-standing zone faces"
5364 OBJstream str(mesh_.time().path()/
"freeStanding.obj");
5371 calcPatchNumMasterFaces(isMasterFace,
patch, nMasterFacesPerEdge);
5376 const label
nZones = markPatchZones
5379 nMasterFacesPerEdge,
5384 for (label zoneI = 0; zoneI <
nZones; zoneI++)
5386 nPosOrientation.insert(zoneI, 0);
5392 consistentOrientation
5396 nMasterFacesPerEdge,
5397 faceToConnectedZone,
5407 label meshFaceI =
patch.addressing()[faceI];
5409 if (isMasterFace.
test(meshFaceI))
5414 posOrientation.
test(meshFaceI)
5415 == meshFlipMap.test(meshFaceI)
5421 nPosOrientation.find(faceToConnectedZone[faceI])() +=
n;
5428 Info<<
"Split " << nFreeStanding <<
" free-standing zone faces"
5429 <<
" into " <<
nZones <<
" disconnected regions with size"
5430 <<
" (negative denotes wrong orientation) :"
5433 for (label zoneI = 0; zoneI <
nZones; zoneI++)
5435 Info<<
" " << zoneI <<
"\t" << nPosOrientation[zoneI]
5443 consistentOrientation
5447 nMasterFacesPerEdge,
5448 faceToConnectedZone,
5477 mesh_.updateMesh(map());
5480 if (map().hasMotionPoints())
5482 mesh_.movePoints(map().preMotionPoints());
5494 if (mesh_.cellZones().size() > 0)
5497 forAll(mesh_.cellZones(), zoneI)
5499 const cellZone& cz = mesh_.cellZones()[zoneI];
5506 if (mesh_.faceZones().size() > 0)
5509 forAll(mesh_.faceZones(), zoneI)
5511 const faceZone& fz = mesh_.faceZones()[zoneI];