TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
tb_hk.cpp
1#include "./tb_hk.hpp"
3
4#include <nda/nda.hpp>
5
6#include <utility>
7
8namespace triqs::experimental::lattice {
9
10 void tb_hk::check_hoppings() {
11
12 // checking displacements and hopping matrices
13 if (n_R() != hoppings().size()) TRIQS_RUNTIME_ERROR << " Number of Rs != Number of hoppings";
14 for (int i = 0; i < n_R(); ++i) {
15 if (first_dim(hoppings()[i]) != n_orbitals())
16 TRIQS_RUNTIME_ERROR << "hopping dimension 1 inconsistent with n_orbitals, for R number " << i << " " << first_dim(hoppings()[i])
17 << " instead of " << n_orbitals();
18 if (second_dim(hoppings()[i]) != n_orbitals())
19 TRIQS_RUNTIME_ERROR << "the second dim matrix is of size " << second_dim(hoppings()[i]) << " instead of " << n_orbitals();
20
21 // check hermiticity of hoppings: Hij(+R)= Hji(-R)* by looping of all displacements again
22 bool found = false;
23 for (int j = 0; j < n_R(); ++j) {
24 if (get_R_list()[i] == -get_R_list()[j]) {
25 found = true;
26 if (max_element(abs(hoppings()[i] - dagger(hoppings()[j]))) > 1.e-12)
27 TRIQS_RUNTIME_ERROR << "For displacement " << get_R_list()[i] << " hopping matrix " << hoppings()[i]
28 << "\nis not the hermitian conjugate of matrix for displacement " << get_R_list()[j] << hoppings()[j] << "\n";
29 break;
30 }
31 }
32 if (not found) TRIQS_RUNTIME_ERROR << "opposite hopping vector of " << get_R_list()[i] << " cannot be found";
33 }
34 }
35
36 nda::array<double, 2> tb_hk::eigenvalues(nda::array_view<double, 2> k) const {
37 // energies in the shape of nk, nbands
38 long nk = k.shape()[0];
39 auto energies = nda::matrix<double>(nk, n_orbitals());
40 // use blas call for FT on a block of kpoints
41 auto Ek_orbital = nda::array<dcomplex, 3>{this->operator()(k)};
42 for (auto ik : nda::range(nk)) { energies(ik, r_all) = nda::linalg::eigvalsh(Ek_orbital(ik, nda::ellipsis())); }
43 return energies;
44 }
45
46 std::pair<nda::array<double, 2>, nda::array<dcomplex, 3>> tb_hk::eigenvectors(nda::array_view<double, 2> k) const {
47 // energies in the shape of nk, nbands
48 long nk = k.shape()[0];
49 auto energies = nda::matrix<double>(nk, n_orbitals());
50 auto eigenvectors = nda::array<dcomplex, 3>(nk, n_orbitals(), n_orbitals());
51 // use blas call for FT on a block of kpoints
52
53 auto Ek_orbital = nda::array<dcomplex, 3>{this->operator()(k)};
54 for (auto ik : nda::range(nk)) {
55 auto [en, eigvec] = nda::linalg::eigh(Ek_orbital(ik, nda::ellipsis()));
56 energies(ik, r_all) = en;
57 eigenvectors(ik, r_all, r_all) = eigvec;
58 }
59 return {energies, eigenvectors};
60 }
61
62}; // namespace triqs::experimental::lattice
const_view_type operator()() const
Make a const view of *this.
int size() const
Get the total number of blocks.
auto hoppings()
Get a lazy range over the hopping matrices, one per R-vector.
Definition tb_hk.hpp:77
std::vector< std::array< long, 3 > > get_R_list() const
Get the list of real-space lattice vectors.
Definition tb_hk.hpp:95
eigenvectors_t eigenvectors(nda::array_view< double, 2 > k) const
Compute the band-basis energies and eigenvectors of for a list of k-points.
Definition tb_hk.cpp:46
nda::array< double, 2 > eigenvalues(nda::array_view< double, 2 > k) const
Compute the band-basis energies of for a list of k-points.
Definition tb_hk.cpp:36
long n_orbitals() const
Get the number of orbitals, i.e. the dimension of the Hamiltonian matrices.
Definition tb_hk.hpp:115
TRIQS exception hierarchy and related macros.
#define TRIQS_RUNTIME_ERROR
Throw a triqs::runtime_error with the current source location.