TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
factories.hpp
Go to the documentation of this file.
1// Copyright (c) 2020 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: Michel Ferrero, Olivier Parcollet
17
22
23#pragma once
24
25#include "./block_gf.hpp"
27
28#include <initializer_list>
29#include <string>
30#include <utility>
31#include <vector>
32
33namespace triqs::gfs {
34
39
40 // ------------------------------- Free Factories for regular type --------------------------------------------------
41
50 template <typename V, typename T, typename L> block_gf<V, T, L> make_block_gf(int n, gf<V, T, L> const &g) { return {n, g}; }
51
59 template <typename V, typename T, typename L> block_gf<V, T, L> make_block_gf(std::vector<gf<V, T, L>> v) { return {std::move(v)}; }
60
68 template <typename V, typename T, typename L> block_gf<V, T, L> make_block_gf(std::initializer_list<gf<V, T, L>> const &v) { return {v}; }
69
78 template <typename V, typename T, typename L> block_gf<V, T, L> make_block_gf(std::vector<std::string> const &b, gf<V, T, L> const &g) {
79 return {b, g};
80 }
81
90 template <typename V, typename T, typename L> block_gf<V, T, L> make_block_gf(std::vector<std::string> const &b, std::vector<gf<V, T, L>> v) {
91 return {b, std::move(v)};
92 }
93
102 template <typename V, typename T, typename L>
103 block_gf<V, T, L> make_block_gf(std::vector<std::string> b, std::initializer_list<gf<V, T, L>> const &v) {
104 return {b, v};
105 }
106
107 // ------------------------------- Free Factories for block_gf_view and block_gf_const_view
108
118 template <typename G0, typename... G> block_gf_view_of<G0> make_block_gf_view(G0 &&g0, G &&...g) {
119 return {details::_make_block_names1(sizeof...(G) + 1), {std::forward<G0>(g0), std::forward<G>(g)...}};
120 }
121
129 template <typename Gf> block_gf_view_of<Gf> make_block_gf_view(std::vector<Gf> &v) {
130 static_assert(Gf::is_view);
131 return {details::_make_block_names1(v.size()), v};
132 }
133
135 template <typename Gf> block_gf_view_of<Gf> make_block_gf_view(std::vector<Gf> &&v) {
136 static_assert(Gf::is_view);
137 return {details::_make_block_names1(v.size()), std::move(v)};
138 }
139
148 template <typename Gf> block_gf_view_of<Gf> make_block_gf_view(std::vector<std::string> b, std::vector<Gf> &v) {
149 static_assert(Gf::is_view);
150 return {std::move(b), v};
151 }
152
154 template <typename Gf> block_gf_view_of<Gf> make_block_gf_view(std::vector<std::string> b, std::vector<Gf> &&v) {
155 static_assert(Gf::is_view);
156 return {std::move(b), std::move(v)};
157 }
158
159 // --- same with const_view
160
170 template <typename G0, typename... G> block_gf_const_view_of<G0> make_block_gf_const_view(G0 &&g0, G &&...g) {
171 return {details::_make_block_names1(sizeof...(G) + 1), {std::forward<G0>(g0), std::forward<G>(g)...}};
172 }
173
181 template <typename Gf> block_gf_const_view_of<Gf> make_block_gf_const_view(std::vector<Gf> &v) {
182 static_assert(Gf::is_view);
183 return {details::_make_block_names1(v.size()), v};
184 }
185
187 template <typename Gf> block_gf_const_view_of<Gf> make_block_gf_const_view(std::vector<Gf> &&v) {
188 static_assert(Gf::is_view);
189 return {details::_make_block_names1(v.size()), std::move(v)};
190 }
191
200 template <typename Gf> block_gf_const_view_of<Gf> make_block_gf_const_view(std::vector<std::string> b, std::vector<Gf> &v) {
201 static_assert(Gf::is_view);
202 return {std::move(b), v};
203 }
204
206 template <typename Gf> block_gf_const_view_of<Gf> make_block_gf_const_view(std::vector<std::string> b, std::vector<Gf> &&v) {
207 static_assert(Gf::is_view);
208 return {std::move(b), std::move(v)};
209 }
210
211 // ------------------------------- Free Factories for block2_gf --------------------------------------------------
212
222 template <typename V, typename T, typename L> block2_gf<V, T, L> make_block2_gf(int n, int p, gf<V, T, L> const &g) { return {n, p, g}; }
223
236 template <typename V, typename T, typename L>
237 block2_gf<V, T, L> make_block2_gf(std::vector<std::string> const &block_names1, std::vector<std::string> const &block_names2,
238 std::vector<std::vector<gf<V, T, L>>> vv) {
239 if (block_names1.size() != vv.size())
240 TRIQS_RUNTIME_ERROR << "make_block2_gf(vector<string>, vector<string>>, vector<vector<gf>>): incompatible outer vector size!";
241 for (auto const &v : vv) {
242 if (block_names2.size() != v.size())
243 TRIQS_RUNTIME_ERROR << "make_block2_gf(vector<string>, vector<string>>, vector<vector<gf>>): incompatible inner vector size!";
244 }
245 return {{block_names1, block_names2}, std::move(vv)};
246 }
247
248 // ------------------------------- Free Factories for block2_gf_view and block2_gf_const_view --------------------------------------------------
249
257 template <typename Gf> block2_gf_view_of<Gf> make_block2_gf_view(std::vector<std::vector<Gf>> &v) {
258 static_assert(Gf::is_view);
259 if (v.size() == 0) return {details::_make_block_names2(0, 0), v};
260 return {details::_make_block_names2(v.size(), v[0].size()), v};
261 }
262
264 template <typename Gf> block2_gf_view_of<Gf> make_block2_gf_view(std::vector<std::vector<Gf>> &&v) {
265 static_assert(Gf::is_view);
266 if (v.size() == 0) return {details::_make_block_names2(0, 0), v};
267 return {details::_make_block_names2(v.size(), v[0].size()), std::move(v)};
268 }
269
279 template <typename Gf>
280 block2_gf_view_of<Gf> make_block2_gf_view(std::vector<std::string> block_names1, std::vector<std::string> block_names2,
281 std::vector<std::vector<Gf>> &v) {
282 static_assert(Gf::is_view);
283 return {{std::move(block_names1), std::move(block_names2)}, v};
284 }
285
287 template <typename Gf>
288 block2_gf_view_of<Gf> make_block2_gf_view(std::vector<std::string> block_names1, std::vector<std::string> block_names2,
289 std::vector<std::vector<Gf>> &&v) {
290 static_assert(Gf::is_view);
291 return {{std::move(block_names1), std::move(block_names2)}, std::move(v)};
292 }
293
294 // --- same for const_view
295
303 template <typename Gf> block2_gf_const_view_of<Gf> make_block2_gf_const_view(std::vector<std::vector<Gf>> &v) {
304 static_assert(Gf::is_view);
305 if (v.size() == 0) return {details::_make_block_names2(0, 0), v};
306 return {details::_make_block_names2(v.size(), v[0].size()), v};
307 }
308
310 template <typename Gf> block2_gf_const_view_of<Gf> make_block2_gf_const_view(std::vector<std::vector<Gf>> &&v) {
311 static_assert(Gf::is_view);
312 if (v.size() == 0) return {details::_make_block_names2(0, 0), v};
313 return {details::_make_block_names2(v.size(), v[0].size()), std::move(v)};
314 }
315
325 template <typename Gf>
326 block2_gf_const_view_of<Gf> make_block2_gf_const_view(std::vector<std::string> block_names1, std::vector<std::string> block_names2,
327 std::vector<std::vector<Gf>> &v) {
328 static_assert(Gf::is_view);
329 return {{std::move(block_names1), std::move(block_names2)}, v};
330 }
331
333 template <typename Gf>
334 block2_gf_const_view_of<Gf> make_block2_gf_const_view(std::vector<std::string> block_names1, std::vector<std::string> block_names2,
335 std::vector<std::vector<Gf>> &&v) {
336 static_assert(Gf::is_view);
337 return {{std::move(block_names1), std::move(block_names2)}, std::move(v)};
338 }
339
341
342} // namespace triqs::gfs
Provides the block Green's function container.
The owning block Green's function container.
Definition block_gf.hpp:259
The owning Green's function container.
Definition gf.hpp:194
TRIQS exception hierarchy and related macros.
block_gf< Mesh, Target, Layout, 2 > block2_gf
Owning two-index block Green's function (a matrix of blocks).
Definition block_gf.hpp:70
block_gf_const_view_of< G0 > make_block_gf_const_view(G0 &&g0, G &&...g)
Make a triqs::gfs::block_gf_const_view from a list of Green's function views (block names default to ...
block2_gf_const_view_of< Gf > make_block2_gf_const_view(std::vector< std::vector< Gf > > &v)
Make a triqs::gfs::block2_gf_const_view from a matrix of views (block names default to "0",...
block2_gf_view_of< Gf > make_block2_gf_view(std::vector< std::vector< Gf > > &v)
Make a triqs::gfs::block2_gf_view from a matrix of views (block names default to "0",...
block_gf_view_of< G0 > make_block_gf_view(G0 &&g0, G &&...g)
Make a triqs::gfs::block_gf_view from a list of Green's function views (block names default to "0",...
block2_gf< V, T, L > make_block2_gf(int n, int p, gf< V, T, L > const &g)
Make a triqs::gfs::block2_gf of n x p copies of a Green's function.
block_gf< V, T, L > make_block_gf(int n, gf< V, T, L > const &g)
Make a triqs::gfs::block_gf of n copies of a Green's function (block names default to "0",...
Definition factories.hpp:50
block2_gf_const_view< get_mesh_t< G >, get_target_t< G > > block2_gf_const_view_of
The triqs::gfs::block2_gf_const_view type matching the mesh and target of G.
Definition block_gf.hpp:187
block2_gf_view< get_mesh_t< G >, get_target_t< G > > block2_gf_view_of
The triqs::gfs::block2_gf_view type matching the mesh and target of G.
Definition block_gf.hpp:184
block_gf_const_view< get_mesh_t< G >, get_target_t< G > > block_gf_const_view_of
The triqs::gfs::block_gf_const_view type matching the mesh and target of G.
Definition block_gf.hpp:178
block_gf_view< get_mesh_t< G >, get_target_t< G > > block_gf_view_of
The triqs::gfs::block_gf_view type matching the mesh and target of G.
Definition block_gf.hpp:175
#define TRIQS_RUNTIME_ERROR
Throw a triqs::runtime_error with the current source location.