diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C index 7ecff13d5d77b9ac99b15b64b34fd8f7ed3387a3..0340be73b191defecace19a76e14923b2885863a 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C @@ -41,6 +41,8 @@ namespace Foam bool Foam::functionObject::postProcess(false); +bool Foam::functionObject::defaultUseNamePrefix(false); + Foam::word Foam::functionObject::outputPrefix("postProcessing"); @@ -48,7 +50,7 @@ Foam::word Foam::functionObject::outputPrefix("postProcessing"); Foam::word Foam::functionObject::scopedName(const word& name) const { - if (scopedNames_) + if (useNamePrefix_) { return IOobject::scopedName(name_, name); } @@ -62,11 +64,11 @@ Foam::word Foam::functionObject::scopedName(const word& name) const Foam::functionObject::functionObject ( const word& name, - const bool scopedNames + const bool withNamePrefix ) : name_(name), - scopedNames_(scopedNames), + useNamePrefix_(withNamePrefix), log(postProcess) {} @@ -144,17 +146,36 @@ const Foam::word& Foam::functionObject::name() const noexcept } -bool Foam::functionObject::scopedNames() const noexcept +bool Foam::functionObject::useNamePrefix() const noexcept +{ + return useNamePrefix_; +} + + +bool Foam::functionObject::useNamePrefix(bool on) noexcept { - return scopedNames_; + bool old(useNamePrefix_); + useNamePrefix_ = on; + return old; } bool Foam::functionObject::read(const dictionary& dict) { +// OR +// useNamePrefix_ = Switch("useNamePrefix", dict, defaultUseNamePrefix); + + useNamePrefix_ = + dict.getOrDefault + ( + "useNamePrefix", + defaultUseNamePrefix, + keyType::LITERAL + ); + + if (!postProcess) { - scopedNames_ = dict.getOrDefault("scopedNames", true); log = dict.getOrDefault("log", true); } diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H index acef941c7d9e0c6bb10adb226078b4428a4604cc..c92320d415c2f95d29872f47a377d7fb379ab454 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H @@ -103,10 +103,11 @@ Description Property | Description | Type | Reqd | Deflt type | Type name of function object | word | yes | - libs | Library name(s) for implementation | words | no | - - errors | Error handling (default/warn/ignore/strict) | word | no | inherits - region | Name of region for multi-region cases | word | no | region0 enabled | Switch to turn function object on/off | bool | no | true + errors | Error handling (default/warn/ignore/strict) | word | no | inherits log | Switch to write log info to standard output | bool | no | true + useNamePrefix | Add scoping prefix to names | bool | no | inherits + region | Name of region for multi-region cases | word | no | region0 timeStart | Start time for function object execution | scalar | no | 0 timeEnd | End time for function object execution | scalar | no | inf executeControl | See time controls below | word | no | timeStep @@ -118,6 +119,10 @@ Description If the \c errors entry is missing, it uses the value (if any) specified within the top-level functionObjectList. + If the \c useNamePrefix entry is missing, it uses the value (if any) + specified within the top-level functionObjectList or otherwise + uses the current value of functionObject::defaultUseNamePrefix + Time controls: \table Option | Description @@ -218,40 +223,47 @@ class functionObject { // Private Data - //- Name + //- Function object name const word name_; - //- Flag to indicate that names should be scoped - bool scopedNames_; + //- Flag to indicate that names should be prefixed + bool useNamePrefix_; protected: // Protected Member Functions - //- Return a scoped name, e.g. used to construct local field names + //- Return a scoped (prefixed) name + // Used to construct local field names, controlled by useNamePrefix_ word scopedName(const word& name) const; public: - // Forward declarations + // Forward Declarations class unavailableFunctionObject; - //- Runtime type information - virtual const word& type() const = 0; - //- Flag to execute debug content - static int debug; + // Public Data + + //- Flag to write log into Info + bool log; - //- Global post-processing mode switch - static bool postProcess; - //- Directory prefix - static word outputPrefix; + // Static Data Members - //- Flag to write log into Info - bool log; + //- Flag to execute debug content + static int debug; + + //- Global post-processing mode switch + static bool postProcess; + + //- Global default for useNamePrefix + static bool defaultUseNamePrefix; + + //- Directory prefix + static word outputPrefix; // Declare run-time constructor selection tables @@ -272,7 +284,7 @@ public: explicit functionObject ( const word& name, - const bool scopedNames = true + const bool withNamePrefix = defaultUseNamePrefix ); //- Return clone @@ -300,11 +312,18 @@ public: // Member Functions + //- Runtime type information + virtual const word& type() const = 0; + //- Return the name of this functionObject const word& name() const noexcept; - //- Return the scoped names flag - bool scopedNames() const noexcept; + //- Return the flag for adding a scoping name prefix + bool useNamePrefix() const noexcept; + + //- Modify the flag for adding a scoping name prefix + // \return previous value. + bool useNamePrefix(bool on) noexcept; //- Read and set the function object if its data have changed virtual bool read(const dictionary& dict); diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 6558b2543e4f38c9083a58ba9e4756124a4bde80..3bd6168c7c59d21d7b09dc66f9811d86703eb432 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -34,6 +34,7 @@ License #include "timeControlFunctionObject.H" #include "dictionaryEntry.H" #include "stringOps.H" +#include "Switch.H" #include "Tuple2.H" #include "etcFiles.H" #include "IOdictionary.H" @@ -1009,10 +1010,27 @@ bool Foam::functionObjectList::read() if (!dEntry.isDict()) { - if (key != "errors" && key != "libs") + // Handle or ignore some known/expected keywords + + if (key == "useNamePrefix") // As per functionObject + { + Switch sw(dEntry.stream().peekFirst()); + if (sw.good()) + { + functionObject::defaultUseNamePrefix = sw; + } + else + { + IOWarningInFunction(parentDict_) + << "Entry '" << key << "' is not a valid switch" + << endl; + } + } + else if (key != "errors" && key != "libs") { IOWarningInFunction(parentDict_) - << "Entry " << key << " is not a dictionary" << endl; + << "Entry '" << key << "' is not a dictionary" + << endl; } continue; diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index 8143711ee684019334976b03c9c29206900ec288..fa57a3c78f21272f8c3a74b7e0f637a0f0f9fc6c 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -58,6 +58,7 @@ Description Property | Description | Type | Reqd | Deflt libs | Preloaded library names | words | no | - errors | Error handling (default/warn/ignore/strict) | word | no | inherits + useNamePrefix | Default enable/disable scoping prefix | bool | no | no-op \endtable The optional \c errors entry controls how FatalError is caught diff --git a/tutorials/combustion/XiEngineFoam/kivaTest/system/momentum b/tutorials/combustion/XiEngineFoam/kivaTest/system/momentum index 2e4f94ba61c6e9a3bb35cb0002892fbd248ae406..746fa027ae47921a442e9c0b642a32334cb3fa88 100644 --- a/tutorials/combustion/XiEngineFoam/kivaTest/system/momentum +++ b/tutorials/combustion/XiEngineFoam/kivaTest/system/momentum @@ -5,6 +5,7 @@ momentum type momentum; libs (fieldFunctionObjects); log true; + useNamePrefix true; writeControl writeTime; // executeInterval 10; diff --git a/tutorials/incompressible/pisoFoam/RAS/cavity/system/FOmomentum b/tutorials/incompressible/pisoFoam/RAS/cavity/system/FOmomentum index 5883e1b66efa80a28489898f6e68fa831ab5852d..66392ec8e216ab7df2ae8f7831cef8b0046f1e74 100644 --- a/tutorials/incompressible/pisoFoam/RAS/cavity/system/FOmomentum +++ b/tutorials/incompressible/pisoFoam/RAS/cavity/system/FOmomentum @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2106 | +| \\ / O peration | Version: v2112 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -33,10 +33,13 @@ momentum1 log true; timeStart 0; timeEnd 1000; + executeControl timeStep; executeInterval 1; writeControl writeTime; writeInterval -1; + + useNamePrefix true; } diff --git a/tutorials/incompressible/simpleFoam/pipeCyclic/system/momentum b/tutorials/incompressible/simpleFoam/pipeCyclic/system/momentum index 66dfd49dacab4e7ddb1dc17f7c9c3f9d6a8b787c..69d3c6836ddbbc19cd3d3fbb3009a3433df251fd 100644 --- a/tutorials/incompressible/simpleFoam/pipeCyclic/system/momentum +++ b/tutorials/incompressible/simpleFoam/pipeCyclic/system/momentum @@ -5,6 +5,7 @@ momentum type momentum; libs (fieldFunctionObjects); log true; + useNamePrefix true; executeInterval 10; writeControl writeTime;