openfoam/tutorials/IO/dictionary/good-word-expand.dict
Mark Olesen 1804d3fed5 ENH: additional #word and #message dictionary directives (#2276)
- use `#word` to concatenate, expand content with the resulting string
  being treated as a word token. Can be used in dictionary or
  primitive context.

  In dictionary context, it fills the gap for constructing dictionary
  names on-the-fly. For example,

  ```
  #word "some_prefix_solverInfo_${application}"
  {
      type    solverInfo;
      libs    (utilityFunctionObjects);
      ...
  }
  ```

  The '#word' directive will automatically squeeze out non-word
  characters. In the block content form, it will also strip out
  comments. This means that this type of content should also work:

  ```
  #word {
     some_prefix_solverInfo
     /* Appended with application name (if defined) */
     ${application:+_}  // Use '_' separator
     ${application}     // The application
  }
  {
      type    solverInfo;
      libs    (utilityFunctionObjects);
      ...
  }
  ```
  This is admittedly quite ugly, but illustrates its capabilities.

- use `#message` to report expanded string content to stderr.
  For example,

  ```
  T
  {
     solver          PBiCG;
     preconditioner  DILU;
     tolerance       1e-10;
     relTol          0;
     #message "using solver: $solver"
  }
  ```
  Only reports on the master node.
2021-11-25 17:05:37 +01:00

62 lines
1.6 KiB
C++

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// message from a word
#message message-word
// message from a string
#message "message string [] from ${FOAM_API:-unset}"
// message from a braced-block string
#message { message block string from ${FOAM_API:-unset} }
// word in primitive entry
foamApi using #word "_ ${FOAM_API:-unset}" version;
// word as dictionary entry (string syntax)
#word "dict1entry_ ${FOAM_API:-unset}"
{
value1 10;
}
// word as dictionary entry (braced-block string)
#word { dict2entry_ ${FOAM_API:-unset} }
{
value1 20;
}
#word
{
dict3entry
${FOAM_API:+_} // Use '_' separator
${FOAM_API} // The value (if any)
}
{
// This is a funny corner-case for #eval.
// It also accepts a single word ... not that many make sense though
value1 #eval pi();
}
// ************************************************************************* //