TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
partial_transform.hpp
Go to the documentation of this file.
1// Copyright (c) 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: Michel Ferrero, Olivier Parcollet, Nils Wentzell
17
22
23#pragma once
24
25#include "../gf/flatten.hpp"
26#include "../gf/gf.hpp"
28
29#include "../../mesh/prod.hpp"
31
32namespace triqs::gfs {
33
50 template <int N = 0, typename... M, typename Target> auto partial_transform(gf_const_view<mesh::prod<M...>, Target> gin, auto lambda) {
51
52 // Flatten the gf except for the variable N
53 auto gin_flatten = flatten_gf_2d<N>(gin);
54
55 auto g2_flat = lambda(gin_flatten);
56
57 auto mesh_tpl = triqs::tuple::replace<N>(gin.mesh().components(), g2_flat.mesh());
58 auto g_out = gf{mesh::prod{mesh_tpl}, gin.target_shape()};
59
60 unflatten_2d<N>(g_out.data(), g2_flat.data());
61 return g_out;
62 }
63
64} // namespace triqs::gfs
A read-only, non-owning view of a Green's function.
The owning Green's function container.
Definition gf.hpp:194
Product mesh type for combining multiple meshes.
Definition prod.hpp:138
Provides utilities to flatten the data of arrays and Green's functions into a two-dimensional form.
Provides the triqs::gfs::gf_const_view container, a read-only non-owning view of a Green's function.
Provides the Green's function class.
auto partial_transform(gf_const_view< mesh::prod< M... >, Target > gin, auto lambda)
Apply a transform to a single mesh component of a product-mesh Green's function.
void unflatten_2d(nda::MemoryArray auto &&out, nda::MemoryArray auto const &afl)
Inverse of triqs::gfs::flatten_2d: scatter a two-dimensional array back into a higher-rank array.
Definition flatten.hpp:65
auto flatten_gf_2d(G const &g)
Flatten a Green's function into a single-mesh, tensor-valued Green's function.
Definition flatten.hpp:85
auto replace(T &&t, R &&r)
Return a copy of a tuple with the elements at the given positions replaced by a given value.
Provides a product mesh type.
Generic tuple manipulation tools.