TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
h5.hpp
Go to the documentation of this file.
1// Copyright (c) 2016-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2016-2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018-2020 Simons Foundation
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You may obtain a copy of the License at
16// https://www.gnu.org/licenses/gpl-3.0.txt
17//
18// Authors: Michel Ferrero, Olivier Parcollet, Nils Wentzell
19
24
25#pragma once
26
29#include "./gf/gf.hpp"
30#include "./gf/gf_view.hpp"
31
32#include "../mesh/imfreq.hpp"
33
34namespace triqs::gfs {
35
36 /*------------------------------------------------------------------------------------------------------
37 * HDF5
38 *-----------------------------------------------------------------------------------------------------*/
39
40 // True if G's target type is exactly Target.
41 template <typename G, typename Target> constexpr bool gf_has_target() { return std::is_same_v<typename G::target_t, Target>; }
42 /*
43 // ---------------------------
44
45 // Some work that may be necessary before writing (some compression, see imfreq)
46 // Default : do nothing
47 template <typename M, typename T> struct gf_h5_before_write {
48 template <typename G> static G const &invoke(h5::group gr, G const &g) { return g; }
49 };
50
51 // Before writing to h5, check if I can save the positive freq only
52 template <typename T> struct gf_h5_before_write<imfreq, T> {
53 template <typename G> static gf_const_view<imfreq, T> invoke(h5::group gr, G const &g) {
54 if (is_gf_real_in_tau(g, 1.e-13)) return positive_freq_view(g);
55 return g;
56 }
57 };
58*/
59 // ---------------------------
60
61 // FIXME : C17 : REMOVE THIS dispatch with a constexpr if
62 // Some work that may be necessary after the read (for backward compatibility e.g.)
63 // Default : do nothing
64 template <typename M, typename T> struct gf_h5_after_read {
65 template <typename G> static void invoke(h5::group, G &) {}
66 };
67
68 // After reading from h5, is the function is for freq >0, unfold it to the full mesh
69 template <typename T> struct gf_h5_after_read<mesh::imfreq, T> {
70 template <typename G> static void invoke(h5::group, G &g) {
71 if (g.mesh().positive_only()) g = make_gf_from_real_gf(make_const_view(g));
72 }
73 };
74 // same, for python interface
75 template <typename T> gf<mesh::imfreq, T> _gf_h5_after_read(gf_view<mesh::imfreq, T> g) {
76 if (g.mesh().positive_only())
78 else
79 return g;
80 }
81
82 // ---------------------------
83
95 template <typename V, typename T> struct gf_h5_rw {
96
97 //template <typename G> static void write(h5::group gr, G const &g) { _write(gr, gf_h5_before_write<V, T>::invoke(gr, g)); }
98
99 template <typename G> static void write(h5::group gr, G const &g) {
100 // write the data
101 //constexpr bool _can_compress = (gf_has_target<G, imtime>() or gf_has_target<G, legendre>());
102 //if (_can_compress and is_gf_real(g))
103 // h5_write(gr, "data", array<double, G::data_t::rank>(real(g.data())));
104 //else
105 h5_write(gr, "data", g.data());
106 h5_write(gr, "mesh", g._mesh);
107 }
108
109 template <typename G> static void read(h5::group gr, G &g) {
110 h5_read(gr, "data", g._data);
111 h5_read(gr, "mesh", g._mesh);
112 gf_h5_after_read<V, T>::invoke(gr, g);
113 }
114 };
115
116} // namespace triqs::gfs
friend void h5_read(h5::group fg, std::string const &subgroup_name, this_t &g)
Read a block Green's function from HDF5.
friend void h5_write(h5::group fg, std::string const &subgroup_name, this_t const &g)
Write a block Green's function to HDF5.
A mutable, non-owning view of a Green's function.
Definition gf_view.hpp:48
The owning Green's function container.
Definition gf.hpp:194
Imaginary frequency mesh type.
Definition imfreq.hpp:102
Provides tail fitting, slicing, inversion, reality and matrix-multiplication functions for Green's fu...
Provides a mutable non-owning view of a Green's function.
Provides Matsubara-frequency-specific functions and reality / hermiticity helpers for Green's functio...
Provides the Green's function class.
gf< mesh::imfreq, T > make_gf_from_real_gf(gf_const_view< mesh::imfreq, T, Layout > g)
Build a full-mesh Matsubara Green's function from one defined on positive frequencies only.
Definition imfreq.hpp:62
auto make_const_view(Gf const &g)
Make a const view of a Green's function.
Provides a mesh type on the imaginary frequency axis.
Traits class for reading/writing a Green's function from/to HDF5.
Definition h5.hpp:95