From f4df00a4e90a73c60d1d20cc0647cc5260a80674 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 13 Jun 2023 15:18:18 +0200 Subject: [PATCH] ENH: support alternative registration name for solution "data" (#2797) --- .../GeometricField/GeometricField.H | 6 +- src/OpenFOAM/meshes/data/data.C | 49 ++++----- src/OpenFOAM/meshes/data/data.H | 99 ++++++++++++++++--- src/OpenFOAM/meshes/data/dataTemplates.C | 3 +- src/finiteArea/faMesh/faMesh.C | 6 +- 5 files changed, 109 insertions(+), 54 deletions(-) diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index eaa54bab72..2d5157abf1 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -660,9 +660,9 @@ public: // alpha is read from controlDict void relax(); - //- Select the final iteration parameters if `final' is true - // by returning the field name + "Final" - // otherwise the standard parameters by returning the field name + //- Select the final iteration parameters if \c final is true + //- by returning the field name + "Final" + //- otherwise the standard parameters by returning the field name word select(bool final) const; //- Helper function to write the min and max to an Ostream diff --git a/src/OpenFOAM/meshes/data/data.C b/src/OpenFOAM/meshes/data/data.C index 15e419193f..083304d26f 100644 --- a/src/OpenFOAM/meshes/data/data.C +++ b/src/OpenFOAM/meshes/data/data.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,48 +29,35 @@ License #include "data.H" #include "Time.H" -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -int Foam::data::debug(Foam::debug::debugSwitch("data", 0)); - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::data::data(const objectRegistry& obr) +Foam::data::data +( + const word& name, + const objectRegistry& obr, + const dictionary* content +) : IOdictionary ( IOobject ( - "data", + name, obr.time().system(), obr, IOobject::NO_READ, - IOobject::NO_WRITE - ) - ), - prevTimeIndex_(0) -{ - set("solverPerformance", dictionary()); -} - - -Foam::data::data(const objectRegistry& obr, const dictionary& dict) -: - IOdictionary - ( - IOobject - ( - "data", - obr.time().system(), - obr, - IOobject::NO_READ, - IOobject::NO_WRITE + IOobject::NO_WRITE, + IOobject::REGISTER ), - dict + content ), - prevTimeIndex_(0) -{} + prevTimeIndex_(-1) +{ + if (content == nullptr || !findDict("solverPerformance", keyType::LITERAL)) + { + set("solverPerformance", dictionary()); + } +} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/data/data.H b/src/OpenFOAM/meshes/data/data.H index 91da9a93d4..202419a4c6 100644 --- a/src/OpenFOAM/meshes/data/data.H +++ b/src/OpenFOAM/meshes/data/data.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,16 +30,17 @@ Class Description Database for solution data, solver performance and other reduced data. - fvMesh is derived from data so that all fields have access to the data from - the mesh reference they hold. + Both faMesh and fvMesh are derived from this class so that every + GeometricField has access to this data via their mesh reference. SourceFiles data.C + dataTemplates.C \*---------------------------------------------------------------------------*/ -#ifndef data_H -#define data_H +#ifndef Foam_data_H +#define Foam_data_H #include "IOdictionary.H" #include "solverPerformance.H" @@ -57,7 +58,7 @@ class data : public IOdictionary { - // Private data + // Private Data //- Previously used time-index, used for reset between iterations mutable label prevTimeIndex_; @@ -65,26 +66,69 @@ class data // Private Member Functions + //- True if boolean entry exists and is set + bool getBoolEntry(const word& keyword) const + { + bool value = false; + return readIfPresent(keyword, value) && value; + } + + //- Add/remove boolean entry + void setBoolEntry(const word& keyword, bool on) + { + if (on) + { + add(keyword, true); + } + else + { + remove(keyword); + } + } + //- No copy construct data(const data&) = delete; //- No copy assignment void operator=(const data&) = delete; - public: - //- Debug switch - static int debug; - - // Constructors - //- Construct for objectRegistry - data(const objectRegistry& obr); + //- Construct for objectRegistry (registered with specified name) + //- optionally with initial content + data + ( + const word& name, + const objectRegistry& obr, + const dictionary* content = nullptr + ); - //- Construct for objectRegistry and initial contents - data(const objectRegistry& obr, const dictionary& dict); + //- Construct for objectRegistry (registered as "data") + explicit data(const objectRegistry& obr) + : + data("data", obr) + {} + + //- Construct for objectRegistry (registered with specified name) + //- copying initial content + data + ( + const word& name, + const objectRegistry& obr, + const dictionary& dict + ) + : + data(name, obr, &dict) + {} + + //- Construct for objectRegistry (registered as "data") + //- copying initial content + data(const objectRegistry& obr, const dictionary& dict) + : + data("data", obr, &dict) + {} // Member Functions @@ -93,6 +137,31 @@ public: //- includes initial and final residuals for convergence checking const dictionary& solverPerformanceDict() const; + //- True if "firstIteration" entry exists and is set + bool isFirstIteration() const + { + return getBoolEntry("firstIteration"); + } + + //- True if "finalIteration" entry exists and is set + bool isFinalIteration() const + { + return getBoolEntry("finalIteration"); + } + + //- Add/remove "firstIteration" entry + void isFirstIteration(bool on) + { + return setBoolEntry("firstIteration", on); + } + + //- Add/remove "finalIteration" entry + void isFinalIteration(bool on) + { + return setBoolEntry("finalIteration", on); + } + + //- Add/set the solverPerformance entry for the named field template void setSolverPerformance diff --git a/src/OpenFOAM/meshes/data/dataTemplates.C b/src/OpenFOAM/meshes/data/dataTemplates.C index baa9c6f403..8bef786dd3 100644 --- a/src/OpenFOAM/meshes/data/dataTemplates.C +++ b/src/OpenFOAM/meshes/data/dataTemplates.C @@ -53,8 +53,7 @@ void Foam::data::setSolverPerformance dict.readIfPresent(name, perfs); } - // Append to list - perfs.setSize(perfs.size()+1, sp); + perfs.push_back(sp); dict.set(name, perfs); } diff --git a/src/finiteArea/faMesh/faMesh.C b/src/finiteArea/faMesh/faMesh.C index eadb9eb7a0..95c5081bbe 100644 --- a/src/finiteArea/faMesh/faMesh.C +++ b/src/finiteArea/faMesh/faMesh.C @@ -350,7 +350,7 @@ Foam::faMesh::faMesh faSchemes(mesh()), edgeInterpolation(*this), faSolution(mesh()), - data(mesh()), // Always NO_READ, NO_WRITE + data(faMesh::thisDb()), // Always NO_READ, NO_WRITE faceLabels_ ( IOobject @@ -473,7 +473,7 @@ Foam::faMesh::faMesh faSchemes(mesh(), io.readOpt()), edgeInterpolation(*this), faSolution(mesh(), io.readOpt()), - data(mesh()), // Always NO_READ, NO_WRITE + data(faMesh::thisDb()), // Always NO_READ, NO_WRITE faceLabels_ ( IOobject @@ -558,7 +558,7 @@ Foam::faMesh::faMesh ), data ( - mesh(), + faMesh::thisDb(), static_cast(baseMesh) ), faceLabels_