TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
imtime.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2013-2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018-2023 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: Thomas Ayral, Philipp Dumitrescu, Olivier Parcollet, Nils Wentzell
19
24
25#pragma once
26
27#include "./bases/linear.hpp"
28#include "./utils.hpp"
29#include "../utility/macros.hpp"
30
31#include <fmt/format.h>
32#include <h5/h5.hpp>
33
34#include <iostream>
35#include <string>
36
37namespace triqs::mesh {
38
43
68 class C2PY_RENAME(MeshImTime) imtime : public detail::linear<imtime, double> {
69 public:
72
81 C2PY_DEPRECATED_PARAMETER_NAME(S : statistic, n_max : n_tau)
82 imtime(double beta = 1.0, statistic_enum statistic = Fermion, long n_tau = 0) : linear(0, beta, n_tau), beta_(beta), stat_(statistic) {}
83
85 bool operator==(imtime const &) const = default;
86
88 [[nodiscard]] C2PY_PROPERTY_GET(beta) double beta() const noexcept { return beta_; }
89
91 [[nodiscard]] C2PY_PROPERTY_GET(statistic) statistic_enum statistic() const noexcept { return stat_; }
92
97 void serialize(auto &ar) const {
98 static_cast<detail::linear<imtime, double> const &>(*this).serialize(ar);
99 ar & beta_ & stat_;
100 }
101
106 void deserialize(auto &ar) {
107 static_cast<detail::linear<imtime, double> &>(*this).deserialize(ar);
108 ar & beta_ & stat_;
109 }
110
112 [[nodiscard]] static std::string hdf5_format() { return "MeshImTime"; }
113
121 friend void h5_write(h5::group g, std::string const &name, imtime const &m) {
122 h5::group gr = g.create_group(name);
123 h5::write_hdf5_format(gr, m); // NOLINT (downcasting to base class)
124 h5::write(gr, "beta", m.beta_);
125 h5::write(gr, "statistic", (m.stat_ == Fermion ? "F" : "B"));
126 h5::write(gr, "n_tau", m.N_);
127 }
128
136 friend void h5_read(h5::group g, std::string const &name, imtime &m) {
137 h5::group gr = g.open_group(name);
138 h5::assert_hdf5_format(gr, m, true); // NOLINT (downcasting to base class)
139
140 // for backward compatibility
141 long N = 0;
142 if (not h5::try_read(gr, "n_tau", N)) h5::read(gr, "size", N);
143 if (gr.has_key("domain")) gr = gr.open_group("domain");
144
145 auto beta = h5::read<double>(gr, "beta");
146 auto statistic = (h5::read<std::string>(gr, "statistic") == "F" ? Fermion : Boson);
147 m = imtime(beta, statistic, N);
148 }
149
157 friend std::ostream &operator<<(std::ostream &sout, imtime const &m) {
158 auto stat_cstr = (m.stat_ == Boson ? "Boson" : "Fermion");
159 return sout << fmt::format("Imaginary time mesh with beta = {}, statistics = {}, N = {}", m.beta_, stat_cstr, m.N_);
160 }
161
162 private:
163 double beta_;
164 statistic_enum stat_;
165 };
166
178 auto evaluate(imtime const &m, auto const &f, double tau) { return m.evaluate(f, tau); }
179
181
182} // namespace triqs::mesh
imtime(double beta=1.0, statistic_enum statistic=Fermion, long n_tau=0)
Construct an imaginary time mesh on the interval with equally spaced mesh points and the given part...
Definition imtime.hpp:82
Mesh point of a triqs::mesh::detail::linear mesh.
Definition linear.hpp:94
Linear mesh type.
Definition linear.hpp:74
auto evaluate(auto const &f, double x) const
Linear interpolation of a function defined on a triqs::mesh::detail::linear mesh at a value .
Definition linear.hpp:364
void serialize(auto &ar) const
Serialize the mesh to a generic archive.
Definition linear.hpp:307
void deserialize(auto &ar)
Deserialize the mesh from a generic archive.
Definition linear.hpp:313
Imaginary time mesh type.
Definition imtime.hpp:68
imtime(double beta=1.0, statistic_enum statistic=Fermion, long n_tau=0)
Construct an imaginary time mesh on the interval with equally spaced mesh points and the given part...
Definition imtime.hpp:82
bool operator==(imtime const &) const =default
Equal-to comparison operator compares , and the particle statistics.
void serialize(auto &ar) const
Serialize the mesh to a generic archive.
Definition imtime.hpp:97
friend std::ostream & operator<<(std::ostream &sout, imtime const &m)
Write a triqs::mesh::imtime mesh to a std::ostream.
Definition imtime.hpp:157
friend void h5_read(h5::group g, std::string const &name, imtime &m)
Read a triqs::mesh::imtime mesh from HDF5.
Definition imtime.hpp:136
friend void h5_write(h5::group g, std::string const &name, imtime const &m)
Write a triqs::mesh::imtime mesh to HDF5.
Definition imtime.hpp:121
double beta() const noexcept
Get the inverse temperature .
Definition imtime.hpp:88
statistic_enum statistic() const noexcept
Get the particle statistics.
Definition imtime.hpp:91
detail::linear< imtime, double >::mesh_point_t mesh_point_t
Mesh point type of a triqs::mesh::imtime mesh (see triqs::mesh::detail::linear::mesh_point_t).
Definition imtime.hpp:71
void deserialize(auto &ar)
Deserialize the mesh from a generic archive.
Definition imtime.hpp:106
static std::string hdf5_format()
Get the HDF5 format tag.
Definition imtime.hpp:112
statistic_enum
Enum to specify particle statistics.
Definition utils.hpp:163
Provides a linear mesh type with equally spaced mesh points on an interval.
Common macros used in TRIQS.
Provides various utilities used with Meshes.