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

View File

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

View File

@ -31,10 +31,13 @@ License
#include "dynamicCode.H" #include "dynamicCode.H"
#include "dynamicCodeContext.H" #include "dynamicCodeContext.H"
#include "dlLibraryTable.H" #include "dlLibraryTable.H"
#include "objectRegistry.H"
#include "IOdictionary.H"
#include "Pstream.H" #include "Pstream.H"
#include "PstreamReduceOps.H" #include "PstreamReduceOps.H"
#include "OSspecific.H" #include "OSspecific.H"
#include "Ostream.H" #include "Ostream.H"
#include "Time.H"
#include "regIOobject.H" #include "regIOobject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -50,7 +53,6 @@ namespace Foam
namespace Foam namespace Foam
{ {
//! \cond fileScope
static inline void writeEntryIfPresent static inline void writeEntryIfPresent
( (
Ostream& os, Ostream& os,
@ -59,16 +61,24 @@ static inline void writeEntryIfPresent
) )
{ {
const entry* eptr = dict.findEntry(key, keyType::LITERAL); 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(); 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]); os.writeEntry(key, toks[0]);
} }
} }
} }
//! \endcond
} // End namespace Foam } // End namespace Foam
@ -77,6 +87,7 @@ static inline void writeEntryIfPresent
void Foam::codedBase::writeCodeDict(Ostream& os, const dictionary& dict) void Foam::codedBase::writeCodeDict(Ostream& os, const dictionary& dict)
{ {
writeEntryIfPresent(os, dict, "codeContext");
writeEntryIfPresent(os, dict, "codeInclude"); writeEntryIfPresent(os, dict, "codeInclude");
writeEntryIfPresent(os, dict, "localCode"); writeEntryIfPresent(os, dict, "localCode");
writeEntryIfPresent(os, dict, "code"); 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 * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void* Foam::codedBase::loadLibrary void* Foam::codedBase::loadLibrary

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -34,12 +34,12 @@ License
void Foam::dynamicCodeContext::inplaceExpand void Foam::dynamicCodeContext::inplaceExpand
( (
string& code, string& str,
const dictionary& dict const dictionary& dict
) )
{ {
stringOps::inplaceTrim(code); stringOps::inplaceTrim(str);
stringOps::inplaceExpand(code, dict); stringOps::inplaceExpand(str, dict);
} }
@ -47,7 +47,7 @@ unsigned Foam::dynamicCodeContext::addLineDirective
( (
string& code, string& code,
label lineNum, label lineNum,
const fileName& file const string& file
) )
{ {
++lineNum; // Change from 0-based to 1-based ++lineNum; // Change from 0-based to 1-based
@ -94,72 +94,81 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::dynamicCodeContext::valid() const bool Foam::dynamicCodeContext::valid() const noexcept
{ {
return &(dict_.get()) != &(dictionary::null); 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) void Foam::dynamicCodeContext::setCodeContext(const dictionary& dict)
{ {
dict_ = std::cref<dictionary>(dict); dict_ = std::cref<dictionary>(dict);
sha1_.clear(); 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) // 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) // No #line for libs (LIB_LIBS)
} readIfPresent("codeLibs", codeLibs_, false);
include_.clear(); readIfPresent("codeInclude", codeInclude_);
sha1_.append("<codeInclude>"); readIfPresent("localCode", localCode_);
if ((eptr = dict.findEntry("codeInclude", keyType::LITERAL)) != nullptr) readIfPresent("code", code_);
{
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);
}
} }

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,38 +35,41 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type> template<class Type>
const Foam::IOdictionary& Foam::codedFixedValuePointPatchField<Type>::dict() Foam::dlLibraryTable& Foam::codedFixedValuePointPatchField<Type>::libs() const
const
{ {
const objectRegistry& obr = this->db(); return this->db().time().libs();
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
)
)
);
} }
template<class Type> 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 // Copy filtered H template
dynCode.addCopyFile(codeTemplateH); dynCode.addCopyFile(codeTemplateH);
// Debugging: make verbose #ifdef FULLDEBUG
// dynCode.setFilterVariable("verbose", "true"); dynCode.setFilterVariable("verbose", "true");
// DetailInfo DetailInfo
// <<"compile " << name_ << " sha1: " <<"compile " << name_ << " sha1: " << context.sha1() << endl;
// << context.sha1() << endl; #endif
// Define Make/options // Define Make/options
dynCode.setMakeOptions dynCode.setMakeOptions
( (
"EXE_INC = -g \\\n" "EXE_INC = -g \\\n"
"-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
"-I$(LIB_SRC)/meshTools/lnInclude \\\n"
+ context.options() + context.options()
+ "\n\nLIB_LIBS = \\\n" + "\n\nLIB_LIBS = \\\n"
" -lOpenFOAM \\\n" " -lOpenFOAM \\\n"
" -lfiniteVolume \\\n" " -lfiniteVolume \\\n"
" -lmeshTools \\\n"
+ context.libs() + 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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type> template<class Type>
@ -153,7 +125,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
: :
fixedValuePointPatchField<Type>(p, iF), fixedValuePointPatchField<Type>(p, iF),
codedBase(), codedBase(),
redirectPatchFieldPtr_() redirectPatchFieldPtr_(nullptr)
{} {}
@ -187,7 +159,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
codedBase(), codedBase(),
dict_(dict), dict_(dict),
name_(dict.getCompat<word>("name", {{"redirectType", 1706}})), name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
redirectPatchFieldPtr_() redirectPatchFieldPtr_(nullptr)
{ {
updateLibrary(name_); updateLibrary(name_);
} }

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,37 +36,41 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type> template<class Type>
const Foam::IOdictionary& Foam::codedFixedValueFvPatchField<Type>::dict() const Foam::dlLibraryTable& Foam::codedFixedValueFvPatchField<Type>::libs() const
{ {
const objectRegistry& obr = this->db(); return this->db().time().libs();
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
)
)
);
} }
template<class Type> 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 // Copy filtered H template
dynCode.addCopyFile(codeTemplateH); dynCode.addCopyFile(codeTemplateH);
// Debugging: make verbose #ifdef FULLDEBUG
// dynCode.setFilterVariable("verbose", "true"); dynCode.setFilterVariable("verbose", "true");
// DetailInfo DetailInfo
// <<"compile " << name_ << " sha1: " <<"compile " << name_ << " sha1: " << context.sha1() << endl;
// << context.sha1() << endl; #endif
// Define Make/options // Define Make/options
dynCode.setMakeOptions dynCode.setMakeOptions
( (
"EXE_INC = -g \\\n" "EXE_INC = -g \\\n"
"-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
"-I$(LIB_SRC)/meshTools/lnInclude \\\n"
+ context.options() + context.options()
+ "\n\nLIB_LIBS = \\\n" + "\n\nLIB_LIBS = \\\n"
" -lOpenFOAM \\\n" " -lOpenFOAM \\\n"
" -lfiniteVolume \\\n" " -lfiniteVolume \\\n"
" -lmeshTools \\\n"
+ context.libs() + 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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type> template<class Type>
@ -153,7 +126,7 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField
: :
fixedValueFvPatchField<Type>(p, iF), fixedValueFvPatchField<Type>(p, iF),
codedBase(), codedBase(),
redirectPatchFieldPtr_() redirectPatchFieldPtr_(nullptr)
{} {}
@ -186,7 +159,7 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField
codedBase(), codedBase(),
dict_(dict), dict_(dict),
name_(dict.getCompat<word>("name", {{"redirectType", 1706}})), name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
redirectPatchFieldPtr_() redirectPatchFieldPtr_(nullptr)
{ {
updateLibrary(name_); updateLibrary(name_);
} }

View File

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

View File

@ -35,37 +35,41 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type> template<class Type>
const Foam::IOdictionary& Foam::codedMixedFvPatchField<Type>::dict() const Foam::dlLibraryTable& Foam::codedMixedFvPatchField<Type>::libs() const
{ {
const objectRegistry& obr = this->db(); return this->db().time().libs();
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
)
)
);
} }
template<class Type> 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 // Copy filtered H template
dynCode.addCopyFile(codeTemplateH); dynCode.addCopyFile(codeTemplateH);
// Debugging: make verbose #ifdef FULLDEBUG
// dynCode.setFilterVariable("verbose", "true"); dynCode.setFilterVariable("verbose", "true");
// DetailInfo DetailInfo
// <<"compile " << name_ << " sha1: " <<"compile " << name_ << " sha1: " << context.sha1() << endl;
// << context.sha1() << endl; #endif
// Define Make/options // Define Make/options
dynCode.setMakeOptions dynCode.setMakeOptions
( (
"EXE_INC = -g \\\n" "EXE_INC = -g \\\n"
"-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
"-I$(LIB_SRC)/meshTools/lnInclude \\\n"
+ context.options() + context.options()
+ "\n\nLIB_LIBS = \\\n" + "\n\nLIB_LIBS = \\\n"
" -lOpenFOAM \\\n" " -lOpenFOAM \\\n"
" -lfiniteVolume \\\n" " -lfiniteVolume \\\n"
" -lmeshTools \\\n"
+ context.libs() + 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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type> template<class Type>
@ -152,7 +125,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
: :
mixedFvPatchField<Type>(p, iF), mixedFvPatchField<Type>(p, iF),
codedBase(), codedBase(),
redirectPatchFieldPtr_() redirectPatchFieldPtr_(nullptr)
{} {}
@ -185,7 +158,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
codedBase(), codedBase(),
dict_(dict), dict_(dict),
name_(dict.getCompat<word>("name", {{"redirectType", 1706}})), name_(dict.getCompat<word>("name", {{"redirectType", 1706}})),
redirectPatchFieldPtr_() redirectPatchFieldPtr_(nullptr)
{ {
updateLibrary(name_); updateLibrary(name_);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -123,7 +123,7 @@ namespace fv
template<class Type> template<class Type>
class CodedSource class CodedSource
: :
public cellSetOption, public fv::cellSetOption,
protected codedBase protected codedBase
{ {
protected: protected:
@ -136,8 +136,8 @@ protected:
string codeAddSup_; string codeAddSup_;
string codeConstrain_; string codeConstrain_;
//- Underlying functionObject //- Underlying code
mutable autoPtr<option> redirectFvOptionPtr_; mutable autoPtr<fv::option> redirectFvOptionPtr_;
// Protected Member Functions // Protected Member Functions
@ -145,21 +145,32 @@ protected:
//- Mutable access to the loaded dynamic libraries //- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const; 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 //- 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
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: 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 //- Runtime type information
TypeName("coded"); TypeName("coded");

View File

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

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -26,6 +26,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "dynamicCode.H" #include "dynamicCode.H"
#include "dynamicCodeContext.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * 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> template<class Type>
void Foam::PatchFunction1Types::CodedField<Type>::prepare void Foam::PatchFunction1Types::CodedField<Type>::prepare
( (
@ -65,70 +108,28 @@ void Foam::PatchFunction1Types::CodedField<Type>::prepare
// Copy filtered H template // Copy filtered H template
dynCode.addCopyFile(codeTemplateH); dynCode.addCopyFile(codeTemplateH);
// Debugging: make verbose #ifdef FULLDEBUG
// dynCode.setFilterVariable("verbose", "true"); dynCode.setFilterVariable("verbose", "true");
// DetailInfo DetailInfo
// <<"compile " << name_ << " sha1: " <<"compile " << name_ << " sha1: " << context.sha1() << endl;
// << context.sha1() << endl; #endif
// Define Make/options // Define Make/options
dynCode.setMakeOptions dynCode.setMakeOptions
( (
"EXE_INC = -g \\\n" "EXE_INC = -g \\\n"
"-I$(LIB_SRC)/meshTools/lnInclude \\\n"
"-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
"-I$(LIB_SRC)/meshTools/lnInclude \\\n"
+ context.options() + context.options()
+ "\n\nLIB_LIBS = \\\n" + "\n\nLIB_LIBS = \\\n"
" -lOpenFOAM \\\n" " -lOpenFOAM \\\n"
" -lfiniteVolume \\\n" " -lfiniteVolume \\\n"
" -lmeshTools \\\n"
+ context.libs() + 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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type> template<class Type>

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -120,20 +120,24 @@ protected:
//- Mutable access to the loaded dynamic libraries //- Mutable access to the loaded dynamic libraries
virtual dlLibraryTable& libs() const; 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 //- 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
virtual string description() const;
// Clear the ptr to the redirected object //- No copy assignment
virtual void clearRedirect() const; void operator=(const CodedField<Type>&) = delete;
// 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;
public: public:
@ -152,12 +156,6 @@ public:
TypeName("coded"); TypeName("coded");
// Generated Methods
//- No copy assignment
void operator=(const CodedField<Type>&) = delete;
// Constructors // Constructors
//- Construct from entry name and dictionary //- Construct from entry name and dictionary