Skip to content

Commit

Permalink
[gf] Rewrite the evaluator of multivariable gf
Browse files Browse the repository at this point in the history
- Use a simpler approach, with a series of little
  template (multivar_eval) which are mako generated.

- Various simplification of one var evaluator as well.

- Clean imfreq evaluator

- Change the call of () of evaluator to & from *
   - Simpler to use a ref.
   - Warning ! The constructor must still take a G *
    otherwise, infinite loop in constructing gf_impl

[gf] Move things around and fix C++11
  • Loading branch information
parcollet committed Dec 15, 2015
1 parent 48fc8af commit 0f59d9e
Show file tree
Hide file tree
Showing 90 changed files with 1,057 additions and 1,032 deletions.
3 changes: 1 addition & 2 deletions doc/reference/gfs/c++/tail_0.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <Python.h>
#include <triqs/gfs.hpp>
#include <iostream>
#include <triqs/gfs/local/tail.hpp>
int main() {
int N1 = 1, N2 = 1;
triqs::gfs::tail t(N1, N2);
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/gfs/c++/tail_1.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <triqs/gfs.hpp>
#include <triqs/gfs/local/fit_tail.hpp>
#include <triqs/gfs/singularity/fit_tail.hpp>
using namespace triqs::gfs;
int main() {
triqs::clef::placeholder<0> iom_;
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/gfs/c++/tail_fit_0.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <triqs/gfs.hpp>
#include <triqs/gfs/local/fit_tail.hpp>
#include <triqs/gfs/singularity/fit_tail.hpp>
using namespace triqs::gfs;
int main() {
triqs::clef::placeholder<0> iom_;
Expand Down
8 changes: 4 additions & 4 deletions pytriqs/gf/local/gf_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

module = module_(full_name = "pytriqs.gf.local.gf", doc = "Local Green functions ...")
module.add_include("<triqs/gfs.hpp>")
module.add_include("<triqs/gfs/local/functions.hpp>")
module.add_include("<triqs/gfs/local/fit_tail.hpp>")
module.add_include("<triqs/gfs/local/pade.hpp>")
module.add_include("<triqs/gfs/local/legendre_matsubara.hpp>")
module.add_include("<triqs/gfs/functions/functions.hpp>")
module.add_include("<triqs/gfs/singularity/fit_tail.hpp>")
module.add_include("<triqs/gfs/transform/pade.hpp>")
module.add_include("<triqs/gfs/legacy_for_python_api.hpp>")
module.add_include("<triqs/python_tools/converters/string.hpp>")
module.add_include("<triqs/python_tools/converters/arrays.hpp>")
module.add_include("<triqs/python_tools/converters/h5.hpp>")
Expand Down
23 changes: 23 additions & 0 deletions run_mako.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from mako.template import Template
import sys

# --- Parsing the arguments of the script and options
import argparse

parser = argparse.ArgumentParser(description="""
Generate the C++ file from the mako/C++ template
""")

parser.add_argument('filename', help = "Name of the file")
parser.add_argument('--outputname', '-o', help="Name of the xxx_desc.py file [default is same as the filename]", default = '')
args = parser.parse_args()

#------------

output = args.outputname or args.filename.replace(r'.mako','')
tpl = Template(filename=args.filename)
rendered = tpl.render().strip()
print rendered
with open(output,'w') as f:
f.write(rendered)

1 change: 0 additions & 1 deletion test/triqs/gfs/fourier1.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/local/fourier_matsubara.hpp>
using namespace triqs::gfs;
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;

Expand Down
3 changes: 0 additions & 3 deletions test/triqs/gfs/g_r_k.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/bz.hpp>
#include <triqs/gfs/cyclic_lattice.hpp>
#include <triqs/gfs/local/fourier_lattice.hpp>

namespace h5 = triqs::h5;
using namespace triqs::gfs;
Expand Down
8 changes: 1 addition & 7 deletions test/triqs/gfs/gf3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ using namespace triqs::gfs;
using namespace triqs::arrays;
namespace h5 = triqs::h5;
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;
#include <triqs/gfs/local/functions.hpp>

// example
//template<typename T> using block_gf = gf<block_index, gf<T>>;
// block_gf<imtime> ...
// but not on gcc 4.6 !
//
#include <triqs/gfs/functions/functions.hpp>

int main() {
try {
Expand Down
4 changes: 1 addition & 3 deletions test/triqs/gfs/gf_mul.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

#include <triqs/gfs/block.hpp>
#include <triqs/gfs/imtime.hpp>
#include <triqs/gfs/imfreq.hpp>
#include <triqs/gfs.hpp>
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;

using namespace triqs::gfs;
Expand Down
2 changes: 1 addition & 1 deletion test/triqs/gfs/gf_notail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace triqs::arrays;
namespace h5 = triqs::h5;

#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> " << (X) << std::endl << std::endl;
#include <triqs/gfs/local/functions.hpp>
#include <triqs/gfs/functions/functions.hpp>

int main() {
try {
Expand Down
2 changes: 1 addition & 1 deletion test/triqs/gfs/gf_positive_and_negative_matsubara.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/local/functions.hpp>
#include <triqs/gfs/functions/functions.hpp>
using namespace triqs::gfs;
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;

Expand Down
2 changes: 1 addition & 1 deletion test/triqs/gfs/gf_scalar.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/local/functions.hpp>
#include <triqs/gfs/functions/functions.hpp>
using namespace triqs::gfs;
namespace h5 = triqs::h5;

Expand Down
3 changes: 2 additions & 1 deletion test/triqs/gfs/gfv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ using namespace triqs::gfs;
using namespace triqs::arrays;
namespace h5 = triqs::h5;
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;
#include <triqs/gfs/local/functions.hpp>
#include <triqs/gfs/functions/functions.hpp>


int main() {
try {
Expand Down
3 changes: 2 additions & 1 deletion test/triqs/gfs/mpi_red.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using namespace triqs::gfs;
using namespace triqs::arrays;
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;
#include <triqs/gfs/local/functions.hpp>
#include <triqs/gfs/functions/functions.hpp>

#include <boost/mpi.hpp>

int main(int argc, char* argv[]) {
Expand Down
17 changes: 6 additions & 11 deletions test/triqs/gfs/multivar/bubble.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include "test_tools.hpp"
#include <triqs/gfs.hpp>
#include <triqs/gfs/bz.hpp>
#include <triqs/gfs/cyclic_lattice.hpp>
#include <triqs/gfs/local/fourier_lattice.hpp>

namespace h5 = triqs::h5;
using namespace triqs::gfs;
using namespace triqs::clef;
using namespace triqs::arrays;
using namespace triqs::lattice;

#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> " << (X) << std::endl << std::endl;

int main() {
try {
TEST(Gf, Bubble) {
int N = 4; // 16; // too long, 30 s
int nw =3;

Expand Down Expand Up @@ -45,10 +40,11 @@ int main() {

chi0r(inu_, iw_, r_) << Gr(inu_, r_) * Gr(inu_ + iw_, -r_);


curry<0,1>(chi0q_from_r)(inu_, iw_) << fourier(on_mesh(curry<0,1>(chi0r))(inu_, iw_));
//curry<0,1>(chi0q_from_r)(inu_, iw_) << fourier(curry<0,1>(chi0r)(inu_, iw_));

if (max_element(abs(chi0q_from_r.data() - chi0q.data())) > 1.e-13) TRIQS_RUNTIME_ERROR << "fourier pb";
EXPECT_CLOSE_ARRAY(chi0q_from_r.data(),chi0q.data());

//simplified, without frequency dependence
auto gk = gf<brillouin_zone>{{bz, N} , {1,1}};
Expand All @@ -64,15 +60,14 @@ int main() {
ggr(r_) << gr(r_)*gr(r_);
ggq_from_r() = fourier(ggr);

if (max_element(abs(ggq_from_r.data() - ggq.data())) > 1.e-13) TRIQS_RUNTIME_ERROR << "fourier pb";
EXPECT_CLOSE_ARRAY(ggq_from_r.data() , ggq.data()); //<<"fourier pb";

// hdf5
h5::file file("chi0q.h5", H5F_ACC_TRUNC);
h5_write(file, "chi0q", chi0q);
h5_write(file, "chi0q_from_r", chi0q_from_r);
}
TRIQS_CATCH_AND_ABORT;
}
MAKE_MAIN;



3 changes: 0 additions & 3 deletions test/triqs/gfs/multivar/bubble_scalar.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/bz.hpp>
#include <triqs/gfs/cyclic_lattice.hpp>
#include <triqs/gfs/local/fourier_lattice.hpp>

namespace h5 = triqs::h5;
using namespace triqs::gfs;
Expand Down
2 changes: 0 additions & 2 deletions test/triqs/gfs/multivar/curry1.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK

#include <triqs/gfs.hpp>
#include <triqs/gfs/local/fourier_real.hpp>

namespace tql= triqs::clef;
using namespace triqs::gfs;
Expand Down
4 changes: 1 addition & 3 deletions test/triqs/gfs/multivar/curry_and_fourier.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/bz.hpp>
#include <triqs/gfs/m_tail.hpp>
#include "../common.hpp"

namespace h5 = triqs::h5;
Expand Down Expand Up @@ -40,7 +38,7 @@ int main() {
// works also, but uses the evaluator which return to the same point
// gk_t(k_) << inverse_fourier(gk_w(k_));
// check last assertion
for (auto k : gk_t.mesh()) assert_equal(k.linear_index(), gk_t.mesh().locate_neighbours(k).linear_index(), "k location point");
for (auto k : gk_t.mesh()) assert_equal(k.linear_index(), gk_t.mesh().index_to_linear(gk_t.mesh().locate_neighbours(k)), "k location point");

/// Testing the result
auto gk_w_test = gf<imfreq>{{beta, Fermion, n_freq}, {1, 1}};
Expand Down
2 changes: 0 additions & 2 deletions test/triqs/gfs/multivar/g_k_om.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/bz.hpp>
#include <triqs/gfs/m_tail.hpp>

namespace h5 = triqs::h5;
using namespace triqs::gfs;
Expand Down
2 changes: 0 additions & 2 deletions test/triqs/gfs/multivar/g_k_tail.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/bz.hpp>
#include <triqs/gfs/m_tail.hpp>

namespace h5 = triqs::h5;
using namespace triqs::gfs;
Expand Down
2 changes: 0 additions & 2 deletions test/triqs/gfs/multivar/g_x_t.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/bz.hpp>
#include <triqs/gfs/m_tail.hpp>
#include "../common.hpp"

namespace h5 = triqs::h5;
Expand Down
3 changes: 1 addition & 2 deletions test/triqs/gfs/multivar/sym3.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/local/fourier_lattice.hpp>

namespace h5 = triqs::h5;
using namespace triqs;
Expand All @@ -24,7 +23,7 @@ struct my_evaluator {

// all evaluation are rewritten with in terms of the default evaluator.
template <typename G, typename Nu, typename Nup, typename Om>
auto operator()(G const *g, Nu const &nu, Nup const &nup, Om const &omega) const {
auto operator()(G const &g, Nu const &nu, Nup const &nup, Om const &omega) const {
if (omega < 0)
return conj(gv(-nu, -nup, -omega));
else
Expand Down
2 changes: 0 additions & 2 deletions test/triqs/gfs/multivar/vertex.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK

#include <triqs/gfs.hpp>
#include <triqs/gfs/local/fourier_real.hpp>

using namespace triqs::gfs;
using triqs::clef::placeholder;
Expand Down
5 changes: 2 additions & 3 deletions test/triqs/gfs/test_fit_tail.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#//define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK

#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/local/fit_tail.hpp>
#include <triqs/gfs/singularity/fit_tail.hpp>

using triqs::arrays::make_shape;
using namespace triqs::gfs;
Expand Down
1 change: 0 additions & 1 deletion test/triqs/gfs/test_fourier_matsubara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ using namespace triqs::gfs;
using namespace triqs::arrays;
namespace h5 = triqs::h5;
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;
#include <triqs/gfs/local/fourier_matsubara.hpp>

int main() {

Expand Down
1 change: 0 additions & 1 deletion test/triqs/gfs/test_fourier_real_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ using namespace triqs::gfs;
using namespace triqs::arrays;
namespace h5 = triqs::h5;
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;
#include <triqs/gfs/local/fourier_real.hpp>

double lorentzian(double w, double a){
return 2*a / (w*w + a*a) ;
Expand Down
1 change: 0 additions & 1 deletion test/triqs/gfs/test_gf_triqs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using namespace triqs::gfs;
using namespace triqs::arrays;
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;
#include <triqs/gfs/local/fourier_matsubara.hpp>
#include<fstream>
#include <stdexcept>
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;
Expand Down
2 changes: 1 addition & 1 deletion test/triqs/gfs/test_rebinning_tau.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/local/functions.hpp>
#include <triqs/gfs/functions/functions.hpp>

using namespace triqs::gfs;

Expand Down
10 changes: 5 additions & 5 deletions triqs/gfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
#ifndef TRIQS_C11
#include <triqs/gfs/product.hpp>
#include <triqs/gfs/curry.hpp>
#include <triqs/gfs/m_tail.hpp>
#include <triqs/gfs/singularity/m_tail.hpp>
#endif

#include <triqs/gfs/local/fourier_matsubara.hpp>
#include <triqs/gfs/local/fourier_real.hpp>
#include <triqs/gfs/local/fourier_lattice.hpp>
#include <triqs/gfs/local/legendre_matsubara.hpp>
#include <triqs/gfs/transform/fourier_matsubara.hpp>
#include <triqs/gfs/transform/fourier_real.hpp>
#include <triqs/gfs/transform/fourier_lattice.hpp>
#include <triqs/gfs/transform/legendre_matsubara.hpp>
#endif

3 changes: 2 additions & 1 deletion triqs/gfs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(local)
add_subdirectory(functions)
add_subdirectory(transform)

2 changes: 0 additions & 2 deletions triqs/gfs/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
*
******************************************************************************/
#pragma once
#include "./tools.hpp"
#include "./gf.hpp"
#include "./local/tail.hpp"
#include "./meshes/discrete.hpp"

namespace triqs {
Expand Down
Loading

0 comments on commit 0f59d9e

Please sign in to comment.