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:
@ -80,15 +80,6 @@ Description
|
|||||||
#{
|
#{
|
||||||
Pout<< "**codeSetValue**" << endl;
|
Pout<< "**codeSetValue**" << endl;
|
||||||
#};
|
#};
|
||||||
|
|
||||||
// Dummy entry. Make dependent on above to trigger recompilation
|
|
||||||
code
|
|
||||||
#{
|
|
||||||
$codeInclude
|
|
||||||
$codeCorrect
|
|
||||||
$codeAddSup
|
|
||||||
$codeSetValue
|
|
||||||
#};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceTimeCoeffs
|
sourceTimeCoeffs
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -59,8 +59,8 @@ namespace functionEntries
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Foam::word Foam::functionEntries::codeStream::codeTemplateC
|
const Foam::word Foam::functionEntries::codeStream::codeTemplateC =
|
||||||
= "codeStreamTemplate.C";
|
"codeStreamTemplate.C";
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
@ -123,8 +123,8 @@ Foam::functionEntries::codeStream::getFunction
|
|||||||
const dictionary& codeDict
|
const dictionary& codeDict
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// get code, codeInclude, codeOptions
|
// get code, codeInclude, ...
|
||||||
dynamicCodeContext context(codeDict);
|
dynamicCodeContext context(codeDict, {"code", "codeInclude", "localCode"});
|
||||||
|
|
||||||
// codeName: codeStream + _<sha1>
|
// codeName: codeStream + _<sha1>
|
||||||
// codeDir : _<sha1>
|
// codeDir : _<sha1>
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -293,7 +293,7 @@ void Foam::codedBase::updateLibrary
|
|||||||
dict
|
dict
|
||||||
);
|
);
|
||||||
|
|
||||||
dynamicCodeContext context(dict);
|
dynamicCodeContext context(dict, codeKeys());
|
||||||
|
|
||||||
// codeName: name + _<sha1>
|
// codeName: name + _<sha1>
|
||||||
// codeDir : name
|
// codeDir : name
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -92,30 +92,26 @@ class codedBase
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
//- Update library as required
|
//- Update library as required
|
||||||
void updateLibrary
|
void updateLibrary(const word& name) const;
|
||||||
(
|
|
||||||
const word& name
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Get the loaded dynamic libraries
|
//- Get the loaded dynamic libraries
|
||||||
virtual dlLibraryTable& libs() const = 0;
|
virtual dlLibraryTable& libs() const = 0;
|
||||||
|
|
||||||
//- Adapt the context for the current object
|
//- Adapt the context for the current object
|
||||||
virtual void prepare
|
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const = 0;
|
||||||
(
|
|
||||||
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;
|
virtual string description() const = 0;
|
||||||
|
|
||||||
// Clear any redirected objects
|
//- Clear any redirected objects
|
||||||
virtual void clearRedirect() const = 0;
|
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;
|
virtual const dictionary& codeDict() const = 0;
|
||||||
|
|
||||||
|
//- Get the keywords associated with source code
|
||||||
|
virtual const wordList& codeKeys() const = 0;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -343,7 +343,13 @@ void Foam::dynamicCode::reset
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
clear();
|
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
|
void Foam::dynamicCode::setFilterVariable
|
||||||
(
|
(
|
||||||
const word& key,
|
const word& key,
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -259,9 +259,6 @@ public:
|
|||||||
//- Add a file to create with its contents. Will not be filtered
|
//- Add a file to create with its contents. Will not be filtered
|
||||||
void addCreateFile(const fileName& name, const string& contents);
|
void addCreateFile(const fileName& name, const string& contents);
|
||||||
|
|
||||||
//- Define filter variables for code, codeInclude, SHA1sum
|
|
||||||
void setFilterContext(const dynamicCodeContext&);
|
|
||||||
|
|
||||||
//- Define a filter variable
|
//- Define a filter variable
|
||||||
void setFilterVariable(const word& key, const std::string& value);
|
void setFilterVariable(const word& key, const std::string& value);
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -27,102 +27,7 @@ License
|
|||||||
#include "stringOps.H"
|
#include "stringOps.H"
|
||||||
#include "OSHA1stream.H"
|
#include "OSHA1stream.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
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 * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
void Foam::dynamicCodeContext::addLineDirective
|
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()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -36,6 +36,7 @@ SourceFiles
|
|||||||
#define dynamicCodeContext_H
|
#define dynamicCodeContext_H
|
||||||
|
|
||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
|
#include "HashTable.H"
|
||||||
#include "SHA1Digest.H"
|
#include "SHA1Digest.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
@ -54,31 +55,42 @@ class dynamicCodeContext
|
|||||||
//- The parent dictionary context
|
//- The parent dictionary context
|
||||||
const dictionary& dict_;
|
const dictionary& dict_;
|
||||||
|
|
||||||
//- Optional "code" entry
|
//- Code entries
|
||||||
string code_;
|
HashTable<string> code_;
|
||||||
|
|
||||||
//- Optional "localCode" entry
|
|
||||||
string localCode_;
|
|
||||||
|
|
||||||
//- Optional "codeInclude" entry
|
|
||||||
string include_;
|
|
||||||
|
|
||||||
//- Optional "codeOptions" entry
|
//- Optional "codeOptions" entry
|
||||||
string options_;
|
string options_;
|
||||||
|
|
||||||
//- Optional "codeLib" entry
|
//- Optional "codeLibs" entry
|
||||||
string libs_;
|
string libs_;
|
||||||
|
|
||||||
//- Calculated SHA1Digest
|
//- Calculated SHA1Digest
|
||||||
SHA1Digest sha1_;
|
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:
|
public:
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from a dictionary
|
//- Construct from a dictionary and lists of which entries correspond
|
||||||
dynamicCodeContext(const dictionary&);
|
// to code
|
||||||
|
dynamicCodeContext
|
||||||
|
(
|
||||||
|
const dictionary& dict,
|
||||||
|
const wordList& codeKeys
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
@ -89,10 +101,10 @@ public:
|
|||||||
return dict_;
|
return dict_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Return the code-includes
|
//- Return the code table
|
||||||
const string& include() const
|
const HashTable<string>& code() const
|
||||||
{
|
{
|
||||||
return include_;
|
return code_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Return the code-options
|
//- Return the code-options
|
||||||
@ -107,31 +119,11 @@ public:
|
|||||||
return libs_;
|
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
|
//- Return SHA1 digest calculated from include, options, code
|
||||||
const SHA1Digest& sha1() const
|
const SHA1Digest& sha1() const
|
||||||
{
|
{
|
||||||
return sha1_;
|
return sha1_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Helper: add \#line directive
|
|
||||||
static void addLineDirective
|
|
||||||
(
|
|
||||||
string&,
|
|
||||||
const label lineNum,
|
|
||||||
const fileName& name
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -31,15 +31,22 @@ License
|
|||||||
#include "dynamicCodeContext.H"
|
#include "dynamicCodeContext.H"
|
||||||
#include "stringOps.H"
|
#include "stringOps.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
const Foam::wordList Foam::codedFixedValuePointPatchField<Type>::codeKeys_ =
|
||||||
|
{"code", "codeInclude", "localCode"};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
const Foam::word Foam::codedFixedValuePointPatchField<Type>::codeTemplateC
|
const Foam::word Foam::codedFixedValuePointPatchField<Type>::codeTemplateC =
|
||||||
= "fixedValuePointPatchFieldTemplate.C";
|
"fixedValuePointPatchFieldTemplate.C";
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
const Foam::word Foam::codedFixedValuePointPatchField<Type>::codeTemplateH
|
const Foam::word Foam::codedFixedValuePointPatchField<Type>::codeTemplateH =
|
||||||
= "fixedValuePointPatchFieldTemplate.H";
|
"fixedValuePointPatchFieldTemplate.H";
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
@ -141,8 +148,8 @@ void Foam::codedFixedValuePointPatchField<Type>::prepare
|
|||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
const Foam::dictionary& Foam::codedFixedValuePointPatchField<Type>::codeDict()
|
const Foam::dictionary&
|
||||||
const
|
Foam::codedFixedValuePointPatchField<Type>::codeDict() const
|
||||||
{
|
{
|
||||||
// Use system/codeDict or in-line
|
// Use system/codeDict or in-line
|
||||||
return
|
return
|
||||||
@ -154,6 +161,14 @@ const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
const Foam::wordList&
|
||||||
|
Foam::codedFixedValuePointPatchField<Type>::codeKeys() const
|
||||||
|
{
|
||||||
|
return codeKeys_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
Foam::string Foam::codedFixedValuePointPatchField<Type>::description() const
|
Foam::string Foam::codedFixedValuePointPatchField<Type>::description() const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -105,6 +105,12 @@ class codedFixedValuePointPatchField
|
|||||||
public fixedValuePointPatchField<Type>,
|
public fixedValuePointPatchField<Type>,
|
||||||
public codedBase
|
public codedBase
|
||||||
{
|
{
|
||||||
|
// Private static data
|
||||||
|
|
||||||
|
//- The keywords associated with source code
|
||||||
|
static const wordList codeKeys_;
|
||||||
|
|
||||||
|
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Dictionary contents for the boundary condition
|
//- Dictionary contents for the boundary condition
|
||||||
@ -128,15 +134,18 @@ class codedFixedValuePointPatchField
|
|||||||
//- Adapt the context for the current object
|
//- Adapt the context for the current object
|
||||||
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
|
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;
|
virtual string description() const;
|
||||||
|
|
||||||
// Clear the ptr to the redirected object
|
//- Clear the ptr to the redirected object
|
||||||
virtual void clearRedirect() const;
|
virtual void clearRedirect() const;
|
||||||
|
|
||||||
// Get the dictionary to initialize the codeContext
|
//- Get the dictionary to initialize the codeContext
|
||||||
virtual const dictionary& codeDict() const;
|
virtual const dictionary& codeDict() const;
|
||||||
|
|
||||||
|
//- Get the keywords associated with source code
|
||||||
|
virtual const wordList& codeKeys() const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@ -31,15 +31,22 @@ License
|
|||||||
#include "dynamicCodeContext.H"
|
#include "dynamicCodeContext.H"
|
||||||
#include "stringOps.H"
|
#include "stringOps.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
const Foam::wordList Foam::codedFixedValueFvPatchField<Type>::codeKeys_ =
|
||||||
|
{"code", "codeInclude", "localCode"};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
const Foam::word Foam::codedFixedValueFvPatchField<Type>::codeTemplateC
|
const Foam::word Foam::codedFixedValueFvPatchField<Type>::codeTemplateC =
|
||||||
= "fixedValueFvPatchFieldTemplate.C";
|
"fixedValueFvPatchFieldTemplate.C";
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
const Foam::word Foam::codedFixedValueFvPatchField<Type>::codeTemplateH
|
const Foam::word Foam::codedFixedValueFvPatchField<Type>::codeTemplateH =
|
||||||
= "fixedValueFvPatchFieldTemplate.H";
|
"fixedValueFvPatchFieldTemplate.H";
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
@ -153,6 +160,13 @@ const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
const Foam::wordList& Foam::codedFixedValueFvPatchField<Type>::codeKeys() const
|
||||||
|
{
|
||||||
|
return codeKeys_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
Foam::string Foam::codedFixedValueFvPatchField<Type>::description() const
|
Foam::string Foam::codedFixedValueFvPatchField<Type>::description() const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -103,6 +103,12 @@ class codedFixedValueFvPatchField
|
|||||||
public fixedValueFvPatchField<Type>,
|
public fixedValueFvPatchField<Type>,
|
||||||
public codedBase
|
public codedBase
|
||||||
{
|
{
|
||||||
|
// Private static data
|
||||||
|
|
||||||
|
//- The keywords associated with source code
|
||||||
|
static const wordList codeKeys_;
|
||||||
|
|
||||||
|
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Dictionary contents for the boundary condition
|
//- Dictionary contents for the boundary condition
|
||||||
@ -126,15 +132,18 @@ class codedFixedValueFvPatchField
|
|||||||
//- Adapt the context for the current object
|
//- Adapt the context for the current object
|
||||||
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
|
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;
|
virtual string description() const;
|
||||||
|
|
||||||
// Clear the ptr to the redirected object
|
//- Clear the ptr to the redirected object
|
||||||
virtual void clearRedirect() const;
|
virtual void clearRedirect() const;
|
||||||
|
|
||||||
// Get the dictionary to initialize the codeContext
|
//- Get the dictionary to initialize the codeContext
|
||||||
virtual const dictionary& codeDict() const;
|
virtual const dictionary& codeDict() const;
|
||||||
|
|
||||||
|
//- Get the keywords associated with source code
|
||||||
|
virtual const wordList& codeKeys() const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -31,15 +31,22 @@ License
|
|||||||
#include "dynamicCodeContext.H"
|
#include "dynamicCodeContext.H"
|
||||||
#include "stringOps.H"
|
#include "stringOps.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
const Foam::wordList Foam::codedMixedFvPatchField<Type>::codeKeys_ =
|
||||||
|
{"code", "codeInclude", "localCode"};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
const Foam::word Foam::codedMixedFvPatchField<Type>::codeTemplateC
|
const Foam::word Foam::codedMixedFvPatchField<Type>::codeTemplateC =
|
||||||
= "mixedFvPatchFieldTemplate.C";
|
"mixedFvPatchFieldTemplate.C";
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
const Foam::word Foam::codedMixedFvPatchField<Type>::codeTemplateH
|
const Foam::word Foam::codedMixedFvPatchField<Type>::codeTemplateH =
|
||||||
= "mixedFvPatchFieldTemplate.H";
|
"mixedFvPatchFieldTemplate.H";
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
@ -153,6 +160,13 @@ const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
const Foam::wordList& Foam::codedMixedFvPatchField<Type>::codeKeys() const
|
||||||
|
{
|
||||||
|
return codeKeys_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
Foam::string Foam::codedMixedFvPatchField<Type>::description() const
|
Foam::string Foam::codedMixedFvPatchField<Type>::description() const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -113,6 +113,12 @@ class codedMixedFvPatchField
|
|||||||
public mixedFvPatchField<Type>,
|
public mixedFvPatchField<Type>,
|
||||||
public codedBase
|
public codedBase
|
||||||
{
|
{
|
||||||
|
// Private static data
|
||||||
|
|
||||||
|
//- The keywords associated with source code
|
||||||
|
static const wordList codeKeys_;
|
||||||
|
|
||||||
|
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Dictionary contents for the boundary condition
|
//- Dictionary contents for the boundary condition
|
||||||
@ -136,15 +142,18 @@ class codedMixedFvPatchField
|
|||||||
//- Adapt the context for the current object
|
//- Adapt the context for the current object
|
||||||
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
|
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;
|
virtual string description() const;
|
||||||
|
|
||||||
// Clear the ptr to the redirected object
|
//- Clear the ptr to the redirected object
|
||||||
virtual void clearRedirect() const;
|
virtual void clearRedirect() const;
|
||||||
|
|
||||||
// Get the dictionary to initialize the codeContext
|
//- Get the dictionary to initialize the codeContext
|
||||||
virtual const dictionary& codeDict() const;
|
virtual const dictionary& codeDict() const;
|
||||||
|
|
||||||
|
//- Get the keywords associated with source code
|
||||||
|
virtual const wordList& codeKeys() const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -33,6 +33,20 @@ License
|
|||||||
#include "stringOps.H"
|
#include "stringOps.H"
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * Protected Static Data Members * * * * * * * * * * * //
|
||||||
|
|
||||||
|
const Foam::wordList Foam::codedFunctionObject::codeKeys_ =
|
||||||
|
{
|
||||||
|
"codeData",
|
||||||
|
"codeEnd",
|
||||||
|
"codeExecute",
|
||||||
|
"codeInclude",
|
||||||
|
"codeRead",
|
||||||
|
"codeWrite",
|
||||||
|
"localCode"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
@ -47,6 +61,7 @@ namespace Foam
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::codedFunctionObject::prepare
|
void Foam::codedFunctionObject::prepare
|
||||||
@ -55,13 +70,7 @@ void Foam::codedFunctionObject::prepare
|
|||||||
const dynamicCodeContext& context
|
const dynamicCodeContext& context
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// Set additional rewrite rules
|
|
||||||
dynCode.setFilterVariable("typeName", name_);
|
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
|
// Compile filtered C template
|
||||||
dynCode.addCompileFile("functionObjectTemplate.C");
|
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 * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::codedFunctionObject::codedFunctionObject
|
Foam::codedFunctionObject::codedFunctionObject
|
||||||
@ -129,9 +144,6 @@ Foam::codedFunctionObject::codedFunctionObject
|
|||||||
dict_(dict)
|
dict_(dict)
|
||||||
{
|
{
|
||||||
read(dict_);
|
read(dict_);
|
||||||
|
|
||||||
updateLibrary(name_);
|
|
||||||
redirectFunctionObject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -184,114 +196,15 @@ bool Foam::codedFunctionObject::end()
|
|||||||
|
|
||||||
bool Foam::codedFunctionObject::read(const dictionary& dict)
|
bool Foam::codedFunctionObject::read(const dictionary& dict)
|
||||||
{
|
{
|
||||||
// Backward compatibility
|
// The name keyword is "name". "redirectType" is also maintained here
|
||||||
if (dict.found("redirectType"))
|
// 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_;
|
dict.lookup("name"); // <-- generate error message with "name" in it
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLibrary(name_);
|
updateLibrary(name_);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -90,6 +90,12 @@ class codedFunctionObject
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
// Protected static data
|
||||||
|
|
||||||
|
//- The keywords associated with source code
|
||||||
|
static const wordList codeKeys_;
|
||||||
|
|
||||||
|
|
||||||
// Protected data
|
// Protected data
|
||||||
|
|
||||||
//- Reference to the time database
|
//- Reference to the time database
|
||||||
@ -98,14 +104,9 @@ protected:
|
|||||||
//- Input dictionary
|
//- Input dictionary
|
||||||
dictionary dict_;
|
dictionary dict_;
|
||||||
|
|
||||||
|
//- The name
|
||||||
word name_;
|
word name_;
|
||||||
|
|
||||||
string codeData_;
|
|
||||||
string codeRead_;
|
|
||||||
string codeExecute_;
|
|
||||||
string codeWrite_;
|
|
||||||
string codeEnd_;
|
|
||||||
|
|
||||||
//- Underlying functionObject
|
//- Underlying functionObject
|
||||||
mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
|
mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
|
||||||
|
|
||||||
@ -118,15 +119,18 @@ protected:
|
|||||||
//- Adapt the context for the current object
|
//- Adapt the context for the current object
|
||||||
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
|
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;
|
virtual string description() const;
|
||||||
|
|
||||||
// Clear any redirected objects
|
//- Clear any redirected objects
|
||||||
virtual void clearRedirect() const;
|
virtual void clearRedirect() const;
|
||||||
|
|
||||||
// Get the dictionary to initialize the codeContext
|
//- Get the dictionary to initialize the codeContext
|
||||||
virtual const dictionary& codeDict() const;
|
virtual const dictionary& codeDict() const;
|
||||||
|
|
||||||
|
//- Get the keywords associated with source code
|
||||||
|
virtual const wordList& codeKeys() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -29,6 +29,13 @@ License
|
|||||||
#include "dynamicCode.H"
|
#include "dynamicCode.H"
|
||||||
#include "dynamicCodeContext.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 * * * * * * * * * * * //
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
@ -45,11 +52,6 @@ void Foam::fv::CodedSource<Type>::prepare
|
|||||||
dynCode.setFilterVariable("TemplateType", sourceType);
|
dynCode.setFilterVariable("TemplateType", sourceType);
|
||||||
dynCode.setFilterVariable("SourceType", sourceType + "Source");
|
dynCode.setFilterVariable("SourceType", sourceType + "Source");
|
||||||
|
|
||||||
// dynCode.removeFilterVariable("code");
|
|
||||||
dynCode.setFilterVariable("codeCorrect", codeCorrect_);
|
|
||||||
dynCode.setFilterVariable("codeAddSup", codeAddSup_);
|
|
||||||
dynCode.setFilterVariable("codeSetValue", codeSetValue_);
|
|
||||||
|
|
||||||
// compile filtered C template
|
// compile filtered C template
|
||||||
dynCode.addCompileFile("codedFvOptionTemplate.C");
|
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 * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -89,15 +89,6 @@ Usage
|
|||||||
#{
|
#{
|
||||||
Pout<< "**codeSetValue**" << endl;
|
Pout<< "**codeSetValue**" << endl;
|
||||||
#};
|
#};
|
||||||
|
|
||||||
// Dummy entry. Make dependent on above to trigger recompilation
|
|
||||||
code
|
|
||||||
#{
|
|
||||||
$codeInclude
|
|
||||||
$codeCorrect
|
|
||||||
$codeAddSup
|
|
||||||
$codeSetValue
|
|
||||||
#};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceTimeCoeffs
|
sourceTimeCoeffs
|
||||||
@ -136,17 +127,19 @@ class CodedSource
|
|||||||
public cellSetOption,
|
public cellSetOption,
|
||||||
public codedBase
|
public codedBase
|
||||||
{
|
{
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
// Protected static data
|
||||||
|
|
||||||
|
//- The keywords associated with source code
|
||||||
|
static const wordList codeKeys_;
|
||||||
|
|
||||||
|
|
||||||
// Protected data
|
// Protected data
|
||||||
|
|
||||||
|
//- The name
|
||||||
word name_;
|
word name_;
|
||||||
|
|
||||||
string codeCorrect_;
|
|
||||||
string codeAddSup_;
|
|
||||||
string codeSetValue_;
|
|
||||||
|
|
||||||
//- Underlying functionObject
|
//- Underlying functionObject
|
||||||
mutable autoPtr<option> redirectFvOptionPtr_;
|
mutable autoPtr<option> redirectFvOptionPtr_;
|
||||||
|
|
||||||
@ -159,15 +152,18 @@ protected:
|
|||||||
//- Adapt the context for the current object
|
//- Adapt the context for the current object
|
||||||
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
|
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;
|
virtual string description() const;
|
||||||
|
|
||||||
// Clear any redirected objects
|
//- Clear any redirected objects
|
||||||
virtual void clearRedirect() const;
|
virtual void clearRedirect() const;
|
||||||
|
|
||||||
// Get the dictionary to initialize the codeContext
|
//- Get the dictionary to initialize the codeContext
|
||||||
virtual const dictionary& codeDict() const;
|
virtual const dictionary& codeDict() const;
|
||||||
|
|
||||||
|
//- Get the keywords associated with source code
|
||||||
|
virtual const wordList& codeKeys() const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -36,67 +36,18 @@ bool Foam::fv::CodedSource<Type>::read(const dictionary& dict)
|
|||||||
coeffs_.lookup("fields") >> fieldNames_;
|
coeffs_.lookup("fields") >> fieldNames_;
|
||||||
applied_.setSize(fieldNames_.size(), false);
|
applied_.setSize(fieldNames_.size(), false);
|
||||||
|
|
||||||
// Backward compatibility
|
// The name keyword is "name". "redirectType" is also maintained here
|
||||||
if (dict.found("redirectType"))
|
// 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_;
|
dict.lookup("name"); // <-- generate error message with "name" in it
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dict.lookup("name") >> name_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Code snippets
|
updateLibrary(name_);
|
||||||
{
|
|
||||||
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()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user