def solve_lattice_bse_e_k_sigma_w(mu, e_k, sigma_w, gamma_wnn, tail_corr_nwf=-1): kmesh = e_k.mesh fmesh_huge = sigma_w.mesh 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_sigma = len(fmesh_huge) / 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_sigma =', nwf_sigma print 'nwf_chi0_tail =', tail_corr_nwf print # -- Lattice BSE calc with built in trace using g_wk from triqs_tprf.lattice import chiq_sum_nu_from_e_k_sigma_w_and_gamma_PH chi_kw = chiq_sum_nu_from_e_k_sigma_w_and_gamma_PH( mu, e_k, sigma_w, gamma_wnn, tail_corr_nwf=tail_corr_nwf) return chi_kw
def bubble_setup(beta, mu, tb_lattice, nk, nw, sigma_w=None): print tprf_banner(), "\n" print 'beta =', beta print 'mu =', mu print 'sigma =', (not (sigma == None)) norb = tb_lattice.NOrbitalsInUnitCell print 'nk =', nk print 'nw =', nw print 'norb =', norb print ntau = 4 * nw ntot = np.prod(nk) * norb**4 + np.prod(nk) * (nw + ntau) * norb**2 nbytes = ntot * np.complex128().nbytes ngb = nbytes / 1024.**3 print 'Approx. Memory Utilization: %2.2f GB\n' % ngb periodization_matrix = np.diag(np.array(list(nk), dtype=np.int32)) #print 'periodization_matrix =\n', periodization_matrix bz = BrillouinZone(tb_lattice.bl) bzmesh = MeshBrillouinZone(bz, periodization_matrix) print '--> ek' e_k = ek_tb_dispersion_on_bzmesh(tb_lattice, bzmesh, bz) if sigma is None: print '--> g0k' wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw) g_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh) else: print '--> gk' sigma_w = strip_sigma(nw, beta, sigma) g_wk = lattice_dyson_g_wk(mu=mu, e_k=e_k, sigma_w=sigma_w) print '--> gr_from_gk (k->r)' g_wr = fourier_wk_to_wr(g_wk) del g_wk print '--> grt_from_grw (w->tau)' g_tr = fourier_wr_to_tr(g_wr) del g_wr if sigma is None: return g_tr else: return g_tr, sigma_w
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
def solve_lattice_bse_depr(g_wk, gamma_wnn, tail_corr_nwf=-1): fmesh_huge, kmesh = g_wk.mesh.components 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_sigma = len(fmesh_huge) // 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_sigma = ', nwf_sigma)) print(('nwf = ', tail_corr_nwf, ' (gf)')) print() # -- Lattice BSE calc with built in trace using g_wk from triqs_tprf.lattice import chiq_sum_nu_from_g_wk_and_gamma_PH chi_kw = chiq_sum_nu_from_g_wk_and_gamma_PH(g_wk, gamma_wnn, tail_corr_nwf=tail_corr_nwf) return chi_kw
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
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
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
def solve_lattice_bse_at_specific_w(g_wk, gamma_wnn, nw_index): r""" Compute the generalized lattice susceptibility :math:`\chi_{\bar{a}b\bar{c}d}(i\omega_{n=\mathrm{nw\_index}}, \mathbf{k})` using the Bethe-Salpeter equation (BSE) for a specific :math:`i\omega_{n=\mathrm{nw\_index}}`. Parameters ---------- g_wk : Gf, Single-particle Green's function :math:`G_{a\bar{b}}(i\nu_n, \mathbf{k})`. gamma_wnn : Gf, Local particle-hole vertex function :math:`\Gamma_{a\bar{b}c\bar{d}}(i\omega_n, i\nu_n, i\nu_n')`. nw_index : int, The bosonic Matsubara frequency index :math:`i\omega_{n=\mathrm{nw\_index}}` at which the BSE is solved. Returns ------- chi_k : Gf, Generalized lattice susceptibility :math:`\chi_{\bar{a}b\bar{c}d}(i\omega_{n=\mathrm{nw\_index}}, \mathbf{k})`. chi0_k : Gf, Generalized bare lattice susceptibility :math:`\chi^0_{\bar{a}b\bar{c}d}(i\omega_{n=\mathrm{nw\_index}}, \mathbf{k})`. """ # Only use \Gamma at the specific \omega gamma_nn = gamma_wnn[Idx(nw_index), :, :] # Keep fake bosonic mesh for usability with other functions gamma_wnn = add_fake_bosonic_mesh(gamma_nn) 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) 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 at specific \omega.\n' ) print('nk =', nk) print('nw_index =', nw_index) print('nwf =', nwf) print('nwf_g =', nwf_g) print() mpi.report('--> chi0_wk_tail_corr') # Calculate chi0_wk up to the specific \omega chi0_wk_tail_corr = imtime_bubble_chi0_wk(g_wk, nw=np.abs(nw_index) + 1, save_memory=True) # Only use specific \omega, but put back on fake bosonic mesh chi0_k_tail_corr = chi0_wk_tail_corr[Idx(nw_index), :] chi0_wk_tail_corr = add_fake_bosonic_mesh(chi0_k_tail_corr, beta=bmesh.beta) chi0_nk = get_chi0_nk_at_specific_w(g_wk, nw_index=nw_index, nwf=nwf) # Keep fake bosonic mesh for usability with other functions chi0_wnk = add_fake_bosonic_mesh(chi0_nk) mpi.report('--> trace chi0_wnk') chi0_wk = chi0q_sum_nu(chi0_wnk) 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.') chi_k = chi_kw[:, Idx(0)] del chi_kw chi0_k = chi0_kw[:, Idx(0)] del chi0_kw return chi_k, chi0_k
def solve_lattice_bse(g_wk, gamma_wnn): r""" Compute the generalized lattice susceptibility :math:`\chi_{\bar{a}b\bar{c}d}(\mathbf{k}, \omega_n)` using the Bethe-Salpeter equation (BSE). Parameters ---------- g_wk : Gf, Single-particle Green's function :math:`G_{a\bar{b}}(i\nu_n, \mathbf{k})`. gamma_wnn : Gf, Local particle-hole vertex function :math:`\Gamma_{a\bar{b}c\bar{d}}(i\omega_n, i\nu_n, i\nu_n')`. Returns ------- chi_kw : Gf, Generalized lattice susceptibility :math:`\chi_{\bar{a}b\bar{c}d}(\mathbf{k}, i\omega_n)`. chi0_kw : Gf, Generalized bare lattice susceptibility :math:`\chi^0_{\bar{a}b\bar{c}d}(\mathbf{k}, i\omega_n)`. """ 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() mpi.report('--> chi0_wk_tail_corr') chi0_wk_tail_corr = imtime_bubble_chi0_wk(g_wk, nw=nw) mpi.barrier() mpi.report('B1 ' + str(chi0_wk_tail_corr[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) mpi.barrier() chi0_wnk = get_chi0_wnk(g_wk, nw=nw, nwf=nwf) 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