From cfed7e32807592df744b1862a6ff324c43036e53 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 May 2008 14:20:03 +0200 Subject: [PATCH] Added compare methods for edge/triFace. Added edgeDirection methods for face/triFace. Added extra constructors for converting faces to triFaces. The collapse() method now returns the new face size and can be used to check if the collapse face is valid. --- src/OpenFOAM/meshes/meshShapes/edge/edge.H | 8 +- src/OpenFOAM/meshes/meshShapes/edge/edgeI.H | 32 ++++- src/OpenFOAM/meshes/meshShapes/face/face.C | 45 ++++++- src/OpenFOAM/meshes/meshShapes/face/face.H | 8 +- .../meshes/meshShapes/triFace/triFace.H | 28 +++- .../meshes/meshShapes/triFace/triFaceI.H | 122 ++++++++++++++++-- 6 files changed, 217 insertions(+), 26 deletions(-) diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edge.H b/src/OpenFOAM/meshes/meshShapes/edge/edge.H index ccef92bf41..f8fb2696b6 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edge.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edge.H @@ -119,6 +119,12 @@ public: //- Return edge line inline linePointRef line(const pointField&) const; + //- compare edges + // - 0: different + // - +1: identical + // - -1: same edge, but different orientation + static inline int compare(const edge&, const edge&); + // Friend Operators @@ -127,7 +133,7 @@ public: }; -//- Hash specialisation +//- Hash specialisation // Simple commutative hash. template<> inline label Hash::operator()(const edge& e) const diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H index 8aa88ebe78..bd3bd339fd 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H @@ -26,6 +26,30 @@ License #include "IOstreams.H" +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + + +// return +// - 0: different +// - +1: identical +// - -1: same edge, but different orientation +inline int Foam::edge::compare(const edge& a, const edge& b) +{ + if (a[0] == b[0] && a[1] == b[1]) + { + return 1; + } + else if (a[0] == b[1] && a[1] == b[0]) + { + return -1; + } + else + { + return 0; + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline Foam::edge::edge() @@ -146,17 +170,13 @@ inline Foam::linePointRef Foam::edge::line(const pointField& p) const inline bool Foam::operator==(const edge& a, const edge& b) { - return - ( - (a[0] == b[0] && a[1] == b[1]) - || (a[0] == b[1] && a[1] == b[0]) - ); + return edge::compare(a,b) != 0; } inline bool Foam::operator!=(const edge& a, const edge& b) { - return !(a == b); + return edge::compare(a,b) == 0; } diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.C b/src/OpenFOAM/meshes/meshShapes/face/face.C index dda506d789..2d06d0db28 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.C +++ b/src/OpenFOAM/meshes/meshShapes/face/face.C @@ -438,7 +438,7 @@ int Foam::face::compare(const face& a, const face& b) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::face::collapse() +Foam::label Foam::face::collapse() { if (size() > 1) { @@ -458,6 +458,8 @@ void Foam::face::collapse() setSize(ci); } + + return size(); } @@ -696,6 +698,47 @@ Foam::edgeList Foam::face::edges() const } +int Foam::face::edgeDirection(const edge& e) const +{ + if (size() > 2) + { + edge found(-1,-1); + + // find start/end points - this breaks down for degenerate faces + forAll (*this, i) + { + if (operator[](i) == e.start()) + { + found.start() = i; + } + else if (operator[](i) == e.end()) + { + found.end() = i; + } + } + + label diff = found.end() - found.start(); + if (!diff || found.start() < 0 || found.end() < 0) + { + return 0; + } + + // forward direction + if (diff == 1 || diff == 1 - size()) + { + return 1; + } + // reverse direction + if (diff == -1 || diff == -1 + size()) + { + return -1; + } + } + + return 0; +} + + // Number of triangles directly known from number of vertices Foam::label Foam::face::nTriangles ( diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index f56919647a..9325801c41 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -145,7 +145,8 @@ public: // Member Functions //- Collapse face by removing duplicate point labels - void collapse(); + // return the collapsed size + label collapse(); //- Return the points corresponding to this face inline pointField points(const pointField& meshPoints) const; @@ -251,6 +252,11 @@ public: //- Return n-th face edge inline edge faceEdge(const label n) const; + //- Return the edge direction on the face + // - 0: edge not found on the face + // - +1: forward (counter-clockwise) on the face + // - -1: reverse (clockwise) on the face + int edgeDirection(const edge&) const; // Face splitting utilities diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H index aad4ee455f..9672b93147 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H @@ -81,18 +81,35 @@ public: const label c ); + //- Construct from a face, discarding excess points + inline triFace(const face&); + + //- Construct from a labelList, discarding excess points + explicit inline triFace(const labelList&); + //- Construct from Istream inline triFace(Istream&); // Member Functions + //- Collapse face by removing duplicate point labels + // return the collapsed size, set collapsed point labels to -1 + inline label collapse(); + + //- Return the edge direction on the face + // - +1: forward (counter-clockwise) on the face + // - -1: reverse (clockwise) on the face + // - 0: edge not found on the face + inline int edgeDirection(const edge&) const; + + // Properties //- Return the points corresponding to this face inline pointField points(const pointField& points) const; - //- Return triagle as a face + //- Return triangle as a face inline face triFaceFace() const; //- Return number of edges @@ -128,9 +145,14 @@ public: const intersection::direction dir = intersection::VECTOR ) const; - //- Return the tetrahedron + //- Return the triangle inline triPointRef tri(const pointField&) const; + //- compare triFaces + // - 0: different + // - +1: identical + // - -1: same face, but different orientation + static inline int compare(const triFace&, const triFace&); // Friend Operators @@ -139,7 +161,7 @@ public: }; -//- Hash specialisation +//- Hash specialisation // Simple commutative hash. template<> inline label Hash::operator()(const triFace& t) const diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H index c92e1e47e7..9574a06cbf 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H @@ -33,14 +33,45 @@ License namespace Foam { +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + + +inline int triFace::compare(const triFace& a, const triFace& b) +{ + if + ( + (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) + || (a[0] == b[1] && a[1] == b[2] && a[2] == b[0]) + || (a[0] == b[2] && a[1] == b[0] && a[2] == b[1]) + ) + { + // identical + return 1; + } + else if + ( + (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) + || (a[0] == b[1] && a[1] == b[0] && a[2] == b[2]) + || (a[0] == b[0] && a[1] == b[2] && a[2] == b[1]) + ) + { + // same face, but reversed orientation + return -1; + } + else + { + return 0; + } +} + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -//- Construct null +// Construct null inline triFace::triFace() {} -//- Construct from components +// Construct from components inline triFace::triFace ( const label a, @@ -53,6 +84,18 @@ inline triFace::triFace operator[](2) = c; } +// Construct from a face +inline triFace::triFace(const face& f) +: + FixedList(SubList