diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index 91fbbca617..c11b9056bd 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -31,6 +31,7 @@ License #include "PstreamBuffers.H" #include "lduSchedule.H" #include "globalMeshData.H" +#include "stringListOps.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -413,6 +414,66 @@ Foam::wordList Foam::polyBoundaryMesh::physicalTypes() const } +Foam::labelList Foam::polyBoundaryMesh::findIndices(const keyType& key) const +{ + labelList indices; + + if (!key.empty()) + { + if (key.isPattern()) + { + indices = findStrings(key, this->names()); + } + else + { + indices.setSize(this->size()); + label nFound = 0; + forAll(*this, i) + { + if (key == operator[](i).name()) + { + indices[nFound++] = i; + } + } + indices.setSize(nFound); + } + } + + return indices; +} + + +Foam::label Foam::polyBoundaryMesh::findIndex(const keyType& key) const +{ + if (!key.empty()) + { + if (key.isPattern()) + { + labelList indices = this->findIndices(key); + + // return first element + if (!indices.empty()) + { + return indices[0]; + } + } + else + { + forAll(*this, i) + { + if (key == operator[](i).name()) + { + return i; + } + } + } + } + + // not found + return -1; +} + + Foam::label Foam::polyBoundaryMesh::findPatchID(const word& patchName) const { const polyPatchList& patches = *this; @@ -444,7 +505,11 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const // with patch start labels. // If the face is internal, return -1; // if it is off the end of the list, abort - if (faceIndex >= mesh().nFaces()) + if (faceIndex < mesh().nInternalFaces()) + { + return -1; + } + else if (faceIndex >= mesh().nFaces()) { FatalErrorIn ( @@ -453,10 +518,6 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const << abort(FatalError); } - if (faceIndex < mesh().nInternalFaces()) - { - return -1; - } forAll(*this, patchI) { @@ -578,7 +639,7 @@ bool Foam::polyBoundaryMesh::checkParallelSync(const bool report) const // Have every processor check but only master print error. - for (label procI = 1; procI < allNames.size(); procI++) + for (label procI = 1; procI < allNames.size(); ++procI) { if ( diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H index 5469c6b8b8..89bd78a17a 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H @@ -38,6 +38,7 @@ SourceFiles #include "polyPatchList.H" #include "regIOobject.H" #include "labelPair.H" +#include "HashSet.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -151,6 +152,12 @@ public: //- Return a list of physical types wordList physicalTypes() const; + //- Return patch indices for all matches + labelList findIndices(const keyType&) const; + + //- Return patch index for the first match, return -1 if not found + label findIndex(const keyType&) const; + //- Find patch index given a name label findPatchID(const word& patchName) const; diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/ZoneID.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/ZoneID.H index 6191a6d6d8..99caad1068 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/ZoneID.H +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/ZoneID.H @@ -35,8 +35,8 @@ Description #ifndef ZoneID_H #define ZoneID_H -#include "label.H" -#include "word.H" +#include "keyType.H" +#include "labelList.H" #include "polyMesh.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -63,10 +63,10 @@ class ZoneID // Private data //- Zone name - word name_; + keyType key_; - //- Zone index - label index_; + //- Zone indices + labelList indices_; public: @@ -74,17 +74,17 @@ public: // Constructors //- Construct from name - ZoneID(const word& name, const ZoneMesh& zm) + ZoneID(const keyType& key, const ZoneMesh& zm) : - name_(name), - index_(zm.findZoneID(name)) + key_(key), + indices_(zm.findIndices(key_)) {} //- Construct from Istream ZoneID(Istream& is, const ZoneMesh& zm) : - name_(is), - index_(zm.findZoneID(name_)) + key_(is), + indices_(zm.findIndices(key_)) {} @@ -96,21 +96,27 @@ public: // Access //- Return name - const word& name() const + const keyType& name() const { - return name_; + return key_; } - //- Return index + //- Return indices of matching zones + const labelList& indices() const + { + return indices_; + } + + //- Return index of first matching zone label index() const { - return index_; + return indices_.empty() ? -1 : indices_[0]; } //- Has the zone been found bool active() const { - return index_ > -1; + return !indices_.empty(); } @@ -119,30 +125,24 @@ public: //- Update void update(const ZoneMesh& zm) { - index_ = zm.findZoneID(name_); + indices_ = zm.findIndices(key_); } // IOstream Operators friend Ostream& operator<< - ( - Ostream& os, const ZoneID& p - ); + (Ostream&, const ZoneID&); }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template -Ostream& operator<< -( - Ostream& os, const ZoneID& p -) +Ostream& operator<<(Ostream& os, const ZoneID& p) { os << token::BEGIN_LIST - << p.name_ << token::SPACE - << p.index_ + << p.name() << token::SPACE << p.index() << token::END_LIST; // Check state of Ostream diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/polyPatchID.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/polyPatchID.H index 58c7ff4c15..75f6a61304 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/polyPatchID.H +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneID/polyPatchID.H @@ -35,6 +35,8 @@ Description #ifndef polyPatchID_H #define polyPatchID_H +#include "keyType.H" +#include "labelList.H" #include "polyBoundaryMesh.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -45,11 +47,11 @@ namespace Foam // Forward declaration of friend functions and operators class polyPatchID; -Ostream& operator<<(Ostream& os, const polyPatchID& p); +Ostream& operator<<(Ostream&, const polyPatchID&); /*---------------------------------------------------------------------------*\ - Class polyPatchID Declaration + Class polyPatchID Declaration \*---------------------------------------------------------------------------*/ class polyPatchID @@ -57,10 +59,10 @@ class polyPatchID // Private data //- Patch name - word name_; + keyType key_; - //- Patch index - label index_; + //- Patch indices + labelList indices_; public: @@ -68,40 +70,49 @@ public: // Constructors //- Construct from name - polyPatchID(const word& name, const polyBoundaryMesh& bm) + polyPatchID(const keyType& key, const polyBoundaryMesh& bm) : - name_(name), - index_(bm.findPatchID(name)) + key_(key), + index_(bm.findIndices(key_)) {} //- Construct from Istream polyPatchID(Istream& is, const polyBoundaryMesh& bm) : - name_(is), - index_(bm.findPatchID(name_)) + key_(is), + index_(bm.findIndices(key_)) {} + // Destructor - default + + // Member Functions // Access //- Return name - const word& name() const + const keyType& name() const { - return name_; + return key_; } - //- Return index + //- Return indices of matching patches + const labelList& indices() const + { + return indices_; + } + + //- Return index of first matching patch label index() const { - return index_; + return indices_.empty() ? -1 : indices_[0]; } //- Has the patch been found bool active() const { - return index_ > -1; + return !indices_.empty(); } @@ -110,27 +121,32 @@ public: //- Update void update(const polyBoundaryMesh& bm) { - index_ = bm.findPatchID(name_); + indices_ = bm.findIndices(key_); } // Ostream Operator - friend Ostream& operator<<(Ostream& os, const polyPatchID& p) - { - os << token::BEGIN_LIST - << p.name_ << token::SPACE - << p.index_ - << token::END_LIST; + friend Ostream& operator<<(Ostream&, const polyPatchID&); - // Check state of Ostream - os.check("Ostream& operator<<(Ostream&, const polyPatchID&)"); - - return os; - } }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Ostream& operator<<(Ostream& os, const polyPatchID& p) +{ + os << token::BEGIN_LIST + << p.name() << token::SPACE << p.index() + << token::END_LIST; + + // Check state of Ostream + os.check("Ostream& operator<<(Ostream&, const polyPatchID&)"); + + return os; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C index c939663b35..e4dbc6bfc7 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C @@ -249,23 +249,27 @@ Foam::labelList Foam::ZoneMesh::findIndices ) const { labelList indices; - if (key.isPattern()) + + if (!key.empty()) { - indices = findStrings(key, this->names()); - } - else - { - indices.setSize(this->size()); - label nFound = 0; - forAll(*this, i) + if (key.isPattern()) { - if (key == operator[](i).name()) - { - indices[nFound++] = i; - } + indices = findStrings(key, this->names()); } - indices.setSize(nFound); - } + else + { + indices.setSize(this->size()); + label nFound = 0; + forAll(*this, i) + { + if (key == operator[](i).name()) + { + indices[nFound++] = i; + } + } + indices.setSize(nFound); + } + } return indices; } @@ -277,22 +281,26 @@ Foam::label Foam::ZoneMesh::findIndex const keyType& key ) const { - if (key.isPattern()) + if (!key.empty()) { - labelList indices = this->findIndices(key); - // return first element - if (!indices.empty()) + if (key.isPattern()) { - return indices[0]; - } - } - else - { - forAll(*this, i) - { - if (key == operator[](i).name()) + labelList indices = this->findIndices(key); + + // return first element + if (!indices.empty()) { - return i; + return indices[0]; + } + } + else + { + forAll(*this, i) + { + if (key == operator[](i).name()) + { + return i; + } } } } @@ -302,24 +310,6 @@ Foam::label Foam::ZoneMesh::findIndex } -template -Foam::PackedBoolList Foam::ZoneMesh::inZone -( - const keyType& key -) const -{ - PackedBoolList lst; - - const labelList indices = this->findIndices(key); - forAll(indices, i) - { - lst |= static_cast(this->operator[](indices[i])); - } - - return lst; -} - - template Foam::label Foam::ZoneMesh::findZoneID ( @@ -349,6 +339,24 @@ Foam::label Foam::ZoneMesh::findZoneID } +template +Foam::PackedBoolList Foam::ZoneMesh::findMatching +( + const keyType& key +) const +{ + PackedBoolList lst; + + const labelList indices = this->findIndices(key); + forAll(indices, i) + { + lst |= static_cast(this->operator[](indices[i])); + } + + return lst; +} + + template void Foam::ZoneMesh::clearAddressing() { diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H index 5f81f4b948..3db8d3f12e 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H @@ -132,17 +132,17 @@ public: //- Return a list of zone names wordList names() const; - //- Find zone index given a name - label findZoneID(const word& zoneName) const; - //- Return zone indices for all matches labelList findIndices(const keyType&) const; //- Return zone index for the first match, return -1 if not found label findIndex(const keyType&) const; - //- Mark all elements that are in the matching zones - PackedBoolList inZone(const keyType&) const; + //- Find zone index given a name + label findZoneID(const word& zoneName) const; + + //- Mark cells that match the zone specification + PackedBoolList findMatching(const keyType&) const; //- Clear addressing void clearAddressing(); diff --git a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C index 9277fc44c3..6c8e0f91a7 100644 --- a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C +++ b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C @@ -134,19 +134,15 @@ bool Foam::sampledPlane::update() sampledSurface::clearGeom(); - PackedBoolList cellsInZone; - if (zoneKey_.size()) - { - cellsInZone = mesh().cellZones().inZone(zoneKey_); - } + labelList selectedCells = mesh().cellZones().findMatching(zoneKey_).used(); - if (cellsInZone.empty()) + if (selectedCells.empty()) { reCut(mesh(), true); // always triangulate. Note:Make option? } else { - reCut(mesh(), true, cellsInZone.used()()); + reCut(mesh(), true, selectedCells); } if (debug)