/******************************************************************************* * * TRIQS: a Toolbox for Research in Interacting Quantum Systems * * Copyright (C) 2012 by M. Ferrero, O. Parcollet * * TRIQS is free software: you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * TRIQS. If not, see . * ******************************************************************************/ #ifndef TRIQS_GF_BLOCK_H #define TRIQS_GF_BLOCK_H #include "./tools.hpp" #include "./gf.hpp" #include "./local/tail.hpp" #include "./meshes/discrete.hpp" namespace triqs { namespace gfs { struct block_index {}; template struct mesh : discrete_mesh { mesh() = default; mesh(size_t s) : discrete_mesh(s) {} }; namespace gfs_implementation { template struct h5_name { static std::string invoke(){ return "BlockGf";}}; /// --------------------------- h5_rw --------------------------------- template struct h5_ops { template static void write(h5::group g, std::string const & s, DataType const & data, GF const & gf) { auto gr = g.create_group(s); for (size_t i =0; i static void read(h5::group g, std::string const & s, DataType & data, GF const & gf) { auto gr = g.create_group(s); for (size_t i =0; i struct data_proxy : data_proxy_vector ::type>{}; // ------------------------------- Factories -------------------------------------------------- template struct factories { typedef mesh mesh_t; typedef gf gf_t; typedef gf_view gf_view_t; static gf_t make_gf(std::vector const & V) { return gf_t ( mesh_t(V.size()), V, nothing(), nothing() ) ; } static gf_t make_gf(std::vector && V) { return gf_t ( mesh_t(V.size()), std::move(V), nothing(), nothing() ) ; } static gf_t make_gf(std::vector const & block_names, std::vector const & V) { return gf_t(mesh_t(block_names), V, nothing(), nothing() ); } static gf_t make_gf(std::vector const & block_names, std::vector && V) { return gf_t(mesh_t(block_names), std::move(V), nothing(), nothing() ); } /* static gf_t make_gf(std::initializer_list const & l) { auto v = std::vector {l}; return make_gf(v); } */ /* template static gf_t make_gf(size_t N, Args&& ...args) { std::vector V; V.reserve(N); for (size_t i=0; i(args...))); return make_gf(V); } */ static gf_t make_gf(int N, Target const & g) { std::vector V; V.reserve(N); for (size_t i=0; i const & block_names, Target const & g) { std::vector V; V.reserve(block_names.size()); for (size_t i=0; i static gf_t make_gf(std::vector const & block_names, Args&& ...args) { std::vector V; V.reserve(block_names.size()); for (size_t i=0; i(args...))); return make_gf(block_names,V); } */ template static gf_view_t make_gf_view(std::vector const & V) { return gf_view_t ( mesh_t(V.size()), V, nothing(), nothing() ) ; } template static gf_view_t make_gf_view(std::vector && V) { return gf_view_t ( mesh_t(V.size()), std::move(V), nothing(), nothing() ) ; } }; } // gfs_implementation // ------------------------------- Free function -------------------------------------------------- // a simple function to get the number of blocks template size_t n_blocks (gf const & g) { return g.mesh().size();} template size_t n_blocks (gf_view const & g) { return g.mesh().size();} // template alias //template using block_gf = gf>; // experimental template gf> make_block_gf(U && ...u) { return gfs_implementation::factories,void>::make_gf(std::forward(u)...);} // also experimental // an iterator over the block template class block_gf_iterator : public boost::iterator_facade< block_gf_iterator, typename Target::view_type , boost::forward_traversal_tag, typename Target::view_type > { friend class boost::iterator_core_access; typedef gf_view big_gf_t; typedef typename big_gf_t::mesh_t::const_iterator mesh_iterator_t; big_gf_t big_gf; mesh_iterator_t mesh_it; typename Target::view_type const & dereference() const { return big_gf[*mesh_it];} bool equal(block_gf_iterator const & other) const { return ((mesh_it == other.mesh_it));} public: block_gf_iterator(gf_view bgf, bool at_end = false): big_gf(std::move(bgf)), mesh_it(&big_gf.mesh(),at_end) {} void increment() { ++mesh_it; } bool at_end() const { return mesh_it.at_end();} }; template block_gf_iterator begin(gf_impl const & bgf) { return {bgf,false};} template block_gf_iterator end(gf_impl const & bgf) { return {bgf,true};} }} #endif