32#include <fmt/format.h>
34#include <itertools/itertools.hpp>
42namespace triqs::mesh {
104 mesh_point_t(
long n,
long d, uint64_t mhash) : index_(n), data_index_(d), mesh_hash_(mhash) {}
107 [[nodiscard]]
long index()
const {
return index_; }
110 [[nodiscard]]
long data_index()
const {
return data_index_; }
113 [[nodiscard]] uint64_t
mesh_hash() const noexcept {
return mesh_hash_; }
117 long data_index_ = 0;
118 uint64_t mesh_hash_ = 0;
132 C2PY_DEPRECATED_PARAMETER_NAME(S :
statistic, n_max : max_n)
188 [[nodiscard]] C2PY_PROPERTY_GET(
beta)
double beta() const noexcept {
return beta_; }
197 [[nodiscard]]
long size()
const {
return N_; }
209 [[nodiscard]]
auto cend()
const {
return end(); }
219 auto stat_cstr = (m.stat_ == Boson ?
"Boson" :
"Fermion");
220 return sout << fmt::format(
"Legendre mesh with beta = {}, statistics = {}, N = {}", m.beta_, stat_cstr, m.
size());
227 void serialize(
auto &ar)
const { ar & beta_ & stat_ & N_ & mesh_hash_; }
233 void deserialize(
auto &ar) { ar & beta_ & stat_ & N_ & mesh_hash_; }
236 [[nodiscard]]
static std::string
hdf5_format() {
return "MeshLegendre"; }
246 h5::group gr = g.create_group(name);
247 h5::write_hdf5_format(gr, m);
248 h5::write(gr,
"beta", m.beta_);
249 h5::write(gr,
"statistic", (m.stat_ == Fermion ?
"F" :
"B"));
250 h5::write(gr,
"max_n", m.N_);
261 h5::group gr = g.open_group(name);
262 h5::assert_hdf5_format(gr, m,
true);
265 if (gr.has_key(
"domain")) { gr = gr.open_group(
"domain"); }
267 auto beta = h5::read<double>(gr,
"beta");
268 auto statistic = (h5::read<std::string>(gr,
"statistic") ==
"F" ? Fermion : Boson);
272 if (not h5::try_read(gr,
"max_n", max_n)) max_n =
static_cast<long>(h5::read<size_t>(gr,
"n_max"));
281 uint64_t mesh_hash_ = 0;
304 inline auto evaluate(
legendre const &m,
auto const &f,
double tau) {
305 EXPECTS(m.
size() > 0 and tau >= 0 and tau <= m.
beta());
308 return detail::sum_to_regular(nda::range(m.
size()), [&](
auto n) { return f(n) * std::sqrt(2 * n + 1) * gen.next() / m.beta(); });
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.
legendre()=default
Default constructor constructs an empty mesh.
Mesh point of a triqs::mesh::legendre mesh.
long data_index() const
Get the data index of the mesh point.
legendre mesh_t
Parent mesh type.
uint64_t mesh_hash() const noexcept
Get the hash value of the parent mesh.
mesh_point_t(long n, long d, uint64_t mhash)
Construct a mesh point with a given index , data index and hash value of the parent mesh.
mesh_point_t()=default
Default constructor leaves the mesh point uninitialized.
long index() const
Get the index of the mesh point.
double beta() const noexcept
Get the inverse temperature .
mesh_point_t operator[](long d) const
Subscript operator to access a mesh point by its data index .
auto begin() const
Get an iterator to the beginning of the mesh.
void deserialize(auto &ar)
Deserialize the mesh from a generic archive.
friend void h5_write(h5::group g, std::string const &name, legendre const &m)
Write a triqs::mesh::legendre mesh to HDF5.
long size() const
Get the size of the mesh, i.e. the number of mesh points or polynomials in the series expansion.
uint64_t mesh_hash() const
Get the hash value of the mesh.
void serialize(auto &ar) const
Serialize the mesh to a generic archive.
index_t to_index(long d) const noexcept
Map a data index to the corresponding index .
auto cbegin() const
Get a const iterator to the beginning of the mesh.
bool is_index_valid(index_t n) const noexcept
Check if an index is valid.
auto statistic() const noexcept
Get the particle statistics.
mesh_point_t operator()(long n) const
Function call operator to access a mesh point by its index .
long data_index_t
Data index type.
data_index_t to_data_index(index_t n) const noexcept
Map an index to its corresponding data index .
static std::string hdf5_format()
Get the HDF5 format tag.
auto cend() const
Get a const iterator to the end of the mesh.
legendre()=default
Default constructor constructs an empty mesh.
bool operator==(legendre const &) const =default
Equal-to comparison operator compares , and the particle statistics.
auto end() const
Get an iterator to the end of the mesh.
friend std::ostream & operator<<(std::ostream &sout, legendre const &m)
Write a triqs::mesh::legendre mesh to a std::ostream.
friend void h5_read(h5::group g, std::string const &name, legendre &m)
Read a triqs::mesh::legendre mesh from HDF5.
Recursive generation of Legendre polynomials .
void reset(double x)
Reset the generator to 0th order and with a new value.
statistic_enum
Enum to specify particle statistics.
uint64_t hash(Ts &&...ts)
Generic hash function for multiple arguments.
Common macros used in TRIQS.
Provides various utilities used with Meshes.
Provides a generic random access iterator for 1D meshes.
A generic random access iterator for 1D meshes.
Provides Legendre polynomials and related functions.