From 95e2a2e887d46ab15bdd9d42d932d5518271f82b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 16 May 2022 14:15:13 +0200 Subject: [PATCH] ENH: add sorted() to objectRegistry and IOobjectList - returns UPtrList view (read-only or read/write) of the objects - shorter names for IOobject checks: hasHeaderClass(), isHeaderClass() - remove unused IOobject::isHeaderClassName(const word&) method. The typed versions are preferable/recommended, but can still check directly if needed: (io.headerClassName() == "foo") --- .../test/IOobjectList/Test-IOobjectList.C | 45 ++++- .../test/objectRegistry/Test-objectRegistry.C | 45 +++-- .../objectRegistry2/Test-objectRegistry2.C | 48 +++-- .../setExprBoundaryFields/readFields.H | 2 +- .../preProcessing/setExprFields/readFields.H | 2 +- .../HashTables/HashTable/HashTable.C | 26 ++- .../HashTables/HashTable/HashTable.H | 7 + src/OpenFOAM/db/IOobject/IOobject.H | 32 +-- src/OpenFOAM/db/IOobject/IOobjectI.H | 10 +- src/OpenFOAM/db/IOobject/IOobjectIO.C | 7 +- src/OpenFOAM/db/IOobjectList/IOobjectList.C | 90 ++++++--- src/OpenFOAM/db/IOobjectList/IOobjectList.H | 187 ++++++++++++------ .../db/IOobjectList/IOobjectListTemplates.C | 133 ++++++++++--- .../db/objectRegistry/objectRegistry.C | 42 +++- .../db/objectRegistry/objectRegistry.H | 76 ++++++- .../objectRegistry/objectRegistryTemplates.C | 120 ++++++++++- src/OpenFOAM/meshes/polyMesh/polyMesh.C | 2 +- src/OpenFOAM/meshes/polyMesh/polyMeshIO.C | 2 +- src/OpenFOAM/primitives/strings/word/word.H | 18 +- .../field/expressions/fvExpressionField.C | 2 +- .../field/readFields/readFields.C | 2 +- 21 files changed, 690 insertions(+), 208 deletions(-) diff --git a/applications/test/IOobjectList/Test-IOobjectList.C b/applications/test/IOobjectList/Test-IOobjectList.C index e9ff98af96..dc46bc710b 100644 --- a/applications/test/IOobjectList/Test-IOobjectList.C +++ b/applications/test/IOobjectList/Test-IOobjectList.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,6 +39,38 @@ Description using namespace Foam; + +void report(const UPtrList& objects) +{ + Info<< "name/type:" << nl + << objects.size() << nl << '(' << nl; + + for (const IOobject& io : objects) + { + Info<< " " << io.name() << " : " << io.headerClassName() << nl; + } + + Info<< ')' << nl << endl; +} + + +template +void report(const UPtrList& objects) +{ + Info<< "name/type:" << nl + << objects.size() << nl << '(' << nl; + + for (const IOobject& io : objects) + { + Info<< " " << io.name() << " : " << io.headerClassName() + << (io.isHeaderClass() ? " is " : " is not ") + << Type::typeName << nl; + } + + Info<< ')' << nl << endl; +} + + void report(const IOobjectList& objects) { Info<< "Names: " << flatOutput(objects.sortedNames()) << nl @@ -199,7 +231,7 @@ void registryTests(const IOobjectList& objs) int main(int argc, char *argv[]) { - argList::noParallel(); + // argList::noParallel(); argList::addOption ( "filter", @@ -269,6 +301,15 @@ int main(int argc, char *argv[]) Info<< "Time: " << runTime.timeName() << nl; report(objects); + report(objects.sorted()); + + report(objects.sorted()); + report(objects.sorted()); + + // Extra checks + report(objects.sorted()); + report(objects.sorted()); + findObjectTest(objects); diff --git a/applications/test/objectRegistry/Test-objectRegistry.C b/applications/test/objectRegistry/Test-objectRegistry.C index 5c3078b2d9..76c3f4a1c5 100644 --- a/applications/test/objectRegistry/Test-objectRegistry.C +++ b/applications/test/objectRegistry/Test-objectRegistry.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,6 +37,7 @@ Description #include "polyMesh.H" #include "IOstreams.H" #include "FlatOutput.H" +#include "PtrListOps.H" #include "objectRegistry.H" using namespace Foam; @@ -47,6 +48,21 @@ using namespace Foam; bool recursive = false; +template +void report(const UPtrList& objects) +{ + Info<< Type::typeName << " name/type:" << nl + << objects.size() << nl << '(' << nl; + + for (const Type& obj : objects) + { + Info<< " " << obj.name() << " : " << obj.type() << nl; + } + + Info<< ')' << nl << endl; +} + + void printRegistry ( Foam::Ostream& os, @@ -62,8 +78,8 @@ void printRegistry Foam::label indent ) { - wordList names(obr.sortedNames()); - wordList regs(obr.sortedNames()); + UPtrList objects(obr.sorted()); + wordList regNames(obr.sortedNames()); std::string prefix; for (label i=indent; i; --i) @@ -74,15 +90,17 @@ void printRegistry os << '#' << prefix.c_str() << obr.name() << " parent:" << obr.parent().name() << nl; - os << ' ' << prefix.c_str() << "objects: " << flatOutput(names) << nl; - os << ' ' << prefix.c_str() << "registries: " << flatOutput(regs) << nl; + os << ' ' << prefix.c_str() << "objects: " + << flatOutput(PtrListOps::names(objects)) << nl; + os << ' ' << prefix.c_str() << "registries: " + << flatOutput(regNames) << nl; - // Print, but skip expansion of sub-registries for now - for (const word& name : names) + // Print without expanding sub-registries + for (const regIOobject& obj : objects) { - os << (regs.found(name) ? '-' : ' ') - << prefix.c_str() << name << " => " << obr[name]->type() << nl; + os << (isA(obj) ? '-' : ' ') + << prefix.c_str() << obj.name() << " => " << obj.type() << nl; } for (label i=indent; i; --i) { @@ -91,7 +109,7 @@ void printRegistry os << '\n'; // Now descend into the sub-registries - for (const word& name : regs) + for (const word& name : regNames) { const objectRegistry& next = obr.lookupObject ( @@ -117,12 +135,15 @@ void printRegistry } } -// Main program: + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Main program: int main(int argc, char *argv[]) { argList::noBanner(); - argList::noParallel(); + // argList::noParallel(); argList::addBoolOption ( "mesh", diff --git a/applications/test/objectRegistry2/Test-objectRegistry2.C b/applications/test/objectRegistry2/Test-objectRegistry2.C index 04028650f0..80780f6b99 100644 --- a/applications/test/objectRegistry2/Test-objectRegistry2.C +++ b/applications/test/objectRegistry2/Test-objectRegistry2.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,10 +36,12 @@ Description #include "fvCFD.H" #include "fvMesh.H" #include "volFields.H" -#include "IOobjectList.H" #include "timeSelector.H" #include "ReadFields.H" #include "IOstreams.H" +#include "PtrListOps.H" +#include "IOobjectList.H" +#include "objectRegistry.H" using namespace Foam; @@ -113,6 +115,21 @@ void loadFields(fvMesh& mesh, const IOobjectList& objects) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +template +void report(const UPtrList& objects) +{ + Info<< Type::typeName << " name/type:" << nl + << objects.size() << nl << '(' << nl; + + for (const Type& obj : objects) + { + Info<< " " << obj.name() << " : " << obj.type() << nl; + } + + Info<< ')' << nl << endl; +} + + void printRegistry ( Foam::Ostream& os, @@ -128,8 +145,8 @@ void printRegistry Foam::label indent ) { - wordList names(obr.sortedNames()); - wordList regs(obr.sortedNames()); + UPtrList objects(obr.sorted()); + wordList regNames(obr.sortedNames()); std::string prefix; for (label i=indent; i; --i) @@ -140,15 +157,17 @@ void printRegistry os << '#' << prefix.c_str() << obr.name() << " parent:" << obr.parent().name() << nl; - os << ' ' << prefix.c_str() << "objects: " << flatOutput(names) << nl; - os << ' ' << prefix.c_str() << "registries: " << flatOutput(regs) << nl; + os << ' ' << prefix.c_str() << "objects: " + << flatOutput(PtrListOps::names(objects)) << nl; + os << ' ' << prefix.c_str() << "registries: " + << flatOutput(regNames) << nl; - // Print, but skip expansion of sub-registries for now - for (const word& name : names) + // Print without expanding sub-registries + for (const regIOobject& obj : objects) { - os << (regs.found(name) ? '-' : ' ') - << prefix.c_str() << name << " => " << obr[name]->type() << nl; + os << (isA(obj) ? '-' : ' ') + << prefix.c_str() << obj.name() << " => " << obj.type() << nl; } for (label i=indent; i; --i) { @@ -157,7 +176,7 @@ void printRegistry os << '\n'; // Now descend into the sub-registries - for (const word& name : regs) + for (const word& name : regNames) { const objectRegistry& next = obr.lookupObject ( @@ -251,12 +270,12 @@ void registryTests(const objectRegistry& obr) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Main program: +// Main program: int main(int argc, char *argv[]) { argList::noBanner(); - argList::noParallel(); + //argList::noParallel(); // argList::addOption // ( // "filter", @@ -296,6 +315,9 @@ int main(int argc, char *argv[]) registryTests(mesh); + report(mesh.sorted()); + report(mesh.csorted()); + Info<< nl; } diff --git a/applications/utilities/preProcessing/setExprBoundaryFields/readFields.H b/applications/utilities/preProcessing/setExprBoundaryFields/readFields.H index 4873ff0dda..c03ed68b3d 100644 --- a/applications/utilities/preProcessing/setExprBoundaryFields/readFields.H +++ b/applications/utilities/preProcessing/setExprBoundaryFields/readFields.H @@ -129,7 +129,7 @@ class readFieldsHandler const bool ok = ( io.typeHeaderOk(false) // Preload header info - && io.hasHeaderClassName() // Extra safety + && io.hasHeaderClass() // Extra safety && ( loadField(io) diff --git a/applications/utilities/preProcessing/setExprFields/readFields.H b/applications/utilities/preProcessing/setExprFields/readFields.H index 4fb47d6608..f9330af132 100644 --- a/applications/utilities/preProcessing/setExprFields/readFields.H +++ b/applications/utilities/preProcessing/setExprFields/readFields.H @@ -129,7 +129,7 @@ class readFieldsHandler const bool ok = ( io.typeHeaderOk(false) // Preload header info - && io.hasHeaderClassName() // Extra safety + && io.hasHeaderClass() // Extra safety && ( loadField(io) diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C index fac18c0c67..ef58ea00ca 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C @@ -159,20 +159,28 @@ Foam::List Foam::HashTable::sortedToc template Foam::UPtrList::node_type> -Foam::HashTable::sorted() const +Foam::HashTable::csorted() const { - UPtrList list(size_); + UPtrList result(size_); label count = 0; for (const_iterator iter = cbegin(); iter != cend(); ++iter) { - list.set(count++, iter.node()); + result.set(count++, iter.node()); } - Foam::sort(list); + Foam::sort(result); - return list; + return result; +} + + +template +Foam::UPtrList::node_type> +Foam::HashTable::sorted() const +{ + return csorted(); } @@ -180,18 +188,18 @@ template Foam::UPtrList::node_type> Foam::HashTable::sorted() { - UPtrList list(size_); + UPtrList result(size_); label count = 0; for (iterator iter = begin(); iter != end(); ++iter) { - list.set(count++, iter.node()); + result.set(count++, iter.node()); } - Foam::sort(list); + Foam::sort(result); - return list; + return result; } diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index cbcdd84179..337effa745 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -346,10 +346,17 @@ public: //- Const access to the hash-table contents in sorted order //- (sorted by keys). + // The lifetime of the returned content cannot exceed the parent! + UPtrList csorted() const; + + //- Const access to the hash-table contents in sorted order + //- (sorted by keys). + // The lifetime of the returned content cannot exceed the parent! UPtrList sorted() const; //- Non-const access to the hash-table contents in sorted order //- (sorted by keys). + // The lifetime of the returned content cannot exceed the parent! UPtrList sorted(); diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index bd90938a0f..947fe64ea9 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -125,13 +125,6 @@ public: // Public Data Types - //- Enumeration defining the valid states of an IOobject - enum objectState : char - { - GOOD, - BAD - }; - //- Enumeration defining the read options enum readOption : char { @@ -148,6 +141,13 @@ public: AUTO_WRITE = 0x10 }; + //- Enumeration defining the valid states of an IOobject + enum objectState : char + { + GOOD, + BAD + }; + //- Enumeration defining the file checking options enum fileCheckTypes : char { @@ -474,14 +474,15 @@ public: // Checks //- True if headerClassName() is non-empty (after reading) - inline bool hasHeaderClassName() const noexcept; + inline bool hasHeaderClass() const noexcept; - //- Test if headerClassName() equals the given class name - inline bool isHeaderClassName(const word& clsName) const; - - //- Test if headerClassName() equals Type::typeName + //- Check if headerClassName() equals Type::typeName template - inline bool isHeaderClassName() const; + inline bool isHeaderClass() const; + + //- Same as isHeaderClass() + template + bool isHeaderClassName() const { return isHeaderClass(); } // Meta-data @@ -638,8 +639,7 @@ public: // Info - //- Return info proxy. - // Used to print token information to a stream + //- Return info proxy, for printing information to a stream InfoProxy info() const { return *this; @@ -674,7 +674,7 @@ public: //- Specialization for \c void always returns true (no headerClassName check). template<> -inline bool IOobject::isHeaderClassName() const +inline bool IOobject::isHeaderClass() const { return true; } diff --git a/src/OpenFOAM/db/IOobject/IOobjectI.H b/src/OpenFOAM/db/IOobject/IOobjectI.H index ab0a0d725b..8c081bf7b1 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectI.H +++ b/src/OpenFOAM/db/IOobject/IOobjectI.H @@ -146,20 +146,14 @@ inline unsigned Foam::IOobject::scalarByteSize() const noexcept // Checks -inline bool Foam::IOobject::hasHeaderClassName() const noexcept +inline bool Foam::IOobject::hasHeaderClass() const noexcept { return !headerClassName_.empty(); } -inline bool Foam::IOobject::isHeaderClassName(const word& clsName) const -{ - return (clsName == headerClassName_); -} - - template -inline bool Foam::IOobject::isHeaderClassName() const +inline bool Foam::IOobject::isHeaderClass() const { return (Type::typeName == headerClassName_); } diff --git a/src/OpenFOAM/db/IOobject/IOobjectIO.C b/src/OpenFOAM/db/IOobject/IOobjectIO.C index faff9f8f4a..2a190537eb 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectIO.C +++ b/src/OpenFOAM/db/IOobject/IOobjectIO.C @@ -26,7 +26,7 @@ License \*---------------------------------------------------------------------------*/ #include "IOobject.H" -#include "token.H" +#include "Ostream.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -36,14 +36,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy& ip) const IOobject& io = ip.t_; os << "IOobject: " - << io.type() << token::SPACE - << io.name() + << io.type() << ' ' << io.name() << " local: " << io.local() << " readOpt: " << static_cast(io.readOpt()) << " writeOpt: " << static_cast(io.writeOpt()) << " registerObject: " << io.registerObject() << " globalObject: " << io.globalObject() - << token::SPACE << io.path() << endl; + << ' ' << io.path() << endl; return os; } diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.C b/src/OpenFOAM/db/IOobjectList/IOobjectList.C index e42d8125dc..b3a5963981 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.C +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,31 +34,54 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -bool Foam::IOobjectList::checkNames(wordList& masterNames, const bool syncPar) +void Foam::IOobjectList::checkObjectOrder +( + const UPtrList& objs, + bool syncPar +) { - // Sort for consistent order on all processors. - // Even do this for serial runs, for consistent behaviour - Foam::sort(masterNames); - if (syncPar && Pstream::parRun()) { - const wordList localNames(masterNames); + wordList objectNames(objs.size()); + + auto iter = objectNames.begin(); + + for (const IOobject& io : objs) + { + *iter = io.name(); // nameOp() + ++iter; + } + + checkNameOrder(objectNames, syncPar); + } +} + + +void Foam::IOobjectList::checkNameOrder +( + const wordList& objectNames, + bool syncPar +) +{ + if (syncPar && Pstream::parRun()) + { + wordList masterNames; + if (Pstream::master()) + { + masterNames = objectNames; + } Pstream::broadcast(masterNames); - if (localNames != masterNames) + if (objectNames != masterNames) { FatalErrorInFunction << "Objects not synchronised across processors." << nl << "Master has " << flatOutput(masterNames) << nl << "Processor " << Pstream::myProcNo() - << " has " << flatOutput(localNames) + << " has " << flatOutput(objectNames) << endl << exit(FatalError); - - return false; } } - - return true; } @@ -71,7 +94,7 @@ void Foam::IOobjectList::syncNames(wordList& objNames) Pstream::broadcast(objNames); } - // Sort for consistent order on all processors + // Consistent order on all processors Foam::sort(objNames); } @@ -196,7 +219,7 @@ Foam::label Foam::IOobjectList::append(const IOobjectList& other) InfoInFunction << "Copy append " << iter.key() << nl; } - set(iter.key(), new IOobject(*(iter.val()))); + set(iter.key(), new IOobject(*iter.val())); ++count; } } @@ -307,6 +330,24 @@ Foam::label Foam::IOobjectList::count(const char* clsName) const } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Foam::UPtrList +Foam::IOobjectList::sorted() const +{ + return sorted(); +} + + +Foam::UPtrList +Foam::IOobjectList::sorted(const bool syncPar) const +{ + return sorted(syncPar); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + Foam::wordList Foam::IOobjectList::names() const { return HashPtrTable::toc(); @@ -315,10 +356,7 @@ Foam::wordList Foam::IOobjectList::names() const Foam::wordList Foam::IOobjectList::names(const bool syncPar) const { - wordList objNames(HashPtrTable::toc()); - - checkNames(objNames, syncPar); - return objNames; + return sortedNames(syncPar); } @@ -336,7 +374,7 @@ Foam::wordList Foam::IOobjectList::names ) const { // No nullptr check - only called with string literals - return names(static_cast(clsName), syncPar); + return sortedNames(static_cast(clsName), syncPar); } @@ -352,7 +390,7 @@ Foam::wordList Foam::IOobjectList::sortedNames(const bool syncPar) const { wordList objNames(HashPtrTable::sortedToc()); - checkNames(objNames, syncPar); + checkNameOrder(objNames, syncPar); return objNames; } @@ -371,7 +409,7 @@ Foam::wordList Foam::IOobjectList::sortedNames ) const { // No nullptr check - only called with string literals - return names(static_cast(clsName), syncPar); + return sortedNames(static_cast(clsName), syncPar); } @@ -397,16 +435,14 @@ Foam::wordList Foam::IOobjectList::allNames() const } -bool Foam::IOobjectList::checkNames(const bool syncPar) const +void Foam::IOobjectList::checkNames(const bool syncPar) const { if (syncPar && Pstream::parRun()) { - wordList objNames(HashPtrTable::toc()); + wordList objNames(HashPtrTable::sortedToc()); - return checkNames(objNames, syncPar); + checkNameOrder(objNames, syncPar); } - - return true; } diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.H b/src/OpenFOAM/db/IOobjectList/IOobjectList.H index 139e6ed0b9..4d366cd03b 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.H +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,11 +36,12 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef IOobjectList_H -#define IOobjectList_H +#ifndef Foam_IOobjectList_H +#define Foam_IOobjectList_H #include "HashPtrTable.H" #include "HashSet.H" +#include "UPtrList.H" #include "IOobject.H" #include "wordRes.H" @@ -59,14 +60,23 @@ class IOobjectList { // Private Member Functions - //- Check name consistency on all processors + //- Check consistency of names and their order on all processors + //- (the input list is assumed to be pre-sorted). // - // With syncPar = true, check that object names are the same on - // all processors. Trigger FatalError if not. + // With syncPar = true, check that object names are identical + // (content and order) on all processors. FatalError if not. + static void checkNameOrder(const wordList& objectNames, bool syncPar); + + //- Check consistency of object names/order on all processors + //- (the input list is assumed to be pre-sorted). // - // When syncPar is used, the object names are sorted as a side-effect, - // since this is required for consistent ordering across processors. - static bool checkNames(wordList& masterNames, const bool syncPar); + // With syncPar = true, check that object names are identical + // (content and order) on all processors. FatalError if not. + static void checkObjectOrder + ( + const UPtrList& objs, + bool syncPar + ); //- Combine names from all processors and sort static void syncNames(wordList& objNames); @@ -116,6 +126,14 @@ class IOobjectList const bool doSort ); + //- Templated implementation for sorted() + template + static UPtrList objectsTypeImpl + ( + const IOobjectList& list, + const MatchPredicate& matchName + ); + //- Templated implementation for lookup() template static IOobjectList lookupImpl @@ -383,6 +401,54 @@ public: HashTable classes(const MatchPredicate& matchName) const; + // Sorted access + + //- The sorted list of IOobjects + // The lifetime of the returned content cannot exceed the parent! + UPtrList sorted() const; + + //- The sorted list of IOobjects with optional check for + //- parallel consistency. + // FatalError if syncPar = true and names are not consistent on all + // processors. + // The lifetime of the returned content cannot exceed the parent! + UPtrList sorted(const bool syncPar) const; + + //- The sorted list of IOobjects with headerClassName == Type::typeName + // + // \note If \a Type is \c void, no headerClassName check is used + // (always true). + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList sorted() const; + + //- The sorted names of the IOobjects with optional check for + //- parallel consistency. + // FatalError if syncPar = true and names are not consistent on all + // processors. + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList sorted(const bool syncPar) const; + + //- The sorted list of IOobjects with headerClassName == Type::typeName + //- that also have a matching object name. + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList sorted(const MatchPredicate& matchName) const; + + //- The sorted list of IOobjects with headerClassName == Type::typeName + //- that also have a matching object name. + // FatalError if syncPar = true and names are not consistent on all + // processors. + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList sorted + ( + const MatchPredicate& matchName, + const bool syncPar + ) const; + + // Number of items //- The number of objects of the given headerClassName @@ -420,29 +486,36 @@ public: // Summary of names - //- The names of the IOobjects + //- The unsorted names of the IOobjects wordList names() const; - //- The names of the IOobjects. - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + //- The sorted names of the IOobjects with optional check for + //- parallel consistency. + // FatalError if syncPar = true and names are not consistent on all + // processors. + // \note Output is always sorted - for consistent serial/parallel + // behaviour. wordList names(const bool syncPar) const; - //- The names of IOobjects with the given headerClassName + //- The unsorted names of IOobjects with the given headerClassName wordList names(const char* clsName) const; - //- The names of the IOobjects with the given headerClassName - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + //- The sorted names of the IOobjects with the given headerClassName + // FatalError if syncPar = true and names are not consistent on all + // processors. + // \note Output is always sorted - for consistent serial/parallel + // behaviour. wordList names(const char* clsName, const bool syncPar) const; - //- The names of IOobjects with the given headerClassName + //- The unsorted names of IOobjects with the given headerClassName template wordList names(const MatchPredicate& matchClass) const; - //- The names of the IOobjects with the given headerClassName - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + //- The sorted names of the IOobjects with the given headerClassName + // FatalError if syncPar = true and names are not consistent on all + // processors. + // \note Output is always sorted - for consistent serial/parallel + // behaviour. template wordList names ( @@ -450,7 +523,7 @@ public: const bool syncPar ) const; - //- The names of IOobjects with the given headerClassName + //- The unsorted names of IOobjects with the given headerClassName //- that also have a matching object name. template wordList names @@ -459,10 +532,12 @@ public: const MatchPredicate2& matchName ) const; - //- The names of the IOobjects with the given headerClassName + //- The sorted names of the IOobjects with the given headerClassName //- that also have a matching object name. - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + // FatalError if syncPar = true and names are not consistent on all + // processors. + // \note Output is always sorted - for consistent serial/parallel + // behaviour. template wordList names ( @@ -472,27 +547,31 @@ public: ) const; - //- The names of objects with headerClassName == Type::typeName + //- The unsorted names of objects with + //- headerClassName == Type::typeName template wordList names() const; - //- The names of objects with headerClassName == Type::typeName - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + //- The sorted names of objects with + //- headerClassName == Type::typeName. + // FatalError if syncPar = true and names are not consistent on all + // processors. + // \note Output is always sorted - for consistent serial/parallel + // behaviour. template wordList names(bool syncPar) const; - //- The names of objects with headerClassName == Type::typeName - //- that also have a matching object name. - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + //- The unsorted names of objects with + //- headerClassName == Type::typeName and a matching object name. template wordList names(const MatchPredicate& matchName) const; - //- The names of objects with headerClassName == Type::typeName - //- that also have a matching object name. - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + //- The sorted names of objects with + //- headerClassName == Type::typeName and a matching object name. + // FatalError if syncPar = true and names are not consistent on all + // processors. + // \note Output is always sorted - for consistent serial/parallel + // behaviour. template wordList names ( @@ -506,17 +585,18 @@ public: //- The sorted names of the IOobjects wordList sortedNames() const; - //- The sorted names of the IOobjects. - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + //- The sorted names of the IOobjects with optional check for + //- parallel consistency. + // FatalError if syncPar = true and names are not consistent on all + // processors. wordList sortedNames(const bool syncPar) const; //- The sorted names of IOobjects with the given headerClassName wordList sortedNames(const char* clsName) const; //- The sorted names of the IOobjects with the given headerClassName - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + // FatalError if syncPar = true and names are not consistent on all + // processors. wordList sortedNames(const char* clsName, const bool syncPar) const; //- The sorted names of IOobjects with the given headerClassName @@ -524,8 +604,8 @@ public: wordList sortedNames(const MatchPredicate& matchClass) const; //- The sorted names of the IOobjects with the given headerClassName - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + // FatalError if syncPar = true and names are not consistent on all + // processors. template wordList sortedNames ( @@ -544,8 +624,8 @@ public: //- The sorted names of the IOobjects with the given headerClassName //- that also have a matching object name. - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + // FatalError if syncPar = true and names are not consistent on all + // processors. template wordList sortedNames ( @@ -560,22 +640,20 @@ public: wordList sortedNames() const; //- The sorted names of objects with headerClassName == Type::typeName - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + // FatalError if syncPar = true and names are not consistent on all + // processors. template wordList sortedNames(bool syncPar) const; //- The sorted names of objects with headerClassName == Type::typeName //- that also have a matching object name. - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. template wordList sortedNames(const MatchPredicate& matchName) const; //- The sorted names of objects with headerClassName == Type::typeName //- that also have a matching object name. - // With syncPar = true, sorts the names and triggers FatalError - // if the names are not consistent on all processors. + // FatalError if syncPar = true and names are not consistent on all + // processors. template wordList sortedNames ( @@ -620,9 +698,8 @@ public: wordList allNames() const; //- Verify that object names are synchronised across processors - // Triggers FatalError if the names are not consistent on all - // processors. - bool checkNames(const bool syncPar = true) const; + // FatalError if the names are not consistent on all processors. + void checkNames(const bool syncPar = true) const; // Member Operators diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C b/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C index 6767639730..87c807ba65 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C +++ b/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -96,7 +96,7 @@ Foam::label Foam::IOobjectList::countTypeImpl { const IOobject* io = iter.val(); - if (io->isHeaderClassName() && matchName(io->name())) + if (io->isHeaderClass() && matchName(io->name())) { ++count; } @@ -159,7 +159,7 @@ Foam::wordList Foam::IOobjectList::namesTypeImpl const word& key = iter.key(); const IOobject* io = iter.val(); - if (io->isHeaderClassName() && matchName(key)) + if (io->isHeaderClass() && matchName(key)) { objNames[count] = key; ++count; @@ -177,6 +177,38 @@ Foam::wordList Foam::IOobjectList::namesTypeImpl } +// Templated implementation for sorted() +template +Foam::UPtrList +Foam::IOobjectList::objectsTypeImpl +( + const IOobjectList& list, + const MatchPredicate& matchName +) +{ + UPtrList result(list.size()); + + label count = 0; + forAllConstIters(list, iter) + { + const word& key = iter.key(); + const IOobject* io = iter.val(); + + if (io->isHeaderClass() && matchName(key)) + { + result.set(count, io); + ++count; + } + } + + result.resize(count); + + Foam::sort(result, nameOp()); // Sort by object name() + + return result; +} + + // Templated implementation for lookup() template Foam::IOobjectList Foam::IOobjectList::lookupImpl @@ -253,7 +285,7 @@ Foam::IOobjectList Foam::IOobjectList::lookupClassTypeImpl const word& key = iter.key(); const IOobject* io = iter.val(); - if (io->isHeaderClassName() && matchName(key)) + if (io->isHeaderClass() && matchName(key)) { if (IOobject::debug) { @@ -282,7 +314,7 @@ const Foam::IOobject* Foam::IOobjectList::cfindObject { const IOobject* io = iter.val(); - if (io->isHeaderClassName()) + if (io->isHeaderClass()) { if (IOobject::debug) { @@ -427,6 +459,62 @@ Foam::label Foam::IOobjectList::count } + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +Foam::UPtrList +Foam::IOobjectList::sorted() const +{ + return objectsTypeImpl(*this, predicates::always()); +} + + +template +Foam::UPtrList +Foam::IOobjectList::sorted(const bool syncPar) const +{ + UPtrList list + ( + objectsTypeImpl(*this, predicates::always()) + ); + + checkObjectOrder(list, syncPar); + + return list; +} + + +template +Foam::UPtrList +Foam::IOobjectList::sorted +( + const MatchPredicate& matchName +) const +{ + return objectsTypeImpl(*this, matchName); +} + + +template +Foam::UPtrList +Foam::IOobjectList::sorted +( + const MatchPredicate& matchName, + const bool syncPar +) const +{ + UPtrList list + ( + objectsTypeImpl(*this, matchName) + ); + + checkObjectOrder(list, syncPar); + + return list; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template @@ -446,13 +534,7 @@ Foam::wordList Foam::IOobjectList::names const bool syncPar ) const { - wordList objNames - ( - namesImpl(*this, matchClass, predicates::always(), false) - ); - - checkNames(objNames, syncPar); - return objNames; + return sortedNames(matchClass, syncPar); } @@ -475,10 +557,7 @@ Foam::wordList Foam::IOobjectList::names const bool syncPar ) const { - wordList objNames(namesImpl(*this, matchClass, matchName, false)); - - checkNames(objNames, syncPar); - return objNames; + return sortedNames(matchClass, matchName, syncPar); } @@ -492,10 +571,7 @@ Foam::wordList Foam::IOobjectList::names() const template Foam::wordList Foam::IOobjectList::names(const bool syncPar) const { - wordList objNames(namesTypeImpl(*this, predicates::always(), false)); - - checkNames(objNames, syncPar); - return objNames; + return sortedNames(syncPar); } @@ -516,10 +592,7 @@ Foam::wordList Foam::IOobjectList::names const bool syncPar ) const { - wordList objNames(namesTypeImpl(*this, matchName, false)); - - checkNames(objNames, syncPar); - return objNames; + return sortedNames(matchName, syncPar); } @@ -547,7 +620,7 @@ Foam::wordList Foam::IOobjectList::sortedNames namesImpl(*this, matchClass, predicates::always(), true) ); - checkNames(objNames, syncPar); + checkNameOrder(objNames, syncPar); return objNames; } @@ -562,6 +635,7 @@ Foam::wordList Foam::IOobjectList::sortedNames return namesImpl(*this, matchClass, matchName, true); } + template Foam::wordList Foam::IOobjectList::sortedNames ( @@ -572,7 +646,7 @@ Foam::wordList Foam::IOobjectList::sortedNames { wordList objNames(namesImpl(*this, matchClass, matchName, true)); - checkNames(objNames, syncPar); + checkNameOrder(objNames, syncPar); return objNames; } @@ -589,7 +663,7 @@ Foam::wordList Foam::IOobjectList::sortedNames(const bool syncPar) const { wordList objNames(namesTypeImpl(*this, predicates::always(), true)); - checkNames(objNames, syncPar); + checkNameOrder(objNames, syncPar); return objNames; } @@ -611,7 +685,10 @@ Foam::wordList Foam::IOobjectList::sortedNames const bool syncPar ) const { - return namesTypeImpl(*this, matchName, true, syncPar); + wordList objNames(namesTypeImpl(*this, matchName, true)); + + checkNameOrder(objNames, syncPar); + return objNames; } diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index 7ec979ae37..95156bf687 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2021 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -144,6 +144,27 @@ Foam::label Foam::objectRegistry::count(const char* clsName) const } +Foam::UPtrList +Foam::objectRegistry::csorted() const +{ + return objectsTypeImpl(*this, predicates::always()); +} + + +Foam::UPtrList +Foam::objectRegistry::sorted() const +{ + return objectsTypeImpl(*this, predicates::always()); +} + + +Foam::UPtrList +Foam::objectRegistry::sorted() +{ + return objectsTypeImpl(*this, predicates::always()); +} + + Foam::wordList Foam::objectRegistry::names() const { return HashTable::toc(); @@ -442,7 +463,7 @@ bool Foam::objectRegistry::modified() const { for (const_iterator iter = cbegin(); iter != cend(); ++iter) { - if ((*iter)->modified()) + if (iter.val()->modified()) { return true; } @@ -463,7 +484,7 @@ void Foam::objectRegistry::readModifiedObjects() << iter.key() << endl; } - (*iter)->readIfModified(); + iter.val()->readIfModified(); } } @@ -487,18 +508,19 @@ bool Foam::objectRegistry::writeObject { if (objectRegistry::debug) { + const regIOobject& obj = *iter.val(); + Pout<< "objectRegistry::write() : " << name() << " : Considering writing object " - << iter.key() - << " of type " << (*iter)->type() - << " with writeOpt " << static_cast((*iter)->writeOpt()) - << " to file " << (*iter)->objectPath() - << endl; + << iter.key() << " of type " + << obj.type() << " with writeOpt " + << static_cast(obj.writeOpt()) + << " to file " << obj.objectRelPath() << endl; } - if ((*iter)->writeOpt() != NO_WRITE) + if (iter.val()->writeOpt() != NO_WRITE) { - ok = (*iter)->writeObject(streamOpt, valid) && ok; + ok = iter.val()->writeObject(streamOpt, valid) && ok; } } diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index fbdec2463b..00145b1ee1 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,11 +36,12 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef objectRegistry_H -#define objectRegistry_H +#ifndef Foam_objectRegistry_H +#define Foam_objectRegistry_H #include "HashTable.H" #include "HashSet.H" +#include "UPtrList.H" #include "regIOobject.H" #include "wordRes.H" @@ -130,6 +131,15 @@ class objectRegistry const bool doSort ); + //- Templated implementation for sorted() + // Called with 'Type' or 'const Type' + template + static UPtrList objectsTypeImpl + ( + const objectRegistry& list, + const MatchPredicate& matchName + ); + //- No copy construct objectRegistry(const objectRegistry&) = delete; @@ -203,6 +213,54 @@ public: HashTable classes(const MatchPredicate& matchName) const; + // Sorted access + + //- Return sorted list of objects + // The lifetime of the returned content cannot exceed the parent! + UPtrList csorted() const; + + //- Return sorted list of objects + // The lifetime of the returned content cannot exceed the parent! + UPtrList sorted() const; + + //- Return sorted list of objects + // The lifetime of the returned content cannot exceed the parent! + UPtrList sorted(); + + //- Return sorted list of objects with a class satisfying \c isA\ + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList csorted() const; + + //- Return sorted list of objects with a class satisfying \c isA\ + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList sorted() const; + + //- Return sorted list of objects with a class satisfying \c isA\ + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList sorted(); + + //- Return sorted list of objects with a class satisfying \c isA\ + //- that also have a matching object name. + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList csorted(const MatchPredicate& matchName) const; + + //- Return sorted list of objects with a class satisfying \c isA\ + //- that also have a matching object name. + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList sorted(const MatchPredicate& matchName) const; + + //- Return sorted list of objects with a class satisfying \c isA\ + //- that also have a matching object name. + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList sorted(const MatchPredicate& matchName); + + // Number of items //- The number of objects of the given class name @@ -244,19 +302,19 @@ public: // Summary of names - //- The names of all objects + //- The unsorted names of all objects wordList names() const; - //- The names of objects with the given class name. + //- The unsorted names of objects with the given class name. // \note uses the class type() method wordList names(const char* clsName) const; - //- The names of objects with a matching class name + //- The unsorted names of objects with a matching class name // \note uses the class type() method template wordList names(const MatchPredicate& matchClass) const; - //- The names of objects with a matching class name + //- The unsorted names of objects with a matching class name //- that also have a matching object name. // \note uses the class type() method template @@ -266,13 +324,13 @@ public: const MatchPredicate2& matchName ) const; - //- The names of objects with a class satisfying \c isA\. + //- The unsorted names of objects with a class satisfying \c isA\. // // \note If \a Type is \c void, no isA check is used (always true). template wordList names() const; - //- The names of objects with a class satisfying \c isA\ + //- The unsorted names of objects with a class satisfying \c isA\ //- that also have a matching object name. // // \note If \a Type is \c void, no isA check is used (always true). diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C index e382021219..6b2d25a957 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -99,7 +99,7 @@ Foam::label Foam::objectRegistry::countTypeImpl if ( - (std::is_void::value || isA(*obj)) + (std::is_void::value || Foam::isA(*obj)) && matchName(obj->name()) ) { @@ -164,7 +164,7 @@ Foam::wordList Foam::objectRegistry::namesTypeImpl if ( - (std::is_void::value || isA(*obj)) + (std::is_void::value || Foam::isA(*obj)) && matchName(obj->name()) ) { @@ -184,6 +184,39 @@ Foam::wordList Foam::objectRegistry::namesTypeImpl } +// Templated implementation for sorted() +template +Foam::UPtrList +Foam::objectRegistry::objectsTypeImpl +( + const objectRegistry& list, + const MatchPredicate& matchName +) +{ + typedef typename std::remove_cv::type BaseType; + + UPtrList result(list.size()); + + label count = 0; + forAllConstIters(list, iter) + { + const BaseType* ptr = Foam::isA(*iter.val()); + + if (ptr && matchName(ptr->name())) + { + result.set(count, const_cast(ptr)); + ++count; + } + } + + result.resize(count); + + Foam::sort(result, nameOp()); // Sort by object name() + + return result; +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template @@ -243,7 +276,12 @@ Foam::label Foam::objectRegistry::count if ( std::is_void::value - || (strict ? isType(*obj) : bool(isA(*obj))) + || + ( + strict + ? bool(Foam::isType(*obj)) + : bool(Foam::isA(*obj)) + ) ) { ++nObjects; @@ -254,6 +292,66 @@ Foam::label Foam::objectRegistry::count } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +Foam::UPtrList +Foam::objectRegistry::csorted() const +{ + return objectsTypeImpl(*this, predicates::always()); +} + + +template +Foam::UPtrList +Foam::objectRegistry::sorted() const +{ + return objectsTypeImpl(*this, predicates::always()); +} + + +template +Foam::UPtrList +Foam::objectRegistry::sorted() +{ + return objectsTypeImpl(*this, predicates::always()); +} + + +template +Foam::UPtrList +Foam::objectRegistry::csorted +( + const MatchPredicate& matchName +) const +{ + return objectsTypeImpl(*this, matchName); +} + + +template +Foam::UPtrList +Foam::objectRegistry::sorted +( + const MatchPredicate& matchName +) const +{ + return objectsTypeImpl(*this, matchName); +} + +template +Foam::UPtrList +Foam::objectRegistry::sorted +( + const MatchPredicate& matchName +) +{ + return objectsTypeImpl(*this, matchName); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + template Foam::wordList Foam::objectRegistry::names ( @@ -342,7 +440,12 @@ Foam::HashTable Foam::objectRegistry::lookupClass { const regIOobject* obj = iter.val(); - if (strict ? isType(*obj) : bool(isA(*obj))) + if + ( + strict + ? bool(Foam::isType(*obj)) + : bool(Foam::isA(*obj)) + ) { objectsOfClass.insert(obj->name(), dynamic_cast(obj)); } @@ -364,7 +467,12 @@ Foam::HashTable Foam::objectRegistry::lookupClass { regIOobject* obj = iter.val(); - if (strict ? isType(*obj) : bool(isA(*obj))) + if + ( + strict + ? bool(Foam::isType(*obj)) + : bool(Foam::isA(*obj)) + ) { objectsOfClass.insert(obj->name(), dynamic_cast(obj)); } diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index e5dd771dcf..f9e96254f1 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -313,7 +313,7 @@ Foam::polyMesh::polyMesh(const IOobject& io, const bool doInit) oldPointsPtr_(nullptr), oldCellCentresPtr_(nullptr) { - if (owner_.hasHeaderClassName()) + if (owner_.hasHeaderClass()) { initMesh(); } diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C b/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C index fed06670e9..6cc2ab9ac3 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C @@ -240,7 +240,7 @@ Foam::polyMesh::readUpdateState Foam::polyMesh::readUpdate() // Boundary is set so can use initMesh now (uses boundary_ to // determine internal and active faces) - if (owner_.hasHeaderClassName()) + if (owner_.hasHeaderClass()) { initMesh(); } diff --git a/src/OpenFOAM/primitives/strings/word/word.H b/src/OpenFOAM/primitives/strings/word/word.H index 0332781130..f3fb2eb7ed 100644 --- a/src/OpenFOAM/primitives/strings/word/word.H +++ b/src/OpenFOAM/primitives/strings/word/word.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. @@ -40,8 +40,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef word_H -#define word_H +#ifndef Foam_word_H +#define Foam_word_H #include "string.H" @@ -241,6 +241,12 @@ struct nameOp { return obj.name(); } + + //- Less-compare two objects by their name() method - for sorting + bool operator()(const T& a, const T& b) const + { + return (a.name() < b.name()); + } }; @@ -252,6 +258,12 @@ struct typeOp { return obj.type(); } + + //- Less-compare two objects by their type() method - for sorting + bool operator()(const T& a, const T& b) const + { + return (a.type() < b.type()); + } }; diff --git a/src/functionObjects/field/expressions/fvExpressionField.C b/src/functionObjects/field/expressions/fvExpressionField.C index b2153d741b..9f126b7990 100644 --- a/src/functionObjects/field/expressions/fvExpressionField.C +++ b/src/functionObjects/field/expressions/fvExpressionField.C @@ -192,7 +192,7 @@ Foam::label Foam::functionObjects::fvExpressionField::loadFields const bool ok = ( io.typeHeaderOk(false) // Preload header info - && io.hasHeaderClassName() // Extra safety + && io.hasHeaderClass() // Extra safety && ( loadField(io) diff --git a/src/functionObjects/field/readFields/readFields.C b/src/functionObjects/field/readFields/readFields.C index 8c6394373e..79a085431a 100644 --- a/src/functionObjects/field/readFields/readFields.C +++ b/src/functionObjects/field/readFields/readFields.C @@ -104,7 +104,7 @@ bool Foam::functionObjects::readFields::execute() const bool ok = ( io.typeHeaderOk(false) // Preload header info - && io.hasHeaderClassName() // Extra safety + && io.hasHeaderClass() // Extra safety && ( loadField(io)