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:
parent
8624d65c5a
commit
9a5125111e
121
etc/codeTemplates/dynamicCode/codedFunction1Template.C
Normal file
121
etc/codeTemplates/dynamicCode/codedFunction1Template.C
Normal 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
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
119
etc/codeTemplates/dynamicCode/codedFunction1Template.H
Normal file
119
etc/codeTemplates/dynamicCode/codedFunction1Template.H
Normal 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
|
||||
|
||||
// ************************************************************************* //
|
@ -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
|
||||
|
||||
// ************************************************************************* //
|
||||
|
@ -163,7 +163,7 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- Code context as a dictionary
|
||||
const dictionary& codeContext() const
|
||||
const dictionary& codeContext() const noexcept
|
||||
{
|
||||
return dictionaryContent::dict();
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
// ************************************************************************* //
|
||||
|
@ -103,7 +103,7 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- Code context as a dictionary
|
||||
const dictionary& codeContext() const
|
||||
const dictionary& codeContext() const noexcept
|
||||
{
|
||||
return dictionaryContent::dict();
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
// ************************************************************************* //
|
||||
|
@ -143,7 +143,7 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- Code context as a dictionary
|
||||
const dictionary& codeContext() const
|
||||
const dictionary& codeContext() const noexcept
|
||||
{
|
||||
return dictionaryContent::dict();
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
// ************************************************************************* //
|
||||
|
@ -144,7 +144,7 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- Code context as a dictionary
|
||||
const dictionary& codeContext() const
|
||||
const dictionary& codeContext() const noexcept
|
||||
{
|
||||
return dictionaryContent::dict();
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
// ************************************************************************* //
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
// ************************************************************************* //
|
||||
|
@ -143,7 +143,7 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- Code context as a dictionary
|
||||
const dictionary& codeContext() const
|
||||
const dictionary& codeContext() const noexcept
|
||||
{
|
||||
return dictionaryContent::dict();
|
||||
}
|
||||
|
@ -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)
|
||||
{}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
@ -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
|
||||
|
||||
// ************************************************************************* //
|
@ -78,7 +78,7 @@ void Foam::Function1Types::FunctionObjectTrigger<Type>::writeEntries
|
||||
) const
|
||||
{
|
||||
os.writeKeyword("triggers");
|
||||
flatOutput(triggers_);
|
||||
os << flatOutput(triggers_);
|
||||
os.endEntry();
|
||||
|
||||
if (defaultValue_)
|
||||
|
@ -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); \
|
||||
|
@ -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)
|
||||
{}
|
||||
|
@ -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)
|
||||
{}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
(
|
||||
|
@ -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
|
||||
(
|
||||
|
@ -40,6 +40,16 @@ boundaryField
|
||||
// For general testing purposes:
|
||||
type exprFixedValue;
|
||||
|
||||
functions<scalar>
|
||||
{
|
||||
trigger
|
||||
{
|
||||
type functionObjectTrigger;
|
||||
triggers (2 4);
|
||||
defaultValue true;
|
||||
}
|
||||
}
|
||||
|
||||
variables
|
||||
(
|
||||
"Tcrit = 500"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user