Majoranapp
A C++ library for studying MZM in non-interacting systems
Solver.hpp
Go to the documentation of this file.
1 #ifndef SOLVER_HPP
2 #define SOLVER_HPP
3 
4 #include <string>
5 #include "Hamiltonian.hpp"
6 #include "VectorViewer.hpp"
7 
11 class Solver
12 {
13 public:
14  //solver options
15 
19  static double tol;
23  static size_t noe;
24 
28  static size_t nov;
32  static std::string target;
33 
37  static bool showEigenvalues;
38 
42  static bool showEigenvectors;
43 
51  template <class T>
52  static void Diagonalize(Hamiltonian<T> &ham)
53  {
54  Info::LogBegining("Solving eigen-equation...");
55  size_t size = ham.elements.n_cols;
56  T &M = ham.elements;
57  T ATA = -(M - M.t()) * (M - M.t());
58 
59  arma::vec eigval;
60  arma::mat eigvec;
61 
62  if constexpr (std::is_same<T, arma::mat>::value)
63  arma::eig_sym(eigval, eigvec, ATA);
64 
65  if constexpr (std::is_same<T, arma::sp_mat>::value)
66  {
67  int k = (size < noe) ? size - 1 : noe;
68  arma::eigs_sym(eigval, eigvec, ATA, k, target.c_str(), tol);
69  }
70 
72 
73  if (showEigenvalues)
74  eigval.print("# === λ ===");
75  if (showEigenvectors)
76  {
77  //arma::mat vectors = join_horiz(eigvec.col(0),eigvec.col(1));
78  arma::mat vectors = eigvec.cols(0, nov < size ? nov - 1 : size - 1);
79  VectorViewer::View(vectors, ham.deg);
80  }
81  }
82 };
83 
84 double Solver::tol = 0.0;
85 size_t Solver::noe = 10;
86 size_t Solver::nov = 2;
87 std::string Solver::target = "sa";
88 bool Solver::showEigenvalues = true;
89 bool Solver::showEigenvectors = false;
90 
91 #endif
static bool showEigenvalues
show eigenvalues (flag)
Definition: Solver.hpp:37
Hamiltonian class for counting MZM in non-interacting systems.
Definition: Hamiltonian.hpp:13
static size_t nov
number of eigenvectors
Definition: Solver.hpp:28
int deg
number degree of freedom deg = 2 spinless systems deg = 4 spinfull systems (1/2 spin) ...
Definition: Hamiltonian.hpp:24
static size_t noe
number of eigenvalues
Definition: Solver.hpp:23
static bool showEigenvectors
show eigenvectors (flag)
Definition: Solver.hpp:42
static void LogAccomplished(std::string text="... done")
LogComment with green color.
Definition: Basics.hpp:91
static double tol
tolerance for arma::eigs_sym procedure
Definition: Solver.hpp:19
static solver
Definition: Solver.hpp:11
T elements
matrix element container
Definition: Hamiltonian.hpp:34
static void Diagonalize(Hamiltonian< T > &ham)
procedure for solving: -(M-M^T).(M-M^T)
Definition: Solver.hpp:52
static ViewerFunction View
Definition: VectorViewer.hpp:22
static void LogBegining(std::string text)
LogComment with red color.
Definition: Basics.hpp:81
static std::string target
target part of the spectrum
Definition: Solver.hpp:32