std::vector<size_t> get_array_lengths(int R, h5::group g, std::string const& name, bool is_complex) { h5::dataset ds = g.open_dataset(name); h5::dataspace d_space = H5Dget_space(ds); int Rank = R + (is_complex ? 1 : 0); int rank = H5Sget_simple_extent_ndims(d_space); if (rank != Rank) TRIQS_RUNTIME_ERROR << "triqs::array::h5::read. Rank mismatch : the array has rank = " << Rank << " while the array stored in the hdf5 file has rank = " << rank; std::vector<size_t> d2(R); hsize_t dims_out[rank]; H5Sget_simple_extent_dims(d_space, dims_out, NULL); for (int u = 0; u < R; ++u) d2[u] = dims_out[u]; return d2; }
std::c14::enable_if_t<is_amv_value_or_view_class<ArrayType>::value && !has_scalar_or_string_value_type<ArrayType>::value> h5_write(h5::group gr, std::string name, ArrayType const& a) { if (a.is_empty()) TRIQS_RUNTIME_ERROR << " Cannot save an empty array into hdf5"; auto gr2 = gr.create_group(name); gr2.write_triqs_hdf5_data_scheme(a); // save the shape array<int, 1> sha(ArrayType::rank); for (int u = 0; u < ArrayType::rank; ++u) sha(u) = a.shape()[u]; h5_write(gr2, "shape", sha); #ifndef __cpp_generic_lambdas foreach(a, h5_impl::_save_lambda<ArrayType>{a, gr2}); #else foreach(a, [&](auto... is) { h5_write(gr2, h5_impl::_h5_name(is...), a(is...)); }); #endif }
std::c14::enable_if_t<is_amv_value_or_view_class<ArrayType>::value && !has_scalar_or_string_value_type<ArrayType>::value> h5_read(h5::group gr, std::string name, ArrayType& a) { static_assert(!std::is_const<ArrayType>::value, "Cannot read in const object"); auto gr2 = gr.open_group(name); // TODO checking scheme... // load the shape auto sha2 = a.shape(); array<int, 1> sha; h5_read(gr2, "shape", sha); if (first_dim(sha) != sha2.size()) TRIQS_RUNTIME_ERROR << " array<array<...>> load : rank mismatch. Expected " << sha2.size()<< " Got " << first_dim(sha); for (int u = 0; u < sha2.size(); ++u) sha2[u] = sha(u); if (a.shape() != sha2) a.resize(sha2); #ifndef __cpp_generic_lambdas foreach(a, h5_impl::_load_lambda<ArrayType>{a, gr2}); #else foreach(a, [&](auto... is) { h5_read(gr2, h5_impl::_h5_name(is...), a(is...)); }); #endif }
/// Write into HDF5 friend void h5_write(h5::group fg, std::string subgroup_name, gf_mesh const& m) { h5::group gr = fg.create_group(subgroup_name); h5_write(gr, "dims", m.dims.to_vector()); }
/** @param fg Parent HDF5 group to write the space to @param name Name of the HDF5 subgroup to be created @param hs Hilbert subspace to be written */ friend void h5_write(h5::group fg, std::string const &name, sub_hilbert_space const &hs) { auto gr = fg.create_group(name); h5_write(gr, "index", hs.index); h5_write(gr, "fock_states", hs.fock_states); }
/** @param fg Parent HDF5 group to read the space from @param name Name of the HDF5 subgroup to be read @param hs Reference to a target Hilbert space object */ friend void h5_read(h5::group fg, std::string const &name, hilbert_space &hs) { auto gr = fg.open_group(name); h5_read(gr, "dim", hs.dim); }
/** @param fg Parent HDF5 group to write the space to @param name Name of the HDF5 subgroup to be created @param hs Hilbert space to be written */ friend void h5_write(h5::group fg, std::string const &name, hilbert_space const &hs) { auto gr = fg.create_group(name); h5_write(gr, "dim", hs.dim); }
/// Read from HDF5 friend void h5_read(h5::group fg, std::string subgroup_name, discrete_mesh &m) { h5::group gr = fg.open_group(subgroup_name); typename discrete_mesh::domain_t dom; h5_read(gr, "domain", dom); m = discrete_mesh(std::move(dom)); }
/// Write into HDF5 friend void h5_write(h5::group fg, std::string subgroup_name, discrete_mesh const &m) { h5::group gr = fg.create_group(subgroup_name); h5_write(gr, "domain", m.domain()); }
/// Read from HDF5 friend void h5_read(h5::group fg, std::string subgroup_name, gf_mesh &m) { h5::group gr = fg.open_group(subgroup_name); auto l = [gr](int N, auto &m) { h5_read(gr, "MeshComponent" + std::to_string(N), m); }; triqs::tuple::for_each_enumerate(m.components(), l); }
// HDF5 interface friend void h5_write (h5::group g, std::string const & name, measure_set const & ms) { auto gr = g.create_group(name); for (auto & p : ms.m_map) h5_write(gr,p.first, p.second); }
friend void h5_read(h5::group fg, std::string subgroup_name, tail_impl &t) { auto gr = fg.open_group(subgroup_name); h5_read(gr, "omin", t.omin); h5_read(gr, "mask", t._mask); h5_read(gr, "data", t._data); }
friend void h5_write(h5::group fg, std::string subgroup_name, tail_impl const &t) { auto gr = fg.create_group(subgroup_name); h5_write(gr, "omin", t.omin); h5_write(gr, "mask", t._mask); h5_write(gr, "data", t._data); }
/// Read from HDF5 void h5_read(h5::group fg, std::string subgroup_name, bravais_lattice& bl) { h5::group gr = fg.open_group(subgroup_name); matrix<double> u; h5_read(gr, "units", u); bl = bravais_lattice{u}; // NOT COMPLETE }
/// Write into HDF5 void h5_write(h5::group fg, std::string subgroup_name, bravais_lattice const& bl) { h5::group gr = fg.create_group(subgroup_name); h5_write(gr, "units", bl.units_); // NOT COMPLETE }
/// Read from HDF5 void h5_read(h5::group fg, std::string subgroup_name, brillouin_zone& bz) { h5::group gr = fg.open_group(subgroup_name); bravais_lattice bl; h5_read(gr, "bravais_lattice", bl); bz = brillouin_zone{bl}; }
//------------------------------------------------------------------------------------ /// Write into HDF5 void h5_write(h5::group fg, std::string subgroup_name, brillouin_zone const& bz) { h5::group gr = fg.create_group(subgroup_name); h5_write(gr, "bravais_lattice", bz.lattice_); }
/// Read from HDF5 friend void h5_read(h5::group fg, std::string subgroup_name, gf_mesh& m) { h5::group gr = fg.open_group(subgroup_name); auto dims = h5::h5_read<std::vector<int>>(gr, "dims"); m = gf_mesh(dims[0], dims[1], dims[2]); }
/// Write into HDF5 friend void h5_write(h5::group fg, std::string subgroup_name, matsubara_domain const &d) { h5::group gr = fg.create_group(subgroup_name); h5_write(gr, "beta", d.beta); h5_write(gr, "statistic", (d.statistic == Fermion ? "F" : "B")); }
friend void h5_read (h5::group g, std::string const & name, measure_set & ms) { auto gr = g.open_group(name); for (auto & p : ms.m_map) h5_read(gr,p.first, p.second); }
/// Write into HDF5 friend void h5_write(h5::group fg, std::string subgroup_name, gf_mesh const &m) { h5::group gr = fg.create_group(subgroup_name); h5_write(gr, "domain", m.domain()); h5_write(gr, "size", long(m.size())); h5_write(gr, "positive_freq_only", (m._positive_only?1:0)); }