From f6fa63c9b35e4e2254d1ae430d630ce53e1cdeba Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Mon, 29 Jul 2013 17:56:31 +0200 Subject: [PATCH] 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 --- triqs/gfs/gf.hpp | 14 ++++++++++++-- triqs/gfs/imfreq.hpp | 3 +-- triqs/gfs/imtime.hpp | 3 +-- triqs/gfs/legendre.hpp | 2 +- triqs/gfs/re_im_time.hpp | 2 +- triqs/gfs/refreq.hpp | 3 +-- triqs/gfs/refreq_imtime.hpp | 2 +- triqs/gfs/retime.hpp | 3 +-- 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/triqs/gfs/gf.hpp b/triqs/gfs/gf.hpp index d35adfe6..820d1840 100644 --- a/triqs/gfs/gf.hpp +++ b/triqs/gfs/gf.hpp @@ -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 struct h5_name; // value is a const char * + template struct h5_name { static std::string invoke(){ return h5_name::invoke() + "_s";}}; + template struct h5_ops { template static void write(h5::group g, std::string const & s, DataType const & data, GF const &) { h5_write(g,"data",data); } template 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::invoke();} + friend std::string get_triqs_hdf5_data_scheme(gf_impl const & g) { return "Gf" + gfs_implementation::h5_name::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::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(g.mesh(), g.data()(range(), args... ), sg , g.symmetry()); + return gf_view(g.mesh(), g.data()(range(), args... ), sg, g.symmetry()); + } + + // a scalar_valued gf can be viewed as a 1x1 matrix + template + gf_view reinterpret_scalar_valued_gf_as_matrix_valued (gf_impl const & g) { + typedef arrays::array_view::storage_t::value_type,3> a_t; + auto a = a_t {typename a_t::indexmap_type (arrays::mini_vector(g.data().shape()[0],1,1)), g.data().storage()}; + return gf_view(g.mesh(), a, g.singularity(), g.symmetry()); } /* diff --git a/triqs/gfs/imfreq.hpp b/triqs/gfs/imfreq.hpp index c680f88e..535e4bcd 100644 --- a/triqs/gfs/imfreq.hpp +++ b/triqs/gfs/imfreq.hpp @@ -47,8 +47,7 @@ namespace triqs { namespace gfs { template struct singularity { typedef local::tail type;}; //h5 name - template struct h5_name { static std::string invoke(){ return "GfImFreq";}}; - template struct h5_name { static std::string invoke(){ return "GfImFreq_s";}}; + template struct h5_name { static std::string invoke(){ return "ImFreq";}}; /// --------------------------- evaluator --------------------------------- template diff --git a/triqs/gfs/imtime.hpp b/triqs/gfs/imtime.hpp index 4a160a9c..30b46aea 100644 --- a/triqs/gfs/imtime.hpp +++ b/triqs/gfs/imtime.hpp @@ -46,8 +46,7 @@ namespace triqs { namespace gfs { template struct singularity { typedef local::tail type;}; // h5 name - template struct h5_name { static std::string invoke(){ return "GfImTime";}}; - template struct h5_name { static std::string invoke(){ return "GfImTime_s";}}; + template struct h5_name { static std::string invoke(){ return "ImTime";}}; /// --------------------------- data access --------------------------------- diff --git a/triqs/gfs/legendre.hpp b/triqs/gfs/legendre.hpp index 04cc8597..c0e4c240 100644 --- a/triqs/gfs/legendre.hpp +++ b/triqs/gfs/legendre.hpp @@ -40,7 +40,7 @@ namespace triqs { namespace gfs { }; // h5 name - template struct h5_name { static std::string invoke(){ return "GfLegendre";}}; + template struct h5_name { static std::string invoke(){ return "Legendre";}}; /// --------------------------- evaluator --------------------------------- diff --git a/triqs/gfs/re_im_time.hpp b/triqs/gfs/re_im_time.hpp index 391f3393..834a0f2d 100644 --- a/triqs/gfs/re_im_time.hpp +++ b/triqs/gfs/re_im_time.hpp @@ -102,7 +102,7 @@ namespace triqs { namespace gfs { void assign_from_expression (gf_impl const &, RHS) {} //slices - gf_view slice_mesh_imtime (gf_view g, size_t index) { + inline gf_view slice_mesh_imtime (gf_view 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() }; } diff --git a/triqs/gfs/refreq.hpp b/triqs/gfs/refreq.hpp index 7653fdc1..b94f47bd 100644 --- a/triqs/gfs/refreq.hpp +++ b/triqs/gfs/refreq.hpp @@ -45,8 +45,7 @@ namespace triqs { namespace gfs { template struct singularity { typedef local::tail type;}; // h5 name - template struct h5_name { static std::string invoke(){ return "GfReFreq";}}; - template struct h5_name { static std::string invoke(){ return "GfReFreq_s";}}; + template struct h5_name { static std::string invoke(){ return "ReFreq";}}; /// --------------------------- evaluator --------------------------------- template diff --git a/triqs/gfs/refreq_imtime.hpp b/triqs/gfs/refreq_imtime.hpp index 07707723..ea7010d5 100644 --- a/triqs/gfs/refreq_imtime.hpp +++ b/triqs/gfs/refreq_imtime.hpp @@ -96,7 +96,7 @@ namespace triqs { namespace gfs { } // gfs_implementation //slices - gf_view slice_mesh_imtime (gf_view g, size_t index) { + inline gf_view slice_mesh_imtime (gf_view 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() }; } diff --git a/triqs/gfs/retime.hpp b/triqs/gfs/retime.hpp index 11e2d7d5..dbddfa8f 100644 --- a/triqs/gfs/retime.hpp +++ b/triqs/gfs/retime.hpp @@ -47,8 +47,7 @@ namespace triqs { namespace gfs { template struct singularity { typedef local::tail type;}; // h5 name - template struct h5_name { static std::string invoke(){ return "GfReTime";}}; - template struct h5_name { static std::string invoke(){ return "GfReTime_s";}}; + template struct h5_name { static std::string invoke(){ return "ReTime";}}; /// --------------------------- evaluator --------------------------------- template