Example #1
0
def test_funspace_2():
    '''Test of FunctionSpace.int_phi_phi made up of linear elements, basic
    integration

    '''
    ox, dx, nx = 0., 1., 1
    mesh = Mesh(type='uniform', lx=dx, nx=nx, block='B1')
    V = FunctionSpace(mesh, {'B1': Element(type='link2')})

    # basic properties
    assert V.num_dof == (nx + 1)
    assert V.size == nx
    X = np.linspace(ox, dx, nx+1)
    assert allclose(V.X, X)

    # Integrate[N(x) N(x) {x, 0, 1}]
    fun = lambda x: x
    f = lambda i, j: integrate(fun(x) * N[i] * N[j], (x, ox, dx))
    ans = V.int_phi_phi(fun=fun, derivative=(False, False))
    exact = Matrix(2, 2, lambda i, j: f(i,j))
    assert areclose(exact, ans)

    # Trivial check with coefficient
    fun = lambda x: 1.
    a1 = V.int_phi_phi()
    a2 = V.int_phi_phi(fun=fun)
    assert areclose(a1, a2)
Example #2
0
def test_funspace_8():
    '''Testing of FunctionSpace.int_phi_phi, MMS'''
    ox, dx, nx = 0., 10., 10
    mesh = Mesh(type='uniform', lx=dx, nx=nx, block='B1')
    V = FunctionSpace(mesh, {'B1': Element(type='link2')})

    rhs = np.random.rand(V.num_dof)
    A = V.int_phi_phi()
    f = lambda x: np.interp(x, V.X, rhs)
    b = V.int_phi(f)
    assert areclose(np.dot(A, rhs), b)
    return
Example #3
0
def test_funspace_7():
    '''Test of FunctionSpace.int_phi_phi made up of linear elements, mixed
    matrix integration

    '''
    ox, dx, nx = 0., 1., 1
    mesh = Mesh(type='uniform', lx=dx, nx=nx, block='B1')
    V = FunctionSpace(mesh, {'B1': Element(type='link2')})

    # Integrate[N(x) N'(x) {x, 0, 1}]
    f = lambda i, j: integrate(N[i] * dN[j], (x, ox, dx))
    ans = V.int_phi_phi(derivative=(False, True))
    exact = Matrix(2, 2, lambda i, j: f(i,j))
    assert areclose(exact, ans)

    # Integrate[N'(x) N(x) {x, 0, 1}]
    f = lambda i, j: integrate(dN[i] * N[j], (x, ox, dx))
    ans = V.int_phi_phi(derivative=(True, False))
    exact = Matrix(2, 2, lambda i, j: f(i,j))
    assert areclose(exact, ans)

    return
Example #4
0
def test_funspace_4():
    '''Test of FunctionSpace.int_phi_phi made up of linear elements, Laplace
    matrix multiply

    '''
    ox, dx, nx = 0., 1., 10
    mesh = Mesh(type='uniform', lx=dx, nx=nx, block='B1')
    V = FunctionSpace(mesh, {'B1': Element(type='link2')})
    C = V.int_phi_phi(derivative=(True, True))

    sol = np.ones(V.num_dof)
    b = np.dot(C, sol)
    assert norm(b) < 1.e-12
Example #5
0
def test_funspace_6():
    '''Test of FunctionSpace.int_phi_phi made up of linear elements, Laplace
    norm check.  Solution = x^2

    '''
    ox, dx, nx = 0., 1., 10
    mesh = Mesh(type='uniform', lx=dx, nx=nx, block='B1')
    V = FunctionSpace(mesh, {'B1': Element(type='link2')})
    C = V.int_phi_phi(derivative=(True, True))

    sol = V.X ** 2
    b = np.dot(C, sol)
    rhs = V.int_phi(lambda x: 2.)
    # natural b.c. not satisfied on right, don't check it
    rhs[-1] = -b[-1]
    assert norm(rhs + b) < 1.e-12
Example #6
0
def test_funspace_9():
    '''Testing of FunctionSpace.int_phi_phi, mixed integration MMS'''
    ox, dx, nx = 0., 10., 10
    mesh = Mesh(type='uniform', lx=dx, nx=nx, block='B1')
    V = FunctionSpace(mesh, {'B1': Element(type='link2')})

    D = V.int_phi_phi(derivative=(False,True))
    sol = np.ones(V.num_dof)
    b = np.dot(D, sol)
    # Norm check (rhs d/dx + Neumann, const soln)
    assert norm(b) < 1.e-12

    D[0, 0] = 1.0
    D[0, 1:] = 0.0
    D[-1, -1] = 1.0
    D[-1, 0:-1] = 0.0
    sol = V.X
    b = np.dot(D, sol)
    rhs = V.int_phi(lambda x: 1)
    rhs[0] = sol[0]
    rhs[-1] = sol[-1]
    # norm check (d/dx+Dirichlet sol=x)
    assert norm(rhs - b) < 1.e-12