32#include <cppdlr/cppdlr.hpp>
34#include <fmt/format.h>
35#include <itertools/itertools.hpp>
45namespace triqs::mesh {
80 class C2PY_RENAME(MeshDLRImFreq) dlr_imfreq {
119 :
matsubara_freq(n_l, b, stat), data_index_(d), mesh_hash_(mhash) {}
122 [[nodiscard]]
long index()
const {
return n; }
125 [[nodiscard]]
long data_index()
const {
return data_index_; }
131 [[nodiscard]] uint64_t
mesh_hash() const noexcept {
return mesh_hash_; }
134 long data_index_ = 0;
135 uint64_t mesh_hash_ = 0;
140 dlr_imfreq(
double beta,
statistic_enum statistic,
double w_max,
double eps,
bool symmetrize, nda::vector<double>
const &dlr_freq)
141 :
dlr_imfreq(beta, statistic, w_max, eps, symmetrize,
142 detail::dlr_ops{.freq = dlr_freq,
143 .imt = {w_max * beta, dlr_freq, symmetrize},
144 .imf = {w_max * beta, dlr_freq,
static_cast<cppdlr::statistic_t
>(statistic), symmetrize}}) {}
147 dlr_imfreq(
double beta, statistic_enum statistic,
double w_max,
double eps,
bool symmetrize, detail::dlr_ops dlr)
152 symmetrize_(symmetrize),
153 mesh_hash_(
hash(beta, statistic, w_max, eps, symmetrize,
hash_bytes(dlr.imf.get_ifnodes()), std::string_view{
"dlr_imfreq"})),
154 dlr_{std::make_shared<detail::dlr_ops>(std::move(dlr))} {}
183 template <nda::AnyOf<dlr_imtime, dlr> M>
189 symmetrize_(m.symmetrize_),
190 mesh_hash_(
hash(beta_, stat_, w_max_, eps_, symmetrize_,
hash_bytes(m.dlr_->imf.get_ifnodes()), std::string_view{
"dlr_imfreq"})),
194 bool operator==(dlr_imfreq
const &m)
const {
return mesh_hash_ == m.mesh_hash_; }
221 [[nodiscard]]
long to_index(
long d)
const noexcept {
244 return {beta_, stat_, dlr_->imf.get_ifnodes()[l], l, mesh_hash_};
256 return {dlr_->imf.get_ifnodes()[l], beta_, stat_};
260 [[nodiscard]] C2PY_PROPERTY_GET(
beta)
double beta() const noexcept {
return beta_; }
266 [[nodiscard]] C2PY_PROPERTY_GET(
w_max)
double w_max() const noexcept {
return w_max_; }
269 [[nodiscard]] C2PY_PROPERTY_GET(
eps)
double eps() const noexcept {
return eps_; }
275 [[nodiscard]] C2PY_PROPERTY_GET(
dlr_freq)
auto const &
dlr_freq()
const {
return dlr_->freq; }
278 [[nodiscard]] C2PY_IGNORE
auto const &
dlr_it()
const {
return dlr_->imt; }
281 [[nodiscard]] C2PY_IGNORE
auto const &
dlr_if()
const {
return dlr_->imf; }
284 [[nodiscard]] C2PY_PROPERTY_GET(
mesh_hash) uint64_t
mesh_hash() const noexcept {
return mesh_hash_; }
288 return std::pair<matsubara_freq, matsubara_freq>{(*this)(0).value(), (*this)(
size() - 1).value()};
292 [[nodiscard]]
long size() const noexcept {
return (dlr_ ? dlr_->imf.get_ifnodes().size() : 0); }
304 [[nodiscard]]
auto cend()
const {
return end(); }
313 friend std::ostream &
operator<<(std::ostream &sout, dlr_imfreq
const &m) {
314 auto stat_cstr = (m.stat_ == Boson ?
"Boson" :
"Fermion");
315 return sout << fmt::format(
"DLR imaginary frequency mesh of size {} with beta = {}, statistics = {}, w_max = {}, eps = {}, symmetrized = {}",
316 m.
size(), m.beta_, stat_cstr, m.w_max_, m.eps_, m.symmetrize_);
325 ar & beta_ & stat_ & w_max_ & eps_ & symmetrize_ & mesh_hash_ & dlr_->freq;
326 dlr_->imt.serialize(ar);
327 dlr_->imf.serialize(ar);
335 nda::vector<double> freq;
336 cppdlr::imtime_ops imt;
337 cppdlr::imfreq_ops imf;
338 ar & beta_ & stat_ & w_max_ & eps_ & symmetrize_ & mesh_hash_ & freq;
341 dlr_ = std::make_shared<detail::dlr_ops>(freq, imt, imf);
345 [[nodiscard]]
static std::string
hdf5_format() {
return "MeshDLRImFreq"; }
354 friend void h5_write(h5::group g, std::string
const &name, dlr_imfreq
const &m) {
355 h5::group gr = g.create_group(name);
356 h5::write_hdf5_format(gr, m);
357 h5::write(gr,
"beta", m.beta_);
358 h5::write(gr,
"statistic", (m.stat_ == Fermion ?
"F" :
"B"));
359 h5::write(gr,
"w_max", m.w_max_);
360 h5::write(gr,
"eps", m.eps_);
361 h5::write(gr,
"symmetrize", m.symmetrize_);
362 h5::write(gr,
"dlr_freq", m.
dlr_freq());
363 h5::write(gr,
"dlr_it", m.
dlr_it());
364 h5::write(gr,
"dlr_if", m.
dlr_if());
374 friend void h5_read(h5::group g, std::string
const &name, dlr_imfreq &m) {
375 h5::group gr = g.open_group(name);
376 h5::assert_hdf5_format(gr, m,
true);
377 auto b = h5::read<double>(gr,
"beta");
378 auto stat = (h5::read<std::string>(gr,
"statistic") ==
"F" ? Fermion : Boson);
379 auto wmax = h5::read<double>(gr,
"w_max");
380 auto epsilon = h5::read<double>(gr,
"eps");
382 h5::try_read(gr,
"symmetrize", sym);
383 auto freq = h5::read<nda::vector<double>>(gr,
"dlr_freq");
384 auto imt = h5::read<cppdlr::imtime_ops>(gr,
"dlr_it");
385 auto imf = h5::read<cppdlr::imfreq_ops>(gr,
"dlr_if");
386 m = dlr_imfreq(b, stat, wmax, epsilon, sym, {.freq = freq, .imt = imt, .imf = imf});
398 bool symmetrize_ =
false;
399 uint64_t mesh_hash_ = 0;
400 std::shared_ptr<const detail::dlr_ops> dlr_ = {};
iterator end()
Get an iterator past the last block.
iterator begin()
Get an iterator to the first block.
int size() const
Get the total number of blocks.
mesh_point_t()=default
Default constructor leaves the mesh point uninitialized.
Mesh point of a triqs::mesh::dlr_imfreq mesh.
dlr_imfreq mesh_t
Parent mesh type.
long index() const
Get the Matsubara index of the mesh point.
mesh_point_t(double b, statistic_enum stat, long n_l, long d, uint64_t mhash)
Construct a mesh point with the given parameters.
mesh_point_t()=default
Default constructor leaves the mesh point uninitialized.
uint64_t mesh_hash() const noexcept
Get the hash value of the parent mesh.
matsubara_freq const & value() const
Get the corresponding Matsubara frequency .
long data_index() const
Get the data index of the mesh point.
Imaginary frequency discrete Lehmann representation (DLR) mesh type.
bool is_index_valid(long l) const noexcept
Check if an index is valid.
long to_data_index(long l) const noexcept
Map an index to its corresponding data index .
mesh_point_t operator[](long d) const
Subscript operator to access a mesh point by its data index .
void deserialize(auto &ar)
Deserialize the mesh from a generic archive.
void serialize(auto &ar) const
Serialize the mesh to a generic archive.
auto const & dlr_if() const
Get the Matsubara frequency DLR operations object (see also cppdlr::imfreq_ops).
dlr_imfreq(double beta, statistic_enum statistic, double w_max, double eps, bool symmetrize=true)
Construct an imaginary frequency DLR mesh with a given energy cutoff and error tolerance .
friend void h5_read(h5::group g, std::string const &name, dlr_imfreq &m)
Read a triqs::mesh::dlr_imfreq mesh from HDF5.
auto end() const
Get an iterator to the end of the mesh.
double w_max() const noexcept
Get the DLR energy cutoff .
statistic_enum statistic() const noexcept
Get the particle statistics.
auto cend() const
Get a const iterator to the end of the mesh.
long size() const noexcept
Get the size of the mesh, i.e. the DLR rank .
friend std::ostream & operator<<(std::ostream &sout, dlr_imfreq const &m)
Write a triqs::mesh::dlr_imfreq mesh to a std::ostream.
auto begin() const
Get an iterator to the beginning of the mesh.
bool symmetrize() const noexcept
Is the mesh symmetric around ?
friend void h5_write(h5::group g, std::string const &name, dlr_imfreq const &m)
Write a triqs::mesh::dlr_imfreq mesh to HDF5.
auto cbegin() const
Get a const iterator to the beginning of the mesh.
dlr_imfreq()=default
Default constructor constructs an empty mesh.
matsubara_freq to_value(long l) const noexcept
Map an index to its corresponding Matsubara frequency .
long to_index(long d) const noexcept
Map a data index to the corresponding index .
double beta() const noexcept
Get the inverse temperature .
matsubara_freq value_t
Value type.
mesh_point_t operator()(long l) const
Function call operator to access a mesh point by its index .
bool operator==(dlr_imfreq const &m) const
Equal-to comparison operator compares the hash values.
long data_index_t
Data index type.
dlr_imfreq(M const &m)
Construct an imaginary frequency DLR mesh from another DLR type mesh.
auto min_max_frequencies() const noexcept
Get a pair containing the smallest and largest Matsubara frequency in the mesh.
static std::string hdf5_format()
Get the HDF5 format tag.
uint64_t mesh_hash() const noexcept
Get the hash value of the mesh.
double eps() const noexcept
Get the DLR error tolerance .
auto const & dlr_freq() const
Get the array of DLR frequencies .
auto const & dlr_it() const
Get the imaginary time DLR operations object (see also cppdlr::imtime_ops).
Imaginary time discrete Lehmann representation (DLR) mesh type.
Discrete Lehmann representation (DLR) mesh type.
statistic_enum
Enum to specify particle statistics.
std::size_t hash_bytes(std::span< std::byte const > bytes)
Hash the raw bytes of a span via the standard library's std::hash<std::string_view>.
uint64_t hash(Ts &&...ts)
Generic hash function for multiple arguments.
Common macros used in TRIQS.
Provides a struct to represent Matsubara frequencies.
Provides a mesh type for the discrete Lehmann representation.
Provides various utilities used with Meshes.
Provides a generic random access iterator for 1D meshes.
Represents a Matsubara frequency .
matsubara_freq()=default
Default constructor initializes the Matsubara frequency with zero index, zero inverse temperature and...
A generic random access iterator for 1D meshes.