TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
evaluate.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 "./concepts.hpp"
26#include "./prod.hpp"
27#include "./utils.hpp"
28
29#include <nda/nda.hpp>
30
31#include <tuple>
32#include <utility>
33
34namespace triqs::mesh {
35
40
41 namespace detail {
42
43 // Create a new tuple by removing the first element of a given tuple.
44 template <typename T>
45 requires(std::tuple_size_v<T> >= 1)
46 auto pop_front_tuple(T const &tup) {
47 return [&]<size_t... Is>(std::index_sequence<Is...>) {
48 return std::tie(std::get<Is + 1>(tup)...);
49 }(std::make_index_sequence<std::tuple_size_v<T> - 1>{});
50 }
51 } // namespace detail
52
63 template <Mesh M> FORCEINLINE auto evaluate(M const &, auto const &f, typename M::index_t const &n) { return f(n); }
64
75 template <typename T> FORCEINLINE auto evaluate(Mesh auto const &, auto const &f, mesh::closest_mesh_point_t<T> const &cmp) { return f(cmp); }
76
85 FORCEINLINE auto evaluate(Mesh auto const &, auto const &f, nda::range::all_t) { return f(nda::range::all_t{}); }
86
100 template <Mesh M> FORCEINLINE auto evaluate(M const &m, auto const &f, typename M::mesh_point_t const &mp) {
101 if constexpr (MeshWithValues<M>) {
102 return evaluate(m, f, mp.value());
103 } else {
104 return f(mp);
105 }
106 }
107
148 template <typename... Ds, typename X1, typename... Xs>
149 FORCEINLINE auto evaluate(std::tuple<Ds...> const &tup, auto const &f, X1 const &x1, Xs const &...xs) {
150 auto const &d1 = std::get<0>(tup);
151 if constexpr (sizeof...(Ds) > 1) {
152 return evaluate(
153 detail::pop_front_tuple(tup),
154 [f, &x1, &d1](auto const &...ys) __attribute__((always_inline)) {
155 return evaluate(d1, [f, &ys...](auto const &y1) __attribute__((always_inline)) { return f(y1, ys...); }, x1);
156 },
157 xs...);
158 } else {
159 return evaluate(d1, f, x1);
160 }
161 }
162
177 template <Mesh... Ms, typename... Xs> FORCEINLINE auto evaluate(mesh::prod<Ms...> const &m, auto const &f, Xs const &...xs) {
178 return evaluate(m.components(), f, xs...);
179 }
180
182
183} // namespace triqs::mesh
Product mesh type for combining multiple meshes.
Definition prod.hpp:138
Concept for a mesh with values.
Definition concepts.hpp:130
Concept for a mesh.
Definition concepts.hpp:85
#define FORCEINLINE
Force-inline attribute portable across GCC and Clang.
Definition macros.hpp:64
Provides concepts for mesh points and meshes.
Provides various utilities used with Meshes.
Provides a product mesh type.
Lazy struct used in various function overloads as a placeholder for the closest mesh point to a given...
Definition utils.hpp:186