TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
Mesh utilities

Detailed Description

Various utilities used with Meshes.

Classes

struct  triqs::mesh::closest_mesh_point_t< T >
 Lazy struct used in various function overloads as a placeholder for the closest mesh point to a given value. More...
struct  triqs::mesh::energy_t
 Represents an energy value to distinguish constructors in imaginary-frequency mesh. More...
struct  triqs::mesh::mesh_iterator< M >
 A generic random access iterator for 1D meshes. More...

Enumerations

enum  triqs::mesh::statistic_enum
 Enum to specify particle statistics. More...

Functions

template<typename... Ts>
auto triqs::mesh::closest_mesh_pt (Ts &&...ts)
 Construct a triqs::mesh::closest_mesh_point_t object for a single value or a std::tuple of triqs::mesh::closest_mesh_point_t objects for multiple values.
template<Mesh M>
triqs::mesh::copy (M const &m)
 Get a copy of a mesh (for Python bindings).
template<Mesh M>
void triqs::mesh::copy_from (M &m1, M const &m2)
 Copy one mesh into another (for Python bindings).
template<Mesh M>
__inline__ auto triqs::mesh::evaluate (M const &, auto const &f, typename M::index_t const &n)
 Evaluate a function \( f \) at the index of a mesh point of the given mesh.
template<Mesh M>
__inline__ auto triqs::mesh::evaluate (M const &m, auto const &f, typename M::mesh_point_t const &mp)
 Evaluate a function \( f \) at a specific mesh point of the given mesh.
template<typename T>
__inline__ auto triqs::mesh::evaluate (Mesh auto const &, auto const &f, mesh::closest_mesh_point_t< T > const &cmp)
 Evaluate a function \( f \) at a triqs::mesh::closest_mesh_point_t object.
__inline__ auto triqs::mesh::evaluate (Mesh auto const &, auto const &f, nda::range::all_t)
 Evaluate a function \( f \) for nda::range::all.
template<Mesh... Ms, typename... Xs>
__inline__ auto triqs::mesh::evaluate (mesh::prod< Ms... > const &m, auto const &f, Xs const &...xs)
 Evaluate a multivariate function \( f \) defined on the given product mesh at the given arguments.
template<typename... Ds, typename X1, typename... Xs>
__inline__ auto triqs::mesh::evaluate (std::tuple< Ds... > const &tup, auto const &f, X1 const &x1, Xs const &...xs)
 Evaluate a multivariate function \( f \) defined on the given domains (meshes) at the given arguments.
template<typename... Ts>
uint64_t triqs::mesh::hash (Ts &&...ts)
 Generic hash function for multiple arguments.
template<nda::MemoryArray R>
std::size_t triqs::mesh::hash_bytes (R const &r)
 Hash the raw bytes of a contiguous nda array's elements (forwards to the byte-span overload).
std::size_t triqs::mesh::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>.
auto triqs::mesh::operator* (statistic_enum s1, statistic_enum s2)
 Multiplication operator for two triqs::mesh::statistic_enum objects.
long triqs::mesh::positive_modulo (long x, long y)
 Calculate the positive modulo of two integer numbers.
int triqs::mesh::sign (statistic_enum s)
 Get the sign associated with the given particle statistics.
template<MeshWithValues M>
auto triqs::mesh::values (M const &m)
 Get the values of all mesh points in a mesh.

Variables

template<Mesh M>
static constexpr bool triqs::mesh::is_product = false
 Constexpr bool that is true if the given triqs::mesh::Mesh type is a product of meshes, i.e. a triqs::mesh::prod.
template<Mesh M>
static constexpr int triqs::mesh::n_variables = 1
 Constexpr variable that holds the number of meshes in a triqs::mesh::Mesh type ( \( 1 \) for non-product meshes).

Enumeration Type Documentation

◆ statistic_enum

#include <triqs/mesh/utils.hpp>

Enum to specify particle statistics.

The following statistics are supported:

  • Boson and
  • Fermion.

Definition at line 163 of file utils.hpp.

Function Documentation

◆ closest_mesh_pt()

template<typename... Ts>
auto triqs::mesh::closest_mesh_pt ( Ts &&... ts)
nodiscard

#include <triqs/mesh/utils.hpp>

Construct a triqs::mesh::closest_mesh_point_t object for a single value or a std::tuple of triqs::mesh::closest_mesh_point_t objects for multiple values.

Template Parameters
TsValue types.
Parameters
tsValues to be wrapped in triqs::mesh::closest_mesh_point_t objects.
Returns
Either a triqs::mesh::closest_mesh_point_t object or a tuple of such objects.

Definition at line 199 of file utils.hpp.

◆ copy()

template<Mesh M>
M triqs::mesh::copy ( M const & m)
nodiscard

#include <triqs/mesh/utils.hpp>

Get a copy of a mesh (for Python bindings).

Template Parameters
MA mesh type.
Parameters
mThe mesh object to copy.
Returns
Copy of the given mesh.

Definition at line 137 of file utils.hpp.

◆ copy_from()

template<Mesh M>
void triqs::mesh::copy_from ( M & m1,
M const & m2 )

#include <triqs/mesh/utils.hpp>

Copy one mesh into another (for Python bindings).

Simply calls the copy assignment operator of the mesh.

Template Parameters
MA mesh type.
Parameters
m1The mesh object to copy into.
m2The mesh object to copy from.

Definition at line 148 of file utils.hpp.

◆ evaluate() [1/6]

template<Mesh M>
__inline__ auto triqs::mesh::evaluate ( M const & ,
auto const & f,
typename M::index_t const & n )

#include <triqs/mesh/evaluate.hpp>

Evaluate a function \( f \) at the index of a mesh point of the given mesh.

It simply forwards the index to the function object \( f \).

Template Parameters
Mtriqs::mesh::Mesh type.
Parameters
fCallable object \( f \) representing the function to be evaluated.
nMesh point index \( n \).
Returns
Result of the function call.

Definition at line 63 of file evaluate.hpp.

◆ evaluate() [2/6]

template<Mesh M>
__inline__ auto triqs::mesh::evaluate ( M const & m,
auto const & f,
typename M::mesh_point_t const & mp )

#include <triqs/mesh/evaluate.hpp>

Evaluate a function \( f \) at a specific mesh point of the given mesh.

If the given mesh satisfies the triqs::mesh::MeshWithValues concept, it calls evaluate with the mesh, the function object \( f \) and the value of the mesh point. Otherwise, it calls \( f \) with the mesh point itself.

Template Parameters
Mtriqs::mesh::Mesh type.
Parameters
mMesh object.
fCallable object \( f \) representing the function to be evaluated.
mpMesh point of the mesh.
Returns
Result of the evaluation.

Definition at line 100 of file evaluate.hpp.

◆ evaluate() [3/6]

template<typename T>
__inline__ auto triqs::mesh::evaluate ( Mesh auto const & ,
auto const & f,
mesh::closest_mesh_point_t< T > const & cmp )

#include <triqs/mesh/evaluate.hpp>

Evaluate a function \( f \) at a triqs::mesh::closest_mesh_point_t object.

It simply forwards the given object to the function object \( f \).

Template Parameters
TValue type of triqs::mesh::closest_mesh_point_t.
Parameters
fCallable object \( f \) representing the function to be evaluated.
cmptriqs::mesh::closest_mesh_point_t object.
Returns
Result of the function call.

Definition at line 75 of file evaluate.hpp.

◆ evaluate() [4/6]

__inline__ auto triqs::mesh::evaluate ( Mesh auto const & ,
auto const & f,
nda::range::all_t  )

#include <triqs/mesh/evaluate.hpp>

Evaluate a function \( f \) for nda::range::all.

It simply calls the function object \( f \) with nda::range::all.

Parameters
fCallable object \( f \) representing the function to be evaluated.
Returns
Result of the function call.

Definition at line 85 of file evaluate.hpp.

◆ evaluate() [5/6]

template<Mesh... Ms, typename... Xs>
__inline__ auto triqs::mesh::evaluate ( mesh::prod< Ms... > const & m,
auto const & f,
Xs const &... xs )

#include <triqs/mesh/evaluate.hpp>

Evaluate a multivariate function \( f \) defined on the given product mesh at the given arguments.

It simply forwards the arguments and the components of the product mesh to triqs::mesh::evaluate.

Template Parameters
Mstriqs::mesh::Mesh types of the product mesh.
XsArgument types.
Parameters
mProduct mesh.
fCallable object \( f \) representing the function to be evaluated.
xsArguments \( x_1, \dots, x_n \).
Returns
Result of the evaluation \( f(x_1, \dots, x_n) \).

Definition at line 177 of file evaluate.hpp.

◆ evaluate() [6/6]

template<typename... Ds, typename X1, typename... Xs>
__inline__ auto triqs::mesh::evaluate ( std::tuple< Ds... > const & tup,
auto const & f,
X1 const & x1,
Xs const &... xs )

#include <triqs/mesh/evaluate.hpp>

Evaluate a multivariate function \( f \) defined on the given domains (meshes) at the given arguments.

The function is evaluated by currying, i.e. it is evaluated step by step for each domain.

Suppose that we want to evaluate the function \( f : \mathrm{D}_1 \times \dots \times \mathrm{D}_n \to \mathrm{R} \) at the points \( x_1 \in \mathrm{D}_1, \dots, x_n \in \mathrm{D}_n \). Then currying works by creating a sequence of functions each taking one argument:

\[ \mathrm{curry}(f) : \mathrm{D}_n \to ( \mathrm{D_{n-1}} \to ( \dots \to ( \mathrm{D}_1 \to \mathrm{R} ) ) ) \; . \]

Here, \( \mathrm{curry}(f) \) is a function that

  • takes an argument \( x_n \in \mathrm{D}_n \) and returns a new function \( f_{x_n} \) that
  • takes an argument \( x_{n-1} \in \mathrm{D}_{n-1} \) and returns a new function \( f_{x_n, x_{n-1}} \) that
  • . . .
  • takes an argument \( x_{2} \in \mathrm{D}_2 \) and returns a new function \( f_{x_n, x_{n-1}, \dots, x_2} \) that
  • takes an argument \( x_1 \in \mathrm{D}_1 \) and returns the final result \( f(x_1, \dots, x_n) \).

This is used to evaluate Green's functions defined on product meshes.

Note
The intermediate functions objects \( f_{x_n, \dots} \) are hidden by nested evaluate calls.
#include <triqs/mesh.hpp>
#include <iostream>
// Dummy domain.
struct domain {};
// Overload evaluate for a single dummy domain.
auto evaluate(domain d, auto f, double x) { return f(x); }
int main() {
// function to evaluate by currying
auto f = [](double x, double y, double z) { return x + y + z; };
// calculate f(1, 2, 3) = 6 using triqs::mesh::evaluate
std::cout << triqs::mesh::evaluate(std::make_tuple(domain{}, domain{}, domain{}), f, 1, 2, 3) << std::endl;
}
Umbrella header for the TRIQS mesh types.

Output:

6
Template Parameters
DsDomain (Mesh) types.
X1First argument type.
XsRemaining argument types.
Parameters
tupTuple of the domains (meshes) \( \mathrm{D}_1, \dots, \mathrm{D}_n \).
fCallable object \( f \) representing the function to be evaluated.
x1First argument \( x_1 \in \mathrm{D}_1 \).
xsRemaining arguments \( x_2 \in \mathrm{D}_2, \dots, x_n \in \mathrm{D}_n \).
Returns
Result of the evaluation \( f(x_1, \dots, x_n) \).

Definition at line 149 of file evaluate.hpp.

◆ hash()

template<typename... Ts>
uint64_t triqs::mesh::hash ( Ts &&... ts)
nodiscard

#include <triqs/mesh/utils.hpp>

Generic hash function for multiple arguments.

It simply uses std::hash for each argument and adds the results.

Template Parameters
TsArgument types.
Parameters
tsObjects to be hashed.
Returns
Combined hash value of all arguments.

Definition at line 70 of file utils.hpp.

◆ hash_bytes() [1/2]

template<nda::MemoryArray R>
std::size_t triqs::mesh::hash_bytes ( R const & r)
nodiscard

#include <triqs/mesh/utils.hpp>

Hash the raw bytes of a contiguous nda array's elements (forwards to the byte-span overload).

Contiguity is asserted at runtime, since nda views may be strided.

Template Parameters
RAn nda::MemoryArray type.
Parameters
rArray to hash; must be contiguous (stride 1).
Returns
Hash value of the array's element bytes.

Definition at line 93 of file utils.hpp.

◆ hash_bytes() [2/2]

std::size_t triqs::mesh::hash_bytes ( std::span< std::byte const > bytes)
inlinenodiscard

#include <triqs/mesh/utils.hpp>

Hash the raw bytes of a span via the standard library's std::hash<std::string_view>.

A proper byte mixer, sensitive to every element and their ordering.

Parameters
bytesByte span to be hashed.
Returns
Hash value of the byte sequence.

Definition at line 80 of file utils.hpp.

◆ operator*()

auto triqs::mesh::operator* ( statistic_enum s1,
statistic_enum s2 )
inlinenodiscard

#include <triqs/mesh/utils.hpp>

Multiplication operator for two triqs::mesh::statistic_enum objects.

Parameters
s1Left-hand side operand.
s2Right-hand side operand.
Returns
Boson statistics if s1 == s2, otherwise Fermion statistics.

Definition at line 180 of file utils.hpp.

◆ positive_modulo()

long triqs::mesh::positive_modulo ( long x,
long y )
inlinenodiscard

#include <triqs/mesh/utils.hpp>

Calculate the positive modulo of two integer numbers.

Parameters
xLeft-hand side operand \( x \) of the modulo operation.
yRight-hand side operand \( y \geq 0 \) of the modulo operation.
Returns

\[ \begin{cases} x \mod y & \text{if } x \geq 0 \\ x \mod y + y & \text{if } \text{x < 0} \end{cases} \]

Definition at line 111 of file utils.hpp.

◆ sign()

int triqs::mesh::sign ( statistic_enum s)
inlinenodiscard

#include <triqs/mesh/utils.hpp>

Get the sign associated with the given particle statistics.

Parameters
striqs::mesh::statistic_enum value.
Returns
\( 1 \) for bosons and \( -1 \) for fermions.

Definition at line 171 of file utils.hpp.

◆ values()

template<MeshWithValues M>
auto triqs::mesh::values ( M const & m)
nodiscard

#include <triqs/mesh/utils.hpp>

Get the values of all mesh points in a mesh.

Template Parameters
MA mesh type whose points each carry a value.
Parameters
mA mesh object.
Returns
Array containing the values of all mesh points.

Definition at line 124 of file utils.hpp.