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> {
|
2013-10-16 23:55:26 +02:00
|
|
|
typedef discrete_mesh<discrete_domain> B;
|
2013-08-27 14:20:50 +02:00
|
|
|
gf_mesh() = default;
|
2013-10-16 23:55:26 +02:00
|
|
|
gf_mesh(int s) : B(s) {}
|
|
|
|
gf_mesh(discrete_domain const & d) : B(d) {}
|
|
|
|
gf_mesh(std::initializer_list<std::string> const & s) : B(s){}
|
2013-08-24 14:47:47 +02:00
|
|
|
};
|
|
|
|
|
2013-10-16 23:55:26 +02:00
|
|
|
namespace gfs_implementation {
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-10-16 23:55:26 +02:00
|
|
|
/// --------------------------- hdf5 ---------------------------------
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-10-16 23:55:26 +02:00
|
|
|
template<typename Target, typename Opt> struct h5_name<block_index,Target,Opt> { static std::string invoke(){ return "BlockGf";}};
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-10-18 13:39:00 +02:00
|
|
|
template <typename Target, typename Opt> struct h5_rw<block_index,Target,Opt> {
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-10-18 13:39:00 +02:00
|
|
|
static void write (h5::group gr, gf_const_view<block_index,Target,Opt> g) {
|
2013-10-16 23:55:26 +02:00
|
|
|
for (size_t i =0; i<g.mesh().size(); ++i) h5_write(gr,g.mesh().domain().names()[i],g._data[i]);
|
|
|
|
//h5_write(gr,"symmetry",g._symmetry);
|
|
|
|
}
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-10-18 13:39:00 +02:00
|
|
|
template<bool IsView>
|
|
|
|
static void read (h5::group gr, gf_impl<block_index,Target,Opt,IsView,false> &g) {
|
2013-10-16 23:55:26 +02:00
|
|
|
// does not work : need to read the block name and remake the mesh...
|
|
|
|
g._mesh = gf_mesh<block_index,Opt> (gr.get_all_subgroup_names());
|
|
|
|
g._data.resize(g._mesh.size());
|
2013-10-18 13:39:00 +02:00
|
|
|
//if (g._data.size() != g._mesh.size()) TRIQS_RUNTIME_ERROR << "h5 read block gf : number of block mismatch";
|
2013-10-16 23:55:26 +02:00
|
|
|
for (size_t i =0; i<g.mesh().size(); ++i) h5_read(gr,g.mesh().domain().names()[i],g._data[i]);
|
|
|
|
//h5_read(gr,"symmetry",g._symmetry);
|
|
|
|
}
|
2013-10-18 13:39:00 +02:00
|
|
|
|
|
|
|
};
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
/// --------------------------- 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;
|
2013-10-16 23:55:26 +02:00
|
|
|
struct target_shape_t{};
|
2013-07-17 19:24:07 +02:00
|
|
|
|
2013-10-16 23:55:26 +02:00
|
|
|
static typename gf_t::data_t make_data(mesh_t const & m, target_shape_t) { return std::vector<Target> (m.size()); }
|
|
|
|
static typename gf_t::singularity_t make_singularity (mesh_t const & m, target_shape_t) { return {};}
|
2013-07-17 19:24:07 +02:00
|
|
|
};
|
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
|
|
|
|
2013-10-18 13:39:00 +02:00
|
|
|
// ------------------------------- aliases --------------------------------------------------
|
|
|
|
|
|
|
|
template<typename ... T> using block_gf = gf<block_index, gf<T...>>;
|
|
|
|
template<typename ... T> using block_gf_view = gf_view<block_index, gf<T...>>;
|
|
|
|
template<typename ... T> using block_gf_const_view = gf_const_view<block_index, gf<T...>>;
|
2013-10-16 23:55:26 +02:00
|
|
|
|
2013-10-18 13:39:00 +02:00
|
|
|
// ------------------------------- Free Factories for regular type --------------------------------------------------
|
2013-10-16 23:55:26 +02:00
|
|
|
|
|
|
|
// from a number and a gf to be copied
|
2013-10-18 13:39:00 +02:00
|
|
|
template <typename Variable, typename Target, typename Opt>
|
|
|
|
block_gf<Variable, Target, Opt> make_block_gf(int n, gf<Variable, Target, Opt> const & g) {
|
|
|
|
auto V = std::vector<gf<Variable, Target, Opt>>{};
|
|
|
|
for (int i = 0; i < n; ++i) V.push_back(g);
|
|
|
|
return {{n}, std::move(V), nothing{}, nothing{}};
|
|
|
|
}
|
2013-10-16 23:55:26 +02:00
|
|
|
|
|
|
|
// from a vector of gf (moving directly)
|
2013-10-18 13:39:00 +02:00
|
|
|
template <typename Variable, typename Target, typename Opt, typename GF2>
|
|
|
|
block_gf<Variable, Target, Opt> make_block_gf(std::vector<gf<Variable, Target, Opt>> &&V) {
|
|
|
|
return {{int(V.size())}, std::move(V), nothing{}, nothing{}};
|
|
|
|
}
|
2013-10-16 23:55:26 +02:00
|
|
|
|
|
|
|
// from a vector of gf : generalized to have a different type of gf in the vector (e.g. views...)
|
2013-10-18 13:39:00 +02:00
|
|
|
template <typename Variable, typename Target, typename Opt, typename GF2>
|
|
|
|
block_gf<Variable, Target, Opt> make_block_gf(std::vector<GF2> const &V) {
|
|
|
|
auto V2 = std::vector<gf<Variable, Target, Opt>>{};
|
|
|
|
for (auto const &g : V) V2.push_back(g);
|
|
|
|
return {{int(V.size())}, std::move(V2), nothing{}, nothing{}};
|
|
|
|
}
|
2013-10-16 23:55:26 +02:00
|
|
|
|
|
|
|
// from a init list of GF with the correct type
|
2013-10-18 13:39:00 +02:00
|
|
|
template <typename Variable, typename Target, typename Opt>
|
|
|
|
block_gf<Variable, Target, Opt> make_block_gf(std::initializer_list<gf<Variable, Target, Opt>> const &V) {
|
|
|
|
return {{int(V.size())}, V, nothing{}, nothing{}};
|
|
|
|
}
|
|
|
|
|
|
|
|
// from vector<string> and a gf to be copied
|
|
|
|
template <typename Variable, typename Target, typename Opt>
|
|
|
|
block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> const &block_names, gf<Variable, Target, Opt> const &g) {
|
|
|
|
auto V = std::vector<gf<Variable, Target, Opt>>{};
|
|
|
|
for (int i = 0; i < block_names.size(); ++i) V.push_back(g);
|
|
|
|
return {{block_names}, std::move(V), nothing{}, nothing{}};
|
|
|
|
}
|
|
|
|
|
2013-10-16 23:55:26 +02:00
|
|
|
// from vector<string>, vector<gf>
|
2013-10-18 13:39:00 +02:00
|
|
|
template <typename Variable, typename Target, typename Opt>
|
|
|
|
block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> const &block_names,
|
|
|
|
std::vector<gf<Variable, Target, Opt>> V) {
|
|
|
|
if (block_names.size() != V.size())
|
|
|
|
TRIQS_RUNTIME_ERROR << "make_block_gf(vector<string>, vector<gf>) : the two vectors do not have the same size !";
|
|
|
|
return {{block_names}, std::move(V), nothing{}, nothing{}};
|
|
|
|
}
|
2013-10-16 23:55:26 +02:00
|
|
|
|
|
|
|
// from vector<string>, init_list<GF>
|
2013-10-18 13:39:00 +02:00
|
|
|
template <typename Variable, typename Target, typename Opt>
|
|
|
|
block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> const &block_names,
|
|
|
|
std::initializer_list<gf<Variable, Target, Opt>> const &V) {
|
|
|
|
if (block_names.size() != V.size()) TRIQS_RUNTIME_ERROR << "make_block_gf(vector<string>, init_list) : size mismatch !";
|
|
|
|
return {{block_names}, V, nothing{}, nothing{}};
|
|
|
|
}
|
2013-10-16 23:55:26 +02:00
|
|
|
|
|
|
|
// ------------------------------- Free Factories for view type --------------------------------------------------
|
|
|
|
|
2013-10-18 13:39:00 +02:00
|
|
|
template<typename G0, typename ... G>
|
|
|
|
gf_view<block_index, typename std::remove_reference<G0>::type::view_type> make_block_gf_view(G0 && g0, G && ... g) {
|
|
|
|
auto V = std::vector<typename std::remove_reference<G0>::type::view_type>{std::forward<G0>(g0), std::forward<G>(g)...};
|
|
|
|
return { {int(V.size())}, std::move(V), nothing{}, nothing{} } ;
|
|
|
|
//return { gf_mesh<block_index, Opt> {int(V.size())}, std::move(V), nothing{}, nothing{} } ;
|
|
|
|
}
|
|
|
|
|
2013-10-16 23:55:26 +02:00
|
|
|
template<typename GF, typename GF2>
|
|
|
|
gf_view<block_index,GF>
|
|
|
|
make_block_gf_view_from_vector (std::vector<GF2> V) { return { {int(V.size())}, std::move(V), nothing{}, nothing{}} ; }
|
|
|
|
|
|
|
|
// ------------------------------- Free functions --------------------------------------------------
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
// 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();}
|
|
|
|
|
2013-07-27 15:06:10 +02:00
|
|
|
// 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
|
|
|
|
2013-10-18 13:39:00 +02:00
|
|
|
template<typename Target, typename Opt, bool B, bool C>
|
|
|
|
block_gf_iterator<Target,Opt> begin(gf_impl<block_index,Target,Opt,B,C> const & bgf) { return {bgf,false};}
|
2013-08-24 14:47:47 +02:00
|
|
|
|
2013-10-18 13:39:00 +02:00
|
|
|
template<typename Target, typename Opt, bool B, bool C>
|
|
|
|
block_gf_iterator<Target,Opt> end(gf_impl<block_index,Target,Opt,B,C> const & bgf) { return {bgf,true};}
|
2013-07-27 15:06:10 +02:00
|
|
|
|
2013-07-17 19:24:07 +02:00
|
|
|
}}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|