33#include <fmt/format.h>
44namespace triqs::mesh {
55 explicit operator double()
const {
return value; }
102 class C2PY_RENAME(MeshImFreq)
imfreq :
public tail_fitter_handle {
141 :
matsubara_freq(n_idx, b, stat), data_index_(d), mesh_hash_(mhash) {}
144 [[nodiscard]]
long index()
const {
return n; }
147 [[nodiscard]]
long data_index()
const {
return data_index_; }
153 [[nodiscard]] uint64_t
mesh_hash() const noexcept {
return mesh_hash_; }
156 long data_index_ = 0;
157 uint64_t mesh_hash_ = 0;
167 enum class option { all_frequencies, positive_frequencies_only };
185 if (opt == option::positive_frequencies_only) first_index_ = 0;
213 bool operator==(
imfreq const &m)
const {
return (std::tie(beta_, stat_, N_iw_, opt_) == std::tie(m.beta_, m.stat_, m.N_iw_, m.opt_)); }
242 EXPECTS(beta_ == iw.beta and stat_ == iw.statistic);
254 EXPECTS(beta_ == cmp.
value.beta and stat_ == cmp.
value.statistic);
265 EXPECTS(0 <= d and d <
size());
319 return {n, beta_, stat_};
332 [[nodiscard]] C2PY_PROPERTY_GET(
beta)
double beta() const noexcept {
return beta_; }
338 [[nodiscard]] C2PY_PROPERTY_GET(
n_iw)
long n_iw() const noexcept {
return N_iw_; }
341 [[nodiscard]] C2PY_PROPERTY_GET(
mesh_hash) uint64_t
mesh_hash() const noexcept {
return mesh_hash_; }
344 [[nodiscard]]
long size() const noexcept {
return last_index_ - first_index_ + 1; }
350 [[nodiscard]]
long last_index()
const {
return last_index_; }
353 [[nodiscard]]
bool positive_only()
const {
return opt_ == option::positive_frequencies_only; }
365 [[nodiscard]]
auto cend()
const {
return end(); }
375 auto stat_cstr = (m.stat_ == Boson ?
"Boson" :
"Fermion");
376 return sout << fmt::format(
"Imaginary frequency mesh with beta = {}, statistics = {}, N_iw = {}, positive_only = {}", m.beta_, stat_cstr,
384 void serialize(
auto &ar)
const { ar & beta_ & stat_ & N_iw_ & opt_ & last_index_ & first_index_ & mesh_hash_; }
390 void deserialize(
auto &ar) { ar & beta_ & stat_ & N_iw_ & opt_ & last_index_ & first_index_ & mesh_hash_; }
393 [[nodiscard]]
static std::string
hdf5_format() {
return "MeshImFreq"; }
403 h5::group gr = g.create_group(name);
404 h5::write_hdf5_format(gr, m);
405 h5::write(gr,
"beta", m.beta_);
406 h5::write(gr,
"statistic", (m.stat_ == Fermion ?
"F" :
"B"));
407 h5::write(gr,
"size", m.
size());
408 h5::write(gr,
"positive_freq_only", (m.
positive_only() ? 1 : 0));
419 h5::group gr = g.open_group(name);
420 h5::assert_hdf5_format(gr, m,
true);
424 if (gr.has_key(
"positive_freq_only")) h5::read(gr,
"positive_freq_only", pos_freq);
425 if (gr.has_key(
"start_at_0")) h5::read(gr,
"start_at_0", pos_freq);
426 auto opt = (pos_freq == 1 ? option::positive_frequencies_only : option::all_frequencies);
429 long N = h5::read<long>(gr,
"size");
430 long N_iw = (pos_freq ? N : (N + 1) / 2);
433 if (gr.has_key(
"domain")) { gr = gr.open_group(
"domain"); }
436 auto beta = h5::read<double>(gr,
"beta");
437 auto stat = (h5::read<std::string>(gr,
"statistic") ==
"F" ? Fermion : Boson);
455 option opt_ = option::all_frequencies;
456 long last_index_ = N_iw_ - 1;
457 long first_index_ = -(last_index_ + ((stat_ == Fermion) ? 1 : 0));
458 uint64_t mesh_hash_ = 0;
471 EXPECTS(m.beta() == iw.
beta and m.statistic() == iw.
statistic);
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.
imfreq()=default
Default constructor constructs an empty mesh.
Mesh point of a triqs::mesh::imfreq mesh.
mesh_point_t(double b, statistic_enum stat, index_t n_idx, long d, uint64_t mhash)
Construct a mesh point with the given parameters.
uint64_t mesh_hash() const noexcept
Get the hash value of the parent mesh.
mesh_point_t()=default
Default constructor leaves the mesh point uninitialized.
long index() const
Get the Matsubara index of the mesh point.
long data_index() const
Get the data index of the mesh point.
matsubara_freq const & value() const
Get the corresponding Matsubara frequency .
imfreq mesh_t
Parent mesh type.
Imaginary frequency mesh type.
option
Enum to specify which frequencies should be included in the mesh.
bool operator==(imfreq const &m) const
Equal-to comparison operator compares , the particle statistics, and whether all or only positive fr...
long n_iw() const noexcept
Get the number of positive Matsubara frequencies .
statistic_enum statistic() const noexcept
Get the particle statistics.
long first_index() const
Get the first Matsubara index, i.e. .
void deserialize(auto &ar)
Deserialize the mesh from a generic archive.
data_index_t to_data_index(closest_mesh_point_t< value_t > const &cmp) const
Map a Matsubara frequency contained in a triqs::mesh::closest_mesh_point_t to its data index .
mesh_point_t operator[](long d) const
Subscript operator to access a mesh point by its data index .
void serialize(auto &ar) const
Serialize the mesh to a generic archive.
bool eval_to_zero(index_t n) const
Return true if the given Matsubara index is not valid (see is_index_valid()).
long size() const noexcept
Get the size of the mesh, i.e. the total number of mesh points.
std::complex< double > w_max() const
Get the complex value of the largest positive Matsubara frequency in the mesh.
uint64_t mesh_hash() const noexcept
Get the hash value of the mesh.
bool eval_to_zero(matsubara_freq iw) const
Return true if the Matsubara index of the given Matsubara frequency is not valid.
imfreq(double beta, statistic_enum statistic, energy_t w_max, option opt=option::all_frequencies)
Construct an imaginary frequency mesh with a threshold for the largest positive Matsubara frequency o...
friend void h5_read(h5::group g, std::string name, imfreq &m)
Read a triqs::mesh::imfreq mesh from HDF5.
double beta() const noexcept
Get the inverse temperature .
long last_index() const
Get the last Matsubara index, i.e. .
mesh_point_t operator()(long n) const
Function call operator to access a mesh point by its Matsubara index .
data_index_t to_data_index(index_t n) const noexcept
Map a Matsubara index to its corresponding data index .
index_t to_index(closest_mesh_point_t< value_t > const &cmp) const
Map a Matsubara frequency contained in a triqs::mesh::closest_mesh_point_t to its Matsubara index .
bool is_index_valid(index_t n) const
Check if a Matsubara index is valid.
auto cend() const
Get a const iterator to the end of the mesh.
index_t to_index(data_index_t d) const
Map a data index to the corresponding Matsubara index .
data_index_t to_data_index(matsubara_freq const &iw) const noexcept
Map a Matsubara frequency to its data index .
friend void h5_write(h5::group g, std::string name, imfreq const &m)
Write a triqs::mesh::imfreq mesh to HDF5.
bool positive_only() const
Is the mesh restricted to positive Matsubara frequencies?
matsubara_freq to_value(index_t n) const
Map a Matsubara index to its corresponding Matsubara frequency .
long data_index_t
Data index type.
bool eval_to_zero(mesh_point_t mp) const
Return true if the Matsubara index of the given mesh point is not valid (see is_index_valid()).
matsubara_freq value_t
Value type.
auto begin() const
Get an iterator to the beginning of the mesh.
auto end() const
Get an iterator to the end of the mesh.
friend std::ostream & operator<<(std::ostream &sout, imfreq const &m)
Write a triqs::mesh::imfreq mesh to a std::ostream.
imfreq get_positive_freq() const
Get a new mesh with the same , particle statistics and but only positive frequencies.
auto cbegin() const
Get a const iterator to the beginning of the mesh.
static std::string hdf5_format()
Get the HDF5 format tag.
imfreq()=default
Default constructor constructs an empty mesh.
mesh_point_t operator[](closest_mesh_point_t< value_t > const &cmp) const
Subscript operator to access a mesh point by a Matsubara frequency contained in a triqs::mesh::close...
statistic_enum
Enum to specify particle statistics.
uint64_t hash(Ts &&...ts)
Generic hash function for multiple arguments.
Common macros used in TRIQS.
Provides a struct to represent Matsubara frequencies.
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...
T value
Use the mesh point closest to this value.
Represents an energy value to distinguish constructors in imaginary-frequency mesh.
double value
Energy value.
Represents a Matsubara frequency .
double beta
Inverse temperature .
statistic_enum statistic
Particle statistics.
matsubara_freq()=default
Default constructor initializes the Matsubara frequency with zero index, zero inverse temperature and...
A generic random access iterator for 1D meshes.
Provides tail fitting for functions defined on frequency meshes.