From 4e48beffd4add6eb60f745de95bf7e438e3157d0 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Sat, 29 Jul 2017 17:44:22 +0200 Subject: [PATCH] ENH: support "one-shot" changes to the dictionary inputMode (issue #429) - Instead of relying on #inputMode to effect a global change it is now possible (and recommended) to a temporary change in the inputMode for the following entry. #default : provide default value if entry is not already defined #overwrite : silently remove a previously existing entry #warn : warn about duplicate entries #error : error if any duplicate entries occur #merge : merge sub-dictionaries when possible (the default mode) This is generally less cumbersome than the switching the global inputMode. For example to provide a set of fallback values. #includeIfPresent "user-files" ... #default value uniform 10; vs. #includeIfPresent "user-files" #inputMode protect ... value uniform 10; #inputMode merge // _Assuming_ we actually had this before These directives can also be used to suppress the normal dictionary merge semantics: #overwrite dict { entry val; ... } --- applications/test/dictionary/testDict | 19 ++-- etc/caseDicts/foamyHexMeshDict | 2 - .../functionEntries/inputMode/inputMode.C | 95 +++++++++++++++++++ .../functionEntries/inputMode/inputMode.H | 80 ++++++++++++++++ .../system/solverControls | 2 - .../system/solverControls.0 | 2 - .../system/solverControls.20 | 2 - .../system/solverControls.5 | 2 - .../system/solverControls.60 | 2 - .../steady/0.orig/include/initialConditions | 2 - .../0.orig/include/initialConditions | 1 - .../0.orig/include/initialConditions | 1 - 12 files changed, 185 insertions(+), 25 deletions(-) diff --git a/applications/test/dictionary/testDict b/applications/test/dictionary/testDict index 736f4263056..a933c543e3f 100644 --- a/applications/test/dictionary/testDict +++ b/applications/test/dictionary/testDict @@ -13,18 +13,19 @@ FoamFile object testDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#inputMode merge + #includeIfPresent "someUnknownFile" #includeIfPresent "$FOAM_CASE/someUnknownFile" #includeIfPresent "$FOAM_CASE/someUnknownFile-$FOAM_CASENAME" internalField uniform 1; -// use 'protect' to supply defaults -#inputMode protect -internalField uniform 10; -dimensions [ 0 2 -2 0 0 0 0 ]; -#inputMode merge +// supply defaults +#default internalField uniform 10; +#default dimensions [ 1 2 -2 0 0 0 0 ]; +#overwrite dimensions [ 0 2 -2 0 0 0 0 ]; +// #warn dimensions [ 0 2 -2 0 0 0 0 ]; +// #error dimensions [ 0 2 -2 0 0 0 0 ]; active { @@ -86,12 +87,12 @@ boundaryField #remove inactive inlet_7 { ${${varType}}} // Test indirection/recursive expansion - #inputMode overwrite inlet_8 { $active } + + #overwrite inlet_8 { type none; } } -// NB: the inputMode has a global scope -#inputMode merge + #include "testDict2" foo diff --git a/etc/caseDicts/foamyHexMeshDict b/etc/caseDicts/foamyHexMeshDict index 088c1a0b987..ee8abb7e154 100644 --- a/etc/caseDicts/foamyHexMeshDict +++ b/etc/caseDicts/foamyHexMeshDict @@ -14,8 +14,6 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#inputMode merge; - surfaceConformation { pointPairDistanceCoeff 0.1; diff --git a/src/OpenFOAM/db/dictionary/functionEntries/inputMode/inputMode.C b/src/OpenFOAM/db/dictionary/functionEntries/inputMode/inputMode.C index bdd92de36e9..160d5ec87d8 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/inputMode/inputMode.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/inputMode/inputMode.C @@ -41,6 +41,51 @@ namespace functionEntries dictionaryIstream, inputMode ); + + addNamedToMemberFunctionSelectionTable + ( + functionEntry, + inputModeDefault, + execute, + dictionaryIstream, + default + ); + + addNamedToMemberFunctionSelectionTable + ( + functionEntry, + inputModeMerge, + execute, + dictionaryIstream, + merge + ); + + addNamedToMemberFunctionSelectionTable + ( + functionEntry, + inputModeOverwrite, + execute, + dictionaryIstream, + overwrite + ); + + addNamedToMemberFunctionSelectionTable + ( + functionEntry, + inputModeWarn, + execute, + dictionaryIstream, + warn + ); + + addNamedToMemberFunctionSelectionTable + ( + functionEntry, + inputModeError, + execute, + dictionaryIstream, + error + ); } } @@ -90,4 +135,54 @@ bool Foam::functionEntries::inputMode::execute } +bool Foam::functionEntries::inputModeDefault::execute +( + dictionary& parentDict, + Istream& is +) +{ + return entry::New(parentDict, is, entry::inputMode::PROTECT); +} + + +bool Foam::functionEntries::inputModeMerge::execute +( + dictionary& parentDict, + Istream& is +) +{ + return entry::New(parentDict, is, entry::inputMode::MERGE); +} + + +bool Foam::functionEntries::inputModeOverwrite::execute +( + dictionary& parentDict, + Istream& is +) +{ + return entry::New(parentDict, is, entry::inputMode::OVERWRITE); +} + + +bool Foam::functionEntries::inputModeWarn::execute +( + dictionary& parentDict, + Istream& is +) +{ + return entry::New(parentDict, is, entry::inputMode::WARN); +} + + +bool Foam::functionEntries::inputModeError::execute +( + dictionary& parentDict, + Istream& is +) +{ + return entry::New(parentDict, is, entry::inputMode::ERROR); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/inputMode/inputMode.H b/src/OpenFOAM/db/dictionary/functionEntries/inputMode/inputMode.H index c670d9230dc..91f0d6362bc 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/inputMode/inputMode.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/inputMode/inputMode.H @@ -84,6 +84,86 @@ public: }; +/*---------------------------------------------------------------------------*\ + Class inputModeDefault Declaration +\*---------------------------------------------------------------------------*/ + +//- Temporarily change inputMode to %protect for the following entry +class inputModeDefault +: + public functionEntry +{ +public: + + //- Execute in a sub-dict context + static bool execute(dictionary& parentDict, Istream& is); +}; + + +/*---------------------------------------------------------------------------*\ + Class inputModeMerge Declaration +\*---------------------------------------------------------------------------*/ + +//- Temporarily change inputMode to %merge for the following entry +class inputModeMerge +: + public functionEntry +{ +public: + + //- Execute in a sub-dict context + static bool execute(dictionary& parentDict, Istream& is); +}; + + +/*---------------------------------------------------------------------------*\ + Class inputModeOverwrite Declaration +\*---------------------------------------------------------------------------*/ + +//- Temporarily change inputMode to %overwrite for the following entry +class inputModeOverwrite +: + public functionEntry +{ +public: + + //- Execute in a sub-dict context + static bool execute(dictionary& parentDict, Istream& is); +}; + + +/*---------------------------------------------------------------------------*\ + Class inputModeWarn Declaration +\*---------------------------------------------------------------------------*/ + +//- Temporarily change inputMode to %warn for the following entry +class inputModeWarn +: + public functionEntry +{ +public: + + //- Execute in a sub-dict context + static bool execute(dictionary& parentDict, Istream& is); +}; + + +/*---------------------------------------------------------------------------*\ + Class inputModeError Declaration +\*---------------------------------------------------------------------------*/ + +//- Temporarily change inputMode to %error for the following entry +class inputModeError +: + public functionEntry +{ +public: + + //- Execute in a sub-dict context + static bool execute(dictionary& parentDict, Istream& is); +}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace functionEntries diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls index 63d17474fbe..0eae3d794b2 100644 --- a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls +++ b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls @@ -12,6 +12,4 @@ maxCo 12; maxDeltaT 1; -#inputMode merge - // ************************************************************************* // diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.0 b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.0 index f23b6a4f10b..65697b02421 100644 --- a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.0 +++ b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.0 @@ -12,6 +12,4 @@ maxCo 2.5; maxDeltaT 0.3; -#inputMode merge - // ************************************************************************* // diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.20 b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.20 index c1143ac2dc3..56a2dc921ff 100644 --- a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.20 +++ b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.20 @@ -12,6 +12,4 @@ maxCo 8; maxDeltaT 1; -#inputMode merge - // ************************************************************************* // diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.5 b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.5 index be96ad74298..9f1c5f5932e 100644 --- a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.5 +++ b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.5 @@ -12,6 +12,4 @@ maxCo 5; maxDeltaT 1; -#inputMode merge - // ************************************************************************* // diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.60 b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.60 index 63d17474fbe..0eae3d794b2 100644 --- a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.60 +++ b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/system/solverControls.60 @@ -12,6 +12,4 @@ maxCo 12; maxDeltaT 1; -#inputMode merge - // ************************************************************************* // diff --git a/tutorials/incompressible/lumpedPointMotion/building/steady/0.orig/include/initialConditions b/tutorials/incompressible/lumpedPointMotion/building/steady/0.orig/include/initialConditions index 8d82530aae2..30be52d9723 100644 --- a/tutorials/incompressible/lumpedPointMotion/building/steady/0.orig/include/initialConditions +++ b/tutorials/incompressible/lumpedPointMotion/building/steady/0.orig/include/initialConditions @@ -12,6 +12,4 @@ turbulentKE 37; turbulentOmega 32; turbulentEpsilon 30; -#inputMode merge - // ************************************************************************* // diff --git a/tutorials/incompressible/overPimpleDyMFoam/cylinder/cylinderAndBackground/0.orig/include/initialConditions b/tutorials/incompressible/overPimpleDyMFoam/cylinder/cylinderAndBackground/0.orig/include/initialConditions index aaa6bd1c6ff..d2b995d3b55 100644 --- a/tutorials/incompressible/overPimpleDyMFoam/cylinder/cylinderAndBackground/0.orig/include/initialConditions +++ b/tutorials/incompressible/overPimpleDyMFoam/cylinder/cylinderAndBackground/0.orig/include/initialConditions @@ -10,6 +10,5 @@ flowVelocity (10 0 0); pressure 0; turbulentKE 1.5; turbulentEpsilon 0.88; -#inputMode merge // ************************************************************************* // diff --git a/tutorials/incompressible/overSimpleFoam/aeroFoil/background_overset/0.orig/include/initialConditions b/tutorials/incompressible/overSimpleFoam/aeroFoil/background_overset/0.orig/include/initialConditions index e0b2bd996ee..14ab8e962cd 100644 --- a/tutorials/incompressible/overSimpleFoam/aeroFoil/background_overset/0.orig/include/initialConditions +++ b/tutorials/incompressible/overSimpleFoam/aeroFoil/background_overset/0.orig/include/initialConditions @@ -11,6 +11,5 @@ pressure 0; turbulentKE 0.375; turbulentOmega 3.6; turbulentEpsilon 0.12; -#inputMode merge // ************************************************************************* // -- GitLab