TRIQS/triqs_tprf 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
fourier_lattice.cpp
1// Copyright (c) 2014-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2014-2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018-2019 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, tayral
19
20#include "./fourier_common.hpp"
21#include <itertools/itertools.hpp>
22
23#include <fftw3.h>
24
25namespace triqs_tprf::fourier {
26
27 // The implementation is almost the same in both cases...
28 template <typename M1, typename M2> fourier_plan __impl_plan(int fftw_backward_forward, M1 const &out_mesh, gf_vec_cvt<M2> g_in) {
29
30 auto g_out = gf_vec_t<M1>{out_mesh, std::array{g_in.target_shape()[0]}};
31 long n_others = g_in.data().shape()[1];
32
33 auto dims = g_in.mesh().dims();
34 auto dims_int = stdutil::make_std_array<int>(dims);
35
36 return _fourier_base_plan(g_in.data(), g_out.data(), dims.size(), dims_int.data(), n_others, fftw_backward_forward);
37 }
38
39 fourier_plan _fourier_plan(triqs::mesh::cyclat const &r_mesh, gf_vec_cvt<brzone> gk) { return __impl_plan(FFTW_FORWARD, r_mesh, gk); }
40 fourier_plan _fourier_plan(triqs::mesh::brzone const &k_mesh, gf_vec_cvt<cyclat> gr) { return __impl_plan(FFTW_BACKWARD, k_mesh, gr); }
41
42 // ------------------------ DIRECT TRANSFORM --------------------------------------------
43
44 gf_vec_t<cyclat> _fourier_impl(triqs::mesh::cyclat const &r_mesh, gf_vec_cvt<brzone> gk, fourier_plan &p) {
45
46 auto gr = gf_vec_t<cyclat>{r_mesh, {gk.target_shape()[0]}};
47 _fourier_base(gk.data(), gr.data(), p);
48
49 gr.data() /= gk.mesh().size();
50 return gr;
51 }
52
53 // ------------------------ INVERSE TRANSFORM --------------------------------------------
54
55 gf_vec_t<brzone> _fourier_impl(triqs::mesh::brzone const &k_mesh, gf_vec_cvt<cyclat> gr, fourier_plan &p) {
56 auto gk = gf_vec_t<brzone>{k_mesh, {gr.target_shape()[0]}};
57 _fourier_base(gr.data(), gk.data(), p);
58 return gk;
59 }
60
61} // namespace triqs_tprf::fourier