TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
triqs::mesh::detail::linear< M, T >

#include <triqs/mesh/bases/linear.hpp>

Detailed Description

template<typename M, typename T>
requires std::totally_ordered<T>
class triqs::mesh::detail::linear< M, T >

Linear mesh type.

This class serves as a CRTP base class for other mesh types and satisfies the triqs::mesh::MeshWithValues concept. It is defined by its size \( N \geq 0 \) and the interval \( [a, b] \) with \( a \leq b \). The mesh points are equally spaced on the interval, i.e. the distance between two consecutive mesh points (step size) is constant.

A linear mesh has the following properties:

  • Each mesh point is identified by a unique index \( n \in \{0, 1, \ldots, N-1\} \).
  • An index \( n \) is mapped to the corresponding data index \( d \) by the identity function \( d(n) = n \) and vice versa.
  • An index \( n \) is mapped to the corresponding value \( m \) by the linear function \( m(n) = a + n \cdot \Delta \) sucht that \( m(0) = a \) and \( m(N-1) = b \). The step size of the mesh is \( \Delta = \frac{b - a}{N - 1} \) for \( N > 1 \), otherwise it is undefined. For implementation purposes, we set \( \Delta = 0 \) and \( \Delta^{-1} = 0 \) for \( N = 0 \) and \( \Delta = 0 \) and \( \Delta^{-1} = \infty \) for \( N = 1 \).
  • An arbitrary value \( x \in [a, b] \) is mapped to the closest mesh point with index \( n \) by the function \( n(x) = \left\lfloor \frac{x - a}{\Delta} + 0.5 \right\rfloor \).

See also triqs::mesh::imtime for an example of a derived classes.

Template Parameters
MMesh type that inherits from this base class.
TValue type of the mesh points.

Definition at line 74 of file linear.hpp.

Classes

class  mesh_point_t
 Mesh point of a triqs::mesh::detail::linear mesh. More...

Public Types

using data_index_t = long
 Data index type.
using index_t = long
 Index type.
using value_t = T
 Value type.

Public Member Functions

 linear ()=default
 Default construct an empty linear mesh of size \( N = 0 \).
 linear (value_t a, value_t b, long N)
 Construct a linear mesh on the interval \( [a, b] \) of a given size \( N \geq 0 \).
auto begin () const
 Get an iterator to the beginning of the mesh.
auto cbegin () const
 Get a const iterator to the beginning of the mesh.
auto cend () const
 Get a const iterator to the end of the mesh.
value_t delta () const noexcept
 Get the step size \( \Delta \) of the mesh, i.e. the distance between two consecutive mesh points.
value_t delta_inv () const noexcept
 Get the inverse of the step size of the mesh, i.e. \( 1 / \Delta \).
void deserialize (auto &ar)
 Deserialize the mesh from a generic archive.
auto end () const
 Get an iterator to the end of the mesh.
auto evaluate (auto const &f, double x) const
 Linear interpolation of a function \( f \) defined on a triqs::mesh::detail::linear mesh at a value \(x \in [a, b] \).
long first_index () const
 Get the first index of the mesh, i.e. \( 0 \).
bool is_index_valid (index_t n) const noexcept
 Check if an index \( n \) is valid.
long last_index () const
 Get the last index of the mesh, i.e. \( N - 1 \).
uint64_t mesh_hash () const noexcept
 Get the hash value of the mesh.
mesh_point_t operator() (index_t n) const noexcept
 Function call operator to access a mesh point by its index \( n \in \{0, 1, \ldots, N-1\} \).
bool operator== (linear const &rhs) const =default
 Equal-to comparison operator compares \( N \) and the interval \( [a, b] \).
mesh_point_t operator[] (closest_mesh_point_t< value_t > const &cmp) const noexcept
 Subscript operator to access a mesh point by a value \( x \) contained in a triqs::mesh::closest_mesh_point_t.
mesh_point_t operator[] (long d) const noexcept
 Subscript operator to access a mesh point by its data index \( d \in \{0, 1, \ldots, N-1\} \).
void serialize (auto &ar) const
 Serialize the mesh to a generic archive.
long size () const noexcept
 Get the size \( N \) of the mesh, i.e. the number of mesh points.
index_t to_data_index (closest_mesh_point_t< value_t > const &cmp) const noexcept
 Map a value \( x \in [a, b] \) to the closest mesh point and return its data index \( d(x) \).
data_index_t to_data_index (index_t n) const noexcept
 Map an index \( n \in \{0, 1, \ldots, N-1\} \) to its corresponding data index \( d(n) \).
index_t to_index (closest_mesh_point_t< value_t > const &cmp) const noexcept
 Map a value \( x \in [a, b] \) to the closest mesh point and return its index \( n(x) \).
index_t to_index (data_index_t d) const noexcept
 Map a data index \( d \in \{0, 1, \ldots, N-1\} \) to the corresponding index \( n(d) \).
value_t to_value (index_t n) const noexcept
 Map an index \( n \in \{0, 1, \ldots, N-1\} \) to its corresponding value \( m(n) \).

Protected Member Functions

void h5_read_impl (h5::group g, std::string const &name, const char *exp_format)
 Read the mesh from HDF5.
void h5_write_impl (h5::group g, std::string const &name, const char *format) const
 Write the mesh to HDF5.

Constructor & Destructor Documentation

◆ linear()

template<typename M, typename T>
triqs::mesh::detail::linear< M, T >::linear ( value_t a,
value_t b,
long N )
inline

Construct a linear mesh on the interval \( [a, b] \) of a given size \( N \geq 0 \).

Parameters
aLower bound \( a \) of the interval.
bUpper bound \( b \) of the interval.
NSize of the mesh.

Definition at line 162 of file linear.hpp.

Member Function Documentation

◆ deserialize()

template<typename M, typename T>
void triqs::mesh::detail::linear< M, T >::deserialize ( auto & ar)
inline

Deserialize the mesh from a generic archive.

Parameters
arArchive to deserialize from.

Definition at line 313 of file linear.hpp.

◆ evaluate()

template<typename M, typename T>
auto triqs::mesh::detail::linear< M, T >::evaluate ( auto const & f,
double x ) const
inline

Linear interpolation of a function \( f \) defined on a triqs::mesh::detail::linear mesh at a value \(x \in [a, b] \).

We calculate

\[ f(x) \approx f_n * (1 - w) + f_{n + 1} * w \; , \]

where \( n(x) = \mathrm{min} \left\{ \left\lfloor \frac{x - a}{\Delta} \right\rfloor, N - 2 \right\} \) is the index of the left mesh point used for the interpolation, \( w = \frac{x - m(n)}{\Delta} \) and \( f_n \) is the function value at the mesh point with index \( n \).

Parameters
fCallable object \( f \) containing the function values \( f_n \) at the mesh points.
xValue \( x \) at which to interpolate the function.
Returns
Linear interpolation of \( f(x) \).

Definition at line 364 of file linear.hpp.

◆ h5_read_impl()

template<typename M, typename T>
void triqs::mesh::detail::linear< M, T >::h5_read_impl ( h5::group g,
std::string const & name,
const char * exp_format )
inlineprotected

Read the mesh from HDF5.

Parameters
gh5::group to be read from.
nameName of the subgroup.
exp_formatExpected format string.

Definition at line 338 of file linear.hpp.

◆ h5_write_impl()

template<typename M, typename T>
void triqs::mesh::detail::linear< M, T >::h5_write_impl ( h5::group g,
std::string const & name,
const char * format ) const
inlineprotected

Write the mesh to HDF5.

Parameters
gh5::group to be written to.
nameName of the subgroup.
formatFormat string to be written.

Definition at line 323 of file linear.hpp.

◆ is_index_valid()

template<typename M, typename T>
bool triqs::mesh::detail::linear< M, T >::is_index_valid ( index_t n) const
inlinenodiscardnoexcept

Check if an index \( n \) is valid.

Parameters
nIndex \( n \) to check.
Returns
True if \( 0 \leq n < N \), false otherwise.

Definition at line 184 of file linear.hpp.

◆ operator()()

template<typename M, typename T>
mesh_point_t triqs::mesh::detail::linear< M, T >::operator() ( index_t n) const
inlinenodiscardnoexcept

Function call operator to access a mesh point by its index \( n \in \{0, 1, \ldots, N-1\} \).

Parameters
nIndex \( n \) of the mesh point.
Returns
mesh_point_t with the index \( n \), data index \( d(n) = n \), hash value of the current mesh and value \( m(n) = a + n \cdot \Delta \).

Definition at line 258 of file linear.hpp.

◆ operator[]() [1/2]

template<typename M, typename T>
mesh_point_t triqs::mesh::detail::linear< M, T >::operator[] ( closest_mesh_point_t< value_t > const & cmp) const
inlinenodiscardnoexcept

Subscript operator to access a mesh point by a value \( x \) contained in a triqs::mesh::closest_mesh_point_t.

Parameters
cmptriqs::mesh::closest_mesh_point_t containing the value \( x \).
Returns
mesh_point_t with the index \( n(x) = \left\lfloor \frac{x - a}{\Delta} + 0.5 \right\rfloor \), data index \( d(x) = n(x) \), hash value of the current mesh and value \( m(x) = a + n(x) \cdot \Delta \).

Definition at line 249 of file linear.hpp.

◆ operator[]() [2/2]

template<typename M, typename T>
mesh_point_t triqs::mesh::detail::linear< M, T >::operator[] ( long d) const
inlinenodiscardnoexcept

Subscript operator to access a mesh point by its data index \( d \in \{0, 1, \ldots, N-1\} \).

Parameters
dData index \( d \) of the mesh point.
Returns
mesh_point_t with the index \( n(d) = d \), data index \( d \), hash value of the current mesh and value \( m(d) = a + d \cdot \Delta \).

Definition at line 239 of file linear.hpp.

◆ serialize()

template<typename M, typename T>
void triqs::mesh::detail::linear< M, T >::serialize ( auto & ar) const
inline

Serialize the mesh to a generic archive.

Parameters
arArchive to serialize to.

Definition at line 307 of file linear.hpp.

◆ to_data_index() [1/2]

template<typename M, typename T>
index_t triqs::mesh::detail::linear< M, T >::to_data_index ( closest_mesh_point_t< value_t > const & cmp) const
inlinenodiscardnoexcept

Map a value \( x \in [a, b] \) to the closest mesh point and return its data index \( d(x) \).

Parameters
cmptriqs::mesh::closest_mesh_point_t containing the value \( x \) to map.
Returns
Data index \( d(x) = \left\lfloor \frac{x - a}{\Delta} + 0.5 \right\rfloor \).

Definition at line 208 of file linear.hpp.

◆ to_data_index() [2/2]

template<typename M, typename T>
data_index_t triqs::mesh::detail::linear< M, T >::to_data_index ( index_t n) const
inlinenodiscardnoexcept

Map an index \( n \in \{0, 1, \ldots, N-1\} \) to its corresponding data index \( d(n) \).

Parameters
nIndex \( n \) to map.
Returns
Data index \( d(n) = n \).

Definition at line 197 of file linear.hpp.

◆ to_index() [1/2]

template<typename M, typename T>
index_t triqs::mesh::detail::linear< M, T >::to_index ( closest_mesh_point_t< value_t > const & cmp) const
inlinenodiscardnoexcept

Map a value \( x \in [a, b] \) to the closest mesh point and return its index \( n(x) \).

Parameters
cmptriqs::mesh::closest_mesh_point_t containing the value \( x \) to map.
Returns
Index \( n(x) = \left\lfloor \frac{x - a}{\Delta} + 0.5 \right\rfloor \).

Definition at line 227 of file linear.hpp.

◆ to_index() [2/2]

template<typename M, typename T>
index_t triqs::mesh::detail::linear< M, T >::to_index ( data_index_t d) const
inlinenodiscardnoexcept

Map a data index \( d \in \{0, 1, \ldots, N-1\} \) to the corresponding index \( n(d) \).

Parameters
dData index \( d \) to map.
Returns
Index \( n(d) = d \).

Definition at line 216 of file linear.hpp.

◆ to_value()

template<typename M, typename T>
value_t triqs::mesh::detail::linear< M, T >::to_value ( index_t n) const
inlinenodiscardnoexcept

Map an index \( n \in \{0, 1, \ldots, N-1\} \) to its corresponding value \( m(n) \).

Parameters
nIndex \( n \) to map.
Returns
Value of the mesh point \( m(n) = a + n \cdot \Delta \).

Definition at line 266 of file linear.hpp.


The documentation for this class was generated from the following file: