示例#1
0
def test_make_laplacian():
    print('Test make_laplacian():')
    n, m, h = 8, 8, 0.1
    r = arange(0, h * m - 1e-10, h)
    D1 = diags((1, -8, 0, 8, -1), (-2, -1, 0, 1, 2), shape=(m, m)).toarray()
    D2 = diags((-1, 16, -30, 16, -1), (-2, -1, 0, 1, 2),
               shape=(m, m)).toarray()
    r[0] = 1
    D1[0, :] = 0
    D1[1, 1] += 1
    D2[0, :3] = [-60, 64, -4]
    D2[1, 1] += -1
    D = D2 / (24 * h**2) + diag(1.0 / r).dot(D1) / (12 * h)
    L = nls.make_laplacian(n, 5, h)
    tolerance = 5.0e-5
    for k in xrange(0, 3):
        err = max(abs(diag(D, 2 - k) - L[k, 2 - k:]))
        print('Diagonal # ', 2 - k, ':    ', err)
        if err >= tolerance:
            print(diag(D, 2 - k))
            print(L[k, 2 - k:])
    for k in xrange(1, 3):
        err = max(abs(diag(D, -k) - L[2 + k, :-k]))
        print('Diagonal #', -k, ':    ', err)
        if err >= tolerance:
            print(diag(D, -k))
            print(L[2 + k, :-k])
示例#2
0
文件: nls_test.py 项目: daskol/nls
def test_make_laplacian():
    print('Test make_laplacian():')
    n, m, h = 8, 8, 0.1
    r = arange(0, h * m - 1e-10, h)
    D1 = diags((1, -8, 0, 8, -1), (-2, -1, 0, 1, 2), shape=(m, m)).toarray()
    D2 = diags((-1, 16, -30, 16, -1), (-2, -1, 0, 1, 2), shape=(m, m)).toarray()
    r[0] = 1
    D1[0, :] = 0
    D1[1, 1] += 1
    D2[0, :3] = [-60, 64, -4]
    D2[1, 1] += -1
    D = D2 / (24 * h ** 2) + diag(1.0 / r).dot(D1)  / (12 * h)
    L = nls.make_laplacian(n, 5, h)
    tolerance = 5.0e-5
    for k in xrange(0, 3):
        err = max(abs(diag(D, 2 - k) - L[k, 2 - k:]))
        print('Diagonal # ', 2 - k, ':    ', err)
        if err >= tolerance:
            print(diag(D, 2 - k))
            print(L[k, 2 - k:])
    for k in xrange(1, 3):
        err = max(abs(diag(D, -k) - L[2 + k, :-k]))
        print('Diagonal #', -k, ':    ', err)
        if err >= tolerance:
            print(diag(D, -k))
            print(L[2 + k, :-k])
示例#3
0
def test_runge_kutta():
    """Call runge_kutta() fortran subroutine directly through f2py wrapper layer.
    """
    print('Test runge_kutta():')
    u0 = array([1, 1, 1, 1, 1, 1, 1, 1])
    op = nls.make_laplacian(8, 5, 0.01)
    u = nls.runge_kutta(0.00001, 0.0, 0.01, u0, op, 10)
    print(u)
示例#4
0
文件: nls_test.py 项目: daskol/nls
def test_runge_kutta():
    """Call runge_kutta() fortran subroutine directly through f2py wrapper layer.
    """
    print('Test runge_kutta():')
    u0 = array([1, 1, 1, 1, 1, 1, 1, 1])
    op = nls.make_laplacian(8, 5, 0.01)
    u = nls.runge_kutta(0.00001, 0.0, 0.01, u0, op, 10)
    print(u)