ENH: support file-scope 'localCode' in dynamicCode
This commit is contained in:
parent
8c3a8fcd21
commit
e8a3587df4
@ -33,10 +33,20 @@ writeInterval #codeStream
|
|||||||
-I$(LIB_SRC)/finiteVolume/lnInclude
|
-I$(LIB_SRC)/finiteVolume/lnInclude
|
||||||
#};
|
#};
|
||||||
|
|
||||||
|
localCode
|
||||||
|
#{
|
||||||
|
static int someCode()
|
||||||
|
{
|
||||||
|
Info<<"called someCode\n";
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
#};
|
||||||
|
|
||||||
code
|
code
|
||||||
#{
|
#{
|
||||||
label interval = ($endIter - $begIter);
|
label interval = ($endIter - $begIter);
|
||||||
label nDumps = $nDumps;
|
// label nDumps = $nDumps;
|
||||||
|
label nDumps = someCode();
|
||||||
os << (interval / nDumps);
|
os << (interval / nDumps);
|
||||||
#};
|
#};
|
||||||
};
|
};
|
||||||
|
@ -34,22 +34,37 @@ Description
|
|||||||
${codeInclude}
|
${codeInclude}
|
||||||
//}}} end codeInclude
|
//}}} end codeInclude
|
||||||
|
|
||||||
using namespace Foam;
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
//{{{ begin localCode
|
||||||
|
${localCode}
|
||||||
|
//}}} end localCode
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
void ${typeName}(Ostream& os, const dictionary& dict)
|
void ${typeName}
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//{{{ begin code
|
//{{{ begin code
|
||||||
${code};
|
${code}
|
||||||
//}}} end code
|
//}}} end code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
@ -38,6 +38,13 @@ ${codeInclude}
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
//{{{ begin localCode
|
||||||
|
${localCode}
|
||||||
|
//}}} end localCode
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@ -188,7 +195,7 @@ void ${typeName}FixedValueFvPatchScalarField::updateCoeffs()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//{{{ begin code
|
//{{{ begin code
|
||||||
${code};
|
${code}
|
||||||
//}}} end code
|
//}}} end code
|
||||||
|
|
||||||
fixedValueFvPatchScalarField::updateCoeffs();
|
fixedValueFvPatchScalarField::updateCoeffs();
|
||||||
|
@ -373,6 +373,7 @@ void Foam::dynamicCode::setFilterContext
|
|||||||
const dynamicCodeContext& context
|
const dynamicCodeContext& context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
filterVars_.set("localCode", context.localCode());
|
||||||
filterVars_.set("code", context.code());
|
filterVars_.set("code", context.code());
|
||||||
filterVars_.set("codeInclude", context.include());
|
filterVars_.set("codeInclude", context.include());
|
||||||
filterVars_.set("SHA1sum", context.sha1().str());
|
filterVars_.set("SHA1sum", context.sha1().str());
|
||||||
|
@ -35,6 +35,7 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
|
|||||||
:
|
:
|
||||||
dict_(dict),
|
dict_(dict),
|
||||||
code_(stringOps::trim(dict["code"])),
|
code_(stringOps::trim(dict["code"])),
|
||||||
|
localCode_(),
|
||||||
include_(),
|
include_(),
|
||||||
options_()
|
options_()
|
||||||
{
|
{
|
||||||
@ -45,6 +46,13 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
|
|||||||
// - necessary for compilation options, convenient for includes
|
// - necessary for compilation options, convenient for includes
|
||||||
// and body.
|
// and body.
|
||||||
|
|
||||||
|
// optional
|
||||||
|
if (dict.found("localCode"))
|
||||||
|
{
|
||||||
|
localCode_ = stringOps::trim(dict["localCode"]);
|
||||||
|
stringOps::inplaceExpand(localCode_, dict);
|
||||||
|
}
|
||||||
|
|
||||||
// optional
|
// optional
|
||||||
if (dict.found("codeInclude"))
|
if (dict.found("codeInclude"))
|
||||||
{
|
{
|
||||||
@ -59,9 +67,9 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
|
|||||||
stringOps::inplaceExpand(options_, dict);
|
stringOps::inplaceExpand(options_, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate SHA1 digest from include, options, code
|
// calculate SHA1 digest from include, options, localCode, code
|
||||||
OSHA1stream os;
|
OSHA1stream os;
|
||||||
os << include_ << options_ << code_;
|
os << include_ << options_ << localCode_ << code_;
|
||||||
sha1_ = os.digest();
|
sha1_ = os.digest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,9 @@ class dynamicCodeContext
|
|||||||
//- Mandatory "code" entry
|
//- Mandatory "code" entry
|
||||||
string code_;
|
string code_;
|
||||||
|
|
||||||
|
//- Optional "localCode" entry
|
||||||
|
string localCode_;
|
||||||
|
|
||||||
//- Optional "codeInclude" entry
|
//- Optional "codeInclude" entry
|
||||||
string include_;
|
string include_;
|
||||||
|
|
||||||
@ -99,6 +102,12 @@ public:
|
|||||||
return code_;
|
return code_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//- Return the local (file-scope) code
|
||||||
|
const string& localCode() const
|
||||||
|
{
|
||||||
|
return localCode_;
|
||||||
|
}
|
||||||
|
|
||||||
//- Return SHA1 digest calculated from include, options, code
|
//- Return SHA1 digest calculated from include, options, code
|
||||||
const SHA1Digest& sha1() const
|
const SHA1Digest& sha1() const
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user