diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index c99ee23fa5..3de2322137 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -60,6 +60,10 @@ $(sha1)/SHA1Digest.C primitives/random/Random.C +functions = primitives/functions +$(functions)/Polynomial/makePolynomialsOrder7.C + + containers/HashTables/HashTable/HashTableName.C containers/HashTables/StaticHashTable/StaticHashTableName.C containers/Lists/SortableList/ParSortableListName.C diff --git a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.C b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.C new file mode 100644 index 0000000000..f3621eabc0 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.C @@ -0,0 +1,162 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "Polynomial.H" +#include "error.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::Polynomial::Polynomial() +: + VectorSpace, scalar, PolySize>(), + name_("unknownPolynomialName") +{} + + +template +Foam::Polynomial::Polynomial(const word& name, Istream& is) +: + VectorSpace, scalar, PolySize>(), + name_(is) +{ + if (name_ != name) + { + FatalErrorIn + ( + "Foam::Polynomial::Polynomial(const word&, Istream&)" + ) << "Expected polynomial name " << name << " but read " << name_ + << nl << exit(FatalError); + } + + VectorSpace, scalar, PolySize>:: + operator=(polyType(is)); + + if (this->size() == 0) + { + FatalErrorIn + ( + "Foam::Polynomial::Polynomial(const word&, Istream&)" + ) << "Polynomial coefficients for entry " << name_ + << " are invalid (empty)" << nl << exit(FatalError); + } +} + + +template +Foam::Polynomial::Polynomial(const Polynomial& poly) +: + VectorSpace, scalar, PolySize>(poly), + name_(poly.name_) +{} + + +template +Foam::Polynomial::Polynomial +( + const word& name, + const Polynomial& poly +) +: + VectorSpace, scalar, PolySize>(poly), + name_(name) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::Polynomial::~Polynomial() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +const Foam::word& Foam::Polynomial::name() const +{ + return name_; +} + + +template +Foam::scalar Foam::Polynomial::evaluate(const scalar x) const +{ + scalar y = 0.0; + forAll(*this, i) + { + y += this->v_[i]*pow(x, i); + } + + return y; +} + + +template +Foam::scalar Foam::Polynomial::integrateLimits +( + const scalar x1, + const scalar x2 +) const +{ + scalar intx = 0.0; + + forAll(*this, i) + { + intx += this->v_[i]/(i + 1)*(pow(x2, i + 1) - pow(x1, i + 1)); + } + + return intx; +} + + +template +typename Foam::Polynomial::intPolyType +Foam::Polynomial::integrate(const scalar intConstant) +{ + intPolyType newCoeffs; + + newCoeffs[0] = intConstant; + forAll(*this, i) + { + newCoeffs[i + 1] = this->v_[i]/(i + 1); + } + + return newCoeffs; +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +template +void Foam::Polynomial::operator=(const Polynomial& poly) +{ + name_ = poly.name_; + VectorSpace, scalar, PolySize>::operator=(poly); +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H new file mode 100644 index 0000000000..0ade28b2c8 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H @@ -0,0 +1,180 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::Polynomial + +Description + Polynomial templated on size (order): + + poly = sum(coeff_[i]*x^i) + + where 0 <= i <= n + + - integer powers, starting at zero + - evaluate(x) to evaluate the poly for a given value + - integrate(x1, x2) between two scalar values + - integrate() to return a new, intergated coeff polynomial + - increases the size (order) + +SourceFiles + Polynomial.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Polynomial_H +#define Polynomial_H + +#include "word.H" +#include "scalar.H" +#include "Ostream.H" +#include "VectorSpace.H" +#include "Vector.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +template +class Polynomial; + +// Forward declaration of friend functions +template +Ostream& operator<< +( + Ostream&, + const Polynomial& +); + + +/*---------------------------------------------------------------------------*\ + Class Polynomial Declaration +\*---------------------------------------------------------------------------*/ + +template +class Polynomial +: + public VectorSpace, scalar, PolySize> +{ +private: + + // Private data + + //- Polynomial name + word name_; + + +public: + + typedef VectorSpace, scalar, PolySize> polyType; + + typedef Polynomial intPolyType; + + //- Run-time type information + TypeName("Polynomial") + + + // Constructors + + //- Construct null + Polynomial(); + + //- Construct from name and Istream + Polynomial(const word& name, Istream& is); + + //- Copy constructor + Polynomial(const Polynomial& poly); + + //- Copy constructor with name + Polynomial(const word& name, const Polynomial& poly); + + + //- Destructor + ~Polynomial(); + + + // Member Functions + + // Access + + //- Return const access to the polynomial name + const word& name() const; + + + // Evaluation + + //- Return polynomial value + scalar evaluate(const scalar x) const; + + //- Return integrated polynomial coefficients + // argument becomes zeroth element (constant of integration) + intPolyType integrate(const scalar intConstant = 0.0); + + //- Integrate between two values + scalar integrateLimits(const scalar x1, const scalar x2) const; + + + // Member operators + + void operator=(const Polynomial& poly); + + + //- Ostream Operator + friend Ostream& operator<< + ( + Ostream&, + const Polynomial& + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define makePolynomial(PolySize) \ + \ +defineTemplateTypeNameAndDebugWithName \ +( \ + Polynomial, \ + "Polynomial<"#PolySize">", \ + 0 \ +) + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "Polynomial.C" +# include "PolynomialIO.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Polynomial/PolynomialIO.C b/src/OpenFOAM/primitives/functions/Polynomial/PolynomialIO.C new file mode 100644 index 0000000000..e7c1fd452a --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Polynomial/PolynomialIO.C @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "Polynomial.H" + +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +template +Foam::Ostream& Foam::operator<< +( + Ostream& os, + const Polynomial& poly +) +{ + os << poly.name_ << token::SPACE + << static_cast + , scalar, PolySize> >(poly); + + // Check state of Ostream + os.check + ( + "Ostream& operator<<(Ostream&, const Polynomial&)" + ); + + return os; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Polynomial/makePolynomialsOrder7.C b/src/OpenFOAM/primitives/functions/Polynomial/makePolynomialsOrder7.C new file mode 100644 index 0000000000..0d502964a8 --- /dev/null +++ b/src/OpenFOAM/primitives/functions/Polynomial/makePolynomialsOrder7.C @@ -0,0 +1,51 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "Polynomial.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +namespace Foam +{ + makePolynomial(2); + makePolynomial(3); + makePolynomial(4); + makePolynomial(5); + makePolynomial(6); + makePolynomial(7); + makePolynomial(8); + + // explicitly define max order + 1 to define the integrated form + defineTemplateTypeNameAndDebugWithName + ( + Polynomial<9>, + "Polynomial<9>", + 0 + ); +} + + +// ************************************************************************* //