/*******************************************************************************
*
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
*
* Copyright (C) 2012 by M. Ferrero, O. Parcollet
*
* TRIQS is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* TRIQS. If not, see .
*
******************************************************************************/
#include "functions.hpp"
#include
namespace triqs { namespace gfs {
dcomplex F(dcomplex a,double b,double Beta) {return -a/(1+exp(-Beta*b));}
using tqa::array;
//-------------------------------------------------------
// For Imaginary Matsubara Frequency functions
// ------------------------------------------------------
tqa::matrix density( gf_view const & G) {
dcomplex I(0,1);
auto sh = G.data().shape().front_pop();
auto Beta = G.domain().beta;
local::tail_view t = G(freq_infty());
if (!t.is_decreasing_at_infinity()) TRIQS_RUNTIME_ERROR<<" density computation : Green Function is not as 1/omega or less !!!";
const size_t N1=sh[0], N2 = sh[1];
tqa::array dens_part(sh), dens_tail(sh), dens(sh);
tqa::matrix res(sh);
dens_part()=0;dens()=0;dens_tail()=0;
for (size_t n1=0; n1 density( gf_view const & gl) {
auto sh = gl.data().shape().front_pop();
tqa::matrix res(sh);
res() = 0.0;
for (auto l : gl.mesh()) {
res -= sqrt(2*l.index()+1) * gl(l);
}
res /= gl.domain().beta;
return res;
}
// compute a tail from the Legendre GF
// this is Eq. 8 of our paper
local::tail_view get_tail(gf_view const & gl, int size = 10, int omin = -1) {
auto sh = gl.data().shape().front_pop();
local::tail t(sh, size, omin);
t.data() = 0.0;
for (int p=1; p<=t.order_max(); p++)
for (auto l : gl.mesh())
t(p) += (triqs::utility::legendre_t(l.index(),p)/pow(gl.domain().beta,p)) * gl(l);
return t;
}
// Impose a discontinuity G(\tau=0)-G(\tau=\beta)
void enforce_discontinuity(gf_view & gl, tqa::array_view disc) {
double norm = 0.0;
tqa::vector t(gl.data().shape()[0]);
for (int i=0; i corr(disc.shape()); corr() = 0;
for (auto l : gl.mesh()) {
corr += t(l.index()) * gl(l);
}
tqa::range R;
for (auto l : gl.mesh()) {
gl.data()(l.index(),R,R) += (disc - corr) * t(l.index()) / norm;
}
}
}}