3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-25 05:43:40 +01:00

gf block : clean

- clean some constructor and clang format
This commit is contained in:
Olivier Parcollet 2013-10-23 18:02:01 +02:00
parent 1b5aceb2a5
commit 1d5ea99d4f
3 changed files with 64 additions and 67 deletions

View File

@ -42,7 +42,7 @@ The factories for the regular type *gf* are ::
// From a vector of gf (moving directly) // From a vector of gf (moving directly)
template <typename Variable, typename Target, typename Opt> template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> block_gf<Variable, Target, Opt>
make_block_gf(std::vector<gf<Variable, Target, Opt>> &&V); make_block_gf(std::vector<gf<Variable, Target, Opt>> V);
// From a vector of gf or views (a gf must be contructible from GF2) // From a vector of gf or views (a gf must be contructible from GF2)
template <typename Variable, typename Target, typename Opt, typename GF2> template <typename Variable, typename Target, typename Opt, typename GF2>
@ -57,19 +57,17 @@ The factories for the regular type *gf* are ::
// From vector<string> and a gf to be copied // From vector<string> and a gf to be copied
template <typename Variable, typename Target, typename Opt> template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> block_gf<Variable, Target, Opt>
make_block_gf(std::vector<std::string> const &block_names, make_block_gf(std::vector<std::string> block_names, gf<Variable, Target, Opt> const &g);
gf<Variable, Target, Opt> const &g);
// From vector<string>, vector<gf> // From vector<string>, vector<gf>
template <typename Variable, typename Target, typename Opt> template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> block_gf<Variable, Target, Opt>
make_block_gf(std::vector<std::string> const &block_names, make_block_gf(std::vector<std::string> block_names, std::vector<gf<Variable, Target, Opt>> V);
std::vector<gf<Variable, Target, Opt>> V);
// From vector<string>, init_list<GF> // From vector<string>, init_list<GF>
template <typename Variable, typename Target, typename Opt> template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> block_gf<Variable, Target, Opt>
make_block_gf(std::vector<std::string> const &block_names, make_block_gf(std::vector<std::string> block_names,
std::initializer_list<gf<Variable, Target, Opt>> const &V); std::initializer_list<gf<Variable, Target, Opt>> const &V);

View File

@ -25,73 +25,76 @@
#include "./local/tail.hpp" #include "./local/tail.hpp"
#include "./meshes/discrete.hpp" #include "./meshes/discrete.hpp"
namespace triqs { namespace gfs { namespace triqs {
namespace gfs {
struct block_index {}; struct block_index {};
template<typename Opt> struct gf_mesh<block_index,Opt> : discrete_mesh<discrete_domain> { template <typename Opt> struct gf_mesh<block_index, Opt> : discrete_mesh<discrete_domain> {
typedef discrete_mesh<discrete_domain> B; typedef discrete_mesh<discrete_domain> B;
gf_mesh() = default; gf_mesh() = default;
gf_mesh(int s) : B(s) {} gf_mesh(int s) : B(s) {}
gf_mesh(discrete_domain const & d) : B(d) {} gf_mesh(discrete_domain const &d) : B(d) {}
gf_mesh(std::initializer_list<std::string> const & s) : B(s){} gf_mesh(std::initializer_list<std::string> const &s) : B(s) {}
}; };
namespace gfs_implementation { namespace gfs_implementation {
/// --------------------------- hdf5 --------------------------------- /// --------------------------- hdf5 ---------------------------------
template<typename Target, typename Opt> struct h5_name<block_index,Target,Opt> { static std::string invoke(){ return "BlockGf";}}; template <typename Target, typename Opt> struct h5_name<block_index, Target, Opt> {
static std::string invoke() { return "BlockGf"; }
};
template <typename Target, typename Opt> struct h5_rw<block_index,Target,Opt> { template <typename Target, typename Opt> struct h5_rw<block_index, Target, Opt> {
static void write (h5::group gr, gf_const_view<block_index,Target,Opt> g) { static void write(h5::group gr, gf_const_view<block_index, Target, Opt> g) {
for (size_t i =0; i<g.mesh().size(); ++i) h5_write(gr,g.mesh().domain().names()[i],g._data[i]); 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); // h5_write(gr,"symmetry",g._symmetry);
} }
template<bool IsView> template <bool IsView> static void read(h5::group gr, gf_impl<block_index, Target, Opt, IsView, false> &g) {
static void read (h5::group gr, gf_impl<block_index,Target,Opt,IsView,false> &g) {
// does not work : need to read the block name and remake the mesh... // 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._mesh = gf_mesh<block_index, Opt>(gr.get_all_subgroup_names());
g._data.resize(g._mesh.size()); g._data.resize(g._mesh.size());
//if (g._data.size() != g._mesh.size()) TRIQS_RUNTIME_ERROR << "h5 read block gf : number of block mismatch"; // if (g._data.size() != g._mesh.size()) TRIQS_RUNTIME_ERROR << "h5 read block gf : number of block mismatch";
for (size_t i =0; i<g.mesh().size(); ++i) h5_read(gr,g.mesh().domain().names()[i],g._data[i]); 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); // h5_read(gr,"symmetry",g._symmetry);
} }
}; };
/// --------------------------- data access --------------------------------- /// --------------------------- data access ---------------------------------
template<typename Target, typename Opt> struct data_proxy<block_index,Target,Opt> : data_proxy_vector <typename regular_type_if_exists_else_type<Target>::type>{}; template <typename Target, typename Opt>
struct data_proxy<block_index, Target, Opt> : data_proxy_vector<typename regular_type_if_exists_else_type<Target>::type> {};
// ------------------------------- Factories -------------------------------------------------- // ------------------------------- Factories --------------------------------------------------
template<typename Target, typename Opt> template <typename Target, typename Opt> struct factories<block_index, Target, Opt> {
struct factories<block_index,Target,Opt> {
typedef gf_mesh<block_index, Opt> mesh_t; typedef gf_mesh<block_index, Opt> mesh_t;
typedef gf<block_index,Target> gf_t; typedef gf<block_index, Target> gf_t;
typedef gf_view<block_index,Target> gf_view_t; typedef gf_view<block_index, Target> gf_view_t;
struct target_shape_t{}; struct target_shape_t {};
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::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 {};} static typename gf_t::singularity_t make_singularity(mesh_t const &m, target_shape_t) {
return {};
}
}; };
} // gfs_implementation } // gfs_implementation
// ------------------------------- aliases -------------------------------------------------- // ------------------------------- aliases --------------------------------------------------
template<typename ... T> using block_gf = gf<block_index, gf<T...>>; 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_view = gf_view<block_index, gf<T...>>;
template<typename ... T> using block_gf_const_view = gf_const_view<block_index, gf<T...>>; template <typename... T> using block_gf_const_view = gf_const_view<block_index, gf<T...>>;
// ------------------------------- Free Factories for regular type -------------------------------------------------- // ------------------------------- Free Factories for regular type --------------------------------------------------
// from a number and a gf to be copied // from a number and a gf to be copied
template <typename Variable, typename Target, typename Opt> template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> make_block_gf(int n, gf<Variable, Target, Opt> const & g) { block_gf<Variable, Target, Opt> make_block_gf(int n, gf<Variable, Target, Opt> const &g) {
auto V = std::vector<gf<Variable, Target, Opt>>{}; auto V = std::vector<gf<Variable, Target, Opt>>{};
for (int i = 0; i < n; ++i) V.push_back(g); for (int i = 0; i < n; ++i) V.push_back(g);
return {{n}, std::move(V), nothing{}, nothing{}}; return {{n}, std::move(V), nothing{}, nothing{}};
@ -99,7 +102,7 @@ namespace triqs { namespace gfs {
// from a vector of gf (moving directly) // from a vector of gf (moving directly)
template <typename Variable, typename Target, typename Opt> template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> make_block_gf(std::vector<gf<Variable, Target, Opt>> &&V) { block_gf<Variable, Target, Opt> make_block_gf(std::vector<gf<Variable, Target, Opt>> V) {
return {{int(V.size())}, std::move(V), nothing{}, nothing{}}; return {{int(V.size())}, std::move(V), nothing{}, nothing{}};
} }
@ -119,7 +122,7 @@ namespace triqs { namespace gfs {
// from vector<string> and a gf to be copied // from vector<string> and a gf to be copied
template <typename Variable, typename Target, typename Opt> 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) { block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> block_names, gf<Variable, Target, Opt> const &g) {
auto V = std::vector<gf<Variable, Target, Opt>>{}; auto V = std::vector<gf<Variable, Target, Opt>>{};
for (int i = 0; i < block_names.size(); ++i) V.push_back(g); for (int i = 0; i < block_names.size(); ++i) V.push_back(g);
return {{block_names}, std::move(V), nothing{}, nothing{}}; return {{block_names}, std::move(V), nothing{}, nothing{}};
@ -127,8 +130,7 @@ namespace triqs { namespace gfs {
// from vector<string>, vector<gf> // from vector<string>, vector<gf>
template <typename Variable, typename Target, typename Opt> template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> const &block_names, block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> block_names, std::vector<gf<Variable, Target, Opt>> V) {
std::vector<gf<Variable, Target, Opt>> V) {
if (block_names.size() != V.size()) 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 !"; 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{}}; return {{block_names}, std::move(V), nothing{}, nothing{}};
@ -136,7 +138,7 @@ namespace triqs { namespace gfs {
// from vector<string>, init_list<GF> // from vector<string>, init_list<GF>
template <typename Variable, typename Target, typename Opt> template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> const &block_names, block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> block_names,
std::initializer_list<gf<Variable, Target, Opt>> const &V) { 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 !"; if (block_names.size() != V.size()) TRIQS_RUNTIME_ERROR << "make_block_gf(vector<string>, init_list) : size mismatch !";
return {{block_names}, V, nothing{}, nothing{}}; return {{block_names}, V, nothing{}, nothing{}};
@ -144,22 +146,22 @@ namespace triqs { namespace gfs {
// ------------------------------- Free Factories for view type -------------------------------------------------- // ------------------------------- Free Factories for view type --------------------------------------------------
template<typename G0, typename ... G> 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) { 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)...}; 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 {{int(V.size())}, std::move(V), nothing{}, nothing{}};
//return { gf_mesh<block_index, Opt> {int(V.size())}, std::move(V), nothing{}, nothing{} } ; // return { gf_mesh<block_index, Opt> {int(V.size())}, std::move(V), nothing{}, nothing{} } ;
} }
template<typename GF, typename GF2> template <typename GF, typename GF2> gf_view<block_index, GF> make_block_gf_view_from_vector(std::vector<GF2> V) {
gf_view<block_index,GF> return {{int(V.size())}, std::move(V), nothing{}, nothing{}};
make_block_gf_view_from_vector (std::vector<GF2> V) { return { {int(V.size())}, std::move(V), nothing{}, nothing{}} ; } }
// ------------------------------- Free functions -------------------------------------------------- // ------------------------------- Free functions --------------------------------------------------
// a simple function to get the number of blocks // 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<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 <typename T> size_t n_blocks(gf_view<block_index, T> const &g) { return g.mesh().size(); }
// ------------------------------- an iterator over the blocks -------------------------------------------------- // ------------------------------- an iterator over the blocks --------------------------------------------------
@ -169,7 +171,7 @@ namespace triqs { namespace gfs {
: public boost::iterator_facade<block_gf_iterator<Target, Opt, B, C>, Target, boost::forward_traversal_tag, Target &> { : public boost::iterator_facade<block_gf_iterator<Target, Opt, B, C>, Target, boost::forward_traversal_tag, Target &> {
friend class boost::iterator_core_access; friend class boost::iterator_core_access;
typedef gf_impl<block_index, Target, Opt, B, C> big_gf_t; typedef gf_impl<block_index, Target, Opt, B, C> big_gf_t;
big_gf_t & big_gf; big_gf_t &big_gf;
typedef typename big_gf_t::mesh_t::const_iterator mesh_iterator_t; typedef typename big_gf_t::mesh_t::const_iterator mesh_iterator_t;
mesh_iterator_t mesh_it; mesh_iterator_t mesh_it;
@ -177,8 +179,7 @@ namespace triqs { namespace gfs {
bool equal(block_gf_iterator const &other) const { return ((mesh_it == other.mesh_it)); } bool equal(block_gf_iterator const &other) const { return ((mesh_it == other.mesh_it)); }
public: public:
block_gf_iterator(big_gf_t & bgf, bool at_end = false) block_gf_iterator(big_gf_t &bgf, bool at_end = false) : big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {}
: big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {}
void increment() { ++mesh_it; } void increment() { ++mesh_it; }
bool at_end() const { return mesh_it.at_end(); } bool at_end() const { return mesh_it.at_end(); }
}; };
@ -197,11 +198,11 @@ namespace triqs { namespace gfs {
//----- const iterator //----- const iterator
template <typename Target, typename Opt, bool B, bool C> template <typename Target, typename Opt, bool B, bool C>
class block_gf_const_iterator class block_gf_const_iterator : public boost::iterator_facade<block_gf_const_iterator<Target, Opt, B, C>, Target,
: public boost::iterator_facade<block_gf_const_iterator<Target, Opt, B, C>, Target, boost::forward_traversal_tag, Target const &> { boost::forward_traversal_tag, Target const &> {
friend class boost::iterator_core_access; friend class boost::iterator_core_access;
typedef gf_impl<block_index, Target, Opt, B, C> big_gf_t; typedef gf_impl<block_index, Target, Opt, B, C> big_gf_t;
big_gf_t const & big_gf; big_gf_t const &big_gf;
typedef typename big_gf_t::mesh_t::const_iterator mesh_iterator_t; typedef typename big_gf_t::mesh_t::const_iterator mesh_iterator_t;
mesh_iterator_t mesh_it; mesh_iterator_t mesh_it;
@ -209,8 +210,7 @@ namespace triqs { namespace gfs {
bool equal(block_gf_const_iterator const &other) const { return ((mesh_it == other.mesh_it)); } bool equal(block_gf_const_iterator const &other) const { return ((mesh_it == other.mesh_it)); }
public: public:
block_gf_const_iterator(big_gf_t const& bgf, bool at_end = false) block_gf_const_iterator(big_gf_t const &bgf, bool at_end = false) : big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {}
: big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {}
void increment() { ++mesh_it; } void increment() { ++mesh_it; }
bool at_end() const { return mesh_it.at_end(); } bool at_end() const { return mesh_it.at_end(); }
}; };
@ -234,8 +234,7 @@ namespace triqs { namespace gfs {
block_gf_const_iterator<Target, Opt, B, C> cend(gf_impl<block_index, Target, Opt, B, C> const &bgf) { block_gf_const_iterator<Target, Opt, B, C> cend(gf_impl<block_index, Target, Opt, B, C> const &bgf) {
return {bgf, true}; return {bgf, true};
} }
}
}} }
#endif #endif