Documentation of CSL
diagonalization.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #ifndef DIAGONALIZATION_H_INCLUDED
24 #define DIAGONALIZATION_H_INCLUDED
25 
26 #ifndef COMPILE_32_BITS
27 #include <gsl/gsl_complex.h>
28 #include <gsl/gsl_matrix.h>
29 #endif
30 #include "vector.h"
31 
32 namespace std {
33  template<class T>
34  class shared_ptr;
35 }
36 namespace csl {
37 
38 class Diagonalizer {
39 
40  public:
41 
42  explicit
44  const Matrix& matrix,
45  bool forceDeterminantZero = false
46  );
47 
48  explicit
50  const Expr& matrix,
51  bool forceDeterminantZero = false
52  );
53 
54  Diagonalizer(const Diagonalizer& other) = default;
55 
56  Diagonalizer& operator=(const Diagonalizer& other) = default;
57 
58  void diagonalize();
59 
60  csl::vector_expr getEigenValues();
61 
62  Expr getDiagonal();
63 
64  Expr getTransform();
65 
66  Expr getInvTransform();
67 
68  private:
69 
70  void checkSquareHermitian();
71 
72  void checkSpecialCases();
73 
74  void diagonalizeNonHermitic();
75 
76  void diagonalize_1x1();
77 
78  void diagonalize_2x2();
79 
80  void diagonalize_3x3();
81 
82  static
83  double extractNumber(const Expr& number);
84 
85 #ifndef COMPILE_32_BITS
86  static
87  gsl_complex csl_to_gsl(const Expr& csl_expr);
88 
89  static
90  gsl_matrix_complex* csl_to_gsl(const Matrix& csl_matrix);
91 
92  static
93  Expr gsl_to_csl(gsl_complex gsl_expr);
94 
95  static
96  Matrix gsl_to_csl(gsl_matrix_complex* gsl_matrix);
97 
98  static
99  Matrix diagFromEigenValues(gsl_vector* eigenValues);
100 #endif
101 
102  private:
103 
104  bool diagonalized = false;
105 
106  bool symbolic = false;
107 
108  bool forceDeterminantZero = false;
109 
110  Matrix init_matrix;
111 
112  Matrix D;
113 
114  Matrix U;
115 
116  Matrix U_inv;
117 };
118 
119 
120 } // End of namespace csl
121 
122 
123 #endif
124 
Namespace for csl library.
Definition: abreviation.h:34
Definition: diagonalization.h:32
Definition: diagonalization.h:34
Definition: diagonalization.h:38
Objects handling vectors, matrices and higher-dimensional tensors.
Definition: vector.h:227
Expression type/.
Definition: abstract.h:1573