mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: provide dictionary access for coded BCs etc (#1922)
- in some cases, additional dictionary inputs are useful for extending
the input parameters or functionality of dynamic coded conditions.
Typically this can be used to provide a simple set of dictionary
inputs that are used to drive specific code, but allows changing the
inputs without causing a recompilation.
Accessed with this type of code:
```
const dictionary& dict = this->codeContext();
```
boundary conditions and function objects:
* specify an additional codeContext dictionary entry:
```
codeContext
{
...
}
```
PatchFunction1:
* The code context dictionary is simply the dictionary used to specify
the PatchFunction1 coefficients.
To replicated persistant data, use local member static data.
Eg,
```
code
#{
// Persistent (Member) Data
static autoPtr<Function1<scalar>> baseVel;
static autoPtr<Function1<vector>> baseDir;
...
#}
```
fvOptions:
* currently not applicable
This commit is contained in:
@ -72,6 +72,14 @@ void Foam::functionObjects::codedFunctionObject::clearRedirect() const
|
||||
}
|
||||
|
||||
|
||||
const Foam::dictionary&
|
||||
Foam::functionObjects::codedFunctionObject::codeContext() const
|
||||
{
|
||||
const dictionary* ptr = dict_.findDict("codeContext", keyType::LITERAL);
|
||||
return (ptr ? *ptr : dictionary::null);
|
||||
}
|
||||
|
||||
|
||||
const Foam::dictionary&
|
||||
Foam::functionObjects::codedFunctionObject::codeDict() const
|
||||
{
|
||||
@ -157,6 +165,22 @@ Foam::functionObjects::codedFunctionObject::redirectFunctionObject() const
|
||||
time_,
|
||||
constructDict
|
||||
);
|
||||
|
||||
|
||||
// Forward copy of codeContext to the code template
|
||||
auto* contentPtr =
|
||||
dynamic_cast<dictionaryContent*>(redirectFunctionObjectPtr_.get());
|
||||
|
||||
if (contentPtr)
|
||||
{
|
||||
contentPtr->dict(this->codeContext());
|
||||
}
|
||||
else
|
||||
{
|
||||
WarningInFunction
|
||||
<< name_ << " Did not derive from dictionaryContent"
|
||||
<< nl << nl;
|
||||
}
|
||||
}
|
||||
return *redirectFunctionObjectPtr_;
|
||||
}
|
||||
|
||||
@ -44,6 +44,7 @@ Description
|
||||
codeExecute | c++; upon functionObject::execute()
|
||||
codeWrite | c++; upon functionObject::write()
|
||||
codeEnd | c++; upon functionObject::end()
|
||||
codeContext | additional dictionary context for the code
|
||||
\endplaintable
|
||||
|
||||
Usage
|
||||
@ -67,6 +68,10 @@ Usage
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Note
|
||||
The code context dictionary can be supplied separately as the
|
||||
\c codeContext entry.
|
||||
|
||||
See also
|
||||
Foam::functionObject
|
||||
Foam::codedBase
|
||||
@ -128,6 +133,9 @@ protected:
|
||||
//- Clear redirected object(s)
|
||||
virtual void clearRedirect() const;
|
||||
|
||||
//- Additional 'codeContext' dictionary to pass through
|
||||
virtual const dictionary& codeContext() const;
|
||||
|
||||
//- The code dictionary
|
||||
virtual const dictionary& codeDict() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user