Example #1
0
def test_domain_join_square():

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

    # ...
    AB_bnd_minus = A.get_boundary(axis=0, ext=1)
    AB_bnd_plus  = B.get_boundary(axis=0, ext=-1)

    AB = A.join(B, name = 'AB',
               bnd_minus = AB_bnd_minus,
               bnd_plus  = AB_bnd_plus)

    print(AB)
    assert AB.interior   == Union(A.interior, B.interior)
    assert AB.interfaces == Interface('A|B', AB_bnd_minus, AB_bnd_plus)
    print(AB.connectivity)
    # ...
    BC_bnd_minus = B.get_boundary(axis=0, ext=1)
    BC_bnd_plus  = C.get_boundary(axis=0, ext=-1)

    ABC = AB.join(C, name = 'ABC',
               bnd_minus = BC_bnd_minus,
               bnd_plus  = BC_bnd_plus)

    print(ABC)
    assert ABC.interior == Union(A.interior, B.interior, C.interior)
    assert ABC.interfaces == Union(Interface('A|B', AB_bnd_minus, AB_bnd_plus),Interface('B|C', BC_bnd_minus, BC_bnd_plus))
    print(list(ABC.connectivity.items()))
    print('')
Example #2
0
def test_boundary_2():
    Omega_1 = InteriorDomain('Omega_1', dim=2)

    Gamma_1 = Boundary('Gamma_1', Omega_1)
    Gamma_2 = Boundary('Gamma_2', Omega_1)
    Gamma_3 = Boundary('Gamma_3', Omega_1)

    Omega = Domain('Omega',
                   interiors=[Omega_1],
                   boundaries=[Gamma_1, Gamma_2, Gamma_3])

    assert(Omega.boundary == Union(Gamma_1, Gamma_2, Gamma_3))
    assert(Omega.boundary.complement(Gamma_1) == Union(Gamma_2, Gamma_3))
    assert(Omega.boundary - Gamma_1 == Union(Gamma_2, Gamma_3))
Example #3
0
def test_interior_domain():
    D1 = InteriorDomain('D1', dim=2)
    D2 = InteriorDomain('D2', dim=2)

    assert( D1.todict() == OrderedDict([('name', 'D1')]) )
    assert( D2.todict() == OrderedDict([('name', 'D2')]) )

    assert( Union(D2, D1) == Union(D1, D2) )

    D = Union(D1, D2)

    assert(D.dim == 2)
    assert(len(D) == 2)
    assert( D.todict() == [OrderedDict([('name', 'D1')]),
                           OrderedDict([('name', 'D2')])] )
Example #4
0
def test_interior_domain():
    D1 = InteriorDomain('D1', dim=2)
    D2 = InteriorDomain('D2', dim=2)

    assert( D1.todict() == {'name': 'D1'} )
    assert( D2.todict() == {'name': 'D2'} )

    assert( Union(D2, D1) == Union(D1, D2) )

    D = Union(D1, D2)

    assert(D.dim == 2)
    assert(len(D) == 2)
    assert( D.todict() == [{'name': 'D1'},
                           {'name': 'D2'}] )
Example #5
0
def test_boundary_2d_2():
    Omega_1 = InteriorDomain('Omega_1', dim=2)

    B1 = Boundary('B1', Omega_1)
    B2 = Boundary('B2', Omega_1)
    B3 = Boundary('B3', Omega_1)

    domain = Domain('Omega', interiors=[Omega_1], boundaries=[B1, B2, B3])

    V = FunctionSpace('V', domain)
    v = TestFunction(V, name='v')
    u = TestFunction(V, name='u')

    x, y = V.coordinates

    alpha = Constant('alpha')

    # ...
    print('==== l0 ====')
    l0 = LinearForm(v, x * y * v, name='l0')

    print(evaluate(l0, verbose=VERBOSE))
    print('')
    # ...

    # ...
    print('==== l1 ====')
    g = Tuple(x**2, y**2)
    l1 = LinearForm(v, v * trace_1(g, domain.boundary))

    print(evaluate(l1, verbose=VERBOSE))
    print('')
    # ...

    # ...
    print('==== l2 ====')
    B_neumann = Union(B1, B2)
    g = Tuple(x**2, y**2)
    l2 = LinearForm(v, v * trace_1(g, B_neumann), name='l2')

    print(evaluate(l2, verbose=VERBOSE))
    print('')
    # ...

    # ...
    print('==== l3 ====')
    l3 = LinearForm(v, l2(v))

    assert (l3(v).__str__ == l2(v).__str__)

    print(evaluate(l3, verbose=VERBOSE))
    print('')
    # ...

    # ...
    print('==== l4 ====')
    l4 = LinearForm(v, l0(v) + l2(v))

    print(evaluate(l4, verbose=VERBOSE))
    print('')
Example #6
0
def _get_domain(expr):
    # expr is an integral of BasicExpr or Add of Integral of BasicExpr
    if isinstance(expr, Integral):
        return expr.domain

    elif isinstance(expr, (Add, Mul)):
        domains = []
        for a in expr.args:
            a = _get_domain(a)
            if isinstance(a, Union):
                domains.extend(list(a.args))
            elif isinstance(a, BasicDomain):
                domains.append(a)
        return Union(*domains)
Example #7
0
def test_element():
    D1 = InteriorDomain('D1', dim=2)
    D2 = InteriorDomain('D2', dim=2)

    D = Union(D1, D2)

    e1 = ElementDomain()

    a = Area(e1)
    print(a)

    a = Area(D1)
    print(a)

    assert(Area(D) ==  Area(D1) + Area(D2))
Example #8
0
def _get_domain(expr):
    # expr is an integral of BasicExpr or Add of Integral of BasicExpr
    if isinstance(expr, (DomainIntegral, BoundaryIntegral, InterfaceIntegral)):
        return expr.domain

    elif isinstance(expr, (Add,Mul)):
        domains = set()
        for a in expr.args:
            a = _get_domain(a)
            if isinstance(a, Union):
                domains = domains.union(a.args)
            elif isinstance(a, BasicDomain):
                domains = domains.union([a])
        if len(domains) == 1:
            return list(domains)[0]
        return Union(*domains)
Example #9
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('')
Example #10
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('')