mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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.
This commit is contained in:
61
tutorials/IO/dictionary/good-word-expand.dict
Normal file
61
tutorials/IO/dictionary/good-word-expand.dict
Normal file
@ -0,0 +1,61 @@
|
||||
/*--------------------------------*- 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();
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,7 +1,7 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: v2106 |
|
||||
| \\ / O peration | Version: v2112 |
|
||||
| \\ / A nd | Website: www.openfoam.com |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -16,6 +16,8 @@ FoamFile
|
||||
|
||||
mergeType points; // Wedge geometry - Merge points instead of topology
|
||||
|
||||
#message "Using mergeType: ${mergeType:-default}"
|
||||
|
||||
scale 0.001;
|
||||
|
||||
vertices
|
||||
|
||||
Reference in New Issue
Block a user