TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
tb_hk.hpp
1#pragma once
2
3#include "./fourier_polynomial.hpp"
4#include "./superlattice.hpp"
6
7#include <h5/h5.hpp>
8#include <itertools/itertools.hpp>
9#include <mpi/mpi.hpp>
10#include <nda/h5.hpp>
11#include <nda/mpi.hpp>
12#include <nda/nda.hpp>
13
14#include <algorithm>
15#include <array>
16#include <ostream>
17#include <ranges>
18#include <string>
19#include <utility>
20#include <vector>
21
22namespace triqs::experimental::lattice {
23
28
40 class tb_hk : public fourier_polynomial<2, 3> {
41
42 static constexpr auto r_all = nda::range::all;
43
44 void check_hoppings();
45
46 public:
48 using eigenvectors_t = std::pair<nda::array<double, 2>, nda::array<dcomplex, 3>>;
49
56 tb_hk(std::vector<std::array<long, 3>> Rs, std::vector<nda::array<dcomplex, 2>> hoppings)
57 : fourier_polynomial<2, 3>(std::move(Rs), std::move(hoppings)) {
58
59 check_hoppings();
60 };
61
63 tb_hk() : fourier_polynomial<2, 3>({{{0, 0, 0}}}, std::vector(1, nda::array<dcomplex, 2>({{dcomplex(0.)}}))) {};
64
69 C2PY_IGNORE tb_hk(fourier_polynomial<2, 3> fp) : fourier_polynomial<2, 3>{std::move(fp)} {}
70
71 // ------------------------ Accessors ----------------------------
72
77 [[nodiscard]] auto hoppings() {
78 return std::views::iota(0L, n_R()) | std::views::transform([this](long i) { return coeff_arr(i, nda::ellipsis{}); });
79 }
80
85 [[nodiscard]] auto hoppings() const {
86 return std::views::iota(0L, n_R()) | std::views::transform([this](long i) { return coeff_arr(i, nda::ellipsis{}); });
87 }
88
93 // Intentionally hides the C2PY_IGNORE base accessor to return the list by value, which is what gets wrapped to Python.
94 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
95 [[nodiscard]] std::vector<std::array<long, 3>> get_R_list() const { return fourier_polynomial<2, 3>::get_R_list(); }
96
102 [[nodiscard]] auto elements() { return std::views::zip(get_R_list(), hoppings()); }
103
109 [[nodiscard]] auto elements() const { return std::views::zip(get_R_list(), hoppings()); }
110
115 [[nodiscard]] long n_orbitals() const { return coeff_arr.shape(1); }
116
117 //------------------- band basis energy functions ---------------------------
118
136 nda::array<double, 2> eigenvalues(nda::array_view<double, 2> k) const;
137
156 eigenvectors_t eigenvectors(nda::array_view<double, 2> k) const;
157
158 // ------------------- Comparison -------------------
159
169 bool operator==(tb_hk const &tb) const {
170 return std::ranges::equal(this->get_R_list(), tb.get_R_list()) && this->get_coeff_arr() == tb.get_coeff_arr();
171 }
172
173 // ------------------- Read / Write -------------------------------
174
185 friend std::ostream &operator<<(std::ostream &out, tb_hk const &tb) {
186 out << "tb_hk consisting of " << tb.n_R() << " lattice components (R)";
187 out << " with hopping dimension (n_orbitals) " << tb.n_orbitals() << "x" << tb.n_orbitals();
188 // if it's a small one, we can print it:
189 if (tb.n_R() < 12) {
190 out << "\n[";
191 for (auto const &[R, C] : tb.elements()) out << "\n " << R << " : " << C;
192 out << " ]";
193 }
194 return out;
195 }
196
202 [[nodiscard]] inline static std::string hdf5_format() { return "tb_hk"; }
203
211 friend void h5_write(h5::group g, std::string const &name, tb_hk const &tb) { tb.h5_write_impl(g, name, "tb_hk"); }
212
220 friend void h5_read(h5::group g, std::string const &name, tb_hk &tb) { tb.h5_read_impl(g, name, "tb_hk"); }
221 };
222
230 inline tb_hk fold(superlattice const &sl, tb_hk const &tb) { return fold(sl, static_cast<fourier_polynomial<2, 3> const &>(tb)); }
231
233
234} // namespace triqs::experimental::lattice
Owning container for a Fourier-series representation of a lattice function.
void h5_write_impl(h5::group g, std::string const &name, char const *format) const
HDF5 write helper for derived classes: writes R_list and coeff_arr under the given format tag.
auto const & get_R_list() const
Get the list of real-space lattice vectors.
void h5_read_impl(h5::group g, std::string const &name, char const *exp_format)
HDF5 read helper for derived classes: reads R_list and coeff_arr in place; rebuilds R_mat.
Representation of a superlattice built on top of an underlying Bravais lattice.
Tight-binding Hamiltonian on a 3D lattice.
Definition tb_hk.hpp:40
tb_hk(fourier_polynomial< 2, 3 > fp)
Construct a tight-binding Hamiltonian from an existing matrix-valued Fourier polynomial.
Definition tb_hk.hpp:69
auto hoppings() const
Get a lazy range over the hopping matrices, one per R-vector (const overload).
Definition tb_hk.hpp:85
friend void h5_write(h5::group g, std::string const &name, tb_hk const &tb)
Write a tight-binding Hamiltonian to HDF5.
Definition tb_hk.hpp:211
auto hoppings()
Get a lazy range over the hopping matrices, one per R-vector.
Definition tb_hk.hpp:77
friend void h5_read(h5::group g, std::string const &name, tb_hk &tb)
Read a tight-binding Hamiltonian from HDF5.
Definition tb_hk.hpp:220
static std::string hdf5_format()
Get the HDF5 format tag.
Definition tb_hk.hpp:202
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
auto elements() const
Get a lazy range over the (R-vector, hopping-matrix) pairs (const overload).
Definition tb_hk.hpp:109
std::pair< nda::array< double, 2 >, nda::array< dcomplex, 3 > > eigenvectors_t
Type used for returning eigenvectors.
Definition tb_hk.hpp:48
bool operator==(tb_hk const &tb) const
Equal-to comparison operator.
Definition tb_hk.hpp:169
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
tb_hk(std::vector< std::array< long, 3 > > Rs, std::vector< nda::array< dcomplex, 2 > > hoppings)
Construct a tight-binding Hamiltonian from lattice vectors and their hopping matrices.
Definition tb_hk.hpp:56
auto elements()
Get a lazy range over the (R-vector, hopping-matrix) pairs.
Definition tb_hk.hpp:102
long n_orbitals() const
Get the number of orbitals, i.e. the dimension of the Hamiltonian matrices.
Definition tb_hk.hpp:115
friend std::ostream & operator<<(std::ostream &out, tb_hk const &tb)
Write a tight-binding Hamiltonian to a std::ostream.
Definition tb_hk.hpp:185
tb_hk()
Default constructor: a single zero hopping matrix for the lattice vector at the origin.
Definition tb_hk.hpp:63
fourier_polynomial< 2, kdim > fold(superlattice const &sl, fourier_polynomial< 2, kdim > const &fp)
Fold a Fourier polynomial defined on a lattice onto a superlattice.
std::complex< double > dcomplex
Convenience alias for std::complex<double>.
Common macros used in TRIQS.