Example #1
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 #2
0
def chi0_w0k_tau_bubble(beta, mu, tb_lattice, nk, nw, sigma_w=None):

    if sigma_w is None:
        g_tr = bubble_setup(beta, mu, tb_lattice, nk, nw)
    else:
        g_tr, sigma_w_cut = bubble_setup(beta,
                                         mu,
                                         tb_lattice,
                                         nk,
                                         nw,
                                         sigma_w=sigma_w)

    print '--> chi0_w0r_from_grt_PH (bubble in tau & r)'
    chi0_wr = chi0_w0r_from_grt_PH(g_tr)
    del grt

    print '--> chi_wk_from_chi_wr (r->k)'
    chi0_wk = chi_wk_from_chi_wr(chi0_wr)
    del chi0_wr

    if sigma is None:
        return chi0_wk
    else:
        return chi0_wk, sigma_w_cut
Example #3
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 #4
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