Esempio n. 1
0
    def on_mesh_brillouin_zone(self, n_k):

        """ Construct a discretization of the tight binding model in
        reciprocal space with given number of k-points.

        Parameters
        ----------

        n_k : three-tuple of ints
            Number of k-points in every dimension.

        Returns
        -------

        e_k : TRIQS Greens function on a Brillioun zone mesh
            Reciprocal space tight binding dispersion.

        """
        
        target_shape = [self.NOrbitalsInUnitCell] * 2

        kmesh = self.get_kmesh(n_k)

        e_k = Gf(mesh=kmesh, target_shape=target_shape)

        k_vec = np.array([k.value for k in kmesh])
        k_vec_rel = np.dot(np.linalg.inv(self.bz.units()).T, k_vec.T).T   
        e_k.data[:] = self.hopping(k_vec_rel.T).transpose(2, 0, 1)

        return e_k
Esempio n. 2
0
File: bse.py Progetto: mzingl/tprf
def fixed_fermionic_window_python_wnk(chi_wnk, nwf):
    r""" Helper routine to reduce the number of fermionic Matsubara 
    frequencies :math:`\nu` in a two frequency and one momenta dependent
    generalized susceptibility :math:`\chi_{abcd}(\omega, \nu, \mathbf{k})`.

    Parameters
    ----------

    chi_wnk : two frequency and one momenta dependent generalized 
              susceptibility :math:`\chi_{abcd}(\omega, \nu, \mathbf{k})`.
    nwf : number of fermionic frequencies to keep.

    Returns
    -------

    chi_wnk_out : Susceptibility with reduced number of fermionic Matsubara
                  frequencies.
    """

    g2 = chi_wnk
    wmesh, nmesh, kmesh = g2.mesh.components

    beta = g2.mesh.components[0].beta
    nmesh_small = MeshImFreq(beta=beta, S='Fermion', n_max=nwf)

    chi_wnk_out = Gf(mesh=MeshProduct(wmesh, nmesh_small, kmesh),
                     target_shape=g2.target_shape)

    n = g2.data.shape[1]
    s = n / 2 - nwf
    e = n / 2 + nwf

    chi_wnk_out.data[:] = g2.data[:, s:e, :]

    return chi_wnk_out
Esempio n. 3
0
    def compute_chi0_k(self):

        from pytriqs.gf import Gf

        chi0_k = Gf(mesh=self.e_k.mesh, target_shape=self.shape_abcd)
        chi0_k.data[:] = self.chi0_kabcd

        return chi0_k
Esempio n. 4
0
def Gf_from_struct(mesh, struct):
    # Without block structure
    if not isinstance(struct[0], list):
        return Gf(mesh=mesh, indices=struct)

    # With block structure
    G_lst = []
    for bl, idx_lst in struct:
        G_lst.append(Gf(mesh=mesh, indices=idx_lst))
    return BlockGf(name_list=[bl[0] for bl in struct], block_list=G_lst)
Esempio n. 5
0
def ek_tb_dispersion_on_bzmesh(tb_lattice, bzmesh, bz):
    """ Evaluate dispersion on bzmesh from tight binding model. """

    n_orb = tb_lattice.NOrbitalsInUnitCell
    ek = Gf(mesh=bzmesh, target_shape=[n_orb] * 2)

    k_vec = np.array([k.value for k in bzmesh])
    k_vec_rel = get_relative_k_from_absolute(k_vec, bz.units())

    ek.data[:] = tb_lattice.hopping(k_vec_rel.T).transpose(2, 0, 1)

    return ek
Esempio n. 6
0
    def on_mesh_brillouin_zone(self, n_k):

        target_shape = [self.NOrbitalsInUnitCell] * 2

        kmesh = self.get_kmesh(n_k)

        e_k = Gf(mesh=kmesh, target_shape=target_shape)

        k_vec = np.array([k.value for k in kmesh])
        k_vec_rel = np.dot(np.linalg.inv(self.bz.units()).T, k_vec.T).T
        e_k.data[:] = self.hopping(k_vec_rel.T).transpose(2, 0, 1)

        return e_k
Esempio n. 7
0
def delta_inv(beta, nw, nk=100):

    mesh = MeshImFreq(beta, 'Fermion', n_max=nw)

    Sigma0, Sigma1 = 1.337, 3.5235
    ek = 2. * np.random.random(nk) - 1.

    G = Gf(mesh=mesh, target_shape=[1, 1])
    Sig = G.copy()
    for w in Sig.mesh:
        Sig[w][:] = Sigma0 + Sigma1 / w

    for e in ek:
        G << G + inverse(iOmega_n - e - Sig)

    G /= nk

    Delta = G.copy()
    Delta << inverse(G) - iOmega_n + Sig

    sum_ek = -np.sum(ek) / nk

    Roo = np.abs(Sigma0) + 1.

    w = [w for w in mesh]
    wmax = np.abs(w[-1].value)

    tail, err = Delta.fit_tail()

    order = len(tail)

    trunc_err_anal = (Roo / (0.8 * wmax))**order

    ratio = tail[0] / sum_ek
    diff = np.abs(1 - ratio)

    print '-' * 72
    print 'beta =', beta
    print 'nw =', nw
    print 'wmax =', wmax
    print 'tail_fit order =', len(tail)
    print 'tail_fit err =', err
    print tail[:3]
    #print sum_ek
    print 'trunc_err_anal =', trunc_err_anal
    print 'ratio =', ratio
    print 'diff =', diff

    return diff[0, 0]
Esempio n. 8
0
def convert_from_ndarray_to_triqs(U_Q, Q, cell, kpts):

    from pytriqs.gf import Gf, MeshBrillouinZone
    from pytriqs.lattice.lattice_tools import BrillouinZone
    from pytriqs.lattice.lattice_tools import BravaisLattice

    bl = BravaisLattice(cell, [(0, 0, 0)])
    bz = BrillouinZone(bl)
    bzmesh = MeshBrillouinZone(bz, np.diag(np.array(kpts, dtype=np.int32)))

    u_q = Gf(mesh=bzmesh, target_shape=U_Q.shape[1:])

    tmp = np.array(Q * kpts[None, :], dtype=np.int)
    I = [tuple(tmp[i]) for i in xrange(Q.shape[0])]

    for qidx, i in enumerate(I):
        for k in bzmesh:

            # -- Generalize this transform absolute to relative k-points
            a = cell[0, 0]
            q = k * 0.5 * a / np.pi

            j = tuple(np.array(kpts * q, dtype=np.int))
            if i == j: u_q[k].data[:] = U_Q[qidx]

    return u_q
Esempio n. 9
0
def setup_dmft_calculation(p):

    p = copy.deepcopy(p)
    p.iter = 0

    # -- Local Hubbard interaction
    from pytriqs.operators import n
    p.solve.h_int = p.U*n('up', 0)*n('do', 0) - 0.5*p.U*(n('up', 0) + n('do', 0))

    # -- 2D square lattice w. nearest neighbour hopping t
    from triqs_tprf.tight_binding import TBLattice
    T = -p.t * np.eye(2)
    H = TBLattice(
        units = [(1, 0, 0), (0, 1, 0)],
        orbital_positions = [(0,0,0)]*2,
        orbital_names = ['up', 'do'],
        hopping = {(0, +1) : T, (0, -1) : T, (+1, 0) : T, (-1, 0) : T})
    
    p.e_k = H.on_mesh_brillouin_zone(n_k = (p.n_k, p.n_k, 1))

    # -- Initial zero guess for the self-energy    
    p.sigma_w = Gf(mesh=MeshImFreq(p.init.beta, 'Fermion', p.init.n_iw), target_shape=[2, 2])
    p.sigma_w.zero()

    return p
Esempio n. 10
0
def solve_lattice_bse(parm, momsus=False):

    print '--> solve_lattice_bse'

    print 'nw =', parm.nw
    print 'nwf =', parm.nwf

    # ------------------------------------------------------------------
    # -- Setup lattice

    bl = BravaisLattice([(1, 0, 0), (0, 1, 0)])

    bz = BrillouinZone(bl)
    bzmesh = MeshBrillouinZone(bz, n_k=1)  # only one k-point

    e_k = Gf(mesh=bzmesh, target_shape=[1, 1])
    e_k *= 0.

    # ------------------------------------------------------------------
    # -- Lattice single-particle Green's function

    mesh = MeshImFreq(beta=parm.beta, S='Fermion', n_max=parm.nwf_gf)

    parm.Sigma_iw = parm.G_iw.copy()
    G0_iw = parm.G_iw.copy()

    G0_iw << inverse(iOmega_n + 0.5 * parm.U)
    parm.Sigma_iw << inverse(G0_iw) - inverse(parm.G_iw)

    parm.mu = 0.5 * parm.U
    g_wk = lattice_dyson_g_wk(mu=parm.mu, e_k=e_k, sigma_w=parm.Sigma_iw)
    g_wr = fourier_wk_to_wr(g_wk)

    # ------------------------------------------------------------------
    # -- Non-interacting generalized lattice susceptibility

    chi0_wr = chi0r_from_gr_PH(nw=parm.nw, nnu=parm.nwf, gr=g_wr)
    chi0_wk = chi0q_from_chi0r(chi0_wr)

    # ------------------------------------------------------------------
    # -- Solve lattice BSE

    parm.chi_wk = chiq_from_chi0q_and_gamma_PH(chi0_wk, parm.gamma_m)

    # ------------------------------------------------------------------
    # -- Store results and static results

    num = np.squeeze(parm.chi_wk.data.real)
    ref = np.squeeze(parm.chi_m.data.real)

    diff = np.max(np.abs(num - ref))
    print 'diff =', diff

    parm.chi_w = chiq_sum_nu_q(parm.chi_wk)  # static suscept

    return parm
Esempio n. 11
0
def fixed_fermionic_window_python_wnk(g2, nwf):

    #nw = (g2.data.shape[0] + 1) / 2

    wmesh, nmesh, kmesh = g2.mesh.components

    beta = g2.mesh.components[0].beta
    nmesh_small = MeshImFreq(beta=beta, S='Fermion', n_max=nwf)

    g2_out = Gf(mesh=MeshProduct(wmesh, nmesh_small, kmesh),
                target_shape=g2.target_shape)

    n = g2.data.shape[1]
    s = n / 2 - nwf
    e = n / 2 + nwf

    g2_out.data[:] = g2.data[:, s:e, :]

    return g2_out
Esempio n. 12
0
def put_gf_on_mesh(g_in, wmesh):

    assert (len(wmesh) <= len(g_in.mesh))

    g_out = Gf(mesh=wmesh, target_shape=g_in.target_shape)

    for w in wmesh:
        index = w.linear_index + wmesh.first_index()  # absolute index
        g_out[w] = g_in[Idx(index)]

    return g_out
Esempio n. 13
0
def G2_loc_fixed_fermionic_window_python(g2, nwf):
    """ Limit the last two fermionic freqiencies of a three
    frequency Green's function object :math:`G(\omega, \nu, \nu')`
    to ``nwf``. """

    nw = (g2.data.shape[0] + 1) / 2
    n = g2.data.shape[1]
    beta = g2.mesh.components[0].beta

    assert (n / 2 >= nwf)

    from pytriqs.gf import Gf, MeshImFreq, MeshProduct

    mesh_iw = MeshImFreq(beta=beta, S='Boson', n_max=nw)
    mesh_inu = MeshImFreq(beta=beta, S='Fermion', n_max=nwf)
    mesh_prod = MeshProduct(mesh_iw, mesh_inu, mesh_inu)

    g2_out = Gf(mesh=mesh_prod, target_shape=g2.target_shape)

    s = n / 2 - nwf
    e = n / 2 + nwf

    g2_out.data[:] = g2.data[:, s:e, s:e]
    return g2_out
Esempio n. 14
0
 def __init__(self,
              g1_inu,
              n_iw,
              n_inu,
              blocks_to_calculate=[],
              blockstructure_to_compare_with="AABB"):
     """
     g1_inu has to be a BlockGf of GfImFreq
     """
     mb = MeshImFreq(g1_inu.mesh.beta, "Boson", n_iw)
     mf = MeshImFreq(g1_inu.mesh.beta, "Fermion", n_inu)
     blockmesh = MeshProduct(mb, mf, mf)
     blocks = []
     self.gf2_struct = dict()
     for i in g1_inu.indices:
         blocksR = []
         for j in g1_inu.indices:
             blockindex = (i, j)
             m, n = g1_inu[i].data.shape[1], g1_inu[j].data.shape[1]
             blockshape = [m, m, n, n]
             blocksR.append(Gf(mesh=blockmesh, target_shape=blockshape))
             self.gf2_struct[blockindex] = (m, n)
         blocks.append(blocksR)
     g1_indices = [i for i in g1_inu.indices]
     Block2Gf.__init__(self, g1_indices, g1_indices, blocks)
     self.beta = g1_inu.mesh.beta
     # mesh adjustments for negative frequencies and g1/g2 mesh-offsets
     self.n_iw = len(mb)
     self.n_inu = len(mf)
     self.bosonic_mesh = np.array(
         [w for w in self[blockindex].mesh.components[0]])
     self.fermionic_mesh = np.array(
         [w for w in self[blockindex].mesh.components[1]])
     g1_mesh = np.array([w for w in g1_inu.mesh])
     fermionic_mesh_offset = np.argwhere(
         g1_mesh.imag == self.fermionic_mesh.imag[0])[0, 0]
     bosonic_mesh_offset = np.argwhere(0 == self.bosonic_mesh.imag)[0, 0]
     self.f_mesh_inds = np.arange(fermionic_mesh_offset,
                                  self.n_inu + fermionic_mesh_offset)
     self.b_mesh_inds = np.arange(-bosonic_mesh_offset,
                                  self.n_iw - bosonic_mesh_offset)
     if len(blocks_to_calculate) == 0:
         blocks_to_calculate = self.indices
     self.blockstruct = blockstructure_to_compare_with
     contractions = {"direct": [1, 0, 3, 2], "exchange": [1, 2, 3, 0]}
     for blockindex in blocks_to_calculate:
         self.set_block(g1_inu, blockindex, contractions)
Esempio n. 15
0
def general_susceptibility_from_charge_and_spin(chi_c, chi_s, spin_fast=True):
    """Construct a general susceptibility (spin dependent) from chi spin and charge

    Parameters:

    chi_c: Greens function, the charge susceptibility
    chi_s: Greens function, the spin susceptibility
    spin_fast: bool, True if spin is the fast index, e.g.
                        xz up, xz down, xy up, xy down, yz up, yz down,
                    or False if spin is the slow index, e.g.
                        xz up, xy up, yz up, xz down, xy down, yz down.
    """

    norb = chi_c.target_shape[-1]
    rank = chi_c.rank
    target_rank = chi_c.target_rank

    chi_general = Gf(mesh=chi_c.mesh, target_shape=target_rank * (2 * norb, ))

    chi_uu = 0.5 * (chi_c + chi_s)
    chi_ud = 0.5 * (chi_c - chi_s)
    chi_xud = chi_s

    idx_rank = rank * (slice(None), )

    if spin_fast:
        up = slice(None, None, 2)
        down = slice(1, None, 2)

    else:
        up = slice(norb)
        down = slice(norb, None)

    chi_general.data[idx_rank + (up, up, up, up)] = chi_uu.data
    chi_general.data[idx_rank + (down, down, down, down)] = chi_uu.data
    chi_general.data[idx_rank + (up, up, down, down)] = chi_ud.data
    chi_general.data[idx_rank + (down, down, up, up)] = chi_ud.data
    chi_general.data[idx_rank + (up, down, down, up)] = chi_xud.data
    chi_general.data[idx_rank + (down, up, up, down)] = chi_xud.data

    return chi_general
Esempio n. 16
0
def strip_sigma(nw, beta, sigma_in, debug=False):

    np.testing.assert_almost_equal(beta, sigma_in.mesh.beta)

    wmesh = MeshImFreq(beta, 'Fermion', n_max=nw)
    sigma = Gf(mesh=wmesh, target_shape=sigma_in.target_shape)

    for w in wmesh:
        index = w.linear_index + wmesh.first_index()  # absolute index
        sigma[w] = sigma_in[Idx(index)]

    if debug:
        from pytriqs.plot.mpl_interface import oplot, plt
        oplot(p.Sigmalatt_iw)
        oplot(sigma, 'x')
        plt.show()
        exit()

    return sigma
Esempio n. 17
0
def make_calc(U=10):

    # ------------------------------------------------------------------
    # -- Hubbard atom with two bath sites, Hamiltonian

    params = dict(
        beta=2.0,
        V1=2.0,
        V2=5.0,
        epsilon1=0.00,
        epsilon2=4.00,
        mu=2.0,
        U=U,
        ntau=40,
        niw=15,
    )

    # ------------------------------------------------------------------

    class Dummy():
        def __init__(self):
            pass

    d = Dummy()  # storage space
    d.params = params

    print '--> Solving SIAM with parameters'
    for key, value in params.items():
        print '%10s = %-10s' % (key, str(value))
        globals()[key] = value  # populate global namespace

    # ------------------------------------------------------------------

    up, do = 0, 1
    docc = c_dag(up, 0) * c(up, 0) * c_dag(do, 0) * c(do, 0)
    nA = c_dag(up, 0) * c(up, 0) + c_dag(do, 0) * c(do, 0)
    nB = c_dag(up, 1) * c(up, 1) + c_dag(do, 1) * c(do, 1)
    nC = c_dag(up, 2) * c(up, 2) + c_dag(do, 2) * c(do, 2)

    d.H = -mu * nA + epsilon1 * nB + epsilon2 * nC + U * docc + \
        V1 * (c_dag(up,0)*c(up,1) + c_dag(up,1)*c(up,0) + \
              c_dag(do,0)*c(do,1) + c_dag(do,1)*c(do,0) ) + \
        V2 * (c_dag(up,0)*c(up,2) + c_dag(up,2)*c(up,0) + \
              c_dag(do,0)*c(do,2) + c_dag(do,2)*c(do,0) )

    # ------------------------------------------------------------------
    # -- Exact diagonalization

    fundamental_operators = [
        c(up, 0), c(do, 0),
        c(up, 1), c(do, 1),
        c(up, 2), c(do, 2)
    ]

    ed = TriqsExactDiagonalization(d.H, fundamental_operators, beta)

    # ------------------------------------------------------------------
    # -- Single-particle Green's functions

    Gopt = dict(beta=beta, statistic='Fermion', indices=[1])
    d.G_tau = GfImTime(name=r'$G(\tau)$', n_points=ntau, **Gopt)
    d.G_iw = GfImFreq(name='$G(i\omega_n)$', n_points=niw, **Gopt)

    ed.set_g2_tau(d.G_tau, c(up, 0), c_dag(up, 0))
    ed.set_g2_iwn(d.G_iw, c(up, 0), c_dag(up, 0))

    # chi2pp = + < c^+_u(\tau^+) c_u(0^+) c^+_d(\tau) c_d(0) >
    #        = - < c^+_u(\tau^+) c^+_d(\tau) c_u(0^+) c_d(0) >

    chi2opt = dict(beta=beta, statistic='Fermion', indices=[1], n_points=ntau)
    d.chi2pp_tau = GfImTime(name=r'$\chi^{(2)}_{PP}(\tau)$', **chi2opt)
    ed.set_g2_tau(d.chi2pp_tau,
                  c_dag(up, 0) * c_dag(do, 0),
                  c(up, 0) * c(do, 0))
    d.chi2pp_tau *= -1.0 * -1.0  # commutation sign and gf sign
    d.chi2pp_iw = g_iw_from_tau(d.chi2pp_tau, niw)

    # chi2ph = < c^+_u(\tau^+) c_u(\tau) c^+_d(0^+) c_d(0) >

    d.chi2ph_tau = GfImTime(name=r'$\chi^{(2)}_{PH}(\tau)$', **chi2opt)
    #d.chi2ph_tau = Gf(name=r'$\chi^{(2)}_{PH}(\tau)$', **chi2opt)
    ed.set_g2_tau(d.chi2ph_tau,
                  c_dag(up, 0) * c(up, 0),
                  c_dag(do, 0) * c(do, 0))
    d.chi2ph_tau *= -1.0  # gf sign
    d.chi2ph_iw = g_iw_from_tau(d.chi2ph_tau, niw)

    # ------------------------------------------------------------------
    # -- Two particle Green's functions

    imtime = MeshImTime(beta, 'Fermion', ntau)
    prodmesh = MeshProduct(imtime, imtime, imtime)
    G2opt = dict(mesh=prodmesh, target_shape=[1, 1, 1, 1])

    d.G02_tau = Gf(name='$G^{(2)}_0(\tau_1, \tau_2, \tau_3)$', **G2opt)
    ed.set_g40_tau(d.G02_tau, d.G_tau)
    d.G02_iw = chi4_iw_from_tau(d.G02_tau, niw)

    d.G2_tau = Gf(name='$G^{(2)}(\tau_1, \tau_2, \tau_3)$', **G2opt)
    ed.set_g4_tau(d.G2_tau, c_dag(up, 0), c(up, 0), c_dag(do, 0), c(do, 0))
    #ed.set_g4_tau(d.G2_tau, c(up,0), c_dag(up,0), c(do,0), c_dag(do,0)) # <cc^+cc^+>
    d.G2_iw = chi4_iw_from_tau(d.G2_tau, niw)

    # -- trying to fix the bug in the fft for w2

    d.G02_iw.data[:] = d.G02_iw.data[:, ::-1, ...].conj()
    d.G2_iw.data[:] = d.G2_iw.data[:, ::-1, ...].conj()

    # ------------------------------------------------------------------
    # -- 3/2-particle Green's functions (equal times)

    prodmesh = MeshProduct(imtime, imtime)
    chi3opt = dict(mesh=prodmesh, target_shape=[1, 1, 1, 1])

    # chi3pp = <c^+_u(\tau) c_u(0^+) c^+_d(\tau') c_d(0) >
    #        = - <c^+_u(\tau) c^+_d(\tau') c_u(0^+) c_d(0) >

    d.chi3pp_tau = Gf(name='$\Chi^{(3)}_{PP}(\tau_1, \tau_2, \tau_3)$',
                      **chi3opt)
    ed.set_g3_tau(d.chi3pp_tau, c_dag(up, 0), c_dag(do, 0),
                  c(up, 0) * c(do, 0))
    d.chi3pp_tau *= -1.0  # from commutation
    d.chi3pp_iw = chi3_iw_from_tau(d.chi3pp_tau, niw)

    # chi3ph = <c^+_u(\tau) c_u(\tau') c^+_d(0^+) c_d(0) >

    d.chi3ph_tau = Gf(name='$\Chi^{(3)}_{PH}(\tau_1, \tau_2, \tau_3)$',
                      **chi3opt)
    ed.set_g3_tau(d.chi3ph_tau, c_dag(up, 0), c(up, 0),
                  c_dag(do, 0) * c(do, 0))
    d.chi3ph_iw = chi3_iw_from_tau(d.chi3ph_tau, niw)

    # ------------------------------------------------------------------
    # -- Store to hdf5

    filename = 'data_ed.h5'
    with HDFArchive(filename, 'w') as res:
        for key, value in d.__dict__.items():
            res[key] = value
Esempio n. 18
0
def make_calc():

    # ------------------------------------------------------------------
    # -- Read precomputed ED data

    filename = "data_pomerol.tar.gz"
    p = read_TarGZ_HDFArchive(filename)

    # ------------------------------------------------------------------
    # -- RPA tensor

    from triqs_tprf.rpa_tensor import get_rpa_tensor
    from triqs_tprf.rpa_tensor import fundamental_operators_from_gf_struct

    fundamental_operators = fundamental_operators_from_gf_struct(p.gf_struct)
    p.U_abcd = get_rpa_tensor(p.H_int, fundamental_operators)

    # ------------------------------------------------------------------
    # -- Generalized PH susceptibility

    loc_bse = ParameterCollection()

    loc_bse.chi_wnn = chi_from_gg2_PH(p.G_iw, p.G2_iw_ph)
    loc_bse.chi0_wnn = chi0_from_gg2_PH(p.G_iw, p.G2_iw_ph)

    loc_bse.gamma_wnn = inverse_PH(loc_bse.chi0_wnn) - inverse_PH(
        loc_bse.chi_wnn)
    loc_bse.chi_wnn_ref = inverse_PH(
        inverse_PH(loc_bse.chi0_wnn) - loc_bse.gamma_wnn)

    np.testing.assert_array_almost_equal(loc_bse.chi_wnn.data,
                                         loc_bse.chi_wnn_ref.data)

    loc_bse.chi0_w = trace_nn(loc_bse.chi0_wnn)
    loc_bse.chi_w = trace_nn(loc_bse.chi_wnn)

    # ------------------------------------------------------------------
    # -- RPA, using BSE inverses and constant Gamma

    loc_rpa = ParameterCollection()
    loc_rpa.U_abcd = p.U_abcd

    # -- Build constant gamma
    loc_rpa.gamma_wnn = loc_bse.gamma_wnn.copy()
    loc_rpa.gamma_wnn.data[:] = loc_rpa.U_abcd[None, None, None, ...]
    # Nb! In the three frequency form $\Gamma \propto U/\beta^2$
    loc_rpa.gamma_wnn.data[:] /= p.beta**2

    loc_rpa.chi0_wnn = loc_bse.chi0_wnn
    loc_rpa.chi0_w = loc_bse.chi0_w

    # -- Solve RPA
    loc_rpa.chi_wnn = inverse_PH(
        inverse_PH(loc_rpa.chi0_wnn) - loc_rpa.gamma_wnn)
    loc_rpa.chi_w = trace_nn(loc_rpa.chi_wnn)

    # ------------------------------------------------------------------
    # -- Bubble RPA on lattice

    lat_rpa = ParameterCollection()

    # -- Setup dummy lattice Green's function equal to local Green's function

    bz = BrillouinZone(
        BravaisLattice(units=np.eye(3), orbital_positions=[(0, 0, 0)]))
    periodization_matrix = np.diag(np.array(list([1] * 3), dtype=np.int32))
    kmesh = MeshBrillouinZone(bz, periodization_matrix)
    wmesh = MeshImFreq(beta=p.beta, S='Fermion', n_max=p.nwf_gf)

    lat_rpa.g_wk = Gf(mesh=MeshProduct(wmesh, kmesh),
                      target_shape=p.G_iw.target_shape)
    lat_rpa.g_wk[:, Idx(0, 0, 0)] = p.G_iw

    # -- chi0_wk bubble and chi_wk_rpa bubble RPA

    from triqs_tprf.lattice_utils import imtime_bubble_chi0_wk
    lat_rpa.chi0_wk = imtime_bubble_chi0_wk(lat_rpa.g_wk, nw=1)

    from triqs_tprf.lattice import solve_rpa_PH
    lat_rpa.chi_wk = solve_rpa_PH(lat_rpa.chi0_wk, p.U_abcd)

    lat_rpa.chi0_w = lat_rpa.chi0_wk[:, Idx(0, 0, 0)]
    lat_rpa.chi_w = lat_rpa.chi_wk[:, Idx(0, 0, 0)]

    print '--> cf Tr[chi0] and chi0_wk'
    print loc_rpa.chi0_w.data.reshape((4, 4)).real
    print lat_rpa.chi0_w.data.reshape((4, 4)).real

    np.testing.assert_array_almost_equal(loc_rpa.chi0_w.data,
                                         lat_rpa.chi0_w.data,
                                         decimal=2)

    print 'ok!'

    print '--> cf Tr[chi_rpa] and chi_wk_rpa'
    print loc_rpa.chi_w.data.reshape((4, 4)).real
    print lat_rpa.chi_w.data.reshape((4, 4)).real

    np.testing.assert_array_almost_equal(loc_rpa.chi_w.data,
                                         lat_rpa.chi_w.data,
                                         decimal=2)

    print 'ok!'

    # ------------------------------------------------------------------
    # -- Lattice BSE

    lat_bse = ParameterCollection()

    lat_bse.g_wk = lat_rpa.g_wk

    from triqs_tprf.lattice import fourier_wk_to_wr
    lat_bse.g_wr = fourier_wk_to_wr(lat_bse.g_wk)

    from triqs_tprf.lattice import chi0r_from_gr_PH
    lat_bse.chi0_wnr = chi0r_from_gr_PH(nw=1, nnu=p.nwf, gr=lat_bse.g_wr)

    from triqs_tprf.lattice import chi0q_from_chi0r
    lat_bse.chi0_wnk = chi0q_from_chi0r(lat_bse.chi0_wnr)

    # -- Lattice BSE calc
    from triqs_tprf.lattice import chiq_from_chi0q_and_gamma_PH
    lat_bse.chi_kwnn = chiq_from_chi0q_and_gamma_PH(lat_bse.chi0_wnk,
                                                    loc_bse.gamma_wnn)

    # -- Trace results
    from triqs_tprf.lattice import chi0q_sum_nu_tail_corr_PH
    from triqs_tprf.lattice import chi0q_sum_nu
    lat_bse.chi0_wk_tail_corr = chi0q_sum_nu_tail_corr_PH(lat_bse.chi0_wnk)
    lat_bse.chi0_wk = chi0q_sum_nu(lat_bse.chi0_wnk)

    from triqs_tprf.lattice import chiq_sum_nu, chiq_sum_nu_q
    lat_bse.chi_kw = chiq_sum_nu(lat_bse.chi_kwnn)

    lat_bse.chi0_w_tail_corr = lat_bse.chi0_wk_tail_corr[:, Idx(0, 0, 0)]
    lat_bse.chi0_w = lat_bse.chi0_wk[:, Idx(0, 0, 0)]
    lat_bse.chi_w = lat_bse.chi_kw[Idx(0, 0, 0), :]

    print '--> cf Tr[chi0_wnk] and chi0_wk'
    print lat_bse.chi0_w_tail_corr.data.reshape((4, 4)).real
    print lat_bse.chi0_w.data.reshape((4, 4)).real
    print lat_rpa.chi0_w.data.reshape((4, 4)).real

    np.testing.assert_array_almost_equal(lat_bse.chi0_w_tail_corr.data,
                                         lat_rpa.chi0_w.data)

    np.testing.assert_array_almost_equal(lat_bse.chi0_w.data,
                                         lat_rpa.chi0_w.data,
                                         decimal=2)

    print 'ok!'

    print '--> cf Tr[chi_kwnn] and chi_wk'
    print lat_bse.chi_w.data.reshape((4, 4)).real
    print loc_bse.chi_w.data.reshape((4, 4)).real

    np.testing.assert_array_almost_equal(lat_bse.chi_w.data,
                                         loc_bse.chi_w.data)

    print 'ok!'

    # ------------------------------------------------------------------
    # -- Store to hdf5

    filename = 'data_bse_rpa.h5'
    with HDFArchive(filename, 'w') as res:
        res['p'] = p
Esempio n. 19
0
def trace_nn(G2_wnn):
    bmesh = G2_wnn.mesh.components[0]
    G2_w = Gf(mesh=bmesh, target_shape=G2_wnn.target_shape)
    G2_w.data[:] = np.sum(G2_wnn.data, axis=(1, 2)) / bmesh.beta**2
    return G2_w
Esempio n. 20
0

# ----------------------------------------------------------------------
if __name__ == '__main__':

    nw = 20
    nt = 45
    beta = 2.0

    imtime = MeshImTime(beta, 'Fermion', nt)
    imfreq = MeshImFreq(beta, 'Fermion', nw)

    imtime3 = MeshProduct(imtime, imtime, imtime)
    imfreq3 = MeshProduct(imfreq, imfreq, imfreq)

    chi4_tau = Gf(name=r'$g(\tau)$', mesh=imtime3, target_shape=[1, 1, 1, 1])

    print dir(chi4_tau.indices)
    for i in chi4_tau.indices:
        print i
    exit()

    # -- Smooth anti-periodic function
    w = 0.5
    e1, e2, e3 = w, w, w
    E = np.array([e1, e2, e3])
    for idx, tau in mesh_product_iterator_numpy(chi4_tau.mesh):
        chi4_tau[idx.tolist()][:] = np.sum(np.cos(np.pi * E * tau))

    # -- Test fourier
Esempio n. 21
0
def solve_lattice_bse(g_wk, gamma_wnn, tail_corr_nwf=None):

    fmesh_g = g_wk.mesh.components[0]
    kmesh = g_wk.mesh.components[1]

    bmesh = gamma_wnn.mesh.components[0]
    fmesh = gamma_wnn.mesh.components[1]

    nk = len(kmesh)
    nw = (len(bmesh) + 1) / 2
    nwf = len(fmesh) / 2
    nwf_g = len(fmesh_g) / 2

    if mpi.is_master_node():
        print tprf_banner(), "\n"
        print 'Lattcie BSE with local vertex approximation.\n'
        print 'nk    =', nk
        print 'nw    =', nw
        print 'nwf   =', nwf
        print 'nwf_g =', nwf_g
        print 'tail_corr_nwf =', tail_corr_nwf
        print

    if tail_corr_nwf is None:
        tail_corr_nwf = nwf

    mpi.report('--> chi0_wnk_tail_corr')
    chi0_wnk_tail_corr = get_chi0_wnk(g_wk, nw=nw, nwf=tail_corr_nwf)

    mpi.report('--> trace chi0_wnk_tail_corr (WARNING! NO TAIL FIT. FIXME!)')
    chi0_wk_tail_corr = chi0q_sum_nu_tail_corr_PH(chi0_wnk_tail_corr)
    #chi0_wk_tail_corr = chi0q_sum_nu(chi0_wnk_tail_corr)

    mpi.barrier()
    mpi.report('B1 ' +
               str(chi0_wk_tail_corr[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0]))
    mpi.barrier()

    mpi.report('--> chi0_wnk_tail_corr to chi0_wnk')
    if tail_corr_nwf != nwf:
        mpi.report('--> fixed_fermionic_window_python_wnk')
        chi0_wnk = fixed_fermionic_window_python_wnk(chi0_wnk_tail_corr,
                                                     nwf=nwf)
    else:
        chi0_wnk = chi0_wnk_tail_corr.copy()

    del chi0_wnk_tail_corr

    mpi.barrier()
    mpi.report('C ' + str(chi0_wnk[Idx(0), Idx(0), Idx(0, 0, 0)][0, 0, 0, 0]))
    mpi.barrier()

    mpi.report('--> trace chi0_wnk')
    chi0_wk = chi0q_sum_nu(chi0_wnk)

    mpi.barrier()
    mpi.report('D ' + str(chi0_wk[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0]))
    mpi.barrier()

    dchi_wk = chi0_wk_tail_corr - chi0_wk

    chi0_kw = Gf(mesh=MeshProduct(kmesh, bmesh),
                 target_shape=chi0_wk_tail_corr.target_shape)
    chi0_kw.data[:] = chi0_wk_tail_corr.data.swapaxes(0, 1)

    del chi0_wk
    del chi0_wk_tail_corr

    assert (chi0_wnk.mesh.components[0] == bmesh)
    assert (chi0_wnk.mesh.components[1] == fmesh)
    assert (chi0_wnk.mesh.components[2] == kmesh)

    # -- Lattice BSE calc with built in trace
    mpi.report('--> chi_kw from BSE')
    #mpi.report('DEBUG BSE INACTIVE'*72)
    chi_kw = chiq_sum_nu_from_chi0q_and_gamma_PH(chi0_wnk, gamma_wnn)
    #chi_kw = chi0_kw.copy()

    mpi.barrier()
    mpi.report('--> chi_kw from BSE (done)')

    del chi0_wnk

    mpi.report('--> chi_kw tail corrected (using chi0_wnk)')
    for k in kmesh:
        chi_kw[
            k, :] += dchi_wk[:,
                             k]  # -- account for high freq of chi_0 (better than nothing)

    del dchi_wk

    mpi.report('--> solve_lattice_bse, done.')

    return chi_kw, chi0_kw
Esempio n. 22
0
                     beta=beta,
                     statistic='Fermion',
                     n_points=10,
                     indices=[1])

    ed.set_g2_tau(g_tau, c(up, 0), c_dag(up, 0))
    ed.set_g2_iwn(g_iwn, c(up, 0), c_dag(up, 0))

    # ------------------------------------------------------------------
    # -- Two particle Green's functions

    ntau = 20
    imtime = MeshImTime(beta, 'Fermion', ntau)
    prodmesh = MeshProduct(imtime, imtime, imtime)

    g40_tau = Gf(name='g40_tau', mesh=prodmesh, target_shape=[1, 1, 1, 1])
    g4_tau = Gf(name='g4_tau', mesh=prodmesh, target_shape=[1, 1, 1, 1])

    ed.set_g40_tau(g40_tau, g_tau)
    ed.set_g4_tau(g4_tau, c(up, 0), c_dag(up, 0), c(up, 0), c_dag(up, 0))

    # ------------------------------------------------------------------
    # -- Two particle Green's functions (equal times)

    prodmesh = MeshProduct(imtime, imtime)
    g3pp_tau = Gf(name='g4_tau', mesh=prodmesh, target_shape=[1, 1, 1, 1])
    ed.set_g3_tau(g3pp_tau, c(up, 0), c_dag(up, 0), c(up, 0) * c_dag(up, 0))

    # ------------------------------------------------------------------
    # -- Store to hdf5
Esempio n. 23
0
    beta = 10.0
    U = 2.0
    mu = 1.0
    h = 0.1
    #V = 0.5
    V = 1.0
    epsilon = 2.3

    H = U * n('up', 0) * n('do', 0) + \
        - mu * (n('up', 0) + n('do', 0)) + \
        h * n('up', 0) - h * n('do', 0) + \
        epsilon * (n('up', 1) + n('do', 1)) - epsilon * (n('up', 2) + n('do', 2)) + \
        V * ( c_dag('up', 0) * c('up', 1) + c_dag('up', 1) * c('up', 0) ) + \
        V * ( c_dag('do', 0) * c('do', 1) + c_dag('do', 1) * c('do', 0) ) + \
        V * ( c_dag('up', 0) * c('up', 2) + c_dag('up', 2) * c('up', 0) ) + \
        V * ( c_dag('do', 0) * c('do', 2) + c_dag('do', 2) * c('do', 0) )

    ed = TriqsExactDiagonalization(H, fundamental_operators, beta)

    n_tau = 101
    G_tau_up = Gf(mesh=MeshImTime(beta, 'Fermion', n_tau), target_shape=[])
    G_tau_do = Gf(mesh=MeshImTime(beta, 'Fermion', n_tau), target_shape=[])

    ed.set_g2_tau(G_tau_up, c('up', 0), c_dag('up', 0))
    ed.set_g2_tau(G_tau_do, c('do', 0), c_dag('do', 0))

    with HDFArchive('anderson.pyed.h5', 'w') as Results:
        Results['up'] = G_tau_up
        Results['dn'] = G_tau_do
beta = 10.0

gf_struct = [['0', [0, 1]]]
target_shape = [2, 2]

nw = 48
nt = 3 * nw

S = SolverCore(beta=beta, gf_struct=gf_struct, n_iw=nw, n_tau=nt)

h_int = n('0', 0) * n('0', 1)

wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw)
tmesh = MeshImTime(beta=beta, S='Fermion', n_max=nt)

Delta_iw = Gf(mesh=wmesh, target_shape=target_shape)

Ek = np.array([
    [1.00,  0.75],
    [0.75, -1.20],
    ])

E_loc = np.array([
    [0.2, 0.3],
    [0.3, 0.4],
    ])

V = np.array([
    [1.0, 0.25],
    [0.25, -1.0],
    ])
Esempio n. 25
0
# ================== TPRF calculations ========================================

# -- Create dispersion relation Green's function object

norbs = e_k_ref.shape[-1]

units = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
orbital_positions = [(0, 0, 0)]
bl = BravaisLattice(units, orbital_positions)
bz = BrillouinZone(bl)
periodization_matrix = nk * np.eye(3, dtype=np.int32)
periodization_matrix[2, 2] = 1
kmesh = MeshBrillouinZone(bz, periodization_matrix)

e_k = Gf(mesh=kmesh, target_shape=[norbs, norbs])

e_k.data[:] = e_k_ref.reshape(nk**2, norbs, norbs)

# --  Calculate bare Green's function

wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=n_max)
g0_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh)

# -- Calculate bare bubble

chi00_wk = imtime_bubble_chi0_wk(g0_wk, nw=n_max)

# -- Calculate chi spin and charge

U_c, U_s = kanamori_charge_and_spin_quartic_interaction_tensors(
Esempio n. 26
0
File: bse.py Progetto: mzingl/tprf
def solve_lattice_bse(g_wk, gamma_wnn, tail_corr_nwf=None):
    r""" Compute the generalized lattice susceptibility 
    :math:`\chi_{abcd}(\omega, \mathbf{k})` using the Bethe-Salpeter 
    equation (BSE).

    Parameters
    ----------

    g_wk : Single-particle Green's function :math:`G_{ab}(\omega, \mathbf{k})`.
    gamma_wnn : Local particle-hole vertex function 
                :math:`\Gamma_{abcd}(\omega, \nu, \nu')`
    tail_corr_nwf : Number of fermionic freqiencies to use in the 
                    tail correction of the sum over fermionic frequencies.

    Returns
    -------

    chi0_wk : Generalized lattice susceptibility
              :math:`\chi_{abcd}(\omega, \mathbf{k})`
    """

    fmesh_g = g_wk.mesh.components[0]
    kmesh = g_wk.mesh.components[1]

    bmesh = gamma_wnn.mesh.components[0]
    fmesh = gamma_wnn.mesh.components[1]

    nk = len(kmesh)
    nw = (len(bmesh) + 1) / 2
    nwf = len(fmesh) / 2
    nwf_g = len(fmesh_g) / 2

    if mpi.is_master_node():
        print tprf_banner(), "\n"
        print 'Lattcie BSE with local vertex approximation.\n'
        print 'nk    =', nk
        print 'nw    =', nw
        print 'nwf   =', nwf
        print 'nwf_g =', nwf_g
        print 'tail_corr_nwf =', tail_corr_nwf
        print

    if tail_corr_nwf is None:
        tail_corr_nwf = nwf

    mpi.report('--> chi0_wnk_tail_corr')
    chi0_wnk_tail_corr = get_chi0_wnk(g_wk, nw=nw, nwf=tail_corr_nwf)

    mpi.report('--> trace chi0_wnk_tail_corr (WARNING! NO TAIL FIT. FIXME!)')
    chi0_wk_tail_corr = chi0q_sum_nu_tail_corr_PH(chi0_wnk_tail_corr)
    #chi0_wk_tail_corr = chi0q_sum_nu(chi0_wnk_tail_corr)

    mpi.barrier()
    mpi.report('B1 ' +
               str(chi0_wk_tail_corr[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0]))
    mpi.barrier()

    mpi.report('--> chi0_wnk_tail_corr to chi0_wnk')
    if tail_corr_nwf != nwf:
        mpi.report('--> fixed_fermionic_window_python_wnk')
        chi0_wnk = fixed_fermionic_window_python_wnk(chi0_wnk_tail_corr,
                                                     nwf=nwf)
    else:
        chi0_wnk = chi0_wnk_tail_corr.copy()

    del chi0_wnk_tail_corr

    mpi.barrier()
    mpi.report('C ' + str(chi0_wnk[Idx(0), Idx(0), Idx(0, 0, 0)][0, 0, 0, 0]))
    mpi.barrier()

    mpi.report('--> trace chi0_wnk')
    chi0_wk = chi0q_sum_nu(chi0_wnk)

    mpi.barrier()
    mpi.report('D ' + str(chi0_wk[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0]))
    mpi.barrier()

    dchi_wk = chi0_wk_tail_corr - chi0_wk

    chi0_kw = Gf(mesh=MeshProduct(kmesh, bmesh),
                 target_shape=chi0_wk_tail_corr.target_shape)
    chi0_kw.data[:] = chi0_wk_tail_corr.data.swapaxes(0, 1)

    del chi0_wk
    del chi0_wk_tail_corr

    assert (chi0_wnk.mesh.components[0] == bmesh)
    assert (chi0_wnk.mesh.components[1] == fmesh)
    assert (chi0_wnk.mesh.components[2] == kmesh)

    # -- Lattice BSE calc with built in trace
    mpi.report('--> chi_kw from BSE')
    #mpi.report('DEBUG BSE INACTIVE'*72)
    chi_kw = chiq_sum_nu_from_chi0q_and_gamma_PH(chi0_wnk, gamma_wnn)
    #chi_kw = chi0_kw.copy()

    mpi.barrier()
    mpi.report('--> chi_kw from BSE (done)')

    del chi0_wnk

    mpi.report('--> chi_kw tail corrected (using chi0_wnk)')
    for k in kmesh:
        chi_kw[
            k, :] += dchi_wk[:,
                             k]  # -- account for high freq of chi_0 (better than nothing)

    del dchi_wk

    mpi.report('--> solve_lattice_bse, done.')

    return chi_kw, chi0_kw
Esempio n. 27
0
noise growing quadratically with the frequency.

Author: Hugo U.R. Strand """

import itertools
import numpy as np

from pytriqs.archive import HDFArchive
from pytriqs.gf import Gf, MeshImFreq, MeshImTime, iOmega_n, inverse, Fourier

nw = 512
beta = 50.0
target_shape = [2, 2]

wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw)
Delta_iw = Gf(mesh=wmesh, target_shape=target_shape)

Ek = np.array([
    [1.00,  0.5],
    [0.5, -1.20],
    ])

E_loc = np.array([
    [0.33,  0.5],
    [0.5, -0.1337],
    ])

V = np.array([
    [1.0, 0.25],
    [0.25, -1.0],
    ])
Esempio n. 28
0
    # Quantum numbers (N_up and N_down)
    QN = []
    for b, idxs in gf_struct: QN.append(n(b,0))
    p["partition_method"] = "quantum_numbers"
    p["quantum_numbers"] = QN
    
    mpi.report("Constructing the solver...")

    # Construct the solver
    S = SolverCore(beta=beta, gf_struct=gf_struct, n_tau=n_tau, n_iw=n_iw)

    mpi.report("Preparing the hybridization function...")

    # Set hybridization function
    #for m, b in enumerate(sorted(gf_struct.keys())):
    for m, (b, idxs) in enumerate(gf_struct):
        delta_w = Gf(mesh=S.G0_iw.mesh, target_shape=[])
        delta_w << (V[m]**2) * inverse(iOmega_n - e[m])
        S.G0_iw[b][0,0] << inverse(iOmega_n - e[m] - delta_w)

    mpi.report("Running the simulation...")

    # Solve the problem
    S.solve(h_int=H, **p)

    # Save results
    if mpi.is_master_node():
        with HDFArchive('nonint.h5','a') as Results:
            Results[str(modes)] = {'G_tau':S.G_tau,'V':V,'e':e}
Esempio n. 29
0
def five_plus_five(use_interaction=True):

    results_file_name = "5_plus_5." + ("int."
                                       if use_interaction else "") + "h5"

    # Block structure of GF
    L = 2  # d-orbital
    spin_names = ("up", "dn")
    orb_names = cubic_names(L)

    # Input parameters
    beta = 40.
    mu = 26

    U = 4.0
    J = 0.7
    F0 = U
    F2 = J * (14.0 / (1.0 + 0.63))
    F4 = F2 * 0.63

    # Dump the local Hamiltonian to a text file (set to None to disable dumping)
    H_dump = "H.txt"
    # Dump Delta parameters to a text file (set to None to disable dumping)
    Delta_dump = "Delta_params.txt"

    # Hybridization function parameters
    # Delta(\tau) is diagonal in the basis of cubic harmonics
    # Each component of Delta(\tau) is represented as a list of single-particle
    # terms parametrized by pairs (V_k,\epsilon_k).
    delta_params = {
        "xy": {
            'V': 0.2,
            'e': -0.2
        },
        "yz": {
            'V': 0.2,
            'e': -0.15
        },
        "z^2": {
            'V': 0.2,
            'e': -0.1
        },
        "xz": {
            'V': 0.2,
            'e': 0.05
        },
        "x^2-y^2": {
            'V': 0.2,
            'e': 0.4
        }
    }

    atomic_levels = {
        ('up_xy', 0): -0.2,
        ('dn_xy', 0): -0.2,
        ('up_yz', 0): -0.15,
        ('dn_yz', 0): -0.15,
        ('up_z^2', 0): -0.1,
        ('dn_z^2', 0): -0.1,
        ('up_xz', 0): 0.05,
        ('dn_xz', 0): 0.05,
        ('up_x^2-y^2', 0): 0.4,
        ('dn_x^2-y^2', 0): 0.4
    }

    n_iw = 1025
    n_tau = 10001

    p = {}
    p["max_time"] = -1
    p["random_name"] = ""
    p["random_seed"] = 123 * mpi.rank + 567
    p["length_cycle"] = 50
    #p["n_warmup_cycles"] = 5000
    p["n_warmup_cycles"] = 500
    p["n_cycles"] = int(1.e1 / mpi.size)
    #p["n_cycles"] = int(5.e5 / mpi.size)
    #p["n_cycles"] = int(5.e6 / mpi.size)
    p["partition_method"] = "autopartition"
    p["measure_G_tau"] = True
    p["move_shift"] = True
    p["move_double"] = True
    p["measure_pert_order"] = False
    p["performance_analysis"] = False
    p["use_trace_estimator"] = False

    mpi.report("Welcome to 5+5 (5 orbitals + 5 bath sites) test.")

    gf_struct = set_operator_structure(spin_names, orb_names, False)
    mkind = get_mkind(False, None)

    H = Operator()

    if use_interaction:
        # Local Hamiltonian
        U_mat = U_matrix(L, [F0, F2, F4], basis='cubic')
        H += h_int_slater(spin_names, orb_names, U_mat, False, H_dump=H_dump)
    else:
        mu = 0.

    p["h_int"] = H

    # Quantum numbers (N_up and N_down)
    QN = [Operator(), Operator()]
    for cn in orb_names:
        for i, sn in enumerate(spin_names):
            QN[i] += n(*mkind(sn, cn))
    if p["partition_method"] == "quantum_numbers": p["quantum_numbers"] = QN

    mpi.report("Constructing the solver...")

    # Construct the solver
    S = SolverCore(beta=beta, gf_struct=gf_struct, n_tau=n_tau, n_iw=n_iw)

    mpi.report("Preparing the hybridization function...")

    H_hyb = Operator()

    # Set hybridization function
    if Delta_dump: Delta_dump_file = open(Delta_dump, 'w')
    for sn, cn in product(spin_names, orb_names):
        bn, i = mkind(sn, cn)
        V = delta_params[cn]['V']
        e = delta_params[cn]['e']

        delta_w = Gf(mesh=MeshImFreq(beta, 'Fermion', n_iw), target_shape=[])
        delta_w << (V**2) * inverse(iOmega_n - e)

        S.G0_iw[bn][i, i] << inverse(iOmega_n + mu - atomic_levels[(bn, i)] -
                                     delta_w)

        cnb = cn + '_b'  # bath level
        a = sn + '_' + cn
        b = sn + '_' + cn + '_b'

        H_hyb += ( atomic_levels[(bn,i)] - mu ) * n(a, 0) + \
            n(b,0) * e + V * ( c(a,0) * c_dag(b,0) + c(b,0) * c_dag(a,0) )

        # Dump Delta parameters
        if Delta_dump:
            Delta_dump_file.write(bn + '\t')
            Delta_dump_file.write(str(V) + '\t')
            Delta_dump_file.write(str(e) + '\n')

    if mpi.is_master_node():
        filename_ham = 'data_Ham%s.h5' % ('_int' if use_interaction else '')
        with HDFArchive(filename_ham, 'w') as arch:
            arch['H'] = H_hyb + H
            arch['gf_struct'] = gf_struct
            arch['beta'] = beta

    mpi.report("Running the simulation...")

    # Solve the problem
    S.solve(**p)

    # Save the results
    if mpi.is_master_node():
        Results = HDFArchive(results_file_name, 'w')
        Results['G_tau'] = S.G_tau
        Results['G0_iw'] = S.G0_iw
        Results['use_interaction'] = use_interaction
        Results['delta_params'] = delta_params
        Results['spin_names'] = spin_names
        Results['orb_names'] = orb_names

        import __main__
        Results.create_group("log")
        log = Results["log"]
        log["version"] = version.version
        log["triqs_hash"] = version.triqs_hash
        log["cthyb_hash"] = version.cthyb_hash
        log["script"] = inspect.getsource(__main__)
Esempio n. 30
0
for tau in g_tau.mesh:
    g_tau[tau] = np.exp(-beta * tau)

for idx, tau in enumerate(g_tau.mesh):

    # comparison does not work at beta since the evaluation g_tau() wraps..
    if idx == len(g_tau.mesh) - 1: break

    #diff_interp = g_tau(tau)[0,0] - g_ref[idx] # FIXME: tau is complex

    diff_interp = g_tau(tau.real)[0, 0] - g_ref[idx]
    diff_dbrack = g_tau[tau][0, 0] - g_ref[idx]

    np.testing.assert_almost_equal(diff_interp, 0.0)
    np.testing.assert_almost_equal(diff_dbrack, 0.0)

# -- three imaginary time gf

imtime = MeshImTime(beta=beta, S='Fermion', n_max=ntau)
g4_tau = Gf(name='g4_tau',
            mesh=MeshProduct(imtime, imtime, imtime),
            indices=[1])

for t1, t2, t3 in g4_tau.mesh:
    g4_tau[t1, t2, t3] = g_tau(t1) * g_tau(t3) - g_tau(t1) * g_tau(t3)

for t1, t2, t3 in g4_tau.mesh:
    val = g4_tau[t1, t2, t3]
    val_ref = g_tau(t1) * g_tau(t3) - g_tau(t1) * g_tau(t3)
    np.testing.assert_array_almost_equal(val, val_ref)