3
0
mirror of https://github.com/triqs/dft_tools synced 2024-10-31 11:13:46 +01:00

gf: clean h5name

- _s automatically done for scalar_valued.
- add simple reinterpretation of gf scalar to matrix view to
easy h5 saving to plot in python
This commit is contained in:
Olivier Parcollet 2013-07-29 17:56:31 +02:00
parent c5c016aa79
commit f6fa63c9b3
8 changed files with 19 additions and 13 deletions

View File

@ -64,6 +64,8 @@ namespace triqs { namespace gfs {
// This trait contains functions to read/write in hdf5 files. Can be specialized for some descriptor (Cf block)
template <typename Variable, typename Target, typename Opt> struct h5_name; // value is a const char *
template<typename Variable, typename Opt> struct h5_name<Variable,scalar_valued,Opt> { static std::string invoke(){ return h5_name<Variable,matrix_valued,Opt>::invoke() + "_s";}};
template <typename Variable, typename Target, typename Opt> struct h5_ops {
template<typename DataType, typename GF> static void write(h5::group g, std::string const & s, DataType const & data, GF const &) { h5_write(g,"data",data); }
template<typename DataType, typename GF> static void read (h5::group g, std::string const & s, DataType & data, GF const &) { h5_read(g,"data",data);}
@ -248,7 +250,7 @@ namespace triqs { namespace gfs {
//----------------------------- HDF5 -----------------------------
friend std::string get_triqs_hdf5_data_scheme(gf_impl const & g) { return gfs_implementation::h5_name<Variable,Target,Opt>::invoke();}
friend std::string get_triqs_hdf5_data_scheme(gf_impl const & g) { return "Gf" + gfs_implementation::h5_name<Variable,Target,Opt>::invoke();}
/// Write into HDF5
friend void h5_write (h5::group fg, std::string subgroup_name, gf_impl const & g) {
@ -407,7 +409,15 @@ namespace triqs { namespace gfs {
static_assert(std::is_same<Target,matrix_valued>::value, "slice_target only for matrix_valued GF's");
using arrays::range;
auto sg=slice_target (g.singularity(),range(args,args+1)...);
return gf_view<Variable,scalar_valued,Opt>(g.mesh(), g.data()(range(), args... ), sg , g.symmetry());
return gf_view<Variable,scalar_valued,Opt>(g.mesh(), g.data()(range(), args... ), sg, g.symmetry());
}
// a scalar_valued gf can be viewed as a 1x1 matrix
template<typename Variable, typename Opt, bool V, typename... Args>
gf_view<Variable,matrix_valued,Opt> reinterpret_scalar_valued_gf_as_matrix_valued (gf_impl<Variable,scalar_valued,Opt,V> const & g) {
typedef arrays::array_view<typename gfs_implementation::data_proxy<Variable,matrix_valued,Opt>::storage_t::value_type,3> a_t;
auto a = a_t {typename a_t::indexmap_type (arrays::mini_vector<size_t,3>(g.data().shape()[0],1,1)), g.data().storage()};
return gf_view<Variable,matrix_valued,Opt>(g.mesh(), a, g.singularity(), g.symmetry());
}
/*

View File

@ -47,8 +47,7 @@ namespace triqs { namespace gfs {
template<typename Opt> struct singularity<imfreq,scalar_valued,Opt> { typedef local::tail type;};
//h5 name
template<typename Opt> struct h5_name<imfreq,matrix_valued,Opt> { static std::string invoke(){ return "GfImFreq";}};
template<typename Opt> struct h5_name<imfreq,scalar_valued,Opt> { static std::string invoke(){ return "GfImFreq_s";}};
template<typename Opt> struct h5_name<imfreq,matrix_valued,Opt> { static std::string invoke(){ return "ImFreq";}};
/// --------------------------- evaluator ---------------------------------
template<typename Opt, typename Target>

View File

@ -46,8 +46,7 @@ namespace triqs { namespace gfs {
template<typename Opt> struct singularity<imtime,scalar_valued,Opt> { typedef local::tail type;};
// h5 name
template<typename Opt> struct h5_name<imtime,matrix_valued,Opt> { static std::string invoke(){ return "GfImTime";}};
template<typename Opt> struct h5_name<imtime,scalar_valued,Opt> { static std::string invoke(){ return "GfImTime_s";}};
template<typename Opt> struct h5_name<imtime,matrix_valued,Opt> { static std::string invoke(){ return "ImTime";}};
/// --------------------------- data access ---------------------------------

View File

@ -40,7 +40,7 @@ namespace triqs { namespace gfs {
};
// h5 name
template<typename Opt> struct h5_name<legendre,matrix_valued,Opt> { static std::string invoke(){ return "GfLegendre";}};
template<typename Opt> struct h5_name<legendre,matrix_valued,Opt> { static std::string invoke(){ return "Legendre";}};
/// --------------------------- evaluator ---------------------------------

View File

@ -102,7 +102,7 @@ namespace triqs { namespace gfs {
void assign_from_expression (gf_impl<Variable,Target,Opt,V> const &, RHS) {}
//slices
gf_view<retime,scalar_valued> slice_mesh_imtime (gf_view<re_im_time,scalar_valued> g, size_t index) {
inline gf_view<retime,scalar_valued> slice_mesh_imtime (gf_view<re_im_time,scalar_valued> g, size_t index) {
auto arr = reinterpret_linear_array(g.mesh(),g.data()); // view it as a 2d array
return { std::get<0>(g.mesh().components()), arr(arrays::range(), index), local::tail(1,1), nothing() };
}

View File

@ -45,8 +45,7 @@ namespace triqs { namespace gfs {
template<typename Opt> struct singularity<refreq,scalar_valued,Opt> { typedef local::tail type;};
// h5 name
template<typename Opt> struct h5_name<refreq,matrix_valued,Opt> { static std::string invoke(){ return "GfReFreq";}};
template<typename Opt> struct h5_name<refreq,scalar_valued,Opt> { static std::string invoke(){ return "GfReFreq_s";}};
template<typename Opt> struct h5_name<refreq,matrix_valued,Opt> { static std::string invoke(){ return "ReFreq";}};
/// --------------------------- evaluator ---------------------------------
template<typename Opt, typename Target>

View File

@ -96,7 +96,7 @@ namespace triqs { namespace gfs {
} // gfs_implementation
//slices
gf_view<refreq,scalar_valued> slice_mesh_imtime (gf_view<refreq_imtime,scalar_valued> g, size_t index) {
inline gf_view<refreq,scalar_valued> slice_mesh_imtime (gf_view<refreq_imtime,scalar_valued> g, size_t index) {
auto arr = reinterpret_linear_array(g.mesh(),g.data()); // view it as a 2d array
return { std::get<0>(g.mesh().components()), arr(arrays::range(),index), local::tail(1,1), nothing() };
}

View File

@ -47,8 +47,7 @@ namespace triqs { namespace gfs {
template<typename Opt> struct singularity<retime,scalar_valued,Opt> { typedef local::tail type;};
// h5 name
template<typename Opt> struct h5_name<retime,matrix_valued,Opt> { static std::string invoke(){ return "GfReTime";}};
template<typename Opt> struct h5_name<retime,scalar_valued,Opt> { static std::string invoke(){ return "GfReTime_s";}};
template<typename Opt> struct h5_name<retime,matrix_valued,Opt> { static std::string invoke(){ return "ReTime";}};
/// --------------------------- evaluator ---------------------------------
template<typename Opt, typename Target>