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; ... }
This commit is contained in:
Mark Olesen
2017-07-29 17:44:22 +02:00
parent 2fdc6b161a
commit 4e48beffd4
12 changed files with 185 additions and 25 deletions

View File

@ -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