From 1d9b311b8228c893804dbae8826b099e69156b8b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sat, 29 Apr 2017 12:14:46 +0200 Subject: [PATCH] ENH: further refinement to edge methods - more hash-like methods. Eg, insert/erase via lists, clear(), empty(),... - minVertex(), maxVertex() to return the smallest/largest label used - improved documentation, more clarification about where/how negative point labels are treated. --- applications/test/edges/Test-edges.C | 23 ++ .../containers/Lists/FixedList/FixedList.H | 2 +- src/OpenFOAM/meshes/meshShapes/edge/edge.H | 149 +++++++-- src/OpenFOAM/meshes/meshShapes/edge/edgeI.H | 289 +++++++++++++----- 4 files changed, 353 insertions(+), 110 deletions(-) diff --git a/applications/test/edges/Test-edges.C b/applications/test/edges/Test-edges.C index abd5f9d8a1..eda9ae0dd9 100644 --- a/applications/test/edges/Test-edges.C +++ b/applications/test/edges/Test-edges.C @@ -31,6 +31,7 @@ Description #include "argList.H" #include "edgeList.H" +#include "edgeHashes.H" using namespace Foam; @@ -79,6 +80,28 @@ int main(int argc, char *argv[]) printInfo(e4); } + e4.start() = e4.end() = -1; + Info<< "insert from list\n"; + labelHashSet newIndices({2, -1, 2, 1, 4, 1, 2, 3}); + e4.insert(newIndices.toc()); + printInfo(e4); + + e4.start() = e4.end() = -1; + Info<< "insert from list\n"; + e4.insert({0, 5, 2, -1, 2, 1, 4, 1, 2, 3}); + printInfo(e4); + + FixedList otherIndices{12, 2, -1, 1, 4, 1, 2, 3}; + e4.start() = e4.end() = -1; + Info<< "insert from list: " << otherIndices << nl; + e4.insert(otherIndices); + printInfo(e4); + + e4.start() = e4.end(); + Info<< "erase from list: " << otherIndices << nl; + Info<< "removed " << e4.erase(otherIndices) << " values" << nl; + printInfo(e4); + for (label i : {-1, 0, 1, 3}) { bool ok = e4.erase(i); diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index c969f4f4ad..bdf75aa401 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -329,7 +329,7 @@ public: //- Return size of the largest possible FixedList inline label max_size() const; - //- Return true if the FixedList is empty (ie, size() is zero) + //- Always false since zero-sized FixedList is compile-time disabled. inline bool empty() const; //- Swap two FixedLists of the same type in constant time diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edge.H b/src/OpenFOAM/meshes/meshShapes/edge/edge.H index f804fda814..f15c901b12 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edge.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edge.H @@ -28,6 +28,14 @@ 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. + 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 + addressing within the mesh). The value '-1' is used to tag invalid + point labels that correspond conceptually to open 'slots', which + can be filled with the HashSet-like functionality. + SourceFiles edgeI.H @@ -60,6 +68,24 @@ class edge : public FixedList { + // Private Member Functions + + //- Insert values, using begin/end iterators. + template + inline int insertMultiple + ( + const InputIter begIter, + const InputIter endIter + ); + + //- Remove values, using begin/end iterators. + template + inline int eraseMultiple + ( + const InputIter begIter, + const InputIter endIter + ); + public: @@ -91,6 +117,8 @@ public: // Member Functions + // Access + //- Return start vertex label inline label start() const; @@ -103,67 +131,138 @@ public: //- Return end vertex label inline label& end(); + //- Return reverse edge as copy. + // No special handling of negative point labels. + inline edge reverseEdge() const; + + + // Queries + + //- Return the smallest point label used by the edge + // No special handling of negative point labels. + inline label minVertex() const; + + //- Return the largest point label used by the edge + // 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 index) const; + //- Do the edges share a common vertex index? + // Negative point labels never connect. inline bool connects(const edge& other) const; //- Return vertex common with otherEdge or -1 on failure + // Negative point labels are never considered common between edges. inline label commonVertex(const edge& other) const; //- Given one vertex index, return the other one. + // No special treatment for negative point labels. inline label otherVertex(const label index) const; - //- 'Collapse' edge by marking duplicate point labels. - // Duplicates point labels are marked with '-1'. - // (the lower vertex is retained). - // Return the collapsed size. - inline label collapse(); - //- Return true if point label is found in edge - // No special treatment for '-1'. - inline bool found(const label index) const; + // Editing + + //- 'Collapse' edge by marking duplicate point labels as '-1', + // the lower vertex is retained. + // Return the effective size after collapsing. + inline int 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 //- Return the number of unique, valid (non -1) point labels. // Similar to a HashTable::size(). - inline label count() const; + inline int count() const; - //- Insert the index if it did not previously exist on the edge. + //- Return true if edge has no valid point labels. + inline bool empty() const; + + //- 'Clears' edge by setting both ends to invalid point labels. + inline void clear(); + + //- Fill any open slot with the index if it did not previously exist. // Returns true on success. A negative label never inserts. // Similar to a HashTable::insert(). inline bool insert(const label index); + //- Fill open slots with the indices if they did not previously exist. + // Returns true on success. Negative labels never inserts. + // Return the number of slots filled. + // Similar to a HashTable::insert(). + inline int insert(const UList