ROL
NodalBasis.hpp
Go to the documentation of this file.
1 #include<iostream>
2 #include"ROL_StdVector.hpp"
4 #include"Lagrange.hpp"
5 #include"LinearAlgebra.hpp"
6 
7 #ifndef __NODAL_BASIS__
8 #define __NODAL_BASIS__
9 
10 
11 template<class Real>
12 struct NodalBasis{
13 
15  ROL::Ptr<Teuchos::LAPACK<int,Real> > lapack_;
16 
18  const int ni_;
19 
21  const int nq_;
22 
23  NodalBasis(ROL::Ptr<Teuchos::LAPACK<int,Real> > lapack, const int ni, const int nq);
24  ~NodalBasis();
25 
27  std::vector<Real> xi_;
28 
30  std::vector<Real> xq_;
31 
33  std::vector<Real> wq_;
34 
36  std::vector<Real> L_;
37  std::vector<Real> Lp_;
38 
40  ROL::Ptr<Lagrange<Real> > lagrange_;
41 
42 
43 };
44 
47 template<class Real>
48 NodalBasis<Real>::NodalBasis(ROL::Ptr<Teuchos::LAPACK<int,Real> > const lapack, const int ni, const int nq):
49  lapack_(lapack), ni_(ni), nq_(nq), xi_(ni_,0), xq_(nq_,0), wq_(nq_,0), L_(ni_*nq_,0), Lp_(ni_*nq_,0)
50  {
51 
52  // Generate Legendre-Gauss-Lobatto nodes and weights (unused)
53  std::vector<Real> ai(ni_,0);
54  std::vector<Real> bi(ni_,0);
55  std::vector<Real> wi(ni_,0);
56  rec_jacobi(this->lapack_,0,0,ai,bi);
57  rec_lobatto(this->lapack_,-1.0,1.0,ai,bi);
58  gauss(this->lapack_,ai,bi,xi_,wi);
59 
60  // Generate Legendre-Gauss nodes and weights
61  std::vector<Real> aq(nq_,0);
62  std::vector<Real> bq(nq_,0);
63  rec_jacobi(this->lapack_,0,0,aq,bq);
64  gauss(this->lapack_,aq,bq,xq_,wq_);
65 
66  std::vector<Real> e(ni_,0);
67  std::vector<Real> ell(nq,0);
68 
69  lagrange_ = ROL::makePtr<Lagrange<Real>>(xi_,xq_);
70 
71  // Loop over canonical vectors
72  for(int i=0;i<ni_;++i) {
73 
74  lagrange_->interpolant(i,ell);
75 
76  std::copy(ell.begin(),ell.end(),L_.begin()+i*nq_);
77 
78 
79  lagrange_->derivative(i,ell);
80  std::copy(ell.begin(),ell.end(),Lp_.begin()+i*nq_);
81 
82  // Rezero the vector
83  std::fill(e.begin(),e.end(),0);
84  }
85 
86 }
87 
88 template<class Real>
90 }
91 
92 #endif
std::vector< Real > Lp_
Definition: NodalBasis.hpp:37
void rec_lobatto(ROL::Ptr< Teuchos::LAPACK< int, Real > > const lapack, const double xl1, const double xl2, std::vector< Real > &a, std::vector< Real > &b)
Modify the given recurrence coefficients so that the set of zeros of the maximal order polynomial inc...
ROL::Ptr< Teuchos::LAPACK< int, Real > > lapack_
Definition: NodalBasis.hpp:15
NodalBasis(ROL::Ptr< Teuchos::LAPACK< int, Real > > lapack, const int ni, const int nq)
Set up quantities we will need repeatedly.
Definition: NodalBasis.hpp:48
const int ni_
Definition: NodalBasis.hpp:18
const int nq_
Definition: NodalBasis.hpp:21
std::vector< Real > xi_
Definition: NodalBasis.hpp:27
ROL::Ptr< Lagrange< Real > > lagrange_
Object for working with Lagrange polynomials and their derivatives.
Definition: NodalBasis.hpp:40
void gauss(ROL::Ptr< Teuchos::LAPACK< int, Real > > lapack, const std::vector< Real > &a, const std::vector< Real > &b, std::vector< Real > &x, std::vector< Real > &w)
Compute the Gauss quadrature nodes and weights for the polynomials generated by the recurrence coeffi...
std::vector< Real > xq_
Definition: NodalBasis.hpp:30
std::vector< Real > L_
Definition: NodalBasis.hpp:36
void rec_jacobi(ROL::Ptr< Teuchos::LAPACK< int, Real > > lapack, const double alpha, const double beta, std::vector< Real > &a, std::vector< Real > &b)
Generate the Jacobi polynomial recursion coeffcients .
std::vector< Real > wq_
Definition: NodalBasis.hpp:33