Commit 38b99504 authored by Henry Weller's avatar Henry Weller
Browse files

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.
parent 83517fac
......@@ -136,45 +136,30 @@ bool ${typeName}FunctionObject::execute(const bool postProcess)
}
bool ${typeName}FunctionObject::end()
bool ${typeName}FunctionObject::write(const bool postProcess)
{
if (${verbose:-false})
{
Info<<"end ${typeName} sha1: ${SHA1sum}\n";
Info<<"write ${typeName} sha1: ${SHA1sum}\n";
}
//{{{ begin code
${codeEnd}
${codeWrite}
//}}} end code
return true;
}
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)
bool ${typeName}FunctionObject::end()
{
if (${verbose:-false})
{
Info<<"write ${typeName} sha1: ${SHA1sum}\n";
Info<<"end ${typeName} sha1: ${SHA1sum}\n";
}
//{{{ begin code
${code}
${codeEnd}
//}}} end code
return true;
......
......@@ -107,9 +107,6 @@ public:
//- Write, execute the "writeCalls"
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
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -27,7 +27,6 @@ License
#include "stringOps.H"
#include "OSHA1stream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
......@@ -39,19 +38,24 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
options_(),
libs_()
{
// expand dictionary entries
// Expand dictionary entries
// Note: removes any leading/trailing whitespace
// - necessary for compilation options, convenient for includes
// and body.
const entry* codePtr = dict.lookupEntryPtr
(
"code",
false,
false
);
if (codePtr)
{
const entry& codeEntry = dict.lookupEntry("code", false, false);
code_ = stringOps::trim(codeEntry.stream());
code_ = stringOps::trim(codePtr->stream());
stringOps::inplaceExpand(code_, dict);
}
// note: removes any leading/trailing whitespace
// - necessary for compilation options, convenient for includes
// and body.
// optional
const entry* includePtr = dict.lookupEntryPtr
(
"codeInclude",
......@@ -64,7 +68,6 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
stringOps::inplaceExpand(include_, dict);
}
// optional
const entry* optionsPtr = dict.lookupEntryPtr
(
"codeOptions",
......@@ -77,7 +80,6 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
stringOps::inplaceExpand(options_, dict);
}
// optional
const entry* libsPtr = dict.lookupEntryPtr("codeLibs", false, false);
if (libsPtr)
{
......@@ -85,7 +87,6 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
stringOps::inplaceExpand(libs_, dict);
}
// optional
const entry* localPtr = dict.lookupEntryPtr("localCode", false, false);
if (localPtr)
{
......@@ -93,20 +94,20 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
stringOps::inplaceExpand(localCode_, dict);
}
// calculate SHA1 digest from include, options, localCode, code
// Calculate SHA1 digest from include, options, localCode, code
OSHA1stream os;
os << include_ << options_ << libs_ << localCode_ << code_;
sha1_ = os.digest();
// Add line number after calculating sha1 since includes processorDDD
// in path which differs between processors.
if (codePtr)
{
const entry& codeEntry = dict.lookupEntry("code", false, false);
addLineDirective(code_, codeEntry.startLineNumber(), dict.name());
addLineDirective(code_, codePtr->startLineNumber(), dict.name());
}
if (includePtr)
{
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
// they are preprocessed as a single line at this point. Can be fixed.
if (localPtr)
{
addLineDirective(localCode_, localPtr->startLineNumber(), dict.name());
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -54,7 +54,7 @@ class dynamicCodeContext
//- The parent dictionary context
const dictionary& dict_;
//- Mandatory "code" entry
//- Optional "code" entry
string code_;
//- Optional "localCode" entry
......@@ -72,6 +72,7 @@ class dynamicCodeContext
//- Calculated SHA1Digest
SHA1Digest sha1_;
public:
// Constructors
......@@ -79,6 +80,7 @@ public:
//- Construct from a dictionary
dynamicCodeContext(const dictionary&);
// Member functions
//- Return the parent dictionary context
......@@ -130,7 +132,6 @@ public:
const label lineNum,
const fileName& name
);
};
......
......@@ -57,12 +57,11 @@ void Foam::codedFunctionObject::prepare
{
// Set additional rewrite rules
dynCode.setFilterVariable("typeName", redirectType_);
dynCode.setFilterVariable("codeData", codeData_);
dynCode.setFilterVariable("codeRead", codeRead_);
dynCode.setFilterVariable("codeExecute", codeExecute_);
dynCode.setFilterVariable("codeWrite", codeWrite_);
dynCode.setFilterVariable("codeEnd", codeEnd_);
dynCode.setFilterVariable("codeData", codeData_);
dynCode.setFilterVariable("codeTimeSet", codeTimeSet_);
//dynCode.setFilterVariable("codeWrite", codeWrite_);
// Compile filtered C template
dynCode.addCompileFile("functionObjectTemplate.C");
......@@ -71,9 +70,9 @@ void Foam::codedFunctionObject::prepare
dynCode.addCopyFile("functionObjectTemplate.H");
// Debugging: make BC verbose
// dynCode.setFilterVariable("verbose", "true");
// Info<<"compile " << redirectType_ << " sha1: "
// << context.sha1() << endl;
// dynCode.setFilterVariable("verbose", "true");
// Info<<"compile " << redirectType_ << " sha1: "
// << context.sha1() << endl;
// Define Make/options
dynCode.setMakeOptions
......@@ -81,12 +80,12 @@ void Foam::codedFunctionObject::prepare
"EXE_INC = -g \\\n"
"-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
"-I$(LIB_SRC)/meshTools/lnInclude \\\n"
+ context.options()
+ "\n\nLIB_LIBS = \\\n"
+ " -lOpenFOAM \\\n"
+ " -lfiniteVolume \\\n"
+ " -lmeshTools \\\n"
+ context.libs()
+ context.options()
+ "\n\nLIB_LIBS = \\\n"
+ " -lOpenFOAM \\\n"
+ " -lfiniteVolume \\\n"
+ " -lmeshTools \\\n"
+ 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)
{
dict.lookup("redirectType") >> redirectType_;
......@@ -248,38 +240,38 @@ bool Foam::codedFunctionObject::read(const dictionary& dict)
);
}
const entry* endPtr = dict.lookupEntryPtr
const entry* writePtr = dict.lookupEntryPtr
(
"codeEnd",
"codeWrite",
false,
false
);
if (endPtr)
if (writePtr)
{
codeEnd_ = stringOps::trim(endPtr->stream());
stringOps::inplaceExpand(codeEnd_, dict);
codeWrite_ = stringOps::trim(writePtr->stream());
stringOps::inplaceExpand(codeWrite_, dict);
dynamicCodeContext::addLineDirective
(
codeEnd_,
endPtr->startLineNumber(),
codeWrite_,
writePtr->startLineNumber(),
dict.name()
);
}
const entry* timeSetPtr = dict.lookupEntryPtr
const entry* endPtr = dict.lookupEntryPtr
(
"codeTimeSet",
"codeEnd",
false,
false
);
if (timeSetPtr)
if (endPtr)
{
codeTimeSet_ = stringOps::trim(timeSetPtr->stream());
stringOps::inplaceExpand(codeTimeSet_, dict);
codeEnd_ = stringOps::trim(endPtr->stream());
stringOps::inplaceExpand(codeEnd_, dict);
dynamicCodeContext::addLineDirective
(
codeTimeSet_,
timeSetPtr->startLineNumber(),
codeEnd_,
endPtr->startLineNumber(),
dict.name()
);
}
......
......@@ -41,7 +41,6 @@ Description
codeRead : c++; upon functionObject::read();
codeEnd : c++; upon functionObject::end();
codeData : c++; local member data (null constructed);
codeTimeSet : c++; upon functionObject::timeSet();
localCode : c++; local static functions
Example of function object specification:
......@@ -108,8 +107,8 @@ protected:
string codeData_;
string codeRead_;
string codeExecute_;
string codeWrite_;
string codeEnd_;
string codeTimeSet_;
//- Underlying functionObject
mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
......@@ -182,9 +181,6 @@ public:
// By default it simply calls execute().
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
virtual bool read(const dictionary&);
};
......
......@@ -54,11 +54,10 @@ functions
type coded;
writeControl timeStep;
// Name of on-the-fly generated functionObject
redirectType error;
code
codeEnd
#{
// Lookup U
Info<< "Looking up field U\n" << endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment