/******************************************************************************* * * TRIQS: a Toolbox for Research in Interacting Quantum Systems * * Copyright (C) 2012-2014 by 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 . * ******************************************************************************/ #pragma once #include "./tools.hpp" #include "./gf.hpp" #include "./local/tail.hpp" namespace triqs { namespace gfs { template void assign_singularity_from_function(gf_impl &s, RHS const &rhs) { auto t = tail_omega(s.get_from_linear_index(0)); // a bit faster to first replace (some part of expression are precomputed). clef::placeholder<0> x_; //auto expr = rhs(x_, t); //for (auto x : s.mesh()) s[x] = eval(expr, x_ = x); for (auto x : s.mesh()) s[x] = rhs(x, t); } /// --------------------------- singularity --------------------------------- template struct gf_default_singularity, Target> { using S1 = typename gf_default_singularity::type; using S2 = typename gf_default_singularity::type; // type is nothing unless S1 is nothing and S2 is not, or 1 <-> 2 using type = std14::conditional_t < is_nothing() && (!is_nothing()), gf, std14::conditional_t < is_nothing() && (!is_nothing()), gf, nothing >> ; }; namespace gfs_implementation { /// --------------------------- hdf5 --------------------------------- template struct h5_name { static std::string invoke() { return "xxxxx"; } }; template struct h5_rw { static void write(h5::group gr, gf_const_view g) { // for (size_t i = 0; i < g.mesh().size(); ++i) h5_write(gr, std::to_string(i), g._data[i]); // h5_write(gr,"symmetry",g._symmetry); } template static void read(h5::group gr, gf_impl &g) { // does not work : need to read the block name and remake the mesh... // g._mesh = gf_mesh(gr.get_all_subgroup_names()); // g._data.resize(g._mesh.size()); // 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]); // h5_read(gr,"symmetry",g._symmetry); } }; // --------------------------- data access --------------------------------- template struct data_proxy { struct storage_t { arrays::array data; arrays::array mask; int omin; }; struct storage_view_t { arrays::array_view data; arrays::array_view mask; int omin; template storage_view_t(S &s): data(s.data), mask(s.mask), omin(s.omin){} }; struct storage_const_view_t { arrays::array_const_view data; arrays::array_const_view mask; int omin; template storage_const_view_t(S &s): data(s.data), mask(s.mask), omin(s.omin){} }; // from the shape of the mesh and the target, make the shape of the array. default is to glue them // template static auto join_shape(S1 const &s1, S2 const &s2) { return make_shape(join(s1, s2); } template static void assign_to_scalar(S &data, RHS &&rhs) { data() = std::forward(rhs); } template static void rebind(ST &data, RHS &&rhs) { data.rebind(rhs.data()); } template tail_view operator()(S &data, int i) const { return {data.data(i, arrays::ellipsis()), data.mask, data.omin}; } template tail_const_view operator()(S const &data, int i) const { return {data.data(i, arrays::ellipsis()), data.mask, data.omin}; } }; // ------------------------------- Factory for data -------------------------------------------------- template struct data_factory { using mesh_t = gf_mesh; using gf_t = gf; using target_shape_t = arrays::mini_vector; // struct target_shape_t {}; using aux_t = nothing; static typename gf_t::data_t make(mesh_t const &m, target_shape_t sh, aux_t) { auto t = tail(sh); // build a defaut tail // and duplicate it over the mesh size return {arrays::array{t.data().shape().front_append(m.size())}, arrays::array{t.shape()}, t.order_min()}; } }; // ------------------------------- Factory for singularity -------------------------------------------------- template struct singularity_factory, Target, gf, Opt> { template static gf make(gf_mesh, Opt> const &m, TargetShape shape) { return {std::get<0>(m.components()), shape}; } }; // ------------------------------- partial_eval -------------------------------------------------- template struct partial_eval_impl { using gv_t = gf_view; template static auto invoke(gv_t g, T const &... x) { return invoke_impl(g, std14::index_sequence(), x...); } template static tail_view invoke_impl(gv_t g, std14::index_sequence<0>, T const &x) { return g.get_from_linear_index(x); } template static gv_t invoke_impl(gv_t g, std14::index_sequence<1>, T const &x) { return g; } }; } // gfs_implementation }}