Ejemplo n.º 1
0
def basis_laplacian_gsd(C, phi, L):
    '''
        Here, to avoid sigular at the boundary, we return
            C * \phi * Laplaican{phi}
        instead of
            C * \phi^{-1} * Laplaican{phi}
    '''
    dphi = (2.0 / L) * cheb_D1_fchebt(phi)
    d2phi = (2.0 / L) * cheb_D1_fchebt(dphi)
    return C * phi * d2phi
Ejemplo n.º 2
0
def test_speed():
    N = 32
    M = 10000
    ii = np.arange(N + 1)
    x = np.cos(np.pi * ii / N)
    f = np.exp(x) * np.sin(5. * x)

    t = time()
    for i in xrange(M):
        D, x = cheb_D1_mat(N)
        w = np.dot(D, f)
    print 'Run time for mat is:', time() - t

    t = time()
    for i in xrange(M):
        w = cheb_D1_fft(f)
    print 'Run time for fft is:', time() - t

    t = time()
    for i in xrange(M):
        w = cheb_D1_fchebt(f)
    print 'Run time for fchebt is:', time() - t

    t = time()
    for i in xrange(M):
        w = cheb_D1_dct(f)
    print 'Run time for dct is:', time() - t
Ejemplo n.º 3
0
def basis_gradient_square_gsd(C, phi, L):
    '''
        Here, to avoid sigular at the boundary, we return
            C * \grad{phi}**2
        instead of
            C * \phi^{-2} * \grad{phi}**2
    '''
    dphi = (2.0 / L) * cheb_D1_fchebt(phi)
    return C * dphi**2
Ejemplo n.º 4
0
def test_cheb_D1_fchebt():
    '''
    Example is from p18.m of Trefethen's book, p.81.
    '''

    xx = np.arange(-1, 1, .01)
    ff = np.exp(xx) * np.sin(5. * xx)
    for N in [10, 20]:
        ii = np.arange(N + 1)
        x = np.cos(np.pi * ii / N)
        f = np.exp(x) * np.sin(5. * x)
        plt.figure()
        plt.plot(x, f, '.')
        plt.plot(xx, ff, 'r-')
        plt.show()

        err = cheb_D1_fchebt(f) - np.exp(x) * (np.sin(5. * x) +
                                               5. * np.cos(5. * x))
        plt.figure()
        plt.plot(x, err, '.')
        plt.plot(x, err, '-')
        plt.show()
Ejemplo n.º 5
0
def basis_gradient_square(C, phi, L):
    dphi = (2.0 / L) * cheb_D1_fchebt(phi)
    return C * dphi**2
Ejemplo n.º 6
0
def basis_laplacian(C, phi, L):
    dphi = (2.0 / L) * cheb_D1_fchebt(phi)
    d2phi = (2.0 / L) * cheb_D1_fchebt(dphi)
    return C * d2phi