mirror of
https://github.com/OpenFOAM/OpenFOAM-6.git
synced 2025-12-08 06:57:46 +00:00
dynamicCode: the "code" entry is now optional
codedFunctionObject: Added the "codeWrite" entry
for the "write" function for consistency.
The previous method of using the "code" entry for the "write"
function was inconsistent and very confusing.
This commit is contained in:
@ -136,6 +136,21 @@ bool ${typeName}FunctionObject::execute(const bool postProcess)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ${typeName}FunctionObject::write(const bool postProcess)
|
||||||
|
{
|
||||||
|
if (${verbose:-false})
|
||||||
|
{
|
||||||
|
Info<<"write ${typeName} sha1: ${SHA1sum}\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//{{{ begin code
|
||||||
|
${codeWrite}
|
||||||
|
//}}} end code
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ${typeName}FunctionObject::end()
|
bool ${typeName}FunctionObject::end()
|
||||||
{
|
{
|
||||||
if (${verbose:-false})
|
if (${verbose:-false})
|
||||||
@ -151,36 +166,6 @@ bool ${typeName}FunctionObject::end()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ${typeName}FunctionObject::timeSet()
|
|
||||||
{
|
|
||||||
if (${verbose:-false})
|
|
||||||
{
|
|
||||||
Info<<"timeSet ${typeName} sha1: ${SHA1sum}\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
//{{{ begin codeTime
|
|
||||||
${codeTimeSet}
|
|
||||||
//}}} end code
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ${typeName}FunctionObject::write(const bool postProcess)
|
|
||||||
{
|
|
||||||
if (${verbose:-false})
|
|
||||||
{
|
|
||||||
Info<<"write ${typeName} sha1: ${SHA1sum}\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
//{{{ begin code
|
|
||||||
${code}
|
|
||||||
//}}} end code
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|||||||
@ -107,9 +107,6 @@ public:
|
|||||||
|
|
||||||
//- Write, execute the "writeCalls"
|
//- Write, execute the "writeCalls"
|
||||||
virtual bool write(const bool postProcess = false);
|
virtual bool write(const bool postProcess = false);
|
||||||
|
|
||||||
//- Called when time was set at the end of the Time::operator++
|
|
||||||
virtual bool timeSet();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -27,7 +27,6 @@ License
|
|||||||
#include "stringOps.H"
|
#include "stringOps.H"
|
||||||
#include "OSHA1stream.H"
|
#include "OSHA1stream.H"
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
|
Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
|
||||||
@ -39,19 +38,24 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
|
|||||||
options_(),
|
options_(),
|
||||||
libs_()
|
libs_()
|
||||||
{
|
{
|
||||||
// expand dictionary entries
|
// Expand dictionary entries
|
||||||
|
|
||||||
{
|
// Note: removes any leading/trailing whitespace
|
||||||
const entry& codeEntry = dict.lookupEntry("code", false, false);
|
|
||||||
code_ = stringOps::trim(codeEntry.stream());
|
|
||||||
stringOps::inplaceExpand(code_, dict);
|
|
||||||
}
|
|
||||||
|
|
||||||
// note: removes any leading/trailing whitespace
|
|
||||||
// - necessary for compilation options, convenient for includes
|
// - necessary for compilation options, convenient for includes
|
||||||
// and body.
|
// and body.
|
||||||
|
|
||||||
// optional
|
const entry* codePtr = dict.lookupEntryPtr
|
||||||
|
(
|
||||||
|
"code",
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
if (codePtr)
|
||||||
|
{
|
||||||
|
code_ = stringOps::trim(codePtr->stream());
|
||||||
|
stringOps::inplaceExpand(code_, dict);
|
||||||
|
}
|
||||||
|
|
||||||
const entry* includePtr = dict.lookupEntryPtr
|
const entry* includePtr = dict.lookupEntryPtr
|
||||||
(
|
(
|
||||||
"codeInclude",
|
"codeInclude",
|
||||||
@ -64,7 +68,6 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
|
|||||||
stringOps::inplaceExpand(include_, dict);
|
stringOps::inplaceExpand(include_, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// optional
|
|
||||||
const entry* optionsPtr = dict.lookupEntryPtr
|
const entry* optionsPtr = dict.lookupEntryPtr
|
||||||
(
|
(
|
||||||
"codeOptions",
|
"codeOptions",
|
||||||
@ -77,7 +80,6 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
|
|||||||
stringOps::inplaceExpand(options_, dict);
|
stringOps::inplaceExpand(options_, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// optional
|
|
||||||
const entry* libsPtr = dict.lookupEntryPtr("codeLibs", false, false);
|
const entry* libsPtr = dict.lookupEntryPtr("codeLibs", false, false);
|
||||||
if (libsPtr)
|
if (libsPtr)
|
||||||
{
|
{
|
||||||
@ -85,7 +87,6 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
|
|||||||
stringOps::inplaceExpand(libs_, dict);
|
stringOps::inplaceExpand(libs_, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// optional
|
|
||||||
const entry* localPtr = dict.lookupEntryPtr("localCode", false, false);
|
const entry* localPtr = dict.lookupEntryPtr("localCode", false, false);
|
||||||
if (localPtr)
|
if (localPtr)
|
||||||
{
|
{
|
||||||
@ -93,20 +94,20 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
|
|||||||
stringOps::inplaceExpand(localCode_, dict);
|
stringOps::inplaceExpand(localCode_, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate SHA1 digest from include, options, localCode, code
|
// Calculate SHA1 digest from include, options, localCode, code
|
||||||
OSHA1stream os;
|
OSHA1stream os;
|
||||||
os << include_ << options_ << libs_ << localCode_ << code_;
|
os << include_ << options_ << libs_ << localCode_ << code_;
|
||||||
sha1_ = os.digest();
|
sha1_ = os.digest();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Add line number after calculating sha1 since includes processorDDD
|
// Add line number after calculating sha1 since includes processorDDD
|
||||||
// in path which differs between processors.
|
// in path which differs between processors.
|
||||||
|
|
||||||
|
if (codePtr)
|
||||||
{
|
{
|
||||||
const entry& codeEntry = dict.lookupEntry("code", false, false);
|
addLineDirective(code_, codePtr->startLineNumber(), dict.name());
|
||||||
addLineDirective(code_, codeEntry.startLineNumber(), dict.name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includePtr)
|
if (includePtr)
|
||||||
{
|
{
|
||||||
addLineDirective(include_, includePtr->startLineNumber(), dict.name());
|
addLineDirective(include_, includePtr->startLineNumber(), dict.name());
|
||||||
@ -114,7 +115,6 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
|
|||||||
|
|
||||||
// Do not add line directive to options_ (Make/options) and libs since
|
// Do not add line directive to options_ (Make/options) and libs since
|
||||||
// they are preprocessed as a single line at this point. Can be fixed.
|
// they are preprocessed as a single line at this point. Can be fixed.
|
||||||
|
|
||||||
if (localPtr)
|
if (localPtr)
|
||||||
{
|
{
|
||||||
addLineDirective(localCode_, localPtr->startLineNumber(), dict.name());
|
addLineDirective(localCode_, localPtr->startLineNumber(), dict.name());
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -54,7 +54,7 @@ class dynamicCodeContext
|
|||||||
//- The parent dictionary context
|
//- The parent dictionary context
|
||||||
const dictionary& dict_;
|
const dictionary& dict_;
|
||||||
|
|
||||||
//- Mandatory "code" entry
|
//- Optional "code" entry
|
||||||
string code_;
|
string code_;
|
||||||
|
|
||||||
//- Optional "localCode" entry
|
//- Optional "localCode" entry
|
||||||
@ -72,6 +72,7 @@ class dynamicCodeContext
|
|||||||
//- Calculated SHA1Digest
|
//- Calculated SHA1Digest
|
||||||
SHA1Digest sha1_;
|
SHA1Digest sha1_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
@ -79,6 +80,7 @@ public:
|
|||||||
//- Construct from a dictionary
|
//- Construct from a dictionary
|
||||||
dynamicCodeContext(const dictionary&);
|
dynamicCodeContext(const dictionary&);
|
||||||
|
|
||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
|
|
||||||
//- Return the parent dictionary context
|
//- Return the parent dictionary context
|
||||||
@ -130,7 +132,6 @@ public:
|
|||||||
const label lineNum,
|
const label lineNum,
|
||||||
const fileName& name
|
const fileName& name
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -57,12 +57,11 @@ void Foam::codedFunctionObject::prepare
|
|||||||
{
|
{
|
||||||
// Set additional rewrite rules
|
// Set additional rewrite rules
|
||||||
dynCode.setFilterVariable("typeName", redirectType_);
|
dynCode.setFilterVariable("typeName", redirectType_);
|
||||||
|
dynCode.setFilterVariable("codeData", codeData_);
|
||||||
dynCode.setFilterVariable("codeRead", codeRead_);
|
dynCode.setFilterVariable("codeRead", codeRead_);
|
||||||
dynCode.setFilterVariable("codeExecute", codeExecute_);
|
dynCode.setFilterVariable("codeExecute", codeExecute_);
|
||||||
|
dynCode.setFilterVariable("codeWrite", codeWrite_);
|
||||||
dynCode.setFilterVariable("codeEnd", codeEnd_);
|
dynCode.setFilterVariable("codeEnd", codeEnd_);
|
||||||
dynCode.setFilterVariable("codeData", codeData_);
|
|
||||||
dynCode.setFilterVariable("codeTimeSet", codeTimeSet_);
|
|
||||||
//dynCode.setFilterVariable("codeWrite", codeWrite_);
|
|
||||||
|
|
||||||
// Compile filtered C template
|
// Compile filtered C template
|
||||||
dynCode.addCompileFile("functionObjectTemplate.C");
|
dynCode.addCompileFile("functionObjectTemplate.C");
|
||||||
@ -71,9 +70,9 @@ void Foam::codedFunctionObject::prepare
|
|||||||
dynCode.addCopyFile("functionObjectTemplate.H");
|
dynCode.addCopyFile("functionObjectTemplate.H");
|
||||||
|
|
||||||
// Debugging: make BC verbose
|
// Debugging: make BC verbose
|
||||||
// dynCode.setFilterVariable("verbose", "true");
|
// dynCode.setFilterVariable("verbose", "true");
|
||||||
// Info<<"compile " << redirectType_ << " sha1: "
|
// Info<<"compile " << redirectType_ << " sha1: "
|
||||||
// << context.sha1() << endl;
|
// << context.sha1() << endl;
|
||||||
|
|
||||||
// Define Make/options
|
// Define Make/options
|
||||||
dynCode.setMakeOptions
|
dynCode.setMakeOptions
|
||||||
@ -81,12 +80,12 @@ void Foam::codedFunctionObject::prepare
|
|||||||
"EXE_INC = -g \\\n"
|
"EXE_INC = -g \\\n"
|
||||||
"-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
|
"-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
|
||||||
"-I$(LIB_SRC)/meshTools/lnInclude \\\n"
|
"-I$(LIB_SRC)/meshTools/lnInclude \\\n"
|
||||||
+ context.options()
|
+ context.options()
|
||||||
+ "\n\nLIB_LIBS = \\\n"
|
+ "\n\nLIB_LIBS = \\\n"
|
||||||
+ " -lOpenFOAM \\\n"
|
+ " -lOpenFOAM \\\n"
|
||||||
+ " -lfiniteVolume \\\n"
|
+ " -lfiniteVolume \\\n"
|
||||||
+ " -lmeshTools \\\n"
|
+ " -lmeshTools \\\n"
|
||||||
+ context.libs()
|
+ context.libs()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,13 +182,6 @@ bool Foam::codedFunctionObject::end()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::codedFunctionObject::timeSet()
|
|
||||||
{
|
|
||||||
updateLibrary(redirectType_);
|
|
||||||
return redirectFunctionObject().timeSet();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Foam::codedFunctionObject::read(const dictionary& dict)
|
bool Foam::codedFunctionObject::read(const dictionary& dict)
|
||||||
{
|
{
|
||||||
dict.lookup("redirectType") >> redirectType_;
|
dict.lookup("redirectType") >> redirectType_;
|
||||||
@ -248,6 +240,24 @@ bool Foam::codedFunctionObject::read(const dictionary& dict)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const entry* writePtr = dict.lookupEntryPtr
|
||||||
|
(
|
||||||
|
"codeWrite",
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
if (writePtr)
|
||||||
|
{
|
||||||
|
codeWrite_ = stringOps::trim(writePtr->stream());
|
||||||
|
stringOps::inplaceExpand(codeWrite_, dict);
|
||||||
|
dynamicCodeContext::addLineDirective
|
||||||
|
(
|
||||||
|
codeWrite_,
|
||||||
|
writePtr->startLineNumber(),
|
||||||
|
dict.name()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const entry* endPtr = dict.lookupEntryPtr
|
const entry* endPtr = dict.lookupEntryPtr
|
||||||
(
|
(
|
||||||
"codeEnd",
|
"codeEnd",
|
||||||
@ -266,24 +276,6 @@ bool Foam::codedFunctionObject::read(const dictionary& dict)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const entry* timeSetPtr = dict.lookupEntryPtr
|
|
||||||
(
|
|
||||||
"codeTimeSet",
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
if (timeSetPtr)
|
|
||||||
{
|
|
||||||
codeTimeSet_ = stringOps::trim(timeSetPtr->stream());
|
|
||||||
stringOps::inplaceExpand(codeTimeSet_, dict);
|
|
||||||
dynamicCodeContext::addLineDirective
|
|
||||||
(
|
|
||||||
codeTimeSet_,
|
|
||||||
timeSetPtr->startLineNumber(),
|
|
||||||
dict.name()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateLibrary(redirectType_);
|
updateLibrary(redirectType_);
|
||||||
return redirectFunctionObject().read(dict);
|
return redirectFunctionObject().read(dict);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,6 @@ Description
|
|||||||
codeRead : c++; upon functionObject::read();
|
codeRead : c++; upon functionObject::read();
|
||||||
codeEnd : c++; upon functionObject::end();
|
codeEnd : c++; upon functionObject::end();
|
||||||
codeData : c++; local member data (null constructed);
|
codeData : c++; local member data (null constructed);
|
||||||
codeTimeSet : c++; upon functionObject::timeSet();
|
|
||||||
localCode : c++; local static functions
|
localCode : c++; local static functions
|
||||||
|
|
||||||
Example of function object specification:
|
Example of function object specification:
|
||||||
@ -108,8 +107,8 @@ protected:
|
|||||||
string codeData_;
|
string codeData_;
|
||||||
string codeRead_;
|
string codeRead_;
|
||||||
string codeExecute_;
|
string codeExecute_;
|
||||||
|
string codeWrite_;
|
||||||
string codeEnd_;
|
string codeEnd_;
|
||||||
string codeTimeSet_;
|
|
||||||
|
|
||||||
//- Underlying functionObject
|
//- Underlying functionObject
|
||||||
mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
|
mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
|
||||||
@ -182,9 +181,6 @@ public:
|
|||||||
// By default it simply calls execute().
|
// By default it simply calls execute().
|
||||||
virtual bool end();
|
virtual bool end();
|
||||||
|
|
||||||
//- Called when time was set at the end of the Time::operator++
|
|
||||||
virtual bool timeSet();
|
|
||||||
|
|
||||||
//- Read and set the function object if its data have changed
|
//- Read and set the function object if its data have changed
|
||||||
virtual bool read(const dictionary&);
|
virtual bool read(const dictionary&);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -54,11 +54,10 @@ functions
|
|||||||
|
|
||||||
type coded;
|
type coded;
|
||||||
|
|
||||||
writeControl timeStep;
|
|
||||||
|
|
||||||
// Name of on-the-fly generated functionObject
|
// Name of on-the-fly generated functionObject
|
||||||
redirectType error;
|
redirectType error;
|
||||||
code
|
|
||||||
|
codeEnd
|
||||||
#{
|
#{
|
||||||
// Lookup U
|
// Lookup U
|
||||||
Info<< "Looking up field U\n" << endl;
|
Info<< "Looking up field U\n" << endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user