TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
concepts.hpp
Go to the documentation of this file.
1// Copyright (c) 2022-2023 Simons Foundation
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You may obtain a copy of the License at
14// https://www.gnu.org/licenses/gpl-3.0.txt
15//
16// Authors: Olivier Parcollet, Nils Wentzell
17
22
23#pragma once
24
25#include <h5/h5.hpp>
26#include <nda/concepts.hpp>
27
28#include <cstdint>
29#include <concepts>
30#include <cstdint>
31#include <ranges>
32#include <string>
33
34namespace triqs::mesh {
35
40
53 template <typename MP>
54 concept MeshPoint = requires(MP const &mp) {
55 // parent mesh type
56 typename MP::mesh_t;
57
58 // unique index, e.g. Matsubara index, a simple long or a std::array<long, 3> for k-points
59 { mp.index() } -> nda::AnyOf<typename MP::mesh_t::index_t, typename MP::mesh_t::index_t const &>;
60
61 // the data index to access data arrays of GF containers
62 { mp.data_index() } -> nda::AnyOf<typename MP::mesh_t::data_index_t, typename MP::mesh_t::data_index_t const &>;
63
64 // hash of the parent mesh to check for compatibility
65 { mp.mesh_hash() } -> std::same_as<uint64_t>;
66 };
67
84 template <typename M>
85 concept Mesh = std::regular<M> and h5::Storable<M> and requires(M const &m) {
86 // mesh point type
87 typename M::mesh_point_t;
89
90 // sized, forward range of mesh points
91 // Workaround libc++ ADL bug with using-directives affecting versions < 21
92#if not(defined(_LIBCPP_VERSION) and (_LIBCPP_VERSION < 210000))
93 requires std::ranges::forward_range<M>;
94 requires std::ranges::sized_range<M>;
95#endif
96 { *std::begin(m) } -> std::same_as<typename M::mesh_point_t>;
97
98 // index type
99 typename M::index_t;
100
101 // data index type
102 typename M::data_index_t;
103 } and requires(M const &m, typename M::index_t index, typename M::data_index_t data_index, typename M::mesh_point_t mp) {
104 // check validity of an index
105 { m.is_index_valid(index) } -> std::same_as<bool>;
106
107 // index <-> data index conversion
108 { m.to_data_index(index) } -> std::same_as<typename M::data_index_t>;
109 { m.to_index(data_index) } -> std::same_as<typename M::index_t>;
110
111 // access mesh points
112 { m.operator[](data_index) } -> std::same_as<typename M::mesh_point_t>;
113 { m.operator()(index) } -> std::same_as<typename M::mesh_point_t>;
114
115 // Hash for easy checking of MeshPoint and Mesh compatibility
116 { m.mesh_hash() } -> std::same_as<uint64_t>;
117 };
118
129 template <typename M>
130 concept MeshWithValues = Mesh<M> and requires(M const &m, typename M::index_t index) {
131 // value type
132 typename M::value_t;
133
134 // convert an index to its value
135 { m.to_value(index) } -> std::same_as<typename M::value_t>;
136
137 // mesh points can return their value and are castable
138 { (*std::begin(m)).value() } -> nda::AnyOf<typename M::value_t, typename M::value_t const &>;
139 { static_cast<typename M::value_t>(*std::begin(m)) };
140 };
141
143
144} // namespace triqs::mesh
Concept for a mesh point.
Definition concepts.hpp:54
Concept for a mesh with values.
Definition concepts.hpp:130
Concept for a mesh.
Definition concepts.hpp:85