From 0eb4354ee01c5ab27b27fed7834836aa8f590fbd Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 28 Jul 2023 19:37:51 +0200 Subject: [PATCH 1/7] ENH: use DynamicList for handling stored objects (ReadFields) - DynamicList can be used as a LIFO with fewer allocations than a linked-list would have. - support generic name matcher for readFields() --- .../postProcessing/postProcess/postProcess.C | 42 +++++---- src/OpenFOAM/fields/ReadFields/ReadFields.H | 63 ++++++++++--- .../fields/ReadFields/ReadFieldsTemplates.C | 92 +++++++++++++++---- 3 files changed, 148 insertions(+), 49 deletions(-) diff --git a/applications/utilities/postProcessing/postProcess/postProcess.C b/applications/utilities/postProcessing/postProcess/postProcess.C index 1071cec35d..348299a452 100644 --- a/applications/utilities/postProcessing/postProcess/postProcess.C +++ b/applications/utilities/postProcessing/postProcess/postProcess.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,16 +49,6 @@ using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define ReadFields(GeoFieldType) \ - readFields(mesh, objects, selectedFields, storedObjects); - -#define ReadPointFields(GeoFieldType) \ - readFields(pMesh, objects, selectedFields, storedObjects); - -#define ReadUniformFields(FieldType) \ - readUniformFields \ - (constantObjects, selectedFields, storedObjects); - void executeFunctionObjects ( const argList& args, @@ -71,13 +61,24 @@ void executeFunctionObjects { Info<< nl << "Reading fields:" << endl; - // Maintain a stack of the stored objects to clear after executing - // the functionObjects - LIFOStack storedObjects; + // Read objects in constant directory + IOobjectList constObjects(mesh, runTime.constant()); // Read objects in time directory IOobjectList objects(mesh, runTime.timeName()); + // List of stored objects to clear after executing functionObjects + DynamicList storedObjects + ( + objects.size() + constObjects.size() + ); + + // Read GeometricFields + + #undef ReadFields + #define ReadFields(FieldType) \ + readFields(mesh, objects, selectedFields, storedObjects); + // Read volFields ReadFields(volScalarField); ReadFields(volVectorField); @@ -99,8 +100,12 @@ void executeFunctionObjects ReadFields(surfaceSymmTensorField); ReadFields(surfaceTensorField); + // Read point fields. const pointMesh& pMesh = pointMesh::New(mesh); + #undef ReadPointFields + #define ReadPointFields(FieldType) \ + readFields(pMesh, objects, selectedFields, storedObjects); ReadPointFields(pointScalarField) ReadPointFields(pointVectorField); @@ -108,8 +113,12 @@ void executeFunctionObjects ReadPointFields(pointSymmTensorField); ReadPointFields(pointTensorField); + // Read uniform dimensioned fields - IOobjectList constantObjects(mesh, runTime.constant()); + + #undef ReadUniformFields + #define ReadUniformFields(FieldType) \ + readUniformFields(constObjects, selectedFields, storedObjects); ReadUniformFields(uniformDimensionedScalarField); ReadUniformFields(uniformDimensionedVectorField); @@ -130,7 +139,8 @@ void executeFunctionObjects while (!storedObjects.empty()) { - storedObjects.pop()->checkOut(); + storedObjects.back()->checkOut(); + storedObjects.pop_back(); } } diff --git a/src/OpenFOAM/fields/ReadFields/ReadFields.H b/src/OpenFOAM/fields/ReadFields/ReadFields.H index bf919a374a..5800a5b325 100644 --- a/src/OpenFOAM/fields/ReadFields/ReadFields.H +++ b/src/OpenFOAM/fields/ReadFields/ReadFields.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,11 +36,12 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef ReadFields_H -#define ReadFields_H +#ifndef Foam_ReadFields_H +#define Foam_ReadFields_H #include "PtrList.H" #include "wordList.H" +#include "DynamicList.H" #include "GeometricField.H" #include "HashSet.H" #include "LIFOStack.H" @@ -113,27 +114,63 @@ static void ReadFields const word& registryName = "fieldsCache" ); -//- Read the selected GeometricFields of the templated type. -// The fields are transferred to the objectRegistry and a list of them is -// returned as a stack for later cleanup -template + +//- Read the selected GeometricFields of the templated type +//- and store on the objectRegistry. +// Returns a list of field pointers for later cleanup +template void readFields ( const typename GeoFieldType::Mesh& mesh, const IOobjectList& objects, - const wordHashSet& selectedFields, + //! Restrict to fields with matching names + const NameMatchPredicate& selectedFields, + //! [out] List of field pointers for later cleanup + DynamicList& storedObjects +); + +//- Read the selected UniformDimensionedFields of the templated type +//- and store on the objectRegistry. +// Returns a list of field pointers for later cleanup +template +void readUniformFields +( + const IOobjectList& objects, + //! Restrict to fields with matching names + const NameMatchPredicate& selectedFields, + //! [out] List of field pointers for later cleanup + DynamicList& storedObjects, + const bool syncPar = true +); + + +// Housekeeping + +//- Read the selected GeometricFields of the templated type +//- and store on the objectRegistry. +// \deprecated(2023-07) - prefer the DynamicList version +// Returns a stack of field pointers for later cleanup +template +FOAM_DEPRECATED_FOR(2023-07, "DynamicList version") +void readFields +( + const typename GeoFieldType::Mesh& mesh, + const IOobjectList& objects, + const NameMatchPredicate& selectedFields, LIFOStack& storedObjects ); -//- Read the selected UniformDimensionedFields of the templated type. -// The fields are transferred to the objectRegistry and a list of them is -// returned as a stack for later cleanup -template +//- Read the selected UniformDimensionedFields of the templated type +//- and store on the objectRegistry. +// \deprecated(2023-07) - prefer the DynamicList version +// Returns a stack of field pointers for later cleanup +template +FOAM_DEPRECATED_FOR(2023-07, "DynamicList version") void readUniformFields ( const IOobjectList& objects, - const wordHashSet& selectedFields, + const NameMatchPredicate& selectedFields, LIFOStack& storedObjects, const bool syncPar = true ); diff --git a/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C b/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C index 6dce0d360f..c819a2ada7 100644 --- a/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C +++ b/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -309,25 +309,25 @@ void Foam::ReadFields } -template +template void Foam::readFields ( const typename GeoFieldType::Mesh& mesh, const IOobjectList& objects, - const wordHashSet& selectedFields, - LIFOStack& storedObjects + const NameMatchPredicate& selectedFields, + DynamicList& storedObjects ) { // Names of GeoField objects, sorted order. Not synchronised. const wordList fieldNames ( - objects.sortedNames - ( - GeoFieldType::typeName, - selectedFields // Only permit these - ) + objects.sortedNames(selectedFields) ); + + // pre-extend reserve + storedObjects.reserve(storedObjects.size() + fieldNames.size()); + label nFields = 0; for (const word& fieldName : fieldNames) @@ -355,7 +355,7 @@ void Foam::readFields mesh ); fieldPtr->store(); - storedObjects.push(fieldPtr); + storedObjects.push_back(fieldPtr); ++nFields; } @@ -364,26 +364,24 @@ void Foam::readFields } -template +template void Foam::readUniformFields ( const IOobjectList& objects, - const wordHashSet& selectedFields, - LIFOStack& storedObjects, + const NameMatchPredicate& selectedFields, + DynamicList& storedObjects, const bool syncPar ) { // Names of UniformField objects, sorted order. const wordList fieldNames ( - objects.names - ( - UniformFieldType::typeName, - selectedFields, // Only permit these - syncPar - ) + objects.names(selectedFields, syncPar) ); + // pre-extend reserve + storedObjects.reserve(storedObjects.size() + fieldNames.size()); + label nFields = 0; for (const word& fieldName : fieldNames) @@ -410,7 +408,7 @@ void Foam::readUniformFields ) ); fieldPtr->store(); - storedObjects.push(fieldPtr); + storedObjects.push_back(fieldPtr); ++nFields; } @@ -419,4 +417,58 @@ void Foam::readUniformFields } +template +void Foam::readFields +( + const typename GeoFieldType::Mesh& mesh, + const IOobjectList& objects, + const NameMatchPredicate& selectedFields, + LIFOStack& storedObjects +) +{ + DynamicList newObjects; + + readFields + ( + mesh, + objects, + selectedFields, + newObjects + ); + + // Transcribe from list to stack + for (regIOobject* fieldPtr : newObjects) + { + storedObjects.push(fieldPtr); + } +} + + +template +void Foam::readUniformFields +( + const IOobjectList& objects, + const NameMatchPredicate& selectedFields, + LIFOStack& storedObjects, + const bool syncPar +) +{ + DynamicList newObjects; + + readUniformFields + ( + objects, + selectedFields, + newObjects, + syncPar + ); + + // Transcribe from list to stack + for (regIOobject* fieldPtr : newObjects) + { + storedObjects.push(fieldPtr); + } +} + + // ************************************************************************* // From 129b738136ffa67f77716a01061b68f651d6549e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 7 Jul 2023 12:25:34 +0200 Subject: [PATCH 2/7] ENH: define IOobjectList::csorted(), deprecate some sorted() const methods - prefer csorted() method for const access since it ensures that the return values are also const pointers (for example) even if the object itself can be accessed as a non-const. - the csorted() method already existed for HashTable and objectRegistry, but now added to IOobjectList for method name consistency (even although the IOobjectList only has a const-access version) ENH: objectRegistry with templated strict lookup - for lookupClass and csorted/sorted. Allows isType restriction as a compile-time specification. --- applications/test/DirLister/DirLister.H | 6 +- .../test/DirLister/DirListerTemplates.C | 12 +- applications/test/DirLister/Test-DirLister.C | 2 +- .../test/HashTable1/Test-HashTable1.C | 6 +- .../test/IOobjectList/Test-IOobjectList.C | 12 +- .../foamToEnsight-check/foamToEnsight-check.C | 8 +- .../Test-gravityMeshObject.C | 2 +- .../test/objectRegistry/Test-objectRegistry.C | 6 +- .../objectRegistry2/Test-objectRegistry2.C | 6 +- .../HashTables/HashTable/HashTable.C | 8 - .../HashTables/HashTable/HashTable.H | 12 +- src/OpenFOAM/db/IOobjectList/IOobjectList.C | 16 -- src/OpenFOAM/db/IOobjectList/IOobjectList.H | 128 ++++++++++-- .../db/IOobjectList/IOobjectListTemplates.C | 57 ++++-- .../db/objectRegistry/objectRegistry.C | 21 -- .../db/objectRegistry/objectRegistry.H | 145 ++++++++++---- .../objectRegistry/objectRegistryTemplates.C | 187 ++++++++++++------ src/OpenFOAM/meshes/MeshObject/MeshObject.C | 4 +- 18 files changed, 418 insertions(+), 220 deletions(-) diff --git a/applications/test/DirLister/DirLister.H b/applications/test/DirLister/DirLister.H index 77db93ad3b..9e76206b51 100644 --- a/applications/test/DirLister/DirLister.H +++ b/applications/test/DirLister/DirLister.H @@ -85,7 +85,7 @@ Description fileNameList procDirs ( - DirLister::dirs(".").sorted(matchProcs) + DirLister::dirs(".").csorted(matchProcs) ); } \endcode @@ -206,11 +206,11 @@ public: //- Return a complete list of names, sorted in natural order template - List sorted() const; + List csorted() const; //- Return complete list of names, sorted in natural order template - List sorted + List csorted ( const UnaryPredicate& pred, const bool prune = false diff --git a/applications/test/DirLister/DirListerTemplates.C b/applications/test/DirLister/DirListerTemplates.C index 5fb079ca6e..7de1216c63 100644 --- a/applications/test/DirLister/DirListerTemplates.C +++ b/applications/test/DirLister/DirListerTemplates.C @@ -70,23 +70,23 @@ Foam::List Foam::DirLister::list() const template -Foam::List Foam::DirLister::sorted +Foam::List Foam::DirLister::csorted ( const UnaryPredicate& pred, const bool prune ) const { - List lst(list(pred, prune)); - sort(lst, stringOps::natural_sort()); + List list(list(pred, prune)); + Foam::sort(list, stringOps::natural_sort()); - return lst; + return list; } template -Foam::List Foam::DirLister::sorted() const +Foam::List Foam::DirLister::csorted() const { - return sorted(predicates::always()); + return csorted(predicates::always()); } diff --git a/applications/test/DirLister/Test-DirLister.C b/applications/test/DirLister/Test-DirLister.C index af0e76bc9d..49a14336a2 100644 --- a/applications/test/DirLister/Test-DirLister.C +++ b/applications/test/DirLister/Test-DirLister.C @@ -162,7 +162,7 @@ int main(int argc, char *argv[]) Info<< "dirList: " << flatOutput ( - DirLister::dirs(".").sorted(relist) + DirLister::dirs(".").csorted(relist) ) << nl; } diff --git a/applications/test/HashTable1/Test-HashTable1.C b/applications/test/HashTable1/Test-HashTable1.C index 75e4eeda2d..1f116d0986 100644 --- a/applications/test/HashTable1/Test-HashTable1.C +++ b/applications/test/HashTable1/Test-HashTable1.C @@ -75,8 +75,8 @@ int main() } - Info<< "\ntable1 sorted() :" << endl; - for (const auto& iter : table1.sorted()) + Info<< "\ntable1 csorted() :" << endl; + for (const auto& iter : table1.csorted()) { Info<< " " << iter.key() << " => " << iter.val() << nl; } @@ -100,7 +100,7 @@ int main() } Info<< "\nInplace modified - via sorted() access :" << endl; - for (const auto& iter : table1.sorted()) + for (const auto& iter : table1.csorted()) { Info<< " " << iter.key() << " => " << iter.val() << nl; } diff --git a/applications/test/IOobjectList/Test-IOobjectList.C b/applications/test/IOobjectList/Test-IOobjectList.C index 5a74e1adfd..c5546650a0 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-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -290,14 +290,14 @@ int main(int argc, char *argv[]) Info<< "Time: " << runTime.timeName() << nl; report(objects); - report(objects.sorted()); + report(objects.csorted()); - report(objects.sorted()); - report(objects.sorted()); + report(objects.csorted()); + report(objects.csorted()); // Extra checks - report(objects.sorted()); - report(objects.sorted()); + report(objects.csorted()); + report(objects.csorted()); findObjectTest(objects); diff --git a/applications/test/foamToEnsight-check/foamToEnsight-check.C b/applications/test/foamToEnsight-check/foamToEnsight-check.C index 18b0dbb131..4885972a81 100644 --- a/applications/test/foamToEnsight-check/foamToEnsight-check.C +++ b/applications/test/foamToEnsight-check/foamToEnsight-check.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022 OpenCFD Ltd. + Copyright (C) 2022-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -139,7 +139,7 @@ void printInfo(const ensightMesh& mesh, int verbose = 0) FixedList cellStats(Zero); FixedList faceStats(Zero); - for (const auto& iter : mesh.cellZoneParts().sorted()) + for (const auto& iter : mesh.cellZoneParts().csorted()) { FixedList stats = printPartInfo(iter.val(), verbose); @@ -149,7 +149,7 @@ void printInfo(const ensightMesh& mesh, int verbose = 0) } } - for (const auto& iter : mesh.faceZoneParts().sorted()) + for (const auto& iter : mesh.faceZoneParts().csorted()) { FixedList stats = printPartInfo(iter.val(), verbose); @@ -159,7 +159,7 @@ void printInfo(const ensightMesh& mesh, int verbose = 0) } } - for (const auto& iter : mesh.boundaryParts().sorted()) + for (const auto& iter : mesh.boundaryParts().csorted()) { FixedList stats = printPartInfo(iter.val(), verbose); diff --git a/applications/test/gravityMeshObject/Test-gravityMeshObject.C b/applications/test/gravityMeshObject/Test-gravityMeshObject.C index bee9e70120..f95a39fe49 100644 --- a/applications/test/gravityMeshObject/Test-gravityMeshObject.C +++ b/applications/test/gravityMeshObject/Test-gravityMeshObject.C @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) Info<< "Found: " << objects << nl << endl; - for (const IOobject& io : objects.sorted()) + for (const IOobject& io : objects.csorted()) { if (io.name() == meshObjects::gravity::typeName) { diff --git a/applications/test/objectRegistry/Test-objectRegistry.C b/applications/test/objectRegistry/Test-objectRegistry.C index 76c3f4a1c5..2b2c6c1ff8 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-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -78,8 +78,8 @@ void printRegistry Foam::label indent ) { - UPtrList objects(obr.sorted()); - wordList regNames(obr.sortedNames()); + const UPtrList objects(obr.csorted()); + const wordList regNames(obr.sortedNames()); std::string prefix; for (label i=indent; i; --i) diff --git a/applications/test/objectRegistry2/Test-objectRegistry2.C b/applications/test/objectRegistry2/Test-objectRegistry2.C index 80780f6b99..66f7da171e 100644 --- a/applications/test/objectRegistry2/Test-objectRegistry2.C +++ b/applications/test/objectRegistry2/Test-objectRegistry2.C @@ -145,8 +145,8 @@ void printRegistry Foam::label indent ) { - UPtrList objects(obr.sorted()); - wordList regNames(obr.sortedNames()); + const UPtrList objects(obr.csorted()); + const wordList regNames(obr.sortedNames()); std::string prefix; for (label i=indent; i; --i) @@ -315,7 +315,7 @@ int main(int argc, char *argv[]) registryTests(mesh); - report(mesh.sorted()); + report(mesh.csorted()); report(mesh.csorted()); Info<< nl; diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C index 01dd0bcfd2..59e247b3a4 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C @@ -192,14 +192,6 @@ Foam::HashTable::csorted() const } -template -Foam::UPtrList::node_type> -Foam::HashTable::sorted() const -{ - return csorted(); -} - - template Foam::UPtrList::node_type> Foam::HashTable::sorted() diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 6879d890e1..3884212de8 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -34,7 +34,7 @@ Description depends on the method used to generate the hash key index, the table capacity, insertion order etc. When the key order is important, use the sortedToc() method to obtain a list of sorted - keys and use that for further access, or the sorted() method + keys and use that for further access, or the csorted()/sorted() methods to obtain a UPtrList of entries to traverse in sorted order. Internally the table uses closed addressing into a flat storage space @@ -351,11 +351,6 @@ public: // 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! @@ -1006,6 +1001,11 @@ public: //- Same as contains() bool found(const Key& key) const { return this->contains(key); } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted() const { return this->csorted(); } }; diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.C b/src/OpenFOAM/db/IOobjectList/IOobjectList.C index 4439109d00..c06d0f7503 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.C +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.C @@ -220,22 +220,6 @@ 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 diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.H b/src/OpenFOAM/db/IOobjectList/IOobjectList.H index 5c951c4ec5..427f8513fd 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-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -129,12 +129,13 @@ class IOobjectList const bool doSort ); - //- Templated implementation for sorted() + //- Templated implementation for csorted()/sorted() template static UPtrList objectsTypeImpl ( const IOobjectList& list, - const MatchPredicate& matchName + const MatchPredicate& matchName, + const bool doSort ); //- Templated implementation for lookup() @@ -421,26 +422,37 @@ public: HashTable classes(const MatchPredicate& matchName) const; - // Sorted access + // List-wise access (unsorted) - //- 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 + //- The unsorted 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; + UPtrList cobjects() const; + + //- The unsorted 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 cobjects + ( + const MatchPredicate& matchName + ) const; + + // List-wise access (sorted) + + //- 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 csorted() const; //- The sorted names of the IOobjects with optional check for //- parallel consistency. @@ -448,13 +460,30 @@ public: // processors. // The lifetime of the returned content cannot exceed the parent! template - UPtrList sorted(const bool syncPar) const; + UPtrList csorted(const bool syncPar) const; + + //- The sorted list of IOobjects + // The lifetime of the returned content cannot exceed the parent! + UPtrList csorted() const + { + return csorted(); + } + + //- 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 csorted(const bool syncPar) const + { + return csorted(syncPar); + } //- 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; + UPtrList csorted(const MatchPredicate& matchName) const; //- The sorted list of IOobjects with headerClassName == Type::typeName //- that also have a matching object name. @@ -462,7 +491,7 @@ public: // processors. // The lifetime of the returned content cannot exceed the parent! template - UPtrList sorted + UPtrList csorted ( const MatchPredicate& matchName, const bool syncPar @@ -769,10 +798,67 @@ public: { return getObject(objName); } + + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted() const + { + return csorted(); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted(const bool syncPar) const + { + return csorted(syncPar); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted() const + { + return csorted(); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted(const bool syncPar) const + { + return csorted(syncPar); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted(const MatchPredicate& matchName) const + { + return csorted(matchName); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted + ( + const MatchPredicate& matchName, + const bool syncPar + ) const + { + return csorted(matchName, syncPar); + } }; -// Ostream operator +// Ostream Operator Ostream& operator<<(Ostream& os, const IOobjectList& list); diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C b/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C index 515e964715..475c3586b6 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-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -177,13 +177,14 @@ Foam::wordList Foam::IOobjectList::namesTypeImpl } -// Templated implementation for sorted() +// Templated implementation for csorted(), csorted() template Foam::UPtrList Foam::IOobjectList::objectsTypeImpl ( const IOobjectList& list, - const MatchPredicate& matchName + const MatchPredicate& matchName, + const bool doSort ) { UPtrList result(list.size()); @@ -203,7 +204,10 @@ Foam::IOobjectList::objectsTypeImpl result.resize(count); - Foam::sort(result, nameOp()); // Sort by object name() + if (doSort) + { + Foam::sort(result, nameOp()); // Sort by object name() + } return result; } @@ -472,19 +476,30 @@ Foam::label Foam::IOobjectList::count template Foam::UPtrList -Foam::IOobjectList::sorted() const +Foam::IOobjectList::cobjects() const { - return objectsTypeImpl(*this, predicates::always()); + // doSort = false + return objectsTypeImpl(*this, predicates::always(), false); } template Foam::UPtrList -Foam::IOobjectList::sorted(const bool syncPar) const +Foam::IOobjectList::csorted() const +{ + // doSort = true + return objectsTypeImpl(*this, predicates::always(), true); +} + + +template +Foam::UPtrList +Foam::IOobjectList::csorted(const bool syncPar) const { UPtrList list ( - objectsTypeImpl(*this, predicates::always()) + // doSort = true + objectsTypeImpl(*this, predicates::always(), true) ); checkObjectOrder(list, syncPar); @@ -495,18 +510,31 @@ Foam::IOobjectList::sorted(const bool syncPar) const template Foam::UPtrList -Foam::IOobjectList::sorted +Foam::IOobjectList::cobjects ( const MatchPredicate& matchName ) const { - return objectsTypeImpl(*this, matchName); + // doSort = false + return objectsTypeImpl(*this, matchName, false); } template Foam::UPtrList -Foam::IOobjectList::sorted +Foam::IOobjectList::csorted +( + const MatchPredicate& matchName +) const +{ + // doSort = true + return objectsTypeImpl(*this, matchName, true); +} + + +template +Foam::UPtrList +Foam::IOobjectList::csorted ( const MatchPredicate& matchName, const bool syncPar @@ -514,7 +542,8 @@ Foam::IOobjectList::sorted { UPtrList list ( - objectsTypeImpl(*this, matchName) + // doSort = true + objectsTypeImpl(*this, matchName, true) ); checkObjectOrder(list, syncPar); @@ -531,6 +560,7 @@ Foam::wordList Foam::IOobjectList::names const MatchPredicate& matchClass ) const { + // doSort = false return namesImpl(*this, matchClass, predicates::always(), false); } @@ -553,6 +583,7 @@ Foam::wordList Foam::IOobjectList::names const MatchPredicate2& matchName ) const { + // doSort = false return namesImpl(*this, matchClass, matchName, false); } @@ -572,6 +603,7 @@ Foam::wordList Foam::IOobjectList::names template Foam::wordList Foam::IOobjectList::names() const { + // doSort = false return namesTypeImpl(*this, predicates::always(), false); } @@ -589,6 +621,7 @@ Foam::wordList Foam::IOobjectList::names const MatchPredicate& matchName ) const { + // doSort = false return namesTypeImpl(*this, matchName, false); } diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index df993fd902..76b7bad5cb 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -158,27 +158,6 @@ 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(); diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index 9ae0c9e868..226ef9f043 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -150,13 +150,24 @@ class objectRegistry const bool doSort ); - //- Templated implementation for sorted() + //- Templated implementation for csorted()/sorted() // Called with 'Type' or 'const Type' template static UPtrList objectsTypeImpl ( + const bool strict, // Check with isType const objectRegistry& list, - const MatchPredicate& matchName + const MatchPredicate& matchName, + const bool doSort // Sort the list by name + ); + + //- Templated implementation for lookupClass() + // Called with 'Type' or 'const Type' + template + static HashTable lookupClassTypeImpl + ( + const bool strict, // Check with isType + const objectRegistry& list ); @@ -240,49 +251,69 @@ public: HashTable classes(const MatchPredicate& matchName) const; - // Sorted access + // List-wise access (unsorted) - //- Return sorted list of objects + //- Return unsorted list of objects with a class satisfying + //- \c isA\ or \c isType\ (with Strict) // The lifetime of the returned content cannot exceed the parent! - UPtrList csorted() const; + template + UPtrList cobjects() const; - //- Return sorted list of objects + //- Return unsorted list of objects with a class satisfying + //- \c isA\ or \c isType\ (with Strict) // The lifetime of the returned content cannot exceed the parent! - UPtrList sorted() const; + template + UPtrList objects(); - //- Return sorted list of objects + //- Return unsorted 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! - 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(); + template + UPtrList cobjects(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 objects(const MatchPredicate& matchName); + + + // List-wise access (sorted) + + //- Return sorted list of objects with a class satisfying + //- \c isA\ or \c isType\ (with Strict) + // 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\ or \c isType\ (with Strict) + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList sorted(); + + //- Return sorted list of objects + // The lifetime of the returned content cannot exceed the parent! + UPtrList csorted() const + { + return csorted(); + } + + //- Return sorted list of objects + // The lifetime of the returned content cannot exceed the parent! + UPtrList sorted() + { + return 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. + //- 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); @@ -351,7 +382,7 @@ public: const MatchPredicate2& matchName ) const; - //- The unsorted 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 @@ -417,17 +448,27 @@ public: ) const; - //- Return all objects with a class satisfying \c isA\ - // - // \param strict use \c isType\ instead of \c isA\ - template - HashTable lookupClass(const bool strict = false) const; + //- Return all objects with a class satisfying + //- \c isA\ or \c isType\ (with Strict) + template + HashTable lookupClass() const; + + //- Return all objects with a class satisfying + //- \c isA\ or \c isType\ (with Strict) + template + HashTable lookupClass(); //- Return all objects with a class satisfying \c isA\ // // \param strict use \c isType\ instead of \c isA\ template - HashTable lookupClass(const bool strict = false); + HashTable lookupClass(const bool strict) const; + + //- Return all objects with a class satisfying \c isA\ + // + // \param strict use \c isType\ instead of \c isA\ + template + HashTable lookupClass(const bool strict); //- Return const pointer to the regIOobject. // @@ -673,6 +714,32 @@ public: { return this->getObjectPtr(name, recursive); } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted() const + { + return csorted(); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted() const + { + return csorted(); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted(const MatchPredicate& matchName) const + { + return csorted(matchName); + } }; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C index 9204516b5d..a03ebcd00c 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C @@ -184,13 +184,15 @@ Foam::wordList Foam::objectRegistry::namesTypeImpl } -// Templated implementation for sorted() +// Templated implementation for cobjects()/objects(), csorted()/sorted() template Foam::UPtrList Foam::objectRegistry::objectsTypeImpl ( + const bool strict, const objectRegistry& list, - const MatchPredicate& matchName + const MatchPredicate& matchName, + const bool doSort ) { typedef typename std::remove_cv::type BaseType; @@ -200,9 +202,15 @@ Foam::objectRegistry::objectsTypeImpl label count = 0; forAllConstIters(list, iter) { - const BaseType* ptr = Foam::isA(*iter.val()); + const regIOobject* obj = iter.val(); + const BaseType* ptr = dynamic_cast(obj); - if (ptr && matchName(ptr->name())) + if + ( + ptr + && (!strict || Foam::isType(*obj)) + && matchName(ptr->name()) + ) { result.set(count, const_cast(ptr)); ++count; @@ -211,7 +219,42 @@ Foam::objectRegistry::objectsTypeImpl result.resize(count); - Foam::sort(result, nameOp()); // Sort by object name() + if (doSort) + { + Foam::sort(result, nameOp()); // Sort by object name() + } + + return result; +} + + +// Templated implementation for lookupClass() +template +Foam::HashTable +Foam::objectRegistry::lookupClassTypeImpl +( + const bool strict, + const objectRegistry& list +) +{ + typedef typename std::remove_cv::type BaseType; + + HashTable result(list.capacity()); + + forAllConstIters(list, iter) + { + const regIOobject* obj = iter.val(); + const BaseType* ptr = dynamic_cast(obj); + + if + ( + ptr + && (!strict || Foam::isType(*obj)) + ) + { + result.insert(obj->name(), const_cast(ptr)); + } + } return result; } @@ -294,27 +337,71 @@ Foam::label Foam::objectRegistry::count // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template +template +Foam::UPtrList +Foam::objectRegistry::cobjects() const +{ + return objectsTypeImpl + ( + Strict, *this, predicates::always(), false // doSort = false + ); +} + + +template +Foam::UPtrList +Foam::objectRegistry::objects() +{ + return objectsTypeImpl + ( + Strict, *this, predicates::always(), false // doSort = false + ); +} + + +template Foam::UPtrList Foam::objectRegistry::csorted() const { - return objectsTypeImpl(*this, predicates::always()); + return objectsTypeImpl + ( + Strict, *this, predicates::always(), true // doSort = true + ); } -template -Foam::UPtrList -Foam::objectRegistry::sorted() const -{ - return objectsTypeImpl(*this, predicates::always()); -} - - -template +template Foam::UPtrList Foam::objectRegistry::sorted() { - return objectsTypeImpl(*this, predicates::always()); + return objectsTypeImpl + ( + Strict, *this, predicates::always(), true // doSort = false + ); +} + + +template +Foam::UPtrList +Foam::objectRegistry::cobjects +( + const MatchPredicate& matchName +) const +{ + // doSort = false + return objectsTypeImpl(false, *this, matchName, false); +} + + +template +Foam::UPtrList +Foam::objectRegistry::objects +( + const MatchPredicate& matchName +) +{ + // doSort = false + return objectsTypeImpl(false, *this, matchName, false); } @@ -325,20 +412,10 @@ Foam::objectRegistry::csorted const MatchPredicate& matchName ) const { - return objectsTypeImpl(*this, matchName); + return objectsTypeImpl(false, *this, matchName, true); } -template -Foam::UPtrList -Foam::objectRegistry::sorted -( - const MatchPredicate& matchName -) const -{ - return objectsTypeImpl(*this, matchName); -} - template Foam::UPtrList Foam::objectRegistry::sorted @@ -346,7 +423,7 @@ Foam::objectRegistry::sorted const MatchPredicate& matchName ) { - return objectsTypeImpl(*this, matchName); + return objectsTypeImpl(false, *this, matchName, true); } @@ -428,30 +505,27 @@ Foam::wordList Foam::objectRegistry::sortedNames } +template +Foam::HashTable Foam::objectRegistry::lookupClass() const +{ + return lookupClassTypeImpl(Strict, *this); +} + + +template +Foam::HashTable Foam::objectRegistry::lookupClass() +{ + return lookupClassTypeImpl(Strict, *this); +} + + template Foam::HashTable Foam::objectRegistry::lookupClass ( const bool strict ) const { - HashTable objectsOfClass(size()); - - forAllConstIters(*this, iter) - { - const regIOobject* obj = iter.val(); - - if - ( - strict - ? bool(Foam::isType(*obj)) - : bool(Foam::isA(*obj)) - ) - { - objectsOfClass.insert(obj->name(), dynamic_cast(obj)); - } - } - - return objectsOfClass; + return lookupClassTypeImpl(strict, *this); } @@ -461,24 +535,7 @@ Foam::HashTable Foam::objectRegistry::lookupClass const bool strict ) { - HashTable objectsOfClass(size()); - - forAllIters(*this, iter) - { - regIOobject* obj = iter.val(); - - if - ( - strict - ? bool(Foam::isType(*obj)) - : bool(Foam::isA(*obj)) - ) - { - objectsOfClass.insert(obj->name(), dynamic_cast(obj)); - } - } - - return objectsOfClass; + return lookupClassTypeImpl(strict, *this); } diff --git a/src/OpenFOAM/meshes/MeshObject/MeshObject.C b/src/OpenFOAM/meshes/MeshObject/MeshObject.C index 6423b898c2..26bbf42e81 100644 --- a/src/OpenFOAM/meshes/MeshObject/MeshObject.C +++ b/src/OpenFOAM/meshes/MeshObject/MeshObject.C @@ -206,7 +206,7 @@ void Foam::meshObject::updateMesh(objectRegistry& obr, const mapPolyMesh& mpm) forAllIters(meshObjects, iter) { - // isA> + // isA> auto* objectPtr = dynamic_cast*>(*iter); if (objectPtr) @@ -277,7 +277,7 @@ void Foam::meshObject::clearUpto(objectRegistry& obr) forAllIters(meshObjects, iter) { - // isA + // isA> auto* objectPtr = dynamic_cast*>(*iter); if (!objectPtr) From 5397c9ac04d2963c14c446ee705256622703e3d6 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 17 Jul 2023 16:04:40 +0200 Subject: [PATCH 3/7] COMP: use csorted() instead of sorted() --- .../utilities/mesh/manipulation/setSet/setSet.C | 4 ++-- .../mesh/manipulation/setsToZones/setsToZones.C | 8 ++++---- .../reconstructPar/reconstructPar.C | 8 ++++---- .../parPointFieldDistributorTemplates.C | 6 +++--- .../fieldsDistributor/fieldsDistributorTemplates.C | 4 ++-- .../distributed/faMeshDistributorTemplates.C | 8 ++++---- .../forces/forceCoeffs/forceCoeffs.C | 14 +++++++------- .../utilities/ensightWrite/ensightWriteImpl.C | 4 ++-- .../utilities/vtkWrite/vtkWriteImpl.C | 6 +++--- .../KinematicSurfaceFilm/KinematicSurfaceFilm.C | 13 ++++++------- .../SurfaceFilmModel/SurfaceFilmModel.C | 2 +- .../lagrangianFieldDecomposerReadFields.C | 10 +++++----- .../faReconstruct/faFieldReconstructorTemplates.C | 10 +++++----- .../reconstruct/fvFieldReconstructorTemplates.C | 14 +++++++------- .../reconstruct/lagrangianReconstructorTemplates.C | 14 +++++++------- .../reconstruct/pointFieldReconstructorTemplates.C | 6 +++--- 16 files changed, 65 insertions(+), 66 deletions(-) diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C index 73a5727663..b717e9f152 100644 --- a/applications/utilities/mesh/manipulation/setSet/setSet.C +++ b/applications/utilities/mesh/manipulation/setSet/setSet.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2018 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -158,7 +158,7 @@ void printSets(Ostream& os, const IOobjectList& objects) { label n = 0; - for (const IOobject& io : objects.sorted()) + for (const IOobject& io : objects.csorted()) { SetType set(io); if (!n++) os << SetType::typeName << "s:" << nl; diff --git a/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C b/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C index e5b86055dd..a42a9ec7ee 100644 --- a/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C +++ b/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2021-2022 OpenCFD Ltd. + Copyright (C) 2021-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) << endl; - for (const IOobject& io : objects.sorted()) + for (const IOobject& io : objects.csorted()) { // Not in memory. Load it. pointSet set(io); @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) wordHashSet slaveCellSets; - for (const IOobject& io : objects.sorted()) + for (const IOobject& io : objects.csorted()) { // Not in memory. Load it. faceSet set(io); @@ -259,7 +259,7 @@ int main(int argc, char *argv[]) - for (const IOobject& io : objects.sorted()) + for (const IOobject& io : objects.csorted()) { if (!slaveCellSets.found(io.name())) { diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C index 7398cb581d..1ae4fb4ca8 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2022 OpenCFD Ltd. + Copyright (C) 2015-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -653,7 +653,7 @@ int main(int argc, char *argv[]) const labelList& cellMap = procMeshes.cellProcAddressing()[proci]; - for (const IOobject& io : objects.sorted()) + for (const IOobject& io : objects.csorted()) { // Load cellSet const cellSet procSet(io); @@ -684,7 +684,7 @@ int main(int argc, char *argv[]) const labelList& faceMap = procMeshes.faceProcAddressing()[proci]; - for (const IOobject& io : objects.sorted()) + for (const IOobject& io : objects.csorted()) { // Load faceSet const faceSet procSet(io); @@ -714,7 +714,7 @@ int main(int argc, char *argv[]) const labelList& pointMap = procMeshes.pointProcAddressing()[proci]; - for (const IOobject& io : objects.sorted()) + for (const IOobject& io : objects.csorted()) { // Load pointSet const pointSet procSet(io); diff --git a/applications/utilities/parallelProcessing/redistributePar/parPointFieldDistributorTemplates.C b/applications/utilities/parallelProcessing/redistributePar/parPointFieldDistributorTemplates.C index e048bed283..4c1964f076 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parPointFieldDistributorTemplates.C +++ b/applications/utilities/parallelProcessing/redistributePar/parPointFieldDistributorTemplates.C @@ -185,11 +185,11 @@ Foam::label Foam::parPointFieldDistributor::distributePointFields { typedef GeometricField fieldType; - UPtrList fieldObjects + const UPtrList fieldObjects ( selectedFields.empty() - ? objects.sorted() - : objects.sorted(selectedFields) + ? objects.csorted() + : objects.csorted(selectedFields) ); label nFields = 0; diff --git a/src/OpenFOAM/parallel/fieldsDistributor/fieldsDistributorTemplates.C b/src/OpenFOAM/parallel/fieldsDistributor/fieldsDistributorTemplates.C index f070fe8b16..8bddfe9130 100644 --- a/src/OpenFOAM/parallel/fieldsDistributor/fieldsDistributorTemplates.C +++ b/src/OpenFOAM/parallel/fieldsDistributor/fieldsDistributorTemplates.C @@ -65,7 +65,7 @@ void Foam::fieldsDistributor::readFields typedef GeometricField GeoField; // GeoField fields - sorted for consistent order on all processors - UPtrList fieldObjects(objects.sorted()); + const UPtrList fieldObjects(objects.csorted()); // Construct the fields fields.resize(fieldObjects.size()); @@ -86,7 +86,7 @@ void Foam::fieldsDistributor::readFields ) { // GeoField fields - sorted for consistent order on all processors - UPtrList fieldObjects(objects.sorted()); + const UPtrList fieldObjects(objects.csorted()); // Construct the fields fields.resize(fieldObjects.size()); diff --git a/src/finiteArea/distributed/faMeshDistributorTemplates.C b/src/finiteArea/distributed/faMeshDistributorTemplates.C index 26d2da28f5..19ddc49404 100644 --- a/src/finiteArea/distributed/faMeshDistributorTemplates.C +++ b/src/finiteArea/distributed/faMeshDistributorTemplates.C @@ -310,8 +310,8 @@ Foam::label Foam::faMeshDistributor::distributeAreaFields const IOobject& io : ( selectedFields.empty() - ? objects.sorted() - : objects.sorted(selectedFields) + ? objects.csorted() + : objects.csorted(selectedFields) ) ) { @@ -368,8 +368,8 @@ Foam::label Foam::faMeshDistributor::distributeEdgeFields const IOobject& io : ( selectedFields.empty() - ? objects.sorted() - : objects.sorted(selectedFields) + ? objects.csorted() + : objects.csorted(selectedFields) ) ) { diff --git a/src/functionObjects/forces/forceCoeffs/forceCoeffs.C b/src/functionObjects/forces/forceCoeffs/forceCoeffs.C index a80062e501..b749dcf81b 100644 --- a/src/functionObjects/forces/forceCoeffs/forceCoeffs.C +++ b/src/functionObjects/forces/forceCoeffs/forceCoeffs.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2022 OpenCFD Ltd. + Copyright (C) 2015-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -236,7 +236,7 @@ void Foam::functionObjects::forceCoeffs::writeIntegratedDataFileHeader writeHeader(os, ""); writeCommented(os, "Time"); - for (const auto& iter : coeffs_.sorted()) + for (const auto& iter : coeffs_.csorted()) { const auto& coeff = iter.val(); @@ -255,7 +255,7 @@ void Foam::functionObjects::forceCoeffs::writeIntegratedDataFile() writeCurrentTime(os); - for (const auto& iter : coeffs_.sorted()) + for (const auto& iter : coeffs_.csorted()) { const auto& coeff = iter.val(); @@ -359,16 +359,16 @@ bool Foam::functionObjects::forceCoeffs::read(const dictionary& dict) for (const word& key : coeffs) { - auto coeffIter = coeffs_.find(key); + auto iter = coeffs_.find(key); - if (!coeffIter.good()) + if (!iter.good()) { FatalIOErrorInFunction(dict) << "Unknown coefficient type " << key << " . Valid entries are : " << coeffs_.sortedToc() << exit(FatalIOError); } - auto& coeff = coeffIter.val(); + auto& coeff = iter.val(); coeff.active_ = true; Info<< " - " << coeff << nl; } @@ -412,7 +412,7 @@ bool Foam::functionObjects::forceCoeffs::execute() }; // Always setting all results - for (const auto& iter : coeffs_.sorted()) + for (const auto& iter : coeffs_.csorted()) { const word& coeffName = iter.key(); const auto& coeff = iter.val(); diff --git a/src/functionObjects/utilities/ensightWrite/ensightWriteImpl.C b/src/functionObjects/utilities/ensightWrite/ensightWriteImpl.C index 1a7096b1a9..b55c4f19b3 100644 --- a/src/functionObjects/utilities/ensightWrite/ensightWriteImpl.C +++ b/src/functionObjects/utilities/ensightWrite/ensightWriteImpl.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,7 +46,7 @@ Foam::label Foam::functionObjects::ensightWrite::writeVolFieldsImpl for ( const GeoField& origField - : baseMesh.sorted(candidateNames) + : baseMesh.csorted(candidateNames) ) { const word& fieldName = origField.name(); diff --git a/src/functionObjects/utilities/vtkWrite/vtkWriteImpl.C b/src/functionObjects/utilities/vtkWrite/vtkWriteImpl.C index 9d3c60ac3e..0e6dfd2f15 100644 --- a/src/functionObjects/utilities/vtkWrite/vtkWriteImpl.C +++ b/src/functionObjects/utilities/vtkWrite/vtkWriteImpl.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -43,7 +43,7 @@ Foam::label Foam::functionObjects::vtkWrite::writeVolFieldsImpl for ( const GeoField& origField - : baseMesh.sorted(candidateNames) + : baseMesh.csorted(candidateNames) ) { bool ok = false; @@ -110,7 +110,7 @@ Foam::label Foam::functionObjects::vtkWrite::writeVolFieldsImpl for ( const GeoField& origField - : baseMesh.sorted(candidateNames) + : baseMesh.csorted(candidateNames) ) { bool ok = false; diff --git a/src/lagrangian/intermediate/submodels/Kinematic/SurfaceFilmModel/KinematicSurfaceFilm/KinematicSurfaceFilm.C b/src/lagrangian/intermediate/submodels/Kinematic/SurfaceFilmModel/KinematicSurfaceFilm/KinematicSurfaceFilm.C index e3fb81f101..2d471effaf 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/SurfaceFilmModel/KinematicSurfaceFilm/KinematicSurfaceFilm.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/SurfaceFilmModel/KinematicSurfaceFilm/KinematicSurfaceFilm.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2021-2022 OpenCFD Ltd. + Copyright (C) 2021-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -114,14 +114,13 @@ void Foam::KinematicSurfaceFilm::initFilmModels() // Set up area films if (areaFilms_.empty()) { - UPtrList models + for ( - mesh.time().objectRegistry::template sorted() - ); - - for (const auto& model : models) + const areaFilm& regionFa + : mesh.time().objectRegistry::template csorted() + ) { - areaFilms_.append(const_cast(&model)); + areaFilms_.push_back(const_cast(®ionFa)); } } } diff --git a/src/lagrangian/intermediate/submodels/Kinematic/SurfaceFilmModel/SurfaceFilmModel/SurfaceFilmModel.C b/src/lagrangian/intermediate/submodels/Kinematic/SurfaceFilmModel/SurfaceFilmModel/SurfaceFilmModel.C index e097e5d3fb..d8c4743582 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/SurfaceFilmModel/SurfaceFilmModel/SurfaceFilmModel.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/SurfaceFilmModel/SurfaceFilmModel/SurfaceFilmModel.C @@ -288,7 +288,7 @@ void Foam::SurfaceFilmModel::inject(TrackCloudType& cloud) for ( const areaFilm& regionFa - : mesh.time().objectRegistry::template sorted() + : mesh.time().objectRegistry::template csorted() ) { if (regionFa.active()) diff --git a/src/parallel/decompose/decompose/lagrangianFieldDecomposerReadFields.C b/src/parallel/decompose/decompose/lagrangianFieldDecomposerReadFields.C index f3534f2d9d..9a62cb0e2b 100644 --- a/src/parallel/decompose/decompose/lagrangianFieldDecomposerReadFields.C +++ b/src/parallel/decompose/decompose/lagrangianFieldDecomposerReadFields.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2022 OpenCFD Ltd. + Copyright (C) 2022-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,9 +40,9 @@ void Foam::lagrangianFieldDecomposer::readFields ) { // List of lagrangian field objects - UPtrList fieldObjects + const UPtrList fieldObjects ( - lagrangianObjects.sorted>() + lagrangianObjects.csorted>() ); auto& cloudFields = @@ -66,12 +66,12 @@ void Foam::lagrangianFieldDecomposer::readFieldFields // List of lagrangian field objects UPtrList fieldObjects ( - lagrangianObjects.sorted>>() + lagrangianObjects.cobjects>>() ); fieldObjects.push_back ( - lagrangianObjects.sorted, Type>>() + lagrangianObjects.cobjects, Type>>() ); Foam::sort(fieldObjects, nameOp()); diff --git a/src/parallel/reconstruct/faReconstruct/faFieldReconstructorTemplates.C b/src/parallel/reconstruct/faReconstruct/faFieldReconstructorTemplates.C index d9cf4a297f..e5c27951ff 100644 --- a/src/parallel/reconstruct/faReconstruct/faFieldReconstructorTemplates.C +++ b/src/parallel/reconstruct/faReconstruct/faFieldReconstructorTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -697,8 +697,8 @@ Foam::label Foam::faFieldReconstructor::reconstructAreaFields ( ( selectedFields.empty() - ? objects.sorted() - : objects.sorted(selectedFields) + ? objects.csorted() + : objects.csorted(selectedFields) ) ); } @@ -717,8 +717,8 @@ Foam::label Foam::faFieldReconstructor::reconstructEdgeFields ( ( selectedFields.empty() - ? objects.sorted() - : objects.sorted(selectedFields) + ? objects.csorted() + : objects.csorted(selectedFields) ) ); } diff --git a/src/parallel/reconstruct/reconstruct/fvFieldReconstructorTemplates.C b/src/parallel/reconstruct/reconstruct/fvFieldReconstructorTemplates.C index 060238bfde..70a31ea8cc 100644 --- a/src/parallel/reconstruct/reconstruct/fvFieldReconstructorTemplates.C +++ b/src/parallel/reconstruct/reconstruct/fvFieldReconstructorTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -707,8 +707,8 @@ Foam::label Foam::fvFieldReconstructor::reconstructInternalFields ( ( selectedFields.empty() - ? objects.sorted() - : objects.sorted(selectedFields) + ? objects.csorted() + : objects.csorted(selectedFields) ) ); } @@ -727,8 +727,8 @@ Foam::label Foam::fvFieldReconstructor::reconstructVolumeFields ( ( selectedFields.empty() - ? objects.sorted() - : objects.sorted(selectedFields) + ? objects.csorted() + : objects.csorted(selectedFields) ) ); } @@ -747,8 +747,8 @@ Foam::label Foam::fvFieldReconstructor::reconstructSurfaceFields ( ( selectedFields.empty() - ? objects.sorted() - : objects.sorted(selectedFields) + ? objects.csorted() + : objects.csorted(selectedFields) ) ); } diff --git a/src/parallel/reconstruct/reconstruct/lagrangianReconstructorTemplates.C b/src/parallel/reconstruct/reconstruct/lagrangianReconstructorTemplates.C index 2789f67282..ef025f22de 100644 --- a/src/parallel/reconstruct/reconstruct/lagrangianReconstructorTemplates.C +++ b/src/parallel/reconstruct/reconstruct/lagrangianReconstructorTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -199,8 +199,8 @@ Foam::label Foam::lagrangianReconstructor::reconstructFields cloudName, ( selectedFields.empty() - ? objects.sorted() - : objects.sorted(selectedFields) + ? objects.csorted() + : objects.csorted(selectedFields) ) ); } @@ -221,13 +221,13 @@ Foam::label Foam::lagrangianReconstructor::reconstructFieldFields if (selectedFields.empty()) { - fieldObjects.append(objects.sorted()); - fieldObjects.append(objects.sorted()); + fieldObjects.push_back(objects.csorted()); + fieldObjects.push_back(objects.csorted()); } else { - fieldObjects.append(objects.sorted(selectedFields)); - fieldObjects.append(objects.sorted(selectedFields)); + fieldObjects.push_back(objects.csorted(selectedFields)); + fieldObjects.push_back(objects.csorted(selectedFields)); } Foam::sort(fieldObjects, nameOp()); diff --git a/src/parallel/reconstruct/reconstruct/pointFieldReconstructorTemplates.C b/src/parallel/reconstruct/reconstruct/pointFieldReconstructorTemplates.C index 01e26fe6c7..ae49e24b1b 100644 --- a/src/parallel/reconstruct/reconstruct/pointFieldReconstructorTemplates.C +++ b/src/parallel/reconstruct/reconstruct/pointFieldReconstructorTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -212,8 +212,8 @@ Foam::label Foam::pointFieldReconstructor::reconstructPointFields ( ( selectedFields.empty() - ? objects.sorted() - : objects.sorted(selectedFields) + ? objects.csorted() + : objects.csorted(selectedFields) ) ); } From ed314b2740fba7772615aad2a6dce0fcb3f6cd94 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 6 Jul 2023 13:05:34 +0200 Subject: [PATCH 4/7] ENH: use sorted order for patch IDs in fieldFunctionObjects (#2819) - replaces labelHashSet with a sorted labelList to ensure that patches will be processed in consistent order in parallel --- .../VoFPatchTransfer/VoFPatchTransfer.C | 1 + src/functionObjects/field/Curle/Curle.C | 18 ++-- src/functionObjects/field/Curle/Curle.H | 10 +- .../binField/binModels/binModel/binModel.C | 20 ++-- .../binField/binModels/binModel/binModel.H | 4 +- .../singleDirectionUniformBin.C | 4 +- .../singleDirectionUniformBinTemplates.C | 3 +- .../binModels/uniformBin/uniformBin.C | 12 +-- .../uniformBin/uniformBinTemplates.C | 3 +- .../field/fieldExtents/fieldExtents.C | 30 +++--- .../field/fieldExtents/fieldExtents.H | 9 +- .../ReynoldsAnalogy/ReynoldsAnalogy.C | 4 +- .../faceZoneReferenceTemperature.C | 2 +- .../fixedReferenceTemperature.C | 2 +- .../heatTransferCoeffModel.C | 13 +-- .../heatTransferCoeffModel.H | 10 +- .../localReferenceTemperature.C | 2 +- .../multiphaseInterHtcModel.C | 6 +- .../reactingEulerHtcModel.C | 4 +- .../field/nearWallFields/nearWallFields.C | 17 ++- .../field/nearWallFields/nearWallFields.H | 8 +- .../nearWallFields/nearWallFieldsTemplates.C | 4 +- .../regionSizeDistribution.C | 99 ++++++++--------- .../regionSizeDistribution.H | 6 +- .../field/wallHeatFlux/wallHeatFlux.C | 102 +++++++++--------- .../field/wallHeatFlux/wallHeatFlux.H | 10 +- .../field/wallShearStress/wallShearStress.C | 84 ++++++++------- .../field/wallShearStress/wallShearStress.H | 7 +- src/functionObjects/forces/forces/forces.C | 19 ++-- src/functionObjects/forces/forces/forces.H | 4 +- .../patchInjection/patchInjection.C | 42 +++----- .../patchInjection/patchInjection.H | 22 ++-- 32 files changed, 279 insertions(+), 302 deletions(-) diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFPatchTransfer/VoFPatchTransfer.C b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFPatchTransfer/VoFPatchTransfer.C index 63cc806366..f3af8611d3 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFPatchTransfer/VoFPatchTransfer.C +++ b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterFilmFoam/VoFPatchTransfer/VoFPatchTransfer.C @@ -86,6 +86,7 @@ VoFPatchTransfer::VoFPatchTransfer wordRes patchNames; if (coeffDict_.readIfPresent("patches", patchNames)) { + // Can also use pbm.indices(), but no warnings... patchIDs_ = pbm.patchSet(patchNames).sortedToc(); Info<< " applying to " << patchIDs_.size() << " patches:" << nl; diff --git a/src/functionObjects/field/Curle/Curle.C b/src/functionObjects/field/Curle/Curle.C index 9cdcbd3c35..6b53be0723 100644 --- a/src/functionObjects/field/Curle/Curle.C +++ b/src/functionObjects/field/Curle/Curle.C @@ -63,7 +63,6 @@ Foam::functionObjects::Curle::Curle fvMeshFunctionObject(name, runTime, dict), writeFile(mesh_, name), pName_("p"), - patchSet_(), observerPositions_(), c0_(0), rawFilePtrs_(), @@ -78,6 +77,8 @@ Foam::functionObjects::Curle::Curle bool Foam::functionObjects::Curle::read(const dictionary& dict) { + const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); + if (!(fvMeshFunctionObject::read(dict) && writeFile::read(dict))) { return false; @@ -85,14 +86,12 @@ bool Foam::functionObjects::Curle::read(const dictionary& dict) dict.readIfPresent("p", pName_); - patchSet_ = mesh_.boundaryMesh().patchSet(dict.get("patches")); + patchIDs_ = pbm.patchSet(dict.get("patches")).sortedToc(); - if (patchSet_.empty()) + if (patchIDs_.empty()) { WarningInFunction - << "No patches defined" - << endl; - + << "No patches defined" << endl; return false; } @@ -117,8 +116,7 @@ bool Foam::functionObjects::Curle::read(const dictionary& dict) if (observerPositions_.empty()) { WarningInFunction - << "No observer positions defined" - << endl; + << "No observer positions defined" << endl; return false; } @@ -205,7 +203,7 @@ bool Foam::functionObjects::Curle::execute() scalarField pDash(observerPositions_.size(), 0); - for (auto patchi : patchSet_) + for (const label patchi : patchIDs_) { const scalarField& pp = pBf[patchi]; const scalarField& dpdtp = dpdtBf[patchi]; @@ -228,7 +226,7 @@ bool Foam::functionObjects::Curle::execute() if (surfaceWriterPtr_) { - if (Pstream::master()) + if (UPstream::master()) { // Time-aware, with time spliced into the output path surfaceWriterPtr_->beginTime(time_); diff --git a/src/functionObjects/field/Curle/Curle.H b/src/functionObjects/field/Curle/Curle.H index 19afa8e3de..06beac04f6 100644 --- a/src/functionObjects/field/Curle/Curle.H +++ b/src/functionObjects/field/Curle/Curle.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -124,8 +124,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef functionObjects_Curle_H -#define functionObjects_Curle_H +#ifndef Foam_functionObjects_Curle_H +#define Foam_functionObjects_Curle_H #include "fvMeshFunctionObject.H" #include "writeFile.H" @@ -163,8 +163,8 @@ class Curle //- Name of pressure field; default = p word pName_; - //- Patches to integrate forces over - labelHashSet patchSet_; + //- List of patches to process + labelList patchIDs_; //- Observer positions List observerPositions_; diff --git a/src/functionObjects/field/binField/binModels/binModel/binModel.C b/src/functionObjects/field/binField/binModels/binModel/binModel.C index fc31d3e860..e610bada7f 100644 --- a/src/functionObjects/field/binField/binModels/binModel/binModel.C +++ b/src/functionObjects/field/binField/binModels/binModel/binModel.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2021-2022 OpenCFD Ltd. + Copyright (C) 2021-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -122,12 +122,8 @@ Foam::binModel::binModel mesh_(mesh), decomposePatchValues_(false), cumulative_(false), - coordSysPtr_(), - nBin_(1), - patchSet_(), - fieldNames_(), - cellZoneIDs_(), - filePtrs_() + coordSysPtr_(nullptr), + nBin_(1) {} @@ -135,19 +131,23 @@ Foam::binModel::binModel bool Foam::binModel::read(const dictionary& dict) { + const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); + if (!functionObjects::writeFile::read(dict)) { return false; } - patchSet_ = mesh_.boundaryMesh().patchSet(dict.get("patches")); + // Can also use pbm.indices(), but no warnings... + patchIDs_ = pbm.patchSet(dict.get("patches")).sortedToc(); fieldNames_ = dict.get("fields").sortedToc(); - if (dict.found("cellZones")) + wordRes zoneNames; + if (dict.readIfPresent("cellZones", zoneNames)) { DynamicList