diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H index a514c660a1d96350897478ca826dba7efe5af1d8..81ce496c7173d96a4ef4f021d9d4a80d440603db 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -911,6 +911,17 @@ private: const HashSet<labelPair, labelPair::Hash<> >& deferredCollapseFaces ) const; + //- Check whether the cell sizes are fine enough. Creates a polyMesh. + void checkCellSizing(); + + //- Find all cells with a patch face that is not near the surface. The + // allowed offset is the fraction of the target cell size. + labelHashSet findOffsetPatchFaces + ( + const polyMesh& mesh, + const scalar allowedOffset + ) const; + //- Create a polyMesh and check its quality, reports which // elements damage the mesh quality, allowing backtracking. labelHashSet checkPolyMeshQuality(const pointField& pts) const; @@ -1005,6 +1016,9 @@ private: const labelList& procNeighbours ) const; + //- Create a polyMesh from points. + autoPtr<polyMesh> createPolyMeshFromPoints(const pointField& pts) const; + //- Rotate the faces on processor patches if necessary void reorderProcessorPatches ( @@ -1193,7 +1207,7 @@ public: //- Find the cellSet of the boundary cells which have points that // protrude out of the surface beyond a tolerance. - void findRemainingProtrusionSet(const fvMesh& mesh) const; + labelHashSet findRemainingProtrusionSet(const polyMesh& mesh) const; void writeProcessorInterface ( diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C index d103d3c0fcb1ff968452105319a3c304e5a65578..5586446cb8a17934c284d07a017d50ff32565908 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,6 +26,7 @@ License #include "conformalVoronoiMesh.H" #include "motionSmoother.H" #include "backgroundMeshDecomposition.H" +#include "polyMeshGeometry.H" // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // @@ -1552,7 +1553,8 @@ void Foam::conformalVoronoiMesh::deferredCollapseFaceSet } -Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality +Foam::autoPtr<Foam::polyMesh> +Foam::conformalVoronoiMesh::createPolyMeshFromPoints ( const pointField& pts ) const @@ -1592,62 +1594,67 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality labelList cellToDelaunayVertex(removeUnusedCells(owner, neighbour)); cellCentres = pointField(cellCentres, cellToDelaunayVertex); - polyMesh pMesh + autoPtr<polyMesh> meshPtr ( - IOobject + new polyMesh ( - "cvMesh_temporary", - runTime_.timeName(), - runTime_, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - xferCopy(pts), - xferMove(faces), - xferMove(owner), - xferMove(neighbour) + IOobject + ( + "cvMesh_temporary", + runTime_.timeName(), + runTime_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + xferCopy(pts), + xferMove(faces), + xferMove(owner), + xferMove(neighbour) + ) ); + polyMesh& pMesh = meshPtr(); + List<polyPatch*> patches(patchStarts.size()); label nValidPatches = 0; forAll(patches, p) { - if (patchTypes[p] == processorPolyPatch::typeName) - { - // Do not create empty processor patches - - if (patchSizes[p] > 0) - { - patches[nValidPatches] = new processorPolyPatch - ( - patchNames[p], - patchSizes[p], - patchStarts[p], - nValidPatches, - pMesh.boundaryMesh(), - Pstream::myProcNo(), - procNeighbours[p] - ); - - nValidPatches++; - } - } - else - { - patches[nValidPatches] = polyPatch::New - ( - patchTypes[p], - patchNames[p], - patchSizes[p], - patchStarts[p], - nValidPatches, - pMesh.boundaryMesh() - ).ptr(); - - nValidPatches++; - } + if (patchTypes[p] == processorPolyPatch::typeName) + { + // Do not create empty processor patches + + if (patchSizes[p] > 0) + { + patches[nValidPatches] = new processorPolyPatch + ( + patchNames[p], + patchSizes[p], + patchStarts[p], + nValidPatches, + pMesh.boundaryMesh(), + Pstream::myProcNo(), + procNeighbours[p] + ); + + nValidPatches++; + } + } + else + { + patches[nValidPatches] = polyPatch::New + ( + patchTypes[p], + patchNames[p], + patchSizes[p], + patchStarts[p], + nValidPatches, + pMesh.boundaryMesh() + ).ptr(); + + nValidPatches++; + } } patches.setSize(nValidPatches); @@ -1672,6 +1679,199 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality // pMesh.overrideCellCentres(cellCentres); + return meshPtr; +} + + +void Foam::conformalVoronoiMesh::checkCellSizing() +{ + Info<< "Checking cell sizes..."<< endl; + + timeCheck("Start of Cell Sizing"); + + PackedBoolList boundaryPts(number_of_cells(), false); + pointField ptsField; + + indexDualVertices(ptsField, boundaryPts); + + // Merge close dual vertices. + mergeCloseDualVertices(ptsField, boundaryPts); + + autoPtr<polyMesh> meshPtr = createPolyMeshFromPoints(ptsField); + const polyMesh& pMesh = meshPtr(); + + //pMesh.write(); + + // Find cells with poor quality + DynamicList<label> checkFaces(identity(pMesh.nFaces())); + labelHashSet wrongFaces(pMesh.nFaces()/100); + + Info<< "Running checkMesh on mesh with " << pMesh.nCells() + << " cells "<< endl; + + const dictionary& dict + = cvMeshControls().cvMeshDict().subDict("meshQualityControls"); + + const scalar maxNonOrtho = readScalar(dict.lookup("maxNonOrtho", true)); + + label nWrongFaces = 0; + + if (maxNonOrtho < 180.0 - SMALL) + { + polyMeshGeometry::checkFaceDotProduct + ( + false, + maxNonOrtho, + pMesh, + pMesh.cellCentres(), + pMesh.faceAreas(), + checkFaces, + List<labelPair>(), + &wrongFaces + ); + + label nNonOrthogonal = returnReduce(wrongFaces.size(), sumOp<label>()); + + Info<< " non-orthogonality > " << maxNonOrtho + << " degrees : " << nNonOrthogonal << endl; + + nWrongFaces += nNonOrthogonal; + } + + labelHashSet protrudingCells = findOffsetPatchFaces(pMesh, 0.25); + + label nProtrudingCells = protrudingCells.size(); + + Info<< " protruding/intruding cells : " << nProtrudingCells << endl; + + nWrongFaces += nProtrudingCells; + +// motionSmoother::checkMesh +// ( +// false, +// pMesh, +// cvMeshControls().cvMeshDict().subDict("meshQualityControls"), +// checkFaces, +// wrongFaces +// ); + + Info<< " Found total of " << nWrongFaces << " bad faces" << endl; + + { + labelHashSet cellsToResizeMap(pMesh.nFaces()/100); + + // Find cells that are attached to the faces in wrongFaces. + forAllConstIter(labelHashSet, wrongFaces, iter) + { + const label faceOwner = pMesh.faceOwner()[iter.key()]; + const label faceNeighbour = pMesh.faceNeighbour()[iter.key()]; + + if (!cellsToResizeMap.found(faceOwner)) + { + cellsToResizeMap.insert(faceOwner); + } + + if (!cellsToResizeMap.found(faceNeighbour)) + { + cellsToResizeMap.insert(faceNeighbour); + } + } + + cellsToResizeMap += protrudingCells; + + pointField cellsToResize(cellsToResizeMap.size()); + + label count = 0; + for (label cellI = 0; cellI < pMesh.nCells(); ++cellI) + { + if (cellsToResizeMap.found(cellI)) + { + cellsToResize[count++] = pMesh.cellCentres()[cellI]; + } + } + + Info<< " Automatically re-sizing " << cellsToResize.size() + << " cells that are attached to the bad faces: DISABLED" << endl; + + //cellSizeControl_.setCellSizes(cellsToResize); + } + + timeCheck("End of Cell Sizing"); + + Info<< "Finished checking cell sizes"<< endl; +} + + +Foam::labelHashSet Foam::conformalVoronoiMesh::findOffsetPatchFaces +( + const polyMesh& mesh, + const scalar allowedOffset +) const +{ + timeCheck("Start findRemainingProtrusionSet"); + + const polyBoundaryMesh& patches = mesh.boundaryMesh(); + + cellSet offsetBoundaryCells + ( + mesh, + "cvMesh_protrudingCells", + mesh.nCells()/1000 + ); + + forAll(patches, patchI) + { + const polyPatch& patch = patches[patchI]; + + const faceList& localFaces = patch.localFaces(); + const pointField& localPoints = patch.localPoints(); + + const labelList& fCell = patch.faceCells(); + + forAll(localFaces, pLFI) + { + const face& f = localFaces[pLFI]; + + const Foam::point& faceCentre = f.centre(localPoints); + + const scalar targetSize = targetCellSize(faceCentre); + + pointIndexHit pHit; + label surfHit = -1; + + geometryToConformTo_.findSurfaceNearest + ( + faceCentre, + sqr(targetSize), + pHit, + surfHit + ); + + if + ( + pHit.hit() + && (mag(pHit.hitPoint() - faceCentre) > allowedOffset*targetSize) + ) + { + offsetBoundaryCells.insert(fCell[pLFI]); + } + } + } + + offsetBoundaryCells.write(); + + return offsetBoundaryCells; +} + + +Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality +( + const pointField& pts +) const +{ + autoPtr<polyMesh> meshPtr = createPolyMeshFromPoints(pts); + polyMesh& pMesh = meshPtr(); + timeCheck("polyMesh created, checking quality"); labelHashSet wrongFaces(pMesh.nFaces()/100); @@ -2264,10 +2464,6 @@ void Foam::conformalVoronoiMesh::createFacesOwnerNeighbourAndPatches } } } - - Pout<< "Patch Names: " << patchNames << endl; - Pout<< "Patch Sizes: " << patchSizes << endl; - Pout<< "Proc Neighbours: " << procNeighbours << endl; } } diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C index 9bc2512f58eb0bf48d108b1bc4ff952795c3d93d..bee04b2fbddc8a165fc72f6f46cdee5b9db1185b 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshConformToSurface.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H index a18b173ecd3c64890c1d9e24d65da8787ff0d297..1e24b7d8ef29cf030425647cfc70fc03f50bf26a 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C index 89afb87134a98ce7b7c9c5ec37afe4764ed4f4b2..68f98e8a9d3e01cf1238bd3817f403b6109fbe84 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -1072,9 +1072,9 @@ void Foam::conformalVoronoiMesh::writeCellCentres } -void Foam::conformalVoronoiMesh::findRemainingProtrusionSet +Foam::labelHashSet Foam::conformalVoronoiMesh::findRemainingProtrusionSet ( - const fvMesh& mesh + const polyMesh& mesh ) const { timeCheck("Start findRemainingProtrusionSet"); @@ -1129,7 +1129,7 @@ void Foam::conformalVoronoiMesh::findRemainingProtrusionSet reduce(protrudingCellsSize, sumOp<label>()); - if (protrudingCellsSize > 0) + if (cvMeshControls().objOutput() && protrudingCellsSize > 0) { Info<< nl << "Found " << protrudingCellsSize << " cells protruding from the surface, writing cellSet " @@ -1138,6 +1138,8 @@ void Foam::conformalVoronoiMesh::findRemainingProtrusionSet protrudingCells.write(); } + + return protrudingCells; }