From a0282c7e4112969e8ac6d74b9afe24a1ea30467f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 12 Sep 2022 12:50:10 +0200 Subject: [PATCH] ENH: prefer PtrList set/get/test instead of PtrList::operator() access - clearer coding intent. Mark operator() as 'deprecated' - add bounds checking to get(label) and set(label) methods. This gives failsafe behaviour for get() that is symmetric with HashPtrTable, autoPtr etc and aligns the set(label) methods for UPtrList, PtrList and PtrDynList. - use top-level PtrList::clone() instead of cloning individual elements ENH: support HashPtrTable set with refPtr/tmp (flexibility) --- .../test/HashPtrTable/Test-HashPtrTable.C | 43 ++++++++++++- .../HashTables/HashPtrTable/HashPtrTable.H | 63 ++++++++++++------- .../HashTables/HashPtrTable/HashPtrTableI.H | 54 +++++++++------- .../containers/HashTables/HashSet/HashSet.H | 4 +- .../PtrLists/PtrDynList/PtrDynList.H | 51 +++++++-------- .../PtrLists/PtrDynList/PtrDynListI.H | 33 +++------- .../containers/PtrLists/PtrList/PtrList.H | 33 ++++++---- .../containers/PtrLists/PtrList/PtrListI.H | 32 +++------- .../containers/PtrLists/UPtrList/UPtrList.H | 21 ++++--- .../containers/PtrLists/UPtrList/UPtrListI.H | 48 +++++++------- .../coordinate/systems/coordinateSystems.C | 8 +-- .../fvMeshAdder/fvMeshAdderTemplates.C | 4 +- .../lduPrimitiveMeshAssemblyTemplates.C | 2 +- .../faFieldReconstructorTemplates.C | 12 ++-- .../fvFieldReconstructorTemplates.C | 12 ++-- .../pointFieldReconstructorTemplates.C | 5 +- .../liquidMixtureProperties.C | 11 +--- .../solidMixtureProperties.C | 10 +-- 18 files changed, 239 insertions(+), 207 deletions(-) diff --git a/applications/test/HashPtrTable/Test-HashPtrTable.C b/applications/test/HashPtrTable/Test-HashPtrTable.C index 31dfb62200..c7deadc2f9 100644 --- a/applications/test/HashPtrTable/Test-HashPtrTable.C +++ b/applications/test/HashPtrTable/Test-HashPtrTable.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,7 +31,10 @@ Description #include #include #include "autoPtr.H" -#include "HashPtrTable.H" +#include "refPtr.H" +#include "tmp.H" +#include "PtrMap.H" +#include "primitiveFields.H" using namespace Foam; @@ -250,6 +253,42 @@ int main() Info<< "Table: " << tbl << nl; } + { + PtrMap fields; + + { + const label patchi = 2; + + scalarField fld1(patchi, 5.0); + scalarField fld2(patchi, 8.0); + + // assign from tmp<> + fields.set( patchi, (fld1 * fld2)); + } + + { + const label patchi = 3; + + scalarField fld1(patchi, 6.0); + + // From tmp (clone) + fields.set(patchi, tmp(fld1)); + } + + { + const label patchi = 4; + + // From refPtr + fields.set(patchi, refPtr::New(patchi, 10.0)); + } + + Info<< nl + << "PtrMap:" << nl + << fields << endl; + } + + Info<< "\nEnd" << nl; + return 0; } diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H index 549b4df75e..f3eca79cc9 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -38,8 +38,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef HashPtrTable_H -#define HashPtrTable_H +#ifndef Foam_HashPtrTable_H +#define Foam_HashPtrTable_H #include "HashTable.H" #include @@ -50,8 +50,9 @@ namespace Foam { // Forward Declarations - template class autoPtr; +template class refPtr; +template class tmp; template class HashPtrTable; template @@ -123,8 +124,12 @@ public: // Access - //- Return const pointer associated with given entry, - //- returning a nullptr if the key does not exist in the table. + //- Return const pointer associated with given entry or a nullptr + //- if the key does not exist in the table. + inline const T* test(const Key& key) const; + + //- Return const pointer associated with given entry or a nullptr + //- if the key does not exist in the table. inline const T* get(const Key& key) const; @@ -211,31 +216,43 @@ public: inline bool insert(const Key&, T*) = delete; //- Insert a new entry, not overwriting existing entries. - // - // \return True if the entry inserted (not previously in table) - inline bool insert(const Key& key, autoPtr& ptr); - - //- Insert a new entry, not overwriting existing entries. - // - // \return True if the entry inserted (not previously in table) - inline bool insert(const Key& key, autoPtr&& ptr); - - //- Insert a new entry, not overwriting existing entries. - // // \return True if the entry inserted (not previously in table) inline bool insert(const Key& key, std::unique_ptr&& ptr); - //- Assign a new entry, overwriting existing entries. + //- Insert a new entry, not overwriting existing entries. + // \return True if the entry inserted (not previously in table) + inline bool insert(const Key& key, autoPtr&& ptr); + + //- Assign a new entry, overwrites existing inline bool set(const Key& key, T* ptr); - //- Assign a new entry, overwriting existing entries. - inline bool set(const Key& key, autoPtr& ptr); + //- Assign a new entry, overwrites existing + inline bool set(const Key& key, std::unique_ptr&& ptr); - //- Assign a new entry, overwriting existing entries. + //- Assign a new entry, overwrites existing inline bool set(const Key& key, autoPtr&& ptr); - //- Assign a new entry, overwriting existing entries. - inline bool set(const Key& key, std::unique_ptr&& ptr); + //- Assign a new entry from refPtr (move or clone), overwrites existing + inline bool set(const Key& key, const refPtr& ptr); + + //- Assign a new entry from tmp (move or clone), overwrites existing + inline bool set(const Key& key, const tmp& ptr); + + + // Housekeeping + + //- Insert a new entry, not overwriting existing entries. + // \return True if the entry inserted (not previously in table) + bool insert(const Key& key, autoPtr& ptr) + { + return this->insert(key, std::move(ptr)); + } + + //- Assign a new entry, overwrites existing + bool set(const Key& key, autoPtr& ptr) + { + return this->set(key, std::move(ptr)); + } }; diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableI.H b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableI.H index ee47d0108c..9213091085 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableI.H +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,6 +26,8 @@ License \*---------------------------------------------------------------------------*/ #include "autoPtr.H" +#include "refPtr.H" +#include "tmp.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -38,9 +40,23 @@ inline Foam::HashPtrTable::HashPtrTable(const label size) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +inline const T* Foam::HashPtrTable::test(const Key& key) const +{ + // Like lookup() with a nullptr + const const_iterator iter(this->cfind(key)); + if (iter.good()) + { + return iter.val(); + } + return nullptr; +} + + template inline const T* Foam::HashPtrTable::get(const Key& key) const { + // Like lookup() with a nullptr const const_iterator iter(this->cfind(key)); if (iter.good()) { @@ -83,7 +99,7 @@ template inline bool Foam::HashPtrTable::insert ( const Key& key, - autoPtr& ptr + std::unique_ptr&& ptr ) { if (parent_type::insert(key, ptr.get())) @@ -113,23 +129,6 @@ inline bool Foam::HashPtrTable::insert } -template -inline bool Foam::HashPtrTable::insert -( - const Key& key, - std::unique_ptr&& ptr -) -{ - if (parent_type::insert(key, ptr.get())) - { - ptr.release(); // Now owned by HashPtrTable - return true; - } - - return false; -} - - template inline bool Foam::HashPtrTable::set ( @@ -154,7 +153,7 @@ template inline bool Foam::HashPtrTable::set ( const Key& key, - autoPtr& ptr + std::unique_ptr&& ptr ) { return this->set(key, ptr.release()); @@ -176,10 +175,21 @@ template inline bool Foam::HashPtrTable::set ( const Key& key, - std::unique_ptr&& ptr + const refPtr& ptr ) { - return this->set(key, ptr.release()); + return this->set(key, ptr.ptr()); // release or clone +} + + +template +inline bool Foam::HashPtrTable::set +( + const Key& key, + const tmp& ptr +) +{ + return this->set(key, ptr.ptr()); // release or clone } diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H index 57cf7af96d..fc6ba60074 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H @@ -178,9 +178,9 @@ public: //- Same as found() - return true if key exists in the set. // Method name compatibility with bitSet and boolList. - bool test(const Key& key) const noexcept + bool test(const Key& key) const { - return found(key); + return this->found(key); } diff --git a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H index 955766be26..51c445f45b 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H +++ b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H @@ -100,24 +100,11 @@ public: // Member Functions - // Access + // Sizing //- Size of the underlying storage. inline label capacity() const noexcept; - //- Return const pointer to element (can be nullptr), - //- with bounds checking. - // The return value can be tested as a bool. - const T* get(const label i) const { return this->test(i); } - - //- Return const pointer to element (if set) or nullptr, - //- with bounds checking. - // The return value can be tested as a bool. - const T* set(const label i) const { return this->test(i); } - - - // Sizing - //- Reserve allocation space for at least this size. inline void reserve(const label len); @@ -164,14 +151,11 @@ public: inline void append(T* ptr); //- Move append an element to the end of the list - inline void append(autoPtr& ptr); + inline void append(std::unique_ptr&& ptr); //- Move append an element to the end of the list inline void append(autoPtr&& ptr); - //- Move append an element to the end of the list - inline void append(std::unique_ptr&& ptr); - //- Move or clone append a tmp to the end of the list inline void append(const refPtr& ptr); @@ -192,22 +176,24 @@ public: template inline autoPtr emplace(const label i, Args&&... args); - //- Set element to given pointer and return old element (can be null) + //- Set element to given pointer and return old element (can be null). + //- Auto-sizes list as required. inline autoPtr set(const label i, T* ptr); - //- Set element to given autoPtr and return old element - inline autoPtr set(const label i, autoPtr& ptr); - - //- Set element to given autoPtr and return old element - inline autoPtr set(const label i, autoPtr&& ptr); - //- Set element to given pointer and return old element + //- Auto-sizes list as required. inline autoPtr set(const label i, std::unique_ptr&& ptr); + //- Set element to given autoPtr and return old element + //- Auto-sizes list as required. + inline autoPtr set(const label i, autoPtr&& ptr); + //- Set element to given refPtr and return old element + //- Auto-sizes list as required. inline autoPtr set(const label i, const refPtr& ptr); //- Set element to given tmp and return old element + //- Auto-sizes list as required. inline autoPtr set(const label i, const tmp& ptr); //- Reorder elements. Reordering must be unique (ie, shuffle). @@ -235,6 +221,21 @@ public: //- Move assignment with different sizing parameters template inline void operator=(PtrDynList&& list); + + + // Housekeeping + + //- Move append an element to the end of the list + void append(autoPtr& ptr) + { + this->append(std::move(ptr)); + } + + //- Set element to given autoPtr and return old element + autoPtr set(const label i, autoPtr& ptr) + { + return this->set(i, std::move(ptr)); + } }; diff --git a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H index e5fc02a675..11d5c2034d 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H +++ b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -241,7 +241,7 @@ inline void Foam::PtrDynList::append(T* ptr) template -inline void Foam::PtrDynList::append(autoPtr& ptr) +inline void Foam::PtrDynList::append(std::unique_ptr&& ptr) { this->append(ptr.release()); } @@ -254,24 +254,17 @@ inline void Foam::PtrDynList::append(autoPtr&& ptr) } -template -inline void Foam::PtrDynList::append(std::unique_ptr&& ptr) -{ - this->append(ptr.release()); -} - - template inline void Foam::PtrDynList::append(const refPtr& ptr) { - this->append(ptr.ptr()); + this->append(ptr.ptr()); // release or clone } template inline void Foam::PtrDynList::append(const tmp& ptr) { - this->append(ptr.ptr()); + this->append(ptr.ptr()); // release or clone } @@ -375,7 +368,7 @@ template inline Foam::autoPtr Foam::PtrDynList::set ( const label i, - autoPtr& ptr + std::unique_ptr&& ptr ) { return this->set(i, ptr.release()); @@ -393,17 +386,6 @@ inline Foam::autoPtr Foam::PtrDynList::set } -template -inline Foam::autoPtr Foam::PtrDynList::set -( - const label i, - std::unique_ptr&& ptr -) -{ - return this->set(i, ptr.release()); -} - - template inline Foam::autoPtr Foam::PtrDynList::set ( @@ -411,7 +393,8 @@ inline Foam::autoPtr Foam::PtrDynList::set const refPtr& ptr ) { - return this->set(i, ptr.ptr()); + return this->set(i, ptr.ptr()); // release or clone + } @@ -422,7 +405,7 @@ inline Foam::autoPtr Foam::PtrDynList::set const tmp& ptr ) { - return this->set(i, ptr.ptr()); + return this->set(i, ptr.ptr()); // release or clone } diff --git a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H index ec59fb7a2b..8997c05b68 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H +++ b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H @@ -120,7 +120,7 @@ public: PtrList(Istream& is); - //- Destructor + //- Destructor. Frees all pointers ~PtrList(); @@ -134,9 +134,9 @@ public: // Access //- Return const pointer to element (can be nullptr), - //- without bounds checking - same as get(). + //- or nullptr for out-of-range access (ie, \em with bounds checking). // The return value can be tested as a bool. - const T* set(const label i) const { return this->get(i); } + const T* set(const label i) const { return UPtrList::set(i); } // Edit @@ -159,14 +159,11 @@ public: inline void append(T* ptr); //- Move append an element to the end of the list - inline void append(autoPtr& ptr); + inline void append(std::unique_ptr&& ptr); //- Move append an element to the end of the list inline void append(autoPtr&& ptr); - //- Move append an element to the end of the list - inline void append(std::unique_ptr&& ptr); - //- Move or clone append a refPtr to the end of the list inline void append(const refPtr& ptr); @@ -184,15 +181,12 @@ public: // No-op if the new pointer value is identical to the current content. inline autoPtr set(const label i, T* ptr); - //- Set element to given autoPtr and return old element - inline autoPtr set(const label i, autoPtr& ptr); + //- Set element to given unique_ptr and return old element + inline autoPtr set(const label i, std::unique_ptr&& ptr); //- Set element to given autoPtr and return old element inline autoPtr set(const label i, autoPtr&& ptr); - //- Set element to given unique_ptr and return old element - inline autoPtr set(const label i, std::unique_ptr&& ptr); - //- Set element to given refPtr and return old element inline autoPtr set(const label i, const refPtr& ptr); @@ -222,6 +216,21 @@ public: //- Read from Istream, discarding contents of existing list friend Istream& operator>> (Istream& is, PtrList& list); + + + // Housekeeping + + //- Move append an element to the end of the list + void append(autoPtr& ptr) + { + this->append(std::move(ptr)); + } + + //- Set element to given autoPtr and return old element + autoPtr set(const label i, autoPtr& ptr) + { + return this->set(i, std::move(ptr)); + } }; diff --git a/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H b/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H index ce80607dc5..fdfa4305d5 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H +++ b/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -117,7 +117,7 @@ inline void Foam::PtrList::append(T* ptr) template -inline void Foam::PtrList::append(autoPtr& ptr) +inline void Foam::PtrList::append(std::unique_ptr&& ptr) { UPtrList::append(ptr.release()); } @@ -130,24 +130,17 @@ inline void Foam::PtrList::append(autoPtr&& ptr) } -template -inline void Foam::PtrList::append(std::unique_ptr&& ptr) -{ - UPtrList::append(ptr.release()); -} - - template inline void Foam::PtrList::append(const refPtr& ptr) { - UPtrList::append(ptr.ptr()); + UPtrList::append(ptr.ptr()); // release or clone } template inline void Foam::PtrList::append(const tmp& ptr) { - UPtrList::append(ptr.ptr()); + UPtrList::append(ptr.ptr()); // release or clone } @@ -202,7 +195,7 @@ template inline Foam::autoPtr Foam::PtrList::set ( const label i, - autoPtr& ptr + std::unique_ptr&& ptr ) { return set(i, ptr.release()); @@ -220,17 +213,6 @@ inline Foam::autoPtr Foam::PtrList::set } -template -inline Foam::autoPtr Foam::PtrList::set -( - const label i, - std::unique_ptr&& ptr -) -{ - return set(i, ptr.release()); -} - - template inline Foam::autoPtr Foam::PtrList::set ( @@ -238,7 +220,7 @@ inline Foam::autoPtr Foam::PtrList::set const refPtr& ptr ) { - return set(i, ptr.ptr()); + return set(i, ptr.ptr()); // release or clone } @@ -249,7 +231,7 @@ inline Foam::autoPtr Foam::PtrList::set const tmp& ptr ) { - return set(i, ptr.ptr()); + return set(i, ptr.ptr()); // release or clone } diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H index 6caee41a85..c1d5d0d2df 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H @@ -234,19 +234,20 @@ public: // The return value can be tested as a bool. inline const T* test(const label i) const; + //- Return const pointer to element (can be nullptr), + //- or nullptr for out-of-range access (ie, \em with bounds checking). + // The return value can be tested as a bool. + inline const T* get(const label i) const; + //- Return pointer to element (can be nullptr), - //- \em without bounds checking. + //- or nullptr for out-of-range access (ie, \em with bounds checking). // The return value can be tested as a bool. inline T* get(const label i); //- Return const pointer to element (can be nullptr), - //- \em without bounds checking. - inline const T* get(const label i) const; - - //- Return const pointer to element (can be nullptr), - //- \em without bounds checking - same as get(). + //- or nullptr for out-of-range access (ie, \em with bounds checking). // The return value can be tested as a bool. - const T* set(const label i) const { return this->get(i); } + inline const T* set(const label i) const; // Edit @@ -307,8 +308,10 @@ public: //- Return reference to the element inline T& operator[](const label i); - //- Return const pointer to the element - same as get(). - inline const T* operator()(const label i) const; + //- Deprecated(2022-09) - same as get() + // \deprecated(2022-09) - use get(), set() or test() methods + FOAM_DEPRECATED_FOR(2022-09, "get(), set() or test() methods") + const T* operator()(const label i) const { return this->get(i); } //- Copy assignment (shallow copies addresses) inline void operator=(const UPtrList& list); diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H index b96f1371e9..ddb563e06c 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H @@ -124,16 +124,36 @@ inline const T* Foam::UPtrList::test(const label i) const template -inline T* Foam::UPtrList::get(const label i) +inline const T* Foam::UPtrList::get(const label i) const { - return ptrs_[i]; + return (i >= 0 && i < ptrs_.size()) ? ptrs_[i] : nullptr; } template -inline const T* Foam::UPtrList::get(const label i) const +inline T* Foam::UPtrList::get(const label i) { - return ptrs_[i]; + return (i >= 0 && i < ptrs_.size()) ? ptrs_[i] : nullptr; +} + + +template +inline const T* Foam::UPtrList::set(const label i) const +{ + return (i >= 0 && i < ptrs_.size()) ? ptrs_[i] : nullptr; +} + + +template +inline T* Foam::UPtrList::set(const label i, T* ptr) +{ + T* old = ptrs_[i]; + if (old == ptr) + { + return nullptr; // Content did not change + } + ptrs_[i] = ptr; + return old; } @@ -208,19 +228,6 @@ inline void Foam::UPtrList::append(UPtrList&& other) } -template -inline T* Foam::UPtrList::set(const label i, T* ptr) -{ - T* old = ptrs_[i]; - if (old == ptr) - { - return nullptr; // Content did not change - } - ptrs_[i] = ptr; - return old; -} - - template inline void Foam::UPtrList::checkNonNull() const { @@ -264,13 +271,6 @@ inline T& Foam::UPtrList::operator[](const label i) } -template -inline const T* Foam::UPtrList::operator()(const label i) const -{ - return ptrs_[i]; -} - - // * * * * * * * * * * * * * * * * iterator * * * * * * * * * * * * * * * * // template diff --git a/src/OpenFOAM/primitives/coordinate/systems/coordinateSystems.C b/src/OpenFOAM/primitives/coordinate/systems/coordinateSystems.C index 69cfa407ff..2188ae4d67 100644 --- a/src/OpenFOAM/primitives/coordinate/systems/coordinateSystems.C +++ b/src/OpenFOAM/primitives/coordinate/systems/coordinateSystems.C @@ -245,12 +245,8 @@ Foam::coordinateSystems::cfind(const word& name) const << name << '=' << index << endl; } - if (index < 0) - { - return nullptr; - } - - return this->operator()(index); + // Return nullptr if not found + return PtrList::test(index); } diff --git a/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C b/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C index 5f534e3d86..dd5d7b357e 100644 --- a/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C +++ b/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C @@ -193,7 +193,7 @@ void Foam::fvMeshAdder::MapVolField const polyPatch& oldPatch = fldToAdd.mesh().boundaryMesh()[patchi]; - if (!bfld(newPatchi)) + if (!bfld.set(newPatchi)) { // First occurrence of newPatchi. Map from existing // patchField @@ -503,7 +503,7 @@ void Foam::fvMeshAdder::MapSurfaceField const polyPatch& oldPatch = fldToAdd.mesh().boundaryMesh()[patchi]; - if (!bfld(newPatchi)) + if (!bfld.set(newPatchi)) { // First occurrence of newPatchi. Map from existing // patchField diff --git a/src/finiteVolume/lduPrimitiveMeshAssembly/lduPrimitiveMeshAssemblyTemplates.C b/src/finiteVolume/lduPrimitiveMeshAssembly/lduPrimitiveMeshAssemblyTemplates.C index 4f0666a0cd..18285466a1 100644 --- a/src/finiteVolume/lduPrimitiveMeshAssembly/lduPrimitiveMeshAssemblyTemplates.C +++ b/src/finiteVolume/lduPrimitiveMeshAssembly/lduPrimitiveMeshAssemblyTemplates.C @@ -314,7 +314,7 @@ void Foam::lduPrimitiveMeshAssembly::update interfaces().set ( globalPatchId, - interfacesLst(patchI) + interfacesLst.get(patchI) ); } } diff --git a/src/parallel/reconstruct/faReconstruct/faFieldReconstructorTemplates.C b/src/parallel/reconstruct/faReconstruct/faFieldReconstructorTemplates.C index 054d27f11c..d9cf4a297f 100644 --- a/src/parallel/reconstruct/faReconstruct/faFieldReconstructorTemplates.C +++ b/src/parallel/reconstruct/faReconstruct/faFieldReconstructorTemplates.C @@ -121,7 +121,7 @@ Foam::faFieldReconstructor::reconstructField { // Regular patch. Fast looping - if (!patchFields(curBPatch)) + if (!patchFields.set(curBPatch)) { patchFields.set ( @@ -195,7 +195,7 @@ Foam::faFieldReconstructor::reconstructField } } - if (!patchFields(curBPatch)) + if (!patchFields.set(curBPatch)) { patchFields.set ( @@ -230,7 +230,7 @@ Foam::faFieldReconstructor::reconstructField if ( isA(mesh_.boundary()[patchI]) - && !patchFields(patchI) + && !patchFields.set(patchI) ) { patchFields.set @@ -362,7 +362,7 @@ Foam::faFieldReconstructor::reconstructField { // Regular patch. Fast looping - if (!patchFields(curBPatch)) + if (!patchFields.set(curBPatch)) { patchFields.set ( @@ -439,7 +439,7 @@ Foam::faFieldReconstructor::reconstructField } } - if (!patchFields(curBPatch)) + if (!patchFields.set(curBPatch)) { patchFields.set ( @@ -481,7 +481,7 @@ Foam::faFieldReconstructor::reconstructField if ( isA(mesh_.boundary()[patchI]) - && !patchFields(patchI) + && !patchFields.set(patchI) ) { patchFields.set diff --git a/src/parallel/reconstruct/reconstruct/fvFieldReconstructorTemplates.C b/src/parallel/reconstruct/reconstruct/fvFieldReconstructorTemplates.C index 73bf6b21a7..060238bfde 100644 --- a/src/parallel/reconstruct/reconstruct/fvFieldReconstructorTemplates.C +++ b/src/parallel/reconstruct/reconstruct/fvFieldReconstructorTemplates.C @@ -116,7 +116,7 @@ Foam::fvFieldReconstructor::reconstructField { // Regular patch. Fast looping - if (!patchFields(curBPatch)) + if (!patchFields.set(curBPatch)) { patchFields.set ( @@ -184,7 +184,7 @@ Foam::fvFieldReconstructor::reconstructField { label curBPatch = mesh_.boundaryMesh().whichPatch(curF); - if (!patchFields(curBPatch)) + if (!patchFields.set(curBPatch)) { patchFields.set ( @@ -217,7 +217,7 @@ Foam::fvFieldReconstructor::reconstructField if ( isType(mesh_.boundary()[patchi]) - && !patchFields(patchi) + && !patchFields.set(patchi) ) { patchFields.set @@ -314,7 +314,7 @@ Foam::fvFieldReconstructor::reconstructField { // Regular patch. Fast looping - if (!patchFields(curBPatch)) + if (!patchFields.set(curBPatch)) { patchFields.set ( @@ -370,7 +370,7 @@ Foam::fvFieldReconstructor::reconstructField label curBPatch = mesh_.boundaryMesh().whichPatch(curF); - if (!patchFields(curBPatch)) + if (!patchFields.set(curBPatch)) { patchFields.set ( @@ -410,7 +410,7 @@ Foam::fvFieldReconstructor::reconstructField if ( isType(mesh_.boundary()[patchi]) - && !patchFields(patchi) + && !patchFields.set(patchi) ) { patchFields.set diff --git a/src/parallel/reconstruct/reconstruct/pointFieldReconstructorTemplates.C b/src/parallel/reconstruct/reconstruct/pointFieldReconstructorTemplates.C index ea1abc54fd..01e26fe6c7 100644 --- a/src/parallel/reconstruct/reconstruct/pointFieldReconstructorTemplates.C +++ b/src/parallel/reconstruct/reconstruct/pointFieldReconstructorTemplates.C @@ -70,9 +70,10 @@ Foam::pointFieldReconstructor::reconstructField // check if the boundary patch is not a processor patch if (curBPatch >= 0) { - if (!patchFields(curBPatch)) + if (!patchFields.set(curBPatch)) { - patchFields.set( + patchFields.set + ( curBPatch, pointPatchField::New ( diff --git a/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquidMixtureProperties/liquidMixtureProperties.C b/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquidMixtureProperties/liquidMixtureProperties.C index 8dca2cfc2f..51952aeab5 100644 --- a/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquidMixtureProperties/liquidMixtureProperties.C +++ b/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquidMixtureProperties/liquidMixtureProperties.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,13 +76,8 @@ Foam::liquidMixtureProperties::liquidMixtureProperties ) : components_(lm.components_), - properties_(lm.properties_.size()) -{ - forAll(properties_, i) - { - properties_.set(i, lm.properties_(i)->clone()); - } -} + properties_(lm.properties_.clone()) +{} // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // diff --git a/src/thermophysicalModels/thermophysicalProperties/solidProperties/solidMixtureProperties/solidMixtureProperties.C b/src/thermophysicalModels/thermophysicalProperties/solidProperties/solidMixtureProperties/solidMixtureProperties.C index 4f3ba23191..b8d5e06675 100644 --- a/src/thermophysicalModels/thermophysicalProperties/solidProperties/solidMixtureProperties/solidMixtureProperties.C +++ b/src/thermophysicalModels/thermophysicalProperties/solidProperties/solidMixtureProperties/solidMixtureProperties.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,13 +66,8 @@ Foam::solidMixtureProperties::solidMixtureProperties ) : components_(s.components_), - properties_(s.properties_.size()) -{ - forAll(properties_, i) - { - properties_.set(i, s.properties_(i)->clone()); - } -} + properties_(s.properties_.clone()) +{} // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //