Esempio n. 1
0
    def __init__(self, r, Ef, **kwargs):
        params = {
            'Temp': 0.01,
            'Ecut': -1.5,
            'B': 0.0,
            'Mmax': 16,
            'grid_intra': 'lin',
            'grid_inter': 'exp'
        }
        params.update(**kwargs)
        self.Emin = min(Ef, params['Ecut'])  # Ecut could be both positive
        self.Emax = max(Ef, params['Ecut'])  # and negative
        self.Temp = params['Temp']
        self.r = r
        self.rexp = util.make_exp_grid(r.min(), r.max(), len(r))
        self.B = params['B']
        self.mlist = np.array(range(0, params['Mmax']))

        grid_dict = {'lin': self.r, 'exp': self.rexp}

        r_inter = Grid(grid_dict[params['grid_inter']], params['grid_inter'])
        r_intra = Grid(grid_dict[params['grid_intra']], params['grid_intra'])

        if False:  # Use this to skip kernel calculation; helpful in debugging
            self.Q_Emin = np.zeros(
                (len(self.rexp),
                 len(self.rexp)))  #RPA_kernel(self.rexp, abs(self.Emin))
            self.Q_Emax = np.zeros(np.shape(
                self.Q_Emin))  #RPA_kernel(self.rexp, abs(self.Emax))
        else:
            # Full RPA kernel
            self.Q_Emin = RPA_tot(r_inter, r_intra, abs(self.Emin))
            self.Q_Emax = RPA_tot(r_inter, r_intra, abs(self.Emax))
            #Kernel(self.rexp, RPA_kernel(self.rexp, abs(self.Emin)))
            #self.Q_Emax  = Kernel(self.rexp, RPA_kernel(self.rexp, abs(self.Emax)))
            # m-resolved RPA kernel
        if False:
            self.Qm_Emax = self.Q_Emax
            #np.zeros(np.shape(self.Q_Emin))#rpakernel.kernel_m(self.rexp, self.mlist, abs(self.Emax))
            self.Qm_Emin = self.Q_Emin
            #np.zeros(np.shape(self.Q_Emax))#rpakernel.kernel_m(self.rexp, self.mlist, abs(self.Emin))
        else:
            self.Qm_Emin = RPA_m(r_inter, r_intra, abs(self.Emin), self.mlist)
            self.Qm_Emax = RPA_m(r_inter, r_intra, abs(self.Emax), self.mlist)
            #rpakernel.kernel_m(self.rexp, self.mlist, abs(self.Emax))
            #self.Qm_Emin =
            #rpakernel.kernel_m(self.rexp, self.mlist, abs(self.Emin))
        self.rho_0 = self.diracDensity(np.zeros(np.shape(r)))
        self.Q_corr = RPA_corr(r_inter, r_intra, abs(self.Emax), self.mlist)
        N = len(self.r)
Esempio n. 2
0
 def __init__ (self, r, Ef, **kwargs):
     params = {
        'Temp'   : 0.01, 
         'Ecut'  : -1.5, 
         'B'     : 0.0, 
         'Mmax'  : 16, 
         'grid_intra' : 'lin', 
         'grid_inter' : 'exp'
     }
     params.update(**kwargs)
     self.Emin = min(Ef, params['Ecut']) # Ecut could be both positive
     self.Emax = max(Ef, params['Ecut']) # and negative
     self.Temp = params['Temp']
     self.r    = r
     self.rexp = util.make_exp_grid(r.min(), r.max(), len(r))
     self.B = params['B']
     self.mlist =  np.array(range(0, params['Mmax']))
     
     grid_dict = {
         'lin' : self.r, 
         'exp' : self.rexp 
     }
     
     r_inter = Grid(grid_dict[params['grid_inter']], params['grid_inter'])
     r_intra = Grid(grid_dict[params['grid_intra']], params['grid_intra'])
     
     if False:  # Use this to skip kernel calculation; helpful in debugging
        self.Q_Emin = np.zeros((len (self.rexp), len(self.rexp)))#RPA_kernel(self.rexp, abs(self.Emin))
        self.Q_Emax = np.zeros(np.shape(self.Q_Emin)) #RPA_kernel(self.rexp, abs(self.Emax))
     else:
        # Full RPA kernel
        self.Q_Emin  = RPA_tot(r_inter, r_intra, abs(self.Emin)) 
        self.Q_Emax  = RPA_tot(r_inter, r_intra, abs(self.Emax)) 
        #Kernel(self.rexp, RPA_kernel(self.rexp, abs(self.Emin)))
        #self.Q_Emax  = Kernel(self.rexp, RPA_kernel(self.rexp, abs(self.Emax)))
        # m-resolved RPA kernel
     if False:
        self.Qm_Emax = self.Q_Emax; #np.zeros(np.shape(self.Q_Emin))#rpakernel.kernel_m(self.rexp, self.mlist, abs(self.Emax))
        self.Qm_Emin = self.Q_Emin; #np.zeros(np.shape(self.Q_Emax))#rpakernel.kernel_m(self.rexp, self.mlist, abs(self.Emin))
     else:
        self.Qm_Emin = RPA_m(r_inter, r_intra, abs(self.Emin), self.mlist) 
        self.Qm_Emax = RPA_m(r_inter, r_intra, abs(self.Emax), self.mlist) 
        #rpakernel.kernel_m(self.rexp, self.mlist, abs(self.Emax))
        #self.Qm_Emin = 
        #rpakernel.kernel_m(self.rexp, self.mlist, abs(self.Emin))
     self.rho_0 = self.diracDensity(np.zeros(np.shape(r)))
     self.Q_corr = RPA_corr(r_inter, r_intra, abs(self.Emax), self.mlist)
     N = len(self.r)
Esempio n. 3
0
 #U = Z / np.sqrt(r**2 + r_0**2)
 #def Ur(rx):
 #    if rx > r_0: 
 #       return -Z/rx 
 #    return -Z / r_0
 #U = np.vectorize(Ur)(r)
 #def rho_b(rx):
 #     #if rx > r_0: return 0.0; 
 #     #return Z / math.pi / r_0**2
 #     return r_0**2 / math.pi / (rx**2 + r_0**2)**2 * Z
 delta_func = deltafunc.DeltaGauss(r_0)
 #delta_func = deltafunc.DeltaCubic(r_0)
 rho_bare = Z * delta_func.rho(r)
 U = Z * delta_func.U(r)
 
 rexp = util.make_exp_grid(0.001, 50.0, 1000)
 Qcoul = Kernel(rexp, coulomb.kernel(rexp))
 #rho_bare = np.vectorize(rho_b)(r)
 #U = Qcoul(r, rho_bare)
 #U[0:3] = U[3]
 if True:
    import pylab as pl
    pl.plot (r, U)
    pl.plot (r, Z / np.sqrt(r**2 + r_0**2))
    pl.figure()
    pl.loglog(r, np.abs(U))
    pl.loglog(r, Z / np.sqrt(r**2 + r_0**2))
    pl.show ()
 rho_th = - math.pi / 8.0 * rho_bare
 #rho_th = -Z * r_0 / 16.0 / np.sqrt(r**2 + r_0**2)**3
 
Esempio n. 4
0
#
import rpakernel
import util
#import pylab as pl
import numpy as np
import mkrpa2
import rpam
import rpacorr

#kF = 3.0
rmin = 0.01
rmax = 50.0
N = 500
Mmax = 31
mlist = np.array(range(0, Mmax))
rexp = util.make_exp_grid(rmin, rmax, N)
rlin = util.make_lin_grid(rmin, rmax, N)

#Q0 = rpakernel.kernel_m_inter(rexp, mlist, 'exp')
#Q1 = mkrpa2.RPA_inter(rexp, 'exp')
Q2 = rpacorr.RPA_corr_inter(rexp, 'exp')

#for kF in [3.0, 2.0, 1.0, 0.5, 0.3, 0.2, 0.1, 2.5, 1.5, 0.5, 0.4, 0.35, 0.25, 0.15, 0.05]:
#for kF in [3.0, 1.0, 0.5, 0.4, 0.3, 0.2, 0.1]:
#for kF in np.arange(0.01, 0.5, 0.01):
grid_intra = 'exp'

r_dict = {'lin': rlin, 'exp': rexp}

intra_r = r_dict[grid_intra]
Esempio n. 5
0
def solve_coulomb(rho_U, Uext, r, tau_u_set, tau_rho_set, **kwarg):
           
    params = {
       'it'               : 0,
       'zero_endpoint'    : False,
       'display_callback' : empty_callback, 
       'fname_template'   : "data/coulombsim-it=%d.npz"   
    } 
    
    params.update(kwarg)
    print params
    
    zero_endpoint = params['zero_endpoint']
    it            = params['it']
    display_callback = params['display_callback']
    fname_template = params['fname_template']

    rexp = util.make_exp_grid(r.min(), r.max(), len(r))
    C = coulomb.kernel( rexp )
    U = np.array( Uext )
    rho = np.zeros( (len(r)) )
    j = 0
    zero_U = True
    
    def mkFilename(it):
       fname = fname_template % (it)
       print "fname: ", fname
       return fname
    
    if it > 0: # Load previous solution, if possible
       data = np.load( mkFilename( it ) )
       rho = data['rho']
       U = data['U']
       
    while True:
        
        tau_U   = tau_u_set  [it % len(tau_u_set)]
        tau_rho = tau_rho_set[it % len(tau_rho_set)]
        
        it += 1
        
        U1 = np.dot( C, util.gridswap(r, rexp, rho ) )
        U1 = util.gridswap(rexp,  r, U1)
        #rho = util.gridswap(rexp, r, rho)
        U1 += Uext
        
        if zero_endpoint: U1 -= U1[-1];
        
        err_U = linalg.norm(U - U1)
        U += tau_U * (U1 - U)
        if zero_endpoint: U -= U[-1];
        
        rho1 = rho_U(U, r)
        err_rho = linalg.norm(rho1 - rho)
        rho += tau_rho * (rho1 - rho)
        
        print "U error", err_U, "rho error", err_rho, "it", it
        np.savez(mkFilename( it ), rho=rho, U=U, rho1=rho1, U1=U1, r=r)
        
        
        display_callback(it, r, U, rho, U1, rho1)
        
        if (err_U < (1e-4)) and (err_rho < (1e-5)):
            break
        if (err_U > 1e+6) or (err_rho > 1e+6): 
            print "A clear divergence"
            break

    return U, rho
Esempio n. 6
0
            break

    return U, rho


if __name__ == '__main__':
   Nf = 4.0 ###
   alpha = 2.5
   rmin = 0.01
   rmax = 100.0
   N = 1000
   Z = 1.0
   r_0 = 1.0
   
   import util
   r = util.make_exp_grid(rmin, rmax, N)
   #r = np.array(rexp)
   #print rexp
   print r
   #import sys
   #sys.exit(1)
   
   tau_u_set = make_tau_set(8, 0.1, 0.01)
   tau_rho_set = list(tau_u_set)
   
   def rho_minus12(U, r):
       return -U / r / 2.0 / np.pi**2 * Nf * alpha

   Uext = Z / np.sqrt (r**2 + r_0**2)

   U, rho = solve_coulomb(rho_minus12, Uext, r, tau_u_set, tau_rho_set) 
Esempio n. 7
0
    #U = Z / np.sqrt(r**2 + r_0**2)
    #def Ur(rx):
    #    if rx > r_0:
    #       return -Z/rx
    #    return -Z / r_0
    #U = np.vectorize(Ur)(r)
    #def rho_b(rx):
    #     #if rx > r_0: return 0.0;
    #     #return Z / math.pi / r_0**2
    #     return r_0**2 / math.pi / (rx**2 + r_0**2)**2 * Z
    delta_func = deltafunc.DeltaGauss(r_0)
    #delta_func = deltafunc.DeltaCubic(r_0)
    rho_bare = Z * delta_func.rho(r)
    U = Z * delta_func.U(r)

    rexp = util.make_exp_grid(0.001, 50.0, 1000)
    Qcoul = Kernel(rexp, coulomb.kernel(rexp))
    #rho_bare = np.vectorize(rho_b)(r)
    #U = Qcoul(r, rho_bare)
    #U[0:3] = U[3]
    if True:
        import pylab as pl
        pl.plot(r, U)
        pl.plot(r, Z / np.sqrt(r**2 + r_0**2))
        pl.figure()
        pl.loglog(r, np.abs(U))
        pl.loglog(r, Z / np.sqrt(r**2 + r_0**2))
        pl.show()
    rho_th = -math.pi / 8.0 * rho_bare
    #rho_th = -Z * r_0 / 16.0 / np.sqrt(r**2 + r_0**2)**3