TRIQS/triqs_tprf 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
rpa.cpp
1/*******************************************************************************
2 *
3 * TRIQS: a Toolbox for Research in Interacting Quantum Systems
4 *
5 * Copyright (C) 2019, The Simons Foundation and S. Käser
6 * Authors: H. U.R. Strand, S. Käser
7 *
8 * TRIQS is free software: you can redistribute it and/or modify it under the
9 * terms of the GNU General Public License as published by the Free Software
10 * Foundation, either version 3 of the License, or (at your option) any later
11 * version.
12 *
13 * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * TRIQS. If not, see <http://www.gnu.org/licenses/>.
20 *
21 ******************************************************************************/
22
23#include "rpa.hpp"
24#include <omp.h>
25#include "../mpi.hpp"
26
27namespace triqs_tprf {
28
29 template<typename CHI_T, typename CHI_VT>
30 CHI_T solve_rpa_PH(CHI_VT chi0_wk, array_contiguous_view<std::complex<double>, 4> U_arr) {
31
32 using scalar_t = chi_wk_t::scalar_t;
33
34 size_t nb = chi0_wk.target_shape()[0];
35
36 auto chi_wk = make_gf(chi0_wk);
37 chi_wk *= 0;
38
39 // PH grouping of the vertex, from cc+cc+, permuting the last two indices.
40 auto U = make_matrix_view(group_indices_view(U_arr, idx_group<0, 1>, idx_group<3, 2>));
41
42 auto I = nda::eye<scalar_t>(U.shape()[0]);
43
44 auto meshes_mpi = mpi_view(chi0_wk.mesh());
45
46#pragma omp parallel for
47 for (unsigned int idx = 0; idx < meshes_mpi.size(); idx++){
48 auto &[w, k] = meshes_mpi[idx];
49
50 array<scalar_t, 4> chi_arr{nb, nb, nb, nb};
51 array<scalar_t, 4> chi0_arr{chi0_wk[w, k]};
52
53 // PH grouping (permuting last two indices)
54 auto chi = make_matrix_view(group_indices_view(chi_arr, idx_group<0, 1>, idx_group<3, 2>));
55 auto chi0 = make_matrix_view(group_indices_view(chi0_arr, idx_group<0, 1>, idx_group<3, 2>));
56
57 chi = nda::linalg::inv(I - chi0 * U) * chi0; // Inverted BSE specialized for rpa
58
59 chi_wk[w, k] = chi_arr; // assign back using the array_view
60 }
61 chi_wk = mpi::all_reduce(chi_wk);
62
63 return chi_wk;
64 }
65
66 chi_wk_t solve_rpa_PH(chi_wk_vt chi0_wk, array_contiguous_view<std::complex<double>, 4> U_arr) {
67 return solve_rpa_PH<chi_wk_t, chi_wk_vt>(chi0_wk, U_arr);
68 }
69
70 chi_Dwk_t solve_rpa_PH(chi_Dwk_vt chi0_Dwk, array_contiguous_view<std::complex<double>, 4> U_arr) {
71 return solve_rpa_PH<chi_Dwk_t, chi_Dwk_vt>(chi0_Dwk, U_arr);
72 }
73
74 chi_fk_t solve_rpa_PH(chi_fk_vt chi0_fk, array_contiguous_view<std::complex<double>, 4> U_arr) {
75 return solve_rpa_PH<chi_fk_t, chi_fk_vt>(chi0_fk, U_arr);
76 }
77
78} // namespace triqs_tprf