ENH: improve dynamicCode consistency

- refactor and provision for additional code context
This commit is contained in:
Mark Olesen
2021-04-01 10:50:38 +02:00
committed by Andrew Heather
parent 2b7b3700c2
commit cf9063878e
23 changed files with 605 additions and 735 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,10 +27,10 @@ License
\*---------------------------------------------------------------------------*/
#include "calcEntry.H"
#include "addToMemberFunctionSelectionTable.H"
#include "codeStream.H"
#include "dictionary.H"
#include "dynamicCode.H"
#include "codeStream.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -27,11 +27,11 @@ License
\*---------------------------------------------------------------------------*/
#include "codeStream.H"
#include "addToMemberFunctionSelectionTable.H"
#include "StringStream.H"
#include "dynamicCode.H"
#include "dynamicCodeContext.H"
#include "StringStream.H"
#include "Time.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -69,11 +69,7 @@ Foam::dlLibraryTable& Foam::functionEntries::codeStream::libs
const dictionary& dict
)
{
const baseIOdictionary& d = static_cast<const baseIOdictionary&>
(
dict.topDict()
);
return d.time().libs();
return static_cast<const baseIOdictionary&>(dict.topDict()).time().libs();
}
@ -82,28 +78,27 @@ bool Foam::functionEntries::codeStream::doingMasterOnlyReading
const dictionary& dict
)
{
const dictionary& topDict = dict.topDict();
// Fallback value
bool masterOnly = regIOobject::masterOnlyReading;
if (isA<baseIOdictionary>(topDict))
const auto* iodictPtr = isA<baseIOdictionary>(dict.topDict());
if (iodictPtr)
{
const baseIOdictionary& d = static_cast<const baseIOdictionary&>
(
topDict
);
masterOnly = iodictPtr->globalObject();
DebugPout
<< "codeStream : baseIOdictionary:" << dict.name()
<< " master-only-reading:" << d.globalObject() << endl;
return d.globalObject();
<< " master-only-reading:" << masterOnly << endl;
}
else
{
DebugPout
<< "codeStream : not a baseIOdictionary:" << dict.name()
<< " master-only-reading:" << regIOobject::masterOnlyReading << endl;
<< " master-only-reading:" << masterOnly << endl;
}
// Fall back to regIOobject::masterOnlyReading
return regIOobject::masterOnlyReading;
return masterOnly;
}

View File

@ -31,10 +31,13 @@ License
#include "dynamicCode.H"
#include "dynamicCodeContext.H"
#include "dlLibraryTable.H"
#include "objectRegistry.H"
#include "IOdictionary.H"
#include "Pstream.H"
#include "PstreamReduceOps.H"
#include "OSspecific.H"
#include "Ostream.H"
#include "Time.H"
#include "regIOobject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -50,7 +53,6 @@ namespace Foam
namespace Foam
{
//! \cond fileScope
static inline void writeEntryIfPresent
(
Ostream& os,
@ -59,16 +61,24 @@ static inline void writeEntryIfPresent
)
{
const entry* eptr = dict.findEntry(key, keyType::LITERAL);
if (eptr)
if (!eptr)
{
// Nothing to do
}
else if (eptr->isDict())
{
eptr->dict().writeEntry(os);
}
else
{
const tokenList& toks = eptr->stream();
if (!toks.empty())
if (!toks.empty()) // Could also check that it is a string-type
{
os.writeEntry(key, toks[0]);
}
}
}
//! \endcond
} // End namespace Foam
@ -77,6 +87,7 @@ static inline void writeEntryIfPresent
void Foam::codedBase::writeCodeDict(Ostream& os, const dictionary& dict)
{
writeEntryIfPresent(os, dict, "codeContext");
writeEntryIfPresent(os, dict, "codeInclude");
writeEntryIfPresent(os, dict, "localCode");
writeEntryIfPresent(os, dict, "code");
@ -85,6 +96,36 @@ void Foam::codedBase::writeCodeDict(Ostream& os, const dictionary& dict)
}
const Foam::dictionary&
Foam::codedBase::codeDict
(
const objectRegistry& obr,
const word& dictName
)
{
IOdictionary* dictptr = obr.getObjectPtr<IOdictionary>(dictName);
if (!dictptr)
{
dictptr = new IOdictionary
(
IOobject
(
dictName,
obr.time().system(),
obr,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);
obr.store(dictptr);
}
return *dictptr;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void* Foam::codedBase::loadLibrary

View File

@ -49,7 +49,6 @@ SourceFiles
#include "dictionary.H"
#include "dynamicCodeContext.H"
#include "fileName.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -57,9 +56,9 @@ namespace Foam
{
// Forward Declarations
class Ostream;
class dynamicCode;
class dlLibraryTable;
class objectRegistry;
/*---------------------------------------------------------------------------*\
Class codedBase Declaration
@ -104,11 +103,24 @@ class codedBase
protected:
// Protected Member Functions
//- Write code-dictionary contents
static void writeCodeDict(Ostream& os, const dictionary& dict);
//- Return "codeDict" from objectRegistry or read from disk
static const dictionary& codeDict
(
const objectRegistry& obr,
const word& dictName = "codeDict"
);
// Protected Member Functions
//- Access to the dynamic code context
dynamicCodeContext& codeContext()
{
return context_;
}
//- Set code context from a dictionary
void setCodeContext(const dictionary& dict);
@ -136,16 +148,10 @@ protected:
//- or use the codeDict() to generate one
void updateLibrary(const word& name) const;
//- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const = 0;
//- Adapt the context for the current object
virtual void prepare
(
dynamicCode& dynCode,
const dynamicCodeContext& context
) const = 0;
// Return a description (type + name) for the output
virtual string description() const = 0;
@ -155,6 +161,13 @@ protected:
// Get the dictionary to initialize the codeContext
virtual const dictionary& codeDict() const = 0;
//- Adapt the context for the current object
virtual void prepare
(
dynamicCode& dynCode,
const dynamicCodeContext& context
) const = 0;
//- No copy construct
codedBase(const codedBase&) = delete;

View File

@ -52,10 +52,11 @@ const Foam::word Foam::dynamicCode::codeTemplateEnvName
const Foam::fileName Foam::dynamicCode::codeTemplateDirName
= "codeTemplates/dynamicCode";
const char* const Foam::dynamicCode::libTargetRoot =
"LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib";
const char* const Foam::dynamicCode::targetLibDir
= "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib";
const char* const Foam::dynamicCode::topDirName = "dynamicCode";
const char* const Foam::dynamicCode::topDirName
= "dynamicCode";
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -224,7 +225,8 @@ bool Foam::dynamicCode::createMakeFiles() const
}
os << nl
<< libTargetRoot << codeName_.c_str() << nl;
<< targetLibDir
<< "/lib" << codeName_.c_str() << nl;
return true;
}

View File

@ -108,8 +108,8 @@ protected:
// Static Data Members
//- Root of the LIB target for Make/files
static const char* const libTargetRoot;
//- Directory for library targets for Make/files
static const char* const targetLibDir;
//- Top-level directory name for copy/compiling
static const char* const topDirName;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -34,12 +34,12 @@ License
void Foam::dynamicCodeContext::inplaceExpand
(
string& code,
string& str,
const dictionary& dict
)
{
stringOps::inplaceTrim(code);
stringOps::inplaceExpand(code, dict);
stringOps::inplaceTrim(str);
stringOps::inplaceExpand(str, dict);
}
@ -47,7 +47,7 @@ unsigned Foam::dynamicCodeContext::addLineDirective
(
string& code,
label lineNum,
const fileName& file
const string& file
)
{
++lineNum; // Change from 0-based to 1-based
@ -94,72 +94,81 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::dynamicCodeContext::valid() const
bool Foam::dynamicCodeContext::valid() const noexcept
{
return &(dict_.get()) != &(dictionary::null);
}
bool Foam::dynamicCodeContext::readEntry
(
const word& key,
string& str,
bool mandatory,
bool withLineNum
)
{
str.clear();
sha1_.append("<" + key + ">");
const dictionary& dict = this->dict();
const entry* eptr = dict.findEntry(key, keyType::LITERAL);
if (!eptr)
{
if (mandatory)
{
FatalIOErrorInFunction(dict)
<< "Entry '" << key << "' not found in dictionary "
<< dict.name() << nl
<< exit(FatalIOError);
}
return false;
}
// Expand dictionary entries.
// Removing any leading/trailing whitespace is necessary for compilation
// options, but is also convenient for includes and code body.
eptr->readEntry(str);
dynamicCodeContext::inplaceExpand(str, dict);
sha1_.append(str);
if (withLineNum)
{
addLineDirective(str, eptr->startLineNumber(), dict);
}
return true;
}
bool Foam::dynamicCodeContext::readIfPresent
(
const word& key,
string& str,
bool withLineNum
)
{
return readEntry(key, str, false, withLineNum);
}
void Foam::dynamicCodeContext::setCodeContext(const dictionary& dict)
{
dict_ = std::cref<dictionary>(dict);
sha1_.clear();
// Expand dictionary entries.
// Removing any leading/trailing whitespace is necessary for compilation
// options, but is also convenient for includes and code body.
const entry* eptr;
options_.clear();
sha1_.append("<codeOptions>");
if ((eptr = dict.findEntry("codeOptions", keyType::LITERAL)) != nullptr)
{
eptr->readEntry(options_);
dynamicCodeContext::inplaceExpand(options_, dict);
sha1_.append(options_);
// No #line for options (Make/options)
}
readIfPresent("codeOptions", codeOptions_, false);
libs_.clear();
sha1_.append("<codeLibs>");
if ((eptr = dict.findEntry("codeLibs", keyType::LITERAL)) != nullptr)
{
eptr->readEntry(libs_);
dynamicCodeContext::inplaceExpand(libs_, dict);
sha1_.append(libs_);
// No #line for libs (LIB_LIBS)
}
readIfPresent("codeLibs", codeLibs_, false);
include_.clear();
sha1_.append("<codeInclude>");
if ((eptr = dict.findEntry("codeInclude", keyType::LITERAL)) != nullptr)
{
eptr->readEntry(include_);
dynamicCodeContext::inplaceExpand(include_, dict);
sha1_.append(include_);
addLineDirective(include_, eptr->startLineNumber(), dict);
}
code_.clear();
sha1_.append("<code>");
if ((eptr = dict.findEntry("code", keyType::LITERAL)) != nullptr)
{
eptr->readEntry(code_);
dynamicCodeContext::inplaceExpand(code_, dict);
sha1_.append(code_);
addLineDirective(code_, eptr->startLineNumber(), dict);
}
localCode_.clear();
sha1_.append("<localCode>");
if ((eptr = dict.findEntry("localCode", keyType::LITERAL)) != nullptr)
{
eptr->readEntry(localCode_);
dynamicCodeContext::inplaceExpand(localCode_, dict);
sha1_.append(localCode_);
addLineDirective(localCode_, eptr->startLineNumber(), dict);
}
readIfPresent("codeInclude", codeInclude_);
readIfPresent("localCode", localCode_);
readIfPresent("code", code_);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,9 +38,9 @@ SourceFiles
#ifndef dynamicCodeContext_H
#define dynamicCodeContext_H
#include <functional>
#include "dictionary.H"
#include "SHA1.H"
#include <functional>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -61,27 +61,27 @@ class dynamicCodeContext
//- The SHA1 of the contents
SHA1 sha1_;
//- Optional "codeOptions" entry
string options_;
//- The "codeOptions" entry (optional)
string codeOptions_;
//- Optional "codeLibs" entry
string libs_;
//- The "codeLibs" entry (optional)
string codeLibs_;
//- Optional "codeInclude" entry
string include_;
//- The "codeInclude" entry (optional)
string codeInclude_;
//- Optional "code" entry
string code_;
//- Optional "localCode" entry
//- The "localCode" entry (optional)
string localCode_;
//- The "code" entry (optional)
string code_;
public:
// Constructors
//- Construct null
//- Default construct
dynamicCodeContext();
//- Construct from a dictionary
@ -91,7 +91,7 @@ public:
// Static Member Functions
//- Cleanup string and expand with dictionary parameters
static void inplaceExpand(string& code, const dictionary& dict);
static void inplaceExpand(string& str, const dictionary& dict);
//- Prefix a \#line directive to code.
// The input lineNum is 0-based.
@ -104,7 +104,7 @@ public:
(
string& code,
label lineNum,
const fileName& file
const string& file
);
//- Prefix a \#line directive to code.
@ -120,49 +120,49 @@ public:
// Member Functions
//- Considered valid if not using dictionary::null as the context
bool valid() const;
bool valid() const noexcept;
//- Set code context from a dictionary
void setCodeContext(const dictionary& dict);
//- Return the parent dictionary context
const dictionary& dict() const
const dictionary& dict() const noexcept
{
return dict_.get();
}
//- Return the code-includes
const string& include() const
//- The code options (Make/options)
const string& options() const noexcept
{
return include_;
return codeOptions_;
}
//- Return the code-options
const string& options() const
//- The code libs (LIB_LIBS)
const string& libs() const noexcept
{
return options_;
return codeLibs_;
}
//- Return the code-libs
const string& libs() const
//- The code includes
const string& include() const noexcept
{
return libs_;
return codeInclude_;
}
//- Return the code
const string& code() const
{
return code_;
}
//- Return the local (file-scope) code
const string& localCode() const
//- The local (file-scope) code
const string& localCode() const noexcept
{
return localCode_;
}
//- Return SHA1 calculated from options, libs, include, code
const SHA1& sha1() const
//- The code
const string& code() const noexcept
{
return code_;
}
//- The SHA1 calculated from options, libs, include, code, etc.
const SHA1& sha1() const noexcept
{
return sha1_;
}
@ -174,14 +174,39 @@ public:
}
// Reading
//- Read string entry from context dictionary
//- append content to SHA1 hashing and add line number etc.
//
// The string is cleared before reading.
bool readEntry
(
const word& key,
string& str,
bool mandatory = true,
bool withLineNum = true
);
//- Read optional string entry from context dictionary,
//- append content to SHA1 hashing and add line number etc.
//
// The string is cleared before reading.
bool readIfPresent
(
const word& key,
string& str,
bool withLineNum = true
);
// Member Operators
//- Cast to dictionary
operator const dictionary&() const
operator const dictionary&() const noexcept
{
return dict_.get();
}
};

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,38 +35,41 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
const Foam::IOdictionary& Foam::codedFixedValuePointPatchField<Type>::dict()
const
Foam::dlLibraryTable& Foam::codedFixedValuePointPatchField<Type>::libs() const
{
const objectRegistry& obr = this->db();
const IOdictionary* dictptr = obr.cfindObject<IOdictionary>("codeDict");
if (dictptr)
{
return *dictptr;
}
return obr.store
(
new IOdictionary
(
IOobject
(
"codeDict",
this->db().time().system(),
this->db(),
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
)
);
return this->db().time().libs();
}
template<class Type>
Foam::dlLibraryTable& Foam::codedFixedValuePointPatchField<Type>::libs() const
Foam::string Foam::codedFixedValuePointPatchField<Type>::description() const
{
return this->db().time().libs();
return
"patch "
+ this->patch().name()
+ " on field "
+ this->internalField().name();
}
template<class Type>
void Foam::codedFixedValuePointPatchField<Type>::clearRedirect() const
{
redirectPatchFieldPtr_.reset(nullptr);
}
template<class Type>
const Foam::dictionary&
Foam::codedFixedValuePointPatchField<Type>::codeDict() const
{
// Inline "code" or from system/codeDict
return
(
dict_.found("code")
? dict_
: codedBase::codeDict(this->db()).subDict(name_)
);
}
@ -89,59 +92,28 @@ void Foam::codedFixedValuePointPatchField<Type>::prepare
// Copy filtered H template
dynCode.addCopyFile(codeTemplateH);
// Debugging: make verbose
// dynCode.setFilterVariable("verbose", "true");
// DetailInfo
// <<"compile " << name_ << " sha1: "
// << context.sha1() << endl;
#ifdef FULLDEBUG
dynCode.setFilterVariable("verbose", "true");
DetailInfo
<<"compile " << name_ << " sha1: " << context.sha1() << endl;
#endif
// Define Make/options
dynCode.setMakeOptions
(
"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()
);
}
template<class Type>
const Foam::dictionary& Foam::codedFixedValuePointPatchField<Type>::codeDict()
const
{
// Use system/codeDict or in-line
return
(
dict_.found("code")
? dict_
: this->dict().subDict(name_)
);
}
template<class Type>
Foam::string Foam::codedFixedValuePointPatchField<Type>::description() const
{
return
"patch "
+ this->patch().name()
+ " on field "
+ this->internalField().name();
}
template<class Type>
void Foam::codedFixedValuePointPatchField<Type>::clearRedirect() const
{
// Remove instantiation of pointPatchField provided by library
redirectPatchFieldPtr_.clear();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
@ -153,7 +125,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
:
fixedValuePointPatchField<Type>(p, iF),
codedBase(),
redirectPatchFieldPtr_()
redirectPatchFieldPtr_(nullptr)
{}
@ -187,7 +159,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
codedBase(),
dict_(dict),
name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
redirectPatchFieldPtr_()
redirectPatchFieldPtr_(nullptr)
{
updateLibrary(name_);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -43,8 +43,7 @@ Description
#{
operator==
(
vector(0,0,1)
*min(10, 0.1*this->db().time().value())
vector(0,0,1) * min(10, 0.1*this->db().time().value())
);
#};
@ -93,9 +92,6 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class IOdictionary;
/*---------------------------------------------------------------------------*\
Class codedFixedValuePointPatchField Declaration
\*---------------------------------------------------------------------------*/
@ -109,7 +105,7 @@ class codedFixedValuePointPatchField
// Private Data
//- Dictionary contents for the boundary condition
mutable dictionary dict_;
dictionary dict_;
const word name_;
@ -118,23 +114,21 @@ class codedFixedValuePointPatchField
// Private Member Functions
const IOdictionary& dict() const;
//- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
// Return a description (type + name) for the output
//- Description (type + name) for the output
virtual string description() const;
// Clear the ptr to the redirected object
//- Clear redirected object(s)
virtual void clearRedirect() const;
// Get the dictionary to initialize the codeContext
//- The code dictionary. Inline "code" or from system/codeDict
virtual const dictionary& codeDict() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
public:

View File

@ -47,6 +47,31 @@ namespace Foam
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::dlLibraryTable& Foam::codedPoints0MotionSolver::libs() const
{
return mesh().time().libs();
}
Foam::string Foam::codedPoints0MotionSolver::description() const
{
return "points0MotionSolver " + name();
}
void Foam::codedPoints0MotionSolver::clearRedirect() const
{
redirectMotionSolverPtr_.reset(nullptr);
}
const Foam::dictionary&
Foam::codedPoints0MotionSolver::codeDict() const
{
return motionSolver::coeffDict();
}
void Foam::codedPoints0MotionSolver::prepare
(
dynamicCode& dynCode,
@ -62,11 +87,11 @@ void Foam::codedPoints0MotionSolver::prepare
// Copy filtered H template
dynCode.addCopyFile(codeTemplateH);
// Debugging: make verbose
// dynCode.setFilterVariable("verbose", "true");
// DetailInfo
// <<"compile " << name_ << " sha1: "
// << context.sha1() << endl;
#ifdef FULLDEBUG
dynCode.setFilterVariable("verbose", "true");
DetailInfo
<<"compile " << name_ << " sha1: " << context.sha1() << endl;
#endif
// Define Make/options
dynCode.setMakeOptions
@ -87,31 +112,6 @@ void Foam::codedPoints0MotionSolver::prepare
}
Foam::dlLibraryTable& Foam::codedPoints0MotionSolver::libs() const
{
return mesh().time().libs();
}
Foam::string Foam::codedPoints0MotionSolver::description() const
{
return "points0MotionSolver " + name();
}
void Foam::codedPoints0MotionSolver::clearRedirect() const
{
redirectMotionSolverPtr_.clear();
}
const Foam::dictionary&
Foam::codedPoints0MotionSolver::codeDict() const
{
return coeffDict();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::codedPoints0MotionSolver::codedPoints0MotionSolver
@ -121,10 +121,10 @@ Foam::codedPoints0MotionSolver::codedPoints0MotionSolver
)
:
motionSolver(mesh, dict, typeName),
codedBase()
codedBase(),
name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
redirectMotionSolverPtr_(nullptr)
{
dict.readCompat<word>("name", {{"redirectType", 1706}}, name_);
updateLibrary(name_);
redirectMotionSolver();
}
@ -140,7 +140,7 @@ Foam::codedPoints0MotionSolver::redirectMotionSolver() const
// Get the dictionary for the solver and override the
// solver name (in case it is not a subdictionary and contains
// the 'coded' as the motionSolver)
dictionary constructDict(coeffDict());
dictionary constructDict(motionSolver::coeffDict());
constructDict.set("solver", name_);
constructDict.set("motionSolver", name_);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -106,18 +106,18 @@ protected:
//- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
//- Return a description (type + name) for the output
//- Description (type + name) for the output
virtual string description() const;
//- Clear any redirected objects
//- Clear redirected object(s)
virtual void clearRedirect() const;
// The dictionary to initialize the codeContext
virtual const dictionary& codeDict() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
//- No copy construct
codedPoints0MotionSolver(const codedPoints0MotionSolver&) = delete;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,37 +36,41 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
const Foam::IOdictionary& Foam::codedFixedValueFvPatchField<Type>::dict() const
Foam::dlLibraryTable& Foam::codedFixedValueFvPatchField<Type>::libs() const
{
const objectRegistry& obr = this->db();
const IOdictionary* dictptr = obr.cfindObject<IOdictionary>("codeDict");
if (dictptr)
{
return *dictptr;
}
return obr.store
(
new IOdictionary
(
IOobject
(
"codeDict",
this->db().time().system(),
this->db(),
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
)
);
return this->db().time().libs();
}
template<class Type>
Foam::dlLibraryTable& Foam::codedFixedValueFvPatchField<Type>::libs() const
Foam::string Foam::codedFixedValueFvPatchField<Type>::description() const
{
return this->db().time().libs();
return
"patch "
+ this->patch().name()
+ " on field "
+ this->internalField().name();
}
template<class Type>
void Foam::codedFixedValueFvPatchField<Type>::clearRedirect() const
{
redirectPatchFieldPtr_.reset(nullptr);
}
template<class Type>
const Foam::dictionary&
Foam::codedFixedValueFvPatchField<Type>::codeDict() const
{
// Inline "code" or from system/codeDict
return
(
dict_.found("code")
? dict_
: codedBase::codeDict(this->db()).subDict(name_)
);
}
@ -89,59 +93,28 @@ void Foam::codedFixedValueFvPatchField<Type>::prepare
// Copy filtered H template
dynCode.addCopyFile(codeTemplateH);
// Debugging: make verbose
// dynCode.setFilterVariable("verbose", "true");
// DetailInfo
// <<"compile " << name_ << " sha1: "
// << context.sha1() << endl;
#ifdef FULLDEBUG
dynCode.setFilterVariable("verbose", "true");
DetailInfo
<<"compile " << name_ << " sha1: " << context.sha1() << endl;
#endif
// Define Make/options
dynCode.setMakeOptions
(
"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()
);
}
template<class Type>
const Foam::dictionary& Foam::codedFixedValueFvPatchField<Type>::codeDict()
const
{
// use system/codeDict or in-line
return
(
dict_.found("code")
? dict_
: this->dict().subDict(name_)
);
}
template<class Type>
Foam::string Foam::codedFixedValueFvPatchField<Type>::description() const
{
return
"patch "
+ this->patch().name()
+ " on field "
+ this->internalField().name();
}
template<class Type>
void Foam::codedFixedValueFvPatchField<Type>::clearRedirect() const
{
// remove instantiation of fvPatchField provided by library
redirectPatchFieldPtr_.clear();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
@ -153,7 +126,7 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField
:
fixedValueFvPatchField<Type>(p, iF),
codedBase(),
redirectPatchFieldPtr_()
redirectPatchFieldPtr_(nullptr)
{}
@ -186,7 +159,7 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField
codedBase(),
dict_(dict),
name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
redirectPatchFieldPtr_()
redirectPatchFieldPtr_(nullptr)
{
updateLibrary(name_);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -94,9 +94,6 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class IOdictionary;
/*---------------------------------------------------------------------------*\
Class codedFixedValueFvPatchField Declaration
\*---------------------------------------------------------------------------*/
@ -110,7 +107,7 @@ class codedFixedValueFvPatchField
// Private Data
//- Dictionary contents for the boundary condition
const dictionary dict_;
dictionary dict_;
const word name_;
@ -119,23 +116,21 @@ class codedFixedValueFvPatchField
// Private Member Functions
const IOdictionary& dict() const;
//- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
// Return a description (type + name) for the output
//- Description (type + name) for the output
virtual string description() const;
// Clear the ptr to the redirected object
//- Clear redirected object(s)
virtual void clearRedirect() const;
// Get the dictionary to initialize the codeContext
//- The code dictionary. Inline "code" or from system/codeDict
virtual const dictionary& codeDict() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
public:

View File

@ -35,37 +35,41 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
const Foam::IOdictionary& Foam::codedMixedFvPatchField<Type>::dict() const
Foam::dlLibraryTable& Foam::codedMixedFvPatchField<Type>::libs() const
{
const objectRegistry& obr = this->db();
const IOdictionary* dictptr = obr.cfindObject<IOdictionary>("codeDict");
if (dictptr)
{
return *dictptr;
}
return obr.store
(
new IOdictionary
(
IOobject
(
"codeDict",
this->db().time().system(),
this->db(),
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
)
);
return this->db().time().libs();
}
template<class Type>
Foam::dlLibraryTable& Foam::codedMixedFvPatchField<Type>::libs() const
Foam::string Foam::codedMixedFvPatchField<Type>::description() const
{
return this->db().time().libs();
return
"patch "
+ this->patch().name()
+ " on field "
+ this->internalField().name();
}
template<class Type>
void Foam::codedMixedFvPatchField<Type>::clearRedirect() const
{
redirectPatchFieldPtr_.reset(nullptr);
}
template<class Type>
const Foam::dictionary&
Foam::codedMixedFvPatchField<Type>::codeDict() const
{
// Inline "code" or from system/codeDict
return
(
dict_.found("code")
? dict_
: codedBase::codeDict(this->db()).subDict(name_)
);
}
@ -88,59 +92,28 @@ void Foam::codedMixedFvPatchField<Type>::prepare
// Copy filtered H template
dynCode.addCopyFile(codeTemplateH);
// Debugging: make verbose
// dynCode.setFilterVariable("verbose", "true");
// DetailInfo
// <<"compile " << name_ << " sha1: "
// << context.sha1() << endl;
#ifdef FULLDEBUG
dynCode.setFilterVariable("verbose", "true");
DetailInfo
<<"compile " << name_ << " sha1: " << context.sha1() << endl;
#endif
// Define Make/options
dynCode.setMakeOptions
(
"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()
);
}
template<class Type>
const Foam::dictionary& Foam::codedMixedFvPatchField<Type>::codeDict()
const
{
// use system/codeDict or in-line
return
(
dict_.found("code")
? dict_
: this->dict().subDict(name_)
);
}
template<class Type>
Foam::string Foam::codedMixedFvPatchField<Type>::description() const
{
return
"patch "
+ this->patch().name()
+ " on field "
+ this->internalField().name();
}
template<class Type>
void Foam::codedMixedFvPatchField<Type>::clearRedirect() const
{
// remove instantiation of fvPatchField provided by library
redirectPatchFieldPtr_.clear();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
@ -152,7 +125,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
:
mixedFvPatchField<Type>(p, iF),
codedBase(),
redirectPatchFieldPtr_()
redirectPatchFieldPtr_(nullptr)
{}
@ -185,7 +158,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
codedBase(),
dict_(dict),
name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
redirectPatchFieldPtr_()
redirectPatchFieldPtr_(nullptr)
{
updateLibrary(name_);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -104,11 +104,6 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class dynamicCode;
class dynamicCodeContext;
class IOdictionary;
/*---------------------------------------------------------------------------*\
Class codedMixedFvPatchField Declaration
\*---------------------------------------------------------------------------*/
@ -122,18 +117,13 @@ class codedMixedFvPatchField
// Private Data
//- Dictionary contents for the boundary condition
mutable dictionary dict_;
dictionary dict_;
const word name_;
mutable autoPtr<mixedFvPatchField<Type>> redirectPatchFieldPtr_;
// Private Member Functions
const IOdictionary& dict() const;
protected:
// Protected Member Functions
@ -141,18 +131,18 @@ protected:
//- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
// Return a description (type + name) for the output
//- Description (type + name) for the output
virtual string description() const;
// Clear the ptr to the redirected object
//- Clear redirected object(s)
virtual void clearRedirect() const;
// Get the dictionary to initialize the codeContext
//- The code dictionary. Inline "code" or from system/codeDict
virtual const dictionary& codeDict() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
public:

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -31,6 +31,7 @@ License
#include "dictionary.H"
#include "Time.H"
#include "dynamicCode.H"
#include "dynamicCodeContext.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -52,6 +53,31 @@ namespace functionObjects
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::dlLibraryTable& Foam::functionObjects::codedFunctionObject::libs() const
{
return time_.libs();
}
Foam::string Foam::functionObjects::codedFunctionObject::description() const
{
return "functionObject " + name();
}
void Foam::functionObjects::codedFunctionObject::clearRedirect() const
{
redirectFunctionObjectPtr_.reset(nullptr);
}
const Foam::dictionary&
Foam::functionObjects::codedFunctionObject::codeDict() const
{
return dict_;
}
void Foam::functionObjects::codedFunctionObject::prepare
(
dynamicCode& dynCode,
@ -72,11 +98,11 @@ void Foam::functionObjects::codedFunctionObject::prepare
// Copy filtered H template
dynCode.addCopyFile(codeTemplateH);
// Debugging: make verbose
// dynCode.setFilterVariable("verbose", "true");
// DetailInfo
// <<"compile " << name_ << " sha1: "
// << context.sha1() << endl;
#ifdef FULLDEBUG
dynCode.setFilterVariable("verbose", "true");
DetailInfo
<<"compile " << name_ << " sha1: " << context.sha1() << endl;
#endif
// Define Make/options
dynCode.setMakeOptions
@ -94,31 +120,6 @@ void Foam::functionObjects::codedFunctionObject::prepare
}
Foam::dlLibraryTable& Foam::functionObjects::codedFunctionObject::libs() const
{
return time_.libs();
}
Foam::string Foam::functionObjects::codedFunctionObject::description() const
{
return "functionObject " + name();
}
void Foam::functionObjects::codedFunctionObject::clearRedirect() const
{
redirectFunctionObjectPtr_.clear();
}
const Foam::dictionary&
Foam::functionObjects::codedFunctionObject::codeDict() const
{
return dict_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::codedFunctionObject::codedFunctionObject
@ -189,99 +190,15 @@ bool Foam::functionObjects::codedFunctionObject::read(const dictionary& dict)
dict.readCompat<word>("name", {{"redirectType", 1706}}, name_);
label nKeywords = 0;
auto& ctx = codedBase::codeContext();
const entry* eptr;
codeData_.clear();
codedBase::append("<codeData>");
if ((eptr = dict.findEntry("codeData", keyType::LITERAL)) != nullptr)
{
eptr->readEntry(codeData_);
dynamicCodeContext::inplaceExpand(codeData_, dict);
codedBase::append(codeData_);
dynamicCodeContext::addLineDirective
(
codeData_,
eptr->startLineNumber(),
dict.name()
);
++nKeywords;
}
codeRead_.clear();
codedBase::append("<codeRead>");
if ((eptr = dict.findEntry("codeRead", keyType::LITERAL)) != nullptr)
{
eptr->readEntry(codeRead_);
dynamicCodeContext::inplaceExpand(codeRead_, dict);
codedBase::append(codeRead_);
dynamicCodeContext::addLineDirective
(
codeRead_,
eptr->startLineNumber(),
dict.name()
);
++nKeywords;
}
codeExecute_.clear();
codedBase::append("<codeExecute>");
if ((eptr = dict.findEntry("codeExecute", keyType::LITERAL)) != nullptr)
{
eptr->readEntry(codeExecute_);
dynamicCodeContext::inplaceExpand(codeExecute_, dict);
codedBase::append(codeExecute_);
dynamicCodeContext::addLineDirective
(
codeExecute_,
eptr->startLineNumber(),
dict.name()
);
++nKeywords;
}
codeWrite_.clear();
codedBase::append("<codeWrite>");
if ((eptr = dict.findEntry("codeWrite", keyType::LITERAL)) != nullptr)
{
eptr->readEntry(codeWrite_);
dynamicCodeContext::inplaceExpand(codeWrite_, dict);
codedBase::append(codeWrite_);
dynamicCodeContext::addLineDirective
(
codeWrite_,
eptr->startLineNumber(),
dict.name()
);
++nKeywords;
}
codeEnd_.clear();
codedBase::append("<codeEnd>");
if ((eptr = dict.findEntry("codeEnd", keyType::LITERAL)) != nullptr)
{
eptr->readEntry(codeEnd_);
dynamicCodeContext::inplaceExpand(codeEnd_, dict);
codedBase::append(codeEnd_);
dynamicCodeContext::addLineDirective
(
codeEnd_,
eptr->startLineNumber(),
dict.name()
);
++nKeywords;
}
// Get code chunks, no short-circuiting
int nKeywords = 0;
nKeywords += ctx.readIfPresent("codeData", codeData_);
nKeywords += ctx.readIfPresent("codeRead", codeRead_);
nKeywords += ctx.readIfPresent("codeExecute", codeExecute_);
nKeywords += ctx.readIfPresent("codeWrite", codeWrite_);
nKeywords += ctx.readIfPresent("codeEnd", codeEnd_);
if (!nKeywords)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,7 +38,7 @@ Description
codeInclude | include files
codeOptions | include paths; inserted into EXE_INC in Make/options
codeLibs | link line; inserted into LIB_LIBS in Make/options
codeData | c++; local member data (null constructed);
codeData | c++; local member data (default constructed);
localCode | c++; local static functions;
codeRead | c++; upon functionObject::read();
codeExecute | c++; upon functionObject::execute();
@ -122,18 +122,18 @@ protected:
//- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
//- Return a description (type + name) for the output
//- Description (type + name) for the output
virtual string description() const;
//- Clear any redirected objects
//- Clear redirected object(s)
virtual void clearRedirect() const;
//- The dictionary to initialize the codeContext
//- The code dictionary
virtual const dictionary& codeDict() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
//- No copy construct
codedFunctionObject(const codedFunctionObject&) = delete;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -34,6 +34,35 @@ License
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
Foam::dlLibraryTable& Foam::fv::CodedSource<Type>::libs() const
{
return mesh_.time().libs();
}
template<class Type>
Foam::string Foam::fv::CodedSource<Type>::description() const
{
return "fvOption::" + name_;
}
template<class Type>
void Foam::fv::CodedSource<Type>::clearRedirect() const
{
redirectFvOptionPtr_.reset(nullptr);
}
template<class Type>
const Foam::dictionary& Foam::fv::CodedSource<Type>::codeDict() const
{
return coeffs_;
}
template<class Type>
void Foam::fv::CodedSource<Type>::prepare
(
@ -53,17 +82,17 @@ void Foam::fv::CodedSource<Type>::prepare
dynCode.setFilterVariable("codeAddSup", codeAddSup_);
dynCode.setFilterVariable("codeConstrain", codeConstrain_);
// compile filtered C template
dynCode.addCompileFile("codedFvOptionTemplate.C");
// Compile filtered C template
dynCode.addCompileFile(codeTemplateC);
// copy filtered H template
dynCode.addCopyFile("codedFvOptionTemplate.H");
// Copy filtered H template
dynCode.addCopyFile(codeTemplateH);
// debugging: make verbose
// dynCode.setFilterVariable("verbose", "true");
// DetailInfo
// <<"compile " << name_ << " sha1: "
// << context.sha1() << endl;
#ifdef FULLDEBUG
dynCode.setFilterVariable("verbose", "true");
DetailInfo
<<"compile " << name_ << " sha1: " << context.sha1() << endl;
#endif
// define Make/options
dynCode.setMakeOptions
@ -75,43 +104,15 @@ void Foam::fv::CodedSource<Type>::prepare
"-I$(LIB_SRC)/sampling/lnInclude \\\n"
+ context.options()
+ "\n\nLIB_LIBS = \\\n"
" -lfiniteVolume \\\n"
" -lfvOptions \\\n"
" -lmeshTools \\\n"
" -lsampling \\\n"
" -lfiniteVolume \\\n"
+ context.libs()
);
}
template<class Type>
Foam::dlLibraryTable& Foam::fv::CodedSource<Type>::libs() const
{
return mesh_.time().libs();
}
template<class Type>
Foam::string Foam::fv::CodedSource<Type>::description() const
{
return "fvOption::" + name_;
}
template<class Type>
void Foam::fv::CodedSource<Type>::clearRedirect() const
{
redirectFvOptionPtr_.clear();
}
template<class Type>
const Foam::dictionary& Foam::fv::CodedSource<Type>::codeDict() const
{
return coeffs_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
@ -140,7 +141,7 @@ Foam::fv::option& Foam::fv::CodedSource<Type>::redirectFvOption() const
constructDict.set("type", name_);
constructDict.changeKeyword(modelType_ & "Coeffs", name_ & "Coeffs");
redirectFvOptionPtr_ = option::New
redirectFvOptionPtr_ = fv::option::New
(
name_,
constructDict,

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -123,7 +123,7 @@ namespace fv
template<class Type>
class CodedSource
:
public cellSetOption,
public fv::cellSetOption,
protected codedBase
{
protected:
@ -136,8 +136,8 @@ protected:
string codeAddSup_;
string codeConstrain_;
//- Underlying functionObject
mutable autoPtr<option> redirectFvOptionPtr_;
//- Underlying code
mutable autoPtr<fv::option> redirectFvOptionPtr_;
// Protected Member Functions
@ -145,21 +145,32 @@ protected:
//- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const;
//- Description (type + name) for the output
virtual string description() const;
//- Clear redirected object(s)
virtual void clearRedirect() const;
//- Get the dictionary to initialize the code context
virtual const dictionary& codeDict() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
//- Return a description (type + name) for the output
virtual string description() const;
//- Clear any redirected objects
virtual void clearRedirect() const;
//- Get the dictionary to initialize the codeContext
virtual const dictionary& codeDict() const;
public:
// Static Data Members
//- Name of the C code template to be used
static constexpr const char* const codeTemplateC
= "codedFvOptionTemplate.C";
//- Name of the H code template to be used
static constexpr const char* const codeTemplateH
= "codedFvOptionTemplate.H";
//- Runtime type information
TypeName("coded");

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -41,70 +41,30 @@ bool Foam::fv::CodedSource<Type>::read(const dictionary& dict)
}
coeffs_.readEntry("fields", fieldNames_);
applied_.setSize(fieldNames_.size(), false);
applied_.resize(fieldNames_.size(), false);
dict.readCompat<word>("name", {{"redirectType", 1706}}, name_);
// Code chunks
codedBase::append("<codeCorrect>");
{
const entry& e =
coeffs_.lookupEntry("codeCorrect", keyType::LITERAL);
// Code context chunks
e.readEntry(codeCorrect_);
dynamicCodeContext::inplaceExpand(codeCorrect_, coeffs_);
auto& ctx = codedBase::codeContext();
codedBase::append(codeCorrect_);
ctx.readEntry("codeCorrect", codeCorrect_);
ctx.readEntry("codeAddSup", codeAddSup_);
dynamicCodeContext::addLineDirective
// ctx.readEntry("codeConstrain", codeConstrain_);
ctx.readEntry // Compatibility
(
codeCorrect_,
e.startLineNumber(),
coeffs_
);
}
codedBase::append("<codeAddSup>");
{
const entry& e =
coeffs_.lookupEntry("codeAddSup", keyType::LITERAL);
e.readEntry(codeAddSup_);
dynamicCodeContext::inplaceExpand(codeAddSup_, coeffs_);
codedBase::append(codeAddSup_);
dynamicCodeContext::addLineDirective
(
codeAddSup_,
e.startLineNumber(),
coeffs_
);
}
codedBase::append("<codeConstrain>");
{
const entry& e =
coeffs_.lookupEntryCompat
(
"codeConstrain",
{{ "codeSetValue", 1812 }}, keyType::LITERAL
{{ "codeSetValue", 1812 }},
keyType::LITERAL
).keyword(),
codeConstrain_
);
e.readEntry(codeConstrain_);
dynamicCodeContext::inplaceExpand(codeConstrain_, coeffs_);
codedBase::append(codeConstrain_);
dynamicCodeContext::addLineDirective
(
codeConstrain_,
e.startLineNumber(),
coeffs_
);
}
return true;
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,6 +26,7 @@ License
\*---------------------------------------------------------------------------*/
#include "dynamicCode.H"
#include "dynamicCodeContext.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -37,6 +38,48 @@ Foam::PatchFunction1Types::CodedField<Type>::libs() const
}
template<class Type>
Foam::string
Foam::PatchFunction1Types::CodedField<Type>::description() const
{
return "CodedField " + name_;
}
template<class Type>
void Foam::PatchFunction1Types::CodedField<Type>::clearRedirect() const
{
redirectFunctionPtr_.reset(nullptr);
}
template<class Type>
const Foam::dictionary&
Foam::PatchFunction1Types::CodedField<Type>::codeDict
(
const dictionary& dict
) const
{
// Use named subdictionary if present to provide the code.
// This allows running with multiple PatchFunction1s
return
(
dict.found("code")
? dict
: dict.subDict(name_)
);
}
template<class Type>
const Foam::dictionary&
Foam::PatchFunction1Types::CodedField<Type>::codeDict() const
{
return codeDict(dict_);
}
template<class Type>
void Foam::PatchFunction1Types::CodedField<Type>::prepare
(
@ -65,70 +108,28 @@ void Foam::PatchFunction1Types::CodedField<Type>::prepare
// Copy filtered H template
dynCode.addCopyFile(codeTemplateH);
// Debugging: make verbose
// dynCode.setFilterVariable("verbose", "true");
// DetailInfo
// <<"compile " << name_ << " sha1: "
// << context.sha1() << endl;
#ifdef FULLDEBUG
dynCode.setFilterVariable("verbose", "true");
DetailInfo
<<"compile " << name_ << " sha1: " << context.sha1() << endl;
#endif
// Define Make/options
dynCode.setMakeOptions
(
"EXE_INC = -g \\\n"
"-I$(LIB_SRC)/meshTools/lnInclude \\\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()
);
}
template<class Type>
const Foam::dictionary&
Foam::PatchFunction1Types::CodedField<Type>::codeDict
(
const dictionary& dict
) const
{
// Use named subdictionary if present to provide the code. This allows
// running with multiple PatchFunction1s
return
(
dict.found("code")
? dict
: dict.subDict(name_)
);
}
template<class Type>
const Foam::dictionary&
Foam::PatchFunction1Types::CodedField<Type>::codeDict() const
{
return codeDict(dict_);
}
template<class Type>
Foam::string
Foam::PatchFunction1Types::CodedField<Type>::description() const
{
return "CodedField " + name_;
}
template<class Type>
void Foam::PatchFunction1Types::CodedField<Type>::clearRedirect() const
{
// remove instantiation of fvPatchField provided by library
redirectFunctionPtr_.clear();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -120,20 +120,24 @@ protected:
//- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const;
//- Description (type + name) for the output
virtual string description() const;
//- Clear redirected object(s)
virtual void clearRedirect() const;
// Get the code (sub)dictionary
virtual const dictionary& codeDict(const dictionary& dict) const;
// Get the code dictionary
virtual const dictionary& codeDict() const;
//- Adapt the context for the current object
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
// Return a description (type + name) for the output
virtual string description() const;
// Clear the ptr to the redirected object
virtual void clearRedirect() const;
// Get the (sub)dictionary to initialize the codeContext
virtual const dictionary& codeDict(const dictionary& fullDict) const;
// Get the dictionary to initialize the codeContext
virtual const dictionary& codeDict() const;
//- No copy assignment
void operator=(const CodedField<Type>&) = delete;
public:
@ -152,12 +156,6 @@ public:
TypeName("coded");
// Generated Methods
//- No copy assignment
void operator=(const CodedField<Type>&) = delete;
// Constructors
//- Construct from entry name and dictionary