TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
gf_tests.hpp
Go to the documentation of this file.
1// Copyright (c) 2015-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2015-2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018-2020 Simons Foundation
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You may obtain a copy of the License at
16// https://www.gnu.org/licenses/gpl-3.0.txt
17//
18// Authors: Michel Ferrero, Olivier Parcollet, Nils Wentzell
19
24
25#pragma once
26
28
29namespace triqs::gfs {
30
35
48 template <typename X, typename Y> void assert_gfs_are_close(X const &x, Y const &y, double precision) {
49
50 // meshes must be identical and data close
51 if (x.mesh() != y.mesh()) TRIQS_RUNTIME_ERROR << "GFs have different meshes\n -- 1st Mesh \n" << x.mesh() << "\n -- 2nd Mesh \n" << y.mesh();
52 if (max_element(abs(x.data() - y.data())) > precision)
53 TRIQS_RUNTIME_ERROR << "Gfs have different data. max(abs(x-y)) = " << max_element(abs(x.data() - y.data()));
54 }
55
68 template <typename X, typename Y> void assert_block_gfs_are_close(X const &x, Y const &y, double precision) {
69
70 if (x.size() != y.size()) TRIQS_RUNTIME_ERROR << "Block GFs have different number of blocks";
71 if (x.block_names() != y.block_names()) TRIQS_RUNTIME_ERROR << "Block GFs have different block_names";
72 for (int u = 0; u < x.size(); ++u) assert_gfs_are_close(x[u], y[u], precision);
73 }
74
87 template <typename X, typename Y> void assert_block2_gfs_are_close(X const &x, Y const &y, double precision) {
88
89 if (x.size() != y.size()) TRIQS_RUNTIME_ERROR << "Block2 GFs have different number of blocks";
90 if (x.block_names() != y.block_names()) TRIQS_RUNTIME_ERROR << "Block2 GFs have different block_names";
91 for (int i = 0; i < x.size1(); ++i)
92 for (int j = 0; j < x.size2(); ++j) assert_gfs_are_close(x(i, j), y(i, j), precision);
93 }
94
96
97} // namespace triqs::gfs
TRIQS exception hierarchy and related macros.
void assert_block2_gfs_are_close(X const &x, Y const &y, double precision)
Assert that two doubly-indexed block Green's functions are numerically close.
Definition gf_tests.hpp:87
void assert_gfs_are_close(X const &x, Y const &y, double precision)
Assert that two Green's functions are numerically close.
Definition gf_tests.hpp:48
void assert_block_gfs_are_close(X const &x, Y const &y, double precision)
Assert that two block Green's functions are numerically close.
Definition gf_tests.hpp:68
#define TRIQS_RUNTIME_ERROR
Throw a triqs::runtime_error with the current source location.