Files
openfoam/applications/test/dictionary/testDict
Mark Olesen efd1ac4b5f ENH: adjust token in preparation for separate expression tokenization
- minor simplification of #if/#endif handling

ENH: improve input robustness with negative-prefixed expansions (#2095)

- especially in blockMeshDict it is useful to negate an value directly.
  Eg,
  ```
     xmax  100;
     xmin  -$xmax;
  ```
  However, this fails since the dictionary expansion is a two-step
  process of tokenization followed by expansion. After the expansion
  the given input would now be the following:
  ```
     xmax  100;
     xmin  - 100;
  ```
  and retrieving a scalar value for 'xmin' fails.

  Counteract this by being more generous on tokenized input when
  attempting to retrieve a label or scalar value.
  If a '-' is found where a number is expected, use it to negate the
  subsequent value.

  The previous solution was to invoke an 'eval':
  ```
     xmax  100;
     xmin  #eval{-$xmax};
  ```
  which adds additional clutter.
2021-05-18 15:30:00 +02:00

133 lines
2.9 KiB
C++

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2012 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#sinclude "someUnknownFile"
#sinclude "$FOAM_CASE/someUnknownFile"
#includeIfPresent "$FOAM_CASE/someUnknownFile-$FOAM_CASENAME"
internalField uniform 1;
// 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
{
type turbulentIntensityKineticEnergyInlet;
intensity 0.1;
value $internalField;
}
inactive
{
type zeroGradient;
}
// Indirection
varType active;
// Indirection of values
x 5;
varName x;
//Indirection for keys
key inlet_9;
boundaryField
{
Default_Boundary_Region
{
type zeroGradient;
}
inlet_1 { $active }
inlet_2 { $inactive }
inlet_3 { $inactive }
inlet_4 { $inactive }
inlet_5 "a primitiveEntry is squashed by a directory entry";
inlet_5 { $inactive }
inlet_6a { $...inactive } // Relative scoping - fairly horrible to use
inlet_6b { $^inactive } // Absolute scoping
inlet_7 { ${inactive}} // Test variable expansion
inlet_8 { $inactive }
${key} { $inactive }
#include "testDictInc"
outlet
{
type inletOutlet;
inletValue $internalField;
value #include "value";
// error #remove self;
x ${${varName}}; // Test indirection/recursive expansion
y 6;
}
// this should have no effect
#remove inactive
inlet_7 { ${${varType}}} // Test indirection/recursive expansion
inlet_8 { $active }
#overwrite inlet_8 { type none; }
}
#include "testDict2"
verbatim #{
This is a somewhat larger chunk of verbatim text that we would much
prefer to move as a token rather than copying its entire content each
time we do parsing or need to resize the token list.
#};
foo
{
$active
}
bar
{
$active
}
baz
{
$active
}
"anynumber.*"
{
$active
}
// this should work
#remove active
// this should work too
#remove ( bar baz )
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //