From b8c2c0acf64eea7906357cb140eaaf7746727a6f Mon Sep 17 00:00:00 2001 From: Mattijs Janssens Date: Thu, 16 Jan 2020 12:22:02 +0000 Subject: [PATCH] ENH: shm: support for automatic faceZones --- .../conformalVoronoiMeshZones.C | 33 +- .../conformationSurfaces.C | 11 +- .../generation/snappyHexMesh/snappyHexMesh.C | 36 +- .../meshRefinement/meshRefinement.H | 21 +- .../meshRefinement/meshRefinementBaffles.C | 230 +- .../refinementSurfaces/refinementSurfaces.C | 55 +- .../refinementSurfaces/refinementSurfaces.H | 17 +- .../refinementSurfaces/surfaceZonesInfo.C | 127 +- .../refinementSurfaces/surfaceZonesInfo.H | 32 +- .../snappyHexMeshDriver/snappySnapDriver.C | 260 +- .../snappyHexMeshDriver/snappySnapDriver.H | 6 +- .../snappySnapDriverFeature.C | 51 +- .../snappyHexMesh/faceZoneRegions/Allclean | 14 + .../mesh/snappyHexMesh/faceZoneRegions/Allrun | 10 + .../snappyHexMesh/faceZoneRegions/README.txt | 2 + .../constant/triSurface/box-randomAligned.stl | 1076 +++ .../constant/triSurface/fixed.obj | 7532 +++++++++++++++++ .../constant/triSurface/rotatingZone.obj | 5948 +++++++++++++ .../faceZoneRegions/system/blockMeshDict | 68 + .../faceZoneRegions/system/controlDict | 47 + .../faceZoneRegions/system/fvOptions | 102 + .../faceZoneRegions/system/fvSchemes | 66 + .../faceZoneRegions/system/fvSolution | 58 + .../faceZoneRegions/system/meshQualityDict | 22 + .../faceZoneRegions/system/snappyHexMeshDict | 166 + .../system/surfaceFeatureExtractDict | 27 + 26 files changed, 15695 insertions(+), 322 deletions(-) create mode 100755 tutorials/mesh/snappyHexMesh/faceZoneRegions/Allclean create mode 100755 tutorials/mesh/snappyHexMesh/faceZoneRegions/Allrun create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/README.txt create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/constant/triSurface/box-randomAligned.stl create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/constant/triSurface/fixed.obj create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/constant/triSurface/rotatingZone.obj create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/system/blockMeshDict create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/system/controlDict create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/system/fvOptions create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/system/fvSchemes create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/system/fvSolution create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/system/meshQualityDict create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/system/snappyHexMeshDict create mode 100644 tutorials/mesh/snappyHexMesh/faceZoneRegions/system/surfaceFeatureExtractDict diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshZones.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshZones.C index 41e6d0e34a..8fae48033c 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshZones.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshZones.C @@ -585,35 +585,52 @@ void Foam::conformalVoronoiMesh::addZones labelList namedSurfaces(surfaceZonesInfo::getNamedSurfaces(surfZones)); + // Tbd. No support yet for multi-faceZones on outside of cellZone + forAll(namedSurfaces, i) { label surfI = namedSurfaces[i]; + const wordList& fzNames = surfZones[surfI].faceZoneNames(); Info<< incrIndent << indent << "Surface : " << geometryToConformTo().geometry().names()[surfI] << nl << indent << " faceZone : " - << surfZones[surfI].faceZoneName() << nl + << (fzNames.size() ? fzNames[0] : "") << nl << indent << " cellZone : " << surfZones[surfI].cellZoneName() << decrIndent << endl; } // Add zones to mesh - labelList surfaceToFaceZone = - surfaceZonesInfo::addFaceZonesToMesh + labelList surfaceToFaceZone(surfZones.size(), -1); + { + const labelListList surfaceToFaceZones ( - surfZones, - namedSurfaces, - mesh + surfaceZonesInfo::addFaceZonesToMesh + ( + surfZones, + namedSurfaces, + mesh + ) ); + forAll(surfaceToFaceZones, surfi) + { + if (surfaceToFaceZones[surfi].size()) + { + surfaceToFaceZone[surfi] = surfaceToFaceZones[surfi][0]; + } + } + } - labelList surfaceToCellZone = + const labelList surfaceToCellZone + ( surfaceZonesInfo::addCellZonesToMesh ( surfZones, namedSurfaces, mesh - ); + ) + ); // Topochange container polyTopoChange meshMod(mesh); diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C index 6dc341e4a8..600ee89ca9 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C @@ -355,7 +355,16 @@ Foam::conformationSurfaces::conformationSurfaces // Surface zones if (dict.found("faceZone")) { - surfZones_.set(surfI, new surfaceZonesInfo(surface, dict)); + surfZones_.set + ( + surfI, + new surfaceZonesInfo + ( + surface, + dict, + allGeometry_.regionNames()[surfaces_[surfI]] + ) + ); } allGeometryToSurfaces_[surfaces_[surfI]] = surfI; diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C index ab3f946896..3998d13538 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C @@ -163,7 +163,16 @@ autoPtr createRefinementSurfaces globalLevelIncr[surfi] = gapLevelIncrement; // Surface zones - surfZones.set(surfi, new surfaceZonesInfo(surface, shapeDict)); + surfZones.set + ( + surfi, + new surfaceZonesInfo + ( + surface, + shapeDict, + allGeometry.regionNames()[surfaces[surfi]] + ) + ); // Global perpendicular angle @@ -1395,9 +1404,10 @@ int main(int argc, char *argv[]) Info<< surfaces.names()[surfi] << ':' << nl << nl; } - const word& fzName = surfaces.surfZones()[surfi].faceZoneName(); + const wordList& fzNames = + surfaces.surfZones()[surfi].faceZoneNames(); - if (fzName.empty()) + if (fzNames.empty()) { // 'Normal' surface forAll(regNames, i) @@ -1520,15 +1530,19 @@ int main(int argc, char *argv[]) // region in surface for patch for zoning if (regNames.size()) { - label globalRegioni = surfaces.globalRegion(surfi, 0); + forAll(fzNames, fzi) + { + const word& fzName = fzNames[fzi]; + label globalRegioni = surfaces.globalRegion(surfi, fzi); - meshRefiner.addFaceZone - ( - fzName, - pbm[globalToMasterPatch[globalRegioni]].name(), - pbm[globalToSlavePatch[globalRegioni]].name(), - surfaces.surfZones()[surfi].faceType() - ); + meshRefiner.addFaceZone + ( + fzName, + pbm[globalToMasterPatch[globalRegioni]].name(), + pbm[globalToSlavePatch[globalRegioni]].name(), + surfaces.surfZones()[surfi].faceType() + ); + } } } diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H index 3a43723a5e..7bbdcf96a3 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H @@ -597,14 +597,15 @@ private: ) const; //- Calculate intersections on zoned faces. Return per face -1 - // or the index of the surface and the orientation w.r.t. surface + // or the global region of the surface and the orientation + // w.r.t. surface void getIntersections ( const labelList& surfacesToTest, const pointField& neiCc, const labelList& testFaces, - labelList& namedSurfaceIndex, + labelList& namedSurfaceRegion, bitSet& posOrientation ) const; @@ -737,13 +738,13 @@ private: //- Finds zone per cell for cells inside closed named surfaces. // (uses geometric test for insideness) - // Adapts namedSurfaceIndex so all faces on boundary of cellZone + // Adapts namedSurfaceRegion so all faces on boundary of cellZone // have corresponding faceZone. void findCellZoneGeometric ( const pointField& neiCc, const labelList& closedNamedSurfaces, - labelList& namedSurfaceIndex, + labelList& namedSurfaceRegion, const labelList& surfaceToCellZone, labelList& cellToZone ) const; @@ -781,14 +782,14 @@ private: //- Finds zone per cell. Uses topological walk with all faces // marked in unnamedSurfaceRegion (intersections with unnamed - // surfaces) and namedSurfaceIndex (intersections with named + // surfaces) and namedSurfaceRegion (intersections with named // surfaces) regarded as blocked. void findCellZoneTopo ( const label backgroundZoneID, const pointField& locationsInMesh, const labelList& unnamedSurfaceRegion, - const labelList& namedSurfaceIndex, + const labelList& namedSurfaceRegion, const labelList& surfaceToCellZone, labelList& cellToZone ) const; @@ -800,17 +801,17 @@ private: const label nErodeCellZones, const label backgroundZoneID, const labelList& unnamedSurfaceRegion, - const labelList& namedSurfaceIndex, + const labelList& namedSurfaceRegion, labelList& cellToZone ) const; - //- Make namedSurfaceIndex consistent with cellToZone + //- Make namedSurfaceRegion consistent with cellToZone // - clear out any blocked faces inbetween same cell zone. void makeConsistentFaceIndex ( const labelList& zoneToNamedSurface, const labelList& cellToZone, - labelList& namedSurfaceIndex + labelList& namedSurfaceRegion ) const; //- Calculate cellZone allocation @@ -825,7 +826,7 @@ private: labelList& cellToZone, labelList& unnamedRegion1, labelList& unnamedRegion2, - labelList& namedSurfaceIndex, + labelList& namedSurfaceRegion, bitSet& posOrientation ) const; diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C index ae7831eb49..fb15e77059 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C @@ -307,7 +307,7 @@ void Foam::meshRefinement::getBafflePatches labelList cellToZone; labelList unnamedRegion1; labelList unnamedRegion2; - labelList namedSurfaceIndex; + labelList namedSurfaceRegion; { bitSet posOrientation; zonify @@ -321,7 +321,7 @@ void Foam::meshRefinement::getBafflePatches cellToZone, unnamedRegion1, unnamedRegion2, - namedSurfaceIndex, + namedSurfaceRegion, posOrientation ); } @@ -381,8 +381,8 @@ void Foam::meshRefinement::getBafflePatches || (neiZone >= 0 && ownZone != -2) ) && ( - namedSurfaceIndex.size() == 0 - || namedSurfaceIndex[faceI] == -1 + namedSurfaceRegion.size() == 0 + || namedSurfaceRegion[faceI] == -1 ) ) { @@ -426,17 +426,17 @@ Foam::Map Foam::meshRefinement::getZoneBafflePatches forAll(surfZones, surfI) { - const word& faceZoneName = surfZones[surfI].faceZoneName(); + const wordList& faceZoneNames = surfZones[surfI].faceZoneNames(); - if (faceZoneName.size()) + forAll(faceZoneNames, fzi) { // Get zone + const word& faceZoneName = faceZoneNames[fzi]; label zoneI = fZones.findZoneID(faceZoneName); - const faceZone& fZone = fZones[zoneI]; // Get patch allocated for zone - label globalRegionI = surfaces_.globalRegion(surfI, 0); + label globalRegionI = surfaces_.globalRegion(surfI, fzi); labelPair zPatches ( globalToMasterPatch[globalRegionI], @@ -1370,7 +1370,7 @@ void Foam::meshRefinement::findCellZoneGeometric ( const pointField& neiCc, const labelList& closedNamedSurfaces, // indices of closed surfaces - labelList& namedSurfaceIndex, // per face index of named surface + labelList& namedSurfaceRegion, // per face: named surface region const labelList& surfaceToCellZone, // cell zone index per surface labelList& cellToZone @@ -1418,11 +1418,9 @@ void Foam::meshRefinement::findCellZoneGeometric // Count points to test. label nCandidates = 0; - forAll(namedSurfaceIndex, faceI) + forAll(namedSurfaceRegion, faceI) { - label surfI = namedSurfaceIndex[faceI]; - - if (surfI != -1) + if (namedSurfaceRegion[faceI] != -1) { if (mesh_.isInternalFace(faceI)) { @@ -1438,11 +1436,9 @@ void Foam::meshRefinement::findCellZoneGeometric // Collect points. pointField candidatePoints(nCandidates); nCandidates = 0; - forAll(namedSurfaceIndex, faceI) + forAll(namedSurfaceRegion, faceI) { - label surfI = namedSurfaceIndex[faceI]; - - if (surfI != -1) + if (namedSurfaceRegion[faceI] != -1) { label own = faceOwner[faceI]; const point& ownCc = cellCentres[own]; @@ -1482,11 +1478,9 @@ void Foam::meshRefinement::findCellZoneGeometric // 3. Update zone information nCandidates = 0; - forAll(namedSurfaceIndex, faceI) + forAll(namedSurfaceRegion, faceI) { - label surfI = namedSurfaceIndex[faceI]; - - if (surfI != -1) + if (namedSurfaceRegion[faceI] != -1) { label own = faceOwner[faceI]; @@ -1518,8 +1512,8 @@ void Foam::meshRefinement::findCellZoneGeometric } - // Adapt the namedSurfaceIndex - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Adapt the namedSurfaceRegion + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // for if any cells were not completely covered. for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++) @@ -1527,7 +1521,7 @@ void Foam::meshRefinement::findCellZoneGeometric label ownZone = cellToZone[mesh_.faceOwner()[faceI]]; label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]]; - if (namedSurfaceIndex[faceI] == -1 && (ownZone != neiZone)) + if (namedSurfaceRegion[faceI] == -1 && (ownZone != neiZone)) { // Give face the zone of min cell zone (but only if the // cellZone originated from a closed, named surface) @@ -1546,12 +1540,14 @@ void Foam::meshRefinement::findCellZoneGeometric minZone = min(ownZone, neiZone); } - // Make sure the cellZone originated from a closed surface + // Make sure the cellZone originated from a closed surface. Use + // hardcoded region 0 inside named surface. label geomSurfI = surfaceToCellZone.find(minZone); if (geomSurfI != -1) { - namedSurfaceIndex[faceI] = geomSurfI; + namedSurfaceRegion[faceI] = + surfaces_.globalRegion(geomSurfI, 0); } } } @@ -1573,7 +1569,7 @@ void Foam::meshRefinement::findCellZoneGeometric label ownZone = cellToZone[mesh_.faceOwner()[faceI]]; label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()]; - if (namedSurfaceIndex[faceI] == -1 && (ownZone != neiZone)) + if (namedSurfaceRegion[faceI] == -1 && (ownZone != neiZone)) { // Give face the min cell zone label minZone; @@ -1590,12 +1586,14 @@ void Foam::meshRefinement::findCellZoneGeometric minZone = min(ownZone, neiZone); } - // Make sure the cellZone originated from a closed surface + // Make sure the cellZone originated from a closed surface. + // Use hardcoded region 0 inside named surface. label geomSurfI = surfaceToCellZone.find(minZone); if (geomSurfI != -1) { - namedSurfaceIndex[faceI] = geomSurfI; + namedSurfaceRegion[faceI] = + surfaces_.globalRegion(geomSurfI, 0); } } } @@ -1603,7 +1601,7 @@ void Foam::meshRefinement::findCellZoneGeometric } // Sync - syncTools::syncFaceList(mesh_, namedSurfaceIndex, maxEqOp