From 7bb68b4dea6e9fdc6edaebaef86a89d99fdd8790 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 7 Aug 2018 22:23:16 +0200 Subject: [PATCH] ENH: new cuttingPlane cutting scheme - takes a direct approach of determining which cells are cut and walks the cell faces directly to build the resulting surface. - better handling of corner cases. * Avoids redundant points when the cut passes exactly through a mesh point. * Supresses generation of duplicates faces when the plane cut coincides exactly with a mesh face. - for severely concave cells where the plane cuts a face multiple times there is currently no remedial action taken, except to note the failure and unwind the insertion of the corresponding points and faces. --- .../surface/cuttingPlane/cuttingPlane.C | 538 +++++++++++------- .../surface/cuttingPlane/cuttingPlane.H | 27 +- .../squareBend/system/samplingDebug | 31 + 3 files changed, 370 insertions(+), 226 deletions(-) diff --git a/src/sampling/surface/cuttingPlane/cuttingPlane.C b/src/sampling/surface/cuttingPlane/cuttingPlane.C index cd8f314482..9838cd7323 100644 --- a/src/sampling/surface/cuttingPlane/cuttingPlane.C +++ b/src/sampling/surface/cuttingPlane/cuttingPlane.C @@ -28,6 +28,8 @@ License #include "volFields.H" #include "linePointRef.H" #include "meshTools.H" +#include "EdgeMap.H" +#include "HashOps.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -39,9 +41,19 @@ int Foam::cuttingPlane::debug(Foam::debug::debugSwitch("cuttingPlane", 0)); namespace Foam { // Check edge/plane intersection based on crossings ... trivial check. - inline bool intersectsEdge(const PackedList<2>& sides, const edge& e) + // Orients the edge (first,last) points in the positive normal direction + inline bool intersectEdgeOrient(const PackedList<2>& sides, edge& e) { - return (sides[e.first()] != sides[e.last()]); + if (sides[e.first()] == sides[e.last()]) + { + return false; + } + else if (sides[e.last()] < sides[e.first()]) + { + e.flip(); + } + + return true; } @@ -67,6 +79,31 @@ namespace Foam return (accum == 3 || accum >= 5); } + + //- Hash specialization for labelList. Hash incrementally. + template<> + inline unsigned Hash::operator() + ( + const labelList& list, + unsigned seed + ) const + { + return Hasher(list.cdata(), list.size()*sizeof(label), seed); + } + + //- Hash specialization for labelList + template<> + inline unsigned Hash::operator() + ( + const labelList& list + ) const + { + return Hash()(list, 0); + } + + //- For hashing face point labels, which are pre-sorted. + typedef HashSet> labelListHashSet; + } // End namespace Foam @@ -213,224 +250,326 @@ Foam::label Foam::cuttingPlane::calcCellCuts } -void Foam::cuttingPlane::intersectEdges +void Foam::cuttingPlane::walkCellCuts ( const primitiveMesh& mesh, const PackedList<2>& sides, const bitSet& cellCuts, - List