From: Guido Kanschat Date: Mon, 29 Jan 2001 06:17:53 +0000 (+0000) Subject: Polynomial is a template now X-Git-Tag: v8.0.0~19772 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aff8865dbdd2dce98b109bced24f9c56600afdf7;p=dealii.git Polynomial is a template now git-svn-id: https://svn.dealii.org/trunk@3813 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/polynomial.h b/deal.II/base/include/base/polynomial.h index 445f31df5c..c0505d035d 100644 --- a/deal.II/base/include/base/polynomial.h +++ b/deal.II/base/include/base/polynomial.h @@ -30,6 +30,7 @@ * * @author Ralf Hartmann, Guido Kanschat, 2000 */ +template class Polynomial : public Subscriptor { public: @@ -48,7 +49,7 @@ class Polynomial : public Subscriptor * the @p{coefficient} array * minus one. */ - Polynomial (const std::vector &coefficients); + Polynomial (const std::vector &coefficients); /** * Default-Constructor. @@ -63,7 +64,7 @@ class Polynomial : public Subscriptor * scheme for numerical stability * of the evaluation. */ - double value (const double x) const; + number value (const number x) const; /** * Return the values and the @@ -81,8 +82,8 @@ class Polynomial : public Subscriptor * scheme for numerical stability * of the evaluation. */ - void value (const double x, - std::vector &values) const; + void value (const number x, + std::vector &values) const; /** * Exception @@ -104,7 +105,7 @@ class Polynomial : public Subscriptor * passed down by derived * classes. */ - std::vector coefficients; + std::vector coefficients; }; @@ -123,7 +124,7 @@ class Polynomial : public Subscriptor * * @author Ralf Hartmann, 2000 */ -class LagrangeEquidistant: public Polynomial +class LagrangeEquidistant: public Polynomial { public: /** @@ -141,15 +142,7 @@ class LagrangeEquidistant: public Polynomial /** * Default-constructor. */ - LagrangeEquidistant (); - - - /** - * Exception - */ - DeclException1 (ExcInvalidSupportPoint, - int, - << "The support point " << arg1 << " is invalid."); + LagrangeEquidistant (); private: @@ -168,5 +161,46 @@ class LagrangeEquidistant: public Polynomial }; +/** + * Legendre polynomials of arbitrary order + * + * Constructing a Legendre polynomial of order @p{k}, the coefficients + * will be computed by the three-term recursion formula. The + * coefficients are stored in a static data vector to be available + * when needed next time. + * + * @author Guido Kanschat, 2000 + */ +template +class Legendre : public Polynomial +{ +public: + /** + * Constructor for polynomial of + * order @p{k}. + */ + Legendre (unsigned int k); +private: + /** + * Vector with already computed + * coefficients. + */ + static std::vector > coefficients + + /** + * Compute coefficients recursively. + */ + static void compute_coeficients (unsigned int k); + + /** + * Get coefficients for + * constructor. This way, it can + * use the non-standard constructor + * of @ref{Polynomial}. + */ + static const std::vector& get_coefficients (unsigned int k); +} + #endif + diff --git a/deal.II/base/include/base/tensor_product_polynomials.h b/deal.II/base/include/base/tensor_product_polynomials.h index 8827888568..2f7283f8e9 100644 --- a/deal.II/base/include/base/tensor_product_polynomials.h +++ b/deal.II/base/include/base/tensor_product_polynomials.h @@ -43,7 +43,7 @@ class TensorProductPolynomials * and will be copied into the * member variable @p{polynomials}. */ - TensorProductPolynomials(const std::vector > &pols); + TensorProductPolynomials(const std::vector > > &pols); /** * Calculates the polynomials @@ -81,7 +81,7 @@ class TensorProductPolynomials * Pointer to the @p{polynomials} * given to the constructor. */ - std::vector > polynomials; + std::vector > > polynomials; /** * Number of tensor product diff --git a/deal.II/base/source/polynomial.cc b/deal.II/base/source/polynomial.cc index 9dd7a5bd35..a85408df96 100644 --- a/deal.II/base/source/polynomial.cc +++ b/deal.II/base/source/polynomial.cc @@ -14,27 +14,30 @@ #include - -Polynomial::Polynomial (const std::vector &a): +template +Polynomial::Polynomial (const std::vector &a): coefficients(a) {} -Polynomial::Polynomial () +template +Polynomial::Polynomial () : coefficients(0) {} -double Polynomial::value (const double x) const +template +number +Polynomial::value (const number x) const { Assert (coefficients.size() > 0, ExcVoidPolynomial()); const unsigned int m=coefficients.size(); // Horner scheme - double value = coefficients.back(); + number value = coefficients.back(); for (int k=m-2; k>=0; --k) value = value*x + coefficients[k]; @@ -43,8 +46,10 @@ double Polynomial::value (const double x) const -void Polynomial::value (const double x, - std::vector &values) const +template +void +Polynomial::value (const number x, + std::vector &values) const { Assert (coefficients.size() > 0, ExcVoidPolynomial()); Assert (values.size() > 0, ExcEmptyArray()); @@ -68,7 +73,7 @@ void Polynomial::value (const double x, // then do it properly by the // full Horner scheme const unsigned int m=coefficients.size(); - std::vector a(coefficients); + std::vector a(coefficients); unsigned int j_faculty=1; for (unsigned int j=0; j(compute_coefficients(n,support_point)) {} @@ -291,3 +296,7 @@ LagrangeEquidistant::compute_coefficients (const unsigned int n, return a; } + +template Polynomial; +template Polynomial; +template Polynomial; diff --git a/deal.II/base/source/tensor_product_polynomials.cc b/deal.II/base/source/tensor_product_polynomials.cc index 80b390f3fa..4bb827db8e 100644 --- a/deal.II/base/source/tensor_product_polynomials.cc +++ b/deal.II/base/source/tensor_product_polynomials.cc @@ -30,7 +30,7 @@ number power(number x, unsigned int y) template TensorProductPolynomials::TensorProductPolynomials( - const std::vector > &pols): + const std::vector > > &pols): polynomials(pols), n_tensor_pols(power(polynomials.size(), dim)) {}