def make_calc(beta=2.0, h_field=0.0): # ------------------------------------------------------------------ # -- Hubbard atom with two bath sites, Hamiltonian p = ParameterCollection( beta = beta, h_field = h_field, U = 5.0, ntau = 40, niw = 15, ) p.mu = 0.5*p.U # ------------------------------------------------------------------ print('--> Solving SIAM with parameters') print(p) # ------------------------------------------------------------------ up, do = 'up', 'dn' docc = c_dag(up,0) * c(up,0) * c_dag(do,0) * c(do,0) mA = 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) p.H = -p.mu * nA + p.U * docc + p.h_field * mA # ------------------------------------------------------------------ fundamental_operators = [c(up,0), c(do,0)] ed = TriqsExactDiagonalization(p.H, fundamental_operators, p.beta) g_tau = GfImTime(beta=beta, statistic='Fermion', n_points=40, indices=[0]) g_iw = GfImFreq(beta=beta, statistic='Fermion', n_points=10, indices=[0]) p.G_tau = BlockGf(name_list=[up,do], block_list=[g_tau]*2, make_copies=True) p.G_iw = BlockGf(name_list=[up,do], block_list=[g_iw]*2, make_copies=True) ed.set_g2_tau(p.G_tau[up], c(up,0), c_dag(up,0)) ed.set_g2_tau(p.G_tau[do], c(do,0), c_dag(do,0)) ed.set_g2_iwn(p.G_iw[up], c(up,0), c_dag(up,0)) ed.set_g2_iwn(p.G_iw[do], c(do,0), c_dag(do,0)) p.magnetization = ed.get_expectation_value(0.5 * mA) p.magnetization2 = ed.get_expectation_value(0.25 * mA * mA) # ------------------------------------------------------------------ # -- Store to hdf5 filename = 'data_pyed_h_field_%4.4f.h5' % h_field with HDFArchive(filename,'w') as res: res['p'] = p
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(H, fundamental_operators, beta) # ------------------------------------------------------------------ # -- Single-particle Green's functions g_tau = GfImTime(name=r'$g$', beta=beta, statistic='Fermion', n_points=50, target_shape=(1,1)) g_iwn = GfImFreq(name='$g$', beta=beta, statistic='Fermion', n_points=10, target_shape=(1,1)) ed.set_g2_tau(g_tau[0,0], c(up,0), c_dag(up,0)) ed.set_g2_iwn(g_iwn[0,0], c(up,0), c_dag(up,0)) # ------------------------------------------------------------------ # -- Two particle Green's functions ntau = 20 imtime = MeshImTime(beta, 'Fermion', ntau) prodmesh = MeshProduct(imtime, imtime, imtime)
2. Linear interpolation for higher order tau greens function g4_tau(t1, t2, t3) """ import itertools import numpy as np from triqs.gf import Gf, GfImTime, MeshImTime, MeshProduct ntau = 10 beta = 1.2345 g_tau = GfImTime(name='g_tau', beta=beta, statistic='Fermion', n_points=ntau, indices=[1]) tau = np.array([tau.value for tau in g_tau.mesh]) g_ref = np.exp(-beta * tau) g_tau.data[:, 0, 0] = np.exp(-beta * tau) 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
def test_two_particle_greens_function(): # ------------------------------------------------------------------ # -- Hubbard atom with two bath sites, Hamiltonian beta = 2.0 V1 = 2.0 V2 = 5.0 epsilon1 = 0.00 epsilon2 = 4.00 mu = 2.0 U = 0.0 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) 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(H, fundamental_operators, beta) # ------------------------------------------------------------------ # -- single particle Green's functions g_tau = GfImTime(name=r'$g$', beta=beta, statistic='Fermion', n_points=100, target_shape=(1, 1)) ed.set_g2_tau(g_tau[0, 0], c(up, 0), c_dag(up, 0)) # ------------------------------------------------------------------ # -- Two particle Green's functions ntau = 10 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_matrix(g40_tau, g_tau) ed.set_g4_tau(g4_tau[0, 0, 0, 0], c(up, 0), c_dag(up, 0), c(up, 0), c_dag(up, 0)) # ------------------------------------------------------------------ # -- compare zero_outer_planes_and_equal_times(g4_tau) zero_outer_planes_and_equal_times(g40_tau) np.testing.assert_array_almost_equal(g4_tau.data, g40_tau.data)
def test_cf_G_tau_and_G_iw_nonint(verbose=False): beta = 3.22 eps = 1.234 niw = 64 ntau = 2 * niw + 1 H = eps * c_dag(0, 0) * c(0, 0) fundamental_operators = [c(0, 0)] ed = TriqsExactDiagonalization(H, fundamental_operators, beta) # ------------------------------------------------------------------ # -- Single-particle Green's functions G_tau = GfImTime(beta=beta, statistic='Fermion', n_points=ntau, target_shape=(1, 1)) G_iw = GfImFreq(beta=beta, statistic='Fermion', n_points=niw, target_shape=(1, 1)) G_iw << inverse(iOmega_n - eps) G_tau << Fourier(G_iw) G_tau_ed = GfImTime(beta=beta, statistic='Fermion', n_points=ntau, target_shape=(1, 1)) G_iw_ed = GfImFreq(beta=beta, statistic='Fermion', n_points=niw, target_shape=(1, 1)) ed.set_g2_tau(G_tau_ed[0, 0], c(0, 0), c_dag(0, 0)) ed.set_g2_iwn(G_iw_ed[0, 0], c(0, 0), c_dag(0, 0)) # ------------------------------------------------------------------ # -- Compare gfs from triqs.utility.comparison_tests import assert_gfs_are_close assert_gfs_are_close(G_tau, G_tau_ed) assert_gfs_are_close(G_iw, G_iw_ed) # ------------------------------------------------------------------ # -- Plotting if verbose: from triqs.plot.mpl_interface import oplot, plt subp = [3, 1, 1] plt.subplot(*subp) subp[-1] += 1 oplot(G_tau.real) oplot(G_tau_ed.real) plt.subplot(*subp) subp[-1] += 1 diff = G_tau - G_tau_ed oplot(diff.real) oplot(diff.imag) plt.subplot(*subp) subp[-1] += 1 oplot(G_iw) oplot(G_iw_ed) plt.show()
# -- Exact diagonalization fundamental_operators = [ c(up, 0), c(do, 0), c(up, 1), c(do, 1), c(up, 2), c(do, 2) ] ed = TriqsExactDiagonalization(H, fundamental_operators, beta) # ------------------------------------------------------------------ # -- Single-particle Green's functions g_tau = GfImTime(name=r'$g$', beta=beta, statistic='Fermion', n_points=500, indices=['A', 'B']) for (i1, s1), (i2, s2) in itertools.product([('A', up), ('B', do)], repeat=2): print(i1, s1, i2, s2) ed.set_g2_tau(g_tau[i1, i2], c(s1, 0), c_dag(s2, 0)) # ------------------------------------------------------------------ # -- Store to hdf5 with HDFArchive('data_ed.h5', 'w') as res: res['tot'] = g_tau # ----------------------------------------------------------------------