Documentation of CSL
libdiagonalization.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 #include <iostream>
27 #include <vector>
28 #include <complex>
29 #include <gsl/gsl_matrix.h>
30 #include <gsl/gsl_vector.h>
31 #ifdef QUAD
32 #include <quadmath.h>
33 #endif
34 
35 class Diagonalizer {
36 
37 public:
38 
39 #ifdef QUAD
40  using real = __float128;
41  using complex = __complex128;
42 #else
43  using real = double;
44  using complex = std::complex<real>;
45 #endif
46 
47  static real precision;
48 
49  static void applyDiagonalization(
50  std::initializer_list<complex> massMatrix,
51  std::initializer_list<complex*> transfer,
52  std::initializer_list<real*> masses
53  );
54 
55  static void applyBiDiagonalization(
56  std::initializer_list<complex> massMatrix,
57  std::initializer_list<complex*> transfer,
58  std::initializer_list<complex*> transfer2,
59  std::initializer_list<real*> masses
60  );
61 
63  std::initializer_list<complex> massMatrix,
64  bool biDiag = false
65  );
66 
67  ~Diagonalizer() = default;
68 
69  std::vector<complex> const &transfer();
70 
71  std::vector<complex> const &transfer2();
72 
73  std::vector<real> const &mass();
74 
75 private:
76 
77  void updateDiagonalization();
78 
79  void diagonalize(
80  std::vector<complex> massMatrix,
81  std::vector<complex> &transfer,
82  std::vector<real> &mass,
83  bool bidiagonalization = false
84  );
85 
86  void swap(
87  const size_t i,
88  const size_t j,
89  std::vector<complex> &transfer,
90  std::vector<real> &mass
91  );
92 
93  void sort(
94  std::vector<complex> &transfer,
95  std::vector<real> &mass
96  );
97 
98  void sort(
99  std::vector<complex> &transfer,
100  std::vector<complex> &transfer2,
101  std::vector<real> &mass
102  );
103 
104  void diagonalize();
105 
106  void bidiagonalize();
107 
108  inline
109  size_t index(
110  const size_t i,
111  const size_t j
112  ) const
113  {
114  return i * m_N + j;
115  }
116 
117  gsl_matrix_complex *getGSLMassMatrix(
118  std::vector<complex> const &massMatrix
119  ) const;
120 
121  void loadGSLMatrix(
122  gsl_matrix_complex const *matrix,
123  std::vector<complex> &target
124  );
125 
126  void loadGSLVector(
127  gsl_vector const *vect,
128  std::vector<real> &target
129  );
130 
131  void positiveDiagonal(
132  std::vector<complex> &transfer
133  );
134 
135  std::vector<complex> hermitian(
136  std::vector<complex> const &init
137  ) const;
138 
139  std::vector<complex> dot(
140  std::vector<complex> const &A,
141  std::vector<complex> const &B
142  ) const;
143 
144  template<class T>
145  void print(std::vector<T> const &v) const
146  {
147  std::cout << "( ";
148  for (const auto &e : v)
149  std::cout << (double)crealq(e) << " ";
150  std::cout << " )" << std::endl;
151  }
152 
153 private:
154 
155  std::vector<complex> m_data;
156  size_t m_N;
157  bool m_bidiag;
158  bool m_computed;
159 
160  std::vector<complex> m_transfer;
161  std::vector<complex> m_transfer2;
162  std::vector<real> m_mass;
163 };
164 
165 #endif
Definition: libdiagonalization.h:35