Exemple #1
0
def gto2tuck(w,cf,x):
    
    n = len(x)
    r = len(cf)
    
    k=0
    for alpha in xrange(r):
        k += len(w[alpha].prims)
    
    U1 = np.zeros((n,k*r))
    U2 = np.zeros((n,k*r))
    U3 = np.zeros((n,k*r))
    c = np.zeros(k*r)
    
    nG = 0
    for alpha in xrange(r):
        for beta in xrange(len(w[alpha].prims)):
            prim = w[alpha].prims[beta]
            i,j,k = prim.powers
            x0,y0,z0 = prim.origin
            #print [x0,y0,z0]
            U1[:,beta + nG] = pow(x-x0,i)*np.exp(-prim.exp*(x-x0)**2)
            U2[:,beta + nG] = pow(x-y0,j)*np.exp(-prim.exp*(x-y0)**2)
            U3[:,beta + nG] = pow(x-z0,k)*np.exp(-prim.exp*(x-z0)**2)
            c[beta + nG] = w[alpha].norm*prim.norm*prim.coef*cf[alpha]
        nG += len(w[alpha].prims)
    return tuck.can2tuck(c,U1,U2,U3)
Exemple #2
0
def poisson(F, mu, N, h, eps, r_add = 4, solver='Fourier'):   # check N+1

    #solves (-\Delta + mu) = F with F.shape = N \times N \times N  
    
    U1_L = np.ones((F.n[0], 4), dtype = np.float64)
    U2_L = U1_L.copy()
    U3_L = U1_L.copy()
    
    if solver=='Fourier':
        U1_L[:, 0] = 4. * np.sin(1./(N+1)*(np.array(range(F.n[0]))+1)*pi/2)**2 / h**2
    elif solver=='spectral':
        U1_L[:, 0] = np.pi**2 * (np.array(range(F.n[0]))+1)**2
    else:
        raise Exception('Incorrect poisson solver name')
    U1_L[:, 3] = mu * U1_L[:, 3].copy()
    U2_L[:, 1] = U1_L[:, 0].copy()
    U3_L[:, 2] = U1_L[:, 0].copy()
    g = np.ones(F.n[0], dtype = np.float64)


    L = tuck.can2tuck(g, U1_L, U2_L, U3_L)
    #L = tuck.round(L, 1e-14)
    
    f = tuck.dst(F)

    frac = tuck.cross.multifun([f, L], eps, lambda (a, b): a/b, r_add = r_add)
    sol = tuck.dst(frac)

    return sol
Exemple #3
0
def newton(x, eps, ind):
    
    # galerkin tensor for convolution as a hartree potential
    
    if ind == 6:
        a, b, r = -15., 10, 80
    elif ind == 8:
        a, b, r = -20., 15, 145
    elif ind == 10:
        a, b, r = -25., 20, 220
    elif ind == 12:
        a, b, r = -30., 25, 320
    else:
        raise Exception("wrong ind parameter")
    
    
    N = x.shape
    
    hr = (b-a)/(r - 1)
    h = x[1]-x[0]
    
    s = np.array(range(r), dtype = np.complex128)
    s = a + hr * (s - 1)
    
    w = np.zeros(r, dtype = np.complex128)
    for alpha in xrange(r):
        w[alpha] = 2*hr * np.exp(s[alpha]) / np.sqrt(pi)
    w[0]   = w[0]/2
    w[r-1] = w[r-1]/2
    
    
    U = np.zeros((N[0], r), dtype = np.complex128)
    for alpha in xrange(r):
        U[:, alpha] = (  func_int(x-h/2, x[0]-h/2, np.exp(2*s[alpha])) -
                       func_int(x+h/2, x[0]-h/2, np.exp(2*s[alpha])) +
                       func_int(x+h/2, x[0]+h/2, np.exp(2*s[alpha])) -
                       func_int(x-h/2, x[0]+h/2, np.exp(2*s[alpha]))  )
    
    newton = tuck.can2tuck(w, U, U, U)
    newton = tuck.round(newton, eps)
    
    return (1./h**3) * newton
Exemple #4
0
def newton(x, eps, ind):

    # galerkin tensor for convolution as a hartree potential

    if ind == 6:
        a, b, r = -15., 10, 80
    elif ind == 8:
        a, b, r = -20., 15, 145
    elif ind == 10:
        a, b, r = -25., 20, 220
    elif ind == 12:
        a, b, r = -30., 25, 320
    else:
        raise Exception("wrong ind parameter")

    N = x.shape

    hr = (b - a) / (r - 1)
    h = x[1] - x[0]

    s = np.array(range(r), dtype=np.complex128)
    s = a + hr * (s - 1)

    w = np.zeros(r, dtype=np.complex128)
    for alpha in xrange(r):
        w[alpha] = 2 * hr * np.exp(s[alpha]) / np.sqrt(pi)
    w[0] = w[0] / 2
    w[r - 1] = w[r - 1] / 2

    U = np.zeros((N[0], r), dtype=np.complex128)
    for alpha in xrange(r):
        U[:,
          alpha] = (func_int(x - h / 2, x[0] - h / 2, np.exp(2 * s[alpha])) -
                    func_int(x + h / 2, x[0] - h / 2, np.exp(2 * s[alpha])) +
                    func_int(x + h / 2, x[0] + h / 2, np.exp(2 * s[alpha])) -
                    func_int(x - h / 2, x[0] + h / 2, np.exp(2 * s[alpha])))

    newton = tuck.can2tuck(w, U, U, U)
    newton = tuck.round(newton, eps)

    return (1. / h**3) * newton
Exemple #5
0
def coulomb(x, vec, ind, eps, beta=1.0):  # 1/|r-vec|**beta in Tucker format

    if ind == 6:
        a, b, r = -15., 10, 80
    elif ind == 8:
        a, b, r = -20., 15, 145
    elif ind == 10:
        a, b, r = -25., 20, 220
    elif ind == 12:
        a, b, r = -30., 25, 320
    else:
        raise Exception("wrong ind parameter")    

    N = x.shape
    h = (b-a)/(r - 1)

    s = np.array(range(r))
    s = a + h * (s - 1)

    w = np.zeros(r, dtype = np.float64)
    for alpha in xrange(r):
        w[alpha] = 2*h * np.exp(beta*s[alpha]) / gamma(beta/2)
    w[0]   = w[0]/2
    w[r-1] = w[r-1]/2


    U1 = np.zeros((N[0], r), dtype=np.float64)
    U2 = np.zeros((N[0], r), dtype=np.float64)
    U3 = np.zeros((N[0], r), dtype=np.float64)

    for alpha in xrange(r):
        U1[:, alpha] = np.exp(-(x-vec[0])**2 * np.exp(2*s[alpha]))
        U2[:, alpha] = np.exp(-(x-vec[1])**2 * np.exp(2*s[alpha]))
        U3[:, alpha] = np.exp(-(x-vec[2])**2 * np.exp(2*s[alpha]))

    
    newton = tuck.can2tuck(w, U1, U2, U3)
    newton = tuck.round(newton, eps)
    
    return newton
Exemple #6
0
def coulomb(x, vec, ind, eps, beta=1.0):  # 1/|r-vec|**beta in Tucker format

    if ind == 6:
        a, b, r = -15., 10, 80
    elif ind == 8:
        a, b, r = -20., 15, 145
    elif ind == 10:
        a, b, r = -25., 20, 220
    elif ind == 12:
        a, b, r = -30., 25, 320
    else:
        raise Exception("wrong ind parameter")

    N = x.shape
    h = (b - a) / (r - 1)

    s = np.array(range(r))
    s = a + h * (s - 1)

    w = np.zeros(r, dtype=np.float64)
    for alpha in xrange(r):
        w[alpha] = 2 * h * np.exp(beta * s[alpha]) / gamma(beta / 2)
    w[0] = w[0] / 2
    w[r - 1] = w[r - 1] / 2

    U1 = np.zeros((N[0], r), dtype=np.float64)
    U2 = np.zeros((N[0], r), dtype=np.float64)
    U3 = np.zeros((N[0], r), dtype=np.float64)

    for alpha in xrange(r):
        U1[:, alpha] = np.exp(-(x - vec[0])**2 * np.exp(2 * s[alpha]))
        U2[:, alpha] = np.exp(-(x - vec[1])**2 * np.exp(2 * s[alpha]))
        U3[:, alpha] = np.exp(-(x - vec[2])**2 * np.exp(2 * s[alpha]))

    newton = tuck.can2tuck(w, U1, U2, U3)
    newton = tuck.round(newton, eps)

    return newton