Esempio n. 1
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]
S.G0_iw << G0_iw

S.solve(
    h_int = h_int,
    length_cycle = 10,
    n_warmup_cycles = 1,
    n_cycles = 1,
    )

h_loc_ref = S.h_loc - h_int

print 'h_loc =\n', h_loc
print 'h_loc_ref =\n', h_loc_ref

Delta_tau_ref = S.Delta_tau['0']
Delta_iw_ref = Delta_iw.copy()
Delta_tail_ref, Delta_tail_err_ref = Delta_iw_ref.fit_hermitian_tail()
Delta_iw_ref << Fourier(Delta_tau_ref, Delta_tail_ref)

diff = h_loc - h_loc_ref
print 'h_loc diff =', diff
for ops, prefactor in diff:
    print prefactor, ops
    assert( np.abs(prefactor) < 1e-10 )
#assert( diff == Operator() )

diff = np.max(np.abs(Delta_tau.data - Delta_tau_ref.data))
print 'Delta_tau diff =', diff
np.testing.assert_array_almost_equal(Delta_tau.data, Delta_tau_ref.data)
assert( diff < 1e-8 )
Esempio n. 3
0
    ])

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

V = np.array([
    [1.0, 0.25],
    [0.25, -1.0],
    ])

Delta_iw << inverse( iOmega_n - Ek ) + inverse( iOmega_n + Ek ) - E_loc
Delta_iw.from_L_G_R(V, Delta_iw, V)

Delta_iw_ref = Delta_iw.copy()

noise_ampl = 1e-3

def get_noise():
    return 2.*np.random.random() - 1.

for w in wmesh:
    re = Delta_iw[w].real + noise_ampl * get_noise() * np.abs(w.value)**2
    im = Delta_iw[w].imag + noise_ampl * get_noise() * np.abs(w.value)**2
    
    Delta_iw[w] = re + 1.j * im

order_max = 3
n_min = 20
n_max = 100