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 "PstreamBuffers.H"
|
||||||
#include "lduSchedule.H"
|
#include "lduSchedule.H"
|
||||||
#include "globalMeshData.H"
|
#include "globalMeshData.H"
|
||||||
|
#include "stringListOps.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * 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
|
Foam::label Foam::polyBoundaryMesh::findPatchID(const word& patchName) const
|
||||||
{
|
{
|
||||||
const polyPatchList& patches = *this;
|
const polyPatchList& patches = *this;
|
||||||
@ -444,7 +505,11 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const
|
|||||||
// with patch start labels.
|
// with patch start labels.
|
||||||
// If the face is internal, return -1;
|
// If the face is internal, return -1;
|
||||||
// if it is off the end of the list, abort
|
// 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
|
FatalErrorIn
|
||||||
(
|
(
|
||||||
@ -453,10 +518,6 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const
|
|||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (faceIndex < mesh().nInternalFaces())
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
forAll(*this, patchI)
|
forAll(*this, patchI)
|
||||||
{
|
{
|
||||||
@ -578,7 +639,7 @@ bool Foam::polyBoundaryMesh::checkParallelSync(const bool report) const
|
|||||||
|
|
||||||
// Have every processor check but only master print error.
|
// 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
|
if
|
||||||
(
|
(
|
||||||
|
|||||||
@ -38,6 +38,7 @@ SourceFiles
|
|||||||
#include "polyPatchList.H"
|
#include "polyPatchList.H"
|
||||||
#include "regIOobject.H"
|
#include "regIOobject.H"
|
||||||
#include "labelPair.H"
|
#include "labelPair.H"
|
||||||
|
#include "HashSet.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -151,6 +152,12 @@ public:
|
|||||||
//- Return a list of physical types
|
//- Return a list of physical types
|
||||||
wordList physicalTypes() const;
|
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
|
//- Find patch index given a name
|
||||||
label findPatchID(const word& patchName) const;
|
label findPatchID(const word& patchName) const;
|
||||||
|
|
||||||
|
|||||||
@ -35,8 +35,8 @@ Description
|
|||||||
#ifndef ZoneID_H
|
#ifndef ZoneID_H
|
||||||
#define ZoneID_H
|
#define ZoneID_H
|
||||||
|
|
||||||
#include "label.H"
|
#include "keyType.H"
|
||||||
#include "word.H"
|
#include "labelList.H"
|
||||||
#include "polyMesh.H"
|
#include "polyMesh.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
@ -63,10 +63,10 @@ class ZoneID
|
|||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Zone name
|
//- Zone name
|
||||||
word name_;
|
keyType key_;
|
||||||
|
|
||||||
//- Zone index
|
//- Zone indices
|
||||||
label index_;
|
labelList indices_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -74,17 +74,17 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from name
|
//- Construct from name
|
||||||
ZoneID(const word& name, const ZoneMesh<ZoneType, polyMesh>& zm)
|
ZoneID(const keyType& key, const ZoneMesh<ZoneType, polyMesh>& zm)
|
||||||
:
|
:
|
||||||
name_(name),
|
key_(key),
|
||||||
index_(zm.findZoneID(name))
|
indices_(zm.findIndices(key_))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
ZoneID(Istream& is, const ZoneMesh<ZoneType, polyMesh>& zm)
|
ZoneID(Istream& is, const ZoneMesh<ZoneType, polyMesh>& zm)
|
||||||
:
|
:
|
||||||
name_(is),
|
key_(is),
|
||||||
index_(zm.findZoneID(name_))
|
indices_(zm.findIndices(key_))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -96,21 +96,27 @@ public:
|
|||||||
// Access
|
// Access
|
||||||
|
|
||||||
//- Return name
|
//- 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
|
label index() const
|
||||||
{
|
{
|
||||||
return index_;
|
return indices_.empty() ? -1 : indices_[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Has the zone been found
|
//- Has the zone been found
|
||||||
bool active() const
|
bool active() const
|
||||||
{
|
{
|
||||||
return index_ > -1;
|
return !indices_.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -119,30 +125,24 @@ public:
|
|||||||
//- Update
|
//- Update
|
||||||
void update(const ZoneMesh<ZoneType, polyMesh>& zm)
|
void update(const ZoneMesh<ZoneType, polyMesh>& zm)
|
||||||
{
|
{
|
||||||
index_ = zm.findZoneID(name_);
|
indices_ = zm.findIndices(key_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// IOstream Operators
|
// IOstream Operators
|
||||||
|
|
||||||
friend Ostream& operator<< <ZoneType>
|
friend Ostream& operator<< <ZoneType>
|
||||||
(
|
(Ostream&, const ZoneID<ZoneType>&);
|
||||||
Ostream& os, const ZoneID<ZoneType>& p
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class ZoneType>
|
template<class ZoneType>
|
||||||
Ostream& operator<<
|
Ostream& operator<<(Ostream& os, const ZoneID<ZoneType>& p)
|
||||||
(
|
|
||||||
Ostream& os, const ZoneID<ZoneType>& p
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
os << token::BEGIN_LIST
|
os << token::BEGIN_LIST
|
||||||
<< p.name_ << token::SPACE
|
<< p.name() << token::SPACE << p.index()
|
||||||
<< p.index_
|
|
||||||
<< token::END_LIST;
|
<< token::END_LIST;
|
||||||
|
|
||||||
// Check state of Ostream
|
// Check state of Ostream
|
||||||
|
|||||||
@ -35,6 +35,8 @@ Description
|
|||||||
#ifndef polyPatchID_H
|
#ifndef polyPatchID_H
|
||||||
#define polyPatchID_H
|
#define polyPatchID_H
|
||||||
|
|
||||||
|
#include "keyType.H"
|
||||||
|
#include "labelList.H"
|
||||||
#include "polyBoundaryMesh.H"
|
#include "polyBoundaryMesh.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
@ -45,7 +47,7 @@ namespace Foam
|
|||||||
// Forward declaration of friend functions and operators
|
// Forward declaration of friend functions and operators
|
||||||
|
|
||||||
class polyPatchID;
|
class polyPatchID;
|
||||||
Ostream& operator<<(Ostream& os, const polyPatchID& p);
|
Ostream& operator<<(Ostream&, const polyPatchID&);
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
@ -57,10 +59,10 @@ class polyPatchID
|
|||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Patch name
|
//- Patch name
|
||||||
word name_;
|
keyType key_;
|
||||||
|
|
||||||
//- Patch index
|
//- Patch indices
|
||||||
label index_;
|
labelList indices_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -68,40 +70,49 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from name
|
//- Construct from name
|
||||||
polyPatchID(const word& name, const polyBoundaryMesh& bm)
|
polyPatchID(const keyType& key, const polyBoundaryMesh& bm)
|
||||||
:
|
:
|
||||||
name_(name),
|
key_(key),
|
||||||
index_(bm.findPatchID(name))
|
index_(bm.findIndices(key_))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
polyPatchID(Istream& is, const polyBoundaryMesh& bm)
|
polyPatchID(Istream& is, const polyBoundaryMesh& bm)
|
||||||
:
|
:
|
||||||
name_(is),
|
key_(is),
|
||||||
index_(bm.findPatchID(name_))
|
index_(bm.findIndices(key_))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Destructor - default
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
// Access
|
// Access
|
||||||
|
|
||||||
//- Return name
|
//- 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
|
label index() const
|
||||||
{
|
{
|
||||||
return index_;
|
return indices_.empty() ? -1 : indices_[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Has the patch been found
|
//- Has the patch been found
|
||||||
bool active() const
|
bool active() const
|
||||||
{
|
{
|
||||||
return index_ > -1;
|
return !indices_.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -110,25 +121,30 @@ public:
|
|||||||
//- Update
|
//- Update
|
||||||
void update(const polyBoundaryMesh& bm)
|
void update(const polyBoundaryMesh& bm)
|
||||||
{
|
{
|
||||||
index_ = bm.findPatchID(name_);
|
indices_ = bm.findIndices(key_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Ostream Operator
|
// Ostream Operator
|
||||||
|
|
||||||
friend Ostream& operator<<(Ostream& os, const polyPatchID& p)
|
friend Ostream& operator<<(Ostream&, const polyPatchID&);
|
||||||
{
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Ostream& operator<<(Ostream& os, const polyPatchID& p)
|
||||||
|
{
|
||||||
os << token::BEGIN_LIST
|
os << token::BEGIN_LIST
|
||||||
<< p.name_ << token::SPACE
|
<< p.name() << token::SPACE << p.index()
|
||||||
<< p.index_
|
|
||||||
<< token::END_LIST;
|
<< token::END_LIST;
|
||||||
|
|
||||||
// Check state of Ostream
|
// Check state of Ostream
|
||||||
os.check("Ostream& operator<<(Ostream&, const polyPatchID&)");
|
os.check("Ostream& operator<<(Ostream&, const polyPatchID&)");
|
||||||
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -249,6 +249,9 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices
|
|||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
labelList indices;
|
labelList indices;
|
||||||
|
|
||||||
|
if (!key.empty())
|
||||||
|
{
|
||||||
if (key.isPattern())
|
if (key.isPattern())
|
||||||
{
|
{
|
||||||
indices = findStrings(key, this->names());
|
indices = findStrings(key, this->names());
|
||||||
@ -266,6 +269,7 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices
|
|||||||
}
|
}
|
||||||
indices.setSize(nFound);
|
indices.setSize(nFound);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
@ -277,9 +281,12 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findIndex
|
|||||||
const keyType& key
|
const keyType& key
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
if (!key.empty())
|
||||||
|
{
|
||||||
if (key.isPattern())
|
if (key.isPattern())
|
||||||
{
|
{
|
||||||
labelList indices = this->findIndices(key);
|
labelList indices = this->findIndices(key);
|
||||||
|
|
||||||
// return first element
|
// return first element
|
||||||
if (!indices.empty())
|
if (!indices.empty())
|
||||||
{
|
{
|
||||||
@ -296,30 +303,13 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findIndex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// not found
|
// not found
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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>
|
template<class ZoneType, class MeshType>
|
||||||
Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID
|
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>
|
template<class ZoneType, class MeshType>
|
||||||
void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing()
|
void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -132,17 +132,17 @@ public:
|
|||||||
//- Return a list of zone names
|
//- Return a list of zone names
|
||||||
wordList names() const;
|
wordList names() const;
|
||||||
|
|
||||||
//- Find zone index given a name
|
|
||||||
label findZoneID(const word& zoneName) const;
|
|
||||||
|
|
||||||
//- Return zone indices for all matches
|
//- Return zone indices for all matches
|
||||||
labelList findIndices(const keyType&) const;
|
labelList findIndices(const keyType&) const;
|
||||||
|
|
||||||
//- Return zone index for the first match, return -1 if not found
|
//- Return zone index for the first match, return -1 if not found
|
||||||
label findIndex(const keyType&) const;
|
label findIndex(const keyType&) const;
|
||||||
|
|
||||||
//- Mark all elements that are in the matching zones
|
//- Find zone index given a name
|
||||||
PackedBoolList inZone(const keyType&) const;
|
label findZoneID(const word& zoneName) const;
|
||||||
|
|
||||||
|
//- Mark cells that match the zone specification
|
||||||
|
PackedBoolList findMatching(const keyType&) const;
|
||||||
|
|
||||||
//- Clear addressing
|
//- Clear addressing
|
||||||
void clearAddressing();
|
void clearAddressing();
|
||||||
|
|||||||
@ -134,19 +134,15 @@ bool Foam::sampledPlane::update()
|
|||||||
|
|
||||||
sampledSurface::clearGeom();
|
sampledSurface::clearGeom();
|
||||||
|
|
||||||
PackedBoolList cellsInZone;
|
labelList selectedCells = mesh().cellZones().findMatching(zoneKey_).used();
|
||||||
if (zoneKey_.size())
|
|
||||||
{
|
|
||||||
cellsInZone = mesh().cellZones().inZone(zoneKey_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cellsInZone.empty())
|
if (selectedCells.empty())
|
||||||
{
|
{
|
||||||
reCut(mesh(), true); // always triangulate. Note:Make option?
|
reCut(mesh(), true); // always triangulate. Note:Make option?
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
reCut(mesh(), true, cellsInZone.used()());
|
reCut(mesh(), true, selectedCells);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
|
|||||||
Reference in New Issue
Block a user