ENH: add coded Function1 (#2282)

- update coded templates with qualified names

GIT: add in missing PatchFunction1 constant() method

- was missed in a previous commit
This commit is contained in:
Mark Olesen
2021-12-03 15:33:07 +01:00
parent 8624d65c5a
commit 9a5125111e
31 changed files with 883 additions and 112 deletions

View File

@ -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
}
// ************************************************************************* //

View File

@ -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
// ************************************************************************* //

View File

@ -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
// ************************************************************************* //

View File

@ -163,7 +163,7 @@ public:
// Member Functions
//- Code context as a dictionary
const dictionary& codeContext() const
const dictionary& codeContext() const noexcept
{
return dictionaryContent::dict();
}

View File

@ -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
// ************************************************************************* //

View File

@ -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;
}
};

View File

@ -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
// ************************************************************************* //

View File

@ -103,7 +103,7 @@ public:
// Member Functions
//- Code context as a dictionary
const dictionary& codeContext() const
const dictionary& codeContext() const noexcept
{
return dictionaryContent::dict();
}

View File

@ -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
// ************************************************************************* //

View File

@ -143,7 +143,7 @@ public:
// Member Functions
//- Code context as a dictionary
const dictionary& codeContext() const
const dictionary& codeContext() const noexcept
{
return dictionaryContent::dict();
}

View File

@ -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
// ************************************************************************* //

View File

@ -144,7 +144,7 @@ public:
// Member Functions
//- Code context as a dictionary
const dictionary& codeContext() const
const dictionary& codeContext() const noexcept
{
return dictionaryContent::dict();
}

View File

@ -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
// ************************************************************************* //

View File

@ -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();
}

View File

@ -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
// ************************************************************************* //

View File

@ -143,7 +143,7 @@ public:
// Member Functions
//- Code context as a dictionary
const dictionary& codeContext() const
const dictionary& codeContext() const noexcept
{
return dictionaryContent::dict();
}