Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
QuadratureRecursiveRelation.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_QUADRATURERECURSIVERELATION_H_
9#define model_QUADRATURERECURSIVERELATION_H_
10
11#include <iostream>
12#include <iomanip>
13#include <assert.h>
14#include <math.h>
15#include <set>
16#include <utility>
17#include <Eigen/Dense>
18#include <Eigen/Eigenvalues>
19
20
21namespace model
22{
23
43 {
44
45 enum {dim=1};
46
47 /* abcsissasAndWeights *******************************/
48 template<typename PolynomialType>
49 static Eigen::MatrixXd abcsissasAndWeights(const int& qOrder)
50 {
51 std::cout<<"computing qOrder="<<qOrder<<"..."<<std::flush;
52
53 // Create and fill the Jacobi upper triangular matrix
54 Eigen::MatrixXd jUT = Eigen::MatrixXd::Zero(qOrder,qOrder);
55 for (int n=0;n<qOrder;++n)
56 {
57 int k = n+1;
58 jUT(n,n) = -PolynomialType::b(k)/PolynomialType::a(k);
59 if (n<qOrder-1)
60 {
61 jUT(n,n+1)= std::sqrt(PolynomialType::c(k+1)/PolynomialType::a(k)/PolynomialType::a(k+1));
62 }
63 }
64
65 // Create a SelfAdjointEigenSolver from the self-adjoint part of jUT
66 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> es(jUT.template selfadjointView<Eigen::Upper>());
67 Eigen::VectorXd eigenVal = es.eigenvalues();
68 Eigen::MatrixXd eigenVec = es.eigenvectors();
69
70 // Insert each abscissa-weight pair in std::set for automatic sorting with increasing abscissas
71 typedef std::set<std::pair<double,double> > EigenSetType;
72 typedef EigenSetType::const_iterator EigenSetIterType;
73 EigenSetType eigenSet;
74 for (int k=0;k<qOrder;++k)
75 {
76 eigenSet.insert( std::make_pair( (eigenVal(k)+1.0)*0.5, std::pow(eigenVec(0,k),2) ) );
77 }
78
79 // Copy the sorted values to abscissas_ and weigts_
80 Eigen::MatrixXd abcsissasAndWeights_(Eigen::MatrixXd::Zero(dim+1,qOrder));
81 int k=0;
82 for (EigenSetIterType iter=eigenSet.begin(); iter!=eigenSet.end();++iter)
83 {
84 abcsissasAndWeights_(0,k)= iter->first;
85 abcsissasAndWeights_(1,k)= iter->second;
86 ++k;
87 }
88
89 std::cout<<" done."<<std::endl;
90
91
92 return abcsissasAndWeights_;
93 }
94
95 };
96
97} // namespace model
98#endif
99
A static class template for generating quadrature abcsissas and weights for arbitrary-order and rule ...
static Eigen::MatrixXd abcsissasAndWeights(const int &qOrder)
int k