diff --git a/applications/utilities/mesh/generation/foamyHexMesh/Make/options b/applications/utilities/mesh/generation/foamyHexMesh/Make/options index 9461fa3725d8b76cc7cdce5cc102b5aa1933bdbf..f03dbf90976d5f7ecedf098b24beced6e5cb968c 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/Make/options +++ b/applications/utilities/mesh/generation/foamyHexMesh/Make/options @@ -21,6 +21,7 @@ EXE_INC = \ -I$(LIB_SRC)/dynamicMesh/lnInclude \ -I$(LIB_SRC)/triSurface/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \ + -I$(LIB_SRC)/mesh/autoMesh/lnInclude \ -IvectorTools EXE_LIBS = \ diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshToolsTemplates.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshToolsTemplates.C index 551380c6e2017e2c7256482d8255ff63e1980f76..1b570e90e768b204555113f8e436687bad288563 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshToolsTemplates.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshToolsTemplates.C @@ -279,11 +279,9 @@ Foam::tmp<Foam::pointField> Foam::DelaunayMeshTools::allPoints const Triangulation& t ) { - tmp<pointField> tpts(new pointField(t.number_of_vertices(), point::max)); + tmp<pointField> tpts(new pointField(t.vertexCount(), point::max)); pointField& pts = tpts(); - label nVert = 0; - for ( typename Triangulation::Finite_vertices_iterator vit = @@ -292,9 +290,9 @@ Foam::tmp<Foam::pointField> Foam::DelaunayMeshTools::allPoints ++vit ) { - if (vit->internalOrBoundaryPoint()) + if (vit->internalOrBoundaryPoint() && !vit->referred()) { - pts[nVert++] = topoint(vit->point()); + pts[vit->index()] = topoint(vit->point()); } } diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/options b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/options index 9963458aa5b3518a505eeb095fe0874c7105c3fa..2be5855323b10652c1de0a434a8d1ec95f6f2c16 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/options +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/options @@ -22,6 +22,7 @@ EXE_INC = \ -I$(LIB_SRC)/surfMesh/lnInclude \ -I$(LIB_SRC)/triSurface/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \ + -I$(LIB_SRC)/mesh/autoMesh/lnInclude \ -IPrintTable \ -I../vectorTools @@ -32,4 +33,5 @@ LIB_LIBS = \ -ltriSurface \ -ldynamicMesh \ -lsurfMesh \ - -lsampling + -lsampling \ + -lautoMesh diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H index dcaf44f99754f758b63723aa61180e140fe3905e..6dd0675993f1835726ab08988eb01e56afd949f0 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H @@ -600,6 +600,29 @@ private: PackedBoolList& boundaryFacesToRemove ); + //- From meshRefinementBaffles.C. Use insidePoint for a surface to + // determine the cell zone. + void findCellZoneInsideWalk + ( + const polyMesh& mesh, + const labelList& locationSurfaces, + const labelList& faceToSurface, + labelList& cellToSurface + ) const; + + //- Calculate the cell zones from cellCentres using all closed surfaces + labelList calcCellZones(const pointField& cellCentres) const; + + //- Calculate the face zones + void calcFaceZones + ( + const polyMesh& mesh, + const pointField& cellCentres, + const labelList& cellToSurface, + labelList& faceToSurface, + boolList& flipMap + ) const; + //- Tet mesh calculation void calcTetMesh ( @@ -712,9 +735,6 @@ private: bool includeEmptyPatches = false ) const; - //- Create the cell centres to use for the mesh - void createCellCentres(pointField& cellCentres) const; - //- Sort the faces, owner and neighbour lists into // upper-triangular order. For internal faces only, use // before adding patch faces diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C index 86892c28d940c822f80756da75be935159891ce8..c943ca978b9e5abb538a8febb19a2040bfafc3a8 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C @@ -2852,32 +2852,6 @@ void Foam::conformalVoronoiMesh::createFacesOwnerNeighbourAndPatches } -void Foam::conformalVoronoiMesh::createCellCentres -( - pointField& cellCentres -) const -{ - cellCentres.setSize(number_of_vertices(), point::max); - - label vertI = 0; - - for - ( - Delaunay::Finite_vertices_iterator vit = finite_vertices_begin(); - vit != finite_vertices_end(); - ++vit - ) - { - if (vit->internalOrBoundaryPoint()) - { - cellCentres[vertI++] = topoint(vit->point()); - } - } - - cellCentres.setSize(vertI); -} - - void Foam::conformalVoronoiMesh::sortFaces ( faceList& faces, @@ -3095,7 +3069,7 @@ Foam::labelList Foam::conformalVoronoiMesh::removeUnusedCells { Info<< nl << "Removing unused cells" << endl; - PackedBoolList cellUsed(number_of_vertices(), false); + PackedBoolList cellUsed(vertexCount(), false); // Scan all faces to find all of the cells that are used diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C index bb34cbd4a69c0e92987c75c77af047b55dd009a5..07fd509e1f5e100151f2eaa9fff5cda5b26e0585 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C @@ -35,6 +35,11 @@ License #include "pointMesh.H" #include "indexedVertexOps.H" #include "DelaunayMeshTools.H" +#include "surfaceZonesInfo.H" +#include "polyModifyCell.H" +#include "polyModifyFace.H" +#include "syncTools.H" +#include "regionSplit.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -402,6 +407,376 @@ void Foam::conformalVoronoiMesh::writeMesh(const fileName& instance) } +void Foam::conformalVoronoiMesh::findCellZoneInsideWalk +( + const polyMesh& mesh, + const labelList& locationSurfaces, // indices of surfaces with inside point + const labelList& faceToSurface, // per face index of named surface + labelList& cellToSurface +) const +{ + // Analyse regions. Reuse regionsplit + boolList blockedFace(mesh.nFaces()); + //selectSeparatedCoupledFaces(blockedFace); + + forAll(faceToSurface, faceI) + { + if (faceToSurface[faceI] == -1) + { + blockedFace[faceI] = false; + } + else + { + blockedFace[faceI] = true; + } + } + // No need to sync since namedSurfaceIndex already is synced + + // Set region per cell based on walking + regionSplit cellRegion(mesh, blockedFace); + blockedFace.clear(); + + + // Force calculation of face decomposition (used in findCell) + (void)mesh.tetBasePtIs(); + + const PtrList<surfaceZonesInfo>& surfZones = + geometryToConformTo().surfZones(); + + // For all locationSurface find the cell + forAll(locationSurfaces, i) + { + label surfI = locationSurfaces[i]; + + const Foam::point& insidePoint = surfZones[surfI].zoneInsidePoint(); + + const word& surfName = geometryToConformTo().geometry().names()[surfI]; + + Info<< " For surface " << surfName + << " finding inside point " << insidePoint + << endl; + + // Find the region containing the insidePoint + label keepRegionI = -1; + + label cellI = mesh.findCell(insidePoint); + + if (cellI != -1) + { + keepRegionI = cellRegion[cellI]; + } + reduce(keepRegionI, maxOp<label>()); + + Info<< " For surface " << surfName + << " found point " << insidePoint << " in cell " << cellI + << " in global region " << keepRegionI + << " out of " << cellRegion.nRegions() << " regions." << endl; + + if (keepRegionI == -1) + { + FatalErrorIn + ( + "conformalVoronoiMesh::findCellZoneInsideWalk" + "(const polyMesh&, const labelList&" + ", const labelList&, labelList&)" + ) << "Point " << insidePoint + << " is not inside the mesh." << nl + << "Bounding box of the mesh:" << mesh.bounds() + << exit(FatalError); + } + + // Set all cells with this region + forAll(cellRegion, cellI) + { + if (cellRegion[cellI] == keepRegionI) + { + if (cellToSurface[cellI] == -2) + { + cellToSurface[cellI] = surfI; + } + else if (cellToSurface[cellI] != surfI) + { + WarningIn + ( + "conformalVoronoiMesh::findCellZoneInsideWalk" + "(const labelList&, const labelList&" + ", const labelList&, const labelList&)" + ) << "Cell " << cellI + << " at " << mesh.cellCentres()[cellI] + << " is inside surface " << surfName + << " but already marked as being in zone " + << cellToSurface[cellI] << endl + << "This can happen if your surfaces are not" + << " (sufficiently) closed." + << endl; + } + } + } + } +} + + +Foam::labelList Foam::conformalVoronoiMesh::calcCellZones +( + const pointField& cellCentres +) const +{ + labelList cellToSurface(cellCentres.size(), -1); + + const PtrList<surfaceZonesInfo>& surfZones = + geometryToConformTo().surfZones(); + + // Get list of closed surfaces + labelList closedNamedSurfaces + ( + surfaceZonesInfo::getAllClosedNamedSurfaces + ( + surfZones, + geometryToConformTo().geometry(), + geometryToConformTo().surfaces() + ) + ); + + forAll(closedNamedSurfaces, i) + { + label surfI = closedNamedSurfaces[i]; + + const searchableSurface& surface = + allGeometry()[geometryToConformTo().surfaces()[surfI]]; + + const surfaceZonesInfo::areaSelectionAlgo selectionMethod = + surfZones[surfI].zoneInside(); + + if + ( + selectionMethod != surfaceZonesInfo::INSIDE + && selectionMethod != surfaceZonesInfo::OUTSIDE + && selectionMethod != surfaceZonesInfo::INSIDEPOINT + ) + { + FatalErrorIn("conformalVoronoiMesh::calcCellZones(..)") + << "Trying to use surface " + << surface.name() + << " which has non-geometric inside selection method " + << surfaceZonesInfo::areaSelectionAlgoNames[selectionMethod] + << exit(FatalError); + } + + if (surface.hasVolumeType()) + { + List<volumeType> volType; + surface.getVolumeType(cellCentres, volType); + + bool selectInside = true; + if (selectionMethod == surfaceZonesInfo::INSIDEPOINT) + { + List<volumeType> volTypeInsidePoint; + surface.getVolumeType + ( + pointField(1, surfZones[surfI].zoneInsidePoint()), + volTypeInsidePoint + ); + + if (volTypeInsidePoint[0] == volumeType::OUTSIDE) + { + selectInside = false; + } + } + else if (selectionMethod == surfaceZonesInfo::OUTSIDE) + { + selectInside = false; + } + + forAll(volType, pointI) + { + if (cellToSurface[pointI] == -1) + { + if + ( + ( + volType[pointI] == volumeType::INSIDE + && selectInside + ) + || ( + volType[pointI] == volumeType::OUTSIDE + && !selectInside + ) + ) + { + cellToSurface[pointI] = surfI; + } + } + } + } + } + + return cellToSurface; +} + + +void Foam::conformalVoronoiMesh::calcFaceZones +( + const polyMesh& mesh, + const pointField& cellCentres, + const labelList& cellToSurface, + labelList& faceToSurface, + boolList& flipMap +) const +{ + faceToSurface.setSize(mesh.nFaces(), -1); + flipMap.setSize(mesh.nFaces(), false); + + const faceList& faces = mesh.faces(); + const labelList& faceOwner = mesh.faceOwner(); + const labelList& faceNeighbour = mesh.faceNeighbour(); + + forAll(faces, faceI) + { + const label ownerSurfaceI = cellToSurface[faceOwner[faceI]]; + + if (mesh.isInternalFace(faceI)) + { + const label neiSurfaceI = cellToSurface[faceNeighbour[faceI]]; + + flipMap[faceI] = + ( + ownerSurfaceI == max(ownerSurfaceI, neiSurfaceI) + ? false + : true + ); + + if + ( + (ownerSurfaceI >= 0 || neiSurfaceI >= 0) + && ownerSurfaceI != neiSurfaceI + ) + { + if (ownerSurfaceI > neiSurfaceI) + { + faceToSurface[faceI] = ownerSurfaceI; + } + else + { + faceToSurface[faceI] = neiSurfaceI; + } + } + } + else + { + if (ownerSurfaceI >= 0) + { + faceToSurface[faceI] = ownerSurfaceI; + } + } + } + + + const PtrList<surfaceZonesInfo>& surfZones = + geometryToConformTo().surfZones(); + + labelList insidePointNamedSurfaces + ( + surfaceZonesInfo::getInsidePointNamedSurfaces(surfZones) + ); + + // Use intersection of cellCentre connections + forAll(faces, faceI) + { + if + ( + mesh.isInternalFace(faceI) + && faceToSurface[faceI] < 0 + ) + { + const label own = faceOwner[faceI]; + const label nei = faceNeighbour[faceI]; + + pointIndexHit surfHit; + label hitSurface; + + geometryToConformTo().findSurfaceAnyIntersection + ( + cellCentres[own], + cellCentres[nei], + surfHit, + hitSurface + ); + + if (surfHit.hit()) + { + if (findIndex(insidePointNamedSurfaces, hitSurface) != -1) + { + faceToSurface[faceI] = hitSurface; + + vectorField norm; + geometryToConformTo().getNormal + ( + hitSurface, + List<pointIndexHit>(1, surfHit), + norm + ); + + const vector fN = faces[faceI].normal(mesh.points()); + + if ((norm[0] & fN/(mag(fN) + SMALL)) < 0) + { + flipMap[faceI] = true; + } + else + { + flipMap[faceI] = false; + } + } + } + } + } + + + labelList neiCellSurface(mesh.nFaces()-mesh.nInternalFaces()); + const polyBoundaryMesh& patches = mesh.boundaryMesh(); + + forAll(patches, patchI) + { + const polyPatch& pp = patches[patchI]; + + if (pp.coupled()) + { + forAll(pp, i) + { + label faceI = pp.start()+i; + label ownSurface = cellToSurface[faceOwner[faceI]]; + neiCellSurface[faceI - mesh.nInternalFaces()] = ownSurface; + } + } + } + syncTools::swapBoundaryFaceList(mesh, neiCellSurface); + + forAll(patches, patchI) + { + const polyPatch& pp = patches[patchI]; + + if (pp.coupled()) + { + forAll(pp, i) + { + label faceI = pp.start()+i; + label ownSurface = cellToSurface[faceOwner[faceI]]; + label neiSurface = neiCellSurface[faceI-mesh.nInternalFaces()]; + + if (faceToSurface[faceI] == -1 && (ownSurface != neiSurface)) + { + // Give face the max cell zone + faceToSurface[faceI] = max(ownSurface, neiSurface); + } + } + } + } + + // Sync + syncTools::syncFaceList(mesh, faceToSurface, maxEqOp<label>()); +} + + Foam::autoPtr<Foam::fvMesh> Foam::conformalVoronoiMesh::createDummyMesh ( const IOobject& io, @@ -883,7 +1258,11 @@ void Foam::conformalVoronoiMesh::writeMesh // Check that the patch is not empty on every processor reduce(totalPatchSize, sumOp<label>()); - if (totalPatchSize > 0) + if + ( + totalPatchSize > 0 +// && !geometryToConformTo().surfZones().set(p) + ) { patches[nValidPatches] = polyPatch::New ( @@ -898,6 +1277,145 @@ void Foam::conformalVoronoiMesh::writeMesh } } + patches.setSize(nValidPatches); + + mesh.addFvPatches(patches); + + + // Add zones to mesh + { + Info<< " Adding zones to mesh" << endl; + + const PtrList<surfaceZonesInfo>& surfZones = + geometryToConformTo().surfZones(); + + labelList cellToSurface(calcCellZones(cellCentres)); + + labelList faceToSurface; + boolList flipMap; + + calcFaceZones + ( + mesh, + cellCentres, + cellToSurface, + faceToSurface, + flipMap + ); + + labelList insidePointNamedSurfaces + ( + surfaceZonesInfo::getInsidePointNamedSurfaces(surfZones) + ); + + findCellZoneInsideWalk + ( + mesh, + insidePointNamedSurfaces, + faceToSurface, + cellToSurface + ); + + labelList namedSurfaces(surfaceZonesInfo::getNamedSurfaces(surfZones)); + + forAll(namedSurfaces, i) + { + label surfI = namedSurfaces[i]; + + Info<< incrIndent << indent << "Surface : " + << geometryToConformTo().geometry().names()[surfI] << nl + << indent << " faceZone : " + << surfZones[surfI].faceZoneName() << nl + << indent << " cellZone : " + << surfZones[surfI].cellZoneName() + << decrIndent << endl; + } + + // Add zones to mesh + labelList surfaceToFaceZone = + surfaceZonesInfo::addFaceZonesToMesh + ( + surfZones, + namedSurfaces, + mesh + ); + + labelList surfaceToCellZone = + surfaceZonesInfo::addCellZonesToMesh + ( + surfZones, + namedSurfaces, + mesh + ); + + // Topochange container + polyTopoChange meshMod(mesh); + + forAll(cellToSurface, cellI) + { + label surfaceI = cellToSurface[cellI]; + + if (surfaceI >= 0) + { + label zoneI = surfaceToCellZone[surfaceI]; + + if (zoneI >= 0) + { + meshMod.setAction + ( + polyModifyCell + ( + cellI, + false, // removeFromZone + zoneI + ) + ); + } + } + } + + const labelList& faceOwner = mesh.faceOwner(); + const labelList& faceNeighbour = mesh.faceNeighbour(); + + forAll(faceToSurface, faceI) + { + if (!mesh.isInternalFace(faceI)) + { + continue; + } + + label surfaceI = faceToSurface[faceI]; + + if (surfaceI >= 0) + { + label own = faceOwner[faceI]; + label nei = faceNeighbour[faceI]; + + meshMod.setAction + ( + polyModifyFace + ( + mesh.faces()[faceI], // modified face + faceI, // label of face + own, // owner + nei, // neighbour + false, // face flip + -1, // patch for face + false, // remove from zone + surfaceToFaceZone[surfaceI], // zone for face + flipMap[faceI] // face flip in zone + ) + ); + } + } + + // Change the mesh (no inflation, parallel sync) + autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false, true); + } + + + + // Add indirectPatchFaces to a face zone { labelList addr(boundaryFacesToRemove.count()); @@ -928,10 +1446,6 @@ void Foam::conformalVoronoiMesh::writeMesh ); } - patches.setSize(nValidPatches); - - mesh.addFvPatches(patches); - timeCheck("Before fvMesh filtering"); autoPtr<polyMeshFilter> meshFilter; diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C index 73bd6038d9ae97740f8cbdb3cca1eda24e02bf49..351b85c952dd13a9f9875c3e6a86f3c346ea8c57 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.C @@ -265,6 +265,7 @@ Foam::conformationSurfaces::conformationSurfaces allGeometryToSurfaces_(), normalVolumeTypes_(), patchNames_(), + surfZones_(), regionOffset_(), patchInfo_(), globalBounds_(), @@ -275,157 +276,198 @@ Foam::conformationSurfaces::conformationSurfaces surfaceConformationDict.subDict("geometryToConformTo") ); - const label nSurf = surfacesDict.size(); - const dictionary& additionalFeaturesDict ( surfaceConformationDict.subDict("additionalFeatures") ); + + // Wildcard specification : loop over all surface, all regions + // and try to find a match. + + // Count number of surfaces. + label surfI = 0; + forAll(allGeometry.names(), geomI) + { + const word& geomName = allGeometry_.names()[geomI]; + + if (surfacesDict.found(geomName)) + { + surfI++; + } + } + const label nAddFeat = additionalFeaturesDict.size(); Info<< nl << "Reading geometryToConformTo" << endl; - surfaces_.setSize(nSurf, -1); - allGeometryToSurfaces_.setSize(allGeometry_.size(), -1); - normalVolumeTypes_.setSize(nSurf); + normalVolumeTypes_.setSize(surfI); + surfaces_.setSize(surfI); + surfZones_.setSize(surfI); // Features may be attached to host surfaces or independent - features_.setSize(nSurf + nAddFeat); + features_.setSize(surfI + nAddFeat); label featureI = 0; - regionOffset_.setSize(nSurf, 0); + regionOffset_.setSize(surfI, 0); - PtrList<dictionary> globalPatchInfo(nSurf); - List<Map<autoPtr<dictionary> > > regionPatchInfo(nSurf); - List<sideVolumeType> globalVolumeTypes(nSurf); - List<Map<sideVolumeType> > regionVolumeTypes(nSurf); + PtrList<dictionary> globalPatchInfo(surfI); + List<Map<autoPtr<dictionary> > > regionPatchInfo(surfI); + List<sideVolumeType> globalVolumeTypes(surfI); + List<Map<sideVolumeType> > regionVolumeTypes(surfI); - label surfI = 0; + HashSet<word> unmatchedKeys(surfacesDict.toc()); - forAllConstIter(dictionary, surfacesDict, iter) + surfI = 0; + forAll(allGeometry_.names(), geomI) { - word surfaceName = iter().keyword(); + const word& geomName = allGeometry_.names()[geomI]; - surfaces_[surfI] = allGeometry_.findSurfaceID(surfaceName); + const entry* ePtr = surfacesDict.lookupEntryPtr(geomName, false, true); - if (surfaces_[surfI] < 0) + if (ePtr) { - FatalErrorIn("Foam::conformationSurfaces::conformationSurfaces") - << "No surface " << surfaceName << " found. " - << "Valid geometry is " << nl << allGeometry_.names() - << exit(FatalError); - } + const dictionary& dict = ePtr->dict(); + unmatchedKeys.erase(ePtr->keyword()); - allGeometryToSurfaces_[surfaces_[surfI]] = surfI; + surfaces_[surfI] = geomI; - Info<< nl << " " << surfaceName << endl; + const searchableSurface& surface = allGeometry_[surfaces_[surfI]]; - const wordList& regionNames = - allGeometry_.regionNames()[surfaces_[surfI]]; + // Surface zones + if (dict.found("faceZone")) + { + surfZones_.set(surfI, new surfaceZonesInfo(surface, dict)); + } - patchNames_.append(regionNames); + allGeometryToSurfaces_[surfaces_[surfI]] = surfI; - const dictionary& surfaceSubDict(surfacesDict.subDict(surfaceName)); + Info<< nl << " " << geomName << endl; - globalVolumeTypes[surfI] = - ( - extendedFeatureEdgeMesh::sideVolumeTypeNames_ - [ - surfaceSubDict.lookupOrDefault<word>("meshableSide", "inside") - ] - ); + const wordList& regionNames = + allGeometry_.regionNames()[surfaces_[surfI]]; - if (!globalVolumeTypes[surfI]) - { - if (!allGeometry_[surfaces_[surfI]].hasVolumeType()) + patchNames_.append(regionNames); + + globalVolumeTypes[surfI] = + ( + extendedFeatureEdgeMesh::sideVolumeTypeNames_ + [ + dict.lookupOrDefault<word> + ( + "meshableSide", + "inside" + ) + ] + ); + + if (!globalVolumeTypes[surfI]) { - WarningIn("conformationSurfaces::conformationSurfaces(..)") - << "Non-baffle surface " - << allGeometry_[surfaces_[surfI]].name() - << " does not allow inside/outside queries." - << " This usually is an error." << endl; + if (!surface.hasVolumeType()) + { + WarningIn("conformationSurfaces::conformationSurfaces(..)") + << "Non-baffle surface " + << surface.name() + << " does not allow inside/outside queries." + << " This usually is an error." << endl; + } } - } - // Load patch info - if (surfaceSubDict.found("patchInfo")) - { - globalPatchInfo.set + // Load patch info + if (dict.found("patchInfo")) + { + globalPatchInfo.set + ( + surfI, + dict.subDict("patchInfo").clone() + ); + } + + readFeatures ( surfI, - surfaceSubDict.subDict("patchInfo").clone() + dict, + geomName, + featureI ); - } - - readFeatures - ( - surfI, - surfaceSubDict, - surfaceName, - featureI - ); - - const wordList& rNames = allGeometry_[surfaces_[surfI]].regions(); - if (surfaceSubDict.found("regions")) - { - const dictionary& regionsDict = surfaceSubDict.subDict("regions"); + const wordList& rNames = surface.regions(); - forAll(rNames, regionI) + if (dict.found("regions")) { - const word& regionName = rNames[regionI]; + const dictionary& regionsDict = dict.subDict("regions"); - if (regionsDict.found(regionName)) + forAll(rNames, regionI) { - Info<< " region " << regionName << endl; - - // Get the dictionary for region - const dictionary& regionDict = regionsDict.subDict - ( - regionName - ); + const word& regionName = rNames[regionI]; - if (regionDict.found("patchInfo")) + if (regionsDict.found(regionName)) { - regionPatchInfo[surfI].insert + Info<< " region " << regionName << endl; + + // Get the dictionary for region + const dictionary& regionDict = regionsDict.subDict + ( + regionName + ); + + if (regionDict.found("patchInfo")) + { + regionPatchInfo[surfI].insert + ( + regionI, + regionDict.subDict("patchInfo").clone() + ); + } + + regionVolumeTypes[surfI].insert ( regionI, - regionDict.subDict("patchInfo").clone() + extendedFeatureEdgeMesh::sideVolumeTypeNames_ + [ + regionDict.lookupOrDefault<word> + ( + "meshableSide", + "inside" + ) + ] ); - } - regionVolumeTypes[surfI].insert - ( - regionI, - extendedFeatureEdgeMesh::sideVolumeTypeNames_ - [ - regionDict.lookupOrDefault<word> - ( - "meshableSide", - "inside" - ) - ] - ); - - readFeatures(regionDict, regionName, featureI); + readFeatures(regionDict, regionName, featureI); + } } } + + surfI++; } + } + - surfI++; + if (unmatchedKeys.size() > 0) + { + IOWarningIn + ( + "conformationSurfaces::conformationSurfaces(..)", + surfacesDict + ) << "Not all entries in conformationSurfaces dictionary were used." + << " The following entries were not used : " + << unmatchedKeys.sortedToc() + << endl; } + // Calculate local to global region offset label nRegions = 0; forAll(surfaces_, surfI) { regionOffset_[surfI] = nRegions; - nRegions += allGeometry_[surfaces_[surfI]].regions().size(); + + const searchableSurface& surface = allGeometry_[surfaces_[surfI]]; + nRegions += surface.regions().size(); } // Rework surface specific information into information per global region @@ -434,7 +476,9 @@ Foam::conformationSurfaces::conformationSurfaces forAll(surfaces_, surfI) { - label nRegions = allGeometry_[surfaces_[surfI]].regions().size(); + const searchableSurface& surface = allGeometry_[surfaces_[surfI]]; + + label nRegions = surface.regions().size(); // Initialise to global (i.e. per surface) for (label i = 0; i < nRegions; i++) @@ -1165,13 +1209,7 @@ Foam::label Foam::conformationSurfaces::findPatch(const point& pt) const pointIndexHit surfHit; label hitSurface; - findSurfaceNearest - ( - pt, - sqr(GREAT), - surfHit, - hitSurface - ); + findSurfaceNearest(pt, sqr(GREAT), surfHit, hitSurface); return getPatchID(hitSurface, surfHit); } @@ -1229,11 +1267,7 @@ void Foam::conformationSurfaces::getNormal vectorField& normal ) const { - allGeometry_[hitSurface].getNormal - ( - surfHit, - normal - ); + allGeometry_[hitSurface].getNormal(surfHit, normal); const label patchID = regionOffset_[allGeometryToSurfaces_[hitSurface]]; diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.H index 04013add369f64934c97ec21816391b56c35681a..68c5fd28b92e93c159622fa21ca2883da222cbd0 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.H +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfaces.H @@ -40,6 +40,7 @@ SourceFiles #include "extendedFeatureEdgeMesh.H" #include "boolList.H" #include "volumeType.H" +#include "surfaceZonesInfo.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,7 +48,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class conformationSurfaces Declaration + Class conformationSurfaces Declaration \*---------------------------------------------------------------------------*/ class conformationSurfaces @@ -86,6 +87,9 @@ class conformationSurfaces // surfaces to be reproduced in the meshed geometry List<word> patchNames_; + //- List of surface zone (face and cell zone) information + PtrList<surfaceZonesInfo> surfZones_; + //- The offset between the patch indices of the individual surface and // the entry in the overall patch list labelList regionOffset_; @@ -170,6 +174,9 @@ public: //- Return the patch names inline const List<word>& patchNames() const; + //- Return the surfaceZonesInfo + inline const PtrList<surfaceZonesInfo>& surfZones() const; + //- Return the patch info inline const PtrList<dictionary>& patchInfo() const; diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfacesI.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfacesI.H index 17ae9636a22943c1ef0e4035e655dd26f6950114..e0a9296f9e5921435569973aed0ac2e57a8fa410 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfacesI.H +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformationSurfaces/conformationSurfacesI.H @@ -56,6 +56,13 @@ const Foam::List<Foam::word>& Foam::conformationSurfaces::patchNames() const } +const Foam::PtrList<Foam::surfaceZonesInfo>& +Foam::conformationSurfaces::surfZones() const +{ + return surfZones_; +} + + const Foam::PtrList<Foam::dictionary>& Foam::conformationSurfaces::patchInfo() const { diff --git a/applications/utilities/mesh/generation/foamyQuadMesh/Make/options b/applications/utilities/mesh/generation/foamyQuadMesh/Make/options index d1a5bfde5422911eb54e6feed45f9fbcd99a6862..62aec78cdb2e485624764ac37477d59dd9387207 100755 --- a/applications/utilities/mesh/generation/foamyQuadMesh/Make/options +++ b/applications/utilities/mesh/generation/foamyQuadMesh/Make/options @@ -23,6 +23,7 @@ EXE_INC = \ -I$(LIB_SRC)/sampling/lnInclude \ -I$(LIB_SRC)/triSurface/lnInclude \ -I$(LIB_SRC)/fileFormats/lnInclude \ + -I$(LIB_SRC)/mesh/autoMesh/lnInclude EXE_LIBS = \ $(CGAL_LIBS) \ diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C index 2475f2a043a12020929a420b991cc4485af9fb65..4bef61c5e4d64d3e055fba69912e42ea0ff9eb8c 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C @@ -98,19 +98,8 @@ autoPtr<refinementSurfaces> createRefinementSurfaces labelList surfaces(surfI); wordList names(surfI); - wordList faceZoneNames(surfI); - wordList cellZoneNames(surfI); - List<refinementSurfaces::areaSelectionAlgo> zoneInside - ( - surfI, - refinementSurfaces::NONE - ); - pointField zoneInsidePoints(surfI); - List<refinementSurfaces::faceZoneType> faceType - ( - surfI, - refinementSurfaces::INTERNAL - ); + PtrList<surfaceZonesInfo> surfZones(surfI); + labelList regionOffset(surfI); labelList globalMinLevel(surfI, 0); @@ -123,21 +112,24 @@ autoPtr<refinementSurfaces> createRefinementSurfaces List<Map<scalar> > regionAngle(surfI); List<Map<autoPtr<dictionary> > > regionPatchInfo(surfI); + HashSet<word> unmatchedKeys(surfacesDict.toc()); + surfI = 0; forAll(allGeometry.names(), geomI) { const word& geomName = allGeometry.names()[geomI]; + const entry* ePtr = surfacesDict.lookupEntryPtr(geomName, false, true); - // Definition of surfaces to conform to - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - if (surfacesDict.found(geomName)) + if (ePtr) { + const dictionary& shapeDict = ePtr->dict(); + unmatchedKeys.erase(ePtr->keyword()); + names[surfI] = geomName; surfaces[surfI] = geomI; - const dictionary& shapeDict = shapeControlDict.subDict(geomName); + const searchableSurface& surface = allGeometry[geomI]; // Find the index in shapeControlDict // Invert surfaceCellSize to get the refinementLevel @@ -160,107 +152,26 @@ autoPtr<refinementSurfaces> createRefinementSurfaces globalMaxLevel[surfI] = refLevel; globalLevelIncr[surfI] = gapLevelIncrement; - const dictionary& dict = surfacesDict.subDict(geomName); - - // Global zone names per surface - if (dict.readIfPresent("faceZone", faceZoneNames[surfI])) - { - // Read optional entry to determine inside of faceZone - - word method; - bool hasSide = dict.readIfPresent("cellZoneInside", method); - if (hasSide) - { - zoneInside[surfI] = - refinementSurfaces::areaSelectionAlgoNames[method]; - if (zoneInside[surfI] == refinementSurfaces::INSIDEPOINT) - { - dict.lookup("insidePoint") >> zoneInsidePoints[surfI]; - } - - } - else - { - // Check old syntax - bool inside; - if (dict.readIfPresent("zoneInside", inside)) - { - hasSide = true; - zoneInside[surfI] = - ( - inside - ? refinementSurfaces::INSIDE - : refinementSurfaces::OUTSIDE - ); - } - } - - // Read optional cellZone name - - if (dict.readIfPresent("cellZone", cellZoneNames[surfI])) - { - if - ( - ( - zoneInside[surfI] == refinementSurfaces::INSIDE - || zoneInside[surfI] == refinementSurfaces::OUTSIDE - ) - && !allGeometry[surfaces[surfI]].hasVolumeType() - ) - { - IOWarningIn - ( - "createRefinementSurfaces(..)", - dict - ) << "Illegal entry zoneInside " - << refinementSurfaces::areaSelectionAlgoNames - [ - zoneInside[surfI] - ] - << " for faceZone " - << faceZoneNames[surfI] - << " since surface " << names[surfI] - << " is not closed." << endl; - } - } - else if (hasSide) - { - IOWarningIn - ( - "createRefinementSurfaces(..)", - dict - ) << "Unused entry zoneInside for faceZone " - << faceZoneNames[surfI] - << " since no cellZone specified." - << endl; - } - - // How to handle faces on faceZone - word faceTypeMethod; - if (dict.readIfPresent("faceType", faceTypeMethod)) - { - faceType[surfI] = - refinementSurfaces::faceZoneTypeNames[faceTypeMethod]; - } - } + // Surface zones + surfZones.set(surfI, new surfaceZonesInfo(surface, shapeDict)); // Global perpendicular angle - if (dict.found("patchInfo")) + if (shapeDict.found("patchInfo")) { globalPatchInfo.set ( surfI, - dict.subDict("patchInfo").clone() + shapeDict.subDict("patchInfo").clone() ); } // Per region override of patchInfo - if (dict.found("regions")) + if (shapeDict.found("regions")) { - const dictionary& regionsDict = dict.subDict("regions"); + const dictionary& regionsDict = shapeDict.subDict("regions"); const wordList& regionNames = allGeometry[surfaces[surfI]].regions(); @@ -333,6 +244,7 @@ autoPtr<refinementSurfaces> createRefinementSurfaces } } } + surfI++; } } @@ -403,11 +315,7 @@ autoPtr<refinementSurfaces> createRefinementSurfaces allGeometry, surfaces, names, - faceZoneNames, - cellZoneNames, - zoneInside, - zoneInsidePoints, - faceType, + surfZones, regionOffset, minLevel, maxLevel, @@ -1188,7 +1096,7 @@ int main(int argc, char *argv[]) Info<< surfaces.names()[surfI] << ':' << nl << nl; - if (surfaces.faceZoneNames()[surfI].empty()) + if (surfaces.surfZones()[surfI].faceZoneName().empty()) { // 'Normal' surface forAll(regNames, i) diff --git a/src/mesh/autoMesh/Make/files b/src/mesh/autoMesh/Make/files index 66cb3c620253287e9529774580e8e6dba566f328..d5bfe6f751fd427461185d9d9e7229c3b6c13ae0 100644 --- a/src/mesh/autoMesh/Make/files +++ b/src/mesh/autoMesh/Make/files @@ -18,6 +18,7 @@ $(autoHexMesh)/meshRefinement/meshRefinementMerge.C $(autoHexMesh)/meshRefinement/meshRefinementProblemCells.C $(autoHexMesh)/meshRefinement/meshRefinementRefine.C $(autoHexMesh)/refinementFeatures/refinementFeatures.C +$(autoHexMesh)/refinementSurfaces/surfaceZonesInfo.C $(autoHexMesh)/refinementSurfaces/refinementSurfaces.C $(autoHexMesh)/shellSurfaces/shellSurfaces.C $(autoHexMesh)/trackedParticle/trackedParticle.C diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C index f4cce333e456e3c8bffebc6bc1c1cfcffb40c668..a53b6f11eb3bf7b9adf66ec8f04d1c93e7272588 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C @@ -927,7 +927,10 @@ void Foam::autoRefineDriver::zonify // into that surface's faceZone. All cells inside faceZone get given the // same cellZone. - if (meshRefiner_.surfaces().getNamedSurfaces().size()) + const labelList namedSurfaces = + surfaceZonesInfo::getNamedSurfaces(meshRefiner_.surfaces().surfZones()); + + if (namedSurfaces.size()) { Info<< nl << "Introducing zones for interfaces" << nl diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C index 53e63e9e44deff6e5f1cd6b69a3d507a7c0e6c3f..e2b2989889df4f4daed1214543aee56c61729f68 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriver.C @@ -590,7 +590,8 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::autoSnapDriver::mergeZoneBaffles const List<labelPair>& baffles ) { - labelList zonedSurfaces = meshRefiner_.surfaces().getNamedSurfaces(); + labelList zonedSurfaces = + surfaceZonesInfo::getNamedSurfaces(meshRefiner_.surfaces().surfZones()); autoPtr<mapPolyMesh> map; @@ -815,9 +816,15 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface // Divide surfaces into zoned and unzoned labelList zonedSurfaces = - meshRefiner.surfaces().getNamedSurfaces(); + surfaceZonesInfo::getNamedSurfaces + ( + meshRefiner.surfaces().surfZones() + ); labelList unzonedSurfaces = - meshRefiner.surfaces().getUnnamedSurfaces(); + surfaceZonesInfo::getUnnamedSurfaces + ( + meshRefiner.surfaces().surfZones() + ); // 1. All points to non-interface surfaces @@ -854,7 +861,7 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Surfaces with zone information - const wordList& faceZoneNames = surfaces.faceZoneNames(); + const PtrList<surfaceZonesInfo>& surfZones = surfaces.surfZones(); // Current best snap distance scalarField minSnapDist(snapDist); @@ -863,6 +870,8 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface { label zoneSurfI = zonedSurfaces[i]; + const word& faceZoneName = surfZones[zoneSurfI].faceZoneName(); + const labelList surfacesToTest(1, zoneSurfI); // Get indices of points both on faceZone and on pp. @@ -872,7 +881,7 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface ( mesh, pp, - faceZoneNames[zoneSurfI] + faceZoneName ) ); @@ -1369,8 +1378,10 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::autoSnapDriver::repatchToSurface indirectPrimitivePatch& pp = ppPtr(); // Divide surfaces into zoned and unzoned - labelList zonedSurfaces = surfaces.getNamedSurfaces(); - labelList unzonedSurfaces = surfaces.getUnnamedSurfaces(); + labelList zonedSurfaces = + surfaceZonesInfo::getNamedSurfaces(surfaces.surfZones()); + labelList unzonedSurfaces = + surfaceZonesInfo::getUnnamedSurfaces(surfaces.surfZones()); // Faces that do not move @@ -1386,13 +1397,13 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::autoSnapDriver::repatchToSurface } // 2. All faces on zoned surfaces - const wordList& faceZoneNames = surfaces.faceZoneNames(); + const PtrList<surfaceZonesInfo>& surfZones = surfaces.surfZones(); const faceZoneMesh& fZones = mesh.faceZones(); forAll(zonedSurfaces, i) { const label zoneSurfI = zonedSurfaces[i]; - const faceZone& fZone = fZones[faceZoneNames[zoneSurfI]]; + const faceZone& fZone = fZones[surfZones[zoneSurfI].faceZoneName()]; forAll(fZone, i) { @@ -1557,9 +1568,7 @@ void Foam::autoSnapDriver::doSnap { const faceZoneMesh& fZones = mesh.faceZones(); const refinementSurfaces& surfaces = meshRefiner_.surfaces(); - const wordList& faceZoneNames = surfaces.faceZoneNames(); - const List<refinementSurfaces::faceZoneType>& faceType = - surfaces.faceType(); + const PtrList<surfaceZonesInfo>& surfZones = surfaces.surfZones(); // Determine which // - faces to remove from list of baffles (so not merge) @@ -1568,18 +1577,23 @@ void Foam::autoSnapDriver::doSnap label nFilterFaces = 0; PackedBoolList duplicatePoint(mesh.nPoints()); label nDuplicatePoints = 0; - forAll(faceZoneNames, surfI) + forAll(surfZones, surfI) { + const word& faceZoneName = surfZones[surfI].faceZoneName(); + + const surfaceZonesInfo::faceZoneType& faceType = + surfZones[surfI].faceType(); + if ( - faceType[surfI] == refinementSurfaces::BAFFLE - || faceType[surfI] == refinementSurfaces::BOUNDARY + faceType == surfaceZonesInfo::BAFFLE + || faceType == surfaceZonesInfo::BOUNDARY ) { - if (faceZoneNames[surfI].size()) + if (faceZoneName.size()) { // Filter out all faces for this zone. - label zoneI = fZones.findZoneID(faceZoneNames[surfI]); + label zoneI = fZones.findZoneID(faceZoneName); const faceZone& fZone = fZones[zoneI]; forAll(fZone, i) { @@ -1588,7 +1602,7 @@ void Foam::autoSnapDriver::doSnap nFilterFaces++; } - if (faceType[surfI] == refinementSurfaces::BOUNDARY) + if (faceType == surfaceZonesInfo::BOUNDARY) { forAll(fZone, i) { diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C index 37e61cbbb7a75c438d96dae300cf898ef250dcae..ad2ad93a917f4206b9d6ad2aca695bd9b35b4ed7 100644 --- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C +++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoSnapDriverFeature.C @@ -337,8 +337,10 @@ void Foam::autoSnapDriver::calcNearestFace faceSurfaceGlobalRegion = -1; // Divide surfaces into zoned and unzoned - labelList zonedSurfaces = surfaces.getNamedSurfaces(); - labelList unzonedSurfaces = surfaces.getUnnamedSurfaces(); + const labelList zonedSurfaces = + surfaceZonesInfo::getNamedSurfaces(surfaces.surfZones()); + const labelList unzonedSurfaces = + surfaceZonesInfo::getUnnamedSurfaces(surfaces.surfZones()); // Per pp face the current surface snapped to labelList snapSurf(pp.size(), -1); @@ -349,20 +351,22 @@ void Foam::autoSnapDriver::calcNearestFace // Zoned faces only attract to corresponding surface // Extract faces per zone - const wordList& faceZoneNames = surfaces.faceZoneNames(); + const PtrList<surfaceZonesInfo>& surfZones = surfaces.surfZones(); forAll(zonedSurfaces, i) { label zoneSurfI = zonedSurfaces[i]; + const word& faceZoneName = surfZones[zoneSurfI].faceZoneName(); + // Get indices of faces on pp that are also in zone - label zoneI = mesh.faceZones().findZoneID(faceZoneNames[zoneSurfI]); + label zoneI = mesh.faceZones().findZoneID(faceZoneName); if (zoneI == -1) { FatalErrorIn ( "autoSnapDriver::calcNearestFace(..)" - ) << "Problem. Cannot find zone " << faceZoneNames[zoneSurfI] + ) << "Problem. Cannot find zone " << faceZoneName << exit(FatalError); } const faceZone& fZone = mesh.faceZones()[zoneI]; diff --git a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.C b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.C index 123fd22281e6f18987aca1cdbd8e03c0d5d02d45..86e129a3e92cd3ed90426216517f7a4b198a7472 100644 --- a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.C +++ b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.C @@ -1235,19 +1235,22 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::meshRefinement::balance // keep owner&neighbour of such a surface zone on the same // processor. - const wordList& fzNames = surfaces().faceZoneNames(); + const PtrList<surfaceZonesInfo>& surfZones = + surfaces().surfZones(); const faceZoneMesh& fZones = mesh_.faceZones(); const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); // Get faces whose owner and neighbour should stay together, // i.e. they are not 'blocked'. - forAll(fzNames, surfI) + forAll(surfZones, surfI) { - if (fzNames[surfI].size()) + const word& fzName = surfZones[surfI].faceZoneName(); + + if (fzName.size()) { // Get zone - const faceZone& fZone = fZones[fzNames[surfI]]; + const faceZone& fZone = fZones[fzName]; forAll(fZone, i) { diff --git a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C index 5dc6cb1c22d466d83d1e2123748bd00725145944..6e5a3f187c1c23fc922d3b37dd058baebefbd170 100644 --- a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C +++ b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C @@ -287,7 +287,10 @@ void Foam::meshRefinement::getBafflePatches const pointField& cellCentres = mesh_.cellCentres(); // Surfaces that need to be baffled - const labelList surfacesToBaffle(surfaces_.getUnnamedSurfaces()); + const labelList surfacesToBaffle + ( + surfaceZonesInfo::getUnnamedSurfaces(surfaces_.surfZones()) + ); ownPatch.setSize(mesh_.nFaces()); ownPatch = -1; @@ -416,15 +419,17 @@ Foam::Map<Foam::labelPair> Foam::meshRefinement::getZoneBafflePatches { Map<labelPair> bafflePatch(mesh_.nFaces()/1000); - const wordList& faceZoneNames = surfaces_.faceZoneNames(); + const PtrList<surfaceZonesInfo>& surfZones = surfaces_.surfZones(); const faceZoneMesh& fZones = mesh_.faceZones(); - forAll(faceZoneNames, surfI) + forAll(surfZones, surfI) { - if (faceZoneNames[surfI].size()) + const word& faceZoneName = surfZones[surfI].faceZoneName(); + + if (faceZoneName.size()) { // Get zone - label zoneI = fZones.findZoneID(faceZoneNames[surfI]); + label zoneI = fZones.findZoneID(faceZoneName); const faceZone& fZone = fZones[zoneI]; @@ -703,7 +708,10 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::createZoneBaffles List<labelPair>& baffles ) { - labelList zonedSurfaces = surfaces_.getNamedSurfaces(); + const labelList zonedSurfaces + ( + surfaceZonesInfo::getNamedSurfaces(surfaces_.surfZones()) + ); autoPtr<mapPolyMesh> map; @@ -1434,11 +1442,14 @@ void Foam::meshRefinement::findCellZoneInsideWalk // Force calculation of face decomposition (used in findCell) (void)mesh_.tetBasePtIs(); + const PtrList<surfaceZonesInfo>& surfZones = surfaces_.surfZones(); + // For all locationSurface find the cell forAll(locationSurfaces, i) { label surfI = locationSurfaces[i]; - const point& insidePoint = surfaces_.zoneInsidePoints()[surfI]; + + const point& insidePoint = surfZones[surfI].zoneInsidePoint(); Info<< "For surface " << surfaces_.names()[surfI] << " finding inside point " << insidePoint @@ -2503,143 +2514,36 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::zonify const bool allowFreeStandingZoneFaces ) { - const wordList& cellZoneNames = surfaces_.cellZoneNames(); - const wordList& faceZoneNames = surfaces_.faceZoneNames(); + const PtrList<surfaceZonesInfo>& surfZones = surfaces_.surfZones(); - labelList namedSurfaces(surfaces_.getNamedSurfaces()); + labelList namedSurfaces(surfaceZonesInfo::getNamedSurfaces(surfZones)); forAll(namedSurfaces, i) { label surfI = namedSurfaces[i]; Info<< "Surface : " << surfaces_.names()[surfI] << nl - << " faceZone : " << faceZoneNames[surfI] << nl - << " cellZone : " << cellZoneNames[surfI] << endl; + << " faceZone : " << surfZones[surfI].faceZoneName() << nl + << " cellZone : " << surfZones[surfI].cellZoneName() << endl; } // Add zones to mesh + labelList surfaceToFaceZone = + surfaceZonesInfo::addFaceZonesToMesh + ( + surfZones, + namedSurfaces, + mesh_ + ); - labelList surfaceToFaceZone(faceZoneNames.size(), -1); - { - faceZoneMesh& faceZones = mesh_.faceZones(); - - forAll(namedSurfaces, i) - { - label surfI = namedSurfaces[i]; - - label zoneI = faceZones.findZoneID(faceZoneNames[surfI]); - - if (zoneI == -1) - { - zoneI = faceZones.size(); - faceZones.setSize(zoneI+1); - faceZones.set - ( - zoneI, - new faceZone - ( - faceZoneNames[surfI], //name - labelList(0), //addressing - boolList(0), //flipmap - zoneI, //index - faceZones //faceZoneMesh - ) - ); - } - - if (debug) - { - Pout<< "Faces on " << surfaces_.names()[surfI] - << " will go into faceZone " << zoneI << endl; - } - surfaceToFaceZone[surfI] = zoneI; - } - - // Check they are synced - List<wordList> allFaceZones(Pstream::nProcs()); - allFaceZones[Pstream::myProcNo()] = faceZones.names(); - Pstream::gatherList(allFaceZones); - Pstream::scatterList(allFaceZones); - - for (label procI = 1; procI < allFaceZones.size(); procI++) - { - if (allFaceZones[procI] != allFaceZones[0]) - { - FatalErrorIn - ( - "meshRefinement::zonify" - "(const label, const point&)" - ) << "Zones not synchronised among processors." << nl - << " Processor0 has faceZones:" << allFaceZones[0] - << " , processor" << procI - << " has faceZones:" << allFaceZones[procI] - << exit(FatalError); - } - } - } - - labelList surfaceToCellZone(cellZoneNames.size(), -1); - { - cellZoneMesh& cellZones = mesh_.cellZones(); - - forAll(namedSurfaces, i) - { - label surfI = namedSurfaces[i]; - - if (cellZoneNames[surfI] != word::null) - { - label zoneI = cellZones.findZoneID(cellZoneNames[surfI]); - - if (zoneI == -1) - { - zoneI = cellZones.size(); - cellZones.setSize(zoneI+1); - cellZones.set - ( - zoneI, - new cellZone - ( - cellZoneNames[surfI], //name - labelList(0), //addressing - zoneI, //index - cellZones //cellZoneMesh - ) - ); - } - - if (debug) - { - Pout<< "Cells inside " << surfaces_.names()[surfI] - << " will go into cellZone " << zoneI << endl; - } - surfaceToCellZone[surfI] = zoneI; - } - } - - // Check they are synced - List<wordList> allCellZones(Pstream::nProcs()); - allCellZones[Pstream::myProcNo()] = cellZones.names(); - Pstream::gatherList(allCellZones); - Pstream::scatterList(allCellZones); - - for (label procI = 1; procI < allCellZones.size(); procI++) - { - if (allCellZones[procI] != allCellZones[0]) - { - FatalErrorIn - ( - "meshRefinement::zonify" - "(const label, const point&)" - ) << "Zones not synchronised among processors." << nl - << " Processor0 has cellZones:" << allCellZones[0] - << " , processor" << procI - << " has cellZones:" << allCellZones[procI] - << exit(FatalError); - } - } - } - + labelList surfaceToCellZone = + surfaceZonesInfo::addCellZonesToMesh + ( + surfZones, + namedSurfaces, + mesh_ + ); const pointField& cellCentres = mesh_.cellCentres(); @@ -2663,7 +2567,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::zonify { // Statistics: number of faces per faceZone - labelList nSurfFaces(faceZoneNames.size(), 0); + labelList nSurfFaces(surfZones.size(), 0); // Note: for all internal faces? internal + coupled? // Since zonify is run after baffling the surfaceIndex_ on baffles is @@ -2767,7 +2671,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::zonify } - // surfaceIndex migh have different surfaces on both sides if + // surfaceIndex might have different surfaces on both sides if // there happen to be a (obviously thin) surface with different // regions between the cell centres. If one is on a named surface // and the other is not this might give problems so sync. @@ -2806,7 +2710,15 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::zonify // ~~~~~~~~~~~~~~~~~~~~~~~~ // Closed surfaces with cellZone specified. - labelList closedNamedSurfaces(surfaces_.getClosedNamedSurfaces()); + labelList closedNamedSurfaces + ( + surfaceZonesInfo::getClosedNamedSurfaces + ( + surfZones, + surfaces_.geometry(), + surfaces_.surfaces() + ) + ); if (closedNamedSurfaces.size()) { @@ -2830,7 +2742,11 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::zonify // Set using provided locations // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - labelList locationSurfaces(surfaces_.getInsidePointNamedSurfaces()); + labelList locationSurfaces + ( + surfaceZonesInfo::getInsidePointNamedSurfaces(surfZones) + ); + if (locationSurfaces.size()) { Info<< "Found " << locationSurfaces.size() diff --git a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementProblemCells.C b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementProblemCells.C index 9f881a52f33ddbfaee0d9df8ef4cbd5dfb2e6e2c..8d7e38512bdbe5eb48712fcd6b65814d5e0fbfa3 100644 --- a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementProblemCells.C +++ b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementProblemCells.C @@ -568,7 +568,7 @@ Foam::labelList Foam::meshRefinement::markFacesOnProblemCells labelList hitSurface; surfaces_.findNearest ( - surfaces_.getUnnamedSurfaces(), + surfaceZonesInfo::getUnnamedSurfaces(surfaces_.surfZones()), localPoints, scalarField(localPoints.size(), sqr(GREAT)), // sqr of attraction hitSurface, diff --git a/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C b/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C index b61fa74be33b236a68703b24bf4a1ca0984976f7..bee6ada5a82a09939712052a3a318ea9fcc05f20 100644 --- a/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C +++ b/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C @@ -33,45 +33,6 @@ License #include "UPtrList.H" #include "volumeType.H" -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ - template<> - const char* Foam::NamedEnum - < - Foam::refinementSurfaces::areaSelectionAlgo, - 4 - >::names[] = - { - "inside", - "outside", - "insidePoint", - "none" - }; -} -const Foam::NamedEnum<Foam::refinementSurfaces::areaSelectionAlgo, 4> - Foam::refinementSurfaces::areaSelectionAlgoNames; - - -namespace Foam -{ - template<> - const char* Foam::NamedEnum - < - Foam::refinementSurfaces::faceZoneType, - 3 - >::names[] = - { - "internal", - "baffle", - "boundary" - }; -} -const Foam::NamedEnum<Foam::refinementSurfaces::faceZoneType, 3> - Foam::refinementSurfaces::faceZoneTypeNames; - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::refinementSurfaces::refinementSurfaces @@ -84,19 +45,15 @@ Foam::refinementSurfaces::refinementSurfaces allGeometry_(allGeometry), surfaces_(surfacesDict.size()), names_(surfacesDict.size()), - faceZoneNames_(surfacesDict.size()), - cellZoneNames_(surfacesDict.size()), - zoneInside_(surfacesDict.size(), NONE), - zoneInsidePoints_(surfacesDict.size()), - faceType_(surfacesDict.size(), INTERNAL), + surfZones_(surfacesDict.size()), regionOffset_(surfacesDict.size()) { - // Wilcard specification : loop over all surface, all regions + // Wildcard specification : loop over all surface, all regions // and try to find a match. // Count number of surfaces. label surfI = 0; - forAll(allGeometry.names(), geomI) + forAll(allGeometry_.names(), geomI) { const word& geomName = allGeometry_.names()[geomI]; @@ -109,10 +66,7 @@ Foam::refinementSurfaces::refinementSurfaces // Size lists surfaces_.setSize(surfI); names_.setSize(surfI); - faceZoneNames_.setSize(surfI); - cellZoneNames_.setSize(surfI); - zoneInside_.setSize(surfI, NONE); - faceType_.setSize(surfI, INTERNAL), + surfZones_.setSize(surfI); regionOffset_.setSize(surfI); labelList globalMinLevel(surfI, 0); @@ -130,7 +84,7 @@ Foam::refinementSurfaces::refinementSurfaces HashSet<word> unmatchedKeys(surfacesDict.toc()); surfI = 0; - forAll(allGeometry.names(), geomI) + forAll(allGeometry_.names(), geomI) { const word& geomName = allGeometry_.names()[geomI]; @@ -173,80 +127,10 @@ Foam::refinementSurfaces::refinementSurfaces << exit(FatalIOError); } + const searchableSurface& surface = allGeometry_[surfaces_[surfI]]; - // Global zone names per surface - if (dict.readIfPresent("faceZone", faceZoneNames_[surfI])) - { - // Read optional entry to determine inside of faceZone - - word method; - bool hasSide = dict.readIfPresent("cellZoneInside", method); - if (hasSide) - { - zoneInside_[surfI] = areaSelectionAlgoNames[method]; - if (zoneInside_[surfI] == INSIDEPOINT) - { - dict.lookup("insidePoint") >> zoneInsidePoints_[surfI]; - } - - } - else - { - // Check old syntax - bool inside; - if (dict.readIfPresent("zoneInside", inside)) - { - hasSide = true; - zoneInside_[surfI] = (inside ? INSIDE : OUTSIDE); - } - } - - // Read optional cellZone name - - if (dict.readIfPresent("cellZone", cellZoneNames_[surfI])) - { - if - ( - ( - zoneInside_[surfI] == INSIDE - || zoneInside_[surfI] == OUTSIDE - ) - && !allGeometry_[surfaces_[surfI]].hasVolumeType() - ) - { - IOWarningIn - ( - "refinementSurfaces::refinementSurfaces(..)", - dict - ) << "Illegal entry zoneInside " - << areaSelectionAlgoNames[zoneInside_[surfI]] - << " for faceZone " - << faceZoneNames_[surfI] - << " since surface " << names_[surfI] - << " is not closed." << endl; - } - } - else if (hasSide) - { - IOWarningIn - ( - "refinementSurfaces::refinementSurfaces(..)", - dict - ) << "Unused entry zoneInside for faceZone " - << faceZoneNames_[surfI] - << " since no cellZone specified." - << endl; - } - - // How to handle faces on faceZone - word faceTypeMethod; - if (dict.readIfPresent("faceType", faceTypeMethod)) - { - faceType_[surfI] = faceZoneTypeNames[faceTypeMethod]; - } - } - - + // Surface zones + surfZones_.set(surfI, new surfaceZonesInfo(surface, dict)); // Global perpendicular angle if (dict.found("patchInfo")) @@ -262,8 +146,7 @@ Foam::refinementSurfaces::refinementSurfaces if (dict.found("regions")) { const dictionary& regionsDict = dict.subDict("regions"); - const wordList& regionNames = - allGeometry_[surfaces_[surfI]].regions(); + const wordList& regionNames = surface.regions(); forAll(regionNames, regionI) { @@ -307,8 +190,6 @@ Foam::refinementSurfaces::refinementSurfaces << exit(FatalIOError); } - - if (regionDict.found("perpendicularAngle")) { regionAngle[surfI].insert @@ -429,11 +310,7 @@ Foam::refinementSurfaces::refinementSurfaces const searchableSurfaces& allGeometry, const labelList& surfaces, const wordList& names, - const wordList& faceZoneNames, - const wordList& cellZoneNames, - const List<areaSelectionAlgo>& zoneInside, - const pointField& zoneInsidePoints, - const List<faceZoneType>& faceType, + const PtrList<surfaceZonesInfo>& surfZones, const labelList& regionOffset, const labelList& minLevel, const labelList& maxLevel, @@ -445,11 +322,7 @@ Foam::refinementSurfaces::refinementSurfaces allGeometry_(allGeometry), surfaces_(surfaces), names_(names), - faceZoneNames_(faceZoneNames), - cellZoneNames_(cellZoneNames), - zoneInside_(zoneInside), - zoneInsidePoints_(zoneInsidePoints), - faceType_(faceType), + surfZones_(surfZones), regionOffset_(regionOffset), minLevel_(minLevel), maxLevel_(maxLevel), @@ -469,90 +342,6 @@ Foam::refinementSurfaces::refinementSurfaces // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -// Get indices of unnamed surfaces (surfaces without faceZoneName) -Foam::labelList Foam::refinementSurfaces::getUnnamedSurfaces() const -{ - labelList anonymousSurfaces(faceZoneNames_.size()); - - label i = 0; - forAll(faceZoneNames_, surfI) - { - if (faceZoneNames_[surfI].empty()) - { - anonymousSurfaces[i++] = surfI; - } - } - anonymousSurfaces.setSize(i); - - return anonymousSurfaces; -} - - -// Get indices of named surfaces (surfaces with faceZoneName) -Foam::labelList Foam::refinementSurfaces::getNamedSurfaces() const -{ - labelList namedSurfaces(faceZoneNames_.size()); - - label namedI = 0; - forAll(faceZoneNames_, surfI) - { - if (faceZoneNames_[surfI].size()) - { - namedSurfaces[namedI++] = surfI; - } - } - namedSurfaces.setSize(namedI); - - return namedSurfaces; -} - - -// Get indices of closed named surfaces -Foam::labelList Foam::refinementSurfaces::getClosedNamedSurfaces() const -{ - labelList closed(cellZoneNames_.size()); - - label closedI = 0; - forAll(cellZoneNames_, surfI) - { - if - ( - cellZoneNames_[surfI].size() - && ( - zoneInside_[surfI] == INSIDE - || zoneInside_[surfI] == OUTSIDE - ) - && allGeometry_[surfaces_[surfI]].hasVolumeType() - ) - { - closed[closedI++] = surfI; - } - } - closed.setSize(closedI); - - return closed; -} - - -// Get indices of named surfaces with a -Foam::labelList Foam::refinementSurfaces::getInsidePointNamedSurfaces() const -{ - labelList closed(cellZoneNames_.size()); - - label closedI = 0; - forAll(cellZoneNames_, surfI) - { - if (cellZoneNames_[surfI].size() && zoneInside_[surfI] == INSIDEPOINT) - { - closed[closedI++] = surfI; - } - } - closed.setSize(closedI); - - return closed; -} - - // // Count number of triangles per surface region // Foam::labelList Foam::refinementSurfaces::countRegions(const triSurface& s) // { @@ -843,7 +632,9 @@ void Foam::refinementSurfaces::findAllHigherIntersections forAll(surfaces_, surfI) { - allGeometry_[surfaces_[surfI]].findLineAll(start, end, hitInfo); + const searchableSurface& surface = allGeometry_[surfaces_[surfI]]; + + surface.findLineAll(start, end, hitInfo); // Repack hits for surface into flat list // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -873,8 +664,8 @@ void Foam::refinementSurfaces::findAllHigherIntersections labelList surfRegion(n); vectorField surfNormal(n); - allGeometry_[surfaces_[surfI]].getRegion(surfInfo, surfRegion); - allGeometry_[surfaces_[surfI]].getNormal(surfInfo, surfNormal); + surface.getRegion(surfInfo, surfRegion); + surface.getNormal(surfInfo, surfNormal); surfInfo.clear(); @@ -929,9 +720,11 @@ void Foam::refinementSurfaces::findAllHigherIntersections labelList pRegions; vectorField pNormals; - forAll(surfaces_, surfI) + forAll(surfaces(), surfI) { - allGeometry_[surfaces_[surfI]].findLineAll(start, end, hitInfo); + const searchableSurface& surface = allGeometry_[surfaces_[surfI]]; + + surface.findLineAll(start, end, hitInfo); // Repack hits for surface into flat list // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -961,8 +754,8 @@ void Foam::refinementSurfaces::findAllHigherIntersections labelList surfRegion(n); vectorField surfNormal(n); - allGeometry_[surfaces_[surfI]].getRegion(surfInfo, surfRegion); - allGeometry_[surfaces_[surfI]].getNormal(surfInfo, surfNormal); + surface.getRegion(surfInfo, surfRegion); + surface.getNormal(surfInfo, surfNormal); // Extract back into pointwise // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1023,14 +816,16 @@ void Foam::refinementSurfaces::findNearestIntersection { label surfI = surfacesToTest[testI]; + const searchableSurface& surface = allGeometry_[surfaces_[surfI]]; + // See if any intersection between start and current nearest - allGeometry_[surfaces_[surfI]].findLine + surface.findLine ( start, nearest, nearestInfo ); - allGeometry_[surfaces_[surfI]].getRegion + surface.getRegion ( nearestInfo, region @@ -1076,14 +871,16 @@ void Foam::refinementSurfaces::findNearestIntersection { label surfI = surfacesToTest[testI]; + const searchableSurface& surface = allGeometry_[surfaces_[surfI]]; + // See if any intersection between end and current nearest - allGeometry_[surfaces_[surfI]].findLine + surface.findLine ( end, nearest, nearestInfo ); - allGeometry_[surfaces_[surfI]].getRegion + surface.getRegion ( nearestInfo, region @@ -1489,20 +1286,29 @@ void Foam::refinementSurfaces::findInside { label surfI = testSurfaces[i]; - if (zoneInside_[surfI] != INSIDE && zoneInside_[surfI] != OUTSIDE) + const searchableSurface& surface = allGeometry_[surfaces_[surfI]]; + + const surfaceZonesInfo::areaSelectionAlgo selectionMethod = + surfZones_[surfI].zoneInside(); + + if + ( + selectionMethod != surfaceZonesInfo::INSIDE + && selectionMethod != surfaceZonesInfo::OUTSIDE + ) { FatalErrorIn("refinementSurfaces::findInside(..)") << "Trying to use surface " - << allGeometry_[surfaces_[surfI]].name() + << surface.name() << " which has non-geometric inside selection method " - << areaSelectionAlgoNames[zoneInside_[surfI]] + << surfaceZonesInfo::areaSelectionAlgoNames[selectionMethod] << exit(FatalError); } - if (allGeometry_[surfaces_[surfI]].hasVolumeType()) + if (surface.hasVolumeType()) { List<volumeType> volType; - allGeometry_[surfaces_[surfI]].getVolumeType(pt, volType); + surface.getVolumeType(pt, volType); forAll(volType, pointI) { @@ -1512,11 +1318,11 @@ void Foam::refinementSurfaces::findInside ( ( volType[pointI] == volumeType::INSIDE - && zoneInside_[surfI] == INSIDE + && selectionMethod == surfaceZonesInfo::INSIDE ) || ( volType[pointI] == volumeType::OUTSIDE - && zoneInside_[surfI] == OUTSIDE + && selectionMethod == surfaceZonesInfo::OUTSIDE ) ) { diff --git a/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.H b/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.H index e705e3a7d877f2f8fb948924e8febf636effba57..7f777daf334a51f4755e6cc8b94d4f8a38623b42 100644 --- a/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.H +++ b/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.H @@ -41,6 +41,7 @@ SourceFiles #include "triSurfaceFields.H" #include "vectorList.H" #include "pointIndexHit.H" +#include "surfaceZonesInfo.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -59,31 +60,6 @@ typedef List<point> pointList; class refinementSurfaces { -public: - - //- Types of selection of area - enum areaSelectionAlgo - { - INSIDE, - OUTSIDE, - INSIDEPOINT, - NONE - }; - - static const NamedEnum<areaSelectionAlgo, 4> areaSelectionAlgoNames; - - //- What to do with faceZone faces - enum faceZoneType - { - INTERNAL, - BAFFLE, - BOUNDARY - }; - - static const NamedEnum<faceZoneType, 3> faceZoneTypeNames; - -private: - // Private data //- Reference to all geometry. @@ -95,23 +71,8 @@ private: //- Surface name (word) wordList names_; - //- Per 'interface' surface : name of faceZone to put faces into - wordList faceZoneNames_; - - //- Per 'interface' surface : name of cellZone to put cells into - wordList cellZoneNames_; - - //- Per 'interface' surface : (only used if surface is closed) - // How to select zone cells : surface inside or outside or given - // inside location. - List<areaSelectionAlgo> zoneInside_; - - //- If zoneInside=location gives the corresponding inside point - pointField zoneInsidePoints_; - - //- Per 'interface' surface : - // What to do with outside - List<faceZoneType> faceType_; + //- List of surface zone (face and cell zone) information + PtrList<surfaceZonesInfo> surfZones_; //- From local region number to global region number labelList regionOffset_; @@ -159,11 +120,7 @@ public: const searchableSurfaces& allGeometry, const labelList& surfaces, const wordList& names, - const wordList& faceZoneNames, - const wordList& cellZoneNames, - const List<areaSelectionAlgo>& zoneInside, - const pointField& zoneInsidePoints, - const List<faceZoneType>& faceType, + const PtrList<surfaceZonesInfo>& surfZones, const labelList& regionOffset, const labelList& minLevel, const labelList& maxLevel, @@ -193,44 +150,9 @@ public: return names_; } - //- Per 'interface' surface : empty or name of faceZone to put - // faces into - const wordList& faceZoneNames() const - { - return faceZoneNames_; - } - - //- Per 'interface' surface : empty or name of cellZone to put - // cells into - const wordList& cellZoneNames() const - { - return cellZoneNames_; - } - - //- Get indices of unnamed surfaces (surfaces without faceZoneName) - labelList getUnnamedSurfaces() const; - - //- Get indices of named surfaces (surfaces with faceZoneName) - labelList getNamedSurfaces() const; - - //- Get indices of surfaces with a cellZone that are closed and - // have 'inside' or 'outside' selection. - labelList getClosedNamedSurfaces() const; - - //- Get indices of surfaces with a cellZone that have 'insidePoint' - // section. - labelList getInsidePointNamedSurfaces() const; - - //- Get specified inside locations for surfaces with a cellZone - const pointField& zoneInsidePoints() const - { - return zoneInsidePoints_; - } - - //- How to handle face of surfaces with a faceZone - const List<faceZoneType>& faceType() const + const PtrList<surfaceZonesInfo>& surfZones() const { - return faceType_; + return surfZones_; } //- From local region number to global region number diff --git a/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/surfaceZonesInfo.C b/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/surfaceZonesInfo.C new file mode 100644 index 0000000000000000000000000000000000000000..5d2b1c2cfcceb84fc560bc238c6496562ebe5350 --- /dev/null +++ b/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/surfaceZonesInfo.C @@ -0,0 +1,456 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "surfaceZonesInfo.H" +#include "searchableSurface.H" +#include "searchableSurfaces.H" +#include "polyMesh.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + template<> + const char* Foam::NamedEnum + < + Foam::surfaceZonesInfo::areaSelectionAlgo, + 4 + >::names[] = + { + "inside", + "outside", + "insidePoint", + "none" + }; +} +const Foam::NamedEnum<Foam::surfaceZonesInfo::areaSelectionAlgo, 4> + Foam::surfaceZonesInfo::areaSelectionAlgoNames; + + +namespace Foam +{ + template<> + const char* Foam::NamedEnum + < + Foam::surfaceZonesInfo::faceZoneType, + 3 + >::names[] = + { + "internal", + "baffle", + "boundary" + }; +} +const Foam::NamedEnum<Foam::surfaceZonesInfo::faceZoneType, 3> + Foam::surfaceZonesInfo::faceZoneTypeNames; + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::surfaceZonesInfo::surfaceZonesInfo +( + const searchableSurface& surface, + const dictionary& surfacesDict +) +: + faceZoneName_(), + cellZoneName_(), + zoneInside_(NONE), + zoneInsidePoint_(point::min), + faceType_(INTERNAL) +{ + // Global zone names per surface + if (surfacesDict.readIfPresent("faceZone", faceZoneName_)) + { + // Read optional entry to determine inside of faceZone + + word method; + bool hasSide = surfacesDict.readIfPresent("cellZoneInside", method); + if (hasSide) + { + zoneInside_ = areaSelectionAlgoNames[method]; + if (zoneInside_ == INSIDEPOINT) + { + surfacesDict.lookup("insidePoint") >> zoneInsidePoint_; + } + + } + else + { + // Check old syntax + bool inside; + if (surfacesDict.readIfPresent("zoneInside", inside)) + { + hasSide = true; + zoneInside_ = (inside ? INSIDE : OUTSIDE); + } + } + + // Read optional cellZone name + + if (surfacesDict.readIfPresent("cellZone", cellZoneName_)) + { + if + ( + ( + zoneInside_ == INSIDE + || zoneInside_ == OUTSIDE + ) + && !surface.hasVolumeType() + ) + { + IOWarningIn + ( + "surfaceZonesInfo::surfaceZonesInfo(..)", + surfacesDict + ) << "Illegal entry zoneInside " + << areaSelectionAlgoNames[zoneInside_] + << " for faceZone " + << faceZoneName_ + << " since surface is not closed." << endl; + } + } + else if (hasSide) + { + IOWarningIn + ( + "surfaceZonesInfo::surfaceZonesInfo(..)", + surfacesDict + ) << "Unused entry zoneInside for faceZone " + << faceZoneName_ + << " since no cellZone specified." + << endl; + } + + // How to handle faces on faceZone + word faceTypeMethod; + if (surfacesDict.readIfPresent("faceType", faceTypeMethod)) + { + faceType_ = faceZoneTypeNames[faceTypeMethod]; + } + } +} + + +Foam::surfaceZonesInfo::surfaceZonesInfo +( + const word& faceZoneName, + const word& cellZoneName, + const areaSelectionAlgo& zoneInside, + const point& zoneInsidePoint, + const faceZoneType& faceType +) +: + faceZoneName_(faceZoneName), + cellZoneName_(cellZoneName), + zoneInside_(zoneInside), + zoneInsidePoint_(zoneInsidePoint), + faceType_(faceType) +{} + + +Foam::surfaceZonesInfo::surfaceZonesInfo(const surfaceZonesInfo& surfZone) +: + faceZoneName_(surfZone.faceZoneName()), + cellZoneName_(surfZone.cellZoneName()), + zoneInside_(surfZone.zoneInside()), + zoneInsidePoint_(surfZone.zoneInsidePoint()), + faceType_(surfZone.faceType()) +{} + + +// Get indices of unnamed surfaces (surfaces without faceZoneName) +Foam::labelList Foam::surfaceZonesInfo::getUnnamedSurfaces +( + const PtrList<surfaceZonesInfo>& surfList +) +{ + labelList anonymousSurfaces(surfList.size()); + + label i = 0; + forAll(surfList, surfI) + { + if (surfList[surfI].faceZoneName().empty()) + { + anonymousSurfaces[i++] = surfI; + } + } + anonymousSurfaces.setSize(i); + + return anonymousSurfaces; +} + + +// Get indices of named surfaces (surfaces with faceZoneName) +Foam::labelList Foam::surfaceZonesInfo::getNamedSurfaces +( + const PtrList<surfaceZonesInfo>& surfList +) +{ + labelList namedSurfaces(surfList.size()); + + label namedI = 0; + forAll(surfList, surfI) + { + if + ( + surfList.set(surfI) + && surfList[surfI].faceZoneName().size() + ) + { + namedSurfaces[namedI++] = surfI; + } + } + namedSurfaces.setSize(namedI); + + return namedSurfaces; +} + + +// Get indices of closed named surfaces +Foam::labelList Foam::surfaceZonesInfo::getClosedNamedSurfaces +( + const PtrList<surfaceZonesInfo>& surfList, + const searchableSurfaces& allGeometry, + const labelList& surfaces +) +{ + labelList closed(surfList.size()); + + label closedI = 0; + forAll(surfList, surfI) + { + if + ( + surfList.set(surfI) + && surfList[surfI].cellZoneName().size() + && ( + surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDE + || surfList[surfI].zoneInside() == surfaceZonesInfo::OUTSIDE + ) + && allGeometry[surfaces[surfI]].hasVolumeType() + ) + { + closed[closedI++] = surfI; + } + } + closed.setSize(closedI); + + return closed; +} + + +// Get indices of closed named surfaces +Foam::labelList Foam::surfaceZonesInfo::getAllClosedNamedSurfaces +( + const PtrList<surfaceZonesInfo>& surfList, + const searchableSurfaces& allGeometry, + const labelList& surfaces +) +{ + labelList closed(surfList.size()); + + label closedI = 0; + forAll(surfList, surfI) + { + if + ( + surfList.set(surfI) + && surfList[surfI].cellZoneName().size() + && allGeometry[surfaces[surfI]].hasVolumeType() + ) + { + closed[closedI++] = surfI; + } + } + closed.setSize(closedI); + + return closed; +} + + +// Get indices of named surfaces with a +Foam::labelList Foam::surfaceZonesInfo::getInsidePointNamedSurfaces +( + const PtrList<surfaceZonesInfo>& surfList +) +{ + labelList closed(surfList.size()); + + label closedI = 0; + forAll(surfList, surfI) + { + if + ( + surfList.set(surfI) + && surfList[surfI].cellZoneName().size() + && surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDEPOINT + ) + { + closed[closedI++] = surfI; + } + } + closed.setSize(closedI); + + return closed; +} + + +Foam::labelList Foam::surfaceZonesInfo::addCellZonesToMesh +( + const PtrList<surfaceZonesInfo>& surfList, + const labelList& namedSurfaces, + polyMesh& mesh +) +{ + labelList surfaceToCellZone(surfList.size(), -1); + + cellZoneMesh& cellZones = mesh.cellZones(); + + forAll(namedSurfaces, i) + { + label surfI = namedSurfaces[i]; + + const word& cellZoneName = surfList[surfI].cellZoneName(); + + if (cellZoneName != word::null) + { + label zoneI = cellZones.findZoneID(cellZoneName); + + if (zoneI == -1) + { + zoneI = cellZones.size(); + cellZones.setSize(zoneI+1); + cellZones.set + ( + zoneI, + new cellZone + ( + cellZoneName, //name + labelList(0), //addressing + zoneI, //index + cellZones //cellZoneMesh + ) + ); + } + + surfaceToCellZone[surfI] = zoneI; + } + } + + // Check they are synced + List<wordList> allCellZones(Pstream::nProcs()); + allCellZones[Pstream::myProcNo()] = cellZones.names(); + Pstream::gatherList(allCellZones); + Pstream::scatterList(allCellZones); + + for (label procI = 1; procI < allCellZones.size(); procI++) + { + if (allCellZones[procI] != allCellZones[0]) + { + FatalErrorIn + ( + "meshRefinement::zonify" + "(const label, const point&)" + ) << "Zones not synchronised among processors." << nl + << " Processor0 has cellZones:" << allCellZones[0] + << " , processor" << procI + << " has cellZones:" << allCellZones[procI] + << exit(FatalError); + } + } + + return surfaceToCellZone; +} + + +Foam::labelList Foam::surfaceZonesInfo::addFaceZonesToMesh +( + const PtrList<surfaceZonesInfo>& surfList, + const labelList& namedSurfaces, + polyMesh& mesh +) +{ + labelList surfaceToFaceZone(surfList.size(), -1); + + faceZoneMesh& faceZones = mesh.faceZones(); + + forAll(namedSurfaces, i) + { + label surfI = namedSurfaces[i]; + + const word& faceZoneName = surfList[surfI].faceZoneName(); + + label zoneI = faceZones.findZoneID(faceZoneName); + + if (zoneI == -1) + { + zoneI = faceZones.size(); + faceZones.setSize(zoneI+1); + faceZones.set + ( + zoneI, + new faceZone + ( + faceZoneName, //name + labelList(0), //addressing + boolList(0), //flipmap + zoneI, //index + faceZones //faceZoneMesh + ) + ); + } + + surfaceToFaceZone[surfI] = zoneI; + } + + // Check they are synced + List<wordList> allFaceZones(Pstream::nProcs()); + allFaceZones[Pstream::myProcNo()] = faceZones.names(); + Pstream::gatherList(allFaceZones); + Pstream::scatterList(allFaceZones); + + for (label procI = 1; procI < allFaceZones.size(); procI++) + { + if (allFaceZones[procI] != allFaceZones[0]) + { + FatalErrorIn + ( + "meshRefinement::zonify" + "(const label, const point&)" + ) << "Zones not synchronised among processors." << nl + << " Processor0 has faceZones:" << allFaceZones[0] + << " , processor" << procI + << " has faceZones:" << allFaceZones[procI] + << exit(FatalError); + } + } + + return surfaceToFaceZone; +} + + +// ************************************************************************* // diff --git a/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/surfaceZonesInfo.H b/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/surfaceZonesInfo.H new file mode 100644 index 0000000000000000000000000000000000000000..39a48adcfd8c33983c21633ac439a1cbc2265cda --- /dev/null +++ b/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/surfaceZonesInfo.H @@ -0,0 +1,241 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::surfaceZonesInfo + +Description + +SourceFiles + surfaceZonesInfo.C + +\*---------------------------------------------------------------------------*/ + +#ifndef surfaceZonesInfo_H +#define surfaceZonesInfo_H + +#include "NamedEnum.H" +#include "point.H" +#include "word.H" +#include "PtrList.H" +#include "labelList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class searchableSurface; +class searchableSurfaces; +class polyMesh; +class dictionary; + +/*---------------------------------------------------------------------------*\ + Class surfaceZonesInfo Declaration +\*---------------------------------------------------------------------------*/ + +class surfaceZonesInfo +{ +public: + + //- Types of selection of area + enum areaSelectionAlgo + { + INSIDE, + OUTSIDE, + INSIDEPOINT, + NONE + }; + + static const NamedEnum<areaSelectionAlgo, 4> areaSelectionAlgoNames; + + //- What to do with faceZone faces + enum faceZoneType + { + INTERNAL, + BAFFLE, + BOUNDARY + }; + + static const NamedEnum<faceZoneType, 3> faceZoneTypeNames; + + +private: + + // Private data + + //- Per 'interface' surface : name of faceZone to put faces into + word faceZoneName_; + + //- Per 'interface' surface : name of cellZone to put cells into + word cellZoneName_; + + //- Per 'interface' surface : (only used if surface is closed) + // How to select zone cells : surface inside or outside or given + // inside location. + areaSelectionAlgo zoneInside_; + + //- If zoneInside=location gives the corresponding inside point + point zoneInsidePoint_; + + //- Per 'interface' surface : + // What to do with outside + faceZoneType faceType_; + + + // Private Member Functions + + //- Disallow default bitwise assignment + void operator=(const surfaceZonesInfo&); + + +public: + + // Constructors + + //- Construct from surfaces and dictionary + surfaceZonesInfo + ( + const searchableSurface& surface, + const dictionary& surfacesDict + ); + + //- Construct from components + surfaceZonesInfo + ( + const word& faceZoneNames, + const word& cellZoneNames, + const areaSelectionAlgo& zoneInside, + const point& zoneInsidePoints, + const faceZoneType& faceType + ); + + //- Copy constructor + surfaceZonesInfo(const surfaceZonesInfo&); + + //- Return clone + autoPtr<surfaceZonesInfo> clone() const + { + return autoPtr<surfaceZonesInfo>(new surfaceZonesInfo(*this)); + } + + + // Member Functions + + // Access + + //- Per 'interface' surface : empty or name of faceZone to put + // faces into + const word& faceZoneName() const + { + return faceZoneName_; + } + + //- Per 'interface' surface : empty or name of cellZone to put + // cells into + const word& cellZoneName() const + { + return cellZoneName_; + } + + const areaSelectionAlgo& zoneInside() const + { + return zoneInside_; + } + + //- Get specified inside locations for surfaces with a cellZone + const point& zoneInsidePoint() const + { + return zoneInsidePoint_; + } + + //- How to handle face of surfaces with a faceZone + const faceZoneType& faceType() const + { + return faceType_; + } + + + // Query + + //- Get indices of unnamed surfaces (surfaces without faceZoneName) + static labelList getUnnamedSurfaces + ( + const PtrList<surfaceZonesInfo>& surfList + ); + + //- Get indices of named surfaces (surfaces with faceZoneName) + static labelList getNamedSurfaces + ( + const PtrList<surfaceZonesInfo>& surfList + ); + + //- Get indices of surfaces with a cellZone that are closed and + // have 'inside' or 'outside' selection. + static labelList getClosedNamedSurfaces + ( + const PtrList<surfaceZonesInfo>& surfList, + const searchableSurfaces& allGeometry, + const labelList& surfaces + ); + + //- Get indices of surfaces with a cellZone that are closed. + static labelList getAllClosedNamedSurfaces + ( + const PtrList<surfaceZonesInfo>& surfList, + const searchableSurfaces& allGeometry, + const labelList& surfaces + ); + + //- Get indices of surfaces with a cellZone that have 'insidePoint' + // section. + static labelList getInsidePointNamedSurfaces + ( + const PtrList<surfaceZonesInfo>& surfList + ); + + static labelList addCellZonesToMesh + ( + const PtrList<surfaceZonesInfo>& surfList, + const labelList& namedSurfaces, + polyMesh& mesh + ); + + static labelList addFaceZonesToMesh + ( + const PtrList<surfaceZonesInfo>& surfList, + const labelList& namedSurfaces, + polyMesh& mesh + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //