diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C index d9bf097d1d6d7023a378ca7d53232c0391795e03..302bd61b55360b706d8ee68df909e1cc79fcb2c2 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C @@ -282,7 +282,7 @@ Foam::tmp<Foam::triSurfacePointScalarField> Foam::automatic::load() forAll(surface_, fI) { - faces[fI] = surface_.triSurface::operator[](fI).triFaceFace(); + faces[fI] = surface_.triSurface::operator[](fI); } vtkSurfaceWriter().write diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C index 410182e01c2a68cda0484476d507ed1731a60bfb..ac840a07f74b0b5497ddf80e07c9f2ca638000fd 100644 --- a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C @@ -721,7 +721,7 @@ int main(int argc, char *argv[]) isoFaces.setSize(iso.size()); forAll(isoFaces, i) { - isoFaces[i] = iso[i].triFaceFace(); + isoFaces[i] = iso[i]; } isoPoints = iso.points(); } diff --git a/applications/utilities/surface/surfaceCheck/surfaceCheck.C b/applications/utilities/surface/surfaceCheck/surfaceCheck.C index 09765e2d938c992bef366978581a35327593a6e5..43812170e1fd72aae248bce61aa8dfcb66c669d3 100644 --- a/applications/utilities/surface/surfaceCheck/surfaceCheck.C +++ b/applications/utilities/surface/surfaceCheck/surfaceCheck.C @@ -150,7 +150,7 @@ void writeZoning faceList faces(surf.size()); forAll(surf, i) { - faces[i] = surf[i].triFaceFace(); + faces[i] = surf[i]; } vtkSurfaceWriter().write diff --git a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C index ca7cba62cc624f7425d00d43a5f925221ff54cd9..eb7103faf1eab2ab0ef3da0d9096d3829acb27af 100644 --- a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C +++ b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C @@ -368,7 +368,7 @@ int main(int argc, char *argv[]) faces.setSize(surf.size()); forAll(surf, fi) { - faces[fi] = surf[fi].triFaceFace(); + faces[fi] = surf[fi]; } } diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edge.H b/src/OpenFOAM/meshes/meshShapes/edge/edge.H index aecb9a9c2e416c1acc4b055fcf1c4ff12e162b17..dabdc197efa866c56d3c5818af7682019c346e42 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edge.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edge.H @@ -28,7 +28,7 @@ Description An edge is a list of two point labels. The functionality it provides supports the discretisation on a 2-D flat mesh. - The edge is implemented as a FixedList of labels. + The edge is implemented as a Pair/FixedList of labels. As well as geometrically relevant methods, it also provides methods similar to HashSet for additional convenience. Valid point labels are always non-negative (since they correspond to @@ -37,6 +37,7 @@ Description can be filled with a HashSet-like functionality. SourceFiles + edge.C edgeI.H \*---------------------------------------------------------------------------*/ @@ -44,10 +45,9 @@ SourceFiles #ifndef edge_H #define edge_H -#include "FixedList.H" #include "labelPair.H" -#include "pointField.H" #include "linePointRef.H" +#include "pointField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -60,7 +60,7 @@ namespace Foam class edge : - public FixedList<label, 2> + public labelPair { // Private Member Functions @@ -93,19 +93,19 @@ public: //- Construct null with invalid point labels (-1) inline edge(); - //- Construct from components + //- Construct from two point labels inline edge(const label from, const label to); - //- Construct, optionally sorted with start less-than end - inline edge(const label from, const label to, const bool doSort); - - //- Construct from two labels + //- Construct from pair of labels inline edge(const labelPair& pair); - //- Construct from FixedList + //- Construct from list inline edge(const FixedList<label, 2>& lst); - //- Construct, optionally sorted with start less-than end + //- Construct from two point labels, sorted with first less-than second + inline edge(const label from, const label to, const bool doSort); + + //- Construct from list, sorted with first less-than second inline edge(const FixedList<label, 2>& lst, const bool doSort); //- Construct from Istream @@ -116,16 +116,26 @@ public: // Access - //- Return start vertex label + //- Return first vertex label + using labelPair::first; + + //- Return last (second) vertex label + using labelPair::last; + + //- Return second (last) vertex label + using labelPair::second; + + + //- Return start (first) vertex label inline label start() const; - //- Return start vertex label + //- Return start (first) vertex label inline label& start(); - //- Return end vertex label + //- Return end (last/second) vertex label inline label end() const; - //- Return end vertex label + //- Return end (last/second) vertex label inline label& end(); //- Return reverse edge as copy. @@ -143,10 +153,6 @@ public: // No special handling of negative point labels. inline label maxVertex() const; - //- True if start() is less-than end() - // No special handling of negative point labels. - inline bool sorted() const; - //- Return true if point label is found in edge. // Always false for a negative label. inline bool found(const label pointLabel) const; @@ -175,14 +181,6 @@ public: // Return the effective size after collapsing. inline label collapse(); - //- Flip the edge in-place. - // No special handling of negative point labels. - inline void flip(); - - //- Sort so that start() is less-than end() - // No special handling of negative point labels. - inline void sort(); - // Hash-like functions @@ -211,8 +209,8 @@ public: // Returns true on success. Negative labels never insert. // Return the number of slots filled. // Similar to a HashTable::insert(). - template<unsigned AnySize> - inline label insert(const FixedList<label, AnySize>& lst); + template<unsigned Size> + inline label insert(const FixedList<label, Size>& lst); //- Fill open slots with the indices if they did not previously exist. // Returns true on success. Negative labels never insert. @@ -231,8 +229,8 @@ public: //- Remove existing indices from the edge and set locations to '-1'. // Returns the number of changes. - template<unsigned AnySize> - inline label erase(const FixedList<label, AnySize>& lst); + template<unsigned Size> + inline label erase(const FixedList<label, Size>& lst); //- Remove existing indices from the edge and set locations to '-1'. // Returns the number of changes. @@ -265,7 +263,7 @@ public: // Comparison //- Compare edges - // Returns: + // \return // - 0: different // - +1: identical values and order used // - -1: identical values, but in different order @@ -274,7 +272,14 @@ public: }; -// Global Operators +// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * // + +//- Return reverse of an edge +inline edge reverse(const edge& e) +{ + return edge(e.second(), e.first()); +} + //- Compare edges for equal content, ignoring orientation inline bool operator==(const edge& a, const edge& b); @@ -290,15 +295,15 @@ inline unsigned Hash<edge>::operator()(const edge& e, unsigned seed) const { unsigned val = seed; - if (e[0] < e[1]) + if (e.first() < e.second()) { - val = Hash<label>()(e[0], val); - val = Hash<label>()(e[1], val); + val = Hash<label>()(e.first(), val); + val = Hash<label>()(e.second(), val); } else { - val = Hash<label>()(e[1], val); - val = Hash<label>()(e[0], val); + val = Hash<label>()(e.second(), val); + val = Hash<label>()(e.first(), val); } return val; @@ -313,7 +318,7 @@ inline unsigned Hash<edge>::operator()(const edge& e) const return Hash<edge>()(e, 0); } - +// Edges are a pair of labels - thus contiguous template<> inline bool contiguous<edge>() {return true;} diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H index e4ca81e9386f6abb51f0abc14ba2035222656268..db939da2aac5c7670af599319bf2c63d453f64e6 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H @@ -24,24 +24,12 @@ License \*---------------------------------------------------------------------------*/ #include "IOstreams.H" -#include "Swap.H" // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // 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; - } + return labelPair::compare(a, b); } @@ -56,7 +44,7 @@ inline Foam::label Foam::edge::insertMultiple { // Available slots. // Don't use count() since it has special treatment for duplicates - const int maxChange = (start() < 0 ? 1 : 0) + (end() < 0 ? 1 : 0); + const int maxChange = (first() < 0 ? 1 : 0) + (second() < 0 ? 1 : 0); int changed = 0; if (maxChange) @@ -86,7 +74,7 @@ inline Foam::label Foam::edge::eraseMultiple { // Occupied slots. // Don't use count() since it has special treatment for duplicates - const int maxChange = (start() >= 0 ? 1 : 0) + (end() >= 0 ? 1 : 0); + const int maxChange = (first() >= 0 ? 1 : 0) + (second() >= 0 ? 1 : 0); int changed = 0; if (maxChange) @@ -109,64 +97,43 @@ inline Foam::label Foam::edge::eraseMultiple inline Foam::edge::edge() : - FixedList<label, 2>(-1) + labelPair(-1, -1) {} inline Foam::edge::edge(const label from, const label to) -{ - start() = from; - end() = to; -} - - -inline Foam::edge::edge(const label from, const label to, const bool doSort) -{ - if (doSort && from > to) - { - start() = to; - end() = from; - } - else - { - start() = from; - end() = to; - } -} +: + labelPair(from, to) +{} inline Foam::edge::edge(const labelPair& pair) -{ - start() = pair.first(); - end() = pair.second(); -} +: + labelPair(pair.first(), pair.second()) +{} inline Foam::edge::edge(const FixedList<label, 2>& lst) -{ - start() = lst[0]; - end() = lst[1]; -} +: + labelPair(lst.first(), lst.last()) +{} + + +inline Foam::edge::edge(const label from, const label to, const bool doSort) +: + labelPair(from, to, doSort) +{} inline Foam::edge::edge(const FixedList<label, 2>& lst, const bool doSort) -{ - if (doSort && lst[0] > lst[1]) - { - start() = lst[1]; - end() = lst[0]; - } - else - { - start() = lst[0]; - end() = lst[1]; - } -} +: + labelPair(lst, doSort) +{} inline Foam::edge::edge(Istream& is) : - FixedList<label, 2>(is) + labelPair(is) {} @@ -174,42 +141,47 @@ inline Foam::edge::edge(Istream& is) inline Foam::label Foam::edge::start() const { - return operator[](0); + return first(); } inline Foam::label& Foam::edge::start() { - return operator[](0); + return first(); } inline Foam::label Foam::edge::end() const { - return operator[](1); + return second(); } + inline Foam::label& Foam::edge::end() { - return operator[](1); + return second(); } inline Foam::label Foam::edge::minVertex() const { - return (start() < end() ? start() : end()); + return (first() < second() ? first() : second()); } inline Foam::label Foam::edge::maxVertex() const { - return (start() > end() ? start() : end()); + return (first() > second() ? first() : second()); } inline bool Foam::edge::found(const label pointLabel) const { // -1: always false - return (pointLabel >= 0 && (pointLabel == start() || pointLabel == end())); + return + ( + pointLabel >= 0 + && (pointLabel == first() || pointLabel == second()) + ); } @@ -218,11 +190,11 @@ inline Foam::label Foam::edge::which(const label pointLabel) const // -1: always false if (pointLabel >= 0) { - if (pointLabel == start()) + if (pointLabel == first()) { return 0; } - if (pointLabel == end()) + if (pointLabel == second()) { return 1; } @@ -233,43 +205,39 @@ inline Foam::label Foam::edge::which(const label pointLabel) const inline bool Foam::edge::connects(const edge& other) const { - return (other.found(start()) || other.found(end())); + return (other.found(first()) || other.found(second())); } inline Foam::label Foam::edge::commonVertex(const edge& other) const { - if (other.found(start())) - { - return start(); - } - else if (other.found(end())) + if (other.found(first())) { - return end(); + return first(); } - else + if (other.found(second())) { - // No shared vertex. - return -1; + return second(); } + + // No shared vertex. + return -1; } inline Foam::label Foam::edge::otherVertex(const label index) const { - if (index == start()) - { - return end(); - } - else if (index == end()) + if (index == first()) { - return start(); + return second(); } - else + if (index == second()) { - // The given vertex is not on the edge in the first place. - return -1; + return first(); } + + // The given vertex is not on the edge in the first place. + return -1; } @@ -280,12 +248,12 @@ inline Foam::label Foam::edge::collapse() // catch any '-1' (eg, if called multiple times) label n = 2; - if (start() == end() || end() < 0) + if (first() == second() || second() < 0) { - end() = -1; + second() = -1; --n; } - if (start() < 0) + if (first() < 0) { --n; } @@ -294,48 +262,27 @@ inline Foam::label Foam::edge::collapse() } -inline bool Foam::edge::sorted() const -{ - return (start() < end()); -} - - -inline void Foam::edge::sort() -{ - if (start() > end()) - { - flip(); - } -} - - -inline void Foam::edge::flip() -{ - Swap(operator[](0), operator[](1)); -} - - inline Foam::edge Foam::edge::reverseEdge() const { - return edge(end(), start()); + return edge(second(), first()); } inline void Foam::edge::clear() { - start() = -1; - end() = -1; + first() = -1; + second() = -1; } inline Foam::label Foam::edge::count() const { label n = 2; - if (start() == end() || end() < 0) + if (first() == second() || second() < 0) { --n; } - if (start() < 0) + if (first() < 0) { --n; } @@ -346,7 +293,7 @@ inline Foam::label Foam::edge::count() const inline bool Foam::edge::empty() const { - return (start() < 0 && end() < 0); + return (first() < 0 && second() < 0); } @@ -358,21 +305,21 @@ inline bool Foam::edge::insert(const label index) return false; } - if (start() < 0) + if (first() < 0) { - // Store at [0], if not duplicate of [1] - if (index != end()) + // Store at first, if not duplicate of second + if (index != second()) { - start() = index; + first() = index; return true; } } - else if (end() < 0) + else if (second() < 0) { - // Store at [1], if not duplicate of [0] - if (index != start()) + // Store at second, if not duplicate of first + if (index != first()) { - end() = index; + second() = index; return true; } } @@ -387,8 +334,8 @@ inline Foam::label Foam::edge::insert(const UList<label>& lst) } -template<unsigned AnySize> -inline Foam::label Foam::edge::insert(const FixedList<label, AnySize>& lst) +template<unsigned Size> +inline Foam::label Foam::edge::insert(const FixedList<label, Size>& lst) { return insertMultiple(lst.begin(), lst.end()); } @@ -409,16 +356,16 @@ inline Foam::label Foam::edge::erase(const label index) } label n = 0; - if (index == start()) + if (index == first()) { - start() = -1; + first() = -1; ++n; } // Automatically handle duplicates, which should not have been there anyhow - if (index == end()) + if (index == second()) { - end() = -1; + second() = -1; ++n; } @@ -432,8 +379,8 @@ inline Foam::label Foam::edge::erase(const UList<label>& lst) } -template<unsigned AnySize> -inline Foam::label Foam::edge::erase(const FixedList<label, AnySize>& lst) +template<unsigned Size> +inline Foam::label Foam::edge::erase(const FixedList<label, Size>& lst) { return eraseMultiple(lst.begin(), lst.end()); } @@ -450,7 +397,7 @@ inline Foam::label Foam::edge::erase(std::initializer_list<label> lst) inline Foam::point Foam::edge::centre(const UList<point>& pts) const { #ifdef FULLDEBUG - if (start() < 0 || end() < 0) + if (first() < 0 || second() < 0) { FatalErrorInFunction << "negative point index on edge " << *this @@ -458,14 +405,14 @@ inline Foam::point Foam::edge::centre(const UList<point>& pts) const } #endif - return 0.5*(pts[start()] + pts[end()]); + return 0.5*(pts[first()] + pts[second()]); } inline Foam::vector Foam::edge::vec(const UList<point>& pts) const { #ifdef FULLDEBUG - if (start() < 0 || end() < 0) + if (first() < 0 || second() < 0) { FatalErrorInFunction << "negative point index on edge " << *this @@ -473,14 +420,14 @@ inline Foam::vector Foam::edge::vec(const UList<point>& pts) const } #endif - return pts[end()] - pts[start()]; + return pts[second()] - pts[first()]; } inline Foam::vector Foam::edge::unitVec(const UList<point>& pts) const { #ifdef FULLDEBUG - if (start() < 0 || end() < 0) + if (first() < 0 || second() < 0) { FatalErrorInFunction << "negative point index on edge " << *this @@ -488,7 +435,7 @@ inline Foam::vector Foam::edge::unitVec(const UList<point>& pts) const } #endif - Foam::vector v = pts[end()] - pts[start()]; + Foam::vector v = pts[second()] - pts[first()]; v /= ::Foam::mag(v) + VSMALL; return v; @@ -504,7 +451,7 @@ inline Foam::scalar Foam::edge::mag(const UList<point>& pts) const inline Foam::linePointRef Foam::edge::line(const UList<point>& pts) const { #ifdef FULLDEBUG - if (start() < 0 || end() < 0) + if (first() < 0 || second() < 0) { FatalErrorInFunction << "negative point index on edge " << *this @@ -512,7 +459,7 @@ inline Foam::linePointRef Foam::edge::line(const UList<point>& pts) const } #endif - return linePointRef(pts[start()], pts[end()]); + return linePointRef(pts[first()], pts[second()]); } diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.C b/src/OpenFOAM/meshes/meshShapes/face/face.C index 9900b4e6f3a926dca1f453fc26c718612664a17a..6f44cb0314a258fa76ac943622f80a31e4195cf8 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.C +++ b/src/OpenFOAM/meshes/meshShapes/face/face.C @@ -773,14 +773,14 @@ int Foam::face::edgeDirection(const edge& e) const { forAll(*this, i) { - if (operator[](i) == e.start()) + if (operator[](i) == e.first()) { - if (operator[](rcIndex(i)) == e.end()) + if (operator[](rcIndex(i)) == e.second()) { // Reverse direction return -1; } - else if (operator[](fcIndex(i)) == e.end()) + else if (operator[](fcIndex(i)) == e.second()) { // Forward direction return 1; @@ -789,14 +789,14 @@ int Foam::face::edgeDirection(const edge& e) const // No match return 0; } - else if (operator[](i) == e.end()) + else if (operator[](i) == e.second()) { - if (operator[](rcIndex(i)) == e.start()) + if (operator[](rcIndex(i)) == e.first()) { // Forward direction return 1; } - else if (operator[](fcIndex(i)) == e.start()) + else if (operator[](fcIndex(i)) == e.first()) { // Reverse direction return -1; diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index 2c640ce52365844b1f9abd2d7f92aaa3852d72a6..0866a7eead9e80ce723a10b370b90b17a9885bca 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -50,6 +50,7 @@ SourceFiles #include "faceListFwd.H" #include "intersection.H" #include "pointHit.H" +#include "FixedList.H" #include "ListListOps.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -106,15 +107,15 @@ class face //- Enumeration listing the modes for split() enum splitMode { - COUNTTRIANGLE, // count if split into triangles - COUNTQUAD, // count if split into triangles&quads - SPLITTRIANGLE, // split into triangles - SPLITQUAD // split into triangles&quads + COUNTTRIANGLE, //!< count if split into triangles + COUNTQUAD, //!< count if split into triangles and quads + SPLITTRIANGLE, //!< split into triangles + SPLITQUAD //!< split into triangles and quads }; - //- Split face into triangles or triangles&quads. + //- Split face into triangles or triangles and quads. // Stores results quadFaces[quadI], triFaces[triI] - // Returns number of new faces created + // \return number of new faces created label split ( const splitMode mode, @@ -152,12 +153,19 @@ public: //- Construct from list of labels explicit inline face(const labelUList& lst); + //- Construct from list of labels + template<unsigned Size> + explicit inline face(const FixedList<label, Size>& lst); + //- Construct from an initializer list of labels explicit inline face(std::initializer_list<label> lst); - //- Construct by transferring the parameter contents + //- Transfer (move) construct explicit inline face(const Xfer<labelList>& lst); + //- Move construct + explicit inline face(labelList&& lst); + //- Copy construct from triFace face(const triFace& f); @@ -311,8 +319,8 @@ public: //- Return n-th face edge inline edge faceEdge(const label n) const; - //- Return the edge direction on the face - // Returns: + //- The edge direction on the face + // \return // - 0: edge not found on the face // - +1: forward (counter-clockwise) on the face // - -1: reverse (clockwise) on the face @@ -373,9 +381,10 @@ public: ) const; //- Compare faces - // 0: different - // +1: identical - // -1: same face, but different orientation + // \return + // - 0: different + // - +1: identical + // - -1: same face, but different orientation static int compare(const face& a, const face& b); //- Return true if the faces have the same vertices diff --git a/src/OpenFOAM/meshes/meshShapes/face/faceI.H b/src/OpenFOAM/meshes/meshShapes/face/faceI.H index 17b58b83bd275f9ac19aee319a9771ee33580fdd..0ec413433d5916517114ef130aa9cefc878a6a96 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/faceI.H +++ b/src/OpenFOAM/meshes/meshShapes/face/faceI.H @@ -57,6 +57,13 @@ inline Foam::face::face(const labelUList& lst) {} +template<unsigned Size> +inline Foam::face::face(const FixedList<label, Size>& lst) +: + labelList(lst) +{} + + inline Foam::face::face(std::initializer_list<label> lst) : labelList(lst) @@ -69,6 +76,12 @@ inline Foam::face::face(const Xfer<labelList>& lst) {} +inline Foam::face::face(labelList&& lst) +: + labelList(std::move(lst)) +{} + + inline Foam::face::face(Istream& is) { is >> *this; @@ -87,9 +100,10 @@ inline Foam::pointField Foam::face::points // For each point in list, set it to the point in 'pnts' addressed // by 'labs' - forAll(p, i) + label i = 0; + for (const label pointi : *this) { - p[i] = meshPoints[operator[](i)]; + p[i++] = meshPoints[pointi]; } // Return list diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H index 301b845d112a82499420b4de2eeddd3daf6f4477..ea18b760194a8d3708a028dd8eeaacd1c40e7e6c 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H @@ -86,7 +86,7 @@ public: const label c ); - //- Construct from a list of 3 labels. + //- Copy construct from a list of 3 labels. explicit inline triFace(const labelUList& lst); //- Construct from an initializer list of 3 labels @@ -223,14 +223,14 @@ public: inline edge faceEdge(const label n) const; //- Return the edge direction on the face - // Returns: + // \return // - +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& e) const; //- Compare triFaces - // Returns: + // \return: // - 0: different // - +1: identical // - -1: same face, but different orientation diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H index ae2545a7aa233e8542a9e4e644e1f098bd6b3c09..bc99e45518cd599c81015c72f062e54ca3b4bf56 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H @@ -147,13 +147,7 @@ inline Foam::pointField Foam::triFace::points(const UList<point>& points) const inline Foam::face Foam::triFace::triFaceFace() const { - Foam::face f(3); - - f[0] = operator[](0); - f[1] = operator[](1); - f[2] = operator[](2); - - return f; + return Foam::face(*this); } @@ -342,14 +336,14 @@ inline Foam::edgeList Foam::triFace::edges() const { edgeList e(3); - e[0].start() = operator[](0); - e[0].end() = operator[](1); + e[0].first() = operator[](0); + e[0].second() = operator[](1); - e[1].start() = operator[](1); - e[1].end() = operator[](2); + e[1].first() = operator[](1); + e[1].second() = operator[](2); - e[2].start() = operator[](2); - e[2].end() = operator[](0); + e[2].first() = operator[](2); + e[2].second() = operator[](0); return e; } @@ -369,18 +363,18 @@ inline int Foam::triFace::edgeDirection(const edge& e) const { if ( - (operator[](0) == e.start() && operator[](1) == e.end()) - || (operator[](1) == e.start() && operator[](2) == e.end()) - || (operator[](2) == e.start() && operator[](0) == e.end()) + (operator[](0) == e.first() && operator[](1) == e.second()) + || (operator[](1) == e.first() && operator[](2) == e.second()) + || (operator[](2) == e.first() && operator[](0) == e.second()) ) { return 1; } else if ( - (operator[](0) == e.end() && operator[](1) == e.start()) - || (operator[](1) == e.end() && operator[](2) == e.start()) - || (operator[](2) == e.end() && operator[](0) == e.start()) + (operator[](0) == e.second() && operator[](1) == e.first()) + || (operator[](1) == e.second() && operator[](2) == e.first()) + || (operator[](2) == e.second() && operator[](0) == e.first()) ) { return -1; diff --git a/src/OpenFOAM/meshes/primitiveShapes/line/line.H b/src/OpenFOAM/meshes/primitiveShapes/line/line.H index 778a843ba75740616ef5922d017b94747f6a839a..a3ccc2319f24d7254408f18d1ed083dcf747432a 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/line/line.H +++ b/src/OpenFOAM/meshes/primitiveShapes/line/line.H @@ -57,10 +57,10 @@ class Ostream; template<class Point, class PointRef> class line; template<class Point, class PointRef> -inline Istream& operator>>(Istream&, line<Point, PointRef>&); +inline Istream& operator>>(Istream& is, line<Point, PointRef>& l); template<class Point, class PointRef> -inline Ostream& operator<<(Ostream&, const line<Point, PointRef>&); +inline Ostream& operator<<(Ostream& os, const line<Point, PointRef>& l); /*---------------------------------------------------------------------------*\ @@ -72,7 +72,11 @@ class line { // Private data - PointRef a_, b_; + //- First point + PointRef a_; + + //- Second point + PointRef b_; public: @@ -86,7 +90,7 @@ public: // The indices could be from edge etc. inline line ( - const UList<Point>&, + const UList<Point>& points, const FixedList<label, 2>& indices ); @@ -96,56 +100,62 @@ public: // Member functions - // Access + // Access + + //- Return first point + inline PointRef first() const; - //- Return first point - inline PointRef start() const; + //- Return second point + inline PointRef second() const; - //- Return second point - inline PointRef end() const; + //- Return first point + inline PointRef start() const; + //- Return second point + inline PointRef end() const; - // Properties - //- Return centre (centroid) - inline Point centre() const; + // Properties - //- Return scalar magnitude - inline scalar mag() const; + //- Return centre (centroid) + inline Point centre() const; - //- Return start-to-end vector - inline Point vec() const; + //- Return scalar magnitude + inline scalar mag() const; - //- Return the unit vector (start-to-end) - inline Point unitVec() const; + //- Return start-to-end vector + inline Point vec() const; - //- Return nearest distance to line from a given point - // If the nearest point is on the line, return a hit - PointHit<Point> nearestDist(const Point& p) const; + //- Return the unit vector (start-to-end) + inline Point unitVec() const; - //- Return nearest distance from line to line. Returns distance - // and sets both points (one on *this, one on the provided - // linePointRef. - scalar nearestDist - ( - const line<Point, const Point&>& edge, - Point& thisPoint, - Point& edgePoint - ) const; + //- Return nearest distance to line from a given point + // If the nearest point is on the line, return a hit + PointHit<Point> nearestDist(const Point& p) const; + + //- Return nearest distance from line to line. Returns distance + // and sets both points (one on *this, one on the provided + // linePointRef. + scalar nearestDist + ( + const line<Point, const Point&>& edge, + Point& thisPoint, + Point& edgePoint + ) const; // Ostream operator friend Istream& operator>> <Point, PointRef> ( - Istream&, - line& + Istream& is, + line& l ); friend Ostream& operator<< <Point, PointRef> ( - Ostream&, - const line& + Ostream& os, + const line& l ); }; diff --git a/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H b/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H index 034f86878034c75a7e60b95cf812206f05b6ebd9..b2ee4d40ea132bfc26517b1b77617546e237aa19 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H +++ b/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H @@ -57,18 +57,32 @@ inline Foam::line<Point, PointRef>::line(Istream& is) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class Point, class PointRef> -inline PointRef Foam::line<Point, PointRef>::start() const +inline PointRef Foam::line<Point, PointRef>::first() const { return a_; } + template<class Point, class PointRef> -inline PointRef Foam::line<Point, PointRef>::end() const +inline PointRef Foam::line<Point, PointRef>::second() const { return b_; } +template<class Point, class PointRef> +inline PointRef Foam::line<Point, PointRef>::start() const +{ + return first(); +} + +template<class Point, class PointRef> +inline PointRef Foam::line<Point, PointRef>::end() const +{ + return second(); +} + + template<class Point, class PointRef> inline Point Foam::line<Point, PointRef>::centre() const { @@ -110,21 +124,21 @@ Foam::PointHit<Point> Foam::line<Point, PointRef>::nearestDist Point w(p - a_); - scalar c1 = v & w; + const scalar c1 = v & w; if (c1 <= 0) { return PointHit<Point>(false, a_, Foam::mag(p - a_), true); } - scalar c2 = v & v; + const scalar c2 = v & v; if (c2 <= c1) { return PointHit<Point>(false, b_, Foam::mag(p - b_), true); } - scalar b = c1/c2; + const scalar b = c1/c2; Point pb(a_ + b*v); diff --git a/src/OpenFOAM/primitives/Pair/Pair.H b/src/OpenFOAM/primitives/Pair/Pair.H index 73b99e5c15d9bc1063b9c77ec1941d6bfa9eae46..3209f4d9421b844872c18447af9666c6fe161272 100644 --- a/src/OpenFOAM/primitives/Pair/Pair.H +++ b/src/OpenFOAM/primitives/Pair/Pair.H @@ -28,6 +28,9 @@ Description An ordered pair of two objects of type \<T\> with first() and second() elements. +SourceFiles + PairI.H + See also Foam::Tuple2 for storing two objects of dissimilar types. @@ -48,10 +51,10 @@ namespace Foam Class Pair Declaration \*---------------------------------------------------------------------------*/ -template<class Type> +template<class T> class Pair : - public FixedList<Type, 2> + public FixedList<T, 2> { public: @@ -59,131 +62,96 @@ public: // Constructors //- Null constructor - inline Pair() - {} + inline Pair(); //- Construct from components - inline Pair(const Type& f, const Type& s) - { - first() = f; - second() = s; - } + inline Pair(const T& f, const T& s); //- Construct from FixedList - inline Pair(const FixedList<Type, 2>& lst) - : - FixedList<Type, 2>(lst) - {} + inline Pair(const FixedList<T, 2>& lst); + + //- Construct, optionally sorted with first less-than second + inline Pair(const T& f, const T& s, const bool doSort); + + //- Construct, optionally sorted with first less-than second + inline Pair(const FixedList<T, 2>& lst, const bool doSort); //- Construct from Istream - inline Pair(Istream& is) - : - FixedList<Type, 2>(is) - {} + inline Pair(Istream& is); // Member Functions - //- Return first - inline const Type& first() const - { - return this->operator[](0); - } - - //- Return first - inline Type& first() - { - return this->operator[](0); - } - - //- Return second - inline const Type& second() const - { - return this->operator[](1); - } - - //- Return second - inline Type& second() - { - return this->operator[](1); - } - - //- Return other - inline const Type& other(const Type& a) const - { - if (first() == second()) - { - FatalErrorInFunction - << "Call to other only valid for Pair with differing" - << " elements:" << *this << abort(FatalError); - } - else if (first() == a) - { - return second(); - } - else - { - if (second() != a) - { - FatalErrorInFunction - << "Pair " << *this - << " does not contain " << a << abort(FatalError); - } - return first(); - } - } + // Access + + //- Return first element + using FixedList<T, 2>::first; + + //- Return last element + using FixedList<T, 2>::last; + + //- Return second element, which is also the last element + inline const T& second() const; + + //- Return second element, which is also the last element + inline T& second(); + + //- Return other element + inline const T& other(const T& a) const; + + + // Queries + + //- True if first() is less-than second() + inline bool sorted() const; + + + // Editing + + //- Flip the Pair in-place. + inline void flip(); + + //- Sort so that first() is less-than second() + inline void sort(); // Comparison //- Compare Pairs - // Returns: + // \return // - 0: different // - +1: identical values and order used // - -1: identical values, but in reversed order - static inline int compare(const Pair<Type>& a, const Pair<Type>& 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; - } - } + static inline int compare(const Pair<T>& a, const Pair<T>& b); }; // * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * // -template<class Type> -Pair<Type> reverse(const Pair<Type>& p) +//- Return reverse of a Pair +template<class T> +Pair<T> reverse(const Pair<T>& p) { - return Pair<Type>(p.second(), p.first()); + return Pair<T>(p.second(), p.first()); } -template<class Type> -bool operator==(const Pair<Type>& a, const Pair<Type>& b) +template<class T> +bool operator==(const Pair<T>& a, const Pair<T>& b) { return (a.first() == b.first() && a.second() == b.second()); } -template<class Type> -bool operator!=(const Pair<Type>& a, const Pair<Type>& b) +template<class T> +bool operator!=(const Pair<T>& a, const Pair<T>& b) { return !(a == b); } -template<class Type> -bool operator<(const Pair<Type>& a, const Pair<Type>& b) +template<class T> +bool operator<(const Pair<T>& a, const Pair<T>& b) { return ( @@ -197,22 +165,22 @@ bool operator<(const Pair<Type>& a, const Pair<Type>& b) } -template<class Type> -bool operator<=(const Pair<Type>& a, const Pair<Type>& b) +template<class T> +bool operator<=(const Pair<T>& a, const Pair<T>& b) { return !(b < a); } -template<class Type> -bool operator>(const Pair<Type>& a, const Pair<Type>& b) +template<class T> +bool operator>(const Pair<T>& a, const Pair<T>& b) { return (b < a); } -template<class Type> -bool operator>=(const Pair<Type>& a, const Pair<Type>& b) +template<class T> +bool operator>=(const Pair<T>& a, const Pair<T>& b) { return !(a < b); } @@ -224,6 +192,10 @@ bool operator>=(const Pair<Type>& a, const Pair<Type>& b) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#include "PairI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/Pair/PairI.H b/src/OpenFOAM/primitives/Pair/PairI.H new file mode 100644 index 0000000000000000000000000000000000000000..2f489a03804ee19f403ecf845d9ca2ce5718dd6d --- /dev/null +++ b/src/OpenFOAM/primitives/Pair/PairI.H @@ -0,0 +1,165 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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 "Swap.H" + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +template<class T> +inline int Foam::Pair<T>::compare(const Pair<T>& a, const Pair<T>& b) +{ + if (a.first() == b.first() && a.second() == b.second()) + { + return 1; + } + if (a.first() == b.second() && a.second() == b.first()) + { + return -1; + } + + return 0; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class T> +inline Foam::Pair<T>::Pair() +{} + + +template<class T> +inline Foam::Pair<T>::Pair(const T& f, const T& s) +{ + first() = f; + second() = s; +} + + +template<class T> +inline Foam::Pair<T>::Pair(const FixedList<T, 2>& lst) +: + FixedList<T, 2>(lst) +{} + + +template<class T> +inline Foam::Pair<T>::Pair(const T& f, const T& s, const bool doSort) +{ + if (doSort && f < s) + { + first() = s; + second() = f; + } + else + { + first() = f; + second() = s; + } +} + + +template<class T> +inline Foam::Pair<T>::Pair(const FixedList<T, 2>& lst, const bool doSort) +: + Pair<T>(lst.first(), lst.last(), doSort) +{} + + + +template<class T> +inline Foam::Pair<T>::Pair(Istream& is) +: + FixedList<T, 2>(is) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class T> +inline const T& Foam::Pair<T>::second() const +{ + return last(); +} + + +template<class T> +inline T& Foam::Pair<T>::second() +{ + return last(); +} + + +template<class T> +inline const T& Foam::Pair<T>::other(const T& a) const +{ + if (first() == second()) + { + FatalErrorInFunction + << "Call to other only valid for Pair with differing" + << " elements:" << *this << abort(FatalError); + } + else if (a == first()) + { + return second(); + } + else + { + if (a != second()) + { + FatalErrorInFunction + << "Pair " << *this + << " does not contain " << a << abort(FatalError); + } + return first(); + } +} + + +template<class T> +inline bool Foam::Pair<T>::sorted() const +{ + return (first() < second()); +} + + +template<class T> +inline void Foam::Pair<T>::flip() +{ + Foam::Swap(first(), second()); +} + + +template<class T> +inline void Foam::Pair<T>::sort() +{ + if (second() < first()) + { + flip(); + } +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/Tuple2/Tuple2.H b/src/OpenFOAM/primitives/Tuple2/Tuple2.H index bf911ebc56bfc42ca40e2fdc66e558a7d9fee582..195f74044ce0ec9e1d21e40f26590a514b68e060 100644 --- a/src/OpenFOAM/primitives/Tuple2/Tuple2.H +++ b/src/OpenFOAM/primitives/Tuple2/Tuple2.H @@ -144,7 +144,7 @@ public: }; -//- Return reverse of a tuple2 +//- Return reverse of a Tuple2 template<class Type1, class Type2> inline Tuple2<Type2, Type1> reverse(const Tuple2<Type1, Type2>& t) { diff --git a/src/surfMesh/triSurface/triSurface.C b/src/surfMesh/triSurface/triSurface.C index b67da2ec63fd75c6a4cee034b884c3d33f390d0f..6a7b60da3f747c897a904371572277b8e98441e9 100644 --- a/src/surfMesh/triSurface/triSurface.C +++ b/src/surfMesh/triSurface/triSurface.C @@ -937,7 +937,7 @@ void Foam::triSurface::triFaceFaces(List<face>& plainFaces) const forAll(*this, facei) { - plainFaces[facei] = operator[](facei).triFaceFace(); + plainFaces[facei] = this->operator[](facei); } }