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); + } +} + + // ************************************************************************* //