mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: use stringOps::expandDict when processing codeStream input
This commit is contained in:
@ -14,10 +14,15 @@ FoamFile
|
|||||||
}
|
}
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// #include "codeStreamDefaults"
|
// values from outer-scope
|
||||||
|
begIter 0;
|
||||||
|
endIter 200;
|
||||||
|
|
||||||
writeInterval #codeStream
|
writeInterval #codeStream
|
||||||
{
|
{
|
||||||
|
// values from inner-scope
|
||||||
|
nDumps 5;
|
||||||
|
|
||||||
codeInclude
|
codeInclude
|
||||||
#{
|
#{
|
||||||
#include "fvCFD.H"
|
#include "fvCFD.H"
|
||||||
@ -30,14 +35,15 @@ writeInterval #codeStream
|
|||||||
|
|
||||||
code
|
code
|
||||||
#{
|
#{
|
||||||
scalar start = 0;
|
label interval = ($endIter - $begIter);
|
||||||
scalar end = 100;
|
label nDumps = $nDumps;
|
||||||
label nDumps = 5;
|
os << (interval / nDumps);
|
||||||
label interval = end - start;
|
|
||||||
Info<<"on-the-fly: " << ((interval)/nDumps) << endl;
|
|
||||||
os << ((interval)/nDumps);
|
|
||||||
#};
|
#};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// play with cleanup
|
||||||
|
#remove begIter
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -83,17 +83,21 @@ bool Foam::functionEntries::codeStream::execute
|
|||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get code dictionary
|
||||||
|
// must reference parent for stringOps::expandDict to work nicely
|
||||||
|
dictionary codeDict("#codeStream", parentDict, is);
|
||||||
|
|
||||||
|
|
||||||
// Read three sections of code.
|
// Read three sections of code.
|
||||||
// Remove any leading whitespace - necessary for compilation options,
|
// Remove any leading whitespace - necessary for compilation options,
|
||||||
// convenience for includes and body.
|
// convenience for includes and body.
|
||||||
dictionary codeDict(is);
|
|
||||||
|
|
||||||
// "codeInclude" is optional
|
// "codeInclude" is optional
|
||||||
string codeInclude;
|
string codeInclude;
|
||||||
if (codeDict.found("codeInclude"))
|
if (codeDict.found("codeInclude"))
|
||||||
{
|
{
|
||||||
codeInclude = stringOps::trim(codeDict["codeInclude"]);
|
codeInclude = stringOps::trim(codeDict["codeInclude"]);
|
||||||
|
stringOps::inplaceExpandDict(codeInclude, codeDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// "codeOptions" is optional
|
// "codeOptions" is optional
|
||||||
@ -101,10 +105,13 @@ bool Foam::functionEntries::codeStream::execute
|
|||||||
if (codeDict.found("codeOptions"))
|
if (codeDict.found("codeOptions"))
|
||||||
{
|
{
|
||||||
codeOptions = stringOps::trim(codeDict["codeOptions"]);
|
codeOptions = stringOps::trim(codeDict["codeOptions"]);
|
||||||
|
stringOps::inplaceExpandDict(codeOptions, codeDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// "code" is mandatory
|
// "code" is mandatory
|
||||||
string code = stringOps::trim(codeDict["code"]);
|
string code = stringOps::trim(codeDict["code"]);
|
||||||
|
stringOps::inplaceExpandDict(code, codeDict);
|
||||||
|
|
||||||
|
|
||||||
// Create SHA1 digest from the contents
|
// Create SHA1 digest from the contents
|
||||||
SHA1Digest sha;
|
SHA1Digest sha;
|
||||||
|
|||||||
@ -159,12 +159,11 @@ void Foam::codeStreamTools::copyAndExpand
|
|||||||
{
|
{
|
||||||
is.getLine(line);
|
is.getLine(line);
|
||||||
|
|
||||||
// normal expansion according to mapping
|
// expand according to mapping
|
||||||
|
// expanding according to env variables might cause too many
|
||||||
|
// surprises
|
||||||
stringOps::inplaceExpand(line, mapping);
|
stringOps::inplaceExpand(line, mapping);
|
||||||
|
|
||||||
// expand according to env variables
|
|
||||||
stringOps::inplaceExpandEnv(line, true, true);
|
|
||||||
|
|
||||||
os << line.c_str() << nl;
|
os << line.c_str() << nl;
|
||||||
}
|
}
|
||||||
while (is.good());
|
while (is.good());
|
||||||
|
|||||||
@ -96,6 +96,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
|
|||||||
if (dict.found("codeInclude"))
|
if (dict.found("codeInclude"))
|
||||||
{
|
{
|
||||||
codeInclude = stringOps::trim(dict["codeInclude"]);
|
codeInclude = stringOps::trim(dict["codeInclude"]);
|
||||||
|
stringOps::inplaceExpandDict(codeInclude, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// "codeOptions" is optional
|
// "codeOptions" is optional
|
||||||
@ -103,10 +104,13 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
|
|||||||
if (dict.found("codeOptions"))
|
if (dict.found("codeOptions"))
|
||||||
{
|
{
|
||||||
codeOptions = stringOps::trim(dict["codeOptions"]);
|
codeOptions = stringOps::trim(dict["codeOptions"]);
|
||||||
|
stringOps::inplaceExpandDict(codeOptions, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// "code" is mandatory
|
// "code" is mandatory
|
||||||
string code = stringOps::trim(dict["code"]);
|
string code = stringOps::trim(dict["code"]);
|
||||||
|
stringOps::inplaceExpandDict(code, dict);
|
||||||
|
|
||||||
|
|
||||||
// Create SHA1 digest from the contents
|
// Create SHA1 digest from the contents
|
||||||
SHA1Digest sha;
|
SHA1Digest sha;
|
||||||
|
|||||||
Reference in New Issue
Block a user