40namespace triqs::lattice {
44namespace triqs::mesh {
53 requires(((
n_variables<Ms> == 1) and ...) and (not(std::is_reference_v<Ms> or ...)))
79 using tuple_t = std::tuple<
typename Ms::mesh_point_t...>;
97 [[nodiscard]] uint64_t
mesh_hash() const noexcept {
return mesh_hash_; }
103 index_t index_ = std::apply([](
auto &...ms) {
return std::make_tuple(ms.index()...); },
as_tuple());
104 data_index_t data_index_ = std::apply([](
auto &...ms) {
return std::make_tuple(ms.data_index()...); },
as_tuple());
105 uint64_t mesh_hash_ = std::apply([](
auto &...ms) {
return (ms.mesh_hash() + ...); },
as_tuple());
136 template <
Mesh... Ms>
137 requires(((
n_variables<Ms> == 1) and ...) and (not(std::is_reference_v<Ms> or ...)))
138 class prod : public std::tuple<Ms...> {
141 using index_t = std::tuple<
typename Ms::index_t...>;
160 requires(
sizeof...(Ms) > 0)
167 template <
typename... U>
168 prod(std::tuple<U...>
const &mt) :
m_tuple_t{mt}, mesh_hash_(std::apply([](auto &...m) {
return (m.mesh_hash() + ...); }, mt)) {}
179 template <
typename... Args> [[nodiscard]]
bool is_index_valid(Args
const &...ns)
const {
180 return triqs::tuple::fold([](
auto &m,
auto &n,
bool res) {
return res && (m.is_index_valid(n)); },
as_tuple(), std::tie(ns...),
true);
201 auto l = [](
auto const &m,
auto const &n_i) {
return m.to_data_index(n_i); };
213 auto l = [](
auto const &m,
auto const &d_i) {
return m.to_index(d_i); };
227 auto l = [](
auto const &m,
auto const &d_i) {
return m[d_i]; };
241 auto l = [](
auto const &m,
auto const &n_i) {
return m(n_i); };
246 [[nodiscard]] uint64_t
mesh_hash()
const {
return mesh_hash_; }
249 [[nodiscard]]
long size()
const {
255 std::array<long, std::tuple_size_v<m_tuple_t>> res;
256 auto l = [&res](
int i,
auto const &m)
mutable { res[i] = m.size(); };
262 [[nodiscard]] m_tuple_t
const &components()
const {
return *
this; }
275 [[nodiscard]]
auto r_()
const {
276 auto f = [](
auto &&...ms) {
return itertools::product(ms...); };
277 auto to_mesh_point = [](
auto &&n_mp) {
return mesh_point_t{n_mp}; };
278 return itertools::transform(std::apply(f, components()), to_mesh_point);
283 [[nodiscard]]
auto begin()
const {
return r_().begin(); }
286 [[nodiscard]]
auto cbegin()
const {
return r_().cbegin(); }
289 [[nodiscard]]
auto end()
const {
return r_().end(); }
292 [[nodiscard]]
auto cend()
const {
return r_().cend(); }
302 sout <<
"Product Mesh";
320 [[nodiscard]]
static std::string
hdf5_format() {
return "MeshProduct"; }
330 h5::group gr = g.create_group(name);
331 h5::write_hdf5_format(gr, m);
332 auto l = [gr](
int N,
auto const &mc) { h5::write(gr,
"MeshComponent" +
std::to_string(N), mc); };
344 h5::group gr = g.open_group(name);
345 h5::assert_hdf5_format(gr, m,
true);
346 auto l = [gr](
int N,
auto &mc) { h5::read(gr,
"MeshComponent" +
std::to_string(N), mc); };
351 uint64_t mesh_hash_ = 0;
355 template <
typename M1,
typename M2,
typename... Ms> prod(M1, M2, Ms...) -> prod<M1, M2, Ms...>;
357 template <
typename M1,
typename M2,
typename... Ms>
358 prod(std::tuple<M1, M2, Ms...>) -> prod<std::decay_t<M1>, std::decay_t<M2>, std::decay_t<Ms>...>;
371 return prod<Ls..., Rs...>{std::tuple_cat(m.components(), n.components())};
385 return prod<L, Rs...>{std::tuple_cat(std::make_tuple(n), m.components())};
399 return prod<Ls..., R>{std::tuple_cat(m.components(), std::make_tuple(n))};
418template <
typename... Ms>
struct std::tuple_size<triqs::mesh::prod<Ms...>> :
public std::integral_constant<size_t, sizeof...(Ms)> {};
421template <
typename... Ms>
struct std::tuple_size<triqs::mesh::prod_mesh_point<Ms...>> :
public std::integral_constant<size_t, sizeof...(Ms)> {};
424template <
size_t N,
typename... Ms>
struct std::tuple_element<N, triqs::mesh::prod<Ms...>> :
public std::tuple_element<N, std::tuple<Ms...>> {};
427template <
size_t N,
typename... Ms>
428struct std::tuple_element<N, triqs::mesh::prod_mesh_point<Ms...>> :
public std::tuple_element<N, std::tuple<typename Ms::mesh_point_t...>> {};
prod()=default
Default constructor calls the default constructor of all its components.
Mesh point type for the triqs::mesh::prod mesh.
prod_mesh_point()=default
Default constructor leaves the mesh point uninitialized.
typename mesh_t::index_t index_t
Index type of the parent mesh.
typename mesh_t::data_index_t data_index_t
Data index type of the parent mesh.
index_t index() const
Get the index tuple of the mesh point.
data_index_t data_index() const
Get the data index tuple of the mesh point.
prod_mesh_point(tuple_t mpt)
Construct a mesh point from a tuple of mesh points.
uint64_t mesh_hash() const noexcept
Get the hash value of the parent mesh.
tuple_t const & as_tuple() const
Get the underlying tuple of mesh points.
prod< Ms... > mesh_t
Parent mesh type.
std::tuple< typename Ms::mesh_point_t... > tuple_t
Underlying tuple type of mesh points.
Product mesh type for combining multiple meshes.
void deserialize(auto &ar)
Deserialize the mesh from a generic archive.
m_tuple_t & as_tuple()
Get the underlying tuple of individual meshes, i.e. .
m_tuple_t & components()
Get the underlying tuple of individual meshes, i.e. .
friend std::ostream & operator<<(std::ostream &sout, prod const &m)
Write a triqs::mesh::prod mesh to a std::ostream.
bool is_index_valid(Args const &...ns) const
Check if the given indices are valid.
friend void h5_write(h5::group g, std::string name, prod const &m)
Write a triqs::mesh::prod mesh to HDF5.
bool operator==(prod const &m) const
Equal-to comparison operator compares the tuple of meshes in the product.
auto end() const
Get an iterator to the end of the mesh.
prod(std::tuple< U... > const &mt)
Construct a product mesh from the given tuple of meshes.
m_tuple_t const & as_tuple() const
auto cend() const
Get a const iterator to the end of the mesh.
prod()=default
Default constructor calls the default constructor of all its components.
mesh_point_t operator[](data_index_t const &d) const
Subscript operator to access a mesh point by its data index tuple .
uint64_t mesh_hash() const
void serialize(auto &ar) const
Serialize the mesh to a generic archive.
auto cbegin() const
Get a const iterator to the beginning of the mesh.
data_index_t to_data_index(index_t const &n) const
Map an index tuple to its corresponding data index tuple .
std::tuple< typename Ms::index_t... > index_t
mesh_point_t operator()(index_t const &n) const
Function call operator to access a mesh point by its index tuple .
prod_mesh_point< Ms... > mesh_point_t
std::tuple< Ms... > m_tuple_t
index_t to_index(data_index_t const &d) const
Map a data index tuple to its corresponding index tuple .
auto size_of_components() const
Get the sizes of the components as a std::array, i.e. .
bool is_index_valid(index_t const &n) const
Check if given index tuple is valid.
std::tuple< typename Ms::data_index_t... > data_index_t
friend void h5_read(h5::group g, std::string name, prod &m)
Read a triqs::mesh::prod mesh from HDF5.
long size() const
Get the size of the mesh, i.e. the product of the sizes of its components.
auto begin() const
Get an iterator to the beginning of the mesh.
prod(Ms const &...ms)
Construct a product mesh with the given meshes .
static std::string hdf5_format()
Get the HDF5 format tag.
k_expr<' *', long, R > operator*(Int l, R &&r)
Lazy multiplication of a triqs::mesh::BzMeshPoint object with a scalar.
static constexpr int n_variables
Constexpr variable that holds the number of meshes in a triqs::mesh::Mesh type ( for non-product mes...
static constexpr bool is_product
Constexpr bool that is true if the given triqs::mesh::Mesh type is a product of meshes,...
string to_string(string const &str)
Identity overload for std::string.
void for_each(T &&t, F &&f)
Apply a callable to every element of a tuple, in order.
decltype(auto) fold(F &&f, T &&t, R &&r)
Left-fold a callable over the elements of a tuple.
auto map_on_zip(F &&f, Ts &&...ts)
Map an N-ary callable across N tuples zipped together.
void for_each_enumerate(T &&t, F &&f)
Apply a callable to every (index, element) pair of a tuple.
Provides concepts for mesh points and meshes.
Provides various utilities used with Meshes.