3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-24 13:23:37 +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)
template <typename Variable, typename Target, typename 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)
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
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);
make_block_gf(std::vector<std::string> block_names, gf<Variable, Target, Opt> const &g);
// From vector<string>, vector<gf>
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);
make_block_gf(std::vector<std::string> block_names, std::vector<gf<Variable, Target, Opt>> V);
// From vector<string>, init_list<GF>
template <typename Variable, typename Target, typename 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);

View File

@ -25,7 +25,8 @@
#include "./local/tail.hpp"
#include "./meshes/discrete.hpp"
namespace triqs { namespace gfs {
namespace triqs {
namespace gfs {
struct block_index {};
@ -41,7 +42,9 @@ namespace triqs { namespace gfs {
/// --------------------------- 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> {
@ -50,8 +53,7 @@ namespace triqs { namespace gfs {
// h5_write(gr,"symmetry",g._symmetry);
}
template<bool IsView>
static void read (h5::group gr, gf_impl<block_index,Target,Opt,IsView,false> &g) {
template <bool IsView> 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...
g._mesh = gf_mesh<block_index, Opt>(gr.get_all_subgroup_names());
g._data.resize(g._mesh.size());
@ -59,24 +61,25 @@ namespace triqs { namespace gfs {
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);
}
};
/// --------------------------- 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 --------------------------------------------------
template<typename Target, typename Opt>
struct factories<block_index,Target,Opt> {
template <typename Target, typename Opt> struct factories<block_index, Target, Opt> {
typedef gf_mesh<block_index, Opt> mesh_t;
typedef gf<block_index, Target> gf_t;
typedef gf_view<block_index, Target> gf_view_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::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
@ -99,7 +102,7 @@ namespace triqs { namespace gfs {
// from a vector of gf (moving directly)
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{}};
}
@ -119,7 +122,7 @@ namespace triqs { namespace gfs {
// 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) {
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>>{};
for (int i = 0; i < block_names.size(); ++i) V.push_back(g);
return {{block_names}, std::move(V), nothing{}, nothing{}};
@ -127,8 +130,7 @@ namespace triqs { namespace gfs {
// from vector<string>, vector<gf>
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) {
block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> 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{}};
@ -136,7 +138,7 @@ namespace triqs { namespace gfs {
// from vector<string>, init_list<GF>
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) {
if (block_names.size() != V.size()) TRIQS_RUNTIME_ERROR << "make_block_gf(vector<string>, init_list) : size mismatch !";
return {{block_names}, V, nothing{}, nothing{}};
@ -151,9 +153,9 @@ namespace triqs { namespace gfs {
// return { gf_mesh<block_index, Opt> {int(V.size())}, std::move(V), nothing{}, nothing{} } ;
}
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{}} ; }
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 --------------------------------------------------
@ -177,8 +179,7 @@ namespace triqs { namespace gfs {
bool equal(block_gf_iterator const &other) const { return ((mesh_it == other.mesh_it)); }
public:
block_gf_iterator(big_gf_t & bgf, bool at_end = false)
: big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {}
block_gf_iterator(big_gf_t &bgf, bool at_end = false) : big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {}
void increment() { ++mesh_it; }
bool at_end() const { return mesh_it.at_end(); }
};
@ -197,8 +198,8 @@ namespace triqs { namespace gfs {
//----- const iterator
template <typename Target, typename Opt, bool B, bool C>
class block_gf_const_iterator
: public boost::iterator_facade<block_gf_const_iterator<Target, Opt, B, C>, Target, boost::forward_traversal_tag, Target const &> {
class block_gf_const_iterator : public boost::iterator_facade<block_gf_const_iterator<Target, Opt, B, C>, Target,
boost::forward_traversal_tag, Target const &> {
friend class boost::iterator_core_access;
typedef gf_impl<block_index, Target, Opt, B, C> big_gf_t;
big_gf_t const &big_gf;
@ -209,8 +210,7 @@ namespace triqs { namespace gfs {
bool equal(block_gf_const_iterator const &other) const { return ((mesh_it == other.mesh_it)); }
public:
block_gf_const_iterator(big_gf_t const& bgf, bool at_end = false)
: big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {}
block_gf_const_iterator(big_gf_t const &bgf, bool at_end = false) : big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {}
void increment() { ++mesh_it; }
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) {
return {bgf, true};
}
}}
}
}
#endif