From 3aa380ba9d4deaf1addd69abb4081c5b35e73f5a Mon Sep 17 00:00:00 2001 From: tayral Date: Wed, 7 May 2014 09:49:50 +0100 Subject: [PATCH] Fixed abs bug in bravais_lattice + added method When constructing the last unit vector in 2D, the sanity check was wrong because of usage of abs instead of std::abs. Added method energy_on_bz_path_2 that returns the energy *matrix* at each k point on a given path instead of the eigenvalues of this matrix. The name of the function should be changed (to energy_matrix_on_bz_path?) Renaming energies_on_bz_path_2 to energy_matrix_on_bz_path --- pytriqs/lattice/lattice_tools.pyx | 5 +++++ pytriqs/lattice/tight_binding.py | 4 ++-- test/triqs/gfs/test_gf_triqs.cpp | 1 + .../lattice/bravais_lattice_and_brillouin_zone.cpp | 1 + triqs/lattice/tight_binding.cpp | 13 +++++++++++++ triqs/lattice/tight_binding.hpp | 1 + 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pytriqs/lattice/lattice_tools.pyx b/pytriqs/lattice/lattice_tools.pyx index 530cd298..62e6a31c 100644 --- a/pytriqs/lattice/lattice_tools.pyx +++ b/pytriqs/lattice/lattice_tools.pyx @@ -27,6 +27,7 @@ cdef extern from "triqs/lattice/tight_binding.hpp" namespace "triqs::gf" : pair [array[double,ONE],array[double,TWO]] dos_c "dos" (tight_binding & TB, size_t nkpts, size_t neps) pair [array[double,ONE],array[double,ONE]] dos_patch_c "dos_patch" (tight_binding & TB, array_view[double,TWO] & triangles, size_t neps, size_t ndiv) array_view[double,TWO] energies_on_bz_path_c "energies_on_bz_path" (tight_binding & TB, tqa_vector[double] & K1, tqa_vector[double] & K2, size_t n_pts) + array_view[complex,THREE] energy_matrix_on_bz_path_c "energy_matrix_on_bz_path" (tight_binding & TB, tqa_vector[double] & K1, tqa_vector[double] & K2, size_t n_pts) array_view[double,TWO] energies_on_bz_grid_c "energies_on_bz_grid" (tight_binding & TB, size_t n_pts) cdef class BravaisLattice : @@ -104,6 +105,10 @@ def energies_on_bz_path ( TightBinding TB, K1, K2, n_pts) : """ """ return energies_on_bz_path_c (deref(TB._c), tqa_vector[double](K1), tqa_vector[double] (K2), n_pts).to_python() +def energy_matrix_on_bz_path ( TightBinding TB, K1, K2, n_pts) : + """ """ + return energy_matrix_on_bz_path_c (deref(TB._c), tqa_vector[double](K1), tqa_vector[double] (K2), n_pts).to_python() + def energies_on_bz_grid ( TightBinding TB, n_pts) : """ """ return energies_on_bz_grid_c (deref(TB._c), n_pts).to_python() diff --git a/pytriqs/lattice/tight_binding.py b/pytriqs/lattice/tight_binding.py index c441088e..06e02a26 100644 --- a/pytriqs/lattice/tight_binding.py +++ b/pytriqs/lattice/tight_binding.py @@ -20,14 +20,14 @@ # ################################################################################ -__all__ = ['BravaisLattice', 'TightBinding', 'dos', 'dos_patch', 'energies_on_bz_grid', 'energies_on_bz_path', +__all__ = ['BravaisLattice', 'TightBinding', 'dos', 'dos_patch', 'energies_on_bz_grid', 'energies_on_bz_path', 'energy_matrix_on_bz_path', 'hopping_stack', 'TBLattice'] from lattice_tools import BravaisLattice as BravaisLattice from lattice_tools import TightBinding as TightBinding from lattice_tools import dos_patch as dos_patch_c from lattice_tools import dos as dos_c -from lattice_tools import energies_on_bz_grid, energies_on_bz_path, hopping_stack +from lattice_tools import energies_on_bz_grid, energies_on_bz_path, hopping_stack, energy_matrix_on_bz_path from pytriqs.dos import DOS import numpy diff --git a/test/triqs/gfs/test_gf_triqs.cpp b/test/triqs/gfs/test_gf_triqs.cpp index 5e57b1f6..ef6b9e05 100644 --- a/test/triqs/gfs/test_gf_triqs.cpp +++ b/test/triqs/gfs/test_gf_triqs.cpp @@ -5,6 +5,7 @@ using namespace triqs::arrays; #define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) < #include +#include #define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) < const & gt){ diff --git a/triqs/lattice/bravais_lattice_and_brillouin_zone.cpp b/triqs/lattice/bravais_lattice_and_brillouin_zone.cpp index fb9a4942..ffb50fae 100644 --- a/triqs/lattice/bravais_lattice_and_brillouin_zone.cpp +++ b/triqs/lattice/bravais_lattice_and_brillouin_zone.cpp @@ -64,6 +64,7 @@ namespace lattice { uy(2) = 1; uy = cross_product(units_(0, _), units_(1, _)); delta = sqrt(dot(uy, uy)); + using std::abs; if (abs(delta) < almost_zero) TRIQS_RUNTIME_ERROR << "Bravais Lattice : the 2 vectors of unit are not independent : " << units__; units_(2, _) = uy / delta; break; diff --git a/triqs/lattice/tight_binding.cpp b/triqs/lattice/tight_binding.cpp index 2e7c8f43..5187529d 100644 --- a/triqs/lattice/tight_binding.cpp +++ b/triqs/lattice/tight_binding.cpp @@ -64,6 +64,19 @@ namespace lattice { return eval; } + //------------------------------------------------------ + array energy_matrix_on_bz_path(tight_binding const& TB, k_t const& K1, k_t const& K2, int n_pts) { + auto TK = fourier(TB); + int norb = TB.lattice().n_orbitals(); + int ndim = TB.lattice().dim(); + array eval(norb,norb,n_pts); + k_t dk = (K2 - K1) / double(n_pts), k = K1; + for (int i = 0; i < n_pts; ++i, k += dk) { + eval(range(),range(),i) = TK(k(range(0, ndim)))(); + } + return eval; + } + //------------------------------------------------------ array energies_on_bz_grid(tight_binding const& TB, int n_pts) { diff --git a/triqs/lattice/tight_binding.hpp b/triqs/lattice/tight_binding.hpp index 2f618bff..f200da24 100644 --- a/triqs/lattice/tight_binding.hpp +++ b/triqs/lattice/tight_binding.hpp @@ -93,6 +93,7 @@ namespace lattice { std::pair, array> dos_patch(tight_binding const& TB, const array& triangles, int neps, int ndiv); array energies_on_bz_path(tight_binding const& TB, k_t const& K1, k_t const& K2, int n_pts); + array energy_matrix_on_bz_path(tight_binding const& TB, k_t const& K1, k_t const& K2, int n_pts); array energies_on_bz_grid(tight_binding const& TB, int n_pts); } }