|
| 1 | +# Two impurity sites coupled to two bath sites. |
| 2 | +# Data in dimer.ref.h5 is obtained by running this script on 800 cores. |
| 3 | + |
| 4 | +from triqs.gf import * |
| 5 | +from triqs.gf.tools import * |
| 6 | +from triqs.gf.gf_factories import make_gf_from_fourier |
| 7 | +from triqs.operators.util import U_matrix_kanamori, h_int_density |
| 8 | +import h5 |
| 9 | +import triqs.utility.mpi as mpi |
| 10 | +from triqs.utility.h5diff import h5diff |
| 11 | +from triqs.operators import n |
| 12 | + |
| 13 | +from triqs_ctseg import Solver |
| 14 | + |
| 15 | +import numpy as np |
| 16 | +from numpy import linalg |
| 17 | + |
| 18 | +# Numerical values |
| 19 | +beta = 10. # Inverse temperature |
| 20 | +mu = 0.0 # Chemical potential |
| 21 | +eps = np.array([0.0, 0.1]) # Impurity site energies |
| 22 | +eps_bath = np.array([0.27, -0.4]) # Bath site energies |
| 23 | +U = 1. # Density-density interaction |
| 24 | +J = 0.2 # Hund's coupling |
| 25 | +V = 1 # Bath-impurity coupling |
| 26 | +block_names = ['up', 'dn'] |
| 27 | +n_orb = len(eps) |
| 28 | +n_orb_bath = len(eps_bath) |
| 29 | +n_tau = 10001 |
| 30 | +gf_struct = [(s, n_orb) for s in block_names] # Green's function structure |
| 31 | + |
| 32 | +######################################################################## |
| 33 | +# --------------- Construct Delta(tau) and h_loc0 --------------- |
| 34 | + |
| 35 | +# Non-interacting impurity Hamiltonian in matrix representation |
| 36 | +h_0_mat = np.diag(eps - mu) |
| 37 | + |
| 38 | +# Bath Hamiltonian in matrix representation |
| 39 | +h_bath_mat = np.diag(eps_bath) |
| 40 | + |
| 41 | +# Coupling matrix |
| 42 | +V_mat = np.matrix([[V, V], |
| 43 | + [V, V]]) |
| 44 | + |
| 45 | +# Total non-interacting Hamiltonian |
| 46 | +h_tot_mat = np.block([[h_0_mat, V_mat], |
| 47 | + [V_mat.H, h_bath_mat]]) |
| 48 | + |
| 49 | +# Non-interacting impurity Green's function |
| 50 | +n_iw = int(10 * beta) |
| 51 | +iw_mesh = MeshImFreq(beta, 'Fermion', n_iw) |
| 52 | +G0_iw = BlockGf(mesh=iw_mesh, gf_struct=gf_struct) |
| 53 | +for bl, iw in product(block_names, iw_mesh): |
| 54 | + G0_iw[bl][iw] = linalg.inv(iw.value * np.eye(2*n_orb) - h_tot_mat)[:n_orb, :n_orb] |
| 55 | + |
| 56 | +# Get Delta(iw) and h_loc0 from G0(iw) |
| 57 | +def get_h0_Delta(G0_iw): |
| 58 | + h0_lst, Delta_iw = [], G0_iw.copy() |
| 59 | + for bl in G0_iw.indices: |
| 60 | + Delta_iw[bl] << iOmega_n - inverse(G0_iw[bl]) |
| 61 | + tail, err = fit_hermitian_tail(Delta_iw[bl]) |
| 62 | + Delta_iw[bl] << Delta_iw[bl] - tail[0] |
| 63 | + h0_lst.append(tail[0].real) |
| 64 | + return h0_lst, Delta_iw |
| 65 | + |
| 66 | +h0_lst, Delta_iw = get_h0_Delta(G0_iw) |
| 67 | +h_loc0 = sum(h0_lst[i][0,0] * n(bl, 0) + h0_lst[i][1,1] * n(bl, 1) for i, bl in enumerate(block_names)) |
| 68 | + |
| 69 | +# Fourier-transform to get Delta(tau) |
| 70 | +tau_mesh = MeshImTime(beta, 'Fermion', n_tau) |
| 71 | +Delta_tau = BlockGf(mesh = tau_mesh, gf_struct = gf_struct) |
| 72 | +for name, g0 in Delta_iw: |
| 73 | + known_moments = make_zero_tail(Delta_iw[name], 1) |
| 74 | + tail, err = fit_hermitian_tail(Delta_iw[name], known_moments) |
| 75 | + Delta_tau[name] << make_gf_from_fourier(Delta_iw[name], tau_mesh, tail).real |
| 76 | +########################################################### |
| 77 | + |
| 78 | +# --------- Construct the CTSEG solver ---------- |
| 79 | +constr_params = { |
| 80 | + 'beta': beta, |
| 81 | + 'gf_struct': gf_struct, |
| 82 | + 'n_tau': n_tau, |
| 83 | +} |
| 84 | +S = Solver(**constr_params) |
| 85 | + |
| 86 | +# Input Delta(tau) |
| 87 | +S.Delta_tau << Delta_tau |
| 88 | + |
| 89 | +# Impurity interaction Hamiltonian |
| 90 | +Umat, Upmat = U_matrix_kanamori(n_orb, U_int=U, J_hund=J) |
| 91 | +h_int = h_int_density(block_names, n_orb, Umat, Upmat, off_diag=True) |
| 92 | + |
| 93 | +# --------- Solve parameters ---------- |
| 94 | +solve_params = { |
| 95 | + 'h_int': h_int, |
| 96 | + 'h_loc0': h_loc0, |
| 97 | + 'n_warmup_cycles': 5000, |
| 98 | + 'n_cycles': 200000000, |
| 99 | + 'length_cycle': 100, |
| 100 | +} |
| 101 | + |
| 102 | +# ---------- Solve ---------- |
| 103 | +S.solve(**solve_params) |
| 104 | + |
| 105 | +# --------- Save output --------- |
| 106 | +if mpi.is_master_node(): |
| 107 | + with h5.HDFArchive("dimer.out.h5", 'w') as A: |
| 108 | + A['G_tau'] = S.results.G_tau |
| 109 | + |
0 commit comments