Esempio n. 1
0
 def apply_kernel(self, Q, U):
     U_exp = util.gridswap(self.r, self.rexp, U)
     rho_exp = np.dot(Q, U_exp)
     return util.gridswap(self.rexp, self.r, rho_exp)
Esempio n. 2
0
 def apply_kernel(self, Q, U):
     U_exp = util.gridswap(self.r, self.rexp, U)
     rho_exp = np.dot(Q, U_exp)
     return util.gridswap(self.rexp, self.r, rho_exp)
Esempio n. 3
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. 4
0
   
   f = datasets[-1][0]
   data = np.load(f)
   r = data['r']
   U = data['U']

   print fields

   Mmax = 50

   Econv = 1e9 * 1.05457173e-34 * 1e6 / 1.60217657e-19 ###eV                              
   print 'Conversion to eV factor', Econv

   if True:
      r2 = np.linspace(r[0], 10.0, 500)
      U = util.gridswap(r, r2, U)
      r = np.array(r2)
      Espace = np.linspace(-0.8, 0.8, 4000)
      mlist = np.arange(0.0, r[-1]*Espace[-1], 1.0)
      print 'Max m =', mlist[-1]
   else:
      Espace = np.arange(-1.999, 1.999, 0.001) + 1e-5
      mlist = np.arange(0.0, 10.5, 1.0)
   dos = odedirac.doscalc(Espace, r, U, mlist)
   
   Econv = 1e9 * 1.05457173e-34 * 1e6 / 1.60217657e-19 ###eV 

   print 'Conversion to eV factor', Econv
   Espace *= Econv
   dos /= Econv