From 96c6c520172747382662a99bbf0c28225e012f21 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Thu, 16 Mar 2017 20:48:26 +0000 Subject: [PATCH] Function1: Added zero and one constant functions for convenience --- .../functions/Function1/One/OneConstant.C | 84 ++++++++++++ .../functions/Function1/One/OneConstant.H | 120 ++++++++++++++++++ .../functions/Function1/Zero/ZeroConstant.C | 77 +++++++++++ .../functions/Function1/Zero/ZeroConstant.H | 117 +++++++++++++++++ 4 files changed, 398 insertions(+) create mode 100644 src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C create mode 100644 src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H create mode 100644 src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C create mode 100644 src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H diff --git a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C new file mode 100644 index 000000000..42779f795 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.C @@ -0,0 +1,84 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 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 "OneConstant.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::Function1Types::OneConstant::OneConstant(const word& entryName) +: + Function1(entryName) +{} + + +template +Foam::Function1Types::OneConstant::OneConstant +( + const word& entryName, + const dictionary& dict +) +: + Function1(entryName) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::Function1Types::OneConstant::~OneConstant() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Type Foam::Function1Types::OneConstant::value(const scalar x) const +{ + return pTraits::one; +} + + +template +Type Foam::Function1Types::OneConstant::integrate +( + const scalar x1, + const scalar x2 +) const +{ + return (x2 - x1)*pTraits::one; +} + + +template +void Foam::Function1Types::OneConstant::writeData(Ostream& os) const +{ + Function1::writeData(os); + + os << token::END_STATEMENT << nl; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H new file mode 100644 index 000000000..ba2f796dc --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function1/One/OneConstant.H @@ -0,0 +1,120 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2016 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::Function1Types::OneConstant + +Description + Templated function that returns the corresponding 1 (one). + + Usage: + \verbatim + one; + \endverbatim + +SourceFiles + OneConstant.C + +\*---------------------------------------------------------------------------*/ + +#ifndef OneConstant_H +#define OneConstant_H + +#include "Function1.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace Function1Types +{ + +/*---------------------------------------------------------------------------*\ + Class OneConstant Declaration +\*---------------------------------------------------------------------------*/ + +template +class OneConstant +: + public Function1 +{ + // Private Member Functions + + //- Disallow default bitwise assignment + void operator=(const OneConstant&); + + +public: + + // Runtime type information + TypeName("one"); + + + // Constructors + + //- Construct from entry name + OneConstant(const word& entryName); + + //- Construct from entry name and dictionary + OneConstant(const word& entryName, const dictionary& dict); + + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp>(new OneConstant(*this)); + } + + + //- Destructor + virtual ~OneConstant(); + + + // Member Functions + + //- Return constant value + Type value(const scalar) const; + + //- Integrate between two values + Type integrate(const scalar x1, const scalar x2) const; + + //- Write in dictionary format + virtual void writeData(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Function1Types +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "OneConstant.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C new file mode 100644 index 000000000..fd89eff02 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.C @@ -0,0 +1,77 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 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 "ZeroConstant.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::Function1Types::ZeroConstant::ZeroConstant +( + const word& entryName, + const dictionary& dict +) +: + Function1(entryName) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::Function1Types::ZeroConstant::~ZeroConstant() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Type Foam::Function1Types::ZeroConstant::value(const scalar x) const +{ + return pTraits::zero; +} + + +template +Type Foam::Function1Types::ZeroConstant::integrate +( + const scalar x1, + const scalar x2 +) const +{ + return pTraits::zero; +} + + +template +void Foam::Function1Types::ZeroConstant::writeData(Ostream& os) const +{ + Function1::writeData(os); + + os << token::END_STATEMENT << nl; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H new file mode 100644 index 000000000..804bd2f00 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Function1/Zero/ZeroConstant.H @@ -0,0 +1,117 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2016 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::Function1Types::ZeroConstant + +Description + Templated function that returns the corresponding 0 (zero). + + Usage: + \verbatim + zero; + \endverbatim + +SourceFiles + ZeroConstant.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ZeroConstant_H +#define ZeroConstant_H + +#include "Function1.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace Function1Types +{ + +/*---------------------------------------------------------------------------*\ + Class ZeroConstant Declaration +\*---------------------------------------------------------------------------*/ + +template +class ZeroConstant +: + public Function1 +{ + // Private Member Functions + + //- Disallow default bitwise assignment + void operator=(const ZeroConstant&); + + +public: + + // Runtime type information + TypeName("zero"); + + + // Constructors + + //- Construct from entry name and dictionary + ZeroConstant(const word& entryName, const dictionary& dict); + + //- Construct and return a clzero + virtual tmp> clzero() const + { + return tmp>(new ZeroConstant(*this)); + } + + + //- Destructor + virtual ~ZeroConstant(); + + + // Member Functions + + //- Return constant value + Type value(const scalar) const; + + //- Integrate between two values + Type integrate(const scalar x1, const scalar x2) const; + + //- Write in dictionary format + virtual void writeData(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Function1Types +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "ZeroConstant.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //