TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
gloc.hpp
1#pragma once
2
3#include "./bz_integrators.hpp"
4#include "./tb_hk.hpp"
5#include "../utility/root_finder.hpp"
6#include "../../gfs.hpp"
8
9#include <itertools/omp_chunk.hpp>
10#include <nda/nda.hpp>
11
12#include <functional>
13#include <stdexcept>
14#include <string>
15#include <utility>
16
17namespace triqs::experimental::lattice {
18
23
37 template <typename Mesh> gfs::gf<Mesh, gfs::matrix_valued> gloc(Mesh const &w_mesh, tb_hk const &H_k, double mu, bz_int_options const &opt) {
38
39 auto I = nda::eye<dcomplex>(H_k.n_orbitals());
40 namespace ph = placeholders;
41 auto expr_kw = nda::linalg::inv((ph::w + mu) * I - nda::clef::make_expr(H_k)(ph::kx, ph::ky, ph::kz));
42 // call the integration for this block
43 return integrate_bz(expr_kw, w_mesh, opt);
44 }
45
60 template <typename Mesh>
62
63 int n_orbitals = Sigma.target_shape()[0];
64 auto I = nda::eye<dcomplex>(n_orbitals);
65 if (n_orbitals != H_k.n_orbitals()) {
66 throw std::runtime_error("Number of orbitals in Hk " + std::to_string(H_k.n_orbitals()) + " not matched to shape of self energy "
67 + std::to_string(n_orbitals));
68 }
69 namespace ph = placeholders;
70 auto expr_kw =
71 nda::linalg::inv((ph::w + mu) * I - nda::clef::make_expr(H_k)(ph::kx, ph::ky, ph::kz) - nda::clef::make_expr(std::move(Sigma))[ph::w]);
72 // call the integration for this block
73 return integrate_bz(expr_kw, Sigma.mesh(), opt);
74 }
75
89 template <typename Mesh>
91 bz_int_options const &opt) {
92
93 auto Gloc_result = gfs::block_gf<Mesh>(Sigma[0].mesh(), Sigma.gf_struct());
94 for (auto block : range(Sigma.size())) { Gloc_result[block] = gloc(H_k, mu, Sigma[block], opt); }
95 return Gloc_result;
96 }
97
114 template <typename Mesh>
115 double find_chemical_potential(double const target_density, tb_hk const &H_k, gfs::block_gf<Mesh, gfs::matrix_valued> const &Sigma,
116 bz_int_options const &opt, std::string method = "dichotomy", double precision = 1.e-5, bool verbosity = false) {
117
118 // density for a block GF
119 std::function<double(double)> f = [&H_k, &Sigma, &opt](double mu) {
120 double n = 0;
121 for (auto block : range(Sigma.size())) {
122 auto Gloc = gloc(H_k, mu, Sigma[block], opt);
123 n += real(nda::trace(density(Gloc)));
124 }
125 return n;
126 };
127 return std::get<0>(utility::root_finder(method, f, 0.0, target_density, precision, 0.5, 1000, "Chemical Potential", "Total Density", verbosity));
128 }
129
146 template <typename Mesh>
147 double find_chemical_potential(double const target_density, tb_hk const &H_k, gfs::gf<Mesh, gfs::matrix_valued> const &Sigma,
148 bz_int_options const &opt, std::string method = "dichotomy", double precision = 1.e-5, bool verbosity = false) {
149
150 std::function<double(double)> f = [&H_k, &Sigma, &opt](double mu) { // density function
151 auto Gloc = gloc(H_k, mu, Sigma, opt);
152 return real(nda::trace(density(Gloc)));
153 };
154 return std::get<0>(utility::root_finder(method, f, 0.0, target_density, precision, 0.5, 1000, "Chemical Potential", "Total Density", verbosity));
155 }
156
158
159} // namespace triqs::experimental::lattice
Tight-binding Hamiltonian on a 3D lattice.
Definition tb_hk.hpp:40
long n_orbitals() const
Get the number of orbitals, i.e. the dimension of the Hamiltonian matrices.
Definition tb_hk.hpp:115
The owning block Green's function container.
Definition block_gf.hpp:259
int size() const
Get the total number of blocks.
Definition block_gf.hpp:109
gf_struct_t gf_struct() const
Get the block structure.
Definition block_gf.hpp:79
The owning Green's function container.
Definition gf.hpp:194
mesh_t const & mesh() const
Get the mesh of the Green's function.
Definition gf.hpp:274
std::array< long, Target::rank > target_shape() const
Get the shape of the target.
Definition gf.hpp:314
Umbrella header for the Green's function library.
double find_chemical_potential(double const target_density, tb_hk const &H_k, gfs::block_gf< Mesh, gfs::matrix_valued > const &Sigma, bz_int_options const &opt, std::string method="dichotomy", double precision=1.e-5, bool verbosity=false)
Find the chemical potential that yields a target density for a block self-energy.
Definition gloc.hpp:115
gfs::gf< Mesh, gfs::matrix_valued > gloc(Mesh const &w_mesh, tb_hk const &H_k, double mu, bz_int_options const &opt)
Compute the non-interacting local Green's function from a tight-binding Hamiltonian on a given mesh.
Definition gloc.hpp:37
gf< Mesh, matrix_valued > integrate_bz(auto const &f_kw, Mesh const &w_mesh, bz_int_options const &opt, mpi::communicator comm={})
Integrate an expression over the Brillouin zone for all frequencies, combining PTR and adaptive integ...
std::pair< double, double > root_finder(std::string method, std::function< double(double)> f, double x_init, double y_value, double precision, double delta_x, long max_loops=1000, std::string x_name="", std::string y_name="", bool verbosity=false)
Find the value that solves using the requested root-finding method.
nda::matrix< dcomplex > density(gf_const_view< mesh::imfreq > g, array_const_view< dcomplex, 3 > known_moments)
Compute the density from a Green's function.
Definition density.cpp:49
G::regular_type::real_t real(G const &g)
Take the real part of a Green's function (no check), returning a new Green's function with a real tar...
string to_string(string const &str)
Identity overload for std::string.
CLEF placeholders for the momentum and frequency arguments of integrable expressions.
Options controlling the combined PTR and adaptive Brillouin-zone integration.
Provides the target types that fix the value stored at each mesh point of a Green's function.