Example #1
0
def bubble_PI_wk(g_wk):
    r""" Compute the particle-hole bubble from the single particle lattice Green's function

    .. math::
        \Pi_{abcd}(i\omega_n, k) = - 
        \mathcal{F}_{\tau, \mathbf{r} \rightarrow i\omega_n, \mathbf{k}}
        \left\{ G_{d\bar{a}}(\tau, \mathbf{r}) G_{b\bar{c}}(-\tau, -\mathbf{r}) \right\}
    
    Parameters
    ----------

    g_wk : TRIQS Green's function (rank 2) on Matsubara and Brillouinzone meshes
           Single particle lattice Green's function.

    Returns
    -------

    PI_wk : TRIQS Green's function (rank 4) on Matsubara and Brillouinzone meshes
            Particle hole bubble.
    """

    nw = len(g_wk.mesh.components[0]) // 2

    g_wr = fourier_wk_to_wr(g_wk)
    g_tr = fourier_wr_to_tr(g_wr)
    del g_wr
    PI_tr = chi0_tr_from_grt_PH(g_tr)
    del g_tr
    PI_wr = chi_wr_from_chi_tr(PI_tr, nw=nw)
    del PI_tr
    PI_wk = chi_wk_from_chi_wr(PI_wr)
    del PI_wr

    return PI_wk
Example #2
0
def bubble_setup(beta, mu, tb_lattice, nk, nw, sigma_w=None):

    print tprf_banner(), "\n"

    print 'beta  =', beta
    print 'mu    =', mu
    print 'sigma =', (not (sigma == None))

    norb = tb_lattice.NOrbitalsInUnitCell
    print 'nk    =', nk
    print 'nw    =', nw
    print 'norb  =', norb
    print

    ntau = 4 * nw
    ntot = np.prod(nk) * norb**4 + np.prod(nk) * (nw + ntau) * norb**2
    nbytes = ntot * np.complex128().nbytes
    ngb = nbytes / 1024.**3
    print 'Approx. Memory Utilization: %2.2f GB\n' % ngb

    periodization_matrix = np.diag(np.array(list(nk), dtype=np.int32))
    #print 'periodization_matrix =\n', periodization_matrix

    bz = BrillouinZone(tb_lattice.bl)
    bzmesh = MeshBrillouinZone(bz, periodization_matrix)

    print '--> ek'
    e_k = ek_tb_dispersion_on_bzmesh(tb_lattice, bzmesh, bz)

    if sigma is None:
        print '--> g0k'
        wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw)
        g_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh)
    else:
        print '--> gk'
        sigma_w = strip_sigma(nw, beta, sigma)
        g_wk = lattice_dyson_g_wk(mu=mu, e_k=e_k, sigma_w=sigma_w)

    print '--> gr_from_gk (k->r)'
    g_wr = fourier_wk_to_wr(g_wk)
    del g_wk

    print '--> grt_from_grw (w->tau)'
    g_tr = fourier_wr_to_tr(g_wr)
    del g_wr

    if sigma is None:
        return g_tr
    else:
        return g_tr, sigma_w
Example #3
0
def imtime_bubble_chi0_wk(g_wk, nw=1):

    wmesh, kmesh = g_wk.mesh.components

    norb = g_wk.target_shape[0]
    beta = wmesh.beta
    nw_g = len(wmesh)
    nk = len(kmesh)

    ntau = 4 * nw_g
    ntot = np.prod(nk) * norb**4 + np.prod(nk) * (nw_g + ntau) * norb**2
    nbytes = ntot * np.complex128().nbytes
    ngb = nbytes / 1024.**3

    if mpi.is_master_node():
        print tprf_banner(), "\n"
        print 'beta  =', beta
        print 'nk    =', nk
        print 'nw    =', nw_g
        print 'norb  =', norb
        print
        print 'Approx. Memory Utilization: %2.2f GB\n' % ngb

    mpi.report('--> fourier_wk_to_wr')
    g_wr = fourier_wk_to_wr(g_wk)
    del g_wk

    mpi.report('--> fourier_wr_to_tr')
    g_tr = fourier_wr_to_tr(g_wr)
    del g_wr

    if nw == 1:
        mpi.report('--> chi0_w0r_from_grt_PH (bubble in tau & r)')
        chi0_wr = chi0_w0r_from_grt_PH(g_tr)
        del g_tr
    else:
        mpi.report('--> chi0_tr_from_grt_PH (bubble in tau & r)')
        chi0_tr = chi0_tr_from_grt_PH(g_tr)
        del g_tr

        mpi.report('--> chi_wr_from_chi_tr')
        chi0_wr = chi_wr_from_chi_tr(chi0_tr, nw=nw)
        del chi_tr

    mpi.report('--> chi_wk_from_chi_wr (r->k)')
    chi0_wk = chi_wk_from_chi_wr(chi0_wr)
    del chi0_wr

    return chi0_wk
Example #4
0
def test_square_lattice_chi00():

    # ------------------------------------------------------------------
    # -- Discretizations

    n_k = (2, 2, 1)
    nw_g = 500
    nnu = 400
    nw = 1

    # ------------------------------------------------------------------
    # -- tight binding parameters

    beta = 20.0
    mu = 0.0
    t = 1.0

    h_loc = np.array([
        [-0.3, -0.5],
        [-0.5, .4],
    ])

    T = -t * np.array([
        [1., 0.23],
        [0.23, 0.5],
    ])

    # ------------------------------------------------------------------
    # -- tight binding

    print '--> tight binding model'
    t_r = TBLattice(
        units=[(1, 0, 0), (0, 1, 0)],
        hopping={
            # nearest neighbour hopping -t
            (0, 0): h_loc,
            (0, +1): T,
            (0, -1): T,
            (+1, 0): T,
            (-1, 0): T,
        },
        orbital_positions=[(0, 0, 0)] * 2,
        orbital_names=['up_0', 'do_0'],
    )

    e_k = t_r.on_mesh_brillouin_zone(n_k)
    kmesh = e_k.mesh

    wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw_g)

    print '--> g0_wk'
    g0_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh)

    print '--> g0_wr'
    g0_wr = fourier_wk_to_wr(g0_wk)

    print '--> g0_tr'
    g0_tr = fourier_wr_to_tr(g0_wr)

    # ------------------------------------------------------------------
    # -- anaytic chi00

    print '--> chi00_wk analytic'
    chi00_wk_analytic = lindhard_chi00_wk(e_k=e_k, nw=nw, beta=beta, mu=mu)

    print '--> chi00_wr analytic'
    chi00_wr_analytic = chi_wr_from_chi_wk(chi00_wk_analytic)

    # ------------------------------------------------------------------
    # -- imtime chi00

    print '--> chi0_tr_from_grt_PH'
    chi00_tr = chi0_tr_from_grt_PH(g0_tr)

    print '--> chi_wr_from_chi_tr'
    chi00_wr = chi_wr_from_chi_tr(chi00_tr, nw=1)

    print '--> chi_w0r_from_chi_tr'
    chi00_wr_ref = chi_w0r_from_chi_tr(chi00_tr)

    print '--> chi0_w0r_from_grt_PH'
    chi00_wr_opt = chi0_w0r_from_grt_PH(g0_tr)

    print 'dchi00_wr     =', np.max(
        np.abs(chi00_wr_analytic.data - chi00_wr.data))
    print 'dchi00_wr_ref =', np.max(
        np.abs(chi00_wr_analytic.data - chi00_wr_ref.data))
    print 'dchi00_wr_opt =', np.max(
        np.abs(chi00_wr_analytic.data - chi00_wr_opt.data))

    np.testing.assert_array_almost_equal(chi00_wr_analytic.data,
                                         chi00_wr.data,
                                         decimal=8)

    np.testing.assert_array_almost_equal(chi00_wr_analytic.data,
                                         chi00_wr_ref.data,
                                         decimal=4)

    np.testing.assert_array_almost_equal(chi00_wr_analytic.data,
                                         chi00_wr_opt.data,
                                         decimal=4)

    print '--> chi_wk_from_chi_wr'
    chi00_wk_imtime = chi_wk_from_chi_wr(chi00_wr)

    # ------------------------------------------------------------------
    # -- imtime chi00 helper function

    chi00_wk_imtime_2 = imtime_bubble_chi0_wk(g0_wk, nw=1)

    # ------------------------------------------------------------------
    # -- imfreq chi00

    print '--> chi00_wnr'
    chi00_wnr = chi0r_from_gr_PH(nw=1, nnu=nnu, gr=g0_wr)

    print '--> chi00_wnk'
    chi00_wnk = chi0q_from_chi0r(chi00_wnr)

    # -- Test per k and w calculator for chi0_wnk
    print '--> chi00_wnk_ref'
    from triqs_tprf.lattice import chi0q_from_g_wk_PH
    chi00_wnk_ref = chi0q_from_g_wk_PH(nw=1, nnu=nnu, g_wk=g0_wk)

    diff = np.max(np.abs(chi00_wnk.data - chi00_wnk_ref.data))
    print 'chi00_wnk diff =', diff
    np.testing.assert_array_almost_equal(chi00_wnk.data, chi00_wnk_ref.data)

    print '--> chi00_wk_imfreq'
    chi00_wk_imfreq = chi0q_sum_nu(chi00_wnk)

    print '--> chi00_wk_imfreq_tail_corr'
    chi00_wk_imfreq_tail_corr = chi0q_sum_nu_tail_corr_PH(chi00_wnk)

    # ------------------------------------------------------------------
    # -- Compare results

    def cf_chi_w0(chi1, chi2, decimal=9):
        chi1, chi2 = chi1[Idx(0), :].data, chi2[Idx(0), :].data
        diff = np.linalg.norm(chi1 - chi2)
        print '|dchi| =', diff
        np.testing.assert_array_almost_equal(chi1, chi2, decimal=decimal)

    print '--> Cf analytic with imtime'
    cf_chi_w0(chi00_wk_analytic, chi00_wk_imtime, decimal=7)

    print '--> Cf analytic with imtime 2'
    cf_chi_w0(chi00_wk_analytic, chi00_wk_imtime_2, decimal=4)

    print '--> Cf analytic with imfreq'
    cf_chi_w0(chi00_wk_analytic, chi00_wk_imfreq, decimal=2)

    print '--> Cf analytic with imfreq (tail corr)'
    cf_chi_w0(chi00_wk_analytic, chi00_wk_imfreq_tail_corr, decimal=5)
Example #5
0
def imtime_bubble_chi0_wk(g_wk, nw=1):
    ncores = multiprocessing.cpu_count()

    wmesh, kmesh = g_wk.mesh.components

    norb = g_wk.target_shape[0]
    beta = wmesh.beta
    nw_g = len(wmesh)
    nk = len(kmesh)

    ntau = 2 * nw_g

    # -- Memory Approximation

    ng_tr = ntau * np.prod(nk) * norb**2  # storing G(tau, r)
    ng_wr = nw_g * np.prod(nk) * norb**2  # storing G(w, r)
    ng_t = ntau * norb**2  # storing G(tau)

    nchi_tr = ntau * np.prod(nk) * norb**4  # storing \chi(tau, r)
    nchi_wr = nw * np.prod(nk) * norb**4  # storing \chi(w, r)
    nchi_t = ntau * norb**4  # storing \chi(tau)
    nchi_w = nw * norb**4  # storing \chi(w)
    nchi_r = np.prod(nk) * norb**4  # storing \chi(r)

    if nw == 1:
        ntot_case_1 = ng_tr + ng_wr
        ntot_case_2 = ng_tr + nchi_wr + ncores * (nchi_t + 2 * ng_t)
        ntot_case_3 = 4 * nchi_wr

        ntot = max(ntot_case_1, ntot_case_2, ntot_case_3)

    else:
        ntot_case_1 = ng_tr + nchi_tr + ncores * (nchi_t + 2 * ng_t)
        ntot_case_2 = nchi_tr + nchi_wr + ncores * (nchi_w + nchi_t)

        ntot = max(ntot_case_1, ntot_case_2)

    nbytes = ntot * np.complex128().nbytes
    ngb = nbytes / 1024.**3

    if mpi.is_master_node():
        print tprf_banner(), "\n"
        print 'beta  =', beta
        print 'nk    =', nk
        print 'nw    =', nw_g
        print 'norb  =', norb
        print
        print 'Approx. Memory Utilization: %2.2f GB\n' % ngb

    mpi.report('--> fourier_wk_to_wr')
    g_wr = fourier_wk_to_wr(g_wk)
    del g_wk

    mpi.report('--> fourier_wr_to_tr')
    g_tr = fourier_wr_to_tr(g_wr)
    del g_wr

    if nw == 1:
        mpi.report('--> chi0_w0r_from_grt_PH (bubble in tau & r)')
        chi0_wr = chi0_w0r_from_grt_PH(g_tr)
        del g_tr
    else:
        mpi.report('--> chi0_tr_from_grt_PH (bubble in tau & r)')
        chi0_tr = chi0_tr_from_grt_PH(g_tr)
        del g_tr

        mpi.report('--> chi_wr_from_chi_tr')
        chi0_wr = chi_wr_from_chi_tr(chi0_tr, nw=nw)
        del chi0_tr

    mpi.report('--> chi_wk_from_chi_wr (r->k)')
    chi0_wk = chi_wk_from_chi_wr(chi0_wr)
    del chi0_wr

    return chi0_wk
Example #6
0
def gw_sigma_wk(Wr_wk, g_wk, fft_flag=False):
    r""" GW self energy :math:`\Sigma(i\omega_n, \mathbf{k})` calculator

    Fourier transforms the screened interaction and the single-particle
    Green's function to imagiary time and real space.

    .. math::
        G_{ab}(\tau, \mathbf{r}) = \mathcal{F}^{-1}
          \left\{ G_{ab}(i\omega_n, \mathbf{k}) \right\}

    .. math::
        W^{(r)}_{abcd}(\tau, \mathbf{r}) = \mathcal{F}^{-1}
          \left\{ W^{(r)}_{abcd}(i\omega_n, \mathbf{k}) \right\}

    computes the GW self-energy as the product

    .. math::
        \Sigma_{ab}(\tau, \mathbf{r}) =
          \sum_{cd} W^{(r)}_{abcd}(\tau, \mathbf{r}) G_{cd}(\tau, \mathbf{r})

    and transforms back to frequency and momentum

    .. math::
        \Sigma_{ab}(i\omega_n, \mathbf{k}) =
          \mathcal{F} \left\{ \Sigma_{ab}(\tau, \mathbf{r}) \right\}

    Parameters
    ----------

    V_k : TRIQS Green's function (rank 4) on a Brillouinzone mesh
          static bare interaction :math:`V_{abcd}(\mathbf{k})`

    Wr_wk : TRIQS Green's function (rank 4) on Matsubara and Brillouinzone meshes
            retarded screened interaction :math:`W^{(r)}_{abcd}(i\omega_n, \mathbf{k})`
    
    g_wk : TRIQS Green's function (rank 2) on Matsubara and Brillouinzone meshes
           single particle Green's function :math:`G_{ab}(i\omega_n, \mathbf{k})`

    Returns
    -------

    sigma_wk : TRIQS Green's function (rank 2) on Matsubara and Brillouinzone meshes
               GW self-energy :math:`\Sigma_{ab}(i\omega_n, \mathbf{k})`
    """

    if fft_flag:

        nw = len(g_wk.mesh.components[0]) // 2
        ntau = nw * 6 + 1

        mpi.report('g wk -> wr')
        g_wr = fourier_wk_to_wr(g_wk)
        mpi.report('g wr -> tr')
        g_tr = fourier_wr_to_tr(g_wr, nt=ntau)
        del g_wr

        mpi.report('W wk -> wr')
        Wr_wr = chi_wr_from_chi_wk(Wr_wk)
        mpi.report('W wr -> tr')
        Wr_tr = chi_tr_from_chi_wr(Wr_wr, ntau=ntau)
        del Wr_wr

        mpi.report('sigma tr')
        sigma_tr = cpp_gw_sigma_tr(Wr_tr, g_tr)
        del Wr_tr
        del g_tr

        mpi.report('sigma tr -> wr')
        sigma_wr = fourier_tr_to_wr(sigma_tr, nw=nw)

        del sigma_tr
        mpi.report('sigma wr -> wk')
        sigma_wk = fourier_wr_to_wk(sigma_wr)
        del sigma_wr

    else:
        sigma_wk = cpp_gw_sigma_wk_serial_fft(Wr_wk, g_wk)

    return sigma_wk