65 Foam::label Foam::meshRefinement::createBaffle
70 polyTopoChange& meshMod
73 const face&
f = mesh_.
faces()[faceI];
75 bool zoneFlip =
false;
79 const faceZone& fZone = mesh_.
faceZones()[zoneID];
80 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
107 <<
"No neighbour patch for internal face " << faceI
112 bool reverseFlip =
false;
115 reverseFlip = !zoneFlip;
118 dupFaceI = meshMod.setAction
178 void Foam::meshRefinement::getIntersections
188 autoPtr<OBJstream> str;
189 if (
debug&OBJINTERSECTIONS)
196 mesh_.time().path()/
timeName()/
"intersections.obj" 200 Pout<<
"getIntersections : Writing surface intersections to file " 205 globalRegion1.setSize(mesh_.nFaces());
207 globalRegion2.setSize(mesh_.nFaces());
235 List<pointIndexHit> hit1;
238 List<pointIndexHit> hit2;
240 surfaces_.findNearestIntersection
258 label faceI = testFaces[i];
260 if (hit1[i].hit() && hit2[i].hit())
264 str().writeLine(start[i], hit1[i].
point());
265 str().writeLine(hit1[i].
point(), hit2[i].
point());
266 str().writeLine(hit2[i].
point(),
end[i]);
270 globalRegion1[faceI] =
271 surfaces_.globalRegion(surface1[i], region1[i]);
272 globalRegion2[faceI] =
273 surfaces_.globalRegion(surface2[i], region2[i]);
275 if (globalRegion1[faceI] == -1 || globalRegion2[faceI] == -1)
285 void Foam::meshRefinement::getBafflePatches
287 const label nErodeCellZones,
292 const bool exitIfLeakPath,
293 const refPtr<coordSetWriter>& leakPathFormatter,
318 bitSet posOrientation;
326 locationsOutsideMesh,
348 ownPatch.setSize(mesh_.nFaces());
350 neiPatch.setSize(mesh_.nFaces());
355 if (unnamedRegion1[faceI] != -1 || unnamedRegion2[faceI] != -1)
357 label ownMasterPatch = -1;
358 if (unnamedRegion1[faceI] != -1)
360 ownMasterPatch = globalToMasterPatch[unnamedRegion1[faceI]];
362 label neiMasterPatch = -1;
363 if (unnamedRegion2[faceI] != -1)
365 neiMasterPatch = globalToMasterPatch[unnamedRegion2[faceI]];
372 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
375 if (mesh_.isInternalFace(faceI))
377 neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
381 neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
389 (ownZone >= 0 && neiZone != -2)
390 || (neiZone >= 0 && ownZone != -2)
393 namedSurfaceRegion.size() == 0
394 || namedSurfaceRegion[faceI] == -1
405 ownPatch[faceI] = ownMasterPatch;
406 neiPatch[faceI] = neiMasterPatch;
426 const bool allowBoundary,
431 Map<labelPair> bafflePatch(mesh_.nFaces()/1000);
433 const PtrList<surfaceZonesInfo>& surfZones = surfaces_.surfZones();
438 const wordList& faceZoneNames = surfZones[surfI].faceZoneNames();
440 forAll(faceZoneNames, fzi)
443 const word& faceZoneName = faceZoneNames[fzi];
444 label zoneI = fZones.findZoneID(faceZoneName);
445 const faceZone& fZone = fZones[zoneI];
448 label globalRegionI = surfaces_.globalRegion(surfI, fzi);
451 globalToMasterPatch[globalRegionI],
452 globalToSlavePatch[globalRegionI]
455 Info<<
"For zone " << fZone.name() <<
" found patches " 456 << mesh_.boundaryMesh()[zPatches[0]].name() <<
" and " 457 << mesh_.boundaryMesh()[zPatches[1]].name()
462 label faceI = fZone[i];
464 if (allowBoundary || mesh_.isInternalFace(faceI))
467 if (fZone.flipMap()[i])
472 if (!bafflePatch.insert(faceI,
patches))
476 <<
" fc:" << mesh_.faceCentres()[faceI]
477 <<
" in zone " << fZone.name()
478 <<
" is in multiple zones!" 497 ownPatch.size() != mesh_.nFaces()
498 || neiPatch.size() != mesh_.nFaces()
503 <<
" ownPatch:" << ownPatch.size()
504 <<
" neiPatch:" << neiPatch.size()
505 <<
". Should be number of faces:" << mesh_.nFaces()
516 forAll(syncedOwnPatch, faceI)
520 (ownPatch[faceI] == -1 && syncedOwnPatch[faceI] != -1)
521 || (neiPatch[faceI] == -1 && syncedNeiPatch[faceI] != -1)
525 <<
"Non synchronised at face:" << faceI
526 <<
" on patch:" << mesh_.boundaryMesh().whichPatch(faceI)
527 <<
" fc:" << mesh_.faceCentres()[faceI] <<
endl 528 <<
"ownPatch:" << ownPatch[faceI]
529 <<
" syncedOwnPatch:" << syncedOwnPatch[faceI]
530 <<
" neiPatch:" << neiPatch[faceI]
531 <<
" syncedNeiPatch:" << syncedNeiPatch[faceI]
538 polyTopoChange meshMod(mesh_);
542 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
544 if (ownPatch[faceI] != -1)
558 const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
562 const polyPatch& pp = pbm[patchI];
564 label coupledPatchI = -1;
568 && !refCast<const coupledPolyPatch>(pp).separated()
571 coupledPatchI = patchI;
576 label faceI = pp.start()+i;
578 if (ownPatch[faceI] != -1)
588 if (coupledPatchI != -1)
590 faceToCoupledPatch_.insert(faceI, coupledPatchI);
599 autoPtr<mapPolyMesh> mapPtr;
607 mapPtr = meshMod.changeMesh(mesh_,
false,
true);
608 mapPolyMesh& map = *mapPtr;
611 mesh_.updateMesh(map);
614 if (map.hasMotionPoints())
616 mesh_.movePoints(map.preMotionPoints());
630 faceSet baffledFacesSet(mesh_,
"baffledFacesSet", 2*nBaffles);
632 const labelList& reverseFaceMap = map.reverseFaceMap();
636 forAll(ownPatch, oldFaceI)
638 label faceI = reverseFaceMap[oldFaceI];
640 if (ownPatch[oldFaceI] != -1 && faceI >= 0)
642 const cell& ownFaces = mesh_.cells()[mesh_.faceOwner()[faceI]];
644 baffledFacesSet.insert(ownFaces);
650 label oldFaceI =
faceMap[faceI];
652 if (oldFaceI >= 0 && reverseFaceMap[oldFaceI] != faceI)
654 const cell& ownFaces = mesh_.cells()[mesh_.faceOwner()[faceI]];
656 baffledFacesSet.insert(ownFaces);
659 baffledFacesSet.sync(mesh_);
661 updateMesh(map, baffledFacesSet.toc());
679 const faceZone& fZone = faceZones[zoneI];
683 bool hasInfo = getFaceZoneInfo(fZone.
name(), mpI, spI, fzType);
685 if (hasInfo && fzTypes.
found(fzType))
707 for (
const label zoneID :
zoneIDs)
718 if (faceToZone[
p[0]] != -1 && (faceToZone[
p[0]] == faceToZone[
p[1]]))
740 ownPatch.
setSize(mesh_.nFaces());
742 neiPatch.
setSize(mesh_.nFaces());
751 const bitSet isInternalOrCoupled
759 const faceZone& fz = faceZones[zoneI];
760 const word& masterName = faceZoneToMasterPatch_[fz.
name()];
761 label masterPatchI = mesh_.boundaryMesh().findPatchID(masterName);
762 const word& slaveName = faceZoneToSlavePatch_[fz.
name()];
763 label slavePatchI = mesh_.boundaryMesh().findPatchID(slaveName);
765 if (masterPatchI == -1 || slavePatchI == -1)
768 <<
"Problem: masterPatchI:" << masterPatchI
775 if (isInternalOrCoupled[faceI])
779 ownPatch[faceI] = slavePatchI;
780 neiPatch[faceI] = masterPatchI;
784 ownPatch[faceI] = masterPatchI;
785 neiPatch[faceI] = slavePatchI;
810 Info<<
"Converting zoned faces into baffles ..." <<
endl;
819 label nLocalBaffles =
sum(nBaffles);
823 if (nTotalBaffles > 0)
828 <<
setf(ios_base::left)
829 <<
setw(30) <<
"FaceZone" 830 <<
setw(10) <<
"FaceType" 831 <<
setw(10) <<
"nBaffles" 833 <<
setw(30) <<
"--------" 834 <<
setw(10) <<
"--------" 835 <<
setw(10) <<
"--------" 841 const faceZone& fz = faceZones[zoneI];
845 bool hasInfo = getFaceZoneInfo(fz.
name(), mpI, spI, fzType);
853 <<
setw(10) << nBaffles[j]
860 map = createBaffles(ownPatch, neiPatch);
866 baffles.
setSize(nLocalBaffles);
867 originatingFaceZone.
setSize(nLocalBaffles);
871 const labelList& reverseFaceMap = map().reverseFaceMap();
875 label faceI = mesh_.nInternalFaces();
876 faceI < mesh_.nFaces();
880 label oldFaceI =
faceMap[faceI];
881 label masterFaceI = reverseFaceMap[oldFaceI];
882 if (masterFaceI != faceI && ownPatch[oldFaceI] != -1)
884 baffles[baffleI] =
labelPair(masterFaceI, faceI);
885 originatingFaceZone[baffleI] =
faceZoneID[oldFaceI];
890 if (baffleI != baffles.
size())
893 <<
"Had " << baffles.
size() <<
" baffles to create " 894 <<
" but encountered " << baffleI
895 <<
" slave faces originating from patcheable faces." 901 const_cast<Time&
>(mesh_.time())++;
902 Pout<<
"Writing zone-baffled mesh to time " <<
timeName()
908 mesh_.time().path()/
"baffles" 912 Info<<
"Created " << nTotalBaffles <<
" baffles in = " 913 << mesh_.time().cpuTimeIncrement() <<
" s\n" <<
nl <<
endl;
918 originatingFaceZone.
clear();
928 const scalar planarAngle
955 const label baffleValue = 1000000;
970 label faceI = pp.
start();
974 const labelList& fEdges = mesh_.faceEdges(faceI);
978 nBafflesPerEdge[fEdges[fEdgeI]]++;
986 DynamicList<label> fe0;
987 DynamicList<label> fe1;
996 label f0 = couples[i].
first();
997 const labelList& fEdges0 = mesh_.faceEdges(f0, fe0);
1000 nBafflesPerEdge[fEdges0[fEdgeI]] += baffleValue;
1005 label f1 = couples[i].second();
1006 const labelList& fEdges1 = mesh_.faceEdges(f1, fe1);
1009 nBafflesPerEdge[fEdges1[fEdgeI]] += baffleValue;
1028 List<labelPair> filteredCouples(couples.
size());
1041 const labelList& fEdges = mesh_.faceEdges(couple.first());
1045 label edgeI = fEdges[fEdgeI];
1047 if (nBafflesPerEdge[edgeI] == 2*baffleValue+2*1)
1049 filteredCouples[filterI++] = couple;
1055 filteredCouples.setSize(filterI);
1058 label nFiltered =
returnReduce(filteredCouples.size(), sumOp<label>());
1060 Info<<
"freeStandingBaffles : detected " 1062 <<
" free-standing baffles out of " 1075 const pointField& cellCentres = mesh_.cellCentres();
1077 forAll(filteredCouples, i)
1079 const labelPair& couple = filteredCouples[i];
1080 start[i] = cellCentres[mesh_.faceOwner()[couple.first()]];
1081 end[i] = cellCentres[mesh_.faceOwner()[couple.second()]];
1095 List<pointIndexHit> hit1;
1100 List<pointIndexHit> hit2;
1104 surfaces_.findNearestIntersection
1106 identity(surfaces_.surfaces().size()),
1130 forAll(filteredCouples, i)
1132 const labelPair& couple = filteredCouples[i];
1146 && hit1[i].
point().dist(hit2[i].
point()) > mergeDistance_
1157 if ((normal1[i]&normal2[i]) > planarAngleCos)
1161 scalar magN =
mag(
n);
1164 filteredCouples[filterI++] = couple;
1168 else if (hit1[i].hit() || hit2[i].hit())
1174 filteredCouples.setSize(filterI);
1176 Info<<
"freeStandingBaffles : detected " 1178 <<
" planar (within " << planarAngle
1179 <<
" degrees) free-standing baffles out of " 1184 return filteredCouples;
1201 const faceList& faces = mesh_.faces();
1202 const labelList& faceOwner = mesh_.faceOwner();
1207 label face0 = couples[i].
first();
1208 label face1 = couples[i].second();
1213 label own0 = faceOwner[face0];
1214 label own1 = faceOwner[face1];
1216 if (face1 < 0 || own0 < own1)
1219 label zoneID = faceZones.
whichZone(face0);
1220 bool zoneFlip =
false;
1224 const faceZone& fZone = faceZones[zoneID];
1228 label nei = (face1 < 0 ? -1 : own1);
1250 label zoneID = faceZones.
whichZone(face1);
1251 bool zoneFlip =
false;
1255 const faceZone& fZone = faceZones[zoneID];
1280 const label faceI = iter.key();
1281 const label patchI = iter.val();
1283 if (!mesh_.isInternalFace(faceI))
1286 <<
"problem: face:" << faceI
1287 <<
" at:" << mesh_.faceCentres()[faceI]
1288 <<
"(wanted patch:" << patchI
1292 label zoneID = faceZones.
whichZone(faceI);
1293 bool zoneFlip =
false;
1297 const faceZone& fZone = faceZones[zoneID];
1321 mesh_.moving(
false);
1324 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
1328 mesh_.updateMesh(map);
1355 newExposedFaces[newI++] = newFace0;
1358 const label newFace1 = map.
reverseFaceMap()[couples[i].second()];
1361 newExposedFaces[newI++] = newFace1;
1364 newExposedFaces.
setSize(newI);
1365 updateMesh(map, newExposedFaces);
1374 const bool doInternalZones,
1375 const bool doBaffleZones
1381 if (doInternalZones)
1405 mapPtr = mergeBaffles(zoneBaffles,
Map<label>(0));
1412 void Foam::meshRefinement::findCellZoneGeometric
1422 const pointField& cellCentres = mesh_.cellCentres();
1423 const labelList& faceOwner = mesh_.faceOwner();
1424 const labelList& faceNeighbour = mesh_.faceNeighbour();
1428 surfaces_.findInside
1430 closedNamedSurfaces,
1435 forAll(insideSurfaces, cellI)
1437 label surfI = insideSurfaces[cellI];
1441 if (cellToZone[cellI] == -2)
1443 cellToZone[cellI] = surfaceToCellZone[surfI];
1445 else if (cellToZone[cellI] == -1)
1450 cellToZone[cellI] = surfaceToCellZone[surfI];
1463 label nCandidates = 0;
1464 forAll(namedSurfaceRegion, faceI)
1466 if (namedSurfaceRegion[faceI] != -1)
1468 if (mesh_.isInternalFace(faceI))
1482 forAll(namedSurfaceRegion, faceI)
1484 if (namedSurfaceRegion[faceI] != -1)
1486 label own = faceOwner[faceI];
1487 const point& ownCc = cellCentres[own];
1489 if (mesh_.isInternalFace(faceI))
1491 label nei = faceNeighbour[faceI];
1492 const point& neiCc = cellCentres[nei];
1494 const vector d = 1
e-4*(neiCc - ownCc);
1495 candidatePoints[nCandidates++] = ownCc-d;
1496 candidatePoints[nCandidates++] = neiCc+d;
1501 const point& neiFc = neiCc[faceI-mesh_.nInternalFaces()];
1504 const vector d = 1
e-4*(neiFc - ownCc);
1505 candidatePoints[nCandidates++] = ownCc-d;
1513 surfaces_.findInside
1515 closedNamedSurfaces,
1524 forAll(namedSurfaceRegion, faceI)
1526 if (namedSurfaceRegion[faceI] != -1)
1528 label own = faceOwner[faceI];
1530 if (mesh_.isInternalFace(faceI))
1532 label ownSurfI = insideSurfaces[nCandidates++];
1535 cellToZone[own] = surfaceToCellZone[ownSurfI];
1538 label neiSurfI = insideSurfaces[nCandidates++];
1541 label nei = faceNeighbour[faceI];
1543 cellToZone[nei] = surfaceToCellZone[neiSurfI];
1548 label ownSurfI = insideSurfaces[nCandidates++];
1551 cellToZone[own] = surfaceToCellZone[ownSurfI];
1562 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
1564 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
1565 label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
1567 if (namedSurfaceRegion[faceI] == -1 && (ownZone != neiZone))
1577 else if (neiZone == -1)
1583 minZone =
min(ownZone, neiZone);
1588 label geomSurfI = surfaceToCellZone.
find(minZone);
1590 if (geomSurfI != -1)
1592 namedSurfaceRegion[faceI] =
1593 surfaces_.globalRegion(geomSurfI, 0);
1601 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
1605 const polyPatch& pp =
patches[patchI];
1611 label faceI = pp.start()+i;
1612 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
1613 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
1615 if (namedSurfaceRegion[faceI] == -1 && (ownZone != neiZone))
1623 else if (neiZone == -1)
1629 minZone =
min(ownZone, neiZone);
1634 label geomSurfI = surfaceToCellZone.
find(minZone);
1636 if (geomSurfI != -1)
1638 namedSurfaceRegion[faceI] =
1639 surfaces_.globalRegion(geomSurfI, 0);
1651 void Foam::meshRefinement::findCellZoneInsideWalk
1661 boolList blockedFace(mesh_.nFaces());
1664 forAll(blockedFace, faceI)
1666 if (faceToZone[faceI] == -1)
1668 blockedFace[faceI] =
false;
1672 blockedFace[faceI] =
true;
1678 regionSplit cellRegion(mesh_, blockedFace);
1679 blockedFace.clear();
1682 (void)mesh_.tetBasePtIs();
1685 forAll(locationsInMesh, i)
1688 const point& insidePoint = locationsInMesh[i];
1689 label zoneID = zonesInMesh[i];
1692 label keepRegionI = findRegion
1696 vector::uniform(mergeDistance_),
1700 Info<<
"For cellZone " 1704 : mesh_.cellZones()[zoneID].name()
1706 <<
" found point " << insidePoint
1707 <<
" in global region " << keepRegionI
1708 <<
" out of " << cellRegion.nRegions() <<
" regions." <<
endl;
1710 if (keepRegionI == -1)
1713 <<
"Point " << insidePoint
1714 <<
" is not inside the mesh." <<
nl 1715 <<
"Bounding box of the mesh:" << mesh_.bounds()
1724 label nWarnings = 0;
1726 forAll(cellRegion, cellI)
1728 if (cellRegion[cellI] == keepRegionI)
1730 if (cellToZone[cellI] == -2)
1733 cellToZone[cellI] = zoneID;
1735 else if (cellToZone[cellI] != zoneID)
1737 if (cellToZone[cellI] != -1 && nWarnings < 10)
1741 <<
" at " << mesh_.cellCentres()[cellI]
1742 <<
" is inside cellZone " 1746 : mesh_.cellZones()[zoneID].name()
1748 <<
" from locationInMesh " << insidePoint
1749 <<
" but already marked as being in zone " 1750 << mesh_.cellZones()[cellToZone[cellI]].name()
1752 <<
"This can happen if your surfaces are not" 1753 <<
" (sufficiently) closed." 1759 cellToZone[cellI] = zoneID;
1767 void Foam::meshRefinement::findCellZoneInsideWalk
1779 forAll(zoneNamesInMesh, i)
1781 zoneIDs[i] = czs.findZoneID(zoneNamesInMesh[i]);
1783 findCellZoneInsideWalk
1793 bool Foam::meshRefinement::calcRegionToZone
1795 const label backgroundZoneID,
1796 const label surfZoneI,
1797 const label ownRegion,
1798 const label neiRegion,
1803 bool changed =
false;
1806 if (ownRegion != neiRegion)
1813 if (regionToCellZone[ownRegion] == -2)
1815 if (surfZoneI == -1)
1820 if (regionToCellZone[neiRegion] != -2)
1822 regionToCellZone[ownRegion] = regionToCellZone[neiRegion];
1826 else if (regionToCellZone[neiRegion] == surfZoneI)
1831 if (backgroundZoneID != -2)
1833 regionToCellZone[ownRegion] = backgroundZoneID;
1837 else if (regionToCellZone[neiRegion] != -2)
1841 regionToCellZone[ownRegion] = surfZoneI;
1845 else if (regionToCellZone[neiRegion] == -2)
1847 if (surfZoneI == -1)
1852 regionToCellZone[neiRegion] = regionToCellZone[ownRegion];
1855 else if (regionToCellZone[ownRegion] == surfZoneI)
1859 if (backgroundZoneID != -2)
1861 regionToCellZone[neiRegion] = backgroundZoneID;
1865 else if (regionToCellZone[ownRegion] != -2)
1869 regionToCellZone[neiRegion] = surfZoneI;
1878 void Foam::meshRefinement::findCellZoneTopo
1880 const label backgroundZoneID,
1909 boolList blockedFace(mesh_.nFaces());
1911 forAll(unnamedSurfaceRegion, faceI)
1915 unnamedSurfaceRegion[faceI] == -1
1916 && namedSurfaceRegion[faceI] == -1
1919 blockedFace[faceI] =
false;
1923 blockedFace[faceI] =
true;
1929 regionSplit cellRegion(mesh_, blockedFace);
1930 blockedFace.clear();
1936 labelList regionToCellZone(cellRegion.nRegions(), -2);
1941 forAll(cellToZone, cellI)
1943 label regionI = cellRegion[cellI];
1944 if (cellToZone[cellI] != -2 && regionToCellZone[regionI] == -2)
1946 regionToCellZone[regionI] = cellToZone[cellI];
1959 forAll(locationsInMesh, i)
1961 const point& keepPoint = locationsInMesh[i];
1962 label keepRegionI = findRegion
1966 vector::uniform(mergeDistance_),
1970 Info<<
"Found point " << keepPoint
1971 <<
" in global region " << keepRegionI
1972 <<
" out of " << cellRegion.nRegions() <<
" regions." <<
endl;
1974 if (keepRegionI == -1)
1977 <<
"Point " << keepPoint
1978 <<
" is not inside the mesh." <<
nl 1979 <<
"Bounding box of the mesh:" << mesh_.bounds()
1987 if (regionToCellZone[keepRegionI] == -2)
1989 regionToCellZone[keepRegionI] = -1;
2008 bool changed =
false;
2012 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
2014 label regionI = namedSurfaceRegion[faceI];
2017 if (unnamedSurfaceRegion[faceI] == -1 && regionI != -1)
2022 label surfI = surfaces_.whichSurface(regionI).first();
2024 bool changedCell = calcRegionToZone
2027 surfaceToCellZone[surfI],
2028 cellRegion[mesh_.faceOwner()[faceI]],
2029 cellRegion[mesh_.faceNeighbour()[faceI]],
2033 changed = changed | changedCell;
2039 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2049 const polyPatch& pp =
patches[patchI];
2055 label faceI = pp.start()+i;
2057 label regionI = namedSurfaceRegion[faceI];
2060 if (unnamedSurfaceRegion[faceI] == -1 && regionI != -1)
2062 label surfI = surfaces_.whichSurface(regionI).first();
2064 bool changedCell = calcRegionToZone
2067 surfaceToCellZone[surfI],
2068 cellRegion[mesh_.faceOwner()[faceI]],
2069 neiCellRegion[faceI-mesh_.nInternalFaces()],
2073 changed = changed | changedCell;
2088 Pout<<
"meshRefinement::findCellZoneTopo :" 2089 <<
" nRegions:" << regionToCellZone.size()
2090 <<
" of which visited (-1 = background, >= 0 : cellZone) :" 2093 forAll(regionToCellZone, regionI)
2095 if (regionToCellZone[regionI] != -2)
2097 Pout<<
"Region " << regionI
2098 <<
" becomes cellZone:" << regionToCellZone[regionI]
2105 forAll(cellToZone, cellI)
2107 label regionI = cellRegion[cellI];
2108 if (cellToZone[cellI] == -2 && regionToCellZone[regionI] != -2)
2110 cellToZone[cellI] = regionToCellZone[regionI];
2116 void Foam::meshRefinement::erodeCellZone
2118 const label nErodeCellZones,
2119 const label backgroundZoneID,
2136 for (label iter = 0; iter < nErodeCellZones; iter++)
2143 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
2147 unnamedSurfaceRegion[facei] == -1
2148 && namedSurfaceRegion[facei] == -1
2151 label own = mesh_.faceOwner()[facei];
2152 label nei = mesh_.faceNeighbour()[facei];
2153 if (cellToZone[own] == -2 && cellToZone[nei] >= -1)
2155 erodedCellToZone[nei] = backgroundZoneID;
2158 else if (cellToZone[nei] == -2 && cellToZone[own] >= -1)
2160 erodedCellToZone[own] = backgroundZoneID;
2168 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2178 const polyPatch& pp =
patches[patchi];
2184 label facei = pp.start()+i;
2187 unnamedSurfaceRegion[facei] == -1
2188 && namedSurfaceRegion[facei] == -1
2191 label own = mesh_.faceOwner()[facei];
2192 label bFacei = facei-mesh_.nInternalFaces();
2193 if (neiCellZone[bFacei] == -2 && cellToZone[own] >= -1)
2195 erodedCellToZone[own] = backgroundZoneID;
2203 cellToZone.transfer(erodedCellToZone);
2205 reduce(nChanged, sumOp<label>());
2208 Pout<<
"erodeCellZone : eroded " << nChanged
2209 <<
" cells (moved from cellZone to background zone " 2210 << backgroundZoneID <<
endl;
2221 void Foam::meshRefinement::growCellZone
2223 const label nGrowCellZones,
2224 const label backgroundZoneID,
2231 if (nGrowCellZones != 1)
2234 <<
"Growing currently only supported for single layer." 2235 <<
" Exiting zone growing" <<
endl;
2252 const FixedList<label, 3> wallTag
2262 List<FixedList<label, 3>> surfaces(1);
2282 List<wallPoints> allCellInfo(mesh_.nCells());
2283 forAll(cellToZone, celli)
2285 if (cellToZone[celli] >= 0)
2287 const FixedList<label, 3> zoneTag
2294 origins[0] = mesh_.cellCentres()[celli];
2296 surfaces[0] = zoneTag;
2297 allCellInfo[celli] = wallPoints(origins, distSqrs, surfaces);
2302 DynamicList<wallPoints> faceDist(mesh_.nFaces()/128);
2303 DynamicList<label> changedFaces(mesh_.nFaces()/128);
2305 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
2307 const label own = mesh_.faceOwner()[facei];
2308 const label nei = mesh_.faceNeighbour()[facei];
2309 if (cellToZone[own] >= 0 && cellToZone[nei] < 0)
2313 origins[0] = mesh_.faceCentres()[facei];
2315 surfaces[0] = FixedList<label, 3>
2321 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2322 changedFaces.append(facei);
2324 else if (cellToZone[own] < 0 && cellToZone[nei] >= 0)
2328 origins[0] = mesh_.faceCentres()[facei];
2330 surfaces[0] = FixedList<label, 3>
2336 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2337 changedFaces.append(facei);
2341 unnamedSurfaceRegion1[facei] != -1
2342 || unnamedSurfaceRegion2[facei] != -1
2347 origins[0] = mesh_.faceCentres()[facei];
2349 surfaces[0] = wallTag;
2350 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2351 changedFaces.append(facei);
2359 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2365 const polyPatch& pp =
patches[patchi];
2372 label facei = pp.start()+i;
2373 label own = mesh_.faceOwner()[facei];
2374 label bFacei = facei-mesh_.nInternalFaces();
2375 if (cellToZone[own] >= 0 && neiCellZone[bFacei] < 0)
2377 origins[0] = mesh_.faceCentres()[facei];
2379 surfaces[0] = FixedList<label, 3>
2385 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2386 changedFaces.append(facei);
2388 else if (cellToZone[own] < 0 && neiCellZone[bFacei] >= 0)
2394 unnamedSurfaceRegion1[facei] != -1
2395 || unnamedSurfaceRegion2[facei] != -1
2399 origins[0] = mesh_.faceCentres()[facei];
2401 surfaces[0] = wallTag;
2402 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2403 changedFaces.append(facei);
2412 label facei = pp.start()+i;
2413 label own = mesh_.faceOwner()[facei];
2414 if (cellToZone[own] < 0)
2416 origins[0] = mesh_.faceCentres()[facei];
2418 surfaces[0] = wallTag;
2419 faceDist.append(wallPoints(origins, distSqrs, surfaces));
2420 changedFaces.append(facei);
2427 List<wallPoints> allFaceInfo(mesh_.nFaces());
2430 const bitSet isBlockedFace(mesh_.nFaces());
2431 List<scalarList> regionToBlockSize(surfaces_.surfaces().size());
2433 forAll(surfaces_.surfaces(), surfi)
2435 const label geomi = surfaces_.surfaces()[surfi];
2436 const auto&
s = surfaces_.geometry()[geomi];
2437 const label nRegions =
s.regions().size();
2438 regionToBlockSize[surfi].setSize(nRegions,
Foam::sqr(GREAT));
2443 wallPoints::trackData td(isBlockedFace, regionToBlockSize);
2444 FaceCellWave<wallPoints, wallPoints::trackData> wallDistCalc
2454 wallDistCalc.iterate(nGrowCellZones);
2461 bitSet isChangedCell(mesh_.nCells());
2463 forAll(allCellInfo, celli)
2465 if (allCellInfo[celli].valid(wallDistCalc.data()))
2467 const List<FixedList<label, 3>>& surfaces =
2468 allCellInfo[celli].surface();
2470 if (surfaces.size())
2474 isChangedCell.set(celli);
2477 if (surfaces.size() > 1)
2483 for (label i = 0; i < surfaces.size(); i++)
2485 const label zonei = surfaces[i][0];
2486 const scalar d2 = allCellInfo[celli].distSqr()[i];
2487 if (zonei != cellToZone[celli] && d2 < minDistSqr)
2496 if (minZone != cellToZone[celli] && minZone != wallTag[0])
2498 cellToZone[celli] = minZone;
2499 isChangedCell.set(celli);
2507 if (backgroundZoneID != -2)
2509 forAll(cellToZone, celli)
2511 if (cellToZone[celli] == -2)
2513 cellToZone[celli] = backgroundZoneID;
2526 for (
const label celli : isChangedCell)
2528 const cell& cFaces = mesh_.cells()[celli];
2529 for (
const label facei : cFaces)
2531 const label own = mesh_.faceOwner()[facei];
2532 const label ownZone = cellToZone[own];
2535 if (mesh_.isInternalFace(facei))
2537 const label neiZone = cellToZone[mesh_.faceNeighbour()[facei]];
2538 nbrZone = (own != celli ? ownZone : neiZone);
2542 nbrZone = neiCellZone[facei-mesh_.nInternalFaces()];
2545 if (nbrZone == cellToZone[celli])
2549 unnamedSurfaceRegion1[facei] != -1
2550 || unnamedSurfaceRegion2[facei] != -1
2553 unnamedSurfaceRegion1[facei] = -1;
2554 unnamedSurfaceRegion2[facei] = -1;
2559 namedSurfaceRegion.size()
2560 && namedSurfaceRegion[facei] != -1
2563 namedSurfaceRegion[facei] = -1;
2570 reduce(nUnnamed, sumOp<label>());
2571 reduce(nNamed, sumOp<label>());
2577 unnamedSurfaceRegion1,
2583 unnamedSurfaceRegion2,
2586 if (namedSurfaceRegion.size())
2598 Pout<<
"growCellZone : grown cellZones by " 2600 <<
" cells (moved from background to nearest cellZone)" 2602 Pout<<
"growCellZone : unmarked " << nUnnamed
2603 <<
" unzoned intersections; " << nNamed <<
" zoned intersections; " 2609 void Foam::meshRefinement::makeConsistentFaceIndex
2624 const labelList& faceOwner = mesh_.faceOwner();
2625 const labelList& faceNeighbour = mesh_.faceNeighbour();
2627 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
2629 label ownZone = cellToZone[faceOwner[faceI]];
2630 label neiZone = cellToZone[faceNeighbour[faceI]];
2631 label globalI = namedSurfaceRegion[faceI];
2637 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2640 namedSurfaceRegion[faceI] = -1;
2644 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
2653 const polyPatch& pp =
patches[patchI];
2659 label faceI = pp.start()+i;
2661 label ownZone = cellToZone[faceOwner[faceI]];
2662 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
2663 label globalI = namedSurfaceRegion[faceI];
2669 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2672 namedSurfaceRegion[faceI] = -1;
2681 label faceI = pp.start()+i;
2682 label globalI = namedSurfaceRegion[faceI];
2687 && surfaceMap[surfaces_.whichSurface(globalI).first()] == -1
2690 namedSurfaceRegion[faceI] = -1;
2698 void Foam::meshRefinement::getIntersections
2705 bitSet& posOrientation
2708 namedSurfaceRegion.setSize(mesh_.nFaces());
2709 namedSurfaceRegion = -1;
2711 posOrientation.setSize(mesh_.nFaces());
2712 posOrientation =
false;
2743 List<pointIndexHit> hit1;
2747 List<pointIndexHit> hit2;
2750 surfaces_.findNearestIntersection
2769 label faceI = testFaces[i];
2770 const vector&
area = mesh_.faceAreas()[faceI];
2772 if (surface1[i] != -1)
2779 magSqr(hit2[i].hitPoint())
2780 <
magSqr(hit1[i].hitPoint())
2784 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2789 posOrientation.
set(faceI, ((
area&normal2[i]) > 0));
2790 nSurfFaces[surface2[i]]++;
2794 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2799 posOrientation.set(faceI, ((
area&normal1[i]) > 0));
2800 nSurfFaces[surface1[i]]++;
2803 else if (surface2[i] != -1)
2805 namedSurfaceRegion[faceI] = surfaces_.globalRegion
2810 posOrientation.set(faceI, ((
area&normal2[i]) > 0));
2811 nSurfFaces[surface2[i]]++;
2830 forAll(nSurfFaces, surfI)
2833 << surfaces_.names()[surfI]
2834 <<
" nZoneFaces:" << nSurfFaces[surfI] <<
nl;
2841 void Foam::meshRefinement::zonify
2843 const bool allowFreeStandingZoneFaces,
2844 const label nErodeCellZones,
2845 const label backgroundZoneID,
2849 const bool exitIfLeakPath,
2850 const refPtr<coordSetWriter>& leakPathFormatter,
2856 bitSet& posOrientation
2869 const PtrList<surfaceZonesInfo>& surfZones = surfaces_.surfZones();
2872 const List<pointField> allLocations
2878 locationsOutsideMesh
2883 labelList neiLevel(mesh_.nBoundaryFaces());
2885 calcNeighbourData(neiLevel, neiCc);
2893 if (namedSurfaces.size())
2905 cellToZone.setSize(mesh_.nCells());
2908 namedSurfaceRegion.clear();
2909 posOrientation.clear();
2929 autoPtr<mapDistribute> unnamedMapPtr;
2930 if (locationsOutsideMesh.size())
2935 [](
const label
x){
return x != -1;}
2938 const globalIndex globalUnnamedFaces(unnamedFaces.size());
2948 unnamedClosureFaces,
2954 Pout<<
"meshRefinement::zonify : found wall closure faces:" 2955 << unnamedClosureFaces.size()
2956 <<
" map:" << unnamedMapPtr.valid() <<
endl;
2961 if (unnamedMapPtr.valid())
2964 if (leakPathFormatter)
2966 boolList blockedFace(mesh_.nFaces(),
false);
2967 UIndirectList<bool>(blockedFace, unnamedFaces) =
true;
2968 const fileName fName
2974 locationsOutsideMesh,
2976 leakPathFormatter.constCast()
2979 Info<<
"Dumped leak path to " << fName <<
endl;
2989 err <<
"Locations in mesh " << locationsInMesh
2990 <<
" connect to one of the locations outside mesh " 2991 << locationsOutsideMesh <<
endl;
3001 UIndirectList<label>(unnamedRegion1, unnamedFaces)
3003 unnamedMapPtr->distribute(packedRegion1);
3006 UIndirectList<label>(unnamedRegion2, unnamedFaces)
3008 unnamedMapPtr->distribute(packedRegion2);
3009 forAll(unnamedClosureFaces, i)
3011 const label sloti = unnamedToClosure[i];
3015 const label facei = unnamedClosureFaces[i];
3016 const label region1 = unnamedRegion1[facei];
3017 const label slotRegion1 = packedRegion1[sloti];
3018 const label region2 = unnamedRegion2[facei];
3019 const label slotRegion2 = packedRegion2[sloti];
3021 if (slotRegion1 != region1 || slotRegion2 != region2)
3023 unnamedRegion1[facei] = slotRegion1;
3024 unnamedRegion2[facei] = slotRegion2;
3036 autoPtr<mapDistribute> namedMapPtr;
3037 if (namedSurfaces.size())
3166 bitSet isClosureFace(mesh_.nFaces());
3167 isClosureFace.set(unnamedClosureFaces);
3168 isClosureFace.set(namedClosureFaces);
3169 const labelList closureFaces(isClosureFace.sortedToc());
3173 UIndirectList<face>(mesh_.faces(), closureFaces),
3178 const labelList nEdgeFaces(countEdgeFaces(pp));
3181 bitSet isFrozenPoint(mesh_.nPoints());
3182 forAll(nEdgeFaces, edgei)
3184 if (nEdgeFaces[edgei] != 1)
3186 const edge&
e = pp.edges()[edgei];
3187 isFrozenPoint.set(pp.meshPoints()[
e[0]]);
3188 isFrozenPoint.set(pp.meshPoints()[
e[1]]);
3196 const_cast<meshRefinement&
>(*this).addPointZone(
"frozenPoints");
3197 const bitSet oldSet(mesh_.nPoints(), pointZones[zonei]);
3198 isFrozenPoint.
set(oldSet);
3204 orEqOp<unsigned int>(),
3209 pointZones.clearAddressing();
3210 pointZones[zonei] = isFrozenPoint.sortedToc();
3214 mkDir(mesh_.time().timePath());
3215 const pointZone& pz = pointZones[zonei];
3216 OBJstream str(mesh_.time().timePath()/pz.name()+
".obj");
3217 Pout<<
"Writing " << pz.size() <<
" frozen points to " 3219 for (
const label pointi : pz)
3221 str.
write(mesh_.points()[pointi]);
3226 mkDir(mesh_.time().timePath());
3227 OBJstream str(mesh_.time().timePath()/
"unnamedClosureFaces.obj");
3228 Pout<<
"Writing " << unnamedClosureFaces.size()
3229 <<
" unnamedClosureFaces to " << str.
name() <<
endl;
3230 for (
const label facei : unnamedClosureFaces)
3232 str.
write(mesh_.faces()[facei], mesh_.points(),
false);
3237 mkDir(mesh_.time().timePath());
3238 OBJstream str(mesh_.time().timePath()/
"namedClosureFaces.obj");
3239 Pout<<
"Writing " << namedClosureFaces.size()
3240 <<
" namedClosureFaces to " << str.
name() <<
endl;
3241 for (
const label facei : namedClosureFaces)
3243 str.
write(mesh_.faces()[facei], mesh_.points(),
false);
3253 if (locationsInMesh.size())
3255 Info<<
"Setting cellZones according to locationsInMesh:" <<
endl;
3257 labelList locationsZoneIDs(zonesInMesh.size(), -1);
3258 forAll(locationsInMesh, i)
3260 const word&
name = zonesInMesh[i];
3262 Info<<
"Location : " << locationsInMesh[i] <<
nl 3267 label zoneID = mesh_.cellZones().findZoneID(
name);
3272 locationsZoneIDs[i] = zoneID;
3279 findCellZoneInsideWalk
3296 if (locationSurfaces.size())
3298 Info<<
"Found " << locationSurfaces.size()
3299 <<
" named surfaces with a provided inside point." 3300 <<
" Assigning cells inside these surfaces" 3301 <<
" to the corresponding cellZone." 3306 labelList insidePointCellZoneIDs(locationSurfaces.size(), -1);
3307 forAll(locationSurfaces, i)
3309 label surfI = locationSurfaces[i];
3312 const word&
name = surfZones[surfI].cellZoneName();
3315 label zoneID = mesh_.cellZones().findZoneID(
name);
3322 insidePointCellZoneIDs[i] = zoneID;
3328 labelList allRegion1(mesh_.nFaces(), -1);
3329 forAll(namedSurfaceRegion, faceI)
3331 allRegion1[faceI] =
max 3333 unnamedRegion1[faceI],
3334 namedSurfaceRegion[faceI]
3338 findCellZoneInsideWalk
3341 insidePointCellZoneIDs,
3357 surfaces_.geometry(),
3358 surfaces_.surfaces()
3362 if (closedNamedSurfaces.
size())
3364 Info<<
"Found " << closedNamedSurfaces.
size()
3365 <<
" closed, named surfaces. Assigning cells in/outside" 3366 <<
" these surfaces to the corresponding cellZone." 3369 findCellZoneGeometric
3372 closedNamedSurfaces,
3383 if (namedSurfaces.size())
3385 if (nErodeCellZones == 0)
3387 Info<<
"Walking from known cellZones; crossing a faceZone " 3388 <<
"face changes cellZone" <<
nl <<
endl;
3401 else if (nErodeCellZones < 0)
3403 Info<<
"Growing cellZones by " << -nErodeCellZones
3404 <<
" layers" <<
nl <<
endl;
3418 Info<<
"Eroding cellZone cells to make these consistent with" 3419 <<
" faceZone faces" <<
nl <<
endl;
3435 if (!allowFreeStandingZoneFaces)
3437 Info<<
"Only keeping zone faces inbetween different cellZones." 3451 labelList surfaceMap(surfZones.size(), -1);
3452 forAll(standaloneNamedSurfaces, i)
3454 surfaceMap[standaloneNamedSurfaces[i]] = i;
3457 makeConsistentFaceIndex
3465 else if (nErodeCellZones < 0 &&
gMax(cellToZone) >= 0)
3470 Info<<
"Growing cellZones by " << -nErodeCellZones
3471 <<
" layers" <<
nl <<
endl;
3484 if (!allowFreeStandingZoneFaces && namedSurfaceRegion.size())
3486 Info<<
"Only keeping zone faces inbetween different cellZones." 3500 labelList surfaceMap(surfZones.size(), -1);
3501 forAll(standaloneNamedSurfaces, i)
3503 surfaceMap[standaloneNamedSurfaces[i]] = i;
3506 makeConsistentFaceIndex
3519 label nZones =
gMax(cellToZone)+1;
3521 label nUnvisited = 0;
3522 label nBackgroundCells = 0;
3524 forAll(cellToZone, cellI)
3526 label zoneI = cellToZone[cellI];
3529 nZoneCells[zoneI]++;
3531 else if (zoneI == -1)
3535 else if (zoneI == -2)
3545 reduce(nUnvisited, sumOp<label>());
3546 reduce(nBackgroundCells, sumOp<label>());
3547 forAll(nZoneCells, zoneI)
3549 reduce(nZoneCells[zoneI], sumOp<label>());
3551 Info<<
"nUnvisited :" << nUnvisited <<
endl;
3552 Info<<
"nBackgroundCells:" << nBackgroundCells <<
endl;
3553 Info<<
"nZoneCells :" << nZoneCells <<
endl;
3557 const_cast<Time&
>(mesh_.time())++;
3558 Pout<<
"Writing cell zone allocation on mesh to time " 3563 writeType(writeLevel() | WRITEMESH),
3564 mesh_.time().path()/
"cell2Zone" 3579 zeroGradientFvPatchScalarField::typeName
3582 forAll(cellToZone, cellI)
3584 volCellToZone[cellI] = cellToZone[cellI];
3586 volCellToZone.write();
3688 void Foam::meshRefinement::handleSnapProblems
3690 const snapParameters& snapParams,
3691 const bool useTopologicalSnapDetection,
3692 const bool removeEdgeConnectedCells,
3694 const dictionary& motionDict,
3701 <<
"Introducing baffles to block off problem cells" <<
nl 3702 <<
"----------------------------------------------" <<
nl 3707 if (useTopologicalSnapDetection)
3709 markFacesOnProblemCells
3712 removeEdgeConnectedCells,
3714 globalToMasterPatch,
3722 markFacesOnProblemCellsGeometric
3726 globalToMasterPatch,
3733 Info<<
"Analyzed problem cells in = " 3738 faceSet problemFaces(mesh_,
"problemFaces", mesh_.nFaces()/100);
3742 if (facePatch[faceI] != -1)
3744 problemFaces.insert(faceI);
3747 problemFaces.instance() =
timeName();
3748 Pout<<
"Dumping " << problemFaces.size()
3749 <<
" problem faces to " << problemFaces.objectPath() <<
endl;
3750 problemFaces.
write();
3753 Info<<
"Introducing baffles to delete problem cells." <<
nl <<
endl;
3764 List<DynamicList<label>> zoneToFaces(fzs.size());
3765 List<DynamicList<bool>> zoneToFlip(fzs.size());
3770 zoneToFaces[zonei].append(fzs[zonei]);
3771 zoneToFlip[zonei].append(fzs[zonei].flipMap());
3777 if (facePatch[facei] != -1)
3779 label zonei = faceZone[facei];
3782 zoneToFaces[zonei].append(facei);
3783 zoneToFlip[zonei].append(
false);
3788 forAll(zoneToFaces, zonei)
3802 createBaffles(facePatch, facePatch);
3809 Info<<
"Created baffles in = " 3812 printMeshInfo(
debug,
"After introducing baffles");
3816 const_cast<Time&
>(mesh_.time())++;
3817 Pout<<
"Writing extra baffled mesh to time " 3822 writeType(writeLevel() | WRITEMESH),
3825 Pout<<
"Dumped debug data in = " 3838 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
3839 const labelList& faceOwner = mesh_.faceOwner();
3840 const labelList& faceNeighbour = mesh_.faceNeighbour();
3857 DynamicList<label> faceLabels(mesh_.nFaces()/100);
3859 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
3861 if (faceToZone[faceI] != -1)
3864 label ownZone = cellToZone[faceOwner[faceI]];
3865 label neiZone = cellToZone[faceNeighbour[faceI]];
3866 if (ownZone == neiZone)
3868 faceLabels.
append(faceI);
3874 const polyPatch& pp =
patches[patchI];
3878 label faceI = pp.start()+i;
3879 if (faceToZone[faceI] != -1)
3882 label ownZone = cellToZone[faceOwner[faceI]];
3883 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
3884 if (ownZone == neiZone)
3886 faceLabels.append(faceI);
3891 return faceLabels.shrink();
3895 void Foam::meshRefinement::calcPatchNumMasterFaces
3897 const bitSet& isMasterFace,
3903 nMasterFacesPerEdge.setSize(
patch.nEdges());
3904 nMasterFacesPerEdge = 0;
3908 const label meshFaceI =
patch.addressing()[faceI];
3910 if (isMasterFace.test(meshFaceI))
3915 nMasterFacesPerEdge[fEdges[fEdgeI]]++;
3923 patch.meshEdges(mesh_.edges(), mesh_.pointEdges()),
3924 nMasterFacesPerEdge,
3931 Foam::label Foam::meshRefinement::markPatchZones
3938 List<edgeTopoDistanceData<label>> allEdgeInfo(
patch.nEdges());
3939 List<edgeTopoDistanceData<label>> allFaceInfo(
patch.size());
3944 label nProtected = 0;
3946 forAll(nMasterFacesPerEdge, edgeI)
3948 if (nMasterFacesPerEdge[edgeI] > 2)
3950 allEdgeInfo[edgeI] = edgeTopoDistanceData<label>(0, -2);
3962 DynamicList<label> changedEdges;
3963 DynamicList<edgeTopoDistanceData<label>> changedInfo;
3965 const scalar tol = PatchEdgeFaceWave
3968 edgeTopoDistanceData<label>
3969 >::propagationTol();
3973 const globalIndex globalFaces(
patch.size());
3977 label currentZoneI = 0;
3983 for (; faceI < allFaceInfo.size(); faceI++)
3985 if (!allFaceInfo[faceI].valid(dummyTrackData))
3987 globalSeed = globalFaces.toGlobal(faceI);
3992 reduce(globalSeed, minOp<label>());
3999 if (globalFaces.isLocal(globalSeed))
4001 const label seedFaceI = globalFaces.toLocal(globalSeed);
4003 edgeTopoDistanceData<label>& faceInfo = allFaceInfo[seedFaceI];
4006 faceInfo = edgeTopoDistanceData<label>(0, currentZoneI);
4012 label edgeI = fEdges[fEdgeI];
4014 edgeTopoDistanceData<label>& edgeInfo = allEdgeInfo[edgeI];
4018 edgeInfo.updateEdge<
int>
4030 changedEdges.append(edgeI);
4031 changedInfo.append(edgeInfo);
4047 edgeTopoDistanceData<label>
4063 faceToZone.setSize(
patch.size());
4064 forAll(allFaceInfo, faceI)
4066 if (!allFaceInfo[faceI].valid(dummyTrackData))
4069 <<
"Problem: unvisited face " << faceI
4070 <<
" at " <<
patch.faceCentres()[faceI]
4073 faceToZone[faceI] = allFaceInfo[faceI].data();
4076 return currentZoneI;
4080 void Foam::meshRefinement::consistentOrientation
4082 const bitSet& isMasterFace,
4086 const Map<label>& zoneToOrientation,
4090 const polyBoundaryMesh& bm = mesh_.boundaryMesh();
4093 List<patchFaceOrientation> allEdgeInfo(
patch.nEdges());
4094 List<patchFaceOrientation> allFaceInfo(
patch.size());
4100 label nProtected = 0;
4104 const label meshFaceI =
patch.addressing()[faceI];
4105 const label patchI = bm.whichPatch(meshFaceI);
4111 && !isMasterFace.test(meshFaceI)
4124 label nProtected = 0;
4126 forAll(nMasterFacesPerEdge, edgeI)
4128 if (nMasterFacesPerEdge[edgeI] > 2)
4135 Info<<
"Protected from visiting " 4137 <<
" non-manifold edges" <<
nl <<
endl;
4142 DynamicList<label> changedEdges;
4143 DynamicList<patchFaceOrientation> changedInfo;
4145 const scalar tol = PatchEdgeFaceWave
4148 patchFaceOrientation
4149 >::propagationTol();
4153 globalIndex globalFaces(
patch.size());
4159 forAll(allFaceInfo, faceI)
4163 globalSeed = globalFaces.toGlobal(faceI);
4168 reduce(globalSeed, minOp<label>());
4175 if (globalFaces.isLocal(globalSeed))
4177 const label seedFaceI = globalFaces.toLocal(globalSeed);
4181 patchFaceOrientation& faceInfo = allFaceInfo[seedFaceI];
4186 if (zoneToOrientation[faceToZone[seedFaceI]] < 0)
4195 label edgeI = fEdges[fEdgeI];
4197 patchFaceOrientation& edgeInfo = allEdgeInfo[edgeI];
4201 edgeInfo.updateEdge<
int>
4213 changedEdges.append(edgeI);
4214 changedInfo.append(edgeInfo);
4231 patchFaceOrientation
4249 mesh_.nBoundaryFaces(),
4255 const label meshFaceI =
patch.addressing()[i];
4256 if (!mesh_.isInternalFace(meshFaceI))
4258 neiStatus[meshFaceI-mesh_.nInternalFaces()] =
4259 allFaceInfo[i].flipStatus();
4266 const label meshFaceI =
patch.addressing()[i];
4267 const label patchI = bm.whichPatch(meshFaceI);
4273 && !isMasterFace.test(meshFaceI)
4277 label bFaceI = meshFaceI-mesh_.nInternalFaces();
4290 <<
"Incorrect status for face " << meshFaceI
4300 meshFlipMap.setSize(mesh_.nFaces());
4301 meshFlipMap =
false;
4303 forAll(allFaceInfo, faceI)
4305 label meshFaceI =
patch.addressing()[faceI];
4309 meshFlipMap.unset(meshFaceI);
4313 meshFlipMap.set(meshFaceI);
4318 <<
"Problem : unvisited face " << faceI
4319 <<
" centre:" << mesh_.faceCentres()[meshFaceI]
4326 void Foam::meshRefinement::zonify
4329 const bitSet& isMasterFace,
4333 const bitSet& meshFlipMap,
4334 polyTopoChange& meshMod
4337 const labelList& faceOwner = mesh_.faceOwner();
4338 const labelList& faceNeighbour = mesh_.faceNeighbour();
4340 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
4342 label faceZoneI = faceToZone[faceI];
4344 if (faceZoneI != -1)
4350 label ownZone = cellToZone[faceOwner[faceI]];
4351 label neiZone = cellToZone[faceNeighbour[faceI]];
4355 if (ownZone == neiZone)
4358 flip = meshFlipMap.
test(faceI);
4365 || (neiZone != -1 && ownZone > neiZone)
4373 mesh_.faces()[faceI],
4376 faceNeighbour[faceI],
4388 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
4393 const polyPatch& pp =
patches[patchI];
4395 label faceI = pp.
start();
4399 label faceZoneI = faceToZone[faceI];
4401 if (faceZoneI != -1)
4403 label ownZone = cellToZone[faceOwner[faceI]];
4404 label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
4408 if (ownZone == neiZone)
4411 flip = meshFlipMap.test(faceI);
4418 || (neiZone != -1 && ownZone > neiZone)
4426 mesh_.faces()[faceI],
4446 forAll(cellToZone, cellI)
4448 label zoneI = cellToZone[cellI];
4466 void Foam::meshRefinement::allocateInterRegionFaceZone
4468 const label ownZone,
4469 const label neiZone,
4471 LabelPairMap<word>& zoneIDsToFaceZone
4476 if (ownZone != neiZone)
4483 || (neiZone != -1 && ownZone > neiZone)
4493 if (!zoneIDsToFaceZone.found(
key))
4496 const word ownZoneName =
4499 ? cellZones[ownZone].name()
4502 const word neiZoneName =
4505 ? cellZones[neiZone].name()
4510 Pair<word> wordKey(ownZoneName, neiZoneName);
4516 word fzName = wordKey.first() +
"_to_" + wordKey.second();
4518 zoneIDsToFaceZone.insert(
key, fzName);
4519 zonesToFaceZone.insert(wordKey, fzName);
4529 const bool doHandleSnapProblems,
4531 const bool useTopologicalSnapDetection,
4532 const bool removeEdgeConnectedCells,
4534 const label nErodeCellZones,
4543 const bool exitIfLeakPath,
4553 Info<<
"Introducing baffles for " 4555 <<
" faces that are intersected by the surface." <<
nl <<
endl;
4558 labelList neiLevel(mesh_.nBoundaryFaces());
4560 calcNeighbourData(neiLevel, neiCc);
4566 globalToMasterPatch,
4570 locationsOutsideMesh,
4581 createBaffles(ownPatch, neiPatch);
4589 Info<<
"Created baffles in = " 4592 printMeshInfo(
debug,
"After introducing baffles");
4596 const_cast<Time&
>(mesh_.time())++;
4605 Pout<<
"Dumped debug data in = " 4615 if (doHandleSnapProblems)
4620 useTopologicalSnapDetection,
4621 removeEdgeConnectedCells,
4625 globalToMasterPatch,
4633 neiLevel.setSize(mesh_.nBoundaryFaces());
4634 neiCc.setSize(mesh_.nBoundaryFaces());
4635 calcNeighbourData(neiLevel, neiCc);
4641 globalToMasterPatch,
4645 locationsOutsideMesh,
4656 createBaffles(ownPatch, neiPatch);
4671 <<
"Remove unreachable sections of mesh" <<
nl 4672 <<
"-----------------------------------" <<
nl 4682 globalToMasterPatch,
4685 locationsOutsideMesh,
4695 Info<<
"Split mesh in = " 4698 printMeshInfo(
debug,
"After subsetting");
4711 Pout<<
"Dumped debug data in = " 4720 const bool useTopologicalSnapDetection,
4721 const bool removeEdgeConnectedCells,
4723 const scalar planarAngle,
4736 <<
"Merge free-standing baffles" <<
nl 4737 <<
"---------------------------" <<
nl 4753 Info<<
"Detected free-standing baffles : " << nCouples <<
endl;
4767 useTopologicalSnapDetection,
4768 removeEdgeConnectedCells,
4772 globalToMasterPatch,
4780 <<
"Remove unreachable sections of mesh" <<
nl 4781 <<
"-----------------------------------" <<
nl 4791 globalToMasterPatch,
4794 locationsOutsideMesh,
4806 Info<<
"Merged free-standing baffles in = " 4813 const label nBufferLayers,
4814 const label nErodeCellZones,
4821 const bool exitIfLeakPath,
4830 labelList neiLevel(mesh_.nBoundaryFaces());
4832 calcNeighbourData(neiLevel, neiCc);
4839 globalToMasterPatch,
4843 locationsOutsideMesh,
4855 boolList blockedFace(mesh_.nFaces(),
false);
4859 if (ownPatch[faceI] != -1 || neiPatch[faceI] != -1)
4861 blockedFace[faceI] =
true;
4873 vector::uniform(mergeDistance_),
4875 locationsOutsideMesh,
4887 globalToMasterPatch,
4898 const label nBufferLayers,
4913 const labelList& faceOwner = mesh_.faceOwner();
4914 const labelList& faceNeighbour = mesh_.faceNeighbour();
4918 for (label facei = 0; facei < mesh_.nInternalFaces(); facei++)
4920 if (ownPatch[facei] == -1 && neiPatch[facei] != -1)
4923 <<
" at:" << mesh_.faceCentres()[facei]
4924 <<
" ownPatch:" << ownPatch[facei]
4925 <<
" neiPatch:" << neiPatch[facei]
4931 const label ownRegion = cellRegion[faceOwner[facei]];
4932 const label neiRegion = cellRegion[faceNeighbour[facei]];
4933 if (ownRegion != neiRegion)
4935 if (ownPatch[facei] == -1)
4938 <<
" at:" << mesh_.faceCentres()[facei]
4939 <<
" ownPatch:" << ownPatch[facei]
4940 <<
" ownRegion:" << ownRegion
4941 <<
" neiPatch:" << neiPatch[facei]
4942 <<
" neiRegion:" << neiRegion
4954 DynamicList<label> startFaces;
4957 if (ownPatch[facei] != -1)
4959 startFaces.append(facei);
4965 autoPtr<mapDistribute> mapPtr;
4969 bitSet(mesh_.nFaces()),
4977 labelList startOwnPatch(ownPatch, startFaces);
4978 mapPtr().distribute(startOwnPatch);
4980 nearestOwnPatch.setSize(mesh_.nFaces());
4981 nearestOwnPatch = -1;
4982 forAll(faceToStart, facei)
4984 const label sloti = faceToStart[facei];
4987 nearestOwnPatch[facei] = startOwnPatch[sloti];
5001 bitSet isFrozenPoint(mesh_.nPoints());
5002 bitSet isFrozenFace(mesh_.nFaces());
5008 const label pointZonei = pzs.
findZoneID(
"frozenPoints");
5009 if (pointZonei != -1)
5011 const pointZone& pz = pzs[pointZonei];
5012 isFrozenPoint.set(pz);
5013 for (
const label pointi : pz)
5015 isFrozenFace.set(pointFaces[pointi]);
5020 const label faceZonei = fzs.
findZoneID(
"frozenFaces");
5021 if (faceZonei != -1)
5023 const faceZone& fz = fzs[faceZonei];
5024 isFrozenFace.set(fz);
5025 for (
const label facei : fz)
5027 isFrozenPoint.set(mesh_.faces()[facei]);
5033 label defaultPatch = 0;
5034 if (globalToMasterPatch.
size())
5036 defaultPatch = globalToMasterPatch[0];
5039 for (label i = 0; i < nBufferLayers; i++)
5043 labelList pointBaffle(mesh_.nPoints(), -1);
5045 forAll(faceNeighbour, facei)
5047 if (!isFrozenFace[facei])
5049 const face&
f = mesh_.faces()[facei];
5051 const label ownRegion = cellRegion[faceOwner[facei]];
5052 const label neiRegion = cellRegion[faceNeighbour[facei]];
5054 if (ownRegion == -1 && neiRegion != -1)
5061 if (!isFrozenPoint[
f[fp]])
5063 pointBaffle[
f[fp]] =
5064 max(defaultPatch, ownPatch[facei]);
5068 else if (ownRegion != -1 && neiRegion == -1)
5070 label newPatchi = neiPatch[facei];
5071 if (newPatchi == -1)
5073 newPatchi =
max(defaultPatch, ownPatch[facei]);
5077 if (!isFrozenPoint[
f[fp]])
5079 pointBaffle[
f[fp]] = newPatchi;
5118 const auto&
patches = mesh_.boundaryMesh();
5119 for (
const auto& pp :
patches)
5130 const label facei = pp.start()+i;
5131 if (!isFrozenFace[facei])
5133 const face&
f = mesh_.faces()[facei];
5134 const label ownRegion = cellRegion[faceOwner[facei]];
5135 const label neiRegion =
5136 neiCellRegion[facei-mesh_.nInternalFaces()];
5140 if (ownRegion == -1 && neiRegion != -1)
5144 if (!isFrozenPoint[
f[fp]])
5146 pointBaffle[
f[fp]] =
5147 max(defaultPatch, ownPatch[facei]);
5151 else if (ownRegion != -1 && neiRegion == -1)
5153 label newPatchI = neiPatch[facei];
5154 if (newPatchI == -1)
5156 newPatchI =
max(defaultPatch, ownPatch[facei]);
5160 if (!isFrozenPoint[
f[fp]])
5162 pointBaffle[
f[fp]] = newPatchI;
5173 const label facei = pp.start()+i;
5174 if (!isFrozenFace[facei])
5176 const face&
f = mesh_.faces()[facei];
5177 const label ownRegion = cellRegion[faceOwner[facei]];
5179 if (ownRegion != -1)
5183 if (!isFrozenPoint[
f[fp]])
5185 pointBaffle[
f[fp]] =
5186 max(defaultPatch, ownPatch[facei]);
5210 forAll(pointFaces, pointi)
5212 if (pointBaffle[pointi] != -1)
5218 const label facei =
pFaces[pFacei];
5220 if (!isFrozenFace[facei] && ownPatch[facei] == -1)
5222 ownPatch[facei] = pointBaffle[pointi];
5236 if (!isFrozenFace[facei] && ownPatch[facei] != -1)
5238 const label own = faceOwner[facei];
5240 if (cellRegion[own] == -1)
5244 const cell& ownFaces = mesh_.cells()[own];
5247 const label ownFacei = ownFaces[j];
5248 if (!isFrozenFace[ownFacei] && ownPatch[ownFacei] == -1)
5250 newOwnPatch[ownFacei] = ownPatch[facei];
5254 if (mesh_.isInternalFace(facei))
5256 const label nei = faceNeighbour[facei];
5258 if (cellRegion[nei] == -1)
5262 const cell& neiFaces = mesh_.cells()[nei];
5265 const label neiFacei = neiFaces[j];
5266 const bool isFrozen = isFrozenFace[neiFacei];
5267 if (!isFrozen && ownPatch[neiFacei] == -1)
5269 newOwnPatch[neiFacei] = ownPatch[facei];
5287 DynamicList<label> cellsToRemove(mesh_.nCells());
5288 forAll(cellRegion, celli)
5290 if (cellRegion[celli] == -1)
5292 cellsToRemove.append(celli);
5295 cellsToRemove.shrink();
5299 mesh_.nCells() - cellsToRemove.size(),
5303 Info<<
"Keeping all cells containing inside points" <<
endl 5304 <<
"Selected for keeping : " << nCellsToKeep <<
" cells." <<
endl;
5308 removeCells cellRemover(mesh_);
5311 const labelList exposedFaces(cellRemover.getExposedFaces(cellsToRemove));
5312 labelList exposedPatches(exposedFaces.size());
5314 label nUnpatched = 0;
5318 label facei = exposedFaces[i];
5320 if (ownPatch[facei] != -1)
5322 exposedPatches[i] = ownPatch[facei];
5326 const label fallbackPatch =
5328 nearestOwnPatch.size()
5329 ? nearestOwnPatch[facei]
5332 if (nUnpatched == 0)
5335 <<
"For exposed face " << facei
5336 <<
" fc:" << mesh_.faceCentres()[facei]
5337 <<
" found no patch." <<
endl 5338 <<
" Taking patch " << fallbackPatch
5339 <<
" instead. Suppressing future warnings" <<
endl;
5343 exposedPatches[i] = fallbackPatch;
5347 reduce(nUnpatched, sumOp<label>());
5350 Info<<
"Detected " << nUnpatched <<
" faces out of " 5352 <<
" for which the default patch " << defaultPatch
5353 <<
" will be used" <<
endl;
5356 return doRemoveCells
5368 const label nBufferLayers,
5369 const label nErodeCellZones,
5381 labelList neiLevel(mesh_.nBoundaryFaces());
5383 calcNeighbourData(neiLevel, neiCc);
5390 globalToMasterPatch,
5394 locationsOutsideMesh,
5409 limitShells_.findLevel
5411 mesh_.cellCentres(),
5415 forAll(levelShell, celli)
5417 if (levelShell[celli] != -1)
5420 cellRegion[celli] = -1;
5427 globalToMasterPatch,
5436 const_cast<Time&
>(mesh_.time())++;
5437 Pout<<
"Writing mesh after removing limitShells" 5468 Info<<
"dupNonManifoldPoints : Found : " << nNonManifPoints
5469 <<
" non-manifold points (out of " 5470 << mesh_.globalData().nTotalPoints()
5476 if (nNonManifPoints)
5486 mesh_.moving(
false);
5489 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
5493 mesh_.updateMesh(map);
5532 label nPointPairs = 0;
5533 forAll(pointToDuplicate, pointI)
5535 label otherPointI = pointToDuplicate[pointI];
5536 if (otherPointI != -1)
5547 forAll(pointToDuplicate, pointI)
5549 label otherPointI = pointToDuplicate[pointI];
5550 if (otherPointI != -1)
5553 pointToMaster.
insert(pointI, otherPointI);
5565 mesh_.moving(
false);
5568 mapPtr = meshMod.
changeMesh(mesh_,
false,
true);
5572 mesh_.updateMesh(map);
5619 internalOrBaffleFaceZones = getZones(fzTypes);
5629 forAll(boundaryFaceZones, j)
5631 const faceZone& fZone = mesh_.faceZones()[boundaryFaceZones[j]];
5634 const face&
f = mesh_.faces()[fZone[i]];
5637 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 1u);
5641 forAll(internalOrBaffleFaceZones, j)
5643 const faceZone& fZone = mesh_.faceZones()[internalOrBaffleFaceZones[j]];
5646 const face&
f = mesh_.faces()[fZone[i]];
5649 pointStatus[
f[fp]] =
max(pointStatus[
f[fp]], 2u);
5664 forAll(pointStatus, pointI)
5666 if (pointStatus[pointI] == 1u)
5673 Info<<
"Duplicating " << globalNPoints <<
" points on" 5674 <<
" faceZones of type " 5684 forAll(pointStatus, pointI)
5686 if (pointStatus[pointI] == 1u)
5688 candidatePoints[
n++] = pointI;
5701 const bool allowFreeStandingZoneFaces,
5702 const label nErodeCellZones,
5706 const bool exitIfLeakPath,
5711 if (locationsInMesh.
size() != zonesInMesh.
size())
5721 labelList neiLevel(mesh_.nBoundaryFaces());
5723 calcNeighbourData(neiLevel, neiCc);
5732 if (namedSurfaces.
size())
5734 Info<<
"Setting cellZones according to named surfaces:" <<
endl;
5737 label surfI = namedSurfaces[i];
5739 Info<<
"Surface : " << surfaces_.names()[surfI] <<
nl 5740 <<
" faceZones : " << surfZones[surfI].faceZoneNames() <<
nl 5741 <<
" cellZone : " << surfZones[surfI].cellZoneName()
5782 allowFreeStandingZoneFaces,
5787 locationsOutsideMesh,
5804 labelList faceToZone(mesh_.nFaces(), -1);
5806 forAll(namedSurfaceRegion, faceI)
5809 label globalI = namedSurfaceRegion[faceI];
5812 const labelPair spr = surfaces_.whichSurface(globalI);
5813 faceToZone[faceI] = surfaceToFaceZones[spr.
first()][spr.
second()];
5827 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
5829 if (faceToZone[faceI] == -1)
5834 allocateInterRegionFaceZone
5836 cellToZone[mesh_.faceOwner()[faceI]],
5837 cellToZone[mesh_.faceNeighbour()[faceI]],
5847 forAll(neiCellZone, bFaceI)
5849 label faceI = bFaceI + mesh_.nInternalFaces();
5850 if (faceToZone[faceI] == -1)
5852 allocateInterRegionFaceZone
5854 cellToZone[mesh_.faceOwner()[faceI]],
5855 neiCellZone[bFaceI],
5873 Info<<
"Setting faceZones according to neighbouring cellZones:" 5887 const word& fzName = zonesToFaceZone[cz];
5890 << cz[0] <<
' ' << cz[1] <<
nl 5891 <<
" faceZone : " << fzName <<
endl;
5901 label cz0 = cellZones.findZoneID(cz[0]);
5902 label cz1 = cellZones.findZoneID(cz[1]);
5912 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
5914 if (faceToZone[faceI] == -1)
5920 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
5921 label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
5922 if (ownZone != neiZone)
5927 || (neiZone != -1 && ownZone > neiZone)
5934 faceToZone[faceI] = fZoneLookup[
key];
5938 forAll(neiCellZone, bFaceI)
5940 label faceI = bFaceI + mesh_.nInternalFaces();
5941 if (faceToZone[faceI] == -1)
5943 label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
5944 label neiZone = neiCellZone[bFaceI];
5945 if (ownZone != neiZone)
5950 || (neiZone != -1 && ownZone > neiZone)
5957 faceToZone[faceI] = fZoneLookup[
key];
5976 label bFaceI = pp.
start()-mesh_.nInternalFaces();
5979 neiCellZone[bFaceI++] = -1;
6000 bitSet meshFlipMap(mesh_.nFaces(),
false);
6008 freeStandingBaffleFaces
6019 if (nFreeStanding > 0)
6021 Info<<
"Detected " << nFreeStanding <<
" free-standing zone faces" 6026 OBJstream str(mesh_.time().path()/
"freeStanding.obj");
6027 Pout<<
"meshRefinement::zonify : dumping faceZone faces to " 6035 calcPatchNumMasterFaces(isMasterFace,
patch, nMasterFacesPerEdge);
6040 const label nZones = markPatchZones
6043 nMasterFacesPerEdge,
6048 for (label zoneI = 0; zoneI < nZones; zoneI++)
6050 nPosOrientation.
insert(zoneI, 0);
6056 consistentOrientation
6060 nMasterFacesPerEdge,
6061 faceToConnectedZone,
6071 label meshFaceI =
patch.addressing()[faceI];
6073 if (isMasterFace.
test(meshFaceI))
6078 posOrientation.
test(meshFaceI)
6079 == meshFlipMap.test(meshFaceI)
6085 nPosOrientation.
find(faceToConnectedZone[faceI])() +=
n;
6091 Info<<
"Split " << nFreeStanding <<
" free-standing zone faces" 6092 <<
" into " << nZones <<
" disconnected regions with size" 6093 <<
" (negative denotes wrong orientation) :" 6096 for (label zoneI = 0; zoneI < nZones; zoneI++)
6098 Info<<
" " << zoneI <<
"\t" << nPosOrientation[zoneI]
6106 consistentOrientation
6110 nMasterFacesPerEdge,
6111 faceToConnectedZone,
6138 mesh_.moving(
false);
6144 mesh_.updateMesh(map());
6147 if (map().hasMotionPoints())
6149 mesh_.movePoints(map().preMotionPoints());
6161 if (mesh_.cellZones().size() > 0)
6164 forAll(mesh_.cellZones(), zoneI)
6166 const cellZone& cz = mesh_.cellZones()[zoneI];
6173 if (mesh_.faceZones().size() > 0)
6176 forAll(mesh_.faceZones(), zoneI)
6178 const faceZone& fz = mesh_.faceZones()[zoneI];
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
virtual const fileName & name() const
Get the name of the output serial stream. (eg, the name of the Fstream file name) ...
List< labelList > labelListList
A List of labelList.
Class containing data for face removal.
const T & first() const noexcept
Access the first element.
void size(const label n)
Older name for setAddressableSize.
ZoneMesh< faceZone, polyMesh > faceZoneMesh
A ZoneMesh with the type faceZone.
const labelIOList & zoneIDs
fileName path() const
Return path.
labelList findIndices(const ListType &input, const UnaryPredicate &pred, label start=0)
Linear search to find all occurences of given element.
Ostream & indent(Ostream &os)
Indent stream.
autoPtr< mapPolyMesh > mergePoints(const labelList &pointToDuplicate)
Merge duplicate points.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Class describing modification of a face.
A face is a list of labels corresponding to mesh vertices.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void append(const T &val)
Append an element at the end of the list.
label find(const T &val, label pos=0) const
Find index of the first occurrence of the value.
virtual const labelList & faceNeighbour() const
Return face neighbour.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Unit conversion functions.
constexpr char nl
The newline '\n' character (0x0a)
static labelListList addFaceZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
label start() const noexcept
The start label of boundary faces in the polyMesh face list.
bool coupled(solutionDict.getOrDefault("coupledEnergyField", false))
T & first()
Access first element of the list, position [0].
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool found(const T &val, label pos=0) const
True if the value if found in the list.
autoPtr< mapPolyMesh > createBaffles(const labelList &ownPatch, const labelList &neiPatch)
Create baffle for every internal face where ownPatch != -1.
static labelList addCellZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
label size() const noexcept
The number of elements in table.
static const Enum< faceZoneType > faceZoneTypeNames
label whichFace(const label globalCellID) const
Helper function to re-direct to zone::localID(...)
labelList getZones(const List< surfaceZonesInfo::faceZoneType > &fzTypes) const
Get zones of given type.
static List< labelPair > subsetBaffles(const polyMesh &mesh, const labelList &zoneIDs, const List< labelPair > &baffles)
Subset baffles according to zones.
const dimensionSet dimless
Dimensionless.
label nFaces() const noexcept
Number of mesh faces.
static labelList getStandaloneNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces without a cellZone.
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field...
autoPtr< mapPolyMesh > changeMesh(polyMesh &mesh, const labelUList &patchMap, const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Inplace changes mesh without change of patches.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
DynamicID< faceZoneMesh > faceZoneID
Foam::faceZoneID.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A class for managing references or pointers (no reference counting)
bool hasMotionPoints() const
Has valid preMotionPoints?
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
bool isInternalFace(const label faceIndex) const noexcept
Return true if given face label is internal to the mesh.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Takes mesh with 'baffles' (= boundary faces sharing points). Determines for selected points on bounda...
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
static labelPairList findDuplicateFacePairs(const polyMesh &)
Helper routine to find all baffles (two boundary faces.
#define forAll(list, i)
Loop across all elements in list.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
void mergeFreeStandingBaffles(const snapParameters &snapParams, const bool useTopologicalSnapDetection, const bool removeEdgeConnectedCells, const scalarField &perpendicularAngle, const scalar planarAngle, const dictionary &motionDict, Time &runTime, const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const pointField &locationsOutsideMesh)
Merge free-standing baffles.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
A list of faces which address into the list of points.
Determines the 'side' for every face and connected to a singly-connected (through edges) region of fa...
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
vectorField pointField
pointField is a vectorField.
const dimensionedScalar e
Elementary charge.
void setSize(const label n)
Alias for resize()
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
dimensionedScalar cos(const dimensionedScalar &ds)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
static void mergePoints(const polyMesh &, const Map< label > &pointToMaster, polyTopoChange &meshMod)
Helper: Merge points.
const wordList area
Standard area field types (scalar, vector, tensor, etc)
void clear()
Clear the list, i.e. set size to zero.
label checkData(const fvMesh &mesh, const instantList &timeDirs, wordList &objectNames)
Check if fields are good to use (available at all times)
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
Simple container to keep together snap specific information.
label size() const noexcept
The number of elements in the list.
void baffleAndSplitMesh(const bool handleSnapProblems, const snapParameters &snapParams, const bool useTopologicalSnapDetection, const bool removeEdgeConnectedCells, const scalarField &perpendicularAngle, const label nErodeCellZones, const dictionary &motionDict, Time &runTime, const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const wordList ®ionsInMesh, const pointField &locationsOutsideMesh, const bool exitIfLeakPath, const refPtr< coordSetWriter > &leakPathFormatter)
Split off unreachable areas of mesh.
autoPtr< mapPolyMesh > mergeZoneBaffles(const bool doInternalZones, const bool doBaffleZones)
Merge all baffles on faceZones.
virtual const labelList & faceOwner() const
Return face owner.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
autoPtr< mapPolyMesh > removeLimitShells(const label nBufferLayers, const label nErodeCellZones, const labelList &globalToMasterPatch, const labelList &globalToSlavePatch, const pointField &locationsInMesh, const wordList ®ionsInMesh, const pointField &locationsOutsideMesh)
Remove cells from limitRegions if level -1.
void reverse(UList< T > &list, const label n)
Reverse the first n elements of the list.
ZoneMesh< pointZone, polyMesh > pointZoneMesh
A ZoneMesh with the type pointZone.
void append(const T &val)
Copy append an element to the end of this list.
virtual const faceList & faces() const
Return raw faces.
static labelList getInsidePointNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of surfaces with a cellZone that have 'insidePoint'.
A HashTable similar to std::unordered_map.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
static labelList getUnnamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of unnamed surfaces (surfaces without faceZoneName)
errorManip< error > abort(error &err)
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
bool test(const label pos) const
Test value at specified position, never auto-vivify entries.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
Istream and Ostream manipulators taking arguments.
An OFstream that keeps track of vertices and provides convenience output methods for OBJ files...
int debug
Static debugging option.
Pair< label > labelPair
A pair of labels.
Type gMax(const FieldField< Field, Type > &f)
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type test(const label i) const
Test bool value at specified position, always false for out-of-range access.
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=cellModel::ref(cellModel::HEX);labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){ pointMap[i]=i;}for(label i=0;i< nPoints;i++){ if(f[i] > 0.0) { hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells].reset(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei) { if(edges[ei].mag(points)< SMALL) { label start=pointMap[edges[ei].start()];while(start !=pointMap[start]) { start=pointMap[start];} label end=pointMap[edges[ei].end()];while(end !=pointMap[end]) { end=pointMap[end];} label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;} } cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){ cellShape &cs=cellShapes[celli];forAll(cs, i) { cs[i]=pointMap[cs[i]];} cs.collapse();}label bcIDs[11]={-1, 0, 2, 4, -1, 5, -1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={ &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &symmetryPolyPatch::typeName, &wedgePolyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &symmetryPolyPatch::typeName, &oldCyclicPolyPatch::typeName};enum patchTypeNames{ PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={ "piston", "valve", "liner", "cylinderHead", "axis", "wedge", "inflow", "outflow", "presin", "presout", "symmetryPlane", "cyclic"};List< SLList< face > > pFaces[nBCs]
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
autoPtr< mapPolyMesh > createZoneBaffles(const labelList &zoneIDs, List< labelPair > &baffles, labelList &originatingFaceZone)
Create baffles for faces on faceZones. Return created baffles.
const vectorField & faceCentres() const
List< word > wordList
A List of words.
PrimitivePatch< UIndirectList< face >, const pointField & > uindirectPrimitivePatch
A PrimitivePatch with UIndirectList for the faces, const reference for the point field.
autoPtr< mapPolyMesh > dupNonManifoldPoints()
Find boundary points that connect to more than one cell.
UIndirectList< label > labelUIndList
UIndirectList of labels.
vector point
Point is a vector.
autoPtr< mapPolyMesh > dupNonManifoldBoundaryPoints()
Find boundary points that are on faceZones of type boundary.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
#define WarningInFunction
Report a warning using Foam::Warning.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Direct mesh changes based on v1.3 polyTopoChange syntax.
label whichPatch(const label faceIndex) const
Return patch index for a given mesh face index.
label start() const
Return start label of this patch in the polyMesh face list.
const polyBoundaryMesh & patches
const word & name() const noexcept
The zone name.
void getZoneFaces(const labelList &zoneIDs, labelList &faceZoneID, labelList &ownPatch, labelList &neiPatch, labelList &nBaffles) const
Get per-face information (faceZone, master/slave patch)
Automatically write from objectRegistry::writeObject()
const std::string patch
OpenFOAM patch number as a std::string.
void setRefinement(const localPointRegion ®ionSide, polyTopoChange &)
Play commands into polyTopoChange to duplicate points. Gets.
label nRegions() const
Return total number of regions.
static List< pointField > zonePoints(const pointField &locationsInMesh, const wordList &zonesInMesh, const pointField &locationsOutsideMesh)
Helper: per zone (entry in zonesInMesh) the locations with.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
autoPtr< mapPolyMesh > mergeBaffles(const List< labelPair > &, const Map< label > &faceToPatch)
Merge baffles. Gets pairs of faces and boundary faces to move.
static labelList getClosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are closed and.
const boolList & flipMap() const noexcept
Return face flip map.
static labelList getNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces (surfaces with faceZoneName)
messageStream Info
Information stream (stdout output on master, null elsewhere)
writeType
Enumeration for what to write. Used as a bit-pattern.
Field< vector > vectorField
Specialisation of Field<T> for vector.
static autoPtr< mapDistribute > calcClosure(const polyMesh &mesh, const List< pointField > &zonePoints, const labelList &blockedFaces, const globalIndex &globalBlockedFaces, const bool erode, labelList &closureFaces, labelList &closureToBlocked)
Optional direct use to generate the set of faces and the method to.
faceZoneType
What to do with faceZone faces.
debugType
Enumeration for what to debug. Used as a bit-pattern.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Mesh consisting of general polyhedral cells.
Omanip< int > setw(const int i)
A subset of mesh faces organised as a primitive patch.
List< label > labelList
A List of labels.
A patch is a list of labels that address the faces in the global face list.
const T & second() const noexcept
Access the second element.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
static void mapCombineReduce(Container &values, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine map values from different processo...
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
List< bool > boolList
A List of bools.
A List with indirect addressing.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
HashTable< word, wordPair, Foam::Hash< wordPair > > wordPairHashTable
HashTable of wordPair.
ZoneMesh< cellZone, polyMesh > cellZoneMesh
A ZoneMesh with the type cellZone.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
static label addFaceZone(const word &name, const labelList &addressing, const boolList &flipMap, polyMesh &mesh)
const labelList & reverseFaceMap() const
Reverse face map.
const pointField & preMotionPoints() const
Pre-motion point positions.
forAllConstIters(mixture.phases(), phase)
static void listCombineReduce(List< T > &values, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
After completion all processors have the same data.
A HashTable to objects of type <T> with a label key.
label setAction(const topoAction &action)
For compatibility with polyTopoChange: set topological action.
static constexpr const zero Zero
Global zero (0)