31#include <cppdlr/cppdlr.hpp>
33#include <fmt/format.h>
34#include <itertools/itertools.hpp>
44namespace triqs::mesh {
75 class C2PY_RENAME(MeshDLRImTime) dlr_imtime {
109 mesh_point_t(
long l,
long d, uint64_t mhash,
double tau_l) : index_(l), data_index_(d), mesh_hash_(mhash), value_(tau_l) {}
112 [[nodiscard]]
long index()
const {
return index_; }
115 [[nodiscard]]
long data_index()
const {
return data_index_; }
118 [[nodiscard]]
double value()
const {
return value_; }
121 [[nodiscard]] uint64_t
mesh_hash() const noexcept {
return mesh_hash_; }
124 operator double()
const {
return value_; }
128 long data_index_ = 0;
129 uint64_t mesh_hash_ = 0;
135 dlr_imtime(
double beta, statistic_enum statistic,
double w_max,
double eps,
bool symmetrize, nda::vector<double>
const &dlr_freq)
136 : dlr_imtime(beta, statistic, w_max, eps, symmetrize,
137 detail::dlr_ops{.freq = dlr_freq,
138 .imt = {w_max * beta, dlr_freq, symmetrize},
139 .imf = {w_max * beta, dlr_freq,
static_cast<cppdlr::statistic_t
>(statistic), symmetrize}}) {}
142 dlr_imtime(
double beta, statistic_enum statistic,
double w_max,
double eps,
bool symmetrize, detail::dlr_ops ops)
147 symmetrize_(symmetrize),
148 mesh_hash_(
hash(beta, statistic, w_max, eps, symmetrize,
hash_bytes(ops.imf.get_ifnodes()), std::string_view{
"dlr_imtime"})),
149 dlr_{std::make_shared<detail::dlr_ops>(std::move(ops))} {}
178 template <nda::AnyOf<dlr_imfreq, dlr> M>
184 symmetrize_(m.symmetrize_),
185 mesh_hash_(
hash(beta_, stat_, w_max_, eps_, symmetrize_,
hash_bytes(m.dlr_->imf.get_ifnodes()), std::string_view{
"dlr_imtime"})),
189 bool operator==(dlr_imtime
const &m)
const {
return mesh_hash_ == m.mesh_hash_ and stat_ == m.stat_; }
219 [[nodiscard]]
long to_index(
long d)
const noexcept {
248 [[nodiscard]]
double to_value(
long l)
const noexcept {
250 auto res = dlr_->imt.get_itnodes()[l] * beta_;
251 if (res < 0) res = beta_ + res;
256 [[nodiscard]] C2PY_PROPERTY_GET(
beta)
double beta() const noexcept {
return beta_; }
262 [[nodiscard]] C2PY_PROPERTY_GET(
w_max)
double w_max() const noexcept {
return w_max_; }
265 [[nodiscard]] C2PY_PROPERTY_GET(
eps)
double eps() const noexcept {
return eps_; }
271 [[nodiscard]] C2PY_PROPERTY_GET(
dlr_freq)
auto const &
dlr_freq()
const {
return dlr_->freq; }
274 [[nodiscard]] C2PY_IGNORE
auto const &
dlr_it()
const {
return dlr_->imt; }
277 [[nodiscard]] C2PY_IGNORE
auto const &
dlr_if()
const {
return dlr_->imf; }
280 [[nodiscard]] C2PY_PROPERTY_GET(
mesh_hash) uint64_t
mesh_hash() const noexcept {
return mesh_hash_; }
283 [[nodiscard]]
long size() const noexcept {
return (dlr_ ? dlr_->imt.get_itnodes().size() : 0); }
295 [[nodiscard]]
auto cend()
const {
return end(); }
304 friend std::ostream &
operator<<(std::ostream &sout, dlr_imtime
const &m) {
305 auto stat_cstr = (m.stat_ == Boson ?
"Boson" :
"Fermion");
306 return sout << fmt::format(
"DLR imaginary time mesh of size {} with beta = {}, statistics = {}, w_max = {}, eps = {}, symmetrized = {}",
307 m.
size(), m.beta_, stat_cstr, m.w_max_, m.eps_, m.symmetrize_);
316 ar & beta_ & stat_ & w_max_ & eps_ & symmetrize_ & mesh_hash_ & dlr_->freq;
317 dlr_->imt.serialize(ar);
318 dlr_->imf.serialize(ar);
326 nda::vector<double> freq;
327 cppdlr::imtime_ops imt;
328 cppdlr::imfreq_ops imf;
329 ar & beta_ & stat_ & w_max_ & eps_ & symmetrize_ & mesh_hash_ & freq;
332 dlr_ = std::make_shared<detail::dlr_ops>(freq, imt, imf);
336 [[nodiscard]]
static std::string
hdf5_format() {
return "MeshDLRImTime"; }
345 friend void h5_write(h5::group g, std::string
const &name, dlr_imtime
const &m) {
346 h5::group gr = g.create_group(name);
347 h5::write_hdf5_format(gr, m);
348 h5::write(gr,
"beta", m.beta_);
349 h5::write(gr,
"statistic", (m.stat_ == Fermion ?
"F" :
"B"));
350 h5::write(gr,
"w_max", m.w_max_);
351 h5::write(gr,
"eps", m.eps_);
352 h5::write(gr,
"symmetrize", m.symmetrize_);
353 h5::write(gr,
"dlr_freq", m.
dlr_freq());
354 h5::write(gr,
"dlr_it", m.
dlr_it());
355 h5::write(gr,
"dlr_if", m.
dlr_if());
365 friend void h5_read(h5::group g, std::string
const &name, dlr_imtime &m) {
366 h5::group gr = g.open_group(name);
367 h5::assert_hdf5_format(gr, m,
true);
368 auto b = h5::read<double>(gr,
"beta");
369 auto stat = (h5::read<std::string>(gr,
"statistic") ==
"F" ? Fermion : Boson);
370 auto wmax = h5::read<double>(gr,
"w_max");
371 auto epsilon = h5::read<double>(gr,
"eps");
373 h5::try_read(gr,
"symmetrize", sym);
374 auto freq = h5::read<nda::vector<double>>(gr,
"dlr_freq");
375 auto imt = h5::read<cppdlr::imtime_ops>(gr,
"dlr_it");
376 auto imf = h5::read<cppdlr::imfreq_ops>(gr,
"dlr_if");
377 m = dlr_imtime{b, stat, wmax, epsilon, sym, {.freq = freq, .imt = imt, .imf = imf}};
389 bool symmetrize_ =
false;
390 uint64_t mesh_hash_ = 0;
391 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.
Imaginary frequency discrete Lehmann representation (DLR) mesh type.
Mesh point of a triqs::mesh::dlr_imtime mesh.
double value() const
Get the value of the mesh point.
long index() const
Get the index of the mesh point.
mesh_point_t(long l, long d, uint64_t mhash, double tau_l)
Construct a mesh point with a given index , data index , hash value of the parent mesh and value .
mesh_point_t()=default
Default constructor leaves the mesh point uninitialized.
dlr mesh_t
Parent mesh type.
uint64_t mesh_hash() const noexcept
Get the hash value of the parent mesh.
long data_index() const
Get the data index of the mesh point.
Imaginary time discrete Lehmann representation (DLR) mesh type.
double value_t
Value type.
static std::string hdf5_format()
Get the HDF5 format tag.
double beta() const noexcept
Get the inverse temperature .
mesh_point_t operator()(long l) const
Function call operator to access a mesh point by its index .
friend void h5_write(h5::group g, std::string const &name, dlr_imtime const &m)
Write a triqs::mesh::dlr_imtime mesh to HDF5.
bool symmetrize() const noexcept
Is the mesh symmetric around ?
bool operator==(dlr_imtime const &m) const
Equal-to comparison operator compares the hash values.
long to_index(long d) const noexcept
Map a data index to the corresponding index .
double w_max() const noexcept
Get the DLR energy cutoff .
dlr_imtime(M const &m)
Construct an imaginary time DLR mesh from another DLR type mesh.
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).
long data_index_t
Data index type.
statistic_enum statistic() const noexcept
Get the particle statistics.
friend void h5_read(h5::group g, std::string const &name, dlr_imtime &m)
Read a triqs::mesh::dlr_imtime mesh from HDF5.
long to_data_index(long l) const noexcept
Map an index to its corresponding data index .
bool is_index_valid(long l) const noexcept
Check if an index is valid.
auto cend() const
Get a const iterator to the end of the mesh.
auto end() const
Get an iterator to the end of the mesh.
double eps() const noexcept
Get the DLR error tolerance .
mesh_point_t operator[](long d) const
Subscript operator to access a mesh point by its data index .
auto const & dlr_it() const
Get the imaginary time DLR operations object (see also cppdlr::imtime_ops).
double to_value(long l) const noexcept
Map an index to its corresponding value .
auto cbegin() const
Get a const iterator to the beginning of the mesh.
auto begin() const
Get an iterator to the beginning of the mesh.
uint64_t mesh_hash() const noexcept
Get the hash value 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_imtime const &m)
Write a triqs::mesh::dlr_imtime mesh to a std::ostream.
void deserialize(auto &ar)
Deserialize the mesh from a generic archive.
dlr_imtime(double beta, statistic_enum statistic, double w_max, double eps, bool symmetrize=true)
Construct an imaginary time DLR mesh with a given energy cutoff and error tolerance .
auto const & dlr_freq() const
Get the array of DLR frequencies .
long to_data_index(closest_mesh_point_t< double > const &cmp) const =delete
Mapping of a value to the data index of the closest mesh point is deleted.
dlr_imtime()=default
Default constructor constructs an empty mesh.
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 mesh type for the discrete Lehmann representation.
Provides various utilities used with Meshes.
Provides a generic random access iterator for 1D meshes.
Lazy struct used in various function overloads as a placeholder for the closest mesh point to a given...
A generic random access iterator for 1D meshes.