예제 #1
0
def test_bilinear_form_2d_4():

    domain = Domain('Omega', dim=2)
    B1 = Boundary(r'\Gamma_1', domain)

    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)

    V = VectorFunctionSpace('V', domain)

    u, u1, u2 = [element_of(V, name=i) for i in ['u', 'u1', 'u2']]
    v, v1, v2 = [element_of(V, name=i) for i in ['v', 'v1', 'v2']]

    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(B1, expr)
    # ...
    a = BilinearForm((u, v), int_0(dot(u, v)))
    assert (a.is_symmetric)
    # ...

    # ...
    a = BilinearForm((u, v), int_0(inner(grad(u), grad(v))))
    assert (a.is_symmetric)
예제 #2
0
def test_terminal_expr_bilinear_2d_2():

    domain = Domain('Omega', dim=2)
    B1 = Boundary(r'\Gamma_1', domain)

    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)
    nn = NormalVector('nn')

    V = VectorFunctionSpace('V', domain)

    u, u1, u2 = [element_of(V, name=i) for i in ['u', 'u1', 'u2']]
    v, v1, v2 = [element_of(V, name=i) for i in ['v', 'v1', 'v2']]

    # ...
    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(B1, expr)

    a = BilinearForm((u, v), int_0(dot(u, v)))
    print(TerminalExpr(a))
    print('')

    # ...
    a = BilinearForm((u, v), int_0(inner(grad(u), grad(v))))
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a = BilinearForm((u, v), int_0(dot(u, v) + inner(grad(u), grad(v))))
    print(TerminalExpr(a))
    print('')
예제 #3
0
def test_terminal_expr_bilinear_3d_1():

    domain = Domain('Omega', dim=3)
    M = Mapping('M', 3)

    mapped_domain = M(domain)

    V = ScalarFunctionSpace('V', domain)
    VM = ScalarFunctionSpace('VM', mapped_domain)

    u, v = elements_of(V, names='u,v')
    um, vm = elements_of(VM, names='u,v')

    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(mapped_domain, expr)

    J = M.det_jacobian
    det = dx1(M[0])*dx2(M[1])*dx3(M[2]) - dx1(M[0])*dx2(M[2])*dx3(M[1]) - dx1(M[1])*dx2(M[0])*dx3(M[2])\
        + dx1(M[1])*dx2(M[2])*dx3(M[0]) + dx1(M[2])*dx2(M[0])*dx3(M[1]) - dx1(M[2])*dx2(M[1])*dx3(M[0])

    a1 = BilinearForm((u, v), int_0(dot(grad(u), grad(v))))
    a2 = BilinearForm((um, vm), int_1(dot(grad(um), grad(vm))))
    a3 = BilinearForm((u, v), int_0(J * dot(grad(u), grad(v))))

    e1 = TerminalExpr(a1)
    e2 = TerminalExpr(a2)
    e3 = TerminalExpr(a3)

    assert e1[0].expr == dx1(u) * dx1(v) + dx2(u) * dx2(v) + dx3(u) * dx3(v)
    assert e2[0].expr == dx(um) * dx(vm) + dy(um) * dy(vm) + dz(um) * dz(vm)
    assert e3[0].expr.factor() == (dx1(u) * dx1(v) + dx2(u) * dx2(v) +
                                   dx3(u) * dx3(v)) * det
예제 #4
0
def test_linearize_form_2d_4():
    domain = Domain('Omega', dim=2)
    Gamma_N = Boundary(r'\Gamma_N', domain)

    x, y = domain.coordinates

    V = ScalarFunctionSpace('V', domain)

    v = element_of(V, name='v')
    u = element_of(V, name='u')
    du = element_of(V, name='du')

    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(Gamma_N, expr)

    #    g = Matrix((cos(pi*x)*sin(pi*y),
    #              sin(pi*x)*cos(pi*y)))

    expr = dot(grad(v), grad(u)) - 4. * exp(-u) * v  # + v*trace_1(g, Gamma_N)

    l = LinearForm(v, int_0(expr))

    # linearising l around u, using du
    a = linearize(l, u, trials=du)

    assert a(du, v) == int_0(dot(grad(v), grad(du)) + 4. * exp(-u) * du * v)
예제 #5
0
def test_terminal_expr_linear_2d_2():

    domain = Domain('Omega', dim=2)
    B1 = Boundary(r'\Gamma_1', domain)

    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)

    V = VectorFunctionSpace('V', domain)

    u, u1, u2 = [element_of(V, name=i) for i in ['u', 'u1', 'u2']]
    v, v1, v2 = [element_of(V, name=i) for i in ['v', 'v1', 'v2']]

    # ...
    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(B1, expr)

    g = Matrix((x, y))
    l = LinearForm(v, int_0(dot(g, v)))
    print(TerminalExpr(l))
    print('')
    # ...

    # ...
    g = Matrix((x, y))
    l = LinearForm(v, int_0(dot(g, v) + div(v)))
    print(TerminalExpr(l))
    print('')
예제 #6
0
def test_interface_2d_1():

    # ...
    def two_patches():

        from sympde.topology import InteriorDomain
        from sympde.topology import Connectivity, Interface

        A = Square('A')
        B = Square('B')

        A = A.interior
        B = B.interior

        connectivity = Connectivity()

        bnd_A_1 = Boundary(r'\Gamma_1', A, axis=0, ext=-1)
        bnd_A_2 = Boundary(r'\Gamma_2', A, axis=0, ext=1)
        bnd_A_3 = Boundary(r'\Gamma_3', A, axis=1, ext=-1)
        bnd_A_4 = Boundary(r'\Gamma_4', A, axis=1, ext=1)

        bnd_B_1 = Boundary(r'\Gamma_1', B, axis=0, ext=-1)
        bnd_B_2 = Boundary(r'\Gamma_2', B, axis=0, ext=1)
        bnd_B_3 = Boundary(r'\Gamma_3', B, axis=1, ext=-1)
        bnd_B_4 = Boundary(r'\Gamma_4', B, axis=1, ext=1)

        connectivity['I'] = Interface('I', bnd_A_2, bnd_B_1)

        Omega = Domain('Omega',
                       interiors=[A, B],
                       boundaries=[
                           bnd_A_1, bnd_A_2, bnd_A_3, bnd_A_4, bnd_B_1,
                           bnd_B_2, bnd_B_3, bnd_B_4
                       ],
                       connectivity=connectivity)

        return Omega

    # ...

    # create a domain with an interface
    domain = two_patches()
    interfaces = domain.interfaces

    V = ScalarFunctionSpace('V', domain)

    u, v = elements_of(V, names='u, v')

    print(integral(interfaces, u * v))

    expr = integral(domain, dot(grad(v), grad(u)))
    expr += integral(interfaces, -avg(Dn(u)) * jump(v) + avg(Dn(v)) * jump(u))
    a = BilinearForm((u, v), expr)
    print(a)
예제 #7
0
def test_interface_integral_1():

    # ...
    A = Square('A')
    B = Square('B')

    domain = A.join(B,
                    name='domain',
                    bnd_minus=A.get_boundary(axis=0, ext=1),
                    bnd_plus=B.get_boundary(axis=0, ext=-1))
    # ...

    x, y = domain.coordinates

    V = ScalarFunctionSpace('V', domain, kind=None)
    assert (V.is_broken)

    u, v = elements_of(V, names='u, v')

    # ...
    I = domain.interfaces
    # ...

    #    expr = minus(Dn(u))
    #    print(expr)
    #    import sys; sys.exit(0)

    # ... bilinear forms
    #    a = BilinearForm((u,v), integral(domain, u*v))
    #    a = BilinearForm((u,v), integral(domain, dot(grad(u),grad(v))))
    #    a = BilinearForm((u,v), integral(I, jump(u) * jump(v)))
    #    a = BilinearForm((u,v), integral(I, jump(Dn(u)) * jump(v)))

    #    a = BilinearForm((u,v), integral(domain, dot(grad(u),grad(v)))
    #                          + integral(I,      jump(u) * jump(v)))

    # Nitsch
    kappa = Constant('kappa')
    expr_I = (-jump(u) * jump(Dn(v)) + kappa * jump(u) * jump(v) +
              plus(Dn(u)) * minus(v) + minus(Dn(u)) * plus(v))
    a = BilinearForm(
        (u, v),
        integral(domain, dot(grad(u), grad(v))) + integral(I, expr_I))

    #    # TODO BUG
    #    bnd_A = A.get_boundary(axis=0, ext=1)
    #
    #    a = BilinearForm((u,v), integral(domain, dot(grad(u),grad(v)))
    #                          + integral(I,      jump(u) * jump(v))
    #                          + integral(bnd_A,      dx(u)*v))

    expr = TerminalExpr(a)
    print(expr)
예제 #8
0
def test_interface_integral_3():

    # ...
    A = Square('A')
    B = Square('B')
    C = Square('C')

    AB = A.join(B,
                name='AB',
                bnd_minus=A.get_boundary(axis=0, ext=1),
                bnd_plus=B.get_boundary(axis=0, ext=-1))

    domain = AB.join(C,
                     name='domain',
                     bnd_minus=B.get_boundary(axis=0, ext=1),
                     bnd_plus=C.get_boundary(axis=0, ext=-1))
    # ...

    x, y = domain.coordinates

    V = ScalarFunctionSpace('V', domain, kind=None)
    assert (V.is_broken)

    u, v = elements_of(V, names='u, v')

    # ...
    I = domain.interfaces
    #    print(I)
    #    print(integral(I, jump(u) * jump(v)))

    #    a = BilinearForm((u,v), integral(domain, u*v))
    #    a = BilinearForm((u,v), integral(domain, dot(grad(u),grad(v))))
    #    a = BilinearForm((u,v), integral(I, jump(u) * jump(v)))

    a = BilinearForm((u, v),
                     integral(domain, dot(grad(u), grad(v))) +
                     integral(I,
                              jump(u) * jump(v)))

    expr = TerminalExpr(a)
    print(expr)
    # ...

    # ... linear forms
    b = LinearForm(
        v,
        integral(domain,
                 sin(x + y) * v) + integral(I,
                                            cos(x + y) * jump(v)))

    expr = TerminalExpr(b)
    print(expr)
예제 #9
0
def test_bilinear_form_2d_2():

    domain = Domain('Omega', dim=2)
    B1 = Boundary(r'\Gamma_1', domain)

    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)

    V = VectorFunctionSpace('V', domain)

    u, u1, u2 = [element_of(V, name=i) for i in ['u', 'u1', 'u2']]
    v, v1, v2 = [element_of(V, name=i) for i in ['v', 'v1', 'v2']]

    # ...
    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(B1, expr)

    a = BilinearForm((u, v), int_0(dot(u, v)))

    assert (a.domain == domain.interior)
    assert (a(u1, v1) == int_0(dot(u1, v1)))
    # ...

    # ...
    a = BilinearForm((u, v), int_0(dot(u, v) + inner(grad(u), grad(v))))

    assert (a.domain == domain.interior)
    assert (a(u1, v1) == int_0(dot(u1, v1)) + int_0(inner(grad(u1), grad(v1))))
    # ...

    # ...
    a1 = BilinearForm((u1, v1), int_0(dot(u1, v1)))
    a = BilinearForm((u, v), a1(u, v))

    assert (a.domain == domain.interior)
    assert (a(u2, v2) == int_0(dot(u2, v2)))
    # ...

    # ...
    a1 = BilinearForm((u1, v1), int_0(dot(u1, v1)))
    a2 = BilinearForm((u2, v2), int_0(inner(grad(u2), grad(v2))))
    a = BilinearForm((u, v), a1(u, v) + kappa * a2(u, v))

    assert (a.domain == domain.interior)
    assert (a(u,
              v) == int_0(dot(u, v)) + int_0(kappa * inner(grad(u), grad(v))))
예제 #10
0
def test_functional_2d_1():

    domain = Domain('Omega', dim=2)
    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)

    V = ScalarFunctionSpace('V', domain)
    F = element_of(V, name='F')

    int_0 = lambda expr: integral(domain, expr)

    # ...
    expr = x * y
    a = Functional(int_0(expr), domain)

    print(a)
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    expr = F - cos(2 * pi * x) * cos(3 * pi * y)
    expr = dot(grad(expr), grad(expr))
    a = Functional(int_0(expr), domain)

    print(a)
    print(TerminalExpr(a))
    print('')
예제 #11
0
def test_user_function_2d_1():

    domain = Domain('Omega', dim=2)
    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)

    # right hand side
    f = Function('f')

    V = ScalarFunctionSpace('V', domain)

    u, v = [element_of(V, name=i) for i in ['u', 'v']]

    int_0 = lambda expr: integral(domain, expr)

    # ...
    expr = dot(grad(u), grad(v)) + f(x, y) * u * v
    a = BilinearForm((v, u), int_0(expr))

    print(a)
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    expr = f(x, y) * v
    l = LinearForm(v, int_0(expr))

    print(l)
    print(TerminalExpr(l))
    print('')
예제 #12
0
def test_linearize_form_2d_3():
    """steady Euler equation."""
    domain = Domain('Omega', dim=2)

    U = VectorFunctionSpace('U', domain)
    W = ScalarFunctionSpace('W', domain)

    # Test functions
    v = element_of(U, name='v')
    phi = element_of(W, name='phi')
    q = element_of(W, name='q')

    # Steady-state fields
    U_0 = element_of(U, name='U_0')
    Rho_0 = element_of(W, name='Rho_0')
    P_0 = element_of(W, name='P_0')

    # Trial functions (displacements from steady-state)
    d_u = element_of(U, name='d_u')
    d_rho = element_of(W, name='d_rho')
    d_p = element_of(W, name='d_p')

    # Shortcut
    int_0 = lambda expr: integral(domain, expr)

    # The Euler equations are a system of three non-linear equations; for each of
    # them we create a linear form in the test functions (phi, v, q) respectively.
    e1 = div(Rho_0 * U_0)
    l1 = LinearForm(phi, int_0(e1 * phi))

    e2 = Rho_0 * convect(U_0, U_0) + grad(P_0)
    l2 = LinearForm(v, int_0(dot(e2, v)))

    e3 = div(P_0 * U_0)
    l3 = LinearForm(q, int_0(e3 * q))
    # ...

    # Linearize l1, l2 and l3 separately
    a1 = linearize(l1, fields=[Rho_0, U_0], trials=[d_rho, d_u])
    a2 = linearize(l2, fields=[Rho_0, U_0, P_0], trials=[d_rho, d_u, d_p])
    a3 = linearize(l3, fields=[U_0, P_0], trials=[d_u, d_p])

    # Check individual bilinear forms
    d_e1 = div(U_0 * d_rho + Rho_0 * d_u)
    d_e2 = d_rho * convect(U_0, U_0) + \
           Rho_0 * convect(d_u, U_0) + \
           Rho_0 * convect(U_0, d_u) + grad(d_p)
    d_e3 = div(d_p * U_0 + P_0 * d_u)

    assert a1([d_rho, d_u], phi) == int_0(d_e1 * phi)
    assert a2([d_rho, d_u, d_p], v) == int_0(dot(d_e2, v))
    assert a3([d_u, d_p], q) == int_0(d_e3 * q)

    # Linearize linear form of system: l = l1 + l2 + l3
    l = LinearForm((phi, v, q), l1(phi) + l2(v) + l3(q))
    a = linearize(l, fields=[Rho_0, U_0, P_0], trials=[d_rho, d_u, d_p])

    # Check composite linear form
    assert a([d_rho, d_u, d_p], [phi, v, q]) == \
            int_0(d_e1 * phi + dot(d_e2, v) + d_e3 * q)
예제 #13
0
def test_tensorize_2d_1_mapping():

    DIM = 2

    M = Mapping('Map', DIM)

    domain = Domain('Omega', dim=DIM)
    B1 = Boundary(r'\Gamma_1', domain)

    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)

    V = ScalarFunctionSpace('V', domain)
    u, v = elements_of(V, names='u, v')

    int_0 = lambda expr: integral(domain, expr)
    # ...
    #    a = BilinearForm((u,v), u*v)
    #    a = BilinearForm((u,v), mu*u*v + dot(grad(u),grad(v)))
    a = BilinearForm((u, v), int_0(dot(grad(u), grad(v))))
    #    a = BilinearForm((u,v), dx(u)*v)
    #    a = BilinearForm((u,v), laplace(u)*laplace(v))

    expr = TensorExpr(a, mapping=M)
    print(expr)
예제 #14
0
def test_linear_form_2d_2():

    domain = Domain('Omega', dim=2)
    B1 = Boundary(r'\Gamma_1', domain)

    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)

    V = VectorFunctionSpace('V', domain)

    u, u1, u2 = [element_of(V, name=i) for i in ['u', 'u1', 'u2']]
    v, v1, v2 = [element_of(V, name=i) for i in ['v', 'v1', 'v2']]

    # ...
    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(B1, expr)

    g = Matrix((x, y))
    l = LinearForm(v, int_0(dot(g, v)))

    assert (l.domain == domain.interior)
    assert (l(v1) == int_0(dot(g, v1)))
    # ...

    # ...
    g = Matrix((x, y))
    l1 = LinearForm(v1, int_0(dot(g, v1)))
    l = LinearForm(v, l1(v))

    assert (l.domain == domain.interior)
    assert (l(u1) == int_0(dot(g, u1)))
    # ...

    # ...
    g1 = Matrix((x, 0))
    g2 = Matrix((0, y))
    l1 = LinearForm(v1, int_0(dot(v1, g1)))
    l2 = LinearForm(v2, int_0(dot(v2, g2)))

    l = LinearForm(v, l1(v) + l2(v))

    assert (l.domain == domain.interior)
    assert (l(u) == int_0(dot(u, g1)) + int_0(dot(u, g2)))
예제 #15
0
def test_interface_integral_2():

    # ...
    A = Square('A')
    B = Square('B')

    domain = A.join(B,
                    name='domain',
                    bnd_minus=A.get_boundary(axis=0, ext=1),
                    bnd_plus=B.get_boundary(axis=0, ext=-1))
    # ...

    x, y = domain.coordinates

    V = ScalarFunctionSpace('V', domain, kind=None)
    assert (V.is_broken)

    u, u1, u2, u3 = elements_of(V, names='u, u1, u2, u3')
    v, v1, v2, v3 = elements_of(V, names='v, v1, v2, v3')

    # ...
    I = domain.interfaces

    a = BilinearForm((u, v), integral(domain, dot(grad(u), grad(v))))
    b = BilinearForm((u, v), integral(I, jump(u) * jump(v)))

    A = BilinearForm(((u1, u2), (v1, v2)),
                     a(u1, v1) + a(u2, v2) + b(u1, v1) + b(u2, v2) + b(u1, v2))
    B = BilinearForm(
        ((u1, u2, u3), (v1, v2, v3)),
        a(u1, v1) + a(u2, v2) + a(u3, v3) + b(u1, v1) + b(u2, v2) + b(u1, v2))

    print(TerminalExpr(A))
    print(TerminalExpr(B))
    # ...

    # ... linear forms
    b = LinearForm(v, integral(I, jump(v)))

    b = LinearForm((v1, v2), b(v1) + b(v2))
    expr = TerminalExpr(b)
    print(expr)
예제 #16
0
def test_terminal_expr_linear_2d_5(boundary=[r'\Gamma_1', r'\Gamma_3']):

    # ... abstract model
    domain = Square()

    V = ScalarFunctionSpace('V', domain)

    B_neumann = [domain.get_boundary(i) for i in boundary]
    if len(B_neumann) == 1:
        B_neumann = B_neumann[0]

    else:
        B_neumann = Union(*B_neumann)

    x, y = domain.coordinates
    nn = NormalVector('nn')

    F = element_of(V, name='F')

    v = element_of(V, name='v')
    u = element_of(V, name='u')

    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(B_neumann, expr)

    expr = dot(grad(v), grad(u))
    a = BilinearForm((v, u), int_0(expr))

    solution = cos(0.5 * pi * x) * cos(0.5 * pi * y)
    f = (1. / 2.) * pi**2 * solution

    expr = f * v
    l0 = LinearForm(v, int_0(expr))

    expr = v * dot(grad(solution), nn)
    l_B_neumann = LinearForm(v, int_1(expr))

    expr = l0(v) + l_B_neumann(v)
    l = LinearForm(v, expr)

    print(TerminalExpr(l))
    print('')
예제 #17
0
def test_linearize_form_2d_1():
    domain = Domain('Omega', dim=2)

    V = ScalarFunctionSpace('V', domain)
    W = VectorFunctionSpace('W', domain)

    v, F, u = elements_of(V, names='v, F, u')
    w, G, m = elements_of(W, names='w, G, m')

    int_0 = lambda expr: integral(domain, expr)

    # ...
    l = LinearForm(v, int_0(F**2 * v))
    a = linearize(l, F, trials=u)
    assert a(u, v) == int_0(2 * F * u * v)
    # ...

    # ...
    l = LinearForm(v, int_0(dot(grad(F), grad(F)) * v))
    a = linearize(l, F, trials=u)
    assert a(u, v) == int_0(2 * dot(grad(F), grad(u)) * v)
    # ...

    # ...
    l = LinearForm(v, int_0(exp(-F) * v))
    a = linearize(l, F, trials=u)
    assert a(u, v) == int_0(-exp(-F) * u * v)
    # ...

    # ...
    l = LinearForm(v, int_0(cos(F) * v))
    a = linearize(l, F, trials=u)
    assert a(u, v) == int_0(-sin(F) * u * v)
    # ...

    # ...
    l = LinearForm(v, int_0(cos(F**2) * v))
    a = linearize(l, F, trials=u)
    assert a(u, v) == int_0(-2 * F * sin(F**2) * u * v)
    # ...

    # ...
    l = LinearForm(v, int_0(F**2 * dot(grad(F), grad(v))))
    a = linearize(l, F, trials=u)
    assert a(u, v) == int_0(2 * F * u * dot(grad(F), grad(v)) +
                            F**2 * dot(grad(u), grad(v)))
    # ...

    # ...
    l = LinearForm(w, int_0(dot(rot(G), grad(G)) * w))
    a = linearize(l, G, trials=m)
    assert a(m, w) == int_0((dot(rot(m), grad(G)) + dot(rot(G), grad(m))) * w)
예제 #18
0
def test_terminal_expr_linear_2d_3():

    domain = Square()
    B = domain.boundary

    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)
    nn = NormalVector('nn')

    V = ScalarFunctionSpace('V', domain)

    u, u1, u2 = [element_of(V, name=i) for i in ['u', 'u1', 'u2']]
    v, v1, v2 = [element_of(V, name=i) for i in ['v', 'v1', 'v2']]

    # ...
    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(B, expr)

    l = LinearForm(v, int_1(dot(grad(v), nn)))
    print(TerminalExpr(l))
    print('')
예제 #19
0
def test_tensorize_2d_2():

    domain = Domain('Omega', dim=2)

    V = VectorFunctionSpace('V', domain)
    u, v = elements_of(V, names='u, v')

    int_0 = lambda expr: integral(domain , expr)
    # ...
#    a = BilinearForm((u,v), dot(u,v))
    a = BilinearForm((u,v), int_0(curl(u)*curl(v) + div(u)*div(v)))

    expr = TensorExpr(a, domain=domain)
    print(expr)
예제 #20
0
def test_tensorize_2d_3():

    domain = Domain('Omega', dim=2)

    V = ScalarFunctionSpace('V', domain)
    u, v = elements_of(V, names='u,v')

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

    expr = integral(domain, dot(b, grad(v)) * dot(b, grad(u)))
    a = BilinearForm((u, v), expr)

    print(TensorExpr(a))
    print('')
예제 #21
0
def test_tensorize_2d_2_mapping():

    DIM = 2
    M = Mapping('M', DIM)
    domain = Domain('Omega', dim=DIM)

    V = VectorFunctionSpace('V', domain)
    u, v = elements_of(V, names='u, v')

    c = Constant('c')

    int_0 = lambda expr: integral(domain, expr)

    a = BilinearForm((u, v), int_0(c * div(v) * div(u) + curl(v) * curl(u)))
    expr = TensorExpr(a, mapping=M)
    print(expr)
예제 #22
0
def test_linearize_form_2d_2():
    domain = Domain('Omega', dim=2)

    V = ScalarFunctionSpace('V', domain)

    v, F, u = elements_of(V, names='v, F, u')

    int_0 = lambda expr: integral(domain, expr)

    # ...
    l1 = LinearForm(v, int_0(F**2 * v))
    l = LinearForm(v, l1(v))

    a = linearize(l, F, trials=u)

    expected = linearize(l1, F, trials=u)
    assert a == expected
예제 #23
0
def test_area_2d_1():

    domain = Domain('Omega', dim=2)
    x, y = domain.coordinates

    mu = Constant('mu', is_real=True)

    e = ElementDomain(domain)
    area = Area(e)

    V = ScalarFunctionSpace('V', domain)

    u, v = [element_of(V, name=i) for i in ['u', 'v']]

    int_0 = lambda expr: integral(domain, expr)

    # ...
    a = BilinearForm((v, u), int_0(area * u * v))
    print(TerminalExpr(a))
예제 #24
0
def test_tensorize_2d_2():

    domain = Domain('Omega', dim=2)
    B1 = Boundary(r'\Gamma_1', domain)

    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)

    V = VectorFunctionSpace('V', domain)
    u, v = elements_of(V, names='u, v')

    int_0 = lambda expr: integral(domain, expr)
    # ...
    #    a = BilinearForm((u,v), dot(u,v))
    a = BilinearForm((u, v), int_0(curl(u) * curl(v) + div(u) * div(v)))

    expr = TensorExpr(a)
    print(expr)
예제 #25
0
def test_tensorize_2d_1():

    domain = Domain('Omega', dim=2)

    mu    = Constant('mu'   , is_real=True)

    V = ScalarFunctionSpace('V', domain)
    u, v = elements_of(V, names='u, v')

    int_0 = lambda expr: integral(domain , expr)

    # ...
#    a = BilinearForm((u,v), u*v)
    a = BilinearForm((u,v), int_0(mu*u*v + dot(grad(u),grad(v))))
#    a = BilinearForm((u,v), dot(grad(u),grad(v)))
#    a = BilinearForm((u,v), dx(u)*v)
#    a = BilinearForm((u,v), laplace(u)*laplace(v))

    expr = TensorExpr(a, domain=domain)
    print(expr)
예제 #26
0
def test_terminal_expr_linear_2d_4():

    D1 = InteriorDomain('D1', dim=2)
    D2 = InteriorDomain('D2', dim=2)
    domain = Union(D1, D2)

    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)

    V = ScalarFunctionSpace('V', domain)

    u, u1, u2 = [element_of(V, name=i) for i in ['u', 'u1', 'u2']]
    v, v1, v2 = [element_of(V, name=i) for i in ['v', 'v1', 'v2']]

    # ...
    int_0 = lambda expr: integral(domain, expr)

    l = LinearForm(v, int_0(x * y * v))
    print(TerminalExpr(l))
    print('')
예제 #27
0
def test_terminal_expr_bilinear_2d_4():

    domain = Domain('Omega', dim=2)

    x, y = domain.coordinates

    V = VectorFunctionSpace('V', domain)
    W = ScalarFunctionSpace('W', domain)

    v = element_of(V, name='v')
    u = element_of(V, name='u')
    p = element_of(W, name='p')
    q = element_of(W, name='q')

    int_0 = lambda expr: integral(domain, expr)

    # stokes
    a = BilinearForm((u, v), int_0(inner(grad(v), grad(u))))
    b = BilinearForm((v, p), int_0(div(v) * p))
    a = BilinearForm(((u, p), (v, q)), a(v, u) - b(v, p) + b(u, q))

    print(TerminalExpr(a))
    print('')
예제 #28
0
def test_terminal_expr_bilinear_2d_3():

    domain = Square()

    V = ScalarFunctionSpace('V', domain)

    B = domain.boundary

    v = element_of(V, name='v')
    u = element_of(V, name='u')

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)
    nn = NormalVector('nn')

    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(B, expr)

    # nitsche
    a0 = BilinearForm((u, v), int_0(dot(grad(v), grad(u))))

    a_B = BilinearForm((u,v), int_1(-u*dot(grad(v), nn) \
                              -v*dot(grad(u), nn) \
                              +kappa*u*v))

    a = BilinearForm((u, v), a0(u, v) + a_B(u, v))

    print(TerminalExpr(a))
    print('')

    a = BilinearForm(
        (u, v),
        int_0(u * v + dot(grad(u), grad(v))) + int_1(v * dot(grad(u), nn)))
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a = BilinearForm((u, v), int_0(u * v))
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a1 = BilinearForm((u, v), int_0(u * v))
    a = BilinearForm((u, v), a1(u, v))
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a1 = BilinearForm((u, v), int_0(u * v))
    a2 = BilinearForm((u, v), int_0(dot(grad(u), grad(v))))
    a = BilinearForm((u, v), a1(u, v) + a2(u, v))
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a1 = BilinearForm((u, v), int_0(u * v))
    a2 = BilinearForm((u, v), int_0(dot(grad(u), grad(v))))
    a = BilinearForm((u, v), a1(u, v) + kappa * a2(u, v))
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a1 = BilinearForm((u, v), int_0(u * v))
    a2 = BilinearForm((u, v), int_0(dot(grad(u), grad(v))))
    a3 = BilinearForm((u, v), int_1(v * dot(grad(u), nn)))
    a = BilinearForm((u, v), a1(u, v) + kappa * a2(u, v) + mu * a3(u, v))
    print(TerminalExpr(a))
    print('')
예제 #29
0
def test_terminal_expr_linear_2d_1():

    domain = Domain('Omega', dim=2)
    B1 = Boundary(r'\Gamma_1', domain)

    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)
    nn = NormalVector('nn')

    V = ScalarFunctionSpace('V', domain)

    u, u1, u2 = [element_of(V, name=i) for i in ['u', 'u1', 'u2']]
    v, v1, v2 = [element_of(V, name=i) for i in ['v', 'v1', 'v2']]

    # ...
    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(B1, expr)

    l = LinearForm(v, int_0(x * y * v))

    print(TerminalExpr(l))
    print('')
    # ...

    # ...
    l = LinearForm(v, int_0(x * y * v + v))
    print(TerminalExpr(l))
    print('')
    # ...

    # ...
    g = Matrix((x**2, y**2))
    l = LinearForm(v, int_1(v * dot(g, nn)))
    print(TerminalExpr(l))
    print('')
    # ...

    # ...
    g = Matrix((x**2, y**2))
    l = LinearForm(v, int_1(v * dot(g, nn)) + int_0(x * y * v))
    print(TerminalExpr(l))
    print('')
    # ...

    # ...
    l1 = LinearForm(v1, int_0(x * y * v1))
    l = LinearForm(v, l1(v))
    print(TerminalExpr(l))
    print('')
    # ...

    # ...
    g = Matrix((x, y))
    l1 = LinearForm(v1, int_0(x * y * v1))
    l2 = LinearForm(v2, int_0(dot(grad(v2), g)))

    l = LinearForm(v, l1(v) + l2(v))
    print(TerminalExpr(l))
    print('')
    # ...

    # ...
    l1 = LinearForm(v1, int_0(x * y * v1))
    l2 = LinearForm(v1, int_0(v1))
    l = LinearForm(v, l1(v) + kappa * l2(v))
    print(TerminalExpr(l))
    print('')
    # ...

    # ...
    g = Matrix((x**2, y**2))
    l1 = LinearForm(v1, int_0(x * y * v1))
    l2 = LinearForm(v1, int_0(v1))
    l3 = LinearForm(v, int_1(v * dot(g, nn)))
    l = LinearForm(v, l1(v) + kappa * l2(v) + mu * l3(v))
    print(TerminalExpr(l))
    print('')
예제 #30
0
def test_terminal_expr_bilinear_2d_1():

    domain = Domain('Omega', dim=2)
    B1 = Boundary(r'\Gamma_1', domain)

    x, y = domain.coordinates

    kappa = Constant('kappa', is_real=True)
    mu = Constant('mu', is_real=True)
    eps = Constant('eps', real=True)
    nn = NormalVector('nn')

    V = ScalarFunctionSpace('V', domain)

    u, u1, u2 = [element_of(V, name=i) for i in ['u', 'u1', 'u2']]
    v, v1, v2 = [element_of(V, name=i) for i in ['v', 'v1', 'v2']]

    # ...

    int_0 = lambda expr: integral(domain, expr)
    int_1 = lambda expr: integral(B1, expr)

    a = BilinearForm((u, v), int_0(u * v))
    print(a)
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a = BilinearForm((u, v), int_0(dot(grad(u), grad(v))))
    print(a)
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a = BilinearForm((u, v), int_0(u * v + dot(grad(u), grad(v))))
    print(a)
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a = BilinearForm(
        (u, v),
        int_0(u * v + dot(grad(u), grad(v))) + int_1(v * dot(grad(u), nn)))
    print(a)
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a = BilinearForm(((u1, u2), (v1, v2)), int_0(u1 * v1 + u2 * v2))
    print(a)
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a1 = BilinearForm((u1, v1), int_0(u1 * v1))
    a = BilinearForm((u, v), a1(u, v))
    print(a)
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a1 = BilinearForm((u1, v1), int_0(u1 * v1))
    a2 = BilinearForm((u2, v2), int_0(dot(grad(u2), grad(v2))))
    a = BilinearForm((u, v), a1(u, v) + a2(u, v))
    print(a)
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a1 = BilinearForm((u1, v1), int_0(u1 * v1))
    a2 = BilinearForm((u2, v2), int_0(dot(grad(u2), grad(v2))))
    a = BilinearForm((u, v), a1(u, v) + kappa * a2(u, v))
    print(a)
    print(TerminalExpr(a))
    print('')
    # ...

    # ...
    a1 = BilinearForm((u1, v1), int_0(u1 * v1))
    a2 = BilinearForm((u2, v2), int_0(dot(grad(u2), grad(v2))))
    a3 = BilinearForm((u, v), int_1(v * dot(grad(u), nn)))
    a = BilinearForm((u, v), a1(u, v) + kappa * a2(u, v) + mu * a3(u, v))
    print(a)
    print(TerminalExpr(a))
    print('')
    # ...

    # ... Poisson with Nitsch method
    a0 = BilinearForm((u, v), int_0(dot(grad(u), grad(v))))
    a_B1 = BilinearForm((u, v),
                        int_1(-kappa * u * dot(grad(v), nn) -
                              v * dot(grad(u), nn) + u * v / eps))
    a = BilinearForm((u, v), a0(u, v) + a_B1(u, v))
    print(a)
    print(TerminalExpr(a))
    print('')