Zones: Now derived from PtrListDictionary to provide faster lookup

Now the HashTable underlying PtrListDictionary is used for zone lookup by name
which is a lot faster than the linear search method used previously if there are
a large number of zones.
This commit is contained in:
Henry Weller
2024-03-28 20:25:29 +00:00
parent 4ad52ea108
commit 3123551bfa
36 changed files with 340 additions and 302 deletions

View File

@ -1209,7 +1209,7 @@ int main(int argc, char *argv[])
{
FatalIOErrorIn(args.executable().c_str(), dict)
<< "Cannot find zone " << zoneNames[zonei]
<< endl << "Valid zones are " << mesh.faceZones().names()
<< endl << "Valid zones are " << mesh.faceZones().toc()
<< exit(FatalIOError);
}
@ -1222,7 +1222,7 @@ int main(int argc, char *argv[])
{
FatalIOErrorIn(args.executable().c_str(), dict)
<< "Cannot find opposite zone " << oppositeZoneNames[zonei]
<< endl << "Valid zones are " << mesh.faceZones().names()
<< endl << "Valid zones are " << mesh.faceZones().toc()
<< exit(FatalIOError);
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -73,7 +73,7 @@ void Foam::faceSelections::faceZoneSelection::select
{
FatalErrorInFunction
<< "Cannot find faceZone " << zoneName_ << nl << "Valid zones are "
<< mesh_.faceZones().names()
<< mesh_.faceZones().toc()
<< exit(FatalError);
}

View File

@ -142,7 +142,7 @@ Foam::mergePolyMesh::mergePolyMesh(polyMesh& mesh)
// Insert point, face and cell zones into the list
// Point zones
wordList curPointZoneNames = mesh_.pointZones().names();
wordList curPointZoneNames = mesh_.pointZones().toc();
if (curPointZoneNames.size())
{
pointZoneNames_.setCapacity(2*curPointZoneNames.size());
@ -156,7 +156,7 @@ Foam::mergePolyMesh::mergePolyMesh(polyMesh& mesh)
pointZonesAddedPoints_.setSize(pointZoneNames_.size());
// Face zones
wordList curFaceZoneNames = mesh_.faceZones().names();
wordList curFaceZoneNames = mesh_.faceZones().toc();
if (curFaceZoneNames.size())
{
@ -171,7 +171,7 @@ Foam::mergePolyMesh::mergePolyMesh(polyMesh& mesh)
faceZonesAddedFaces_.setSize(faceZoneNames_.size());
// Cell zones
wordList curCellZoneNames = mesh_.cellZones().names();
wordList curCellZoneNames = mesh_.cellZones().toc();
if (curCellZoneNames.size())
{

View File

@ -1196,7 +1196,7 @@ void matchRegions
labelList zoneSizes(cellZones.size(), 0);
{
List<wordList> zoneNames(Pstream::nProcs());
zoneNames[Pstream::myProcNo()] = cellZones.names();
zoneNames[Pstream::myProcNo()] = cellZones.toc();
Pstream::gatherList(zoneNames);
Pstream::scatterList(zoneNames);

View File

@ -272,11 +272,11 @@ Foam::autoPtr<Foam::fvMesh> Foam::loadOrCreateMesh
// Determine zones
// ~~~~~~~~~~~~~~~
wordList pointZoneNames(mesh.pointZones().names());
wordList pointZoneNames(mesh.pointZones().toc());
Pstream::scatter(pointZoneNames);
wordList faceZoneNames(mesh.faceZones().names());
wordList faceZoneNames(mesh.faceZones().toc());
Pstream::scatter(faceZoneNames);
wordList cellZoneNames(mesh.cellZones().names());
wordList cellZoneNames(mesh.cellZones().toc());
Pstream::scatter(cellZoneNames);
if (!haveMesh)

View File

@ -261,7 +261,7 @@ void Foam::ensightMesh::correct()
// faceZones
if (faceZones_)
{
wordList faceZoneNamesAll = mesh_.faceZones().names();
wordList faceZoneNamesAll = mesh_.faceZones().toc();
// Need to sort the list of all face zones since the index may vary
// from processor to processor...
sort(faceZoneNamesAll);

View File

@ -148,7 +148,7 @@ int main(int argc, char *argv[])
if (args.optionFound("faceZones"))
{
wordReList zoneNames(args.optionLookup("faceZones")());
const wordList allZoneNames(mfz.names());
const wordList allZoneNames(mfz.toc());
forAll(zoneNames, i)
{
const wordRe& zoneName = zoneNames[i];

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2015-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -69,9 +69,56 @@ Foam::PtrListDictionary<T>::PtrListDictionary(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline Foam::autoPtr<T> Foam::PtrListDictionary<T>::set
Foam::label Foam::PtrListDictionary<T>::findIndex(const word& key) const
{
forAll(*this, i)
{
if (operator[](i).keyword() == key)
{
return i;
}
}
return -1;
}
template<class T>
Foam::List<Foam::label> Foam::PtrListDictionary<T>::findIndices
(
const wordRe& key
) const
{
List<label> indices;
if (!key.empty())
{
if (key.isPattern())
{
indices = findStrings(key, this->toc());
}
else
{
indices.setSize(this->size());
label nFound = 0;
forAll(*this, i)
{
if (key == operator[](i).keyword())
{
indices[nFound++] = i;
}
}
indices.setSize(nFound);
}
}
return indices;
}
template<class T>
inline void Foam::PtrListDictionary<T>::append
(
const label i,
const word& key,
T* ptr
)
@ -82,7 +129,50 @@ inline Foam::autoPtr<T> Foam::PtrListDictionary<T>::set
<< "Cannot insert with key '" << key << "' into hash-table"
<< abort(FatalError);
}
return PtrList<T>::set(i, ptr);
return PtrList<T>::append(ptr);
}
template<class T>
inline void Foam::PtrListDictionary<T>::append
(
const word& key,
const autoPtr<T>& aptr
)
{
return append(key, const_cast<autoPtr<T>&>(aptr).ptr());
}
template<class T>
inline void Foam::PtrListDictionary<T>::append
(
const word& key,
const tmp<T>& t
)
{
return append(key, const_cast<tmp<T>&>(t).ptr());
}
template<class T>
inline void Foam::PtrListDictionary<T>::append(T* ptr)
{
append(ptr->keyword(), ptr);
}
template<class T>
inline void Foam::PtrListDictionary<T>::append(const autoPtr<T>& aptr)
{
append(aptr->keyword(), aptr);
}
template<class T>
inline void Foam::PtrListDictionary<T>::append(const tmp<T>& t)
{
append(t->keyword(), t);
}
@ -91,14 +181,13 @@ inline Foam::autoPtr<T> Foam::PtrListDictionary<T>::set
(
const label i,
const word& key,
autoPtr<T>& aptr
T* ptr
)
{
T* ptr = aptr.ptr();
if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
if (!DictionaryBase<PtrList<T>, T>::hashedTs_.set(key, ptr))
{
FatalErrorInFunction
<< "Cannot insert with key '" << key << "' into hash-table"
<< "Cannot set with key '" << key << "' into hash-table"
<< abort(FatalError);
}
return PtrList<T>::set(i, ptr);
@ -110,17 +199,55 @@ inline Foam::autoPtr<T> Foam::PtrListDictionary<T>::set
(
const label i,
const word& key,
tmp<T>& t
const autoPtr<T>& aptr
)
{
T* ptr = t.ptr();
if (!DictionaryBase<PtrList<T>, T>::hashedTs_.insert(key, ptr))
{
FatalErrorInFunction
<< "Cannot insert with key '" << key << "' into hash-table"
<< abort(FatalError);
}
return PtrList<T>::set(i, ptr);
return set(i, key, const_cast<autoPtr<T>&>(aptr).ptr());
}
template<class T>
inline Foam::autoPtr<T> Foam::PtrListDictionary<T>::set
(
const label i,
const word& key,
const tmp<T>& t
)
{
return set(i, key, const_cast<tmp<T>&>(t).ptr());
}
template<class T>
inline Foam::autoPtr<T> Foam::PtrListDictionary<T>::set
(
const label i,
T* ptr
)
{
return set(i, ptr->keyword(), ptr);
}
template<class T>
inline Foam::autoPtr<T> Foam::PtrListDictionary<T>::set
(
const label i,
const autoPtr<T>& aptr
)
{
return set(i, aptr->keyword(), aptr);
}
template<class T>
inline Foam::autoPtr<T> Foam::PtrListDictionary<T>::set
(
const label i,
const tmp<T>& t
)
{
return set(i, t->keyword(), t);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2015-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -40,6 +40,7 @@ SourceFiles
#include "DictionaryBase.H"
#include "PtrList.H"
#include "wordRe.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -88,14 +89,59 @@ public:
// Member Functions
//- Set element to pointer provided and return old element
autoPtr<T> set(const label, const word& key, T*);
// Access
//- Set element to autoPtr value provided and return old element
autoPtr<T> set(const label, const word& key, autoPtr<T>&);
//- Return the index of the given the key or -1 if not found
label findIndex(const word& key) const;
//- Set element to tmp value provided and return old element
autoPtr<T> set(const label, const word& key, tmp<T>&);
//- Return the indices for all matches
// of the given key regular expression
List<label> findIndices(const wordRe& key) const;
// Edit
//- Append an element at the end of the list
inline void append(const word& key, T*);
//- Append an element at the end of the list
inline void append(const word& key, const autoPtr<T>&);
//- Append an element at the end of the list
inline void append(const word& key, const tmp<T>&);
//- Append an element at the end of the list
// using the element's keyword as the key
inline void append(T*);
//- Append an element at the end of the list
// using the element's keyword as the key
inline void append(const autoPtr<T>&);
//- Append an element at the end of the list
// using the element's keyword as the key
inline void append(const tmp<T>&);
//- Set element to pointer provided and return old element
autoPtr<T> set(const label, const word& key, T*);
//- Set element to autoPtr value provided and return old element
autoPtr<T> set(const label, const word& key, const autoPtr<T>&);
//- Set element to tmp value provided and return old element
autoPtr<T> set(const label, const word& key, const tmp<T>&);
//- Set element to pointer provided and return old element
// using the element's keyword as the key
autoPtr<T> set(const label, T*);
//- Set element to autoPtr value provided and return old element
// using the element's keyword as the key
autoPtr<T> set(const label, const autoPtr<T>&);
//- Set element to tmp value provided and return old element
// using the element's keyword as the key
autoPtr<T> set(const label, const tmp<T>&);
// Conversion

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -98,6 +98,12 @@ Foam::functionObjects::logFiles::~logFiles()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::wordList& Foam::functionObjects::logFiles::toc() const
{
return names_;
}
const Foam::wordList& Foam::functionObjects::logFiles::names() const
{
return names_;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -107,7 +107,10 @@ public:
// Member Functions
//- Return const access to the names
//- Return the list of log file names
const wordList& toc() const;
//- Return the list of log file names
const wordList& names() const;
//- Return access to the files

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -567,7 +567,7 @@ void Foam::polyBoundaryMesh::setGroup
}
Foam::wordList Foam::polyBoundaryMesh::names() const
Foam::wordList Foam::polyBoundaryMesh::toc() const
{
const polyPatchList& patches = *this;
@ -582,6 +582,12 @@ Foam::wordList Foam::polyBoundaryMesh::names() const
}
Foam::wordList Foam::polyBoundaryMesh::names() const
{
return toc();
}
Foam::wordList Foam::polyBoundaryMesh::types() const
{
const polyPatchList& patches = *this;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -153,7 +153,10 @@ public:
// Only valid for singly connected polyBoundaryMesh and not parallel
const List<labelPairList>& nbrEdges() const;
//- Return a list of patch names
//- Return the list of patch names
wordList toc() const;
//- Return the list of patch names
wordList names() const;
//- Return a list of patch types

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -1144,7 +1144,7 @@ void Foam::polyMesh::addZones
// Copy the zone pointers
forAll(pz, pI)
{
pointZones_.set(pI, pz[pI]);
pointZones_.set(pI, pz[pI]->name(), pz[pI]);
}
pointZones_.writeOpt() = IOobject::AUTO_WRITE;
@ -1158,7 +1158,7 @@ void Foam::polyMesh::addZones
// Copy the zone pointers
forAll(fz, fI)
{
faceZones_.set(fI, fz[fI]);
faceZones_.set(fI, fz[fI]->name(), fz[fI]);
}
faceZones_.writeOpt() = IOobject::AUTO_WRITE;
@ -1172,7 +1172,7 @@ void Foam::polyMesh::addZones
// Copy the zone pointers
forAll(cz, cI)
{
cellZones_.set(cI, cz[cI]);
cellZones_.set(cI, cz[cI]->name(), cz[cI]);
}
cellZones_.writeOpt() = IOobject::AUTO_WRITE;

View File

@ -183,6 +183,12 @@ public:
return name_;
}
//- Return name as the keyword
const word& keyword() const
{
return name_;
}
//- Return ZonesType reference
const ZonesType& zones() const;

View File

@ -47,7 +47,7 @@ bool Foam::Zones<ZoneType, ZonesType, MeshType>::read()
<< endl;
}
PtrList<ZoneType>& zones = *this;
PtrListDictionary<ZoneType>& zones = *this;
// Read zones
Istream& is = readStream(typeName);
@ -60,6 +60,7 @@ bool Foam::Zones<ZoneType, ZonesType, MeshType>::read()
zones.set
(
zi,
patchEntries[zi].keyword(),
ZoneType::New
(
patchEntries[zi].keyword(),
@ -97,8 +98,8 @@ Foam::Zones<ZoneType, ZonesType, MeshType>::Zones
const MeshType& mesh
)
:
PtrList<ZoneType>(),
regIOobject(io),
PtrListDictionary<ZoneType>(0),
mesh_(mesh)
{
read();
@ -113,8 +114,8 @@ Foam::Zones<ZoneType, ZonesType, MeshType>::Zones
const label size
)
:
PtrList<ZoneType>(size),
regIOobject(io),
PtrListDictionary<ZoneType>(size),
mesh_(mesh)
{
// Optionally read contents, otherwise keep size
@ -130,21 +131,26 @@ Foam::Zones<ZoneType, ZonesType, MeshType>::Zones
const PtrList<ZoneType>& mpz
)
:
PtrList<ZoneType>(),
regIOobject(io),
PtrListDictionary<ZoneType>(0),
mesh_(mesh)
{
if (!read())
{
// Nothing read. Use supplied zones
PtrList<ZoneType>& zones = *this;
PtrListDictionary<ZoneType>& zones = *this;
zones.setSize(mpz.size());
forAll(zones, zi)
{
zones.set(zi, mpz[zi].clone
zones.set
(
static_cast<const ZonesType&>(*this)
).ptr());
zi,
mpz[zi].name(),
mpz[zi].clone
(
static_cast<const ZonesType&>(*this)
)
);
}
}
}
@ -202,7 +208,7 @@ Foam::labelList Foam::Zones<ZoneType, ZonesType, MeshType>::whichZones
template<class ZoneType, class ZonesType, class MeshType>
Foam::wordList Foam::Zones<ZoneType, ZonesType, MeshType>::types() const
{
const PtrList<ZoneType>& zones = *this;
const PtrListDictionary<ZoneType>& zones = *this;
wordList lst(zones.size());
@ -215,124 +221,6 @@ Foam::wordList Foam::Zones<ZoneType, ZonesType, MeshType>::types() const
}
template<class ZoneType, class ZonesType, class MeshType>
Foam::wordList Foam::Zones<ZoneType, ZonesType, MeshType>::names() const
{
const PtrList<ZoneType>& zones = *this;
wordList lst(zones.size());
forAll(zones, zi)
{
lst[zi] = zones[zi].name();
}
return lst;
}
template<class ZoneType, class ZonesType, class MeshType>
bool Foam::Zones<ZoneType, ZonesType, MeshType>::found
(
const word& zoneName
) const
{
if (zoneName != word::null)
{
forAll(*this, i)
{
if (zoneName == operator[](i).name())
{
return true;
}
}
}
// Not found
return false;
}
template<class ZoneType, class ZonesType, class MeshType>
Foam::label Foam::Zones<ZoneType, ZonesType, MeshType>::findIndex
(
const word& zoneName
) const
{
const PtrList<ZoneType>& zones = *this;
forAll(zones, zi)
{
if (zones[zi].name() == zoneName)
{
return zi;
}
}
// Zone not found
if (debug)
{
InfoInFunction
<< "Zone named " << zoneName << " not found. "
<< "List of available zone names: " << names() << endl;
}
// not found
return -1;
}
template<class ZoneType, class ZonesType, class MeshType>
Foam::labelList Foam::Zones<ZoneType, ZonesType, MeshType>::findIndices
(
const wordRe& 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;
}
template<class ZoneType, class ZonesType, class MeshType>
Foam::PackedBoolList Foam::Zones<ZoneType, ZonesType, MeshType>::findMatching
(
const wordRe& 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 ZonesType, class MeshType>
void Foam::Zones<ZoneType, ZonesType, MeshType>::append(ZoneType* zonePtr) const
{
@ -346,7 +234,11 @@ void Foam::Zones<ZoneType, ZonesType, MeshType>::append(ZoneType* zonePtr) const
}
else
{
zones.PtrList<ZoneType>::append(zonePtr);
zones.PtrListDictionary<ZoneType>::append
(
zonePtr->name(),
zonePtr
);
}
}
@ -366,7 +258,11 @@ void Foam::Zones<ZoneType, ZonesType, MeshType>::append
}
else
{
zones.PtrList<ZoneType>::append(zone.clone(*this));
zones.PtrListDictionary<ZoneType>::append
(
zone.name(),
zone.clone(*this)
);
}
}
@ -374,7 +270,7 @@ void Foam::Zones<ZoneType, ZonesType, MeshType>::append
template<class ZoneType, class ZonesType, class MeshType>
void Foam::Zones<ZoneType, ZonesType, MeshType>::clearAddressing()
{
PtrList<ZoneType>& zones = *this;
PtrListDictionary<ZoneType>& zones = *this;
forAll(zones, zi)
{
@ -387,7 +283,7 @@ template<class ZoneType, class ZonesType, class MeshType>
void Foam::Zones<ZoneType, ZonesType, MeshType>::clear()
{
clearAddressing();
PtrList<ZoneType>::clear();
PtrListDictionary<ZoneType>::clear();
}
@ -399,7 +295,7 @@ bool Foam::Zones<ZoneType, ZonesType, MeshType>::checkDefinition
{
bool inError = false;
const PtrList<ZoneType>& zones = *this;
const PtrListDictionary<ZoneType>& zones = *this;
forAll(zones, zi)
{
@ -421,13 +317,13 @@ bool Foam::Zones<ZoneType, ZonesType, MeshType>::checkParallelSync
}
const PtrList<ZoneType>& zones = *this;
const PtrListDictionary<ZoneType>& zones = *this;
bool hasError = false;
// Collect all names
List<wordList> allNames(Pstream::nProcs());
allNames[Pstream::myProcNo()] = this->names();
allNames[Pstream::myProcNo()] = this->toc();
Pstream::gatherList(allNames);
Pstream::scatterList(allNames);
@ -493,7 +389,7 @@ void Foam::Zones<ZoneType, ZonesType, MeshType>::insert
const List<labelHashSet>& zonesIndices
)
{
PtrList<ZoneType>& zones = *this;
PtrListDictionary<ZoneType>& zones = *this;
if (zonesIndices.size() != zones.size())
{
@ -513,7 +409,7 @@ void Foam::Zones<ZoneType, ZonesType, MeshType>::insert
template<class ZoneType, class ZonesType, class MeshType>
void Foam::Zones<ZoneType, ZonesType, MeshType>::movePoints(const pointField& p)
{
PtrList<ZoneType>& zones = *this;
PtrListDictionary<ZoneType>& zones = *this;
forAll(zones, zi)
{
@ -528,7 +424,7 @@ void Foam::Zones<ZoneType, ZonesType, MeshType>::topoChange
const polyTopoChangeMap& map
)
{
PtrList<ZoneType>& zones = *this;
PtrListDictionary<ZoneType>& zones = *this;
forAll(zones, zi)
{
@ -540,7 +436,7 @@ void Foam::Zones<ZoneType, ZonesType, MeshType>::topoChange
template<class ZoneType, class ZonesType, class MeshType>
void Foam::Zones<ZoneType, ZonesType, MeshType>::mapMesh(const polyMeshMap& map)
{
PtrList<ZoneType>& zones = *this;
PtrListDictionary<ZoneType>& zones = *this;
forAll(zones, zi)
{
@ -555,7 +451,7 @@ void Foam::Zones<ZoneType, ZonesType, MeshType>::distribute
const polyDistributionMap& map
)
{
PtrList<ZoneType>& zones = *this;
PtrListDictionary<ZoneType>& zones = *this;
forAll(zones, zi)
{
@ -570,7 +466,7 @@ void Foam::Zones<ZoneType, ZonesType, MeshType>::swap(ZonesType& otherZones)
clearAddressing();
otherZones.clearAddressing();
PtrList<ZoneType>& zones = *this;
PtrListDictionary<ZoneType>& zones = *this;
DynamicList<label> toOtherZone;
@ -586,15 +482,19 @@ void Foam::Zones<ZoneType, ZonesType, MeshType>::swap(ZonesType& otherZones)
forAll(otherZones, ozi)
{
const label zi = findIndex(otherZones[ozi].name());
const label zi = this->findIndex(otherZones[ozi].name());
if (zi < 0)
{
zones.append(otherZones[ozi].clone
zones.append
(
static_cast<const ZonesType&>(*this))
otherZones[ozi].name(),
otherZones[ozi].clone
(
static_cast<const ZonesType&>(*this)
)
);
otherZones.set(ozi, nullptr);
otherZones.set(ozi, otherZones[ozi].name(), nullptr);
}
else
{
@ -604,11 +504,12 @@ void Foam::Zones<ZoneType, ZonesType, MeshType>::swap(ZonesType& otherZones)
forAll(toOtherZone, i)
{
otherZones.PtrList<ZoneType>::append
otherZones.PtrListDictionary<ZoneType>::append
(
zones[toOtherZone[i]].name(),
zones[toOtherZone[i]].clone(otherZones)
);
zones.set(toOtherZone[i], nullptr);
zones.set(toOtherZone[i], zones[toOtherZone[i]].name(), nullptr);
}
zones.shrink();
@ -624,48 +525,6 @@ bool Foam::Zones<ZoneType, ZonesType, MeshType>::writeData(Ostream& os) const
}
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
template<class ZoneType, class ZonesType, class MeshType>
const ZoneType& Foam::Zones<ZoneType, ZonesType, MeshType>::operator[]
(
const word& zoneName
) const
{
const label zi = findIndex(zoneName);
if (zi < 0)
{
FatalErrorInFunction
<< "Zone named " << zoneName << " not found." << nl
<< "Available zone names: " << names() << endl
<< abort(FatalError);
}
return operator[](zi);
}
template<class ZoneType, class ZonesType, class MeshType>
ZoneType& Foam::Zones<ZoneType, ZonesType, MeshType>::operator[]
(
const word& zoneName
)
{
const label zi = findIndex(zoneName);
if (zi < 0)
{
FatalErrorInFunction
<< "Zone named " << zoneName << " not found." << nl
<< "Available zone names: " << names() << endl
<< abort(FatalError);
}
return operator[](zi);
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class ZoneType, class ZonesType, class MeshType>

View File

@ -35,6 +35,7 @@ SourceFiles
#ifndef Zones_H
#define Zones_H
#include "PtrListDictionary.H"
#include "regIOobject.H"
#include "pointFieldFwd.H"
#include "Map.H"
@ -66,8 +67,8 @@ Ostream& operator<<(Ostream&, const Zones<ZoneType, ZonesType, MeshType>&);
template<class ZoneType, class ZonesType, class MeshType>
class Zones
:
public PtrList<ZoneType>,
public regIOobject
public regIOobject,
public PtrListDictionary<ZoneType>
{
// Private Data
@ -127,6 +128,8 @@ public:
return mesh_;
}
using PtrListDictionary<ZoneType>::found;
//- Return true if objectIndex is in any zone
bool found(const label objectIndex) const;
@ -136,21 +139,6 @@ public:
//- Return a list of zone types
wordList types() const;
//- Return a list of zone names
wordList names() const;
//- Return true if the given zoneName is present
bool found(const word& zoneName) const;
//- Find the zone index given the zone name
label findIndex(const word& zoneName) const;
//- Find and return the zone indices for all matches
labelList findIndices(const wordRe&) const;
//- Mark cells that match the zone specification
PackedBoolList findMatching(const wordRe&) const;
//- Append or update a zone
void append(ZoneType*) const;
@ -196,13 +184,7 @@ public:
// Member Operators
//- Return const and non-const reference to ZoneType by index.
using PtrList<ZoneType>::operator[];
//- Return const reference to ZoneType by name.
const ZoneType& operator[](const word&) const;
//- Return reference to ZoneType by name.
ZoneType& operator[](const word&);
using PtrListDictionary<ZoneType>::operator[];
//- Disallow default bitwise assignment
void operator=(const Zones<ZoneType, ZonesType, MeshType>&) = delete;

View File

@ -70,7 +70,7 @@ lookup
void Foam::meshReader::addCellZones(polyMesh& mesh) const
{
cellTable_.addCellZones(mesh, cellTableId_);
warnDuplicates("cellZones", mesh.cellZones().names());
warnDuplicates("cellZones", mesh.cellZones().toc());
}
@ -112,7 +112,7 @@ void Foam::meshReader::addFaceZones(polyMesh& mesh) const
nZone++;
}
mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
warnDuplicates("faceZones", mesh.faceZones().names());
warnDuplicates("faceZones", mesh.faceZones().toc());
}

View File

@ -399,7 +399,7 @@ void Foam::cellTable::operator=(const polyMesh& mesh)
// create cellTableId and cellTable based on cellZones
label nZoneCells = 0;
wordList zoneNames = mesh.cellZones().names();
wordList zoneNames = mesh.cellZones().toc();
label unZonedType = zoneNames.size() + 1;
// do cell zones

View File

@ -292,14 +292,14 @@ void Foam::singleCellFvMesh::agglomerateMesh
{
forAll(mesh.cellZones(), zoneI)
{
const cellZone& oldFz = mesh.cellZones()[zoneI];
const cellZone& oldCz = mesh.cellZones()[zoneI];
DynamicList<label> newAddressing;
cellZones().set
(
zoneI,
oldFz.clone
oldCz.clone
(
newAddressing,
cellZones()
@ -348,13 +348,13 @@ void Foam::singleCellFvMesh::agglomerateMesh
{
forAll(mesh.pointZones(), zoneI)
{
const pointZone& oldFz = mesh.pointZones()[zoneI];
const pointZone& oldPz = mesh.pointZones()[zoneI];
DynamicList<label> newAddressing(oldFz.size());
DynamicList<label> newAddressing(oldPz.size());
forAll(oldFz, i)
forAll(oldPz, i)
{
label newPointi = reversePointMap_[oldFz[i]];
label newPointi = reversePointMap_[oldPz[i]];
if (newPointi != -1)
{
newAddressing.append(newPointi);
@ -364,7 +364,7 @@ void Foam::singleCellFvMesh::agglomerateMesh
pointZones().set
(
zoneI,
oldFz.clone
oldPz.clone
(
newAddressing,
pointZones()

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -112,7 +112,7 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::setFaceZoneFaces()
<< selectionTypeNames[selectionType_]
<< "(" << selectionName_ << "):" << nl
<< " Unknown face zone name: " << selectionName_
<< ". Valid face zones are: " << mesh_.faceZones().names()
<< ". Valid face zones are: " << mesh_.faceZones().toc()
<< nl << exit(FatalError);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -250,7 +250,7 @@ bool Foam::functionObjects::layerAverage::read(const dictionary& dict)
findStrings
(
dict.lookupOrDefault<wordReList>("zones", wordReList()),
mesh_.faceZones().names()
mesh_.faceZones().toc()
);
if (patchIndices_.empty() && zoneIndices_.empty())

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2013-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -75,7 +75,7 @@ void Foam::fv::effectivenessHeatExchanger::setZone()
FatalErrorInFunction
<< type() << " " << this->name() << ": "
<< " Unknown face zone name: " << faceZoneName_
<< ". Valid face zones are: " << mesh().faceZones().names()
<< ". Valid face zones are: " << mesh().faceZones().toc()
<< nl << exit(FatalError);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -223,7 +223,7 @@ void Foam::CellZoneInjection<CloudType>::topoChange()
{
FatalErrorInFunction
<< "Unknown cell zone name: " << cellZoneName_
<< ". Valid cell zones are: " << mesh.cellZones().names()
<< ". Valid cell zones are: " << mesh.cellZones().toc()
<< nl << exit(FatalError);
}

View File

@ -1807,7 +1807,7 @@ void Foam::meshRefinement::checkCoupledFaceZones(const polyMesh& mesh)
{
List<wordList> zoneNames(Pstream::nProcs());
zoneNames[Pstream::myProcNo()] = fZones.names();
zoneNames[Pstream::myProcNo()] = fZones.toc();
Pstream::gatherList(zoneNames);
Pstream::scatterList(zoneNames);
// All have same data now. Check.

View File

@ -374,7 +374,7 @@ Foam::labelList Foam::surfaceZonesInfo::addCellZonesToMesh
// Check they are synced
List<wordList> allCellZones(Pstream::nProcs());
allCellZones[Pstream::myProcNo()] = cellZones.names();
allCellZones[Pstream::myProcNo()] = cellZones.toc();
Pstream::gatherList(allCellZones);
Pstream::scatterList(allCellZones);
@ -436,7 +436,7 @@ Foam::labelList Foam::surfaceZonesInfo::addFaceZonesToMesh
// Check they are synced
List<wordList> allFaceZones(Pstream::nProcs());
allFaceZones[Pstream::myProcNo()] = faceZones.names();
allFaceZones[Pstream::myProcNo()] = faceZones.toc();
Pstream::gatherList(allFaceZones);
Pstream::scatterList(allFaceZones);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -91,7 +91,7 @@ void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
{
WarningInFunction
<< "Cannot find any faceZone named " << zoneName_ << endl
<< "Valid names are " << mesh_.faceZones().names() << endl;
<< "Valid names are " << mesh_.faceZones().toc() << endl;
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -71,7 +71,7 @@ void Foam::zoneToCell::combine(topoSet& set, const bool add) const
{
WarningInFunction
<< "Cannot find any cellZone named " << zoneName_ << endl
<< "Valid names are " << mesh_.cellZones().names() << endl;
<< "Valid names are " << mesh_.cellZones().toc() << endl;
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -71,7 +71,7 @@ void Foam::zoneToFace::combine(topoSet& set, const bool add) const
{
WarningInFunction
<< "Cannot find any faceZone named " << zoneName_ << endl
<< "Valid names are " << mesh_.faceZones().names() << endl;
<< "Valid names are " << mesh_.faceZones().toc() << endl;
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -72,7 +72,7 @@ void Foam::zoneToPoint::combine(topoSet& set, const bool add) const
{
WarningInFunction
<< "Cannot find any pointZone named " << zoneName_ << endl
<< "Valid names are " << mesh_.pointZones().names() << endl;
<< "Valid names are " << mesh_.pointZones().toc() << endl;
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -102,7 +102,7 @@ void Foam::polyCellSet::setCells()
{
FatalErrorInFunction
<< "Cannot find cellZone " << cellSetName_ << endl
<< "Valid cellZones are " << mesh_.cellZones().names()
<< "Valid cellZones are " << mesh_.cellZones().toc()
<< exit(FatalError);
}

View File

@ -309,7 +309,7 @@ void Foam::displacementLayeredMotionMotionSolver::cellZoneSolve
{
FatalErrorInFunction
<< "Cannot find faceZone " << faceZoneName
<< endl << "Valid zones are " << mesh().faceZones().names()
<< endl << "Valid zones are " << mesh().faceZones().toc()
<< exit(FatalError);
}
@ -543,7 +543,7 @@ void Foam::displacementLayeredMotionMotionSolver::solve()
{
FatalErrorInFunction
<< "Cannot find cellZone " << cellZoneName
<< endl << "Valid zones are " << mesh().cellZones().names()
<< endl << "Valid zones are " << mesh().cellZones().toc()
<< exit(FatalError);
}

View File

@ -72,7 +72,7 @@ Foam::multiSolidBodyMotionSolver::multiSolidBodyMotionSolver
(
coeffDict()
) << "Cannot find cellZone named " << iter().keyword()
<< ". Valid zones are " << mesh.cellZones().names()
<< ". Valid zones are " << mesh.cellZones().toc()
<< exit(FatalIOError);
}

View File

@ -99,7 +99,7 @@ void Foam::decompositionConstraints::preserveFaceZonesConstraint::add
const faceZones& fZones = mesh.faceZones();
const labelList zoneIDs = findStrings(zones_, fZones.names());
const labelList zoneIDs = findStrings(zones_, fZones.toc());
label nUnblocked = 0;
@ -169,7 +169,7 @@ void Foam::decompositionConstraints::preserveFaceZonesConstraint::apply
const faceZones& fZones = mesh.faceZones();
const labelList zoneIDs = findStrings(zones_, fZones.names());
const labelList zoneIDs = findStrings(zones_, fZones.toc());
label nChanged = 0;

View File

@ -1879,9 +1879,9 @@ Foam::autoPtr<Foam::polyDistributionMap> Foam::fvMeshDistribute::distribute
// Collect any zone names
const wordList pointZoneNames(mergeWordList(mesh_.pointZones().names()));
const wordList faceZoneNames(mergeWordList(mesh_.faceZones().names()));
const wordList cellZoneNames(mergeWordList(mesh_.cellZones().names()));
const wordList pointZoneNames(mergeWordList(mesh_.pointZones().toc()));
const wordList faceZoneNames(mergeWordList(mesh_.faceZones().toc()));
const wordList cellZoneNames(mergeWordList(mesh_.cellZones().toc()));
// Local environment of all boundary faces

View File

@ -573,7 +573,7 @@ void Foam::polyMeshAdder::mergePointZones
)
{
zoneNames.setCapacity(pz0.size() + pz1.size());
zoneNames.append(pz0.names());
zoneNames.append(pz0.toc());
from1ToAll.setSize(pz1.size());
@ -719,7 +719,7 @@ void Foam::polyMeshAdder::mergeFaceZones
zoneNames.setCapacity(fz0.size() + fz1.size());
zoneNames.append(fz0.names());
zoneNames.append(fz0.toc());
from1ToAll.setSize(fz1.size());
@ -900,7 +900,7 @@ void Foam::polyMeshAdder::mergeCellZones
)
{
zoneNames.setCapacity(cz0.size() + cz1.size());
zoneNames.append(cz0.names());
zoneNames.append(cz0.toc());
from1ToAll.setSize(cz1.size());
forAll(cz1, zoneI)