diff --git a/etc/codeTemplates/dynamicCode/codedFunction1Template.C b/etc/codeTemplates/dynamicCode/codedFunction1Template.C new file mode 100644 index 0000000000000000000000000000000000000000..ebdf9765561cf1a7cf6481a2c5218940b347cd0c --- /dev/null +++ b/etc/codeTemplates/dynamicCode/codedFunction1Template.C @@ -0,0 +1,121 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) YEAR AUTHOR,AFFILIATION +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "codedFunction1Template.H" +#include "addToRunTimeSelectionTable.H" +#include "unitConversion.H" + +//{{{ begin codeInclude +${codeInclude} +//}}} end codeInclude + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +//{{{ begin localCode +${localCode} +//}}} end localCode + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +// dynamicCode: +// SHA1 = ${SHA1sum} +// +// unique function name that can be checked if the correct library version +// has been loaded +extern "C" void ${typeName}_${SHA1sum}(bool load) +{ + if (load) + { + // Code that can be explicitly executed after loading + } + else + { + // Code that can be explicitly executed before unloading + } +} + + +namespace Function1Types +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +//makeFunction1(${typeName}Function1, ${TemplateType}); +defineTypeNameAndDebug +( + ${typeName}Function1_${TemplateType}, + 0 +); +Function1<${TemplateType}>::addRemovabledictionaryConstructorToTable + <${typeName}Function1_${TemplateType}> + addRemovable${typeName}Function1_${TemplateType}ConstructorToTable_; + +} // namespace Function1Types +} // namespace Foam + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::Function1Types:: +${typeName}Function1_${TemplateType}:: +${typeName}Function1_${TemplateType} +( + const word& entryName, + const dictionary& dict, + const objectRegistry* obrPtr +) +: + Function1<${TemplateType}>(entryName, dict, obrPtr) +{ + if (${verbose:-false}) + { + printMessage("Construct ${typeName} Function1 from dictionary"); + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::${TemplateType} +Foam::Function1Types::${typeName}Function1_${TemplateType}::value +( + const scalar x +) const +{ +//{{{ begin code + ${code} +//}}} end code +} + + +// ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/codedFunction1Template.H b/etc/codeTemplates/dynamicCode/codedFunction1Template.H new file mode 100644 index 0000000000000000000000000000000000000000..3b2de974a937201c76899149d3902fc4c947ee72 --- /dev/null +++ b/etc/codeTemplates/dynamicCode/codedFunction1Template.H @@ -0,0 +1,119 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Description + Template for use with dynamic code generation of a Function1 + +SourceFiles + codedFunction1Template.C + +\*---------------------------------------------------------------------------*/ + +#ifndef dynamicCode_codedFunction1_${typeName}_${TemplateType}_H +#define dynamicCode_codedFunction1_${typeName}_${TemplateType}_H + +#include "Function1.H" +#include "dictionaryContent.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace Function1Types +{ + +/*---------------------------------------------------------------------------*\ + A coded version Function1 +\*---------------------------------------------------------------------------*/ + +class ${typeName}Function1_${TemplateType} +: + public Function1<${TemplateType}>, + public dictionaryContent +{ + // Private Member Functions + + //- Report a message with the SHA1sum + inline static void printMessage(const char* message) + { + Info<< message << " sha1: " << SHA1sum << '\n'; + } + +public: + + //- SHA1 representation of the code content + static constexpr const char* const SHA1sum = "${SHA1sum}"; + + //- Runtime type information + TypeName("${typeName}"); + + + // Constructors + + //- Construct from entry name, dictionary and registry + ${typeName}Function1_${TemplateType} + ( + const word& entryName, + const dictionary& dict, + const objectRegistry* obrPtr = nullptr + ); + + //- Copy construct + ${typeName}Function1_${TemplateType} + ( + const ${typeName}Function1_${TemplateType}& rhs + ) = default; + + //- Construct and return a clone + virtual tmp<Function1<${TemplateType}>> clone() const + { + return tmp<Function1<${TemplateType}>> + ( + new ${typeName}Function1_${TemplateType}(*this) + ); + } + + + //- Destructor + virtual ~${typeName}Function1_${TemplateType}() = default; + + + // Member Functions + + //- Return value as a function of (scalar) independent variable + virtual ${TemplateType} value(const scalar x) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Function1Types +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C index aad851509e8e1d0baad7ff8bebe0920115918392..0e8a9cb9aadbd85e0616e3f685e2e9ded628e585 100644 --- a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C +++ b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C @@ -83,9 +83,13 @@ addRemovableToRunTimeSelectionTable dictionary ); +} // End namespace fv +} // End namespace Foam + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam::fv:: ${typeName}FvOption${SourceType}:: ${typeName}FvOption${SourceType} ( @@ -106,6 +110,7 @@ ${typeName}FvOption${SourceType} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // +Foam::fv:: ${typeName}FvOption${SourceType}:: ~${typeName}FvOption${SourceType}() { @@ -119,6 +124,7 @@ ${typeName}FvOption${SourceType}:: // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void +Foam::fv:: ${typeName}FvOption${SourceType}::correct ( GeometricField<${TemplateType}, fvPatchField, volMesh>& fld @@ -136,6 +142,7 @@ ${typeName}FvOption${SourceType}::correct void +Foam::fv:: ${typeName}FvOption${SourceType}::addSup ( fvMatrix<${TemplateType}>& eqn, @@ -154,6 +161,7 @@ ${typeName}FvOption${SourceType}::addSup void +Foam::fv:: ${typeName}FvOption${SourceType}::addSup ( const volScalarField& rho, @@ -173,6 +181,7 @@ ${typeName}FvOption${SourceType}::addSup void +Foam::fv:: ${typeName}FvOption${SourceType}::constrain ( fvMatrix<${TemplateType}>& eqn, @@ -190,9 +199,4 @@ ${typeName}FvOption${SourceType}::constrain } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace fv -} // End namespace Foam - // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H index b38b4e92f60264fd51c1f804bd360888d82a3f78..199c07243bc7bfc3f0c1f229d951163aa86b2651 100644 --- a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H +++ b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H @@ -163,7 +163,7 @@ public: // Member Functions //- Code context as a dictionary - const dictionary& codeContext() const + const dictionary& codeContext() const noexcept { return dictionaryContent::dict(); } diff --git a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C index ffce21acf361b7fadd2f43047816d7dab33e70b5..79a06ac799e6fe4bc3120e5fcbba4623d0700eca 100644 --- a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C +++ b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C @@ -80,14 +80,17 @@ defineTypeNameAndDebug ${typeName}PatchFunction1${FieldType}, 0 ); -PatchFunction1<${TemplateType}>::adddictionaryConstructorToTable +PatchFunction1<${TemplateType}>::addRemovabledictionaryConstructorToTable <${typeName}PatchFunction1${FieldType}> - add${typeName}PatchFunction1${FieldType}ConstructorToTable_; + addRemovable${typeName}PatchFunction1${FieldType}ConstructorToTable_; +} // namespace PatchFunction1Types +} // namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam::PatchFunction1Types:: ${typeName}PatchFunction1${FieldType}:: ${typeName}PatchFunction1${FieldType} ( @@ -107,6 +110,7 @@ ${typeName}PatchFunction1${FieldType} } +Foam::PatchFunction1Types:: ${typeName}PatchFunction1${FieldType}:: ${typeName}PatchFunction1${FieldType} ( @@ -121,7 +125,7 @@ ${typeName}PatchFunction1${FieldType} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::tmp<Foam::Field<Foam::${TemplateType}>> -${typeName}PatchFunction1${FieldType}::value +Foam::PatchFunction1Types::${typeName}PatchFunction1${FieldType}::value ( const scalar x ) const @@ -132,10 +136,4 @@ ${typeName}PatchFunction1${FieldType}::value } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace PatchFunction1Types -} // End namespace Foam - - // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H index 46d7d08086beb9cac1b5dfd74f563793801ac90f..c67d16001272039e067b1f2165930a5484158cf8 100644 --- a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H +++ b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H @@ -31,8 +31,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef codedPatchFunction1Template${FieldType}_H -#define codedPatchFunction1Template${FieldType}_H +#ifndef dynamicCode_codedPatchFunction1_${typeName}_${FieldType}_H +#define dynamicCode_codedPatchFunction1_${typeName}_${FieldType}_H #include "PatchFunction1.H" #include "dictionaryContent.H" @@ -126,14 +126,11 @@ public: // Member Functions + //- Is value uniform (i.e. independent of coordinate) + virtual bool uniform() const { return false; } + //- Return value as a function of (scalar) independent variable virtual tmp<Field<${TemplateType}>> value(const scalar x) const; - - //- Is value uniform (i.e. independent of coordinate) - virtual bool uniform() const - { - return false; - } }; diff --git a/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.C b/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.C index d38ef18c97e0dd18e288cbbf2701f78bd7b2d244..4ce7a79d083deb1aaf9361b313462d85b26c1b37 100644 --- a/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.C +++ b/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.C @@ -75,10 +75,14 @@ extern "C" void ${typeName}_${SHA1sum}(bool load) ${localCode} //}}} end localCode +} // End namespace Foam + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -${typeName}Points0MotionSolver::${typeName}Points0MotionSolver +Foam:: +${typeName}Points0MotionSolver:: +${typeName}Points0MotionSolver ( const polyMesh& mesh, const IOdictionary& dict @@ -90,13 +94,16 @@ ${typeName}Points0MotionSolver::${typeName}Points0MotionSolver // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // -${typeName}Points0MotionSolver::~${typeName}Points0MotionSolver() +Foam:: +${typeName}Points0MotionSolver:: +~${typeName}Points0MotionSolver() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -tmp<pointField> ${typeName}Points0MotionSolver::curPoints() const +Foam::tmp<Foam::pointField> +Foam::${typeName}Points0MotionSolver::curPoints() const { if (${verbose:-false}) { @@ -109,8 +116,4 @@ tmp<pointField> ${typeName}Points0MotionSolver::curPoints() const } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.H b/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.H index 8a2a70fcf8d4786ea3cd511d7062232654cd393b..e420c2af67592a9977f21452147d49c051131804 100644 --- a/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.H +++ b/etc/codeTemplates/dynamicCode/codedPoints0MotionSolverTemplate.H @@ -103,7 +103,7 @@ public: // Member Functions //- Code context as a dictionary - const dictionary& codeContext() const + const dictionary& codeContext() const noexcept { return dictionaryContent::dict(); } diff --git a/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.C b/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.C index a9db42f5fdeaea490582d29d20e006628a170473..3252c4cc76a6e0d2fc083dc2c21f3c3f447c0170 100644 --- a/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.C +++ b/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.C @@ -78,9 +78,12 @@ makeRemovablePatchTypeField ${typeName}FixedValueFvPatch${FieldType} ); +} // End namespace Foam + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam:: ${typeName}FixedValueFvPatch${FieldType}:: ${typeName}FixedValueFvPatch${FieldType} ( @@ -97,6 +100,7 @@ ${typeName}FixedValueFvPatch${FieldType} } +Foam:: ${typeName}FixedValueFvPatch${FieldType}:: ${typeName}FixedValueFvPatch${FieldType} ( @@ -115,6 +119,7 @@ ${typeName}FixedValueFvPatch${FieldType} } +Foam:: ${typeName}FixedValueFvPatch${FieldType}:: ${typeName}FixedValueFvPatch${FieldType} ( @@ -132,6 +137,7 @@ ${typeName}FixedValueFvPatch${FieldType} } +Foam:: ${typeName}FixedValueFvPatch${FieldType}:: ${typeName}FixedValueFvPatch${FieldType} ( @@ -147,6 +153,7 @@ ${typeName}FixedValueFvPatch${FieldType} } +Foam:: ${typeName}FixedValueFvPatch${FieldType}:: ${typeName}FixedValueFvPatch${FieldType} ( @@ -165,6 +172,7 @@ ${typeName}FixedValueFvPatch${FieldType} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // +Foam:: ${typeName}FixedValueFvPatch${FieldType}:: ~${typeName}FixedValueFvPatch${FieldType}() { @@ -178,6 +186,7 @@ ${typeName}FixedValueFvPatch${FieldType}:: // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void +Foam:: ${typeName}FixedValueFvPatch${FieldType}::updateCoeffs() { if (this->updated()) @@ -198,8 +207,4 @@ ${typeName}FixedValueFvPatch${FieldType}::updateCoeffs() } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.H b/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.H index 5c345838d9ebbd73d90311db9f93e5aba75e587b..1baf7be91e73294948c3241c02d044886ef48d3d 100644 --- a/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.H +++ b/etc/codeTemplates/dynamicCode/fixedValueFvPatchFieldTemplate.H @@ -143,7 +143,7 @@ public: // Member Functions //- Code context as a dictionary - const dictionary& codeContext() const + const dictionary& codeContext() const noexcept { return dictionaryContent::dict(); } diff --git a/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.C b/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.C index c91a478c6210fcf78c5baad2d751e5508e4b8fe7..93bdec669edf51c0d556ffa84e54aab59d8fa8dc 100644 --- a/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.C +++ b/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.C @@ -77,9 +77,12 @@ makePointPatchTypeField ${typeName}FixedValuePointPatch${FieldType} ); +} // End namespace Foam + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam:: ${typeName}FixedValuePointPatch${FieldType}:: ${typeName}FixedValuePointPatch${FieldType} ( @@ -96,6 +99,7 @@ ${typeName}FixedValuePointPatch${FieldType} } +Foam:: ${typeName}FixedValuePointPatch${FieldType}:: ${typeName}FixedValuePointPatch${FieldType} ( @@ -114,6 +118,7 @@ ${typeName}FixedValuePointPatch${FieldType} } +Foam:: ${typeName}FixedValuePointPatch${FieldType}:: ${typeName}FixedValuePointPatch${FieldType} ( @@ -132,6 +137,7 @@ ${typeName}FixedValuePointPatch${FieldType} } +Foam:: ${typeName}FixedValuePointPatch${FieldType}:: ${typeName}FixedValuePointPatch${FieldType} ( @@ -147,6 +153,7 @@ ${typeName}FixedValuePointPatch${FieldType} } +Foam:: ${typeName}FixedValuePointPatch${FieldType}:: ${typeName}FixedValuePointPatch${FieldType} ( @@ -165,6 +172,7 @@ ${typeName}FixedValuePointPatch${FieldType} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // +Foam:: ${typeName}FixedValuePointPatch${FieldType}:: ~${typeName}FixedValuePointPatch${FieldType}() { @@ -178,6 +186,7 @@ ${typeName}FixedValuePointPatch${FieldType}:: // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void +Foam:: ${typeName}FixedValuePointPatch${FieldType}::updateCoeffs() { if (this->updated()) @@ -198,8 +207,4 @@ ${typeName}FixedValuePointPatch${FieldType}::updateCoeffs() } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.H b/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.H index 9fd6198afbf9d9f75e0e82747a782575a1447fde..85a9cf08fc3086791628421ffc5709814b24f93f 100644 --- a/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.H +++ b/etc/codeTemplates/dynamicCode/fixedValuePointPatchFieldTemplate.H @@ -144,7 +144,7 @@ public: // Member Functions //- Code context as a dictionary - const dictionary& codeContext() const + const dictionary& codeContext() const noexcept { return dictionaryContent::dict(); } diff --git a/etc/codeTemplates/dynamicCode/functionObjectTemplate.C b/etc/codeTemplates/dynamicCode/functionObjectTemplate.C index 274fd29f7c22042723e60a7a148e86e70526087e..f6b014bd1e0efbea44c0427e930ff83aecbb258e 100644 --- a/etc/codeTemplates/dynamicCode/functionObjectTemplate.C +++ b/etc/codeTemplates/dynamicCode/functionObjectTemplate.C @@ -75,10 +75,13 @@ extern "C" void ${typeName}_${SHA1sum}(bool load) ${localCode} //}}} end localCode +} // End namespace Foam + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -const fvMesh& ${typeName}FunctionObject::mesh() const +const Foam::fvMesh& +Foam::${typeName}FunctionObject::mesh() const { return refCast<const fvMesh>(obr_); } @@ -86,7 +89,9 @@ const fvMesh& ${typeName}FunctionObject::mesh() const // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -${typeName}FunctionObject::${typeName}FunctionObject +Foam:: +${typeName}FunctionObject:: +${typeName}FunctionObject ( const word& name, const Time& runTime, @@ -101,13 +106,16 @@ ${typeName}FunctionObject::${typeName}FunctionObject // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // -${typeName}FunctionObject::~${typeName}FunctionObject() +Foam:: +${typeName}FunctionObject:: +~${typeName}FunctionObject() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool +Foam:: ${typeName}FunctionObject::read(const dictionary& dict) { if (${verbose:-false}) @@ -124,6 +132,7 @@ ${typeName}FunctionObject::read(const dictionary& dict) bool +Foam:: ${typeName}FunctionObject::execute() { if (${verbose:-false}) @@ -140,6 +149,7 @@ ${typeName}FunctionObject::execute() bool +Foam:: ${typeName}FunctionObject::write() { if (${verbose:-false}) @@ -156,6 +166,7 @@ ${typeName}FunctionObject::write() bool +Foam:: ${typeName}FunctionObject::end() { if (${verbose:-false}) @@ -171,8 +182,4 @@ ${typeName}FunctionObject::end() } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/functionObjectTemplate.H b/etc/codeTemplates/dynamicCode/functionObjectTemplate.H index 8cb7aaaca4d25620a9aa20e11d7c65434027ad97..2742cf9e787510a6eef5e89ac807fc1a23f5c9ac 100644 --- a/etc/codeTemplates/dynamicCode/functionObjectTemplate.H +++ b/etc/codeTemplates/dynamicCode/functionObjectTemplate.H @@ -32,8 +32,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef functionObjectTemplate_H -#define functionObjectTemplate_H +#ifndef coded_functionObjectTemplate_H +#define coded_functionObjectTemplate_H #include "regionFunctionObject.H" #include "dictionaryContent.H" @@ -116,7 +116,7 @@ public: // Member Functions //- Code context as a dictionary - const dictionary& codeContext() const + const dictionary& codeContext() const noexcept { return dictionaryContent::dict(); } diff --git a/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.C b/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.C index 8602b151bec78cafecf7a64be848e35c87465eb4..6a42a890a9f9c320783a9a07f5462beecd6f12ae 100644 --- a/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.C +++ b/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.C @@ -77,9 +77,12 @@ makeRemovablePatchTypeField ${typeName}MixedValueFvPatch${FieldType} ); +} // End namespace Foam + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam:: ${typeName}MixedValueFvPatch${FieldType}:: ${typeName}MixedValueFvPatch${FieldType} ( @@ -96,6 +99,7 @@ ${typeName}MixedValueFvPatch${FieldType} } +Foam:: ${typeName}MixedValueFvPatch${FieldType}:: ${typeName}MixedValueFvPatch${FieldType} ( @@ -114,6 +118,7 @@ ${typeName}MixedValueFvPatch${FieldType} } +Foam:: ${typeName}MixedValueFvPatch${FieldType}:: ${typeName}MixedValueFvPatch${FieldType} ( @@ -131,6 +136,7 @@ ${typeName}MixedValueFvPatch${FieldType} } +Foam:: ${typeName}MixedValueFvPatch${FieldType}:: ${typeName}MixedValueFvPatch${FieldType} ( @@ -146,6 +152,7 @@ ${typeName}MixedValueFvPatch${FieldType} } +Foam:: ${typeName}MixedValueFvPatch${FieldType}:: ${typeName}MixedValueFvPatch${FieldType} ( @@ -164,6 +171,7 @@ ${typeName}MixedValueFvPatch${FieldType} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // +Foam:: ${typeName}MixedValueFvPatch${FieldType}:: ~${typeName}MixedValueFvPatch${FieldType}() { @@ -177,6 +185,7 @@ ${typeName}MixedValueFvPatch${FieldType}:: // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void +Foam:: ${typeName}MixedValueFvPatch${FieldType}::updateCoeffs() { if (this->updated()) @@ -197,8 +206,4 @@ ${typeName}MixedValueFvPatch${FieldType}::updateCoeffs() } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.H b/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.H index 83ef277870caa6c8e47ee592b4e9df8c483262c1..74195dc8df5b3dc1a5f56245bba701446d98c8d6 100644 --- a/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.H +++ b/etc/codeTemplates/dynamicCode/mixedFvPatchFieldTemplate.H @@ -143,7 +143,7 @@ public: // Member Functions //- Code context as a dictionary - const dictionary& codeContext() const + const dictionary& codeContext() const noexcept { return dictionaryContent::dict(); } diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C index ae21366c0f6f7709f2633e1005b376576b577aa3..25a067f2f4a87fe3773442667d1866718abd7a29 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C @@ -150,7 +150,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField : parent_bctype(rhs, p, iF, mapper), codedBase(), - dict_(rhs.dict_), + dict_(rhs.dict_), // Deep copy name_(rhs.name_), redirectPatchFieldPtr_(nullptr) {} @@ -169,12 +169,12 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField codedBase(), dict_ ( - // Copy dictionary, but without "heavy" data chunks + // Copy dictionary without "heavy" data chunks dictionaryContent::copyDict ( dict, - wordRes(), // allow - wordRes // deny + wordList(), // allow + wordList // deny ({ "type", // redundant "value" @@ -196,7 +196,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField : parent_bctype(rhs), codedBase(), - dict_(rhs.dict_), + dict_(rhs.dict_), // Deep copy name_(rhs.name_), redirectPatchFieldPtr_(nullptr) {} @@ -211,7 +211,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField : parent_bctype(rhs, iF), codedBase(), - dict_(rhs.dict_), + dict_(rhs.dict_), // Deep copy name_(rhs.name_), redirectPatchFieldPtr_(nullptr) {} diff --git a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C new file mode 100644 index 0000000000000000000000000000000000000000..bd7aa98dce2d739b0c862f484ca5d4c61ca4f5dc --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C @@ -0,0 +1,247 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "dynamicCode.H" +#include "dynamicCodeContext.H" +#include "dictionaryContent.H" + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template<class Type> +Foam::dlLibraryTable& +Foam::Function1Types::CodedFunction1<Type>::libs() const +{ + return this->time().libs(); +} + + +template<class Type> +Foam::string +Foam::Function1Types::CodedFunction1<Type>::description() const +{ + return "CodedFunction1 " + redirectName_; +} + + +template<class Type> +void Foam::Function1Types::CodedFunction1<Type>::clearRedirect() const +{ + redirectFunctionPtr_.reset(nullptr); +} + + +template<class Type> +const Foam::dictionary& +Foam::Function1Types::CodedFunction1<Type>::codeContext() const +{ + // What else would make sense? + return dict_; +} + + +template<class Type> +const Foam::dictionary& +Foam::Function1Types::CodedFunction1<Type>::codeDict +( + const dictionary& dict +) const +{ + // Use named subdictionary if present to provide the code. + // This allows running with multiple Function1s + + return + ( + dict.found("code") + ? dict + : dict.subDict(redirectName_) + ); +} + + +template<class Type> +const Foam::dictionary& +Foam::Function1Types::CodedFunction1<Type>::codeDict() const +{ + return codeDict(dict_); +} + + +template<class Type> +void Foam::Function1Types::CodedFunction1<Type>::prepare +( + dynamicCode& dynCode, + const dynamicCodeContext& context +) const +{ + if (context.code().empty()) + { + FatalIOErrorInFunction(dict_) + << "No code section in input dictionary for Function1 " + << " name " << redirectName_ + << exit(FatalIOError); + } + + // Take no chances - typeName must be identical to redirectName_ + dynCode.setFilterVariable("typeName", redirectName_); + + // Set TemplateType and FieldType filter variables + dynCode.setFieldTemplates<Type>(); + + // Compile filtered C template + dynCode.addCompileFile(codeTemplateC); + + // Copy filtered H template + dynCode.addCopyFile(codeTemplateH); + + #ifdef FULLDEBUG + dynCode.setFilterVariable("verbose", "true"); + DetailInfo + <<"compile " << redirectName_ << " sha1: " << context.sha1() << endl; + #endif + + // Define Make/options + dynCode.setMakeOptions + ( + "EXE_INC = -g \\\n" + "-I$(LIB_SRC)/meshTools/lnInclude \\\n" + + context.options() + + "\n\nLIB_LIBS = \\\n" + " -lOpenFOAM \\\n" + " -lmeshTools \\\n" + + context.libs() + ); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Type> +Foam::Function1Types::CodedFunction1<Type>::CodedFunction1 +( + const word& entryName, + const dictionary& dict, + const objectRegistry* obrPtr +) +: + Function1<Type>(entryName, dict, obrPtr), + codedBase(), + dict_(dict), + redirectName_(dict.getOrDefault<word>("name", entryName)) +{ + this->codedBase::setCodeContext(dict_); + + // No additional code chunks... + + updateLibrary(redirectName_); +} + + +template<class Type> +Foam::Function1Types::CodedFunction1<Type>::CodedFunction1 +( + const CodedFunction1<Type>& rhs +) +: + Function1<Type>(rhs), + codedBase(), + dict_(rhs.dict_), + redirectName_(rhs.redirectName_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Type> +const Foam::Function1<Type>& +Foam::Function1Types::CodedFunction1<Type>::redirectFunction() const +{ + if (!redirectFunctionPtr_) + { + dictionary constructDict; + // Force 'redirectName_' sub-dictionary into existence + dictionary& coeffs = constructDict.subDictOrAdd(redirectName_); + + coeffs = dict_; // Copy input code and coefficients + coeffs.remove("name"); // Redundant + coeffs.set("type", redirectName_); // Specify our new (redirect) type + + redirectFunctionPtr_.reset + ( + Function1<Type>::New + ( + redirectName_, + constructDict, + this->whichDb() + ) + ); + + // Forward copy of codeContext to the code template + auto* contentPtr = + dynamic_cast<dictionaryContent*>(redirectFunctionPtr_.get()); + + if (contentPtr) + { + contentPtr->dict(this->codeContext()); + } + else + { + WarningInFunction + << redirectName_ << " Did not derive from dictionaryContent" + << nl << nl; + } + } + return *redirectFunctionPtr_; +} + + +template<class Type> +Type Foam::Function1Types::CodedFunction1<Type>::value +( + const scalar x +) const +{ + // Ensure library containing user-defined code is up-to-date + updateLibrary(redirectName_); + + return redirectFunction().value(x); +} + + +template<class Type> +void Foam::Function1Types::CodedFunction1<Type>::writeData +( + Ostream& os +) const +{ + // Should really only output only relevant entries but since using + // Function1-from-subdict upon construction our dictionary contains + // only the relevant entries. + dict_.writeEntry(this->name(), os); +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H new file mode 100644 index 0000000000000000000000000000000000000000..ed8dbfe01e410c92c25e099d06f908058a4a7283 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H @@ -0,0 +1,225 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::Function1Types::CodedFunction1 + +Description + Function1 with the code supplied by an on-the-fly compiled C++ + expression. + + The code entries: + \plaintable + codeInclude | include files + codeOptions | compiler line: added to EXE_INC (Make/options) + codeLibs | linker line: added to LIB_LIBS (Make/options) + localCode | c++; local static functions + code | c++; return the patch values at (scalar x) + \endplaintable + +Usage + Example: + \verbatim + <patchName> + { + type uniformFixedValue; + uniformValue + { + type coded; + name myExpression; // Name of generated PatchFunction1 + + code + #{ + const polyPatch& pp = this->patch(); + Pout<< "** Patch size:" << pp.size() << endl; + return tmp<vectorField>::New(pp.size(), vector(1, 0, 0)) + #}; + + //codeInclude + //#{ + // #include "volFields.H" + //#}; + + //codeOptions + //#{ + // -I$(LIB_SRC)/finiteVolume/lnInclude + //#}; + } + } + \endverbatim + +Note + The code context dictionary is simply the dictionary used to specify + the PatchFunction1 coefficients. + +See also + Foam::dynamicCode + Foam::codedFixedValue + Foam::functionEntries::codeStream + +SourceFiles + CodedFunction1.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Function1Types_CodedFunction1_H +#define Function1Types_CodedFunction1_H + +#include "Function1.H" +#include "codedBase.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace Function1Types +{ + +/*---------------------------------------------------------------------------*\ + Class CodedFunction1 Declaration +\*---------------------------------------------------------------------------*/ + +template<class Type> +class CodedFunction1 +: + public Function1<Type>, + protected codedBase +{ + // Private Data + + //- Dictionary contents for the function + const dictionary dict_; + + const word redirectName_; + + mutable autoPtr<Function1<Type>> redirectFunctionPtr_; + + + // Private Member Functions + + //- Get reference to the underlying Function1 + const Function1<Type>& redirectFunction() const; + + +protected: + + // Protected Member Functions + + //- 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; + + //- Additional 'codeContext' dictionary to pass through + virtual const dictionary& codeContext() 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; + + + // Generated Methods + + //- No copy assignment + void operator=(const CodedFunction1<Type>&) = delete; + +public: + + // Static Data Members + + //- Name of the C code template to be used + static constexpr const char* const codeTemplateC + = "codedFunction1Template.C"; + + //- Name of the H code template to be used + static constexpr const char* const codeTemplateH + = "codedFunction1Template.H"; + + + //- Runtime type information + TypeName("coded"); + + + // Constructors + + //- Construct from entry name, dictionary and optional registry + CodedFunction1 + ( + const word& entryName, + const dictionary& dict, + const objectRegistry* obrPtr = nullptr + ); + + //- Copy construct + explicit CodedFunction1(const CodedFunction1<Type>& rhs); + + //- Construct and return a clone + virtual tmp<Function1<Type>> clone() const + { + return tmp<Function1<Type>>(new CodedFunction1<Type>(*this)); + } + + + //- Destructor + virtual ~CodedFunction1() = default; + + + // Member Functions + + //- Return value at current time + virtual inline Type value(const scalar x) const; + + // Integrate etc are not implemented! + + //- Write in dictionary format + virtual void writeData(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Function1Types +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "CodedFunction1.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/FunctionObjectTrigger/FunctionObjectTrigger.C b/src/OpenFOAM/primitives/functions/Function1/FunctionObjectTrigger/FunctionObjectTrigger.C index cc94b94eb58561d7f747ac3a7514bbe79ab0cc36..710e91b3ae7617d57214d85d23c6f534baa70c83 100644 --- a/src/OpenFOAM/primitives/functions/Function1/FunctionObjectTrigger/FunctionObjectTrigger.C +++ b/src/OpenFOAM/primitives/functions/Function1/FunctionObjectTrigger/FunctionObjectTrigger.C @@ -78,7 +78,7 @@ void Foam::Function1Types::FunctionObjectTrigger<Type>::writeEntries ) const { os.writeKeyword("triggers"); - flatOutput(triggers_); + os << flatOutput(triggers_); os.endEntry(); if (defaultValue_) diff --git a/src/OpenFOAM/primitives/functions/Function1/makeFunction1s.C b/src/OpenFOAM/primitives/functions/Function1/makeFunction1s.C index 06f07ca8fd8b88e9def6d08a73618305ba48c4a3..f77245ea0fd6d816b2a1c5347d7ebe32497eb5d0 100644 --- a/src/OpenFOAM/primitives/functions/Function1/makeFunction1s.C +++ b/src/OpenFOAM/primitives/functions/Function1/makeFunction1s.C @@ -26,6 +26,7 @@ License \*---------------------------------------------------------------------------*/ +#include "CodedFunction1.H" #include "Constant.H" #include "Uniform.H" #include "ZeroConstant.H" @@ -48,6 +49,7 @@ License #define makeFunction1s(Type) \ makeFunction1(Type); \ + makeFunction1Type(CodedFunction1, Type); \ makeFunction1Type(Constant, Type); \ makeFunction1Type(Uniform, Type); \ makeFunction1Type(None, Type); \ diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C index 73f1e3600412094a60a02c46a869e467f07184af..c85d0dc2638b1bebfee1af2564e26732e86c56d8 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C @@ -150,7 +150,7 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField : parent_bctype(rhs, p, iF, mapper), codedBase(), - dict_(rhs.dict_), + dict_(rhs.dict_), // Deep copy name_(rhs.name_), redirectPatchFieldPtr_(nullptr) {} @@ -168,12 +168,12 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField codedBase(), dict_ ( - // Copy dictionary, but without "heavy" data chunks + // Copy dictionary without "heavy" data chunks dictionaryContent::copyDict ( dict, - wordRes(), // allow - wordRes // deny + wordList(), // allow + wordList // deny ({ "type", // redundant "value" @@ -195,7 +195,7 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField : parent_bctype(rhs), codedBase(), - dict_(rhs.dict_), + dict_(rhs.dict_), // Deep copy name_(rhs.name_), redirectPatchFieldPtr_(nullptr) {} @@ -210,7 +210,7 @@ Foam::codedFixedValueFvPatchField<Type>::codedFixedValueFvPatchField : parent_bctype(rhs, iF), codedBase(), - dict_(rhs.dict_), + dict_(rhs.dict_), // Deep copy name_(rhs.name_), redirectPatchFieldPtr_(nullptr) {} diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C index e294c6474d5f614f55e8fd96435df057a53e02e0..c63ebc4abc2a8ee8085a09d5e75b15acfb84748a 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C @@ -150,7 +150,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField : parent_bctype(rhs, p, iF, mapper), codedBase(), - dict_(rhs.dict_), + dict_(rhs.dict_), // Deep copy name_(rhs.name_), redirectPatchFieldPtr_(nullptr) {} @@ -172,8 +172,8 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField dictionaryContent::copyDict ( dict, - wordRes(), // allow - wordRes // deny + wordList(), // allow + wordList // deny ({ "type", // redundant "value", "refValue", "refGradient", "valueFraction" @@ -195,7 +195,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField : parent_bctype(rhs), codedBase(), - dict_(rhs.dict_), + dict_(rhs.dict_), // Deep copy name_(rhs.name_), redirectPatchFieldPtr_(nullptr) {} @@ -210,7 +210,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField : parent_bctype(rhs, iF), codedBase(), - dict_(rhs.dict_), + dict_(rhs.dict_), // Deep copy name_(rhs.name_), redirectPatchFieldPtr_(nullptr) {} diff --git a/src/meshTools/PatchFunction1/CodedField/CodedField.C b/src/meshTools/PatchFunction1/CodedField/CodedField.C index 60ca1ecca878d2ecbd20e205bcb6dd3f9a801c6b..8cea612466b573cfed98b885440837347645bb3e 100644 --- a/src/meshTools/PatchFunction1/CodedField/CodedField.C +++ b/src/meshTools/PatchFunction1/CodedField/CodedField.C @@ -43,7 +43,7 @@ template<class Type> Foam::string Foam::PatchFunction1Types::CodedField<Type>::description() const { - return "CodedField " + name_; + return "CodedField " + redirectName_; } @@ -77,7 +77,7 @@ Foam::PatchFunction1Types::CodedField<Type>::codeDict ( dict.found("code") ? dict - : dict.subDict(name_) + : dict.subDict(redirectName_) ); } @@ -102,12 +102,12 @@ void Foam::PatchFunction1Types::CodedField<Type>::prepare FatalIOErrorInFunction(dict_) << "No code section in input dictionary for patch " << this->patch_.name() - << " name " << name_ + << " name " << redirectName_ << exit(FatalIOError); } - // Take no chances - typeName must be identical to name_ - dynCode.setFilterVariable("typeName", name_); + // Take no chances - typeName must be identical to redirectName_ + dynCode.setFilterVariable("typeName", redirectName_); // Set TemplateType and FieldType filter variables dynCode.setFieldTemplates<Type>(); @@ -121,7 +121,7 @@ void Foam::PatchFunction1Types::CodedField<Type>::prepare #ifdef FULLDEBUG dynCode.setFilterVariable("verbose", "true"); DetailInfo - <<"compile " << name_ << " sha1: " << context.sha1() << endl; + <<"compile " << redirectName_ << " sha1: " << context.sha1() << endl; #endif // Define Make/options @@ -155,13 +155,13 @@ Foam::PatchFunction1Types::CodedField<Type>::CodedField PatchFunction1<Type>(pp, entryName, dict, faceValues), codedBase(), dict_(dict), - name_(dict.getOrDefault<word>("name", entryName)) + redirectName_(dict.getOrDefault<word>("name", entryName)) { this->codedBase::setCodeContext(dict_); // No additional code chunks... - updateLibrary(name_); + updateLibrary(redirectName_); } @@ -185,7 +185,7 @@ Foam::PatchFunction1Types::CodedField<Type>::CodedField PatchFunction1<Type>(rhs, pp), codedBase(), dict_(rhs.dict_), - name_(rhs.name_) + redirectName_(rhs.redirectName_) {} @@ -198,19 +198,19 @@ Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const if (!redirectFunctionPtr_) { dictionary constructDict; - // Force 'name_' sub-dictionary into existence - dictionary& coeffs = constructDict.subDictOrAdd(name_); + // Force 'redirectName_' sub-dictionary into existence + dictionary& coeffs = constructDict.subDictOrAdd(redirectName_); coeffs = dict_; // Copy input code and coefficients coeffs.remove("name"); // Redundant - coeffs.set("type", name_); // Specify our new (redirect) type + coeffs.set("type", redirectName_); // Specify our new (redirect) type redirectFunctionPtr_.reset ( PatchFunction1<Type>::New ( this->patch(), - name_, + redirectName_, constructDict, this->faceValues() ) @@ -227,7 +227,7 @@ Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const else { WarningInFunction - << name_ << " Did not derive from dictionaryContent" + << redirectName_ << " Did not derive from dictionaryContent" << nl << nl; } } @@ -243,7 +243,7 @@ Foam::PatchFunction1Types::CodedField<Type>::value ) const { // Ensure library containing user-defined code is up-to-date - updateLibrary(name_); + updateLibrary(redirectName_); return redirectFunction().value(x); } @@ -258,7 +258,7 @@ Foam::PatchFunction1Types::CodedField<Type>::integrate ) const { // Ensure library containing user-defined code is up-to-date - updateLibrary(name_); + updateLibrary(redirectName_); return redirectFunction().integrate(x1, x2); } diff --git a/src/meshTools/PatchFunction1/CodedField/CodedField.H b/src/meshTools/PatchFunction1/CodedField/CodedField.H index a4dd238c8d6e30ac4d7d0357eec47e1f43f68d24..54cf23076e1f941b0503dd18a8731f5f197fdca2 100644 --- a/src/meshTools/PatchFunction1/CodedField/CodedField.H +++ b/src/meshTools/PatchFunction1/CodedField/CodedField.H @@ -112,7 +112,7 @@ class CodedField //- Dictionary contents for the function const dictionary dict_; - const word name_; + const word redirectName_; mutable autoPtr<PatchFunction1<Type>> redirectFunctionPtr_; @@ -216,23 +216,15 @@ public: // Member Functions + //- Is value uniform (i.e. independent of coordinate) + virtual inline bool uniform() const { return false; } + + // Evaluation //- Return CodedField value virtual tmp<Field<Type>> value(const scalar x) const; - //- Is value constant (i.e. independent of x) - virtual inline bool constant() const - { - return false; - } - - //- Is value uniform (i.e. independent of coordinate) - virtual inline bool uniform() const - { - return false; - } - //- Integrate between two values virtual tmp<Field<Type>> integrate ( diff --git a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H index 1f844cfaa420056f06daad0d6d317cc320a545d1..56a7994c46d44ad9263ca441a59206baed612677 100644 --- a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H +++ b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H @@ -215,17 +215,18 @@ public: // Member Functions + //- Is value constant (i.e. independent of x) + virtual bool constant() const { return false; } + + //- Is value uniform (i.e. independent of coordinate) + virtual bool uniform() const = 0; + + // Evaluation //- Return value as a function of (scalar) independent variable virtual tmp<Field<Type>> value(const scalar x) const; - //- Is value constant (i.e. independent of x) - virtual bool constant() const = 0; - - //- Is value uniform (i.e. independent of coordinate) - virtual bool uniform() const = 0; - //- Integrate between two (scalar) values virtual tmp<Field<Type>> integrate ( diff --git a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/T b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/T index 59a334114a0013e04de458a0f6685a76f1251a19..a2ccf90752c071ded15bfc65a9105e3221ec71e0 100644 --- a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/T +++ b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/T @@ -40,6 +40,16 @@ boundaryField // For general testing purposes: type exprFixedValue; + functions<scalar> + { + trigger + { + type functionObjectTrigger; + triggers (2 4); + defaultValue true; + } + } + variables ( "Tcrit = 500" diff --git a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/U b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/U index 7192f3f9cb18f55c41642cfeb1917bdc78b92f31..5136d6af51889c5910761e59cd83432154fc2b3e 100644 --- a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/U +++ b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/0.orig/U @@ -23,8 +23,26 @@ boundaryField inlet { type flowRateInletVelocity; - massFlowRate constant 5; rhoInlet 1000; // Guess for rho + + // massFlowRate constant 5; + + massFlowRate + { + type coded; + name liquidIn; + code + #{ + // Receives 'x' as the argument + static bool reported(false); + if (!reported) + { + Info<< "Using coded value for massFlowRate" << nl; + reported = true; + } + return 5; + #}; + } } outlet diff --git a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun index 088d3bc05812944922e5ae24e3bcb134ae6fcf5a..2a084391f1f0f6d5dbb238703ec5223873a64637 100755 --- a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun +++ b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun @@ -5,6 +5,12 @@ cd "${0%/*}" || exit # Run from this directory ./Allrun.pre +if ! canCompile +then + echo "-- No dynamicCode: replace coded Function1 with constant value" + foamDictionary -entry boundaryField/inlet/massFlowRate -set 'constant 5' 0/U +fi + runApplication decomposePar #- Run without processorAgglomerator diff --git a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun-seq b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun-seq index 78d5debbe7f687177b9c06cd6b65b939d99f8820..908248a711601e752fb861ac1f760bb037b59c0f 100755 --- a/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun-seq +++ b/tutorials/compressible/rhoSimpleFoam/squareBendLiq/Allrun-seq @@ -5,6 +5,12 @@ cd "${0%/*}" || exit # Run from this directory ./Allrun.pre +if ! canCompile +then + echo "-- No dynamicCode: replace coded Function1 with constant value" + foamDictionary -entry boundaryField/inlet/massFlowRate -set 'constant 5' 0/U +fi + runApplication $(getApplication) #------------------------------------------------------------------------------ diff --git a/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U b/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U index ebe13c6d5df23e8757d18b7d5c4636baa1a67ece..0fa62ef7a07680ed39a938a65c06b4103da8f801 100644 --- a/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U +++ b/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/0.orig/U @@ -70,7 +70,7 @@ boundaryField { baseVel = Function1<scalar>::New ( - "timeFunction", dict, &db() + "timeFunction", dict, this->whichDb() ); } @@ -81,7 +81,7 @@ boundaryField // ie, NewIfPresent baseDir = Function1<vector>::New ( - "directionFunction", dict, &db() + "directionFunction", dict, this->whichDb() ); InfoErr