Пример #1
0
def test_3d_block_2():
    print('============== test_3d_block_2 ================')

    x, y, z = symbols('x y z')

    u = IndexedBase('u')
    v = IndexedBase('v')

    F = Field('F')

    a = Lambda((x, y, z, v, u),
               Dot(Curl(u), Curl(v)) + 0.2 * Dot(u, v) + F * u[0] * v[0])

    # ...  create a finite element space
    p1 = 2
    p2 = 2
    p3 = 2
    ne1 = 2
    ne2 = 2
    ne3 = 2

    print('> Grid   :: [{},{},{}]'.format(ne1, ne2, ne3))
    print('> Degree :: [{},{},{}]'.format(p1, p2, p3))

    grid_1 = linspace(0., 1., ne1 + 1)
    grid_2 = linspace(0., 1., ne2 + 1)
    grid_3 = linspace(0., 1., ne3 + 1)

    V1 = SplineSpace(p1, grid=grid_1)
    V2 = SplineSpace(p2, grid=grid_2)
    V3 = SplineSpace(p3, grid=grid_3)

    W = TensorFemSpace(V1, V2, V3)
    # ...

    # ... vector space
    V = VectorFemSpace(W, W, W)
    # ...

    F = Spline(W)
    F.coeffs._data[:, :, :] = 1.

    # ...
    kernel_py = compile_kernel('kernel_block_2', a, V, backend='python')
    kernel_f90 = compile_kernel('kernel_block_2', a, V, backend='fortran')

    M_py = assemble_matrix(V, kernel_py, fields={'F': F})
    M_f90 = assemble_matrix(V, kernel_f90, fields={'F': F})
    # ...

    assert_identical_coo(M_py, M_f90)
Пример #2
0
def test_2d_block_2():
    print('============== test_2d_block_2 ================')

    # ... define the weak formulation
    x, y = symbols('x y')

    u = IndexedBase('u')
    v = IndexedBase('v')

    F = Field('F')

    a = Lambda(
        (x, y, v, u),
        Rot(u) * Rot(v) + Div(u) * Div(v) + 0.2 * Dot(u, v) + F * u[0] * v[0])
    # ...

    # ...  create a finite element space
    p1 = 2
    p2 = 2
    ne1 = 8
    ne2 = 8

    print('> Grid   :: [{ne1},{ne2}]'.format(ne1=ne1, ne2=ne2))
    print('> Degree :: [{p1},{p2}]'.format(p1=p1, p2=p2))

    grid_1 = linspace(0., 1., ne1 + 1)
    grid_2 = linspace(0., 1., ne2 + 1)

    V1 = SplineSpace(p1, grid=grid_1)
    V2 = SplineSpace(p2, grid=grid_2)

    W = TensorFemSpace(V1, V2)
    # ...

    # ... vector space
    V = VectorFemSpace(W, W)
    # ...

    F = Spline(W)
    F.coeffs._data[:, :] = 1.

    # ...
    kernel_py = compile_kernel('kernel_block_2', a, V, backend='python')
    kernel_f90 = compile_kernel('kernel_block_2', a, V, backend='fortran')

    M_py = assemble_matrix(V, kernel_py, fields={'F': F})
    M_f90 = assemble_matrix(V, kernel_f90, fields={'F': F})
    # ...

    assert_identical_coo(M_py, M_f90)
Пример #3
0
def test_3d_scalar_4():
    print('============== test_3d_scalar_4 ================')

    # ... define the weak formulation
    x, y, z = symbols('x y z')

    u = Symbol('u')
    v = Symbol('v')

    F = Field('F')

    a = Lambda((x, y, z, v, u), Dot(Grad(F * u), Grad(v)) + u * v)
    # ...

    # ...  create a finite element space
    p1 = 2
    p2 = 2
    p3 = 2
    ne1 = 2
    ne2 = 2
    ne3 = 2
    # ...

    print('> Grid   :: [{},{},{}]'.format(ne1, ne2, ne3))
    print('> Degree :: [{},{},{}]'.format(p1, p2, p3))

    grid_1 = linspace(0., 1., ne1 + 1)
    grid_2 = linspace(0., 1., ne2 + 1)
    grid_3 = linspace(0., 1., ne3 + 1)

    V1 = SplineSpace(p1, grid=grid_1)
    V2 = SplineSpace(p2, grid=grid_2)
    V3 = SplineSpace(p3, grid=grid_3)

    V = TensorFemSpace(V1, V2, V3)
    # ...

    F = Spline(V)
    F.coeffs._data[:, :, :] = 1.

    # ...
    kernel_py = compile_kernel('kernel_scalar_4', a, V, backend='python')
    kernel_f90 = compile_kernel('kernel_scalar_4', a, V, backend='fortran')

    M_py = assemble_matrix(V, kernel_py, fields={'F': F})
    M_f90 = assemble_matrix(V, kernel_f90, fields={'F': F})
    # ...

    assert_identical_coo(M_py, M_f90)
Пример #4
0
def test_1d_4():
    x,y = symbols('x y')

    u = Symbol('u')
    v = Symbol('v')

    F = Field('F')

    a = Lambda((x,y,v,u), Dot(Grad(F*u), Grad(v)) + u*v)
    print('> input       := {0}'.format(a))

    expr = gelatize(a, dim=DIM)
    print('> gelatized   := {0}'.format(expr))

    expr = normalize_weak_from(expr)
    print('> normal form := {0}'.format(expr))

    print('')
Пример #5
0
def test_1d_scalar_4():
    print('============== test_1d_scalar_4 ================')

    # ... define the weak formulation
    x = Symbol('x')

    u = Symbol('u')
    v = Symbol('v')

    F = Field('F')

    a = Lambda((x, v, u), Dot(Grad(F * u), Grad(v)) + u * v)
    # ...

    # ...  create a finite element space
    p = 3
    ne = 64

    print('> Grid   :: {ne}'.format(ne=ne))
    print('> Degree :: {p}'.format(p=p))

    grid = linspace(0., 1., ne + 1)

    V = SplineSpace(p, grid=grid)
    # ...

    # ...
    kernel_py = compile_kernel('kernel_scalar_4', a, V, backend='python')
    kernel_f90 = compile_kernel('kernel_scalar_4', a, V, backend='fortran')

    F = Spline(V)
    F.coeffs._data[:] = 1.

    M_py = assemble_matrix(V, kernel_py, fields={'F': F})
    M_f90 = assemble_matrix(V, kernel_f90, fields={'F': F})
    # ...

    assert_identical_coo(M_py, M_f90)