From 1b26f41bd5ad161dee1e6594e93a20ad5f9cf2ea Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 28 Jul 2011 13:48:12 +0100 Subject: [PATCH] ENH: conformalMeshCalcDualMesh: protect merging processor points --- .../backgroundMeshDecomposition.C | 13 ++-- .../conformalVoronoiMesh.C | 10 +++ .../conformalVoronoiMesh.H | 15 +++- .../conformalVoronoiMeshCalcDualMesh.C | 68 +++++++++++++++++-- .../conformalVoronoiMeshI.H | 17 +++++ .../conformalVoronoiMesh/indexedCell.H | 1 - 6 files changed, 108 insertions(+), 16 deletions(-) diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C index 3065963202..7f3e6ac9ef 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C @@ -1294,11 +1294,12 @@ Foam::labelList Foam::backgroundMeshDecomposition::processorPosition "Foam::labelList" "Foam::backgroundMeshDecomposition::processorPosition" "(" - "const List& pts" + "const List&" ") const" ) << "The position " << pts[pI] - << " is not in any part of the background mesh. " + << " is not in any part of the background mesh " + << globalBackgroundBounds_ << endl << "A background mesh with a wider margin around " << "the geometry may help." << exit(FatalError); @@ -1311,11 +1312,11 @@ Foam::labelList Foam::backgroundMeshDecomposition::processorPosition "Foam::labelList" "Foam::backgroundMeshDecomposition::processorPosition" "(" - "const List& pts" + "const List&" ") const" - ) - << "The position " << pts[pI] - << " was not found in the background mesh, finding nearest." + ) << "The position " << pts[pI] + << " was not found in the background mesh " + << globalBackgroundBounds_ << ", finding nearest." << endl; } diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C index 4b074e05fc..732a7c2251 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C @@ -30,6 +30,16 @@ License #include "backgroundMeshDecomposition.H" #include "meshSearch.H" +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + +defineTypeNameAndDebug(conformalVoronoiMesh, 0); + +} + + // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // Foam::tensor Foam::conformalVoronoiMesh::requiredAlignment diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H index 60adea3456..65ec474a77 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H @@ -722,6 +722,13 @@ private: const Delaunay::Finite_facets_iterator& fit ) const; + //- Determines if the edge constructed from the face is on + // a processor patch + inline bool isParallelDualEdge + ( + const Delaunay::Finite_facets_iterator& fit + ) const; + //- Merge vertices that are very close together void mergeCloseDualVertices ( @@ -771,7 +778,7 @@ private: ) const; //- Collapse a face to an edge, updating the point and point - // map. Returns the collapse mode that was applied. + // map. Returns the collapse mode that was applied. faceCollapseMode collapseFace ( const face& f, @@ -783,7 +790,7 @@ private: label maxFC ) const; - // Identify the index of the longest edge on the face + //- Identify the index of the longest edge on the face label longestEdge(const face& f, const pointField& pts) const; //- Identify the face labels of the deferred collapse faces @@ -886,6 +893,10 @@ private: public: + //- Runtime type information + ClassName("conformalVoronoiMesh"); + + // Constructors //- Construct from Time and cvMeshDict diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C index 5a5cbfe44d..2f3a2717d7 100644 --- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C +++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C @@ -543,8 +543,21 @@ Foam::label Foam::conformalVoronoiMesh::mergeCloseDualVertices { label nPtsMerged = 0; + label nIdentical = 0; + label nProcEdge = 0; + + // Relative distance for points to be merged scalar closenessTolerance = cvMeshControls().mergeClosenessCoeff(); + // Absolute distance for points to be considered coincident. Bit adhoc + // but points were seen with distSqr ~ 1E-30 which is SMALL^2. Add a few + // digits to account for truncation errors. + scalar coincidentDistanceSqr = sqr + ( + SMALL*1E2*geometryToConformTo_.globalBounds().mag() + ); + + for ( Delaunay::Finite_facets_iterator fit = finite_facets_begin(); @@ -567,14 +580,14 @@ Foam::label Foam::conformalVoronoiMesh::mergeCloseDualVertices continue; } - if (!c1->farCell() && !c2->farCell() && (c1I != c2I)) + if ((c1I != c2I) && !c1->farCell() && !c2->farCell()) { - if - ( - magSqr(pts[c1I] - pts[c2I]) - < sqr(averageAnyCellSize(fit)*closenessTolerance) - ) + scalar distSqr = magSqr(pts[c1I] - pts[c2I]); + + if (pts[c1I] == pts[c2I] || distSqr < coincidentDistanceSqr) { + nIdentical++; + if (boundaryPts[c2I] == true) { // If c2I is a boundary point, then it is kept. @@ -583,18 +596,59 @@ Foam::label Foam::conformalVoronoiMesh::mergeCloseDualVertices dualPtIndexMap.insert(c1I, c2I); dualPtIndexMap.insert(c2I, c2I); + nPtsMerged++; } else { dualPtIndexMap.insert(c1I, c1I); dualPtIndexMap.insert(c2I, c1I); + nPtsMerged++; } - nPtsMerged++; + } + else if (distSqr < sqr(averageAnyCellSize(fit)*closenessTolerance)) + { + if (c1->parallelDualVertex() || c2->parallelDualVertex()) + //if (isParallelDualEdge(fit)) + { + // Skip if face uses any edge that becomes a processor + // dual face. + // Note: the real test should be whether the Delaunay edge + // will form a processor patch. + nProcEdge++; + } + else if (boundaryPts[c2I] == true) + { + // If c2I is a boundary point, then it is kept. + // If both are boundary points then c2I is chosen + // arbitrarily to be kept. + + dualPtIndexMap.insert(c1I, c2I); + dualPtIndexMap.insert(c2I, c2I); + nPtsMerged++; + } + else + { + dualPtIndexMap.insert(c1I, c1I); + dualPtIndexMap.insert(c2I, c1I); + nPtsMerged++; + } } } } + if (debug) + { + Info<< "mergeCloseDualVertices:" + << " coincident distance:" << coincidentDistanceSqr + << " closenessTolerance:" << closenessTolerance << endl + << " identical points : " + << returnReduce(nIdentical, sumOp