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());
2411 FaceCellWave<wallPoints> wallDistCalc
2420 wallDistCalc.iterate(nGrowCellZones);
2427 bitSet isChangedCell(mesh_.nCells());
2429 forAll(allCellInfo, celli)
2431 if (allCellInfo[celli].valid(wallDistCalc.data()))
2433 const List<FixedList<label, 3>>& surfaces =
2434 allCellInfo[celli].surface();
2436 if (surfaces.size())
2440 isChangedCell.set(celli);
2443 if (surfaces.size() > 1)
2449 for (label i = 0; i < surfaces.size(); i++)
2451 const label zonei = surfaces[i][0];
2452 const scalar d2 = allCellInfo[celli].distSqr()[i];
2453 if (zonei != cellToZone[celli] && d2 < minDistSqr)
2462 if (minZone != cellToZone[celli] && minZone != wallTag[0])
2464 cellToZone[celli] = minZone;
2465 isChangedCell.set(celli);
2473 if (backgroundZoneID != -2)
2475 forAll(cellToZone, celli)
2477 if (cellToZone[celli] == -2)
2479 cellToZone[celli] = backgroundZoneID;
2492 for (
const label celli : isChangedCell)
2494 const cell& cFaces = mesh_.cells()[celli];
2495 for (
const label facei : cFaces)
2497 const label own = mesh_.faceOwner()[facei];
2498 const label ownZone = cellToZone[own];
2501 if (mesh_.isInternalFace(facei))
2503 const label neiZone = cellToZone[mesh_.faceNeighbour()[facei]];
2504 nbrZone = (own != celli ? ownZone : neiZone);
2508 nbrZone = neiCellZone[facei-mesh_.nInternalFaces()];
2511 if (nbrZone == cellToZone[celli])
2515 unnamedSurfaceRegion1[facei] != -1
2516 || unnamedSurfaceRegion2[facei] != -1
2519 unnamedSurfaceRegion1[facei] = -1;
2520 unnamedSurfaceRegion2[facei] = -1;
2525 namedSurfaceRegion.size()
2526 && namedSurfaceRegion[facei] != -1
2529 namedSurfaceRegion[facei] = -1;
2536 reduce(nUnnamed, sumOp<label>());
2537 reduce(nNamed, sumOp<label>());
2543 unnamedSurfaceRegion1,
2549 unnamedSurfaceRegion2,
2552 if (namedSurfaceRegion.size())
2564 Pout<<
"growCellZone : grown cellZones by "
2566 <<
" cells (moved from background to nearest cellZone)"
2568 Pout<<
"growCellZone : unmarked " << nUnnamed
2569 <<
" unzoned intersections; " << nNamed <<
" zoned intersections; "
2575 void Foam::meshRefinement::makeConsistentFaceIndex
2590 const labelList& faceOwner = mesh_.faceOwner();
2591 const labelList& faceNeighbour = mesh_.faceNeighbour();
2593 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
2595 label ownZone = cellToZone[faceOwner[faceI]];
2596 label neiZone = cellToZone[faceNeighbour[faceI]];
2597 label globalI = namedSurfaceRegion[faceI];
2603 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2606 namedSurfaceRegion[faceI] = -1;
2610 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2619 const polyPatch& pp =
patches[patchI];
2625 label faceI = pp.start()+i;
2627 label ownZone = cellToZone[faceOwner[faceI]];
2628 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
2629 label globalI = namedSurfaceRegion[faceI];
2635 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2638 namedSurfaceRegion[faceI] = -1;
2647 label faceI = pp.start()+i;
2648 label globalI = namedSurfaceRegion[faceI];
2653 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2656 namedSurfaceRegion[faceI] = -1;
2664 void Foam::meshRefinement::getIntersections
2671 bitSet& posOrientation
2674 namedSurfaceRegion.setSize(mesh_.nFaces());
2675 namedSurfaceRegion = -1;
2677 posOrientation.setSize(mesh_.nFaces());
2678 posOrientation =
false;
2709 List<pointIndexHit> hit1;
2713 List<pointIndexHit> hit2;
2716 surfaces_.findNearestIntersection
2735 label faceI = testFaces[i];
2736 const vector&
area = mesh_.faceAreas()[faceI];
2738 if (surface1[i] != -1)
2745 magSqr(hit2[i].hitPoint())
2746 <
magSqr(hit1[i].hitPoint())
2750 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2755 posOrientation.
set(faceI, ((
area&normal2[i]) > 0));
2756 nSurfFaces[surface2[i]]++;
2760 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2765 posOrientation.set(faceI, ((
area&normal1[i]) > 0));
2766 nSurfFaces[surface1[i]]++;
2769 else if (surface2[i] != -1)
2771 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2776 posOrientation.set(faceI, ((
area&normal2[i]) > 0));
2777 nSurfFaces[surface2[i]]++;
2796 forAll(nSurfFaces, surfI)
2799 << surfaces_.names()[surfI]
2800 <<
" nZoneFaces:" << nSurfFaces[surfI] <<
nl;
2807 void Foam::meshRefinement::zonify
2809 const bool allowFreeStandingZoneFaces,
2810 const label nErodeCellZones,
2811 const label backgroundZoneID,
2819 bitSet& posOrientation
2832 const PtrList<surfaceZonesInfo>& surfZones = surfaces_.surfZones();
2835 labelList neiLevel(mesh_.nBoundaryFaces());
2837 calcNeighbourData(neiLevel, neiCc);
2845 if (namedSurfaces.size())
2857 cellToZone.setSize(mesh_.nCells());
2860 namedSurfaceRegion.clear();
2861 posOrientation.clear();
2878 if (namedSurfaces.size())
2894 if (locationsInMesh.size())
2896 Info<<
"Setting cellZones according to locationsInMesh:" <<
endl;
2898 labelList locationsZoneIDs(zonesInMesh.size(), -1);
2899 forAll(locationsInMesh, i)
2901 const word&
name = zonesInMesh[i];
2903 Info<<
"Location : " << locationsInMesh[i] <<
nl
2908 label
zoneID = mesh_.cellZones().findZoneID(
name);
2913 locationsZoneIDs[i] =
zoneID;
2920 findCellZoneInsideWalk
2937 if (locationSurfaces.size())
2939 Info<<
"Found " << locationSurfaces.size()
2940 <<
" named surfaces with a provided inside point."
2941 <<
" Assigning cells inside these surfaces"
2942 <<
" to the corresponding cellZone."
2947 labelList insidePointCellZoneIDs(locationSurfaces.size(), -1);
2948 forAll(locationSurfaces, i)
2950 label surfI = locationSurfaces[i];
2953 const word&
name = surfZones[surfI].cellZoneName();
2956 label
zoneID = mesh_.cellZones().findZoneID(
name);
2963 insidePointCellZoneIDs[i] =
zoneID;
2969 labelList allRegion1(mesh_.nFaces(), -1);
2970 forAll(namedSurfaceRegion, faceI)
2972 allRegion1[faceI] =
max
2974 unnamedRegion1[faceI],
2975 namedSurfaceRegion[faceI]
2979 findCellZoneInsideWalk
2982 insidePointCellZoneIDs,
2998 surfaces_.geometry(),
2999 surfaces_.surfaces()
3003 if (closedNamedSurfaces.size())
3005 Info<<
"Found " << closedNamedSurfaces.size()
3006 <<
" closed, named surfaces. Assigning cells in/outside"
3007 <<
" these surfaces to the corresponding cellZone."
3010 findCellZoneGeometric
3013 closedNamedSurfaces,
3024 if (namedSurfaces.size())
3026 if (nErodeCellZones == 0)
3028 Info<<
"Walking from known cellZones; crossing a faceZone "
3029 <<
"face changes cellZone" <<
nl <<
endl;
3042 else if (nErodeCellZones < 0)
3044 Info<<
"Growing cellZones by " << -nErodeCellZones
3045 <<
" layers" <<
nl <<
endl;
3059 Info<<
"Eroding cellZone cells to make these consistent with"
3060 <<
" faceZone faces" <<
nl <<
endl;
3076 if (!allowFreeStandingZoneFaces)
3078 Info<<
"Only keeping zone faces inbetween different cellZones."
3092 labelList surfaceMap(surfZones.size(), -1);
3093 forAll(standaloneNamedSurfaces, i)
3095 surfaceMap[standaloneNamedSurfaces[i]] = i;
3098 makeConsistentFaceIndex
3106 else if (nErodeCellZones < 0 &&
gMax(cellToZone) >= 0)
3111 Info<<
"Growing cellZones by " << -nErodeCellZones
3112 <<
" layers" <<
nl <<
endl;
3125 if (!allowFreeStandingZoneFaces && namedSurfaceRegion.size())
3127 Info<<
"Only keeping zone faces inbetween different cellZones."
3141 labelList surfaceMap(surfZones.size(), -1);
3142 forAll(standaloneNamedSurfaces, i)
3144 surfaceMap[standaloneNamedSurfaces[i]] = i;
3147 makeConsistentFaceIndex
3162 label nUnvisited = 0;
3163 label nBackgroundCells = 0;
3165 forAll(cellToZone, cellI)
3167 label zoneI = cellToZone[cellI];
3170 nZoneCells[zoneI]++;
3172 else if (zoneI == -1)
3176 else if (zoneI == -2)
3186 reduce(nUnvisited, sumOp<label>());
3187 reduce(nBackgroundCells, sumOp<label>());
3188 forAll(nZoneCells, zoneI)
3190 reduce(nZoneCells[zoneI], sumOp<label>());
3192 Info<<
"nUnvisited :" << nUnvisited <<
endl;
3193 Info<<
"nBackgroundCells:" << nBackgroundCells <<
endl;
3194 Info<<
"nZoneCells :" << nZoneCells <<
endl;
3198 const_cast<Time&
>(mesh_.time())++;
3199 Pout<<
"Writing cell zone allocation on mesh to time "
3204 writeType(writeLevel() | WRITEMESH),
3205 mesh_.time().path()/
"cell2Zone"
3220 zeroGradientFvPatchScalarField::typeName
3223 forAll(cellToZone, cellI)
3225 volCellToZone[cellI] = cellToZone[cellI];
3227 volCellToZone.write();
3329 void Foam::meshRefinement::handleSnapProblems
3331 const snapParameters& snapParams,
3332 const bool useTopologicalSnapDetection,
3333 const bool removeEdgeConnectedCells,
3335 const dictionary& motionDict,
3342 <<
"Introducing baffles to block off problem cells" <<
nl
3343 <<
"----------------------------------------------" <<
nl
3347 if (useTopologicalSnapDetection)
3349 facePatch = markFacesOnProblemCells
3352 removeEdgeConnectedCells,
3359 facePatch = markFacesOnProblemCellsGeometric
3363 globalToMasterPatch,
3367 Info<<
"Analyzed problem cells in = "
3372 faceSet problemFaces(mesh_,
"problemFaces", mesh_.nFaces()/100);
3376 if (facePatch[faceI] != -1)
3378 problemFaces.insert(faceI);
3381 problemFaces.instance() =
timeName();
3382 Pout<<
"Dumping " << problemFaces.size()
3383 <<
" problem faces to " << problemFaces.objectPath() <<
endl;
3384 problemFaces.
write();
3387 Info<<
"Introducing baffles to delete problem cells." <<
nl <<
endl;
3395 createBaffles(facePatch, facePatch);
3402 Info<<
"Created baffles in = "
3405 printMeshInfo(
debug,
"After introducing baffles");
3409 const_cast<Time&
>(mesh_.time())++;
3410 Pout<<
"Writing extra baffled mesh to time "
3415 writeType(writeLevel() | WRITEMESH),
3418 Pout<<
"Dumped debug data in = "
3431 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
3432 const labelList& faceOwner = mesh_.faceOwner();
3433 const labelList& faceNeighbour = mesh_.faceNeighbour();
3450 DynamicList<label> faceLabels(mesh_.nFaces()/100);
3452 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
3454 if (faceToZone[faceI] != -1)
3457 label ownZone = cellToZone[faceOwner[faceI]];
3458 label neiZone = cellToZone[faceNeighbour[faceI]];
3459 if (ownZone == neiZone)
3461 faceLabels.
append(faceI);
3467 const polyPatch& pp =
patches[patchI];
3471 label faceI = pp.start()+i;
3472 if (faceToZone[faceI] != -1)
3475 label ownZone = cellToZone[faceOwner[faceI]];
3476 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
3477 if (ownZone == neiZone)
3479 faceLabels.append(faceI);
3484 return faceLabels.shrink();
3488 void Foam::meshRefinement::calcPatchNumMasterFaces
3490 const bitSet& isMasterFace,
3496 nMasterFacesPerEdge.setSize(
patch.nEdges());
3497 nMasterFacesPerEdge = 0;
3501 const label meshFaceI =
patch.addressing()[faceI];
3503 if (isMasterFace.test(meshFaceI))
3508 nMasterFacesPerEdge[fEdges[fEdgeI]]++;
3516 patch.meshEdges(mesh_.edges(), mesh_.pointEdges()),
3517 nMasterFacesPerEdge,
3524 Foam::label Foam::meshRefinement::markPatchZones
3531 List<edgeTopoDistanceData<label>> allEdgeInfo(
patch.nEdges());
3532 List<edgeTopoDistanceData<label>> allFaceInfo(
patch.size());
3537 label nProtected = 0;
3539 forAll(nMasterFacesPerEdge, edgeI)
3541 if (nMasterFacesPerEdge[edgeI] > 2)
3543 allEdgeInfo[edgeI] = edgeTopoDistanceData<label>(0, -2);
3555 DynamicList<label> changedEdges;
3556 DynamicList<edgeTopoDistanceData<label>> changedInfo;
3558 const scalar tol = PatchEdgeFaceWave
3561 edgeTopoDistanceData<label>
3562 >::propagationTol();
3566 const globalIndex globalFaces(
patch.size());
3570 label currentZoneI = 0;
3576 for (; faceI < allFaceInfo.size(); faceI++)
3578 if (!allFaceInfo[faceI].valid(dummyTrackData))
3580 globalSeed = globalFaces.toGlobal(faceI);
3585 reduce(globalSeed, minOp<label>());
3592 label procI = globalFaces.whichProcID(globalSeed);
3593 label seedFaceI = globalFaces.toLocal(procI, globalSeed);
3601 edgeTopoDistanceData<label>& faceInfo = allFaceInfo[seedFaceI];
3605 faceInfo = edgeTopoDistanceData<label>(0, currentZoneI);
3611 label edgeI = fEdges[fEdgeI];
3613 edgeTopoDistanceData<label>& edgeInfo = allEdgeInfo[edgeI];
3617 edgeInfo.updateEdge<
int>
3629 changedEdges.append(edgeI);
3630 changedInfo.append(edgeInfo);
3636 if (
returnReduce(changedEdges.size(), sumOp<label>()) == 0)
3646 edgeTopoDistanceData<label>
3662 faceToZone.setSize(
patch.size());
3663 forAll(allFaceInfo, faceI)
3665 if (!allFaceInfo[faceI].valid(dummyTrackData))
3668 <<
"Problem: unvisited face " << faceI
3669 <<
" at " <<
patch.faceCentres()[faceI]
3672 faceToZone[faceI] = allFaceInfo[faceI].data();
3675 return currentZoneI;
3679 void Foam::meshRefinement::consistentOrientation
3681 const bitSet& isMasterFace,
3685 const Map<label>& zoneToOrientation,
3689 const polyBoundaryMesh& bm = mesh_.boundaryMesh();
3692 List<patchFaceOrientation> allEdgeInfo(
patch.nEdges());
3693 List<patchFaceOrientation> allFaceInfo(
patch.size());
3699 label nProtected = 0;
3703 const label meshFaceI =
patch.addressing()[faceI];
3704 const label patchI = bm.whichPatch(meshFaceI);
3709 && bm[patchI].coupled()
3710 && !isMasterFace.test(meshFaceI)
3723 label nProtected = 0;
3725 forAll(nMasterFacesPerEdge, edgeI)
3727 if (nMasterFacesPerEdge[edgeI] > 2)
3734 Info<<
"Protected from visiting "
3736 <<
" non-manifold edges" <<
nl <<
endl;
3741 DynamicList<label> changedEdges;
3742 DynamicList<patchFaceOrientation> changedInfo;
3744 const scalar tol = PatchEdgeFaceWave
3747 patchFaceOrientation
3748 >::propagationTol();
3752 globalIndex globalFaces(
patch.size());
3758 forAll(allFaceInfo, faceI)
3762 globalSeed = globalFaces.toGlobal(faceI);
3767 reduce(globalSeed, minOp<label>());
3774 label procI = globalFaces.whichProcID(globalSeed);
3775 label seedFaceI = globalFaces.toLocal(procI, globalSeed);
3784 patchFaceOrientation& faceInfo = allFaceInfo[seedFaceI];
3789 if (zoneToOrientation[faceToZone[seedFaceI]] < 0)
3798 label edgeI = fEdges[fEdgeI];
3800 patchFaceOrientation& edgeInfo = allEdgeInfo[edgeI];
3804 edgeInfo.updateEdge<
int>
3816 changedEdges.append(edgeI);
3817 changedInfo.append(edgeInfo);
3823 if (
returnReduce(changedEdges.size(), sumOp<label>()) == 0)
3834 patchFaceOrientation
3852 mesh_.nBoundaryFaces(),
3858 const label meshFaceI =
patch.addressing()[i];
3859 if (!mesh_.isInternalFace(meshFaceI))
3861 neiStatus[meshFaceI-mesh_.nInternalFaces()] =
3862 allFaceInfo[i].flipStatus();
3869 const label meshFaceI =
patch.addressing()[i];
3870 const label patchI = bm.whichPatch(meshFaceI);
3875 && bm[patchI].coupled()
3876 && !isMasterFace.test(meshFaceI)
3880 label bFaceI = meshFaceI-mesh_.nInternalFaces();
3893 <<
"Incorrect status for face " << meshFaceI
3903 meshFlipMap.setSize(mesh_.nFaces());
3904 meshFlipMap =
false;
3906 forAll(allFaceInfo, faceI)
3908 label meshFaceI =
patch.addressing()[faceI];
3912 meshFlipMap.unset(meshFaceI);
3916 meshFlipMap.set(meshFaceI);
3921 <<
"Problem : unvisited face " << faceI
3922 <<
" centre:" << mesh_.faceCentres()[meshFaceI]
3929 void Foam::meshRefinement::zonify
3932 const bitSet& isMasterFace,
3936 const bitSet& meshFlipMap,
3937 polyTopoChange& meshMod
3940 const labelList& faceOwner = mesh_.faceOwner();
3941 const labelList& faceNeighbour = mesh_.faceNeighbour();
3943 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
3945 label faceZoneI = faceToZone[faceI];
3947 if (faceZoneI != -1)
3953 label ownZone = cellToZone[faceOwner[faceI]];
3954 label neiZone = cellToZone[faceNeighbour[faceI]];
3958 if (ownZone == neiZone)
3961 flip = meshFlipMap.test(faceI);
3968 || (neiZone != -1 && ownZone > neiZone)
3976 mesh_.faces()[faceI],
3979 faceNeighbour[faceI],
3991 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
3996 const polyPatch& pp =
patches[patchI];
3998 label faceI = pp.
start();
4002 label faceZoneI = faceToZone[faceI];
4004 if (faceZoneI != -1)
4006 label ownZone = cellToZone[faceOwner[faceI]];
4007 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
4011 if (ownZone == neiZone)
4014 flip = meshFlipMap.test(faceI);
4021 || (neiZone != -1 && ownZone > neiZone)
4029 mesh_.faces()[faceI],
4049 forAll(cellToZone, cellI)
4051 label zoneI = cellToZone[cellI];
4069 void Foam::meshRefinement::allocateInterRegionFaceZone
4071 const label ownZone,
4072 const label neiZone,
4074 LabelPairMap<word>& zoneIDsToFaceZone
4079 if (ownZone != neiZone)
4086 || (neiZone != -1 && ownZone > neiZone)
4096 if (!zoneIDsToFaceZone.found(key))
4099 const word ownZoneName =
4102 ? cellZones[ownZone].name()
4105 const word neiZoneName =
4108 ? cellZones[neiZone].name()
4113 Pair<word> wordKey(ownZoneName, neiZoneName);
4119 word fzName = wordKey.first() +
"_to_" + wordKey.second();
4121 zoneIDsToFaceZone.insert(key, fzName);
4122 zonesToFaceZone.insert(wordKey, fzName);
4132 const bool doHandleSnapProblems,
4134 const bool useTopologicalSnapDetection,
4135 const bool removeEdgeConnectedCells,
4137 const label nErodeCellZones,
4155 Info<<
"Introducing baffles for "
4157 <<
" faces that are intersected by the surface." <<
nl <<
endl;
4160 labelList neiLevel(mesh_.nBoundaryFaces());
4162 calcNeighbourData(neiLevel, neiCc);
4168 globalToMasterPatch,
4180 createBaffles(ownPatch, neiPatch);
4188 Info<<
"Created baffles in = "
4191 printMeshInfo(
debug,
"After introducing baffles");
4195 const_cast<Time&
>(mesh_.time())++;
4204 Pout<<
"Dumped debug data in = "
4214 if (doHandleSnapProblems)
4219 useTopologicalSnapDetection,
4220 removeEdgeConnectedCells,
4224 globalToMasterPatch,
4232 neiLevel.setSize(mesh_.nBoundaryFaces());
4233 neiCc.setSize(mesh_.nBoundaryFaces());
4234 calcNeighbourData(neiLevel, neiCc);
4240 globalToMasterPatch,
4252 createBaffles(ownPatch, neiPatch);
4267 <<
"Remove unreachable sections of mesh" <<
nl
4268 <<
"-----------------------------------" <<
nl
4278 globalToMasterPatch,
4281 locationsOutsideMesh,
4291 Info<<
"Split mesh in = "
4294 printMeshInfo(
debug,
"After subsetting");
4307 Pout<<
"Dumped debug data in = "
4316 const bool useTopologicalSnapDetection,
4317 const bool removeEdgeConnectedCells,
4319 const scalar planarAngle,
4333 <<
"Merge free-standing baffles" <<
nl
4334 <<
"---------------------------" <<
nl
4348 label nCouples = couples.size();
4351 Info<<
"Detected free-standing baffles : " << nCouples <<
endl;
4365 useTopologicalSnapDetection,
4366 removeEdgeConnectedCells,
4370 globalToMasterPatch,
4378 <<
"Remove unreachable sections of mesh" <<
nl
4379 <<
"-----------------------------------" <<
nl
4389 globalToMasterPatch,
4392 locationsOutsideMesh,
4404 Info<<
"Merged free-standing baffles in = "
4411 const label nBufferLayers,
4412 const label nErodeCellZones,
4426 labelList neiLevel(mesh_.nBoundaryFaces());
4428 calcNeighbourData(neiLevel, neiCc);
4435 globalToMasterPatch,
4448 boolList blockedFace(mesh_.nFaces(),
false);
4452 if (ownPatch[faceI] != -1 || neiPatch[faceI] != -1)
4454 blockedFace[faceI] =
true;
4468 locationsOutsideMesh,
4479 globalToMasterPatch,
4489 const label nBufferLayers,
4504 const labelList& faceOwner = mesh_.faceOwner();
4505 const labelList& faceNeighbour = mesh_.faceNeighbour();
4508 label defaultPatch = 0;
4509 if (globalToMasterPatch.size())
4511 defaultPatch = globalToMasterPatch[0];
4514 for (label i = 0; i < nBufferLayers; i++)
4518 labelList pointBaffle(mesh_.nPoints(), -1);
4520 forAll(faceNeighbour, faceI)
4522 const face&
f = mesh_.faces()[faceI];
4524 label ownRegion = cellRegion[faceOwner[faceI]];
4525 label neiRegion = cellRegion[faceNeighbour[faceI]];
4527 if (ownRegion == -1 && neiRegion != -1)
4534 pointBaffle[
f[fp]] =
max(defaultPatch, ownPatch[faceI]);
4537 else if (ownRegion != -1 && neiRegion == -1)
4539 label newPatchI = neiPatch[faceI];
4540 if (newPatchI == -1)
4542 newPatchI =
max(defaultPatch, ownPatch[faceI]);
4546 pointBaffle[
f[fp]] = newPatchI;
4552 label faceI = mesh_.nInternalFaces();
4553 faceI < mesh_.nFaces();
4557 const face&
f = mesh_.faces()[faceI];
4559 label ownRegion = cellRegion[faceOwner[faceI]];
4561 if (ownRegion == -1)
4565 pointBaffle[
f[fp]] =
max(defaultPatch, ownPatch[faceI]);
4584 forAll(pointFaces, pointI)
4586 if (pointBaffle[pointI] != -1)
4592 label faceI =
pFaces[pFaceI];
4594 if (ownPatch[faceI] == -1)
4596 ownPatch[faceI] = pointBaffle[pointI];
4610 if (ownPatch[faceI] != -1)
4612 label own = faceOwner[faceI];
4614 if (cellRegion[own] == -1)
4618 const cell& ownFaces = mesh_.cells()[own];
4621 if (ownPatch[ownFaces[j]] == -1)
4623 newOwnPatch[ownFaces[j]] = ownPatch[faceI];
4627 if (mesh_.isInternalFace(faceI))
4629 label nei = faceNeighbour[faceI];
4631 if (cellRegion[nei] == -1)
4635 const cell& neiFaces = mesh_.cells()[nei];
4638 if (ownPatch[neiFaces[j]] == -1)
4640 newOwnPatch[neiFaces[j]] = ownPatch[faceI];
4659 DynamicList<label> cellsToRemove(mesh_.nCells());
4660 forAll(cellRegion, cellI)
4662 if (cellRegion[cellI] == -1)
4664 cellsToRemove.append(cellI);
4667 cellsToRemove.shrink();
4669 label nCellsToKeep = mesh_.nCells() - cellsToRemove.size();
4670 reduce(nCellsToKeep, sumOp<label>());
4672 Info<<
"Keeping all cells containing inside points" <<
endl
4673 <<
"Selected for keeping : " << nCellsToKeep <<
" cells." <<
endl;
4677 removeCells cellRemover(mesh_);
4680 labelList exposedFaces(cellRemover.getExposedFaces(cellsToRemove));
4681 labelList exposedPatches(exposedFaces.size());
4685 label faceI = exposedFaces[i];
4687 if (ownPatch[faceI] != -1)
4689 exposedPatches[i] = ownPatch[faceI];
4694 <<
"For exposed face " << faceI
4695 <<
" fc:" << mesh_.faceCentres()[faceI]
4696 <<
" found no patch." <<
endl
4697 <<
" Taking patch " << defaultPatch
4698 <<
" instead." <<
endl;
4699 exposedPatches[i] = defaultPatch;
4703 return doRemoveCells
4715 const label nBufferLayers,
4716 const label nErodeCellZones,
4727 labelList neiLevel(mesh_.nBoundaryFaces());
4729 calcNeighbourData(neiLevel, neiCc);
4736 globalToMasterPatch,
4752 limitShells_.findLevel
4754 mesh_.cellCentres(),
4758 forAll(levelShell, celli)
4760 if (levelShell[celli] != -1)
4763 cellRegion[celli] = -1;
4770 globalToMasterPatch,
4779 const_cast<Time&
>(mesh_.time())++;
4780 Pout<<
"Writing mesh after removing limitShells"
4811 Info<<
"dupNonManifoldPoints : Found : " << nNonManifPoints
4812 <<
" non-manifold points (out of "
4813 << mesh_.globalData().nTotalPoints()
4819 if (nNonManifPoints)
4828 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
4832 mesh_.updateMesh(map);
4871 label nPointPairs = 0;
4872 forAll(pointToDuplicate, pointI)
4874 label otherPointI = pointToDuplicate[pointI];
4875 if (otherPointI != -1)
4886 forAll(pointToDuplicate, pointI)
4888 label otherPointI = pointToDuplicate[pointI];
4889 if (otherPointI != -1)
4892 pointToMaster.insert(pointI, otherPointI);
4903 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
4907 mesh_.updateMesh(map);
4954 internalOrBaffleFaceZones = getZones(fzTypes);
4964 forAll(boundaryFaceZones, j)
4966 const faceZone& fZone = mesh_.faceZones()[boundaryFaceZones[j]];
4969 const face&
f = mesh_.faces()[fZone[i]];
4972 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 1u);
4976 forAll(internalOrBaffleFaceZones, j)
4978 const faceZone& fZone = mesh_.faceZones()[internalOrBaffleFaceZones[j]];
4981 const face&
f = mesh_.faces()[fZone[i]];
4984 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 2u);
4999 forAll(pointStatus, pointI)
5001 if (pointStatus[pointI] == 1u)
5008 Info<<
"Duplicating " << globalNPoints <<
" points on"
5009 <<
" faceZones of type "
5019 forAll(pointStatus, pointI)
5021 if (pointStatus[pointI] == 1u)
5023 candidatePoints[
n++] = pointI;
5036 const bool allowFreeStandingZoneFaces,
5037 const label nErodeCellZones,
5043 if (locationsInMesh.size() != zonesInMesh.size())
5053 labelList neiLevel(mesh_.nBoundaryFaces());
5055 calcNeighbourData(neiLevel, neiCc);
5064 if (namedSurfaces.size())
5066 Info<<
"Setting cellZones according to named surfaces:" <<
endl;
5069 label surfI = namedSurfaces[i];
5071 Info<<
"Surface : " << surfaces_.names()[surfI] <<
nl
5072 <<
" faceZones : " << surfZones[surfI].faceZoneNames() <<
nl
5073 <<
" cellZone : " << surfZones[surfI].cellZoneName()
5114 allowFreeStandingZoneFaces,
5133 labelList faceToZone(mesh_.nFaces(), -1);
5135 forAll(namedSurfaceRegion, faceI)
5138 label globalI = namedSurfaceRegion[faceI];
5141 const labelPair spr = surfaces_.whichSurface(globalI);
5142 faceToZone[faceI] = surfaceToFaceZones[spr.first()][spr.
second()];
5156 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
5158 if (faceToZone[faceI] == -1)
5163 allocateInterRegionFaceZone
5165 cellToZone[mesh_.faceOwner()[faceI]],
5166 cellToZone[mesh_.faceNeighbour()[faceI]],
5176 forAll(neiCellZone, bFaceI)
5178 label faceI = bFaceI + mesh_.nInternalFaces();
5179 if (faceToZone[faceI] == -1)
5181 allocateInterRegionFaceZone
5183 cellToZone[mesh_.faceOwner()[faceI]],
5184 neiCellZone[bFaceI],
5203 Info<<
"Setting faceZones according to neighbouring cellZones:"
5209 zonesToFaceZone.
size()
5220 const word& fzName = zonesToFaceZone[cz];
5223 << cz[0] <<
' ' << cz[1] <<
nl
5224 <<
" faceZone : " << fzName <<
endl;
5234 label cz0 = cellZones.findZoneID(cz[0]);
5235 label cz1 = cellZones.findZoneID(cz[1]);
5245 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
5247 if (faceToZone[faceI] == -1)
5253 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
5254 label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
5255 if (ownZone != neiZone)
5260 || (neiZone != -1 && ownZone > neiZone)
5267 faceToZone[faceI] = fZoneLookup[key];
5271 forAll(neiCellZone, bFaceI)
5273 label faceI = bFaceI + mesh_.nInternalFaces();
5274 if (faceToZone[faceI] == -1)
5276 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
5277 label neiZone = neiCellZone[bFaceI];
5278 if (ownZone != neiZone)
5283 || (neiZone != -1 && ownZone > neiZone)
5290 faceToZone[faceI] = fZoneLookup[key];
5309 label bFaceI = pp.
start()-mesh_.nInternalFaces();
5312 neiCellZone[bFaceI++] = -1;
5333 bitSet meshFlipMap(mesh_.nFaces(),
false);
5341 freeStandingBaffleFaces
5352 if (nFreeStanding > 0)
5354 Info<<
"Detected " << nFreeStanding <<
" free-standing zone faces"
5359 OBJstream str(mesh_.time().path()/
"freeStanding.obj");
5366 calcPatchNumMasterFaces(isMasterFace,
patch, nMasterFacesPerEdge);
5371 const label
nZones = markPatchZones
5374 nMasterFacesPerEdge,
5379 for (label zoneI = 0; zoneI <
nZones; zoneI++)
5381 nPosOrientation.insert(zoneI, 0);
5387 consistentOrientation
5391 nMasterFacesPerEdge,
5392 faceToConnectedZone,
5402 label meshFaceI =
patch.addressing()[faceI];
5404 if (isMasterFace.
test(meshFaceI))
5409 posOrientation.
test(meshFaceI)
5410 == meshFlipMap.test(meshFaceI)
5416 nPosOrientation.find(faceToConnectedZone[faceI])() +=
n;
5423 Info<<
"Split " << nFreeStanding <<
" free-standing zone faces"
5424 <<
" into " <<
nZones <<
" disconnected regions with size"
5425 <<
" (negative denotes wrong orientation) :"
5428 for (label zoneI = 0; zoneI <
nZones; zoneI++)
5430 Info<<
" " << zoneI <<
"\t" << nPosOrientation[zoneI]
5438 consistentOrientation
5442 nMasterFacesPerEdge,
5443 faceToConnectedZone,
5472 mesh_.updateMesh(map());
5475 if (map().hasMotionPoints())
5477 mesh_.movePoints(map().preMotionPoints());
5489 if (mesh_.cellZones().size() > 0)
5492 forAll(mesh_.cellZones(), zoneI)
5494 const cellZone& cz = mesh_.cellZones()[zoneI];
5501 if (mesh_.faceZones().size() > 0)
5504 forAll(mesh_.faceZones(), zoneI)
5506 const faceZone& fz = mesh_.faceZones()[zoneI];