diff --git a/applications/test/Polynomial/Test-Polynomial.C b/applications/test/Polynomial/Test-Polynomial.C index 8d2e36d4fd..c013597bcb 100644 --- a/applications/test/Polynomial/Test-Polynomial.C +++ b/applications/test/Polynomial/Test-Polynomial.C @@ -31,7 +31,6 @@ Description #include "IStringStream.H" #include "Polynomial.H" -#include "polynomialFunction.H" #include "Random.H" #include "cpuTime.H" @@ -111,14 +110,12 @@ int main(int argc, char *argv[]) scalar sum = 0.0; Info<< "null poly = " << (Polynomial<8>()) << nl - << "null poly = " << (polynomialFunction(8)) << nl << endl; Polynomial<8> poly(coeff); Polynomial<9> intPoly(poly.integral(0.0)); IStringStream is(polyDef); - polynomialFunction polyfunc(is); Info<< "poly = " << poly << nl << "intPoly = " << intPoly << nl @@ -131,19 +128,9 @@ int main(int argc, char *argv[]) << "3*poly - 2*poly = " << 3*poly - 2*poly << nl << endl; - Info<< nl << "--- as polynomialFunction" << nl << endl; - Info<< "polyf = " << polyfunc << nl - << "intPoly = " << poly.integral(0.0) << nl + Info<< "intPoly = " << poly.integral(0.0) << nl << endl; - Info<< "2*polyf = " << 2*polyfunc << nl - << "polyf+polyf = " << polyfunc + polyfunc << nl - << "3*polyf = " << 3*polyfunc << nl - << "polyf+polyf+polyf = " << polyfunc + polyfunc + polyfunc << nl - << "3*polyf - 2*polyf = " << 3*polyfunc - 2*polyfunc << nl - << endl; - - Polynomial<8> polyCopy = poly; Info<< "poly, polyCopy = " << poly << ", " << polyCopy << nl << endl; polyCopy = 2.5*poly; @@ -197,18 +184,6 @@ int main(int argc, char *argv[]) Info<< "value: " << sum << " in " << timer.cpuTimeIncrement() << " s\n"; - for (int loop = 0; loop < n; ++loop) - { - sum = 0.0; - for (label iter = 0; iter < nIters; ++iter) - { - sum += polyfunc.value(loop+iter); - } - } - Info<< "via function: " << sum - << " in " << timer.cpuTimeIncrement() << " s\n"; - - for (int loop = 0; loop < n; ++loop) { sum = 0.0; diff --git a/src/OpenFOAM/primitives/functions/Polynomial/polynomialFunction.C b/src/OpenFOAM/primitives/functions/Polynomial/polynomialFunction.C deleted file mode 100644 index dc8e38efec..0000000000 --- a/src/OpenFOAM/primitives/functions/Polynomial/polynomialFunction.C +++ /dev/null @@ -1,403 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 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 "polynomialFunction.H" -#include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ - defineTypeNameAndDebug(polynomialFunction, 0); -} - - -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - - -Foam::polynomialFunction Foam::polynomialFunction::cloneIntegral -( - const polynomialFunction& poly, - const scalar intConstant -) -{ - polynomialFunction newPoly(poly.size()+1); - - newPoly[0] = intConstant; - forAll(poly, i) - { - newPoly[i+1] = poly[i]/(i + 1); - } - - return newPoly; -} - - -Foam::polynomialFunction Foam::polynomialFunction::cloneIntegralMinus1 -( - const polynomialFunction& poly, - const scalar intConstant -) -{ - polynomialFunction newPoly(poly.size()+1); - - if (poly[0] > vSmall) - { - newPoly.logActive_ = true; - newPoly.logCoeff_ = poly[0]; - } - - newPoly[0] = intConstant; - for (label i=1; i < poly.size(); ++i) - { - newPoly[i] = poly[i]/i; - } - - return newPoly; -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::polynomialFunction::polynomialFunction(const label order) -: - scalarList(order, 0.0), - logActive_(false), - logCoeff_(0.0) -{ - if (this->empty()) - { - FatalErrorInFunction - << "polynomialFunction coefficients are invalid (empty)" - << nl << exit(FatalError); - } -} - - -Foam::polynomialFunction::polynomialFunction(const polynomialFunction& poly) -: - scalarList(poly), - logActive_(poly.logActive_), - logCoeff_(poly.logCoeff_) -{} - - -Foam::polynomialFunction::polynomialFunction(const UList& coeffs) -: - scalarList(coeffs), - logActive_(false), - logCoeff_(0.0) -{ - if (this->empty()) - { - FatalErrorInFunction - << "polynomialFunction coefficients are invalid (empty)" - << nl << exit(FatalError); - } -} - - -Foam::polynomialFunction::polynomialFunction(Istream& is) -: - scalarList(is), - logActive_(false), - logCoeff_(0.0) -{ - if (this->empty()) - { - FatalErrorInFunction - << "polynomialFunction coefficients are invalid (empty)" - << nl << exit(FatalError); - } -} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::polynomialFunction::~polynomialFunction() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -bool Foam::polynomialFunction::logActive() const -{ - return logActive_; -} - - -Foam::scalar Foam::polynomialFunction::logCoeff() const -{ - return logCoeff_; -} - - -Foam::scalar Foam::polynomialFunction::value(const scalar x) const -{ - const scalarList& coeffs = *this; - scalar val = coeffs[0]; - - // avoid costly pow() in calculation - scalar powX = x; - for (label i=1; ilogCoeff_*log(x); - } - - return val; -} - - -Foam::scalar Foam::polynomialFunction::integrate -( - const scalar x1, - const scalar x2 -) const -{ - const scalarList& coeffs = *this; - - if (logActive_) - { - FatalErrorInFunction - << "Cannot integrate polynomial with logarithmic coefficients" - << nl << abort(FatalError); - } - - // avoid costly pow() in calculation - scalar powX1 = x1; - scalar powX2 = x2; - - scalar val = coeffs[0]*(powX2 - powX1); - for (label i=1; i poly.size()) - { - forAll(poly, i) - { - coeffs[i] += poly[i]; - } - } - else - { - coeffs.setSize(poly.size(), 0.0); - - forAll(coeffs, i) - { - coeffs[i] += poly[i]; - } - } - - return *this; -} - - -Foam::polynomialFunction& -Foam::polynomialFunction::operator-=(const polynomialFunction& poly) -{ - scalarList& coeffs = *this; - - if (coeffs.size() > poly.size()) - { - forAll(poly, i) - { - coeffs[i] -= poly[i]; - } - } - else - { - coeffs.setSize(poly.size(), 0.0); - - forAll(coeffs, i) - { - coeffs[i] -= poly[i]; - } - } - - return *this; -} - - -Foam::polynomialFunction& -Foam::polynomialFunction::operator*=(const scalar s) -{ - scalarList& coeffs = *this; - forAll(coeffs, i) - { - coeffs[i] *= s; - } - - return *this; -} - - -Foam::polynomialFunction& -Foam::polynomialFunction::operator/=(const scalar s) -{ - scalarList& coeffs = *this; - forAll(coeffs, i) - { - coeffs[i] /= s; - } - - return *this; -} - - -// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // - -Foam::Ostream& Foam::operator<<(Ostream& os, const polynomialFunction& poly) -{ - // output like VectorSpace - os << token::BEGIN_LIST; - - if (!poly.empty()) - { - for (int i=0; i. - -Class - Foam::polynomialFunction - -Description - Polynomial function representation - - \verbatim - poly = logCoeff*log(x) + sum(coeffs[i]*x^i) - \endverbatim - - where 0 <= i <= N - - - integer powers, starting at zero - - \c value(x) to evaluate the poly for a given value - - \c integrate(x1, x2) between two scalar values - - \c integral() to return a new, integral coeff polynomial - - increases the size (order) - - \c integralMinus1() to return a new, integral coeff polynomial where - the base poly starts at order -1 - -See also - Foam::Polynomial for a templated implementation - -SourceFiles - polynomialFunction.C - -\*---------------------------------------------------------------------------*/ - -#ifndef polynomialFunction_H -#define polynomialFunction_H - -#include "scalarList.H" -#include "Ostream.H" -#include "runTimeSelectionTables.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// Forward declaration of classes -class polynomialFunction; - -// Forward declaration of friend functions -Ostream& operator<<(Ostream&, const polynomialFunction&); - - -/*---------------------------------------------------------------------------*\ - Class polynomialFunction Declaration -\*---------------------------------------------------------------------------*/ - -class polynomialFunction -: - private scalarList -{ - // Private data - - //- Include the log term? - only activated using integralMinus1() - bool logActive_; - - //- Log coefficient - only activated using integralMinus1() - scalar logCoeff_; - - - // Private Member Functions - - //- Return integral coefficients. - // Argument becomes zeroth element (constant of integration) - static polynomialFunction cloneIntegral - ( - const polynomialFunction&, - const scalar intConstant = 0.0 - ); - - //- Return integral coefficients when lowest order is -1. - // Argument becomes zeroth element (constant of integration) - static polynomialFunction cloneIntegralMinus1 - ( - const polynomialFunction&, - const scalar intConstant = 0.0 - ); - - - //- Disallow default bitwise assignment - void operator=(const polynomialFunction&); - - - -public: - - //- Runtime type information - TypeName("polynomialFunction"); - - - // Constructors - - //- Construct a particular size, with all coefficients = 0.0 - explicit polynomialFunction(const label); - - //- Copy constructor - polynomialFunction(const polynomialFunction&); - - //- Construct from a list of coefficients - explicit polynomialFunction(const UList& coeffs); - - //- Construct from Istream - polynomialFunction(Istream&); - - - //- Destructor - virtual ~polynomialFunction(); - - - // Member Functions - - //- Return the number of coefficients - using scalarList::size; - - //- Return coefficient - using scalarList::operator[]; - - - // Access - - - //- Return true if the log term is active - bool logActive() const; - - //- Return the log coefficient - scalar logCoeff() const; - - - // Evaluation - - //- Return polynomial value - scalar value(const scalar x) const; - - //- Integrate between two values - scalar integrate(const scalar x1, const scalar x2) const; - - - //- Return integral coefficients. - // Argument becomes zeroth element (constant of integration) - polynomialFunction integral - ( - const scalar intConstant = 0.0 - ) const; - - //- Return integral coefficients when lowest order is -1. - // Argument becomes zeroth element (constant of integration) - polynomialFunction integralMinus1 - ( - const scalar intConstant = 0.0 - ) const; - - - // Member Operators - - polynomialFunction& operator+=(const polynomialFunction&); - polynomialFunction& operator-=(const polynomialFunction&); - - polynomialFunction& operator*=(const scalar); - polynomialFunction& operator/=(const scalar); - - - //- Ostream Operator - friend Ostream& operator<<(Ostream&, const polynomialFunction&); -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // - -polynomialFunction operator+ -( - const polynomialFunction&, - const polynomialFunction& -); - - -polynomialFunction operator- -( - const polynomialFunction&, - const polynomialFunction& -); - - -polynomialFunction operator* -( - const scalar, - const polynomialFunction& -); - - -polynomialFunction operator/ -( - const scalar, - const polynomialFunction& -); - - -polynomialFunction operator* -( - const polynomialFunction&, - const scalar -); - - -polynomialFunction operator/ -( - const polynomialFunction&, - const scalar -); - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* //