From fc05d1b4929203caea7f37a6450051651daa637e Mon Sep 17 00:00:00 2001 From: Bastien Gorissen <bastien.gorissen@cenaero.be> Date: Mon, 28 Nov 2011 12:15:00 +0000 Subject: [PATCH] Added Legendre polynomials (preparation for Bergot basis for pyramids) --- Numeric/CMakeLists.txt | 1 + Numeric/legendrePolynomials.cpp | 34 +++++++++++++++++++++++++++++++++ Numeric/legendrePolynomials.h | 21 ++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 Numeric/legendrePolynomials.cpp create mode 100644 Numeric/legendrePolynomials.h diff --git a/Numeric/CMakeLists.txt b/Numeric/CMakeLists.txt index 9a29763052..29ecc6f1f8 100644 --- a/Numeric/CMakeLists.txt +++ b/Numeric/CMakeLists.txt @@ -9,6 +9,7 @@ set(SRC polynomialBasis.cpp JacobianBasis.cpp jacobiPolynomials.cpp + legendrePolynomials.cpp GaussIntegration.cpp GaussQuadratureLin.cpp GaussQuadratureTri.cpp diff --git a/Numeric/legendrePolynomials.cpp b/Numeric/legendrePolynomials.cpp new file mode 100644 index 0000000000..2b229ec692 --- /dev/null +++ b/Numeric/legendrePolynomials.cpp @@ -0,0 +1,34 @@ +#include "legendrePolynomials.h" + +LegendrePolynomials::LegendrePolynomials(int o): n(o) {} +LegendrePolynomials::~LegendrePolynomials() {;} + +void LegendrePolynomials::f(double u, double *val) const { + val[0] = 1; + + for (int i=0;i<n;i++) { + + double a1i = i+1; + double a3i = 2.*i+1; + double a4i = i; + + val[i+1] = a3i * u * val[i]; + if (i>0) val[i+1] -= a4i * val[i-1]; + val[i+1] /= a1i; + } +} + +void LegendrePolynomials::df(double u, double *val) const { + double tmp[n+1]; + f(u,tmp); + + val[0] = 0; + double g2 = (1.-u*u); + + for (int i=1;i<=n;i++) { + double g1 = - u*i; + double g0 = (double) i; + + val[i] = (g1 * tmp[i] + g0 * tmp[i-1])/g2; + } +} diff --git a/Numeric/legendrePolynomials.h b/Numeric/legendrePolynomials.h new file mode 100644 index 0000000000..ab67139a6f --- /dev/null +++ b/Numeric/legendrePolynomials.h @@ -0,0 +1,21 @@ +#ifndef LEGENDREPOLYNOMIALS_H +#define LEGENDREPOLYNOMIALS_H + +#include "fullMatrix.h" + +class LegendrePolynomials { + + public: + LegendrePolynomials(int o); + ~LegendrePolynomials(); + + void f(double u, double *val) const; + + void df(double u, double *val) const; + + private: + int n; +}; + + +#endif -- GitLab