diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C index 9cd0fce6d9..6fd52f11e2 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C @@ -487,39 +487,68 @@ Foam::label Foam::ZoneMesh::findZoneID { label zoneId = findIndexImpl(*this, zoneName); - if (zoneId >= 0) + if (zoneId < 0) { - return zoneId; - } + DebugInFunction + << "Zone named " << zoneName << " not found. " + << "List of available zone names: " << names() << endl; - // Zone not found - DebugInFunction - << "Zone named " << zoneName << " not found. " - << "List of available zone names: " << names() << endl; + // Used for -dry-run, for example + if (disallowGenericZones != 0) + { + auto& zm = const_cast&>(*this); + zoneId = zm.size(); - if (disallowGenericZones != 0) - { - // Create a new ... - - Info<< "Creating dummy zone " << zoneName << endl; - dictionary dict; - dict.set("type", ZoneType::typeName); - dict.set(ZoneType::labelsName, labelList()); - - // flipMap only really applicable for face zones, but should not get - // in the way for cell- and point-zones... - dict.set("flipMap", boolList()); - - auto& zm = const_cast&>(*this); - zoneId = zm.size(); - - zm.append(new ZoneType(zoneName, dict, zoneId, zm)); + Info<< "Creating dummy zone " << zoneName << endl; + zm.append(new ZoneType(zoneName, zoneId, zm)); + } } return zoneId; } +template +const ZoneType* Foam::ZoneMesh::cfindZone +( + const word& zoneName +) const +{ + const PtrList& zones = *this; + + for (auto iter = zones.begin(); iter != zones.end(); ++iter) + { + const ZoneType* ptr = iter.get(); + + if (ptr && zoneName == ptr->name()) + { + return ptr; + } + } + + // Used for -dry-run, for example + if (disallowGenericZones != 0) + { + auto& zm = const_cast&>(*this); + + Info<< "Creating dummy zone " << zoneName << endl; + zm.append(new ZoneType(zoneName, zm.size(), zm)); + } + + return nullptr; +} + + +template +ZoneType* Foam::ZoneMesh::findZone +( + const word& zoneName +) +{ + return const_cast(this->cfindZone(zoneName)); +} + + template Foam::bitSet Foam::ZoneMesh::selection ( @@ -570,50 +599,6 @@ Foam::bitSet Foam::ZoneMesh::selection } -template -const ZoneType* Foam::ZoneMesh::zonePtr -( - const word& zoneName -) const -{ - const PtrList& zones = *this; - - for (auto iter = zones.begin(); iter != zones.end(); ++iter) - { - const ZoneType* ptr = iter.get(); - - if (ptr && zoneName == ptr->name()) - { - return ptr; - } - } - - return nullptr; -} - - -template -ZoneType* Foam::ZoneMesh::zonePtr -( - const word& zoneName -) -{ - PtrList& zones = *this; - - for (auto iter = zones.begin(); iter != zones.end(); ++iter) - { - ZoneType* ptr = iter.get(); - - if (ptr && zoneName == ptr->name()) - { - return ptr; - } - } - - return nullptr; -} - - template void Foam::ZoneMesh::clearAddressing() { @@ -801,34 +786,25 @@ ZoneType& Foam::ZoneMesh::operator() const bool verbose ) { - PtrList& zones = *this; + ZoneType* ptr = findZone(zoneName); - label zoneId = findZoneID(zoneName); + const bool existing = bool(ptr); - if (zoneId < 0) + if (!ptr) { - zoneId = zones.size(); - zones.resize(zoneId+1); - zones.set(zoneId, new ZoneType(zoneName, zoneId, *this)); - - if (verbose) - { - Info<< ZoneType::typeName << " " << zoneName - << " (new at index " << zoneId << ")" - << endl; - } - } - else - { - if (verbose) - { - Info<< ZoneType::typeName << " " << zoneName - << " (existing at index " << zoneId << ")" - << endl; - } + ptr = new ZoneType(zoneName, this->size(), *this); + this->append(ptr); } - return zones[zoneId]; + if (verbose) + { + Info<< ZoneType::typeName << ' ' << zoneName + << " (" << (existing ? "existing" : "new") + << " at index " << ptr->index() << ')' + << endl; + } + + return *ptr; } diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H index 5d3e7c44ca..4161f9d1ea 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H @@ -198,17 +198,21 @@ public: //- Return zone indices for all matches labelList indices(const wordRes& matcher) const; - - //- Return zone index for the first match, return -1 if not found + //- Zone index for the first match, return -1 if not found label findIndex(const keyType& key) const; - //- Return zone index for the first match, return -1 if not found + //- Zone index for the first match, return -1 if not found label findIndex(const wordRes& matcher) const; - - //- Find zone index given a name, return -1 if not found + //- Find zone index by name, return -1 if not found label findZoneID(const word& zoneName) const; + //- Find zone by name and return const pointer, nullptr on error + const ZoneType* cfindZone(const word& zoneName) const; + + //- Find zone by name and return pointer, nullptr on error + ZoneType* findZone(const word& zoneName); + //- Return all elements (cells, faces, points) contained in the //- listed zones. @@ -229,13 +233,6 @@ public: bitSet selection(const wordRes& matcher) const; - //- Lookup zone by name and return const pointer, nullptr on error. - const ZoneType* zonePtr(const word& zoneName) const; - - //- Lookup zone by name and return pointer, nullptr on error. - ZoneType* zonePtr(const word& zoneName); - - //- Clear addressing void clearAddressing();