diff --git a/etc/codeTemplates/dynamicCode/Function1Template.H b/etc/codeTemplates/dynamicCode/Function1Template.H index d7da5a2139..f7624d7429 100644 --- a/etc/codeTemplates/dynamicCode/Function1Template.H +++ b/etc/codeTemplates/dynamicCode/Function1Template.H @@ -93,7 +93,7 @@ public: // Member Functions - //- Return constant value + //- Return value as a function of scalar variable inline virtual ${TemplateType} value(const scalar x) const { //{{{ begin code diff --git a/etc/codeTemplates/dynamicCode/Function2Template.C b/etc/codeTemplates/dynamicCode/Function2Template.C new file mode 100644 index 0000000000..5214542e4e --- /dev/null +++ b/etc/codeTemplates/dynamicCode/Function2Template.C @@ -0,0 +1,127 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) YEAR OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +\*---------------------------------------------------------------------------*/ + +#include "Function2Template.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace Function2s +{ + defineTypeNameAndDebug(${typeName}Function2${TemplateType}, 0); +} + Function2<${TemplateType}>::adddictionaryConstructorToTable + ${typeName}Function2${TemplateType}ConstructorToTable_; +} + + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +extern "C" +{ + // dynamicCode: + // SHA1 = ${SHA1sum} + // + // Unique function name that can be checked if the correct library version + // has been loaded + void ${typeName}_${SHA1sum}(bool load) + { + if (load) + { + // code that can be explicitly executed after loading + } + else + { + // code that can be explicitly executed before unloading + } + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::Function2s::${typeName}Function2${TemplateType}:: +${typeName}Function2${TemplateType} +( + const word& entryName, + const dictionary& dict +) +: + FieldFunction2<${TemplateType}, ${typeName}Function2${TemplateType}> + ( + entryName + ) +{ + if (${verbose:-false}) + { + Info<< "Construct ${typeName} sha1: ${SHA1sum} from dictionary\n"; + } +} + + +Foam::Function2s::${typeName}Function2${TemplateType}:: +${typeName}Function2${TemplateType} +( + const ${typeName}Function2${TemplateType}& f1 +) +: + FieldFunction2<${TemplateType}, ${typeName}Function2${TemplateType}> + ( + f1 + ) +{ + if (${verbose:-false}) + { + Info<< "Construct ${typeName} sha1: ${SHA1sum} as copy\n"; + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::Function2s::${typeName}Function2${TemplateType}:: +~${typeName}Function2${TemplateType}() +{ + if (${verbose:-false}) + { + Info<< "Destroy ${typeName} sha1: ${SHA1sum}\n"; + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::Function2s::${typeName}Function2${TemplateType}::writeData +( + Ostream& os +) const +{ + NotImplemented; +} + + +// ************************************************************************* i/ diff --git a/etc/codeTemplates/dynamicCode/Function2Template.H b/etc/codeTemplates/dynamicCode/Function2Template.H new file mode 100644 index 0000000000..742c71a628 --- /dev/null +++ b/etc/codeTemplates/dynamicCode/Function2Template.H @@ -0,0 +1,128 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) YEAR OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +Description + Template for use with dynamic code generation of a Function2. + + - without state + +SourceFiles + Function2Template.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Function2Template_H +#define Function2Template_H + +#include "Function2.H" + +//{{{ begin codeInclude +${codeInclude} +//}}} end codeInclude + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace Function2s +{ + +/*---------------------------------------------------------------------------*\ + A templated Function2 +\*---------------------------------------------------------------------------*/ + +class ${typeName}Function2${TemplateType} +: + public FieldFunction2<${TemplateType}, ${typeName}Function2${TemplateType}> +{ + +public: + + // Runtime type information + TypeName("${typeName}"); + + + // Constructors + + //- Construct from entry name and dictionary + ${typeName}Function2${TemplateType} + ( + const word& entryName, + const dictionary& dict + ); + + //- Copy constructor + ${typeName}Function2${TemplateType} + ( + const ${typeName}Function2${TemplateType}& f1 + ); + + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp> + ( + new ${typeName}Function2${TemplateType}(*this) + ); + } + + + //- Destructor + virtual ~${typeName}Function2${TemplateType}(); + + + // Member Functions + + //- Return value as a function of two scalars + inline virtual ${TemplateType} value + ( + const scalar x, + const scalar y + ) const + { +//{{{ begin code + ${code} +//}}} end code + } + + //- Write in dictionary format + virtual void writeData(Ostream& os) const; + + + // Member Operators + + //- Disallow default bitwise assignment + void operator=(const ${typeName}Function2${TemplateType}&) = delete; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Function2s +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index cafea9e161..9c4167ba7e 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -99,6 +99,8 @@ primitives/functions/Function1/halfCosineRamp/halfCosineRamp.C primitives/functions/Function1/Table/tableBase.C primitives/functions/Function1/TableFile/TableReader/makeTableReaders.C +primitives/functions/Function2/makeFunction2s.C + primitives/subModelBase/subModelBase.C strings = primitives/strings diff --git a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H index 97791378b6..31344b0e53 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H +++ b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.H @@ -145,16 +145,16 @@ public: // Member Functions - //- Return value + //- Return value as a function of a scalar virtual inline Type value(const scalar x) const; - //- Return value as a function of (scalar) independent variable + //- Return value as a function of a scalar field virtual tmp> value(const scalarField& x) const; - //- Integrate between two values + //- Integrate between two scalars virtual Type integrate(const scalar x1, const scalar x2) const; - //- Integrate between two (scalar) values + //- Integrate between two scalar fields virtual tmp> integrate ( const scalarField& x1, diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H index 5ab283a1a3..4bd70a6421 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H +++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H @@ -25,10 +25,10 @@ Class Foam::Function1 Description - Top level data entry class for use in dictionaries. Provides a mechanism - to specify a variable as a certain type, e.g. constant or table, and - provide functions to return the (interpolated) value, and integral between - limits. + Run-time selectable general function of one variable + + with many options provided from simple constant values to complex + functions, interpolated tabulated data etc. etc. SourceFiles Function1.C @@ -118,32 +118,36 @@ public: // Member Functions - // Access + //- Return the name of the entry + const word& name() const; - //- Return the name of the entry - const word& name() const; + //- Return value as a function of scalar x + virtual Type value(const scalar x) const = 0; + + //- Return value as a function of a scalar field x + virtual tmp> value(const scalarField& x) const = 0; + + //- Integrate between two scalars + virtual Type integrate(const scalar x1, const scalar x2) const = 0; + + //- Integrate between two scalar fields + virtual tmp> integrate + ( + const scalarField& x1, + const scalarField& x2 + ) const = 0; + + //- Write in dictionary format + virtual void writeData(Ostream& os) const; - // Evaluation + // Member Operators - //- Return value as a function of (scalar) independent variable - virtual Type value(const scalar x) const = 0; - - //- Return value as a function of (scalar) independent variable - virtual tmp> value(const scalarField& x) const = 0; - - //- Integrate between two (scalar) values - virtual Type integrate(const scalar x1, const scalar x2) const = 0; - - //- Integrate between two (scalar) values - virtual tmp> integrate - ( - const scalarField& x1, - const scalarField& x2 - ) const = 0; + //- Disallow default bitwise assignment + void operator=(const Function1&) = delete; - // I/O + // IOstream Operators //- Ostream Operator friend Ostream& operator<< @@ -151,15 +155,6 @@ public: Ostream& os, const Function1& func ); - - //- Write in dictionary format - virtual void writeData(Ostream& os) const; - - - // Member Operators - - //- Disallow default bitwise assignment - void operator=(const Function1&) = delete; }; @@ -197,23 +192,21 @@ public: // Member Functions - // Evaluation + //- Return value as a function of one scalars + virtual Type value(const scalar x) const = 0; - //- Return value as a function of (scalar) independent variable - virtual Type value(const scalar x) const = 0; + //- Return value as a function of one scalar field + virtual tmp> value(const scalarField& x) const; - //- Return value as a function of (scalar) independent variable - virtual tmp> value(const scalarField& x) const; + //- Integrate between two scalar values + virtual Type integrate(const scalar x1, const scalar x2) const = 0; - //- Integrate between two (scalar) values - virtual Type integrate(const scalar x1, const scalar x2) const = 0; - - //- Integrate between two (scalar) values - virtual tmp> integrate - ( - const scalarField& x1, - const scalarField& x2 - ) const; + //- Integrate between two scalar fields + virtual tmp> integrate + ( + const scalarField& x1, + const scalarField& x2 + ) const; }; @@ -235,7 +228,7 @@ public: defineNamedTemplateTypeNameAndDebug(Function1s::SS, 0); \ \ Function1::adddictionaryConstructorToTable> \ - add##SS##Type##ConstructorToTable_; + addFunction1##SS##Type##ConstructorToTable_; #define makeScalarFunction1(SS) \ @@ -243,7 +236,7 @@ public: defineTypeNameAndDebug(SS, 0); \ \ Function1::adddictionaryConstructorToTable \ - add##SS##ConstructorToTable_; + addFunction1##SS##ConstructorToTable_; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H b/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H index 7d5cd42215..34ba210b16 100644 --- a/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H +++ b/src/OpenFOAM/primitives/functions/Function1/PolynomialEntry/PolynomialEntry.H @@ -103,10 +103,10 @@ public: // Evaluation - //- Return Polynomial value + //- Return Polynomial value as a function of scalar x virtual Type value(const scalar x) const; - //- Integrate between two (scalar) values + //- Integrate between two scalar fields virtual Type integrate(const scalar x1, const scalar x2) const; diff --git a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H index a356218bb1..5e0503e9d8 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H +++ b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H @@ -128,10 +128,10 @@ public: // Member Functions - //- Return Table value + //- Return Table value as a function of scalar x virtual Type value(const scalar x) const; - //- Integrate between two (scalar) values + //- Integrate between two scalars virtual Type integrate(const scalar x1, const scalar x2) const; //- Return the reference values diff --git a/src/OpenFOAM/primitives/functions/Function1/evaluate/Function1Evaluate.C b/src/OpenFOAM/primitives/functions/Function1/evaluate/Function1Evaluate.C index 8a0e65c0bf..331086f52c 100644 --- a/src/OpenFOAM/primitives/functions/Function1/evaluate/Function1Evaluate.C +++ b/src/OpenFOAM/primitives/functions/Function1/evaluate/Function1Evaluate.C @@ -32,20 +32,20 @@ void Foam::evaluate ( GeometricField& result, const Function1& func, - const GeometricField& f + const GeometricField& x ) { - result.primitiveFieldRef() = func.value(f()); + result.primitiveFieldRef() = func.value(x()); typename GeometricField::Boundary& bresult = result.boundaryFieldRef(); - const typename GeometricField::Boundary& bf = - f.boundaryField(); + const typename GeometricField::Boundary& bx = + x.boundaryField(); forAll(bresult, patchi) { - bresult[patchi] = func.value(bf[patchi]); + bresult[patchi] = func.value(bx[patchi]); } } @@ -55,20 +55,20 @@ Foam::tmp> Foam::evaluate ( const Function1& func, const dimensionSet& dims, - const GeometricField& f + const GeometricField& x ) { tmp> tresult ( GeometricField::New ( - func.name() + "(" + f.name() + ')', - f.mesh(), + func.name() + "(" + x.name() + ')', + x.mesh(), dims ) ); - evaluate(tresult.ref(), func, f); + evaluate(tresult.ref(), func, x); return tresult; } diff --git a/src/OpenFOAM/primitives/functions/Function1/evaluate/Function1Evaluate.H b/src/OpenFOAM/primitives/functions/Function1/evaluate/Function1Evaluate.H index f6fd27340d..d96faa22b9 100644 --- a/src/OpenFOAM/primitives/functions/Function1/evaluate/Function1Evaluate.H +++ b/src/OpenFOAM/primitives/functions/Function1/evaluate/Function1Evaluate.H @@ -49,7 +49,7 @@ void evaluate ( GeometricField& result, const Function1& func, - const GeometricField& f + const GeometricField& x ); template class PatchField, class GeoMesh> @@ -57,7 +57,7 @@ tmp> evaluate ( const Function1& func, const dimensionSet& dims, - const GeometricField& f + const GeometricField& x ); diff --git a/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1.H b/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1.H index e7007ccedf..97fe92a783 100644 --- a/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1.H +++ b/src/OpenFOAM/primitives/functions/Function1/objectFunction1/objectFunction1.H @@ -96,27 +96,25 @@ public: // Member Functions - // Evaluation + //- Return value as a function of scalar x + template + PrimitiveType value(const scalar x) const; - //- Return value as a function of (scalar) independent variable - template - PrimitiveType value(const scalar x) const; + //- Return value as a function of scalarField x + template + tmp> value(const scalarField& x) const; - //- Return value as a function of (scalar) independent variable - template - tmp> value(const scalarField& x) const; + //- Integrate between two scalars + template + PrimitiveType integrate(const scalar x1, const scalar x2) const; - //- Integrate between two (scalar) values - template - PrimitiveType integrate(const scalar x1, const scalar x2) const; - - //- Integrate between two (scalar) values - template - tmp> integrate - ( - const scalarField& x1, - const scalarField& x2 - ) const; + //- Integrate between two scalar fields + template + tmp> integrate + ( + const scalarField& x1, + const scalarField& x2 + ) const; // Member Operators diff --git a/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.C b/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.C new file mode 100644 index 0000000000..3ce4317a69 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.C @@ -0,0 +1,154 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +\*---------------------------------------------------------------------------*/ + +#include "CodedFunction2.H" +#include "dynamicCode.H" +#include "dynamicCodeContext.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +void Foam::Function2s::Coded::prepare +( + dynamicCode& dynCode, + const dynamicCodeContext& context +) const +{ + dynCode.setFilterVariable("typeName", codeName()); + + // Set TemplateType filter variables + dynCode.setFilterVariable("TemplateType", pTraits::typeName); + + // Compile filtered C template + dynCode.addCompileFile(codeTemplateC); + + // Copy filtered H template + dynCode.addCopyFile(codeTemplateH); + + // Debugging: make verbose + if (debug) + { + dynCode.setFilterVariable("verbose", "true"); + Info<<"compile " << codeName() << " sha1: " + << context.sha1() << endl; + } + + // Define Make/options + dynCode.setMakeOptions + ( + "EXE_INC = -g \\\n" + + context.options() + + "\n\nLIB_LIBS = \\\n" + + " -lOpenFOAM \\\n" + + context.libs() + ); +} + + +template +void Foam::Function2s::Coded::clearRedirect() const +{ + // Remove instantiation of Function2 provided by library + redirectFunction2Ptr_.clear(); +} + + +template +Foam::autoPtr> +Foam::Function2s::Coded::compileNew() +{ + this->updateLibrary(); + + dictionary redirectDict(codeDict()); + redirectDict.set(codeName(), codeName()); + + return Function2::New(codeName(), redirectDict); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::Function2s::Coded::Coded +( + const word& entryName, + const dictionary& dict +) +: + Function2(entryName), + CodedBase(dict) +{ + redirectFunction2Ptr_ = compileNew(); +} + + + +template +Foam::Function2s::Coded::Coded(const Coded& cf1) +: + Function2(cf1), + CodedBase(cf1) +{ + redirectFunction2Ptr_ = compileNew(); +} + + +template +Foam::tmp> Foam::Function2s::Coded::clone() const +{ + return tmp>(new Coded(*this)); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::Function2s::Coded::~Coded() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::tmp> Foam::Function2s::Coded::value +( + const scalarField& x, + const scalarField& y +) const +{ + return redirectFunction2Ptr_->value(x, y); +} + + +template +void Foam::Function2s::Coded::writeData(Ostream& os) const +{ + Function2::writeData(os); + os << token::END_STATEMENT << nl; + writeCode(os); +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.H b/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.H new file mode 100644 index 0000000000..0b2c524875 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2.H @@ -0,0 +1,159 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +Class + Foam::Function2s::Coded + +Description + Constructs a dynamically compiled function of two variables. + +See also + Foam::dynamicCode + Foam::functionEntries::codeStream + +SourceFiles + CodedFunction2I.H + CodedFunction2.C + +\*---------------------------------------------------------------------------*/ + +#ifndef CodedFunction2_H +#define CodedFunction2_H + +#include "Function2.H" +#include "CodedBase.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace Function2s +{ + +/*---------------------------------------------------------------------------*\ + Class coded Declaration +\*---------------------------------------------------------------------------*/ + +class coded +{ +public: + + ClassNameNoDebug("Function2"); +}; + + +/*---------------------------------------------------------------------------*\ + Class Coded Declaration +\*---------------------------------------------------------------------------*/ + +template +class Coded +: + public Function2, + public CodedBase +{ + // Private Data + + //- The dynamically generated Function2 pointer + mutable autoPtr> redirectFunction2Ptr_; + + + // Private Member Functions + + //- Adapt the context for the current object + virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; + + //- Clear the ptr to the redirected object + virtual void clearRedirect() const; + + //- Compile, link and return the now coded Function2 + autoPtr> compileNew(); + + +public: + + // Runtime type information + TypeName("coded"); + + + // Constructors + + //- Construct from entry name and dictionary + Coded + ( + const word& entryName, + const dictionary& dict + ); + + //- Copy constructor + Coded(const Coded& cf1); + + //- Construct and return a clone + virtual tmp> clone() const; + + + //- Destructor + virtual ~Coded(); + + + // Member Functions + + //- Return value as a function of two scalars + virtual inline Type value(const scalar x, const scalar y) const; + + //- Return value as a function of two scalar fields + virtual tmp> value + ( + const scalarField& x, + const scalarField& y + ) const; + + //- Write in dictionary format + virtual void writeData(Ostream& os) const; + + + // Member Operators + + //- Disallow default bitwise assignment + void operator=(const Coded&) = delete; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Function2s +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "CodedFunction2I.H" + +#ifdef NoRepository + #include "CodedFunction2.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2I.H b/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2I.H new file mode 100644 index 0000000000..c2183d3123 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function2/Coded/CodedFunction2I.H @@ -0,0 +1,44 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +\*---------------------------------------------------------------------------*/ + +#include "CodedFunction2.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +inline Type Foam::Function2s::Coded::value +( + const scalar x, + const scalar y +) const +{ + // Make sure library containing user-defined Function2 is up-to-date + this->updateLibrary(); + + return redirectFunction2Ptr_->value(x, y); +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.C b/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.C new file mode 100644 index 0000000000..88e37551ae --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.C @@ -0,0 +1,110 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +\*---------------------------------------------------------------------------*/ + +#include "Constant2.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::Function2s::Constant::Constant +( + const word& entryName, + const Type& val +) +: + FieldFunction2>(entryName), + value_(val) +{} + + +template +Foam::Function2s::Constant::Constant +( + const word& entryName, + const dictionary& dict +) +: + FieldFunction2>(entryName), + value_(Zero) +{ + if (!dict.found(entryName)) + { + dict.lookup("value") >> value_; + } + else + { + Istream& is(dict.lookup(entryName)); + word entryType(is); + if (is.eof()) + { + dict.lookup("value") >> value_; + } + else + { + is >> value_; + } + } +} + + +template +Foam::Function2s::Constant::Constant +( + const word& entryName, + Istream& is +) +: + FieldFunction2>(entryName), + value_(pTraits(is)) +{} + + +template +Foam::Function2s::Constant::Constant(const Constant& cnst) +: + FieldFunction2>(cnst), + value_(cnst.value_) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::Function2s::Constant::~Constant() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::Function2s::Constant::writeData(Ostream& os) const +{ + Function2::writeData(os); + + os << token::SPACE << value_ << token::END_STATEMENT << nl; +} + + +// ************************************************************************* i/ diff --git a/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.H b/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.H new file mode 100644 index 0000000000..33f877d1e2 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2.H @@ -0,0 +1,147 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +Class + Foam::Function2s::Constant + +Description + Templated function of two variables that returns a constant value. + + Usage - for entry \ returning the value : + \verbatim + constant ; + \endverbatim + + or simply + + \verbatim + ; + \endverbatim + +SourceFiles + Constant.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Constant2_H +#define Constant2_H + +#include "Function2.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace Function2s +{ + +/*---------------------------------------------------------------------------*\ + Class Constant Declaration +\*---------------------------------------------------------------------------*/ + +template +class Constant +: + public FieldFunction2> +{ + // Private Data + + //- Constant value + Type value_; + + +public: + + // Runtime type information + TypeName("constant"); + + + // Constructors + + //- Construct from entry name and value + Constant(const word& entryName, const Type& val); + + //- Construct from entry name and dictionary + Constant(const word& entryName, const dictionary& dict); + + //- Construct from entry name and Istream + // Reads the constant value without the Function2 type + // for backward compatibility + Constant(const word& entryName, Istream& is); + + //- Copy constructor + Constant(const Constant& cnst); + + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp>(new Constant(*this)); + } + + + //- Destructor + virtual ~Constant(); + + + // Member Functions + + //- Return constant + virtual inline Type value(const scalar x, const scalar y) const; + + //- Return constant field + virtual inline tmp> value + ( + const scalarField& x, + const scalarField& y + ) const; + + //- Write in dictionary format + virtual void writeData(Ostream& os) const; + + + // Member Operators + + //- Disallow default bitwise assignment + void operator=(const Constant&) = delete; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Function2s +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "Constant2I.H" + +#ifdef NoRepository + #include "Constant2.C" + #include "Function2New.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2I.H b/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2I.H new file mode 100644 index 0000000000..7b35c12eee --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function2/Constant/Constant2I.H @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +\*---------------------------------------------------------------------------*/ + +#include "Constant2.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +inline Type Foam::Function2s::Constant::value +( + const scalar x, + const scalar y +) const +{ + return value_; +} + + +template +inline Foam::tmp> Foam::Function2s::Constant::value +( + const scalarField& x, + const scalarField& y +) const +{ + return tmp>(new Field(x.size(), value_)); +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.C b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.C new file mode 100644 index 0000000000..a330643d27 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.C @@ -0,0 +1,153 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +\*---------------------------------------------------------------------------*/ + +#include "Function2.H" + +// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * // + +template +Foam::Function2::Function2(const word& entryName) +: + name_(entryName) +{} + + +template +Foam::Function2::Function2(const Function2& de) +: + tmp>::refCount(), + name_(de.name_) +{} + + +template +Foam::FieldFunction2::FieldFunction2 +( + const word& entryName +) +: + Function2(entryName) +{} + + +template +Foam::FieldFunction2::FieldFunction2 +( + const FieldFunction2& ff1 +) +: + Function2(ff1) +{} + + +template +Foam::tmp> +Foam::FieldFunction2::clone() const +{ + return tmp> + ( + new Function2Type(refCast(*this)) + ); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::Function2::~Function2() +{} + + +template +Foam::FieldFunction2::~FieldFunction2() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +const Foam::word& Foam::Function2::name() const +{ + return name_; +} + + +template +void Foam::Function2::writeData(Ostream& os) const +{ + writeKeyword(os, name_) << type(); +} + + +template +Foam::tmp> Foam::FieldFunction2::value +( + const scalarField& x, + const scalarField& y +) const +{ + tmp> tfld(new Field(x.size())); + Field& fld = tfld.ref(); + + forAll(x, i) + { + fld[i] = refCast(*this).value(x[i], y[i]); + } + + return tfld; +} + + +// * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * // + +template +void Foam::writeEntry(Ostream& os, const Function2& f1) +{ + f1.writeData(os); +} + + +// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * // + +template +Foam::Ostream& Foam::operator<< +( + Ostream& os, + const Function2& f1 +) +{ + // Check state of Ostream + os.check + ( + "Ostream& operator<<(Ostream&, const Function2&)" + ); + + f1.writeData(os); + + return os; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.H b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.H new file mode 100644 index 0000000000..86ef98a278 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2.H @@ -0,0 +1,241 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +Class + Foam::Function2 + +Description + Run-time selectable function of two variables + + with many options provided from simple constant values to complex + functions, interpolated tabulated data etc. etc. + +SourceFiles + Function2.C + Function2New.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Function2_H +#define Function2_H + +#include "dictionary.H" +#include "tmp.H" +#include "typeInfo.H" +#include "Field.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of friend functions and operators +template class Function2; +template Ostream& operator<<(Ostream&, const Function2&); + +/*---------------------------------------------------------------------------*\ + Class Function2 Declaration +\*---------------------------------------------------------------------------*/ + +template +class Function2 +: + public tmp>::refCount +{ + +protected: + + // Protected data + + //- Name of entry + const word name_; + + +public: + + typedef Type returnType; + + //- Runtime type information + TypeName("Function2") + + //- Declare runtime constructor selection table + declareRunTimeSelectionTable + ( + autoPtr, + Function2, + dictionary, + ( + const word& entryName, + const dictionary& dict + ), + (entryName, dict) + ); + + + // Constructors + + //- Construct from entry name + Function2(const word& entryName); + + //- Copy constructor + Function2(const Function2& f1); + + //- Construct and return a clone + virtual tmp> clone() const = 0; + + + //- Selector + static autoPtr> New + ( + const word& entryName, + const dictionary& dict + ); + + + //- Destructor + virtual ~Function2(); + + + // Member Functions + + //- Return the name of the entry + const word& name() const; + + //- Return value as a function of two scalars + virtual Type value(const scalar x, const scalar y) const = 0; + + //- Return value as a function of two scalar fields + virtual tmp> value + ( + const scalarField& x, + const scalarField& y + ) const = 0; + + //- Write in dictionary format + virtual void writeData(Ostream& os) const; + + + // Member Operators + + //- Disallow default bitwise assignment + void operator=(const Function2&) = delete; + + + // IOstream Operators + + //- Ostream Operator + friend Ostream& operator<< + ( + Ostream& os, + const Function2& func + ); +}; + + +template +void writeEntry(Ostream& os, const Function2& f1); + + +/*---------------------------------------------------------------------------*\ + Class FieldFunction2 Declaration +\*---------------------------------------------------------------------------*/ + +template +class FieldFunction2 +: + public Function2 +{ + +public: + + // Constructors + + //- Construct from entry name + FieldFunction2(const word& entryName); + + //- Copy constructor + FieldFunction2(const FieldFunction2& ff1); + + //- Construct and return a clone + virtual tmp> clone() const; + + + //- Destructor + virtual ~FieldFunction2(); + + + // Member Functions + + //- Return value as a function of two scalars + virtual Type value(const scalar x, const scalar y) const = 0; + + //- Return value as a function of two scalar fields + virtual tmp> value + ( + const scalarField& x, + const scalarField& y + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define makeFunction2(Type) \ + \ + defineNamedTemplateTypeNameAndDebug(Function2, 0); \ + \ + defineTemplateRunTimeSelectionTable(Function2, dictionary); + + +#define makeFunction2Type(SS, Type) \ + \ + defineNamedTemplateTypeNameAndDebug(Function2s::SS, 0); \ + \ + Function2::adddictionaryConstructorToTable> \ + addFunction2##SS##Type##ConstructorToTable_; + + +#define makeScalarFunction2(SS) \ + \ + defineTypeNameAndDebug(SS, 0); \ + \ + Function2::adddictionaryConstructorToTable \ + addFunction2##SS##ConstructorToTable_; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "Function2.C" + #include "Constant2.H" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function2/Function2/Function2Fwd.H b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2Fwd.H new file mode 100644 index 0000000000..dd7bf6d45a --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function2/Function2/Function2Fwd.H @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +\*---------------------------------------------------------------------------*/ + +#ifndef Function2Fwd_H +#define Function2Fwd_H + +#include "Function2.H" +#include "vector.H" +#include "symmTensor.H" +#include "sphericalTensor.H" +#include "tensor.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef Function2