ENH: handle entry alternatives outside of string expansion

- string expansions have supported "${var:-default}" syntax for
  several versions, but this did not apply plain dictionary expansions.

  Eg, the following did not parse

     massFlow  ${entry1:-100};

ENH: remove content and length restriction on '${..}' quoted variables

- allows this type of content:

     velocity2  ${velocity1:- ( 0 -100 10) };

- accept empty parameter strings for entries. This allows the
  following expansion to work as expected:

      hex (n1 n2..)  ${inletBlock:-} (10 10 10) simpleGrading (1 1 1)

  ie, optionally define the cellZone name for a given block

ENH: add single parameter dictionary writeEntry method.

- the dictionary knows its own name (dictName), which can be used
  when writing content
This commit is contained in:
Mark Olesen
2020-02-21 14:37:11 +01:00
parent 3c9c39e92a
commit 083181cac4
5 changed files with 218 additions and 42 deletions

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v1912 |
| \\ / O peration | Version: v2006 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -14,21 +14,48 @@ FoamFile
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Do comparison
// Do comparison. Handles the first token after then '#if', which should
// correspond to a logical (true/false, ...) and integer (0,1, ...)
// but also a floating-point value with 0-1 range.
#if #eval "${FOAM_API:-0}"
foamApi nonZero;
#if ${FOAM_API:-false}
foamApi nonZero is ${FOAM_API:-0};
#else
foamApi zeroValue;
#endif
#if #eval "${XX_XXX_FOAM_API:-1000}"
other "some entry";
#if ${XX_XXX_FOAM_API:-1000}
other "some entry" ${XX_XXX_FOAM_API:-(0 1 0)};
#else
other "unexpected";
#endif
#if 0.1
roundToZero failed;
#else
roundToZero good with ${__expand_or_ignore_:-};
#endif
#if 0.99
roundToOne good;
#else
roundToOne failed;
#endif
#if -0.1
roundNegZero failed;
#else
roundNegZero good;
#endif
#if -0.99
roundToNegOne good;
#else
roundToNegOne failed;
#endif
#if #eval "${FOAM_API:-0} >= 1910"
evalType hasEvalWithConditionals;
#else
@ -44,5 +71,23 @@ FoamFile
condition false;
#endif
// Some other conditionals
condition1 true;
condition2 false;
#if ${unknown:-${condition2:-${condition1}}}
multiExpansion1 failed;
#else
multiExpansion1 good;
#endif
#if ${unknown:-${unknown:-${condition2:+true}}}
multiExpansion2 good = ${unkn:-${unkn:-${condition2:+on}}};
#else
multiExpansion2 failed;
#endif
// ************************************************************************* //