dynamicCode: Put code entries on a list

The dynamic code functionality has been generalised so that the names of
the code entries in the specifying dictionary can be set by the caller.
This means that functions which utilise dynamic code but use different
entry names (e.g., codedFunctionObject uses codeExecute, codeEnd,
etc..., instead of code) now function correctly. The differently named
entries now form part of the library hash, and re-building triggers
appropriately as they are modified.
This commit is contained in:
Will Bainbridge
2019-01-31 15:00:57 +00:00
parent 0497d2a170
commit 700f11fa11
19 changed files with 298 additions and 415 deletions

View File

@ -80,15 +80,6 @@ Description
#{
Pout<< "**codeSetValue**" << endl;
#};
// Dummy entry. Make dependent on above to trigger recompilation
code
#{
$codeInclude
$codeCorrect
$codeAddSup
$codeSetValue
#};
}
sourceTimeCoeffs

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -59,8 +59,8 @@ namespace functionEntries
}
const Foam::word Foam::functionEntries::codeStream::codeTemplateC
= "codeStreamTemplate.C";
const Foam::word Foam::functionEntries::codeStream::codeTemplateC =
"codeStreamTemplate.C";
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -123,8 +123,8 @@ Foam::functionEntries::codeStream::getFunction
const dictionary& codeDict
)
{
// get code, codeInclude, codeOptions
dynamicCodeContext context(codeDict);
// get code, codeInclude, ...
dynamicCodeContext context(codeDict, {"code", "codeInclude", "localCode"});
// codeName: codeStream + _<sha1>
// codeDir : _<sha1>

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -293,7 +293,7 @@ void Foam::codedBase::updateLibrary
dict
);
dynamicCodeContext context(dict);
dynamicCodeContext context(dict, codeKeys());
// codeName: name + _<sha1>
// codeDir : name

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -92,30 +92,26 @@ class codedBase
protected:
//- Update library as required
void updateLibrary
(
const word& name
) const;
void updateLibrary(const word& name) const;
//- Get the loaded dynamic libraries
virtual dlLibraryTable& libs() const = 0;
//- Adapt the context for the current object
virtual void prepare
(
dynamicCode&,
const dynamicCodeContext&
) const = 0;
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const = 0;
// Return a description (type + name) for the output
//- Return a description (type + name) for the output
virtual string description() const = 0;
// Clear any redirected objects
//- Clear any redirected objects
virtual void clearRedirect() const = 0;
// Get the dictionary to initialize the codeContext
//- Get the dictionary to initialize the codeContext
virtual const dictionary& codeDict() const = 0;
//- Get the keywords associated with source code
virtual const wordList& codeKeys() const = 0;
public:

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -343,7 +343,13 @@ void Foam::dynamicCode::reset
)
{
clear();
setFilterContext(context);
forAllConstIter(HashTable<string>, context.code(), iter)
{
setFilterVariable(iter.key(), iter());
}
setFilterVariable("SHA1sum", context.sha1().str());
}
@ -369,18 +375,6 @@ void Foam::dynamicCode::addCreateFile
}
void Foam::dynamicCode::setFilterContext
(
const dynamicCodeContext& context
)
{
filterVars_.set("localCode", context.localCode());
filterVars_.set("code", context.code());
filterVars_.set("codeInclude", context.include());
filterVars_.set("SHA1sum", context.sha1().str());
}
void Foam::dynamicCode::setFilterVariable
(
const word& key,

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -259,9 +259,6 @@ public:
//- Add a file to create with its contents. Will not be filtered
void addCreateFile(const fileName& name, const string& contents);
//- Define filter variables for code, codeInclude, SHA1sum
void setFilterContext(const dynamicCodeContext&);
//- Define a filter variable
void setFilterVariable(const word& key, const std::string& value);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -27,102 +27,7 @@ License
#include "stringOps.H"
#include "OSHA1stream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
:
dict_(dict),
code_(),
localCode_(),
include_(),
options_(),
libs_()
{
// 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)
{
code_ = stringOps::trim(codePtr->stream());
stringOps::inplaceExpand(code_, dict);
}
const entry* includePtr = dict.lookupEntryPtr
(
"codeInclude",
false,
false
);
if (includePtr)
{
include_ = stringOps::trim(includePtr->stream());
stringOps::inplaceExpand(include_, dict);
}
const entry* optionsPtr = dict.lookupEntryPtr
(
"codeOptions",
false,
false
);
if (optionsPtr)
{
options_ = stringOps::trim(optionsPtr->stream());
stringOps::inplaceExpand(options_, dict);
}
const entry* libsPtr = dict.lookupEntryPtr("codeLibs", false, false);
if (libsPtr)
{
libs_ = stringOps::trim(libsPtr->stream());
stringOps::inplaceExpand(libs_, dict);
}
const entry* localPtr = dict.lookupEntryPtr("localCode", false, false);
if (localPtr)
{
localCode_ = stringOps::trim(localPtr->stream());
stringOps::inplaceExpand(localCode_, dict);
}
// 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)
{
addLineDirective(code_, codePtr->startLineNumber(), dict.name());
}
if (includePtr)
{
addLineDirective(include_, includePtr->startLineNumber(), dict.name());
}
// 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());
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::dynamicCodeContext::addLineDirective
(
@ -135,4 +40,69 @@ void Foam::dynamicCodeContext::addLineDirective
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::dynamicCodeContext::dynamicCodeContext
(
const dictionary& dict,
const wordList& codeKeys
)
:
dict_(dict),
code_(),
options_(),
libs_()
{
// Expand all dictionary entries. Note that this removes any leading or
// trailing whitespace, which is necessary for compilation options, and
// doesn't hurt for everything else
List<const entry*> codePtrs(codeKeys.size(), nullptr);
forAll(codeKeys, i)
{
const word& key = codeKeys[i];
codePtrs[i] = dict.lookupEntryPtr(key, false, false);
if (codePtrs[i])
{
code_.insert
(
key,
stringOps::expand
(
stringOps::trim(codePtrs[i]->stream()),
dict
)
);
}
else
{
code_.insert(key, "");
}
}
// Calculate SHA1 digest from all entries
OSHA1stream os;
forAllConstIter(HashTable<string>, code_, iter)
{
os << iter();
}
sha1_ = os.digest();
// Add line directive after calculating SHA1 since this includes
// "processor..." in the path which differs between cores
forAll(codeKeys, i)
{
if (codePtrs[i])
{
const word& key = codeKeys[i];
addLineDirective
(
code_[key],
codePtrs[i]->startLineNumber(),
dict.name()
);
}
}
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -36,6 +36,7 @@ SourceFiles
#define dynamicCodeContext_H
#include "dictionary.H"
#include "HashTable.H"
#include "SHA1Digest.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -54,31 +55,42 @@ class dynamicCodeContext
//- The parent dictionary context
const dictionary& dict_;
//- Optional "code" entry
string code_;
//- Optional "localCode" entry
string localCode_;
//- Optional "codeInclude" entry
string include_;
//- Code entries
HashTable<string> code_;
//- Optional "codeOptions" entry
string options_;
//- Optional "codeLib" entry
//- Optional "codeLibs" entry
string libs_;
//- Calculated SHA1Digest
SHA1Digest sha1_;
// Private member functions
//- Add a \#line directive to the start of the given source string that
// compilation messages are meaningful
static void addLineDirective
(
string&,
const label lineNum,
const fileName& name
);
public:
// Constructors
//- Construct from a dictionary
dynamicCodeContext(const dictionary&);
//- Construct from a dictionary and lists of which entries correspond
// to code
dynamicCodeContext
(
const dictionary& dict,
const wordList& codeKeys
);
// Member functions
@ -89,10 +101,10 @@ public:
return dict_;
}
//- Return the code-includes
const string& include() const
//- Return the code table
const HashTable<string>& code() const
{
return include_;
return code_;
}
//- Return the code-options
@ -107,31 +119,11 @@ public:
return libs_;
}
//- Return the code
const string& code() const
{
return code_;
}
//- Return the local (file-scope) code
const string& localCode() const
{
return localCode_;
}
//- Return SHA1 digest calculated from include, options, code
const SHA1Digest& sha1() const
{
return sha1_;
}
//- Helper: add \#line directive
static void addLineDirective
(
string&,
const label lineNum,
const fileName& name
);
};

View File

@ -31,15 +31,22 @@ License
#include "dynamicCodeContext.H"
#include "stringOps.H"
// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * //
template<class Type>
const Foam::wordList Foam::codedFixedValuePointPatchField<Type>::codeKeys_ =
{"code", "codeInclude", "localCode"};
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class Type>
const Foam::word Foam::codedFixedValuePointPatchField<Type>::codeTemplateC
= "fixedValuePointPatchFieldTemplate.C";
const Foam::word Foam::codedFixedValuePointPatchField<Type>::codeTemplateC =
"fixedValuePointPatchFieldTemplate.C";
template<class Type>
const Foam::word Foam::codedFixedValuePointPatchField<Type>::codeTemplateH
= "fixedValuePointPatchFieldTemplate.H";
const Foam::word Foam::codedFixedValuePointPatchField<Type>::codeTemplateH =
"fixedValuePointPatchFieldTemplate.H";
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -141,8 +148,8 @@ void Foam::codedFixedValuePointPatchField<Type>::prepare
template<class Type>
const Foam::dictionary& Foam::codedFixedValuePointPatchField<Type>::codeDict()
const
const Foam::dictionary&
Foam::codedFixedValuePointPatchField<Type>::codeDict() const
{
// Use system/codeDict or in-line
return
@ -154,6 +161,14 @@ const
}
template<class Type>
const Foam::wordList&
Foam::codedFixedValuePointPatchField<Type>::codeKeys() const
{
return codeKeys_;
}
template<class Type>
Foam::string Foam::codedFixedValuePointPatchField<Type>::description() const
{

View File

@ -105,6 +105,12 @@ class codedFixedValuePointPatchField
public fixedValuePointPatchField<Type>,
public codedBase
{
// Private static data
//- The keywords associated with source code
static const wordList codeKeys_;
// Private data
//- Dictionary contents for the boundary condition
@ -128,15 +134,18 @@ class codedFixedValuePointPatchField
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
// Return a description (type + name) for the output
//- Return a description (type + name) for the output
virtual string description() const;
// Clear the ptr to the redirected object
//- Clear the ptr to the redirected object
virtual void clearRedirect() const;
// Get the dictionary to initialize the codeContext
//- Get the dictionary to initialize the codeContext
virtual const dictionary& codeDict() const;
//- Get the keywords associated with source code
virtual const wordList& codeKeys() const;
public:

View File

@ -31,15 +31,22 @@ License
#include "dynamicCodeContext.H"
#include "stringOps.H"
// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * //
template<class Type>
const Foam::wordList Foam::codedFixedValueFvPatchField<Type>::codeKeys_ =
{"code", "codeInclude", "localCode"};
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class Type>
const Foam::word Foam::codedFixedValueFvPatchField<Type>::codeTemplateC
= "fixedValueFvPatchFieldTemplate.C";
const Foam::word Foam::codedFixedValueFvPatchField<Type>::codeTemplateC =
"fixedValueFvPatchFieldTemplate.C";
template<class Type>
const Foam::word Foam::codedFixedValueFvPatchField<Type>::codeTemplateH
= "fixedValueFvPatchFieldTemplate.H";
const Foam::word Foam::codedFixedValueFvPatchField<Type>::codeTemplateH =
"fixedValueFvPatchFieldTemplate.H";
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -153,6 +160,13 @@ const
}
template<class Type>
const Foam::wordList& Foam::codedFixedValueFvPatchField<Type>::codeKeys() const
{
return codeKeys_;
}
template<class Type>
Foam::string Foam::codedFixedValueFvPatchField<Type>::description() const
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -103,6 +103,12 @@ class codedFixedValueFvPatchField
public fixedValueFvPatchField<Type>,
public codedBase
{
// Private static data
//- The keywords associated with source code
static const wordList codeKeys_;
// Private data
//- Dictionary contents for the boundary condition
@ -126,15 +132,18 @@ class codedFixedValueFvPatchField
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
// Return a description (type + name) for the output
//- Return a description (type + name) for the output
virtual string description() const;
// Clear the ptr to the redirected object
//- Clear the ptr to the redirected object
virtual void clearRedirect() const;
// Get the dictionary to initialize the codeContext
//- Get the dictionary to initialize the codeContext
virtual const dictionary& codeDict() const;
//- Get the keywords associated with source code
virtual const wordList& codeKeys() const;
public:

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -31,15 +31,22 @@ License
#include "dynamicCodeContext.H"
#include "stringOps.H"
// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * //
template<class Type>
const Foam::wordList Foam::codedMixedFvPatchField<Type>::codeKeys_ =
{"code", "codeInclude", "localCode"};
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class Type>
const Foam::word Foam::codedMixedFvPatchField<Type>::codeTemplateC
= "mixedFvPatchFieldTemplate.C";
const Foam::word Foam::codedMixedFvPatchField<Type>::codeTemplateC =
"mixedFvPatchFieldTemplate.C";
template<class Type>
const Foam::word Foam::codedMixedFvPatchField<Type>::codeTemplateH
= "mixedFvPatchFieldTemplate.H";
const Foam::word Foam::codedMixedFvPatchField<Type>::codeTemplateH =
"mixedFvPatchFieldTemplate.H";
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -153,6 +160,13 @@ const
}
template<class Type>
const Foam::wordList& Foam::codedMixedFvPatchField<Type>::codeKeys() const
{
return codeKeys_;
}
template<class Type>
Foam::string Foam::codedMixedFvPatchField<Type>::description() const
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -113,6 +113,12 @@ class codedMixedFvPatchField
public mixedFvPatchField<Type>,
public codedBase
{
// Private static data
//- The keywords associated with source code
static const wordList codeKeys_;
// Private data
//- Dictionary contents for the boundary condition
@ -136,15 +142,18 @@ class codedMixedFvPatchField
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
// Return a description (type + name) for the output
//- Return a description (type + name) for the output
virtual string description() const;
// Clear the ptr to the redirected object
//- Clear the ptr to the redirected object
virtual void clearRedirect() const;
// Get the dictionary to initialize the codeContext
//- Get the dictionary to initialize the codeContext
virtual const dictionary& codeDict() const;
//- Get the keywords associated with source code
virtual const wordList& codeKeys() const;
public:

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -33,6 +33,20 @@ License
#include "stringOps.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * Protected Static Data Members * * * * * * * * * * * //
const Foam::wordList Foam::codedFunctionObject::codeKeys_ =
{
"codeData",
"codeEnd",
"codeExecute",
"codeInclude",
"codeRead",
"codeWrite",
"localCode"
};
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
@ -47,6 +61,7 @@ namespace Foam
);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::codedFunctionObject::prepare
@ -55,13 +70,7 @@ void Foam::codedFunctionObject::prepare
const dynamicCodeContext& context
) const
{
// Set additional rewrite rules
dynCode.setFilterVariable("typeName", name_);
dynCode.setFilterVariable("codeData", codeData_);
dynCode.setFilterVariable("codeRead", codeRead_);
dynCode.setFilterVariable("codeExecute", codeExecute_);
dynCode.setFilterVariable("codeWrite", codeWrite_);
dynCode.setFilterVariable("codeEnd", codeEnd_);
// Compile filtered C template
dynCode.addCompileFile("functionObjectTemplate.C");
@ -114,6 +123,12 @@ const Foam::dictionary& Foam::codedFunctionObject::codeDict() const
}
const Foam::wordList& Foam::codedFunctionObject::codeKeys() const
{
return codeKeys_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::codedFunctionObject::codedFunctionObject
@ -129,9 +144,6 @@ Foam::codedFunctionObject::codedFunctionObject
dict_(dict)
{
read(dict_);
updateLibrary(name_);
redirectFunctionObject();
}
@ -184,114 +196,15 @@ bool Foam::codedFunctionObject::end()
bool Foam::codedFunctionObject::read(const dictionary& dict)
{
// Backward compatibility
if (dict.found("redirectType"))
// The name keyword is "name". "redirectType" is also maintained here
// for backwards compatibility, but "name" is taken in preference and
// is printed in the error message if neither keyword is present.
name_ = word::null;
name_ = dict.lookupOrDefault("redirectType", name_);
name_ = dict.lookupOrDefault("name", name_);
if (name_ == word::null)
{
dict.lookup("redirectType") >> name_;
}
else
{
dict.lookup("name") >> name_;
}
const entry* dataPtr = dict.lookupEntryPtr
(
"codeData",
false,
false
);
if (dataPtr)
{
codeData_ = stringOps::trim(dataPtr->stream());
stringOps::inplaceExpand(codeData_, dict);
dynamicCodeContext::addLineDirective
(
codeData_,
dataPtr->startLineNumber(),
dict.name()
);
}
const entry* readPtr = dict.lookupEntryPtr
(
"codeRead",
false,
false
);
if (readPtr)
{
codeRead_ = stringOps::trim(readPtr->stream());
stringOps::inplaceExpand(codeRead_, dict);
dynamicCodeContext::addLineDirective
(
codeRead_,
readPtr->startLineNumber(),
dict.name()
);
}
const entry* execPtr = dict.lookupEntryPtr
(
"codeExecute",
false,
false
);
if (execPtr)
{
codeExecute_ = stringOps::trim(execPtr->stream());
stringOps::inplaceExpand(codeExecute_, dict);
dynamicCodeContext::addLineDirective
(
codeExecute_,
execPtr->startLineNumber(),
dict.name()
);
}
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
(
"codeEnd",
false,
false
);
if (endPtr)
{
codeEnd_ = stringOps::trim(endPtr->stream());
stringOps::inplaceExpand(codeEnd_, dict);
dynamicCodeContext::addLineDirective
(
codeEnd_,
endPtr->startLineNumber(),
dict.name()
);
}
if(!dataPtr && !readPtr && !execPtr && !writePtr && !endPtr)
{
IOWarningInFunction
(
dict
) << "No critical \"code\" prefixed keywords were found."
<< " Please check the code documentation for more details."
<< nl << endl;
dict.lookup("name"); // <-- generate error message with "name" in it
}
updateLibrary(name_);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -90,6 +90,12 @@ class codedFunctionObject
{
protected:
// Protected static data
//- The keywords associated with source code
static const wordList codeKeys_;
// Protected data
//- Reference to the time database
@ -98,14 +104,9 @@ protected:
//- Input dictionary
dictionary dict_;
//- The name
word name_;
string codeData_;
string codeRead_;
string codeExecute_;
string codeWrite_;
string codeEnd_;
//- Underlying functionObject
mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
@ -118,15 +119,18 @@ protected:
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
// Return a description (type + name) for the output
//- Return a description (type + name) for the output
virtual string description() const;
// Clear any redirected objects
//- Clear any redirected objects
virtual void clearRedirect() const;
// Get the dictionary to initialize the codeContext
//- Get the dictionary to initialize the codeContext
virtual const dictionary& codeDict() const;
//- Get the keywords associated with source code
virtual const wordList& codeKeys() const;
private:

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -29,6 +29,13 @@ License
#include "dynamicCode.H"
#include "dynamicCodeContext.H"
// * * * * * * * * * * * Protected Static Data Members * * * * * * * * * * * //
template<class Type>
const Foam::wordList Foam::fv::CodedSource<Type>::codeKeys_ =
{"codeAddSup", "codeCorrect", "codeInclude", "codeSetValue", "localCode"};
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
@ -45,11 +52,6 @@ void Foam::fv::CodedSource<Type>::prepare
dynCode.setFilterVariable("TemplateType", sourceType);
dynCode.setFilterVariable("SourceType", sourceType + "Source");
// dynCode.removeFilterVariable("code");
dynCode.setFilterVariable("codeCorrect", codeCorrect_);
dynCode.setFilterVariable("codeAddSup", codeAddSup_);
dynCode.setFilterVariable("codeSetValue", codeSetValue_);
// compile filtered C template
dynCode.addCompileFile("codedFvOptionTemplate.C");
@ -108,6 +110,13 @@ const Foam::dictionary& Foam::fv::CodedSource<Type>::codeDict() const
}
template<class Type>
const Foam::wordList& Foam::fv::CodedSource<Type>::codeKeys() const
{
return codeKeys_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -89,15 +89,6 @@ Usage
#{
Pout<< "**codeSetValue**" << endl;
#};
// Dummy entry. Make dependent on above to trigger recompilation
code
#{
$codeInclude
$codeCorrect
$codeAddSup
$codeSetValue
#};
}
sourceTimeCoeffs
@ -136,17 +127,19 @@ class CodedSource
public cellSetOption,
public codedBase
{
protected:
// Protected static data
//- The keywords associated with source code
static const wordList codeKeys_;
// Protected data
//- The name
word name_;
string codeCorrect_;
string codeAddSup_;
string codeSetValue_;
//- Underlying functionObject
mutable autoPtr<option> redirectFvOptionPtr_;
@ -159,15 +152,18 @@ protected:
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
// Return a description (type + name) for the output
//- Return a description (type + name) for the output
virtual string description() const;
// Clear any redirected objects
//- Clear any redirected objects
virtual void clearRedirect() const;
// Get the dictionary to initialize the codeContext
//- Get the dictionary to initialize the codeContext
virtual const dictionary& codeDict() const;
//- Get the keywords associated with source code
virtual const wordList& codeKeys() const;
public:

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -36,67 +36,18 @@ bool Foam::fv::CodedSource<Type>::read(const dictionary& dict)
coeffs_.lookup("fields") >> fieldNames_;
applied_.setSize(fieldNames_.size(), false);
// Backward compatibility
if (dict.found("redirectType"))
// The name keyword is "name". "redirectType" is also maintained here
// for backwards compatibility, but "name" is taken in preference and
// is printed in the error message if neither keyword is present.
name_ = word::null;
name_ = dict.lookupOrDefault("redirectType", name_);
name_ = dict.lookupOrDefault("name", name_);
if (name_ == word::null)
{
dict.lookup("redirectType") >> name_;
}
else
{
dict.lookup("name") >> name_;
dict.lookup("name"); // <-- generate error message with "name" in it
}
// Code snippets
{
const entry& e = coeffs_.lookupEntry
(
"codeCorrect",
false,
false
);
codeCorrect_ = stringOps::trim(e.stream());
stringOps::inplaceExpand(codeCorrect_, coeffs_);
dynamicCodeContext::addLineDirective
(
codeCorrect_,
e.startLineNumber(),
coeffs_.name()
);
}
{
const entry& e = coeffs_.lookupEntry
(
"codeAddSup",
false,
false
);
codeAddSup_ = stringOps::trim(e.stream());
stringOps::inplaceExpand(codeAddSup_, coeffs_);
dynamicCodeContext::addLineDirective
(
codeAddSup_,
e.startLineNumber(),
coeffs_.name()
);
}
{
const entry& e = coeffs_.lookupEntry
(
"codeSetValue",
false,
false
);
codeSetValue_ = stringOps::trim(e.stream());
stringOps::inplaceExpand(codeSetValue_, coeffs_);
dynamicCodeContext::addLineDirective
(
codeSetValue_,
e.startLineNumber(),
coeffs_.name()
);
}
updateLibrary(name_);
return true;
}