mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add findIndex/Indices to polyBoundaryMesh, align polyPatchID, ZoneID with keyType syntax
This commit is contained in:
@ -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
|
||||
(
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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<ZoneType, polyMesh>& zm)
|
||||
ZoneID(const keyType& key, const ZoneMesh<ZoneType, polyMesh>& zm)
|
||||
:
|
||||
name_(name),
|
||||
index_(zm.findZoneID(name))
|
||||
key_(key),
|
||||
indices_(zm.findIndices(key_))
|
||||
{}
|
||||
|
||||
//- Construct from Istream
|
||||
ZoneID(Istream& is, const ZoneMesh<ZoneType, polyMesh>& 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<ZoneType, polyMesh>& zm)
|
||||
{
|
||||
index_ = zm.findZoneID(name_);
|
||||
indices_ = zm.findIndices(key_);
|
||||
}
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
friend Ostream& operator<< <ZoneType>
|
||||
(
|
||||
Ostream& os, const ZoneID<ZoneType>& p
|
||||
);
|
||||
(Ostream&, const ZoneID<ZoneType>&);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class ZoneType>
|
||||
Ostream& operator<<
|
||||
(
|
||||
Ostream& os, const ZoneID<ZoneType>& p
|
||||
)
|
||||
Ostream& operator<<(Ostream& os, const ZoneID<ZoneType>& p)
|
||||
{
|
||||
os << token::BEGIN_LIST
|
||||
<< p.name_ << token::SPACE
|
||||
<< p.index_
|
||||
<< p.name() << token::SPACE << p.index()
|
||||
<< token::END_LIST;
|
||||
|
||||
// Check state of Ostream
|
||||
|
||||
@ -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
|
||||
|
||||
@ -249,23 +249,27 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::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<ZoneType, MeshType>::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<ZoneType, MeshType>::findIndex
|
||||
}
|
||||
|
||||
|
||||
template<class ZoneType, class MeshType>
|
||||
Foam::PackedBoolList Foam::ZoneMesh<ZoneType, MeshType>::inZone
|
||||
(
|
||||
const keyType& key
|
||||
) const
|
||||
{
|
||||
PackedBoolList lst;
|
||||
|
||||
const labelList indices = this->findIndices(key);
|
||||
forAll(indices, i)
|
||||
{
|
||||
lst |= static_cast<const labelList&>(this->operator[](indices[i]));
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
|
||||
template<class ZoneType, class MeshType>
|
||||
Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID
|
||||
(
|
||||
@ -349,6 +339,24 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID
|
||||
}
|
||||
|
||||
|
||||
template<class ZoneType, class MeshType>
|
||||
Foam::PackedBoolList Foam::ZoneMesh<ZoneType, MeshType>::findMatching
|
||||
(
|
||||
const keyType& key
|
||||
) const
|
||||
{
|
||||
PackedBoolList lst;
|
||||
|
||||
const labelList indices = this->findIndices(key);
|
||||
forAll(indices, i)
|
||||
{
|
||||
lst |= static_cast<const labelList&>(this->operator[](indices[i]));
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
|
||||
template<class ZoneType, class MeshType>
|
||||
void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing()
|
||||
{
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user