/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2026 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 "FixedPolynomial.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::FixedPolynomial::FixedPolynomial() : VectorSpace, T, PN>() {} template Foam::FixedPolynomial::FixedPolynomial(const zero) : VectorSpace, T, PN>(Zero) {} template Foam::FixedPolynomial::FixedPolynomial(const T (&coeffs)[PN]) : VectorSpace, T, PN>() { for (uint8_t i = 0; i < PN; ++ i) { this->v_[i] = coeffs[i]; } } template Foam::FixedPolynomial::FixedPolynomial(const UList& coeffs) : VectorSpace, T, PN>() { if (coeffs.size() != PN) { FatalErrorInFunction << "Given " << coeffs.size() << " coefficients for polynomial with " << PN << " terms" << exit(FatalError); } for (uint8_t i = 0; i < PN; ++ i) { this->v_[i] = coeffs[i]; } } template Foam::FixedPolynomial::FixedPolynomial(Istream& is) : VectorSpace, T, PN>(is) {} template Foam::FixedPolynomial::FixedPolynomial ( const char* symbols, const Function1s::unitSets& units, const dictionary& dict ) : VectorSpace, T, PN>() { unitSet unitsXpow(dimless); for (uint8_t i = 0; i < PN; ++ i) { this->v_[i] = dict.lookup(word(symbols[i]), units.value/unitsXpow); unitsXpow.reset(units.x*unitsXpow); } } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template T Foam::FixedPolynomial::value(const scalar x) const { T result = this->v_[PN - 1]; for (uint8_t i = 1; i < PN; ++ i) { result *= x; result += this->v_[PN - 1 - i]; } return result; } template T Foam::FixedPolynomial::derivative(const scalar x) const { T result = this->v_[PN - 1]*(PN - 1); for (uint8_t i = 1; i < PN - 1; ++ i) { result *= x; result += this->v_[PN - 1 - i]*(PN - 1 - i); } return result; } template T Foam::FixedPolynomial::integral(const scalar x) const { T result = pTraits::zero; for (uint8_t i = 0; i < PN; ++ i) { result += this->v_[PN - 1 - i]/(PN - i); result *= x; } return result; } template T Foam::FixedPolynomial::integral ( const scalar x0, const scalar x1 ) const { return integral(x1) - integral(x0); } template Foam::FixedPolynomial Foam::FixedPolynomial::integralPolynomial(const scalar x) const { FixedPolynomial result(Zero); for (uint8_t i = 0; i < PN; ++ i) { result[i + 1] = this->v_[i]/(i + 1); } result[0] = - result.value(x); return result; } template void Foam::FixedPolynomial::write ( const char* symbols, const Function1s::unitSets& units, Ostream& os ) const { FixedPolynomial copy(*this); convert(copy, units, unitSet::makeUserOp()); for (uint8_t i = 0; i < PN; ++ i) { writeEntry(os, word(symbols[i]), copy[i]); } } // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // template void Foam::convert ( FixedPolynomial& poly, const Function1s::unitSets& units, const unitSet::makeStandardOp& ) { unitSet unitsXpow(dimless); for (uint8_t i = 0; i < PN; ++ i) { poly[i] = units.value.toStandard(unitsXpow.toUser(poly[i])); unitsXpow.reset(units.x*unitsXpow); } } template void Foam::convert ( FixedPolynomial& poly, const Function1s::unitSets& units, const unitSet::makeUserOp& ) { unitSet unitsXpow(dimless); for (uint8_t i = 0; i < PN; ++ i) { poly[i] = units.value.toUser(unitsXpow.toStandard(poly[i])); unitsXpow.reset(units.x*unitsXpow); } } // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // template Foam::Ostream& Foam::operator<< ( Ostream& os, const InfoProxy>& ip ) { const FixedPolynomial& poly = ip.t_; if (PN > 0) { os << poly[0]; } for (label p = 1; p < PN; ++ p) { os << " + " << poly[p] << "*x"; if (p > 1) os << "^" << p; } return os; } // ************************************************************************* //