From dbdc119309a5cef2d8d6530e80f683e22317c5f1 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sat, 1 Feb 2020 17:00:35 +0000 Subject: [PATCH] CodedFunction1: Updated documentation --- .../Function1/Coded/CodedFunction1.C | 41 +++++++++------- .../Function1/Coded/CodedFunction1.H | 49 +++++++------------ 2 files changed, 42 insertions(+), 48 deletions(-) diff --git a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C index 10c3066dc9..9c74943b9f 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C +++ b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C @@ -31,7 +31,10 @@ License template const Foam::wordList Foam::Function1s::Coded::codeKeys_ = - {"code", "codeInclude"}; +{ + "code", + "codeInclude" +}; // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -85,7 +88,7 @@ void Foam::Function1s::Coded::prepare template Foam::string Foam::Function1s::Coded::description() const { - return "Function1 " + name_; + return Function1::typeName_() + " " + name_; } @@ -112,6 +115,19 @@ const Foam::wordList& Foam::Function1s::Coded::codeKeys() const } +template +Foam::autoPtr> +Foam::Function1s::Coded::compileAndLink() +{ + updateLibrary(name_); + + dictionary redirectDict(dict_); + redirectDict.set(name_, name_); + + return Function1::New(name_, redirectDict); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -129,14 +145,8 @@ Foam::Function1s::Coded::Coded ? dict.lookup("redirectType") : dict.lookup("name") ), - redirectFunction1Ptr_() -{ - updateLibrary(name_); - - dictionary redirectDict(dict_); - redirectDict.set(name_, name_); - redirectFunction1Ptr_ = Function1::New(name_, redirectDict); -} + redirectFunction1Ptr_(compileAndLink()) +{} @@ -146,14 +156,9 @@ Foam::Function1s::Coded::Coded(const Coded& cf1) Function1(cf1), codedBase(), dict_(cf1.dict_), - name_(cf1.name_) -{ - updateLibrary(name_); - - dictionary redirectDict(dict_); - redirectDict.set(name_, name_); - redirectFunction1Ptr_ = Function1::New(name_, redirectDict); -} + name_(cf1.name_), + redirectFunction1Ptr_(compileAndLink()) +{} template diff --git a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H index b18a78ddba..d65c4a0e71 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H +++ b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H @@ -25,44 +25,31 @@ Class Foam::Function1s::Coded Description - Constructs on-the-fly a Function1 which is then used to evaluate. + Constructs a dynamically compiled Function1. Usage - Example: + Example of a cosine bell shaped pulse inlet: \verbatim - + inlet { - type codedFixedValue; - value uniform 0; - name rampedFixedValue; // name of generated BC + type uniformFixedValue; + uniformValue coded; - code + name pulse; + + codeInclude #{ - operator==(min(10, 0.1*this->db().time().value())); + #include "mathematicalConstants.H" #}; - // codeInclude - //#{ - // #include "fvCFD.H" - //#}; - - // codeOptions - //#{ - // -I$(LIB_SRC)/finiteVolume/lnInclude - //#}; - } - \endverbatim - - A special form is if the 'code' section is not supplied. In this case - the code is read from a (runTimeModifiable!) dictionary system/codeDict - which would have a corresponding entry: - - \verbatim - - { code #{ - operator==(min(10, 0.1*this->db().time().value())); + return vector + ( + 0.5*(1 - cos(constant::mathematical::twoPi*min(x/0.3, 1))), + 0, + 0 + ); #}; } \endverbatim @@ -72,8 +59,8 @@ See also Foam::functionEntries::codeStream SourceFiles - CodedI.H - Coded.C + CodedFunction1I.H + CodedFunction1.C \*---------------------------------------------------------------------------*/ @@ -135,6 +122,8 @@ class Coded //- Get the keywords associated with source code virtual const wordList& codeKeys() const; + autoPtr> compileAndLink(); + public: