Beispiel #1
0
def test_3d_4b():
    """Alfven operator."""
    x, y, z = symbols('x y z')

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

    bx = Constant('bx')
    by = Constant('by')
    bz = Constant('bz')
    b = Tuple(bx, by, bz)

    c0, c1, c2 = symbols('c0 c1 c2')

    a = Lambda((x, y, z, v, u),
               (c0 * Dot(u, v) - c1 * Div(u) * Div(v) +
                c2 * Dot(Curl(Cross(b, u)), Curl(Cross(b, v)))))
    print('> input       := {0}'.format(a))

    # ...
    expr = construct_weak_form(a, dim=DIM, is_block=True, verbose=True)
    print('> weak form := {0}'.format(expr))
    # ...

    print('')
Beispiel #2
0
def test_3d_4b():
    """Alfven operator."""
    x,y,z = symbols('x y z')

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

    bx = Constant('bx')
    by = Constant('by')
    bz = Constant('bz')
    b = Tuple(bx, by, bz)

    c0,c1,c2 = symbols('c0 c1 c2')

    a = Lambda((x,y,z,v,u), (  c0 * Dot(u, v)
                             - c1 * Div(u) * Div(v)
                             + c2 *Dot(Curl(Cross(b,u)), Curl(Cross(b,v)))))
    print('> input       := {0}'.format(a))

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

    expr, info = initialize_weak_form(expr, dim=DIM)
    print('> temp form   :=')
    # for a nice printing, we print the dictionary entries one by one
    for key, value in list(expr.items()):
        print('\t\t', key, '\t', value)

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

    print('')
Beispiel #3
0
def test_3d_4a():
    x, y, z = symbols('x y z')

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

    b = Tuple(1.0, 0., 0.)

    a = Lambda((x, y, z, v, u),
               Dot(Curl(Cross(b, u)), Curl(Cross(b, v))) + 0.2 * Dot(u, v))
    print('> input       := {0}'.format(a))

    # ...
    expr = construct_weak_form(a, dim=DIM, is_block=True, verbose=True)
    print('> weak form := {0}'.format(expr))
    # ...

    print('')
Beispiel #4
0
def test_2d_3():
    x, y = symbols('x y')

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

    a = Lambda((x, y, v, u), Cross(Curl(u), Curl(v)) + 0.2 * u * v)
    print('> input       := {0}'.format(a))

    # ...
    expr = construct_weak_form(a, dim=DIM, is_block=True)
    print('> weak form := {0}'.format(expr))
    # ...

    print('')
Beispiel #5
0
def test_3d_4a():
    x,y,z = symbols('x y z')

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

    b = Tuple(1.0, 0., 0.)

    a = Lambda((x,y,z,v,u), Dot(Curl(Cross(b,u)), Curl(Cross(b,v))) + 0.2 * Dot(u, v))
    print('> input       := {0}'.format(a))

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

    expr, info = initialize_weak_form(expr, dim=DIM)
    print('> temp form   :=')
    # for a nice printing, we print the dictionary entries one by one
    for key, value in list(expr.items()):
        print('\t\t', key, '\t', value)

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

    print('')
Beispiel #6
0
def test_2d_scalar_4():
    print('============== test_2d_scalar_4 ================')

    x, y = symbols('x y')

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

    a = Lambda((x, y, v, u), Cross(Curl(u), Curl(v)) + 0.2 * u * v)
    print('> input       := {0}'.format(a))

    # ...  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)

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

    # ... create a glt symbol from a string without evaluation
    expr = glt_symbol(a, space=V)
    print('> glt symbol  := {0}'.format(expr))
    # ...

    # ...
    symbol_f90 = compile_symbol('symbol_scalar_4', a, V, backend='fortran')
    # ...

    # ... example of symbol evaluation
    t1 = linspace(-pi, pi, ne1 + 1)
    t2 = linspace(-pi, pi, ne2 + 1)
    x1 = linspace(0., 1., ne1 + 1)
    x2 = linspace(0., 1., ne2 + 1)
    e = zeros((ne1 + 1, ne2 + 1), order='F')
    symbol_f90(x1, x2, t1, t2, e)
    # ...

    print('')
Beispiel #7
0
def test_2d_3():
    x, y = symbols('x y')

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

    a = Lambda((x, y, v, u), Cross(Curl(u), Curl(v)) + 0.2 * u * v)
    print('> input       := {0}'.format(a))

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

    expr, info = initialize_weak_form(expr, dim=DIM)
    print('> temp form   := {0}'.format(expr))

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

    print('')
Beispiel #8
0
def test_3d_block_4():
    print('============== test_3d_block_4 ================')
    """Alfven operator."""
    x, y, z = symbols('x y z')

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

    bx = Constant('bx')
    by = Constant('by')
    bz = Constant('bz')
    b = Tuple(bx, by, bz)

    c0 = Constant('c0')
    c1 = Constant('c1')
    c2 = Constant('c2')

    a = Lambda((x, y, z, v, u),
               (c0 * Dot(u, v) + c1 * Div(u) * Div(v) +
                c2 * Dot(Curl(Cross(b, u)), Curl(Cross(b, v)))))
    print('> input       := {0}'.format(a))

    # ...  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)

    Vx = TensorFemSpace(V1, V2, V3)
    Vy = TensorFemSpace(V1, V2, V3)
    Vz = TensorFemSpace(V1, V2, V3)

    V = VectorFemSpace(Vx, Vy, Vz)
    # ...

    # ... create a glt symbol from a string without evaluation
    expr = glt_symbol(a, space=V)
    print('> glt symbol  := {0}'.format(expr))
    # ...

    # ...
    symbol_f90 = compile_symbol('symbol_block_4',
                                a,
                                V,
                                d_constants={
                                    'bx': 0.1,
                                    'by': 1.,
                                    'bz': 0.2,
                                    'c0': 0.1,
                                    'c1': 1.,
                                    'c2': 1.
                                },
                                backend='fortran')
    # ...

    # ... example of symbol evaluation
    t1 = linspace(-pi, pi, ne1 + 1)
    t2 = linspace(-pi, pi, ne2 + 1)
    t3 = linspace(-pi, pi, ne3 + 1)
    x1 = linspace(0., 1., ne1 + 1)
    x2 = linspace(0., 1., ne2 + 1)
    x3 = linspace(0., 1., ne3 + 1)
    e = zeros((3, 3, ne1 + 1, ne2 + 1, ne3 + 1), order='F')
    symbol_f90(x1, x2, x3, t1, t2, t3, e)
    # ...

    print('')
Beispiel #9
0
def test_3d_block_3():
    print('============== test_3d_block_3 ================')

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

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

    b = Tuple(1.0, 0., 0.)

    a = Lambda((x, y, z, v, u),
               Dot(Curl(Cross(b, u)), Curl(Cross(b, v))) + 0.2 * Dot(u, v))
    print('> input       := {0}'.format(a))

    # ...  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)

    Vx = TensorFemSpace(V1, V2, V3)
    Vy = TensorFemSpace(V1, V2, V3)
    Vz = TensorFemSpace(V1, V2, V3)

    V = VectorFemSpace(Vx, Vy, Vz)
    # ...

    # ... create a glt symbol from a string without evaluation
    expr = glt_symbol(a, space=V)
    print('> glt symbol  := {0}'.format(expr))
    # ...

    # ...
    symbol_f90 = compile_symbol('symbol_block_3', a, V, backend='fortran')
    # ...

    # ... example of symbol evaluation
    t1 = linspace(-pi, pi, ne1 + 1)
    t2 = linspace(-pi, pi, ne2 + 1)
    t3 = linspace(-pi, pi, ne3 + 1)
    x1 = linspace(0., 1., ne1 + 1)
    x2 = linspace(0., 1., ne2 + 1)
    x3 = linspace(0., 1., ne3 + 1)
    e = zeros((3, 3, ne1 + 1, ne2 + 1, ne3 + 1), order='F')
    symbol_f90(x1, x2, x3, t1, t2, t3, e)
    # ...

    print('')