diff --git a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.C b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.C index cad4676c67506f4a797fa5f610e07647ee6d49ae..867f57f6c4cfa9fbcc10d3e660f2f3e9c9c2bdfd 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.C +++ b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.C @@ -68,7 +68,7 @@ Foam::PtrList<T>::PtrList(const SLPtrList<T>& list) template<class T> Foam::PtrList<T>::~PtrList() { - (this->ptrs_).free(); + (this->ptrs_).free(); // free old pointers } diff --git a/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H b/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H index bb2a19064a4334fe7e8c855489651f4b927af77d..c05db5554b9a390b41de14d46b89359502f489cb 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H +++ b/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H @@ -31,7 +31,7 @@ License template<class T> inline void Foam::PtrList<T>::free() { - (this->ptrs_).free(); + (this->ptrs_).free(); // free old pointers } @@ -82,7 +82,7 @@ inline Foam::PtrList<T>::PtrList template<class T> inline void Foam::PtrList<T>::clear() { - (this->ptrs_).free(); + (this->ptrs_).free(); // free old pointers UPtrList<T>::clear(); } @@ -160,7 +160,7 @@ inline Foam::autoPtr<T> Foam::PtrList<T>::set(label i, const tmp<T>& tptr) template<class T> inline void Foam::PtrList<T>::transfer(PtrList<T>& list) { - this->free(); // free old pointers + (this->ptrs_).free(); // free old pointers UPtrList<T>::transfer(list); } diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H index 37bb8d97ec3f830005616db4b0ef665925120f01..f778c850f924f66266fa18d17f428f82ab11c8e2 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H @@ -32,7 +32,7 @@ Description Note The class definition is such that it contains a list of pointers, but itself does not inherit from a list of pointers since this would - wreak havoc later inheritance resolution. + wreak havoc later with inheritance resolution. See Also Foam::PtrList @@ -226,6 +226,11 @@ public: //- Construct for a given entry inline iterator(T** ptr); + // Member functions + + //- Return pointer, can be nullptr. + inline pointer get() const; + // Member operators inline bool operator==(const iterator& iter) const; @@ -280,6 +285,11 @@ public: //- Copy construct from non-const iterator inline const_iterator(const iterator& iter); + // Member functions + + //- Return pointer, can be nullptr. + inline pointer get() const; + // Member operators inline bool operator==(const const_iterator& iter) const; diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H index a93b00df713bba77426ac656e45e879a554516df..d416564a3b4fec75c30f276b0d9c8ae6fbe346ea 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H @@ -237,6 +237,13 @@ inline Foam::UPtrList<T>::iterator::iterator(T** ptr) {} +template<class T> +inline T* Foam::UPtrList<T>::iterator::get() const +{ + return *ptr_; +} + + template<class T> inline bool Foam::UPtrList<T>::iterator::operator==(const iterator& iter) const { @@ -403,6 +410,13 @@ inline Foam::UPtrList<T>::const_iterator::const_iterator(const iterator& iter) {} +template<class T> +inline const T* Foam::UPtrList<T>::const_iterator::get() const +{ + return *ptr_; +} + + template<class T> inline bool Foam::UPtrList<T>::const_iterator::operator== ( diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C index 1abac79a9ad06f1bdafaaa35dce3cd5cbbe67828..6fe7f6fac109ffdd0cee6ce396c2b4df1d68f50a 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -366,7 +366,7 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices } else { - indices.setSize(this->size()); + indices.resize(this->size()); label count = 0; forAll(*this, i) { @@ -375,7 +375,7 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices indices[count++] = i; } } - indices.setSize(count); + indices.resize(count); } return indices; @@ -487,11 +487,12 @@ Foam::bitSet Foam::ZoneMesh<ZoneType, MeshType>::findMatching bitSet bitset; const labelList indices = this->findIndices(key); - forAll(indices, i) + + for (const label zonei : indices) { bitset.set ( - static_cast<const labelList&>(this->operator[](indices[i])) + static_cast<const labelList&>(this->operator[](zonei)) ); } @@ -499,6 +500,50 @@ Foam::bitSet Foam::ZoneMesh<ZoneType, MeshType>::findMatching } +template<class ZoneType, class MeshType> +const ZoneType* Foam::ZoneMesh<ZoneType, MeshType>::zonePtr +( + const word& zoneName +) const +{ + const PtrList<ZoneType>& 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<class ZoneType, class MeshType> +ZoneType* Foam::ZoneMesh<ZoneType, MeshType>::zonePtr +( + const word& zoneName +) +{ + PtrList<ZoneType>& 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<class ZoneType, class MeshType> void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing() { diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H index 59d1d220526ee53ac4fb838442d5d9a79d2da2ff..2389c8f5b48a5a4495e6a36f8e7a243abce2b1a6 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,13 +49,14 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Forward declaration of friend functions and operators +// Forward declarations template<class ZoneType, class MeshType> class ZoneMesh; template<class ZoneType, class MeshType> Ostream& operator<<(Ostream& os, const ZoneMesh<ZoneType, MeshType>& zones); + /*---------------------------------------------------------------------------*\ Class ZoneMesh Declaration \*---------------------------------------------------------------------------*/ @@ -186,6 +187,14 @@ public: //- Mark items (cells, faces, points) that match the zone specification bitSet findMatching(const keyType& key) 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(); @@ -205,6 +214,7 @@ public: //- writeData member function required by regIOobject bool writeData(Ostream& os) const; + // Member Operators //- Return const and non-const reference to zone by index.