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]]))
732 Info<<
"Converting zoned faces into baffles ..." <<
endl;
745 const faceZone& fz = faceZones[zoneI];
747 const word& masterName = faceZoneToMasterPatch_[fz.
name()];
748 label masterPatchI = mesh_.boundaryMesh().findPatchID(masterName);
749 const word& slaveName = faceZoneToSlavePatch_[fz.
name()];
750 label slavePatchI = mesh_.boundaryMesh().findPatchID(slaveName);
752 if (masterPatchI == -1 || slavePatchI == -1)
755 <<
"Problem: masterPatchI:" << masterPatchI
762 if (mesh_.isInternalFace(faceI))
766 ownPatch[faceI] = slavePatchI;
767 neiPatch[faceI] = masterPatchI;
771 ownPatch[faceI] = masterPatchI;
772 neiPatch[faceI] = slavePatchI;
781 label nLocalBaffles =
sum(nBaffles);
786 if (nTotalBaffles > 0)
792 <<
setf(ios_base::left)
793 <<
setw(30) <<
"FaceZone"
794 <<
setw(10) <<
"FaceType"
795 <<
setw(10) <<
"nBaffles"
797 <<
setw(30) <<
"--------"
798 <<
setw(10) <<
"--------"
799 <<
setw(10) <<
"--------"
805 const faceZone& fz = faceZones[zoneI];
809 bool hasInfo = getFaceZoneInfo(fz.
name(), mpI, spI, fzType);
817 <<
setw(10) << nBaffles[j]
824 map = createBaffles(ownPatch, neiPatch);
830 baffles.
setSize(nLocalBaffles);
831 originatingFaceZone.
setSize(nLocalBaffles);
835 const labelList& reverseFaceMap = map().reverseFaceMap();
839 label faceI = mesh_.nInternalFaces();
840 faceI < mesh_.nFaces();
844 label oldFaceI =
faceMap[faceI];
845 label masterFaceI = reverseFaceMap[oldFaceI];
846 if (masterFaceI != faceI && ownPatch[oldFaceI] != -1)
848 baffles[baffleI] =
labelPair(masterFaceI, faceI);
849 originatingFaceZone[baffleI] =
faceZoneID[oldFaceI];
854 if (baffleI != baffles.size())
857 <<
"Had " << baffles.size() <<
" baffles to create "
858 <<
" but encountered " << baffleI
859 <<
" slave faces originating from patcheable faces."
865 const_cast<Time&
>(mesh_.time())++;
866 Pout<<
"Writing zone-baffled mesh to time " <<
timeName()
872 mesh_.time().path()/
"baffles"
876 Info<<
"Created " << nTotalBaffles <<
" baffles in = "
877 << mesh_.time().cpuTimeIncrement() <<
" s\n" <<
nl <<
endl;
882 originatingFaceZone.
clear();
892 const scalar planarAngle
919 const label baffleValue = 1000000;
934 label faceI = pp.
start();
938 const labelList& fEdges = mesh_.faceEdges(faceI);
942 nBafflesPerEdge[fEdges[fEdgeI]]++;
950 DynamicList<label> fe0;
951 DynamicList<label> fe1;
960 label f0 = couples[i].first();
961 const labelList& fEdges0 = mesh_.faceEdges(f0, fe0);
964 nBafflesPerEdge[fEdges0[fEdgeI]] += baffleValue;
969 label f1 = couples[i].second();
970 const labelList& fEdges1 = mesh_.faceEdges(f1, fe1);
973 nBafflesPerEdge[fEdges1[fEdgeI]] += baffleValue;
992 List<labelPair> filteredCouples(couples.size());
1005 const labelList& fEdges = mesh_.faceEdges(couple.first());
1009 label edgeI = fEdges[fEdgeI];
1011 if (nBafflesPerEdge[edgeI] == 2*baffleValue+2*1)
1013 filteredCouples[filterI++] = couple;
1019 filteredCouples.setSize(filterI);
1022 label nFiltered =
returnReduce(filteredCouples.size(), sumOp<label>());
1024 Info<<
"freeStandingBaffles : detected "
1026 <<
" free-standing baffles out of "
1039 const pointField& cellCentres = mesh_.cellCentres();
1041 forAll(filteredCouples, i)
1043 const labelPair& couple = filteredCouples[i];
1044 start[i] = cellCentres[mesh_.faceOwner()[couple.first()]];
1045 end[i] = cellCentres[mesh_.faceOwner()[couple.second()]];
1059 List<pointIndexHit> hit1;
1064 List<pointIndexHit> hit2;
1068 surfaces_.findNearestIntersection
1070 identity(surfaces_.surfaces().size()),
1094 forAll(filteredCouples, i)
1096 const labelPair& couple = filteredCouples[i];
1110 &&
mag(hit1[i].hitPoint()-hit2[i].hitPoint()) > mergeDistance_
1121 if ((normal1[i]&normal2[i]) > planarAngleCos)
1125 scalar magN =
mag(
n);
1128 filteredCouples[filterI++] = couple;
1132 else if (hit1[i].hit() || hit2[i].hit())
1138 filteredCouples.setSize(filterI);
1140 Info<<
"freeStandingBaffles : detected "
1142 <<
" planar (within " << planarAngle
1143 <<
" degrees) free-standing baffles out of "
1148 return filteredCouples;
1165 const faceList& faces = mesh_.faces();
1166 const labelList& faceOwner = mesh_.faceOwner();
1171 label face0 = couples[i].first();
1172 label face1 = couples[i].second();
1177 label own0 = faceOwner[face0];
1178 label own1 = faceOwner[face1];
1180 if (face1 < 0 || own0 < own1)
1184 bool zoneFlip =
false;
1192 label nei = (face1 < 0 ? -1 : own1);
1215 bool zoneFlip =
false;
1244 const label faceI = iter.key();
1245 const label patchI = iter.val();
1247 if (!mesh_.isInternalFace(faceI))
1250 <<
"problem: face:" << faceI
1251 <<
" at:" << mesh_.faceCentres()[faceI]
1252 <<
"(wanted patch:" << patchI
1257 bool zoneFlip =
false;
1284 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
1288 mesh_.updateMesh(map);
1307 labelList newExposedFaces(2*couples.size());
1315 newExposedFaces[newI++] = newFace0;
1318 const label newFace1 = map.
reverseFaceMap()[couples[i].second()];
1321 newExposedFaces[newI++] = newFace1;
1324 newExposedFaces.
setSize(newI);
1325 updateMesh(map, newExposedFaces);
1334 const bool doInternalZones,
1335 const bool doBaffleZones
1341 if (doInternalZones)
1365 mapPtr = mergeBaffles(zoneBaffles,
Map<label>(0));
1372 void Foam::meshRefinement::findCellZoneGeometric
1382 const pointField& cellCentres = mesh_.cellCentres();
1383 const labelList& faceOwner = mesh_.faceOwner();
1384 const labelList& faceNeighbour = mesh_.faceNeighbour();
1388 surfaces_.findInside
1390 closedNamedSurfaces,
1395 forAll(insideSurfaces, cellI)
1397 label surfI = insideSurfaces[cellI];
1401 if (cellToZone[cellI] == -2)
1403 cellToZone[cellI] = surfaceToCellZone[surfI];
1405 else if (cellToZone[cellI] == -1)
1410 cellToZone[cellI] = surfaceToCellZone[surfI];
1423 label nCandidates = 0;
1424 forAll(namedSurfaceRegion, faceI)
1426 if (namedSurfaceRegion[faceI] != -1)
1428 if (mesh_.isInternalFace(faceI))
1442 forAll(namedSurfaceRegion, faceI)
1444 if (namedSurfaceRegion[faceI] != -1)
1446 label own = faceOwner[faceI];
1447 const point& ownCc = cellCentres[own];
1449 if (mesh_.isInternalFace(faceI))
1451 label nei = faceNeighbour[faceI];
1452 const point& neiCc = cellCentres[nei];
1454 const vector d = 1
e-4*(neiCc - ownCc);
1455 candidatePoints[nCandidates++] = ownCc-d;
1456 candidatePoints[nCandidates++] = neiCc+d;
1461 const point& neiFc = neiCc[faceI-mesh_.nInternalFaces()];
1464 const vector d = 1
e-4*(neiFc - ownCc);
1465 candidatePoints[nCandidates++] = ownCc-d;
1473 surfaces_.findInside
1475 closedNamedSurfaces,
1484 forAll(namedSurfaceRegion, faceI)
1486 if (namedSurfaceRegion[faceI] != -1)
1488 label own = faceOwner[faceI];
1490 if (mesh_.isInternalFace(faceI))
1492 label ownSurfI = insideSurfaces[nCandidates++];
1495 cellToZone[own] = surfaceToCellZone[ownSurfI];
1498 label neiSurfI = insideSurfaces[nCandidates++];
1501 label nei = faceNeighbour[faceI];
1503 cellToZone[nei] = surfaceToCellZone[neiSurfI];
1508 label ownSurfI = insideSurfaces[nCandidates++];
1511 cellToZone[own] = surfaceToCellZone[ownSurfI];
1522 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
1524 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
1525 label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
1527 if (namedSurfaceRegion[faceI] == -1 && (ownZone != neiZone))
1537 else if (neiZone == -1)
1543 minZone =
min(ownZone, neiZone);
1548 label geomSurfI = surfaceToCellZone.find(minZone);
1550 if (geomSurfI != -1)
1552 namedSurfaceRegion[faceI] =
1553 surfaces_.globalRegion(geomSurfI, 0);
1561 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
1565 const polyPatch& pp =
patches[patchI];
1571 label faceI = pp.start()+i;
1572 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
1573 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
1575 if (namedSurfaceRegion[faceI] == -1 && (ownZone != neiZone))
1583 else if (neiZone == -1)
1589 minZone =
min(ownZone, neiZone);
1594 label geomSurfI = surfaceToCellZone.find(minZone);
1596 if (geomSurfI != -1)
1598 namedSurfaceRegion[faceI] =
1599 surfaces_.globalRegion(geomSurfI, 0);
1611 void Foam::meshRefinement::findCellZoneInsideWalk
1621 boolList blockedFace(mesh_.nFaces());
1624 forAll(blockedFace, faceI)
1626 if (faceToZone[faceI] == -1)
1628 blockedFace[faceI] =
false;
1632 blockedFace[faceI] =
true;
1638 regionSplit cellRegion(mesh_, blockedFace);
1639 blockedFace.clear();
1642 (void)mesh_.tetBasePtIs();
1645 forAll(locationsInMesh, i)
1648 const point& insidePoint = locationsInMesh[i];
1649 label
zoneID = zonesInMesh[i];
1652 label keepRegionI = findRegion
1660 Info<<
"For cellZone "
1666 <<
" found point " << insidePoint
1667 <<
" in global region " << keepRegionI
1668 <<
" out of " << cellRegion.nRegions() <<
" regions." <<
endl;
1670 if (keepRegionI == -1)
1673 <<
"Point " << insidePoint
1674 <<
" is not inside the mesh." <<
nl
1675 <<
"Bounding box of the mesh:" << mesh_.bounds()
1684 label nWarnings = 0;
1686 forAll(cellRegion, cellI)
1688 if (cellRegion[cellI] == keepRegionI)
1690 if (cellToZone[cellI] == -2)
1693 cellToZone[cellI] =
zoneID;
1695 else if (cellToZone[cellI] !=
zoneID)
1697 if (cellToZone[cellI] != -1 && nWarnings < 10)
1701 <<
" at " << mesh_.cellCentres()[cellI]
1702 <<
" is inside cellZone "
1708 <<
" from locationInMesh " << insidePoint
1709 <<
" but already marked as being in zone "
1710 << mesh_.cellZones()[cellToZone[cellI]].name()
1712 <<
"This can happen if your surfaces are not"
1713 <<
" (sufficiently) closed."
1719 cellToZone[cellI] =
zoneID;
1727 void Foam::meshRefinement::findCellZoneInsideWalk
1739 forAll(zoneNamesInMesh, i)
1741 zoneIDs[i] = czs.findZoneID(zoneNamesInMesh[i]);
1743 findCellZoneInsideWalk
1753 bool Foam::meshRefinement::calcRegionToZone
1755 const label backgroundZoneID,
1756 const label surfZoneI,
1757 const label ownRegion,
1758 const label neiRegion,
1763 bool changed =
false;
1766 if (ownRegion != neiRegion)
1773 if (regionToCellZone[ownRegion] == -2)
1775 if (surfZoneI == -1)
1780 if (regionToCellZone[neiRegion] != -2)
1782 regionToCellZone[ownRegion] = regionToCellZone[neiRegion];
1786 else if (regionToCellZone[neiRegion] == surfZoneI)
1791 if (backgroundZoneID != -2)
1793 regionToCellZone[ownRegion] = backgroundZoneID;
1797 else if (regionToCellZone[neiRegion] != -2)
1801 regionToCellZone[ownRegion] = surfZoneI;
1805 else if (regionToCellZone[neiRegion] == -2)
1807 if (surfZoneI == -1)
1812 regionToCellZone[neiRegion] = regionToCellZone[ownRegion];
1815 else if (regionToCellZone[ownRegion] == surfZoneI)
1819 if (backgroundZoneID != -2)
1821 regionToCellZone[neiRegion] = backgroundZoneID;
1825 else if (regionToCellZone[ownRegion] != -2)
1829 regionToCellZone[neiRegion] = surfZoneI;
1838 void Foam::meshRefinement::findCellZoneTopo
1840 const label backgroundZoneID,
1869 boolList blockedFace(mesh_.nFaces());
1871 forAll(unnamedSurfaceRegion, faceI)
1875 unnamedSurfaceRegion[faceI] == -1
1876 && namedSurfaceRegion[faceI] == -1
1879 blockedFace[faceI] =
false;
1883 blockedFace[faceI] =
true;
1889 regionSplit cellRegion(mesh_, blockedFace);
1890 blockedFace.clear();
1896 labelList regionToCellZone(cellRegion.nRegions(), -2);
1901 forAll(cellToZone, cellI)
1903 label regionI = cellRegion[cellI];
1904 if (cellToZone[cellI] != -2 && regionToCellZone[regionI] == -2)
1906 regionToCellZone[regionI] = cellToZone[cellI];
1920 forAll(locationsInMesh, i)
1922 const point& keepPoint = locationsInMesh[i];
1923 label keepRegionI = findRegion
1931 Info<<
"Found point " << keepPoint
1932 <<
" in global region " << keepRegionI
1933 <<
" out of " << cellRegion.nRegions() <<
" regions." <<
endl;
1935 if (keepRegionI == -1)
1938 <<
"Point " << keepPoint
1939 <<
" is not inside the mesh." <<
nl
1940 <<
"Bounding box of the mesh:" << mesh_.bounds()
1948 if (regionToCellZone[keepRegionI] == -2)
1950 regionToCellZone[keepRegionI] = -1;
1970 bool changed =
false;
1974 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
1976 label regionI = namedSurfaceRegion[faceI];
1979 if (unnamedSurfaceRegion[faceI] == -1 && regionI != -1)
1984 label surfI = surfaces_.whichSurface(regionI).first();
1986 bool changedCell = calcRegionToZone
1989 surfaceToCellZone[surfI],
1990 cellRegion[mesh_.faceOwner()[faceI]],
1991 cellRegion[mesh_.faceNeighbour()[faceI]],
1995 changed = changed | changedCell;
2001 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2011 const polyPatch& pp =
patches[patchI];
2017 label faceI = pp.start()+i;
2019 label regionI = namedSurfaceRegion[faceI];
2022 if (unnamedSurfaceRegion[faceI] == -1 && regionI != -1)
2024 label surfI = surfaces_.whichSurface(regionI).first();
2026 bool changedCell = calcRegionToZone
2029 surfaceToCellZone[surfI],
2030 cellRegion[mesh_.faceOwner()[faceI]],
2031 neiCellRegion[faceI-mesh_.nInternalFaces()],
2035 changed = changed | changedCell;
2050 Pout<<
"meshRefinement::findCellZoneTopo :"
2051 <<
" nRegions:" << regionToCellZone.size()
2052 <<
" of which visited (-1 = background, >= 0 : cellZone) :"
2055 forAll(regionToCellZone, regionI)
2057 if (regionToCellZone[regionI] != -2)
2059 Pout<<
"Region " << regionI
2060 <<
" becomes cellZone:" << regionToCellZone[regionI]
2067 forAll(cellToZone, cellI)
2069 label regionI = cellRegion[cellI];
2070 if (cellToZone[cellI] == -2 && regionToCellZone[regionI] != -2)
2072 cellToZone[cellI] = regionToCellZone[regionI];
2078 void Foam::meshRefinement::erodeCellZone
2080 const label nErodeCellZones,
2081 const label backgroundZoneID,
2098 for (label iter = 0; iter < nErodeCellZones; iter++)
2105 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
2109 unnamedSurfaceRegion[facei] == -1
2110 && namedSurfaceRegion[facei] == -1
2113 label own = mesh_.faceOwner()[facei];
2114 label nei = mesh_.faceNeighbour()[facei];
2115 if (cellToZone[own] == -2 && cellToZone[nei] >= -1)
2117 erodedCellToZone[nei] = backgroundZoneID;
2120 else if (cellToZone[nei] == -2 && cellToZone[own] >= -1)
2122 erodedCellToZone[own] = backgroundZoneID;
2130 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2140 const polyPatch& pp =
patches[patchi];
2146 label facei = pp.start()+i;
2149 unnamedSurfaceRegion[facei] == -1
2150 && namedSurfaceRegion[facei] == -1
2153 label own = mesh_.faceOwner()[facei];
2154 label bFacei = facei-mesh_.nInternalFaces();
2155 if (neiCellZone[bFacei] == -2 && cellToZone[own] >= -1)
2157 erodedCellToZone[own] = backgroundZoneID;
2165 cellToZone.transfer(erodedCellToZone);
2167 reduce(nChanged, sumOp<label>());
2170 Pout<<
"erodeCellZone : eroded " << nChanged
2171 <<
" cells (moved from cellZone to background zone "
2172 << backgroundZoneID <<
endl;
2183 void Foam::meshRefinement::growCellZone
2185 const label nGrowCellZones,
2186 const label backgroundZoneID,
2193 if (nGrowCellZones != 1)
2196 <<
"Growing currently only supported for single layer."
2197 <<
" Exiting zone growing" <<
endl;
2214 const FixedList<label, 3> wallTag
2224 List<FixedList<label, 3>> surfaces(1);
2244 List<wallPoints> allCellInfo(mesh_.nCells());
2245 forAll(cellToZone, celli)
2247 if (cellToZone[celli] >= 0)
2249 const FixedList<label, 3> zoneTag
2256 origins[0] = mesh_.cellCentres()[celli];
2258 surfaces[0] = zoneTag;
2259 allCellInfo[celli] = wallPoints(origins, distSqrs, surfaces);
2264 DynamicList<wallPoints> faceDist(mesh_.nFaces()/128);
2265 DynamicList<label> changedFaces(mesh_.nFaces()/128);
2267 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
2269 const label own = mesh_.faceOwner()[facei];
2270 const label nei = mesh_.faceNeighbour()[facei];
2271 if (cellToZone[own] >= 0 && cellToZone[nei] < 0)
2275 origins[0] = mesh_.faceCentres()[facei];
2277 surfaces[0] = FixedList<label, 3>
2283 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2284 changedFaces.append(facei);
2286 else if (cellToZone[own] < 0 && cellToZone[nei] >= 0)
2290 origins[0] = mesh_.faceCentres()[facei];
2292 surfaces[0] = FixedList<label, 3>
2298 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2299 changedFaces.append(facei);
2303 unnamedSurfaceRegion1[facei] != -1
2304 || unnamedSurfaceRegion2[facei] != -1
2309 origins[0] = mesh_.faceCentres()[facei];
2311 surfaces[0] = wallTag;
2312 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2313 changedFaces.append(facei);
2321 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2327 const polyPatch& pp =
patches[patchi];
2334 label facei = pp.start()+i;
2335 label own = mesh_.faceOwner()[facei];
2336 label bFacei = facei-mesh_.nInternalFaces();
2337 if (cellToZone[own] >= 0 && neiCellZone[bFacei] < 0)
2339 origins[0] = mesh_.faceCentres()[facei];
2341 surfaces[0] = FixedList<label, 3>
2347 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2348 changedFaces.append(facei);
2350 else if (cellToZone[own] < 0 && neiCellZone[bFacei] >= 0)
2356 unnamedSurfaceRegion1[facei] != -1
2357 || unnamedSurfaceRegion2[facei] != -1
2361 origins[0] = mesh_.faceCentres()[facei];
2363 surfaces[0] = wallTag;
2364 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2365 changedFaces.append(facei);
2374 label facei = pp.start()+i;
2375 label own = mesh_.faceOwner()[facei];
2376 if (cellToZone[own] < 0)
2378 origins[0] = mesh_.faceCentres()[facei];
2380 surfaces[0] = wallTag;
2381 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2382 changedFaces.append(facei);
2389 List<wallPoints> allFaceInfo(mesh_.nFaces());
2390 FaceCellWave<wallPoints> wallDistCalc
2399 wallDistCalc.iterate(nGrowCellZones);
2406 bitSet isChangedCell(mesh_.nCells());
2408 forAll(allCellInfo, celli)
2410 if (allCellInfo[celli].valid(wallDistCalc.data()))
2412 const List<FixedList<label, 3>>& surfaces =
2413 allCellInfo[celli].surface();
2415 if (surfaces.size())
2419 isChangedCell.set(celli);
2422 if (surfaces.size() > 1)
2428 for (label i = 0; i < surfaces.size(); i++)
2430 const label zonei = surfaces[i][0];
2431 const scalar d2 = allCellInfo[celli].distSqr()[i];
2432 if (zonei != cellToZone[celli] && d2 < minDistSqr)
2441 if (minZone != cellToZone[celli] && minZone != wallTag[0])
2443 cellToZone[celli] = minZone;
2444 isChangedCell.set(celli);
2452 if (backgroundZoneID != -2)
2454 forAll(cellToZone, celli)
2456 if (cellToZone[celli] == -2)
2458 cellToZone[celli] = backgroundZoneID;
2471 for (
const label celli : isChangedCell)
2473 const cell& cFaces = mesh_.cells()[celli];
2474 for (
const label facei : cFaces)
2476 const label own = mesh_.faceOwner()[facei];
2477 const label ownZone = cellToZone[own];
2480 if (mesh_.isInternalFace(facei))
2482 const label neiZone = cellToZone[mesh_.faceNeighbour()[facei]];
2483 nbrZone = (own != celli ? ownZone : neiZone);
2487 nbrZone = neiCellZone[facei-mesh_.nInternalFaces()];
2490 if (nbrZone == cellToZone[celli])
2494 unnamedSurfaceRegion1[facei] != -1
2495 || unnamedSurfaceRegion2[facei] != -1
2498 unnamedSurfaceRegion1[facei] = -1;
2499 unnamedSurfaceRegion2[facei] = -1;
2504 namedSurfaceRegion.size()
2505 && namedSurfaceRegion[facei] != -1
2508 namedSurfaceRegion[facei] = -1;
2515 reduce(nUnnamed, sumOp<label>());
2516 reduce(nNamed, sumOp<label>());
2522 unnamedSurfaceRegion1,
2528 unnamedSurfaceRegion2,
2531 if (namedSurfaceRegion.size())
2543 Pout<<
"growCellZone : grown cellZones by "
2545 <<
" cells (moved from background to nearest cellZone)"
2547 Pout<<
"growCellZone : unmarked " << nUnnamed
2548 <<
" unzoned intersections; " << nNamed <<
" zoned intersections; "
2554 void Foam::meshRefinement::makeConsistentFaceIndex
2569 const labelList& faceOwner = mesh_.faceOwner();
2570 const labelList& faceNeighbour = mesh_.faceNeighbour();
2572 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
2574 label ownZone = cellToZone[faceOwner[faceI]];
2575 label neiZone = cellToZone[faceNeighbour[faceI]];
2576 label globalI = namedSurfaceRegion[faceI];
2582 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2585 namedSurfaceRegion[faceI] = -1;
2589 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2598 const polyPatch& pp =
patches[patchI];
2604 label faceI = pp.start()+i;
2606 label ownZone = cellToZone[faceOwner[faceI]];
2607 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
2608 label globalI = namedSurfaceRegion[faceI];
2614 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2617 namedSurfaceRegion[faceI] = -1;
2626 label faceI = pp.start()+i;
2627 label globalI = namedSurfaceRegion[faceI];
2632 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2635 namedSurfaceRegion[faceI] = -1;
2643 void Foam::meshRefinement::getIntersections
2650 bitSet& posOrientation
2653 namedSurfaceRegion.setSize(mesh_.nFaces());
2654 namedSurfaceRegion = -1;
2656 posOrientation.setSize(mesh_.nFaces());
2657 posOrientation =
false;
2688 List<pointIndexHit> hit1;
2692 List<pointIndexHit> hit2;
2695 surfaces_.findNearestIntersection
2714 label faceI = testFaces[i];
2715 const vector&
area = mesh_.faceAreas()[faceI];
2717 if (surface1[i] != -1)
2724 magSqr(hit2[i].hitPoint())
2725 <
magSqr(hit1[i].hitPoint())
2729 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2734 posOrientation.
set(faceI, ((
area&normal2[i]) > 0));
2735 nSurfFaces[surface2[i]]++;
2739 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2744 posOrientation.set(faceI, ((
area&normal1[i]) > 0));
2745 nSurfFaces[surface1[i]]++;
2748 else if (surface2[i] != -1)
2750 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2755 posOrientation.set(faceI, ((
area&normal2[i]) > 0));
2756 nSurfFaces[surface2[i]]++;
2775 forAll(nSurfFaces, surfI)
2778 << surfaces_.names()[surfI]
2779 <<
" nZoneFaces:" << nSurfFaces[surfI] <<
nl;
2786 void Foam::meshRefinement::zonify
2788 const bool allowFreeStandingZoneFaces,
2789 const label nErodeCellZones,
2790 const label backgroundZoneID,
2798 bitSet& posOrientation
2811 const PtrList<surfaceZonesInfo>& surfZones = surfaces_.surfZones();
2814 labelList neiLevel(mesh_.nBoundaryFaces());
2816 calcNeighbourData(neiLevel, neiCc);
2824 if (namedSurfaces.size())
2836 cellToZone.setSize(mesh_.nCells());
2839 namedSurfaceRegion.clear();
2840 posOrientation.clear();
2857 if (namedSurfaces.size())
2873 if (locationsInMesh.size())
2875 Info<<
"Setting cellZones according to locationsInMesh:" <<
endl;
2877 labelList locationsZoneIDs(zonesInMesh.size(), -1);
2878 forAll(locationsInMesh, i)
2880 const word&
name = zonesInMesh[i];
2882 Info<<
"Location : " << locationsInMesh[i] <<
nl
2887 label
zoneID = mesh_.cellZones().findZoneID(
name);
2892 locationsZoneIDs[i] =
zoneID;
2899 findCellZoneInsideWalk
2916 if (locationSurfaces.size())
2918 Info<<
"Found " << locationSurfaces.size()
2919 <<
" named surfaces with a provided inside point."
2920 <<
" Assigning cells inside these surfaces"
2921 <<
" to the corresponding cellZone."
2926 labelList insidePointCellZoneIDs(locationSurfaces.size(), -1);
2927 forAll(locationSurfaces, i)
2929 label surfI = locationSurfaces[i];
2932 const word&
name = surfZones[surfI].cellZoneName();
2935 label
zoneID = mesh_.cellZones().findZoneID(
name);
2942 insidePointCellZoneIDs[i] =
zoneID;
2948 labelList allRegion1(mesh_.nFaces(), -1);
2949 forAll(namedSurfaceRegion, faceI)
2951 allRegion1[faceI] =
max
2953 unnamedRegion1[faceI],
2954 namedSurfaceRegion[faceI]
2958 findCellZoneInsideWalk
2961 insidePointCellZoneIDs,
2977 surfaces_.geometry(),
2978 surfaces_.surfaces()
2982 if (closedNamedSurfaces.size())
2984 Info<<
"Found " << closedNamedSurfaces.size()
2985 <<
" closed, named surfaces. Assigning cells in/outside"
2986 <<
" these surfaces to the corresponding cellZone."
2989 findCellZoneGeometric
2992 closedNamedSurfaces,
3003 if (namedSurfaces.size())
3005 if (nErodeCellZones == 0)
3007 Info<<
"Walking from known cellZones; crossing a faceZone "
3008 <<
"face changes cellZone" <<
nl <<
endl;
3021 else if (nErodeCellZones < 0)
3023 Info<<
"Growing cellZones by " << -nErodeCellZones
3024 <<
" layers" <<
nl <<
endl;
3038 Info<<
"Eroding cellZone cells to make these consistent with"
3039 <<
" faceZone faces" <<
nl <<
endl;
3055 if (!allowFreeStandingZoneFaces)
3057 Info<<
"Only keeping zone faces inbetween different cellZones."
3071 labelList surfaceMap(surfZones.size(), -1);
3072 forAll(standaloneNamedSurfaces, i)
3074 surfaceMap[standaloneNamedSurfaces[i]] = i;
3077 makeConsistentFaceIndex
3085 else if (nErodeCellZones < 0 &&
gMax(cellToZone) >= 0)
3090 Info<<
"Growing cellZones by " << -nErodeCellZones
3091 <<
" layers" <<
nl <<
endl;
3104 if (!allowFreeStandingZoneFaces && namedSurfaceRegion.size())
3106 Info<<
"Only keeping zone faces inbetween different cellZones."
3120 labelList surfaceMap(surfZones.size(), -1);
3121 forAll(standaloneNamedSurfaces, i)
3123 surfaceMap[standaloneNamedSurfaces[i]] = i;
3126 makeConsistentFaceIndex
3141 label nUnvisited = 0;
3142 label nBackgroundCells = 0;
3144 forAll(cellToZone, cellI)
3146 label zoneI = cellToZone[cellI];
3149 nZoneCells[zoneI]++;
3151 else if (zoneI == -1)
3155 else if (zoneI == -2)
3165 reduce(nUnvisited, sumOp<label>());
3166 reduce(nBackgroundCells, sumOp<label>());
3167 forAll(nZoneCells, zoneI)
3169 reduce(nZoneCells[zoneI], sumOp<label>());
3171 Info<<
"nUnvisited :" << nUnvisited <<
endl;
3172 Info<<
"nBackgroundCells:" << nBackgroundCells <<
endl;
3173 Info<<
"nZoneCells :" << nZoneCells <<
endl;
3177 const_cast<Time&
>(mesh_.time())++;
3178 Pout<<
"Writing cell zone allocation on mesh to time "
3183 writeType(writeLevel() | WRITEMESH),
3184 mesh_.time().path()/
"cell2Zone"
3199 zeroGradientFvPatchScalarField::typeName
3202 forAll(cellToZone, cellI)
3204 volCellToZone[cellI] = cellToZone[cellI];
3206 volCellToZone.write();
3308 void Foam::meshRefinement::handleSnapProblems
3310 const snapParameters& snapParams,
3311 const bool useTopologicalSnapDetection,
3312 const bool removeEdgeConnectedCells,
3314 const dictionary& motionDict,
3321 <<
"Introducing baffles to block off problem cells" <<
nl
3322 <<
"----------------------------------------------" <<
nl
3326 if (useTopologicalSnapDetection)
3328 facePatch = markFacesOnProblemCells
3331 removeEdgeConnectedCells,
3338 facePatch = markFacesOnProblemCellsGeometric
3342 globalToMasterPatch,
3346 Info<<
"Analyzed problem cells in = "
3351 faceSet problemFaces(mesh_,
"problemFaces", mesh_.nFaces()/100);
3355 if (facePatch[faceI] != -1)
3357 problemFaces.insert(faceI);
3360 problemFaces.instance() =
timeName();
3361 Pout<<
"Dumping " << problemFaces.size()
3362 <<
" problem faces to " << problemFaces.objectPath() <<
endl;
3363 problemFaces.
write();
3366 Info<<
"Introducing baffles to delete problem cells." <<
nl <<
endl;
3374 createBaffles(facePatch, facePatch);
3381 Info<<
"Created baffles in = "
3384 printMeshInfo(
debug,
"After introducing baffles");
3388 const_cast<Time&
>(mesh_.time())++;
3389 Pout<<
"Writing extra baffled mesh to time "
3394 writeType(writeLevel() | WRITEMESH),
3397 Pout<<
"Dumped debug data in = "
3410 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
3411 const labelList& faceOwner = mesh_.faceOwner();
3412 const labelList& faceNeighbour = mesh_.faceNeighbour();
3429 DynamicList<label> faceLabels(mesh_.nFaces()/100);
3431 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
3433 if (faceToZone[faceI] != -1)
3436 label ownZone = cellToZone[faceOwner[faceI]];
3437 label neiZone = cellToZone[faceNeighbour[faceI]];
3438 if (ownZone == neiZone)
3440 faceLabels.
append(faceI);
3446 const polyPatch& pp =
patches[patchI];
3450 label faceI = pp.start()+i;
3451 if (faceToZone[faceI] != -1)
3454 label ownZone = cellToZone[faceOwner[faceI]];
3455 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
3456 if (ownZone == neiZone)
3458 faceLabels.append(faceI);
3463 return faceLabels.shrink();
3467 void Foam::meshRefinement::calcPatchNumMasterFaces
3469 const bitSet& isMasterFace,
3475 nMasterFacesPerEdge.setSize(
patch.nEdges());
3476 nMasterFacesPerEdge = 0;
3480 const label meshFaceI =
patch.addressing()[faceI];
3482 if (isMasterFace.test(meshFaceI))
3487 nMasterFacesPerEdge[fEdges[fEdgeI]]++;
3495 patch.meshEdges(mesh_.edges(), mesh_.pointEdges()),
3496 nMasterFacesPerEdge,
3503 Foam::label Foam::meshRefinement::markPatchZones
3510 List<edgeTopoDistanceData<label>> allEdgeInfo(
patch.nEdges());
3511 List<edgeTopoDistanceData<label>> allFaceInfo(
patch.size());
3516 label nProtected = 0;
3518 forAll(nMasterFacesPerEdge, edgeI)
3520 if (nMasterFacesPerEdge[edgeI] > 2)
3522 allEdgeInfo[edgeI] = edgeTopoDistanceData<label>(0, -2);
3534 DynamicList<label> changedEdges;
3535 DynamicList<edgeTopoDistanceData<label>> changedInfo;
3537 const scalar tol = PatchEdgeFaceWave
3540 edgeTopoDistanceData<label>
3541 >::propagationTol();
3545 const globalIndex globalFaces(
patch.size());
3549 label currentZoneI = 0;
3555 for (; faceI < allFaceInfo.size(); faceI++)
3557 if (!allFaceInfo[faceI].valid(dummyTrackData))
3559 globalSeed = globalFaces.toGlobal(faceI);
3564 reduce(globalSeed, minOp<label>());
3571 label procI = globalFaces.whichProcID(globalSeed);
3572 label seedFaceI = globalFaces.toLocal(procI, globalSeed);
3580 edgeTopoDistanceData<label>& faceInfo = allFaceInfo[seedFaceI];
3584 faceInfo = edgeTopoDistanceData<label>(0, currentZoneI);
3590 label edgeI = fEdges[fEdgeI];
3592 edgeTopoDistanceData<label>& edgeInfo = allEdgeInfo[edgeI];
3596 edgeInfo.updateEdge<
int>
3608 changedEdges.append(edgeI);
3609 changedInfo.append(edgeInfo);
3615 if (
returnReduce(changedEdges.size(), sumOp<label>()) == 0)
3625 edgeTopoDistanceData<label>
3641 faceToZone.setSize(
patch.size());
3642 forAll(allFaceInfo, faceI)
3644 if (!allFaceInfo[faceI].valid(dummyTrackData))
3647 <<
"Problem: unvisited face " << faceI
3648 <<
" at " <<
patch.faceCentres()[faceI]
3651 faceToZone[faceI] = allFaceInfo[faceI].data();
3654 return currentZoneI;
3658 void Foam::meshRefinement::consistentOrientation
3660 const bitSet& isMasterFace,
3664 const Map<label>& zoneToOrientation,
3668 const polyBoundaryMesh& bm = mesh_.boundaryMesh();
3671 List<patchFaceOrientation> allEdgeInfo(
patch.nEdges());
3672 List<patchFaceOrientation> allFaceInfo(
patch.size());
3678 label nProtected = 0;
3682 const label meshFaceI =
patch.addressing()[faceI];
3683 const label patchI = bm.whichPatch(meshFaceI);
3688 && bm[patchI].coupled()
3689 && !isMasterFace.test(meshFaceI)
3702 label nProtected = 0;
3704 forAll(nMasterFacesPerEdge, edgeI)
3706 if (nMasterFacesPerEdge[edgeI] > 2)
3713 Info<<
"Protected from visiting "
3715 <<
" non-manifold edges" <<
nl <<
endl;
3720 DynamicList<label> changedEdges;
3721 DynamicList<patchFaceOrientation> changedInfo;
3723 const scalar tol = PatchEdgeFaceWave
3726 patchFaceOrientation
3727 >::propagationTol();
3731 globalIndex globalFaces(
patch.size());
3737 forAll(allFaceInfo, faceI)
3741 globalSeed = globalFaces.toGlobal(faceI);
3746 reduce(globalSeed, minOp<label>());
3753 label procI = globalFaces.whichProcID(globalSeed);
3754 label seedFaceI = globalFaces.toLocal(procI, globalSeed);
3763 patchFaceOrientation& faceInfo = allFaceInfo[seedFaceI];
3768 if (zoneToOrientation[faceToZone[seedFaceI]] < 0)
3777 label edgeI = fEdges[fEdgeI];
3779 patchFaceOrientation& edgeInfo = allEdgeInfo[edgeI];
3783 edgeInfo.updateEdge<
int>
3795 changedEdges.append(edgeI);
3796 changedInfo.append(edgeInfo);
3802 if (
returnReduce(changedEdges.size(), sumOp<label>()) == 0)
3813 patchFaceOrientation
3831 mesh_.nBoundaryFaces(),
3837 const label meshFaceI =
patch.addressing()[i];
3838 if (!mesh_.isInternalFace(meshFaceI))
3840 neiStatus[meshFaceI-mesh_.nInternalFaces()] =
3841 allFaceInfo[i].flipStatus();
3848 const label meshFaceI =
patch.addressing()[i];
3849 const label patchI = bm.whichPatch(meshFaceI);
3854 && bm[patchI].coupled()
3855 && !isMasterFace.test(meshFaceI)
3859 label bFaceI = meshFaceI-mesh_.nInternalFaces();
3872 <<
"Incorrect status for face " << meshFaceI
3882 meshFlipMap.setSize(mesh_.nFaces());
3883 meshFlipMap =
false;
3885 forAll(allFaceInfo, faceI)
3887 label meshFaceI =
patch.addressing()[faceI];
3891 meshFlipMap.unset(meshFaceI);
3895 meshFlipMap.set(meshFaceI);
3900 <<
"Problem : unvisited face " << faceI
3901 <<
" centre:" << mesh_.faceCentres()[meshFaceI]
3908 void Foam::meshRefinement::zonify
3911 const bitSet& isMasterFace,
3915 const bitSet& meshFlipMap,
3916 polyTopoChange& meshMod
3919 const labelList& faceOwner = mesh_.faceOwner();
3920 const labelList& faceNeighbour = mesh_.faceNeighbour();
3922 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
3924 label faceZoneI = faceToZone[faceI];
3926 if (faceZoneI != -1)
3932 label ownZone = cellToZone[faceOwner[faceI]];
3933 label neiZone = cellToZone[faceNeighbour[faceI]];
3937 if (ownZone == neiZone)
3940 flip = meshFlipMap.test(faceI);
3947 || (neiZone != -1 && ownZone > neiZone)
3955 mesh_.faces()[faceI],
3958 faceNeighbour[faceI],
3970 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
3975 const polyPatch& pp =
patches[patchI];
3977 label faceI = pp.
start();
3981 label faceZoneI = faceToZone[faceI];
3983 if (faceZoneI != -1)
3985 label ownZone = cellToZone[faceOwner[faceI]];
3986 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
3990 if (ownZone == neiZone)
3993 flip = meshFlipMap.test(faceI);
4000 || (neiZone != -1 && ownZone > neiZone)
4008 mesh_.faces()[faceI],
4028 forAll(cellToZone, cellI)
4030 label zoneI = cellToZone[cellI];
4048 void Foam::meshRefinement::allocateInterRegionFaceZone
4050 const label ownZone,
4051 const label neiZone,
4053 LabelPairMap<word>& zoneIDsToFaceZone
4058 if (ownZone != neiZone)
4065 || (neiZone != -1 && ownZone > neiZone)
4075 if (!zoneIDsToFaceZone.found(key))
4078 const word ownZoneName =
4081 ? cellZones[ownZone].name()
4084 const word neiZoneName =
4087 ? cellZones[neiZone].name()
4092 Pair<word> wordKey(ownZoneName, neiZoneName);
4098 word fzName = wordKey.first() +
"_to_" + wordKey.second();
4100 zoneIDsToFaceZone.insert(key, fzName);
4101 zonesToFaceZone.insert(wordKey, fzName);
4111 const bool doHandleSnapProblems,
4113 const bool useTopologicalSnapDetection,
4114 const bool removeEdgeConnectedCells,
4116 const label nErodeCellZones,
4134 Info<<
"Introducing baffles for "
4136 <<
" faces that are intersected by the surface." <<
nl <<
endl;
4139 labelList neiLevel(mesh_.nBoundaryFaces());
4141 calcNeighbourData(neiLevel, neiCc);
4147 globalToMasterPatch,
4159 createBaffles(ownPatch, neiPatch);
4167 Info<<
"Created baffles in = "
4170 printMeshInfo(
debug,
"After introducing baffles");
4174 const_cast<Time&
>(mesh_.time())++;
4183 Pout<<
"Dumped debug data in = "
4193 if (doHandleSnapProblems)
4198 useTopologicalSnapDetection,
4199 removeEdgeConnectedCells,
4203 globalToMasterPatch,
4211 neiLevel.setSize(mesh_.nBoundaryFaces());
4212 neiCc.setSize(mesh_.nBoundaryFaces());
4213 calcNeighbourData(neiLevel, neiCc);
4219 globalToMasterPatch,
4231 createBaffles(ownPatch, neiPatch);
4246 <<
"Remove unreachable sections of mesh" <<
nl
4247 <<
"-----------------------------------" <<
nl
4257 globalToMasterPatch,
4260 locationsOutsideMesh,
4270 Info<<
"Split mesh in = "
4273 printMeshInfo(
debug,
"After subsetting");
4286 Pout<<
"Dumped debug data in = "
4295 const bool useTopologicalSnapDetection,
4296 const bool removeEdgeConnectedCells,
4298 const scalar planarAngle,
4312 <<
"Merge free-standing baffles" <<
nl
4313 <<
"---------------------------" <<
nl
4327 label nCouples = couples.size();
4330 Info<<
"Detected free-standing baffles : " << nCouples <<
endl;
4344 useTopologicalSnapDetection,
4345 removeEdgeConnectedCells,
4349 globalToMasterPatch,
4357 <<
"Remove unreachable sections of mesh" <<
nl
4358 <<
"-----------------------------------" <<
nl
4368 globalToMasterPatch,
4371 locationsOutsideMesh,
4383 Info<<
"Merged free-standing baffles in = "
4390 const label nBufferLayers,
4391 const label nErodeCellZones,
4405 labelList neiLevel(mesh_.nBoundaryFaces());
4407 calcNeighbourData(neiLevel, neiCc);
4414 globalToMasterPatch,
4427 boolList blockedFace(mesh_.nFaces(),
false);
4431 if (ownPatch[faceI] != -1 || neiPatch[faceI] != -1)
4433 blockedFace[faceI] =
true;
4447 locationsOutsideMesh,
4458 globalToMasterPatch,
4468 const label nBufferLayers,
4483 const labelList& faceOwner = mesh_.faceOwner();
4484 const labelList& faceNeighbour = mesh_.faceNeighbour();
4487 label defaultPatch = 0;
4488 if (globalToMasterPatch.size())
4490 defaultPatch = globalToMasterPatch[0];
4493 for (label i = 0; i < nBufferLayers; i++)
4497 labelList pointBaffle(mesh_.nPoints(), -1);
4499 forAll(faceNeighbour, faceI)
4501 const face&
f = mesh_.faces()[faceI];
4503 label ownRegion = cellRegion[faceOwner[faceI]];
4504 label neiRegion = cellRegion[faceNeighbour[faceI]];
4506 if (ownRegion == -1 && neiRegion != -1)
4513 pointBaffle[
f[fp]] =
max(defaultPatch, ownPatch[faceI]);
4516 else if (ownRegion != -1 && neiRegion == -1)
4518 label newPatchI = neiPatch[faceI];
4519 if (newPatchI == -1)
4521 newPatchI =
max(defaultPatch, ownPatch[faceI]);
4525 pointBaffle[
f[fp]] = newPatchI;
4531 label faceI = mesh_.nInternalFaces();
4532 faceI < mesh_.nFaces();
4536 const face&
f = mesh_.faces()[faceI];
4538 label ownRegion = cellRegion[faceOwner[faceI]];
4540 if (ownRegion == -1)
4544 pointBaffle[
f[fp]] =
max(defaultPatch, ownPatch[faceI]);
4563 forAll(pointFaces, pointI)
4565 if (pointBaffle[pointI] != -1)
4571 label faceI =
pFaces[pFaceI];
4573 if (ownPatch[faceI] == -1)
4575 ownPatch[faceI] = pointBaffle[pointI];
4589 if (ownPatch[faceI] != -1)
4591 label own = faceOwner[faceI];
4593 if (cellRegion[own] == -1)
4597 const cell& ownFaces = mesh_.cells()[own];
4600 if (ownPatch[ownFaces[j]] == -1)
4602 newOwnPatch[ownFaces[j]] = ownPatch[faceI];
4606 if (mesh_.isInternalFace(faceI))
4608 label nei = faceNeighbour[faceI];
4610 if (cellRegion[nei] == -1)
4614 const cell& neiFaces = mesh_.cells()[nei];
4617 if (ownPatch[neiFaces[j]] == -1)
4619 newOwnPatch[neiFaces[j]] = ownPatch[faceI];
4638 DynamicList<label> cellsToRemove(mesh_.nCells());
4639 forAll(cellRegion, cellI)
4641 if (cellRegion[cellI] == -1)
4643 cellsToRemove.append(cellI);
4646 cellsToRemove.shrink();
4648 label nCellsToKeep = mesh_.nCells() - cellsToRemove.size();
4649 reduce(nCellsToKeep, sumOp<label>());
4651 Info<<
"Keeping all cells containing inside points" <<
endl
4652 <<
"Selected for keeping : " << nCellsToKeep <<
" cells." <<
endl;
4656 removeCells cellRemover(mesh_);
4659 labelList exposedFaces(cellRemover.getExposedFaces(cellsToRemove));
4660 labelList exposedPatches(exposedFaces.size());
4664 label faceI = exposedFaces[i];
4666 if (ownPatch[faceI] != -1)
4668 exposedPatches[i] = ownPatch[faceI];
4673 <<
"For exposed face " << faceI
4674 <<
" fc:" << mesh_.faceCentres()[faceI]
4675 <<
" found no patch." <<
endl
4676 <<
" Taking patch " << defaultPatch
4677 <<
" instead." <<
endl;
4678 exposedPatches[i] = defaultPatch;
4682 return doRemoveCells
4694 const label nBufferLayers,
4695 const label nErodeCellZones,
4706 labelList neiLevel(mesh_.nBoundaryFaces());
4708 calcNeighbourData(neiLevel, neiCc);
4715 globalToMasterPatch,
4731 limitShells_.findLevel
4733 mesh_.cellCentres(),
4737 forAll(levelShell, celli)
4739 if (levelShell[celli] != -1)
4742 cellRegion[celli] = -1;
4749 globalToMasterPatch,
4758 const_cast<Time&
>(mesh_.time())++;
4759 Pout<<
"Writing mesh after removing limitShells"
4790 Info<<
"dupNonManifoldPoints : Found : " << nNonManifPoints
4791 <<
" non-manifold points (out of "
4792 << mesh_.globalData().nTotalPoints()
4798 if (nNonManifPoints)
4807 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
4811 mesh_.updateMesh(map);
4850 label nPointPairs = 0;
4851 forAll(pointToDuplicate, pointI)
4853 label otherPointI = pointToDuplicate[pointI];
4854 if (otherPointI != -1)
4865 forAll(pointToDuplicate, pointI)
4867 label otherPointI = pointToDuplicate[pointI];
4868 if (otherPointI != -1)
4871 pointToMaster.insert(pointI, otherPointI);
4882 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
4886 mesh_.updateMesh(map);
4933 internalOrBaffleFaceZones = getZones(fzTypes);
4943 forAll(boundaryFaceZones, j)
4945 const faceZone& fZone = mesh_.faceZones()[boundaryFaceZones[j]];
4948 const face&
f = mesh_.faces()[fZone[i]];
4951 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 1u);
4955 forAll(internalOrBaffleFaceZones, j)
4957 const faceZone& fZone = mesh_.faceZones()[internalOrBaffleFaceZones[j]];
4960 const face&
f = mesh_.faces()[fZone[i]];
4963 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 2u);
4978 forAll(pointStatus, pointI)
4980 if (pointStatus[pointI] == 1u)
4987 Info<<
"Duplicating " << globalNPoints <<
" points on"
4988 <<
" faceZones of type "
4998 forAll(pointStatus, pointI)
5000 if (pointStatus[pointI] == 1u)
5002 candidatePoints[
n++] = pointI;
5015 const bool allowFreeStandingZoneFaces,
5016 const label nErodeCellZones,
5022 if (locationsInMesh.size() != zonesInMesh.size())
5032 labelList neiLevel(mesh_.nBoundaryFaces());
5034 calcNeighbourData(neiLevel, neiCc);
5043 if (namedSurfaces.size())
5045 Info<<
"Setting cellZones according to named surfaces:" <<
endl;
5048 label surfI = namedSurfaces[i];
5050 Info<<
"Surface : " << surfaces_.names()[surfI] <<
nl
5051 <<
" faceZones : " << surfZones[surfI].faceZoneNames() <<
nl
5052 <<
" cellZone : " << surfZones[surfI].cellZoneName()
5093 allowFreeStandingZoneFaces,
5112 labelList faceToZone(mesh_.nFaces(), -1);
5114 forAll(namedSurfaceRegion, faceI)
5117 label globalI = namedSurfaceRegion[faceI];
5120 const labelPair spr = surfaces_.whichSurface(globalI);
5121 faceToZone[faceI] = surfaceToFaceZones[spr.first()][spr.
second()];
5135 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
5137 if (faceToZone[faceI] == -1)
5142 allocateInterRegionFaceZone
5144 cellToZone[mesh_.faceOwner()[faceI]],
5145 cellToZone[mesh_.faceNeighbour()[faceI]],
5155 forAll(neiCellZone, bFaceI)
5157 label faceI = bFaceI + mesh_.nInternalFaces();
5158 if (faceToZone[faceI] == -1)
5160 allocateInterRegionFaceZone
5162 cellToZone[mesh_.faceOwner()[faceI]],
5163 neiCellZone[bFaceI],
5182 Info<<
"Setting faceZones according to neighbouring cellZones:"
5188 zonesToFaceZone.
size()
5199 const word& fzName = zonesToFaceZone[cz];
5202 << cz[0] <<
' ' << cz[1] <<
nl
5203 <<
" faceZone : " << fzName <<
endl;
5213 label cz0 = cellZones.findZoneID(cz[0]);
5214 label cz1 = cellZones.findZoneID(cz[1]);
5224 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
5226 if (faceToZone[faceI] == -1)
5232 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
5233 label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
5234 if (ownZone != neiZone)
5239 || (neiZone != -1 && ownZone > neiZone)
5246 faceToZone[faceI] = fZoneLookup[key];
5250 forAll(neiCellZone, bFaceI)
5252 label faceI = bFaceI + mesh_.nInternalFaces();
5253 if (faceToZone[faceI] == -1)
5255 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
5256 label neiZone = neiCellZone[bFaceI];
5257 if (ownZone != neiZone)
5262 || (neiZone != -1 && ownZone > neiZone)
5269 faceToZone[faceI] = fZoneLookup[key];
5288 label bFaceI = pp.
start()-mesh_.nInternalFaces();
5291 neiCellZone[bFaceI++] = -1;
5312 bitSet meshFlipMap(mesh_.nFaces(),
false);
5320 freeStandingBaffleFaces
5331 if (nFreeStanding > 0)
5333 Info<<
"Detected " << nFreeStanding <<
" free-standing zone faces"
5338 OBJstream str(mesh_.time().path()/
"freeStanding.obj");
5345 calcPatchNumMasterFaces(isMasterFace,
patch, nMasterFacesPerEdge);
5350 const label
nZones = markPatchZones
5353 nMasterFacesPerEdge,
5358 for (label zoneI = 0; zoneI <
nZones; zoneI++)
5360 nPosOrientation.insert(zoneI, 0);
5366 consistentOrientation
5370 nMasterFacesPerEdge,
5371 faceToConnectedZone,
5381 label meshFaceI =
patch.addressing()[faceI];
5383 if (isMasterFace.
test(meshFaceI))
5388 posOrientation.
test(meshFaceI)
5389 == meshFlipMap.test(meshFaceI)
5395 nPosOrientation.find(faceToConnectedZone[faceI])() +=
n;
5402 Info<<
"Split " << nFreeStanding <<
" free-standing zone faces"
5403 <<
" into " <<
nZones <<
" disconnected regions with size"
5404 <<
" (negative denotes wrong orientation) :"
5407 for (label zoneI = 0; zoneI <
nZones; zoneI++)
5409 Info<<
" " << zoneI <<
"\t" << nPosOrientation[zoneI]
5417 consistentOrientation
5421 nMasterFacesPerEdge,
5422 faceToConnectedZone,
5451 mesh_.updateMesh(map());
5454 if (map().hasMotionPoints())
5456 mesh_.movePoints(map().preMotionPoints());
5468 if (mesh_.cellZones().size() > 0)
5471 forAll(mesh_.cellZones(), zoneI)
5473 const cellZone& cz = mesh_.cellZones()[zoneI];
5480 if (mesh_.faceZones().size() > 0)
5483 forAll(mesh_.faceZones(), zoneI)
5485 const faceZone& fz = mesh_.faceZones()[zoneI];