32#include <fmt/ranges.h>
41namespace triqs::mesh {
47 using lattice::bravais_lattice;
88 class C2PY_RENAME(MeshCycLat)
cyclat {
124 :
value_t(n, bl_ptr), data_index_(d), mesh_hash_(mhash) {}
127 [[nodiscard]]
long data_index()
const {
return data_index_; }
133 [[nodiscard]] uint64_t
mesh_hash() const noexcept {
return mesh_hash_; }
145 long data_index_ = 0;
146 uint64_t mesh_hash_ = 0;
157 C2PY_DEPRECATED_PARAMETER_NAME(lattice : bl)
161 size_(nda::stdutil::product(
dims)),
163 s1_(dims_[1] * dims_[2]),
165 units_inv_(nda::linalg::inv(units_)),
167 EXPECTS(dims_[0] > 0 and dims_[1] > 0 and dims_[2] > 0);
180 EXPECTS((M.shape() == std::array{3l, 3l}));
181 EXPECTS(nda::is_matrix_diagonal(M));
210 for (
auto i : nda::range(3))
211 if (n[i] < 0 or n[i] >= dims_[i])
return false;
223 return n[0] * s1_ + n[1] * s2_ + n[2];
243 EXPECTS(0 <= d and d <
size());
244 long const r0 = d % s1_;
245 return {d / s1_, r0 / s2_, r0 % s2_};
297 [[nodiscard]] C2PY_PROPERTY_GET(
dims)
auto const &
dims()
const {
return dims_; }
302 [[nodiscard]] C2PY_PROPERTY_GET(
units)
auto units()
const {
return nda::matrix_const_view<double>{units_}; }
305 [[nodiscard]] C2PY_PROPERTY_GET(
lattice)
auto const &
lattice() const noexcept {
return bl_; }
311 [[nodiscard]]
long size()
const {
return size_; }
334 [[nodiscard]]
auto cend()
const {
return end(); }
350 return sout <<
"Cyclic lattice mesh with linear dimensions " << m.
dims() <<
" and an underlying " << m.
lattice();
357 void serialize(
auto &ar)
const { ar & bl_ & dims_ & size_ & s2_ & s1_ & units_ & units_inv_ & mesh_hash_; }
363 void deserialize(
auto &ar) { ar & bl_ & dims_ & size_ & s2_ & s1_ & units_ & units_inv_ & mesh_hash_; }
366 [[nodiscard]]
static std::string
hdf5_format() {
return "MeshCyclicLattice"; }
376 h5::group gr = g.create_group(name);
377 h5::write_hdf5_format(gr, m);
378 h5::write(gr,
"dims", m.dims_);
379 h5::write(gr,
"bravais_lattice", m.bl_);
390 h5::group gr = g.open_group(name);
391 h5::assert_hdf5_format(gr, m,
true);
393 std::array<long, 3>
dims{};
394 if (gr.has_key(
"dims")) {
395 h5::read(gr,
"dims",
dims);
398 auto M = h5::read<nda::matrix<long>>(gr,
"periodization_matrix");
399 dims = {M(0, 0), M(1, 1), M(2, 2)};
403 if (gr.has_key(
"bravais_lattice")) {
404 h5::read(gr,
"bravais_lattice", bl);
407 h5::read(gr,
"bl", bl);
415 std::array<long, 3> dims_ = {0, 0, 0};
419 nda::matrix<double> units_ = nda::eye<double>(3);
420 nda::matrix<double> units_inv_ = nda::eye<double>(3);
421 uint64_t mesh_hash_ = 0;
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.
Provides a Bravais lattice class.
mesh_point_t()=default
Default constructor leaves the mesh point uninitialized.
bravais_lattice::point_t value_t
Value type.
cyclat(bravais_lattice const &bl, std::array< long, 3 > const &dims)
Construct a cyclic lattice mesh on a Bravais lattice with the given supercell dimensions.
auto index() const
Get the index vector of the lattice point.
Lattice point of a Bravais lattice.
Mesh point of a triqs::mesh::cyclat mesh.
uint64_t mesh_hash() const noexcept
Get the hash value of the parent mesh.
value_t const & value() const
Get the lattice point of the mesh point.
mesh_point_t()=default
Default constructor leaves the mesh point uninitialized.
friend std::ostream & operator<<(std::ostream &sout, mesh_point_t const &mp)
Write triqs::mesh::cyclat::mesh_point_t to a std::ostream.
mesh_point_t(std::array< long, 3 > const &n, long d, uint64_t mhash, bravais_lattice const *bl_ptr)
Construct a mesh point with a given index , data index , hash value of the parent mesh and Bravais la...
long data_index() const
Get the data index of the mesh point.
cyclat mesh_t
Parent mesh type.
Cyclic lattice mesh type for Bravais lattices with Born-von Karman periodic boundary conditions.
index_t to_index(closest_mesh_point_t< value_t > const &cmp) const
Map a lattice point to its index .
friend void h5_write(h5::group g, std::string const &name, cyclat const &m)
Write a triqs::mesh::cyclat mesh to HDF5.
long data_index_t
Data index type.
uint64_t mesh_hash() const
Get the hash value of the mesh.
value_t to_value(index_t const &n) const
Map an index to its corresponding lattice point .
mesh_point_t operator()(index_t const &n) const
Function call operator to access a mesh point by its index .
void serialize(auto &ar) const
Serialize the mesh to a generic archive.
void deserialize(auto &ar)
Deserialize the mesh from a generic archive.
cyclat(long L1=1, long L2=1, long L3=1)
Construct a cyclic lattice mesh on a cubic Bravais lattice with and the given supercell dimensions.
friend std::ostream & operator<<(std::ostream &sout, cyclat const &m)
Write a triqs::mesh::cyclat mesh to a std::ostream.
bool operator==(cyclat const &m) const
Equal-to comparison operator compares the underlying Bravais lattice and the number of unit cells in ...
index_t to_index(data_index_t d) const
Map a data index to the corresponding index .
auto end() const
Get an iterator to the end of the mesh.
auto const & lattice() const noexcept
Get the underlying Bravais lattice.
friend void h5_read(h5::group g, std::string const &name, cyclat &m)
Read a triqs::mesh::cyclat mesh from HDF5.
bool is_index_valid(index_t const &n) const noexcept
Check if an index is valid, i.e. corresponds to a unit cell/lattice point in the supercell.
data_index_t to_data_index(index_t const &n) const
Map an index to its corresponding data index .
index_t index_modulo(index_t const &n_tilde) const
Map an arbitrary index to the unique index in the supercell.
mesh_point_t operator[](closest_mesh_point_t< value_t > const &cmp) const
Subscript operator to access a mesh point by a lattice point contained in a triqs::mesh::closest_mes...
cyclat(bravais_lattice const &bl, long L)
Construct a cyclic lattice mesh on a Bravais lattice with a cubic supercell.
cyclat(bravais_lattice const &bl, nda::matrix< long > const &M)
Construct a cyclic lattice mesh on a Bravais lattice with the given periodization matrix.
bravais_lattice::point_t value_t
Value type.
long size() const
Get the size of the mesh, i.e. the number of unit cells in the supercell.
auto cend() const
Get a const iterator to the end of the mesh.
std::array< long, 3 > index_t
Index type.
cyclat(bravais_lattice const &bl, std::array< long, 3 > const &dims)
Construct a cyclic lattice mesh on a Bravais lattice with the given supercell dimensions.
auto cbegin() const
Get a const iterator to the beginning of the mesh.
mesh_point_t operator[](long d) const
Subscript operator to access a mesh point by its data index .
auto units() const
Get the matrix containing the basis vectors of the Bravais lattice in its rows.
auto begin() const
Get an iterator to the beginning of the mesh.
static std::string hdf5_format()
Get the HDF5 format tag.
data_index_t to_data_index(closest_mesh_point_t< value_t > const &cmp) const
Map a lattice point to its data index .
auto const & dims() const
Get the number of unit cells in each of the three dimensions.
uint64_t hash(Ts &&...ts)
Generic hash function for multiple arguments.
long positive_modulo(long x, long y)
Calculate the positive modulo of two integer numbers.
Common macros used in TRIQS.
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.
A generic random access iterator for 1D meshes.