2013-07-17 19:24:07 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
#ifndef TRIQS_GF_BLOCK_H
|
|
|
|
#define TRIQS_GF_BLOCK_H
|
|
|
|
#include "./tools.hpp"
|
|
|
|
#include "./gf.hpp"
|
|
|
|
#include "./local/tail.hpp"
|
|
|
|
#include "./meshes/discrete.hpp"
|
|
|
|
|
2013-07-28 13:28:19 +02:00
|
|
|
namespace triqs { namespace gfs {
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
struct block_index {};
|
|
|
|
|
2013-08-27 14:20:50 +02:00
|
|
|
template<typename Opt> struct gf_mesh<block_index,Opt> : discrete_mesh<discrete_domain> {
|
|
|
|
gf_mesh() = default;
|
|
|
|
gf_mesh(size_t s) : discrete_mesh<discrete_domain>(s) {}
|
2013-08-30 12:37:12 +02:00
|
|
|
gf_mesh(discrete_domain const & d) : discrete_mesh<discrete_domain>(d) {}
|
2013-08-24 14:47:47 +02:00
|
|
|
};
|
|
|
|
|
2013-07-28 13:28:19 +02:00
|
|
|
namespace gfs_implementation {
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
template<typename Target, typename Opt> struct h5_name<block_index,Target,Opt> { static std::string invoke(){ return "BlockGf";}};
|
|
|
|
|
|
|
|
/// --------------------------- h5_rw ---------------------------------
|
|
|
|
|
|
|
|
template <typename Target,typename Opt> struct h5_ops<block_index,Target,Opt> {
|
|
|
|
|
|
|
|
template<typename DataType, typename GF>
|
|
|
|
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<gf.mesh().size(); ++i) h5_write(gr,gf.mesh().domain().names()[i],data[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename DataType,typename GF>
|
|
|
|
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<gf.mesh().size(); ++i) h5_read(gr,gf.mesh().domain().names()[i],data[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// --------------------------- evaluator ---------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/// --------------------------- data access ---------------------------------
|
|
|
|
|
2013-08-20 16:15:43 +02:00
|
|
|
template<typename Target, typename Opt> struct data_proxy<block_index,Target,Opt> : data_proxy_vector <typename regular_type_if_exists_else_type<Target>::type>{};
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
// ------------------------------- Factories --------------------------------------------------
|
|
|
|
|
|
|
|
template<typename Target, typename Opt>
|
|
|
|
struct factories<block_index,Target,Opt> {
|
2013-08-27 14:20:50 +02:00
|
|
|
typedef gf_mesh<block_index, Opt> mesh_t;
|
2013-07-17 19:24:07 +02:00
|
|
|
typedef gf<block_index,Target> gf_t;
|
|
|
|
typedef gf_view<block_index,Target> gf_view_t;
|
|
|
|
|
|
|
|
static gf_t make_gf(std::vector<Target> const & V) { return gf_t ( mesh_t(V.size()), V, nothing(), nothing() ) ; }
|
|
|
|
static gf_t make_gf(std::vector<Target> && V) { return gf_t ( mesh_t(V.size()), std::move(V), nothing(), nothing() ) ; }
|
|
|
|
|
|
|
|
static gf_t make_gf(std::vector<std::string> const & block_names, std::vector<Target> const & V) {
|
|
|
|
return gf_t(mesh_t(block_names), V, nothing(), nothing() );
|
|
|
|
}
|
|
|
|
static gf_t make_gf(std::vector<std::string> const & block_names, std::vector<Target> && V) {
|
|
|
|
return gf_t(mesh_t(block_names), std::move(V), nothing(), nothing() );
|
|
|
|
}
|
|
|
|
|
2013-08-24 14:47:47 +02:00
|
|
|
/* static gf_t make_gf(std::initializer_list<Target> const & l) {
|
|
|
|
auto v = std::vector<Target> {l};
|
|
|
|
return make_gf(v);
|
|
|
|
}
|
|
|
|
*/
|
2013-07-17 19:24:07 +02:00
|
|
|
/* template<typename... Args>
|
|
|
|
static gf_t make_gf(size_t N, Args&& ...args) {
|
|
|
|
std::vector<Target> V; V.reserve(N);
|
|
|
|
for (size_t i=0; i<N; ++i) V.push_back( Target::make_gf (std::forward<Args>(args...)));
|
|
|
|
return make_gf(V);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
static gf_t make_gf(int N, Target const & g) {
|
|
|
|
std::vector<Target> V; V.reserve(N);
|
|
|
|
for (size_t i=0; i<N; ++i) V.push_back(g);
|
|
|
|
return make_gf(V);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gf_t make_gf(std::vector<std::string> const & block_names, Target const & g) {
|
|
|
|
std::vector<Target> V; V.reserve(block_names.size());
|
|
|
|
for (size_t i=0; i<block_names.size(); ++i) V.push_back(g);
|
|
|
|
return make_gf(block_names,V);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* template<typename... Args>
|
|
|
|
static gf_t make_gf(std::vector<std::string> const & block_names, Args&& ...args) {
|
|
|
|
std::vector<Target> V; V.reserve(block_names.size());
|
|
|
|
for (size_t i=0; i<block_names.size(); ++i) V.push_back( Target::make_gf (std::forward<Args>(args...)));
|
|
|
|
return make_gf(block_names,V);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
template<typename GF>
|
|
|
|
static gf_view_t make_gf_view(std::vector<GF> const & V) { return gf_view_t ( mesh_t(V.size()), V, nothing(), nothing() ) ; }
|
|
|
|
template<typename GF>
|
|
|
|
static gf_view_t make_gf_view(std::vector<GF> && V) { return gf_view_t ( mesh_t(V.size()), std::move(V), nothing(), nothing() ) ; }
|
|
|
|
|
|
|
|
};
|
2013-08-24 14:47:47 +02:00
|
|
|
|
2013-07-28 13:28:19 +02:00
|
|
|
} // gfs_implementation
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
// ------------------------------- Free function --------------------------------------------------
|
|
|
|
|
|
|
|
// a simple function to get the number of blocks
|
|
|
|
template<typename T> size_t n_blocks (gf<block_index,T> const & g) { return g.mesh().size();}
|
|
|
|
template<typename T> size_t n_blocks (gf_view<block_index,T> const & g) { return g.mesh().size();}
|
|
|
|
|
|
|
|
|
|
|
|
// template alias
|
|
|
|
//template<typename T> using block_gf = gf<block_index, gf<T>>;
|
|
|
|
|
|
|
|
// experimental
|
|
|
|
template<typename Target, typename ... U>
|
2013-07-28 13:28:19 +02:00
|
|
|
gf<block_index, gf<Target>> make_block_gf(U && ...u) { return gfs_implementation::factories<block_index,gf<Target>,void>::make_gf(std::forward<U>(u)...);}
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-07-27 15:06:10 +02:00
|
|
|
// also experimental
|
|
|
|
// an iterator over the block
|
2013-08-24 14:47:47 +02:00
|
|
|
template<typename Target, typename Opt>
|
2013-07-27 15:06:10 +02:00
|
|
|
class block_gf_iterator :
|
|
|
|
public boost::iterator_facade< block_gf_iterator<Target,Opt>, typename Target::view_type , boost::forward_traversal_tag, typename Target::view_type > {
|
|
|
|
friend class boost::iterator_core_access;
|
|
|
|
typedef gf_view<block_index,Target,Opt> big_gf_t;
|
2013-08-24 17:24:02 +02:00
|
|
|
typedef typename big_gf_t::mesh_t::const_iterator mesh_iterator_t;
|
2013-07-27 15:06:10 +02:00
|
|
|
big_gf_t big_gf;
|
|
|
|
mesh_iterator_t mesh_it;
|
|
|
|
|
2013-07-28 13:47:42 +02:00
|
|
|
typename Target::view_type const & dereference() const { return big_gf[*mesh_it];}
|
2013-07-27 15:06:10 +02:00
|
|
|
bool equal(block_gf_iterator const & other) const { return ((mesh_it == other.mesh_it));}
|
|
|
|
public:
|
|
|
|
block_gf_iterator(gf_view<block_index,Target,Opt> 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();}
|
|
|
|
};
|
2013-08-24 14:47:47 +02:00
|
|
|
|
|
|
|
template<typename Target, typename Opt, bool B>
|
2013-07-27 15:06:10 +02:00
|
|
|
block_gf_iterator<Target,Opt> begin(gf_impl<block_index,Target,Opt,B> const & bgf) { return {bgf,false};}
|
2013-08-24 14:47:47 +02:00
|
|
|
|
|
|
|
template<typename Target, typename Opt, bool B>
|
2013-07-27 15:06:10 +02:00
|
|
|
block_gf_iterator<Target,Opt> end(gf_impl<block_index,Target,Opt,B> const & bgf) { return {bgf,true};}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-17 19:24:07 +02:00
|
|
|
}}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|