/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright held by original author \\/ 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 * * * * * * * * * * * * * * // template Foam::Polynomial::Polynomial() : VectorSpace, scalar, PolySize>(), logActive_(false), logCoeff_(0.0) {} template Foam::Polynomial::Polynomial(const word& name, Istream& is) : VectorSpace, scalar, PolySize>(), logActive_(false), logCoeff_(0.0) { word isName(is); if (isName != name) { FatalErrorIn ( "Polynomial::Polynomial(const word&, Istream&)" ) << "Expected polynomial name " << name << " but read " << isName << nl << exit(FatalError); } VectorSpace, scalar, PolySize>:: operator=(VectorSpace, scalar, PolySize>(is)); if (this->size() == 0) { FatalErrorIn ( "Polynomial::Polynomial(const word&, Istream&)" ) << "Polynomial coefficients for entry " << isName << " are invalid (empty)" << nl << exit(FatalError); } } template Foam::Polynomial::Polynomial ( const Polynomial& poly ) : VectorSpace, scalar, PolySize>(poly), logActive_(poly.logActive_), logCoeff_(poly.logCoeff_) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template bool& Foam::Polynomial::logActive() { return logActive_; } template Foam::scalar& Foam::Polynomial::logCoeff() { return logCoeff_; } template Foam::scalar Foam::Polynomial::evaluate(const scalar x) const { scalar y = this->v_[0]; for (label i=1; iv_[i]*pow(x, i); } if (logActive_) { y += logCoeff_*log(x); } return y; } template Foam::scalar Foam::Polynomial::integrateLimits ( const scalar x1, const scalar x2 ) const { if (logActive_) { FatalErrorIn ( "scalar Polynomial::integrateLimits" "(" "const scalar, " "const scalar" ") const" ) << "Cannot integrate polynomial with logarithmic coefficients" << nl << abort(FatalError); } intPolyType poly = this->integrate(); return poly.evaluate(x2) - poly.evaluate(x1); } 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; } template typename Foam::Polynomial::polyType Foam::Polynomial::integrateMinus1(const scalar intConstant) { polyType newCoeffs; if (this->v_[0] > VSMALL) { newCoeffs.logActive() = true; newCoeffs.logCoeff() = this->v_[0]; } newCoeffs[0] = intConstant; if (PolySize > 0) { for (label i=1; iv_[i]/i; } } return newCoeffs; } // ************************************************************************* //