Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
MatrixCompanion.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_MatrixCompanion_h_
9#define model_MatrixCompanion_h_
10
11#include <Eigen/Dense>
12#include <assert.h>
13#include <cfloat>
14
15
16namespace model
17{
18
19
20 template <int pOrder>
22 {
25 enum{Ncoeff=pOrder+1};
26 typedef Eigen::Matrix<double,1,Ncoeff> VectorNcoeff;
27 typedef Eigen::Matrix<double,pOrder,pOrder> MatrixPorder;
28 typedef Eigen::EigenSolver<Eigen::MatrixXd> EigenSolverType;
29
30 public:
31
32 const VectorNcoeff coeffs;
33 const Eigen::MatrixXd cM; // the matrix companion
34 const EigenSolverType es;
35 const size_t rootSize;
36
37 /**********************************************************************/
38 MatrixCompanion(const VectorNcoeff& coeffsIN) :
39 /* init list */ coeffs(coeffsIN),
40 /* init list */ cM(getCM(coeffsIN)),
41 /* init list */ es(cM),
42 /* init list */ rootSize(cM.rows())
43 {
49 }
50
51 /**********************************************************************/
52 typename EigenSolverType::ComplexScalar root(const int& i) const
53 {
56 return es.eigenvalues()(i);
57 }
58
59
60 /**********************************************************************/
61 static Eigen::MatrixXd getCM(const VectorNcoeff& coeffsIN)
62 {
63
64 //assert(std::fabs(coeffsIN(0))>FLT_EPSILON && "COEFFICIENT OF HIGHEST DEGREE CANNOT BE 0");
65
66 Eigen::MatrixXd temp;
67
68 if ( std::fabs(coeffsIN(0))>FLT_EPSILON)
69 {
70 temp=MatrixPorder::Zero();
71 temp.row(0)=coeffsIN.template segment<pOrder>(1)/(-coeffsIN(0));
72 temp.template block<pOrder-1,pOrder-1>(1,0).setIdentity();
73 }
74 else
75 {
76 temp=MatrixCompanion<pOrder-1>::getCM(coeffsIN.template segment<pOrder>(1));
77 }
78
79 return temp;
80 }
81
82 };
83
84 /**********************************************************************/
85 /**********************************************************************/
86 template <>
88 {
89 enum{pOrder=1};
90 enum{Ncoeff=pOrder+1};
91 typedef Eigen::Matrix<double,1,Ncoeff> VectorNcoeff;
92 typedef Eigen::Matrix<double,pOrder,pOrder> MatrixPorder;
93 typedef Eigen::EigenSolver<Eigen::MatrixXd> EigenSolverType;
94
95
96
97 public:
98
99 const VectorNcoeff coeffs;
100 const Eigen::MatrixXd cM; // the matrix companion
101 const EigenSolverType es;
102 const size_t rootSize;
103
104
105 MatrixCompanion(const VectorNcoeff& coeffsIN) :
106 /* init list */ coeffs(coeffsIN),
107 /* init list */ cM(getCM(coeffsIN)),
108 /* init list */ es(cM),
109 /* init list */ rootSize(cM.rows())
110 {
111
112 }
113
114 /**********************************************************************/
115 typename EigenSolverType::ComplexScalar root(const int& i) const
116 {
117 return es.eigenvalues()(i);
118 }
119
120 /**********************************************************************/
121 static MatrixPorder getCM(const VectorNcoeff& coeffsIN)
122 {
123 assert(std::fabs(coeffsIN(0))>FLT_EPSILON && "COEFFICIENT OF HIGHEST DEGREE CANNOT BE 0");
124 MatrixPorder temp(MatrixPorder::Zero());
125 temp.row(0)=coeffsIN.segment<pOrder>(1)/(-coeffsIN(0));
126 return temp;
127 }
128
129 };
130
131
132} // close namespace model
133#endif
EigenSolverType::ComplexScalar root(const int &i) const
static MatrixPorder getCM(const VectorNcoeff &coeffsIN)
const EigenSolverType es
const Eigen::MatrixXd cM
MatrixCompanion(const VectorNcoeff &coeffsIN)
const Eigen::MatrixXd cM
MatrixCompanion(const VectorNcoeff &coeffsIN)
const EigenSolverType es
const VectorNcoeff coeffs
static Eigen::MatrixXd getCM(const VectorNcoeff &coeffsIN)
EigenSolverType::ComplexScalar root(const int &i) const
int i
vertex temp