mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve dynamicCode consistency
- refactor and provision for additional code context
This commit is contained in:
committed by
Andrew Heather
parent
2b7b3700c2
commit
cf9063878e
@ -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)
|
||||
{
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user