コード例 #1
0
ファイル: test_logical_expr.py プロジェクト: pyccel/sympde
def test_logical_expr_2d_3():
    dim = 2

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

    M1 = Mapping('M1', dim=dim)
    M2 = Mapping('M2', dim=dim)

    D1 = M1(A)
    D2 = M2(B)

    domain = D1.join(D2,
                     name='domain',
                     bnd_minus=D1.get_boundary(axis=0, ext=1),
                     bnd_plus=D2.get_boundary(axis=0, ext=-1))

    V = VectorFunctionSpace('V', domain, kind='hcurl')

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

    int_0 = lambda expr: integral(domain, expr)

    expr = LogicalExpr(int_0(dot(u, v)), domain)
    assert str(
        expr.args[0]
    ) == 'Integral(A, Dot((Jacobian(M1)**(-1)).T * u, (Jacobian(M1)**(-1)).T * v)*sqrt(det(Jacobian(M1).T * Jacobian(M1))))'
    assert str(
        expr.args[1]
    ) == 'Integral(B, Dot((Jacobian(M2)**(-1)).T * u, (Jacobian(M2)**(-1)).T * v)*sqrt(det(Jacobian(M2).T * Jacobian(M2))))'
コード例 #2
0
    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
コード例 #3
0
def test_square():
    square = Square('square')

    assert (square.dim == 2)
    assert (len(square.boundary) == 4)

    square.export('square.h5')

    # read it again
    D = Domain.from_file('square.h5')
コード例 #4
0
def test_system_2d():

    domain = Square()

    V = FunctionSpace('V', domain)
    x, y = V.coordinates

    u, v, p, q = [TestFunction(V, name=i) for i in ['u', 'v', 'p', 'q']]

    a1, a2, b1, b2 = [Constant(i, real=True) for i in ['a1', 'a2', 'b1', 'b2']]

    # ...
    a = BilinearForm((v, u), dot(grad(u), grad(v)))
    m = BilinearForm((v, u), u * v)

    expr = a(p, u) + a1 * m(p, u) + b1 * m(p, v) + a(
        q, v) + a2 * m(q, u) + b2 * m(q, v)
    b = BilinearForm(((p, q), (u, v)), expr)

    print(evaluate(b, verbose=True))
    # ...

    # ...
    f1 = x * y
    f2 = x + y
    l1 = LinearForm(p, f1 * p)
    l2 = LinearForm(q, f2 * q)

    expr = l1(p) + l2(q)
    l = LinearForm((p, q), expr)

    print(evaluate(l, verbose=True))
コード例 #5
0
def test_calls_2d_3():

    domain = Square()

    V = FunctionSpace('V', domain)

    x, y = domain.coordinates

    pn = Field('pn', V)
    wn = Field('wn', V)

    dp = TestFunction(V, name='dp')
    dw = TestFunction(V, name='dw')
    tau = TestFunction(V, name='tau')
    sigma = TestFunction(V, name='sigma')

    Re = Constant('Re', real=True)
    dt = Constant('dt', real=True)
    alpha = Constant('alpha', real=True)

    l1 = LinearForm(tau,
                    bracket(pn, wn) * tau - 1. / Re * dot(grad(tau), grad(wn)))

    # ...
    l = LinearForm((tau, sigma), dt * l1(tau))

    print(evaluate(l, verbose=True))
コード例 #6
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('')
コード例 #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_rectangle():

    # Create 2D rectangular domain [1, 5] X [3, 7]
    domain = Square('rectangle', bounds1=(1, 5), bounds2=(3, 7))

    assert isinstance(domain, Square)

    # BasicDomain's attributes
    assert domain.dim == 2
    assert domain.name == 'rectangle'
    assert domain.coordinates == (x1, x2)

    # Domain's attributes
    assert isinstance(domain.interior, InteriorDomain)
    assert isinstance(domain.interior.target, ProductDomain)
    assert all(isinstance(i, Interval) for i in domain.interior.target.domains)
    assert len(domain.interior.target.domains) == 2
    assert len(domain.boundary) == 4
    assert domain.dtype == {
        'type': 'Square',
        'parameters': {
            'bounds1': [1, 5],
            'bounds2': [3, 7]
        }
    }

    # NCube's attributes
    assert domain.min_coords == (1, 3)
    assert domain.max_coords == (5, 7)

    # Square's attributes
    assert domain.bounds1 == (1, 5)
    assert domain.bounds2 == (3, 7)

    # Export to file, read it again and compare with original domain
    domain.export('domain.h5')
    D = Domain.from_file('domain.h5')
    assert D.logical_domain == domain
コード例 #9
0
def test_unit_square():

    # Create 2D square domain [0, 1]^2
    domain = Square('square')

    assert isinstance(domain, Square)

    # BasicDomain's attributes
    assert domain.dim == 2
    assert domain.name == 'square'
    assert domain.coordinates == (x1, x2)

    # Domain's attributes
    assert isinstance(domain.interior, InteriorDomain)
    assert isinstance(domain.interior.target, ProductDomain)
    assert all(isinstance(i, Interval) for i in domain.interior.target.domains)
    assert len(domain.interior.target.domains) == 2
    assert len(domain.boundary) == 4
    assert domain.dtype == {
        'type': 'Square',
        'parameters': {
            'bounds1': [0, 1],
            'bounds2': [0, 1]
        }
    }

    # NCube's attributes
    assert domain.min_coords == (0, 0)
    assert domain.max_coords == (1, 1)

    # Square's attributes
    assert domain.bounds1 == (0, 1)
    assert domain.bounds2 == (0, 1)

    # Export to file, read it again and compare with original domain
    domain.export('domain.h5')
    D = Domain.from_file('domain.h5')
    assert D.logical_domain == domain
コード例 #10
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)
コード例 #11
0
def test_equation_2d_5():
    domain = Square()
    x, y = domain.coordinates

    f0 = Matrix([
        2 * pi**2 * sin(pi * x) * sin(pi * y),
        2 * pi**2 * sin(pi * x) * sin(pi * y)
    ])

    f1 = cos(pi * x) * cos(pi * y)

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

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

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

    int_0 = lambda expr: integral(domain, expr)

    a0 = BilinearForm((v, u), int_0(inner(grad(v), grad(u))))
    print('     a0 done.')
    a1 = BilinearForm((q, p), int_0(p * q))
    print('     a1 done.')
    a = BilinearForm(((v, q), (u, p)), a0(v, u) + a1(q, p))
    print('     a  done.')

    l0 = LinearForm(v, int_0(dot(f0, v)))
    l1 = LinearForm(q, int_0(f1 * q))
    l = LinearForm((v, q), l0(v) + l1(q))

    print('****************************')
    bc = EssentialBC(u, 0, domain.boundary)
    equation = Equation(a, l, tests=[v, q], trials=[u, p], bc=bc)

    # ...
    print('=======')
    print(equation.lhs.expr)
    print('')
    # ...

    # ...
    print('=======')
    print(equation.rhs.expr)
    print('')
コード例 #12
0
def test_bilinearity_2d_1():
    domain = Square()
    x, y = domain.coordinates

    alpha = Constant('alpha')
    beta = Constant('beta')

    f1 = x * y
    f2 = x + y
    f = Tuple(f1, f2)

    V = FunctionSpace('V', domain)

    # TODO improve: naming are not given the same way
    G = Field('G', V)

    p, q = [TestFunction(V, name=i) for i in ['p', 'q']]

    #####################################
    # linear expressions
    #####################################
    # ...
    expr = p * q
    assert (is_bilinear_form(expr, (p, q)))
    # ...

    # ...
    expr = dot(grad(p), grad(q))
    assert (is_bilinear_form(expr, (p, q)))
    # ...

    # ...
    expr = alpha * dot(grad(p),
                       grad(q)) + beta * p * q + laplace(p) * laplace(q)
    assert (is_bilinear_form(expr, (p, q)))
    # ...
    #####################################

    #####################################
    # nonlinear expressions
    #####################################
    # ...
    with pytest.raises(UnconsistentLinearExpressionError):
        expr = alpha * dot(grad(p**2), grad(q)) + beta * p * q
        is_bilinear_form(expr, (p, q))
コード例 #13
0
def test_curldiv_2d():

    domain = Square()

    W1 = VectorFunctionSpace('W1', domain)
    T1 = VectorFunctionSpace('T1', domain)

    w1 = VectorTestFunction(W1, name='w1')
    t1 = VectorTestFunction(T1, name='t1')

    mu = Constant('mu')

    # ...
    a = BilinearForm((w1, t1),
                     rot(w1) * rot(t1) + mu * div(w1) * div(t1),
                     name='a')
    print(a)
    print(atomize(a))
    print(evaluate(a))
コード例 #14
0
def test_calls_2d_2():

    domain = Square()

    V = FunctionSpace('V', domain)
    x, y = V.coordinates

    u, v = [TestFunction(V, name=i) for i in ['u', 'v']]
    Un = Field('Un', V)

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

    expr = a(v, Un)
    print(evaluate(expr, verbose=True))
    # ...

    # ...
    l = LinearForm(v, a(v, Un))

    print(evaluate(l, verbose=True))
コード例 #15
0
def test_equation_2d_2():

    domain = Square()

    V = ScalarFunctionSpace('V', domain)

    x, y = domain.coordinates

    pn, wn = [element_of(V, name=i) for i in ['pn', 'wn']]

    dp = element_of(V, name='dp')
    dw = element_of(V, name='dw')
    tau = element_of(V, name='tau')
    sigma = element_of(V, name='sigma')

    Re = Constant('Re', real=True)
    dt = Constant('dt', real=True)
    alpha = Constant('alpha', real=True)

    int_0 = lambda expr: integral(domain, expr)

    s = BilinearForm((tau, sigma), int_0(dot(grad(tau), grad(sigma))))
    m = BilinearForm((tau, sigma), int_0(tau * sigma))
    b1 = BilinearForm((tau, dw), int_0(bracket(pn, dw) * tau))
    b2 = BilinearForm((tau, dp), int_0(bracket(dp, wn) * tau))

    l1 = LinearForm(
        tau, int_0(bracket(pn, wn) * tau - 1. / Re * dot(grad(tau), grad(wn))))

    expr = m(tau, dw) - alpha * dt * b1(tau, dw) - dt * b2(
        tau, dp) - (alpha * dt / Re) * s(tau, dw)
    a = BilinearForm(((tau, sigma), (dp, dw)), int_0(expr))

    l = LinearForm((tau, sigma), dt * l1(tau))

    bc = [EssentialBC(dp, 0, domain.boundary)]
    bc += [EssentialBC(dw, 0, domain.boundary)]
    equation = Equation(a, l, tests=[tau, sigma], trials=[dp, dw], bc=bc)
コード例 #16
0
def test_evaluation_2d_2():
    domain = Square()
    x, y = domain.coordinates

    f0 = Tuple(2 * pi**2 * sin(pi * x) * sin(pi * y),
               2 * pi**2 * sin(pi * x) * sin(pi * y))

    f1 = cos(pi * x) * cos(pi * y)

    W = VectorFunctionSpace('W', domain)
    V = FunctionSpace('V', domain)
    X = ProductSpace(W, V)

    # TODO improve: naming are not given the same way
    F = VectorField(W, name='F')
    G = Field('G', V)

    u, v = [VectorTestFunction(W, name=i) for i in ['u', 'v']]
    p, q = [TestFunction(V, name=i) for i in ['p', 'q']]

    a0 = BilinearForm((v, u), inner(grad(v), grad(u)))
    a1 = BilinearForm((q, p), p * q)
    a = BilinearForm(((v, q), (u, p)), a0(v, u) + a1(q, p))

    l0 = LinearForm(v, dot(f0, v))
    l1 = LinearForm(q, f1 * q)
    l = LinearForm((v, q), l0(v) + l1(q))

    # ...
    print(a)
    print(evaluate(a))
    print('')
    # ...

    # ...
    print(l)
    print(evaluate(l))
    print('')
コード例 #17
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('')
コード例 #18
0
ファイル: test_logical_expr.py プロジェクト: pyccel/sympde
def test_logical_expr_2d_2():
    dim = 2

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

    M1 = Mapping('M1', dim=dim)
    M2 = Mapping('M2', dim=dim)

    D1 = M1(A)
    D2 = M2(B)

    domain = D1.join(D2,
                     name='domain',
                     bnd_minus=D1.get_boundary(axis=0, ext=1),
                     bnd_plus=D2.get_boundary(axis=0, ext=-1))

    V1 = ScalarFunctionSpace('V1', domain, kind='h1')
    V2 = VectorFunctionSpace('V2', domain, kind='h1')

    u1, v1 = [element_of(V1, name=i) for i in ['u1', 'v1']]
    u2, v2 = [element_of(V2, name=i) for i in ['u2', 'v2']]

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

    expr = LogicalExpr(int_0(u1 * v1), domain)
    assert str(
        expr.args[0]
    ) == 'Integral(A, u1*v1*sqrt(det(Jacobian(M1).T * Jacobian(M1))))'
    assert str(
        expr.args[1]
    ) == 'Integral(B, u1*v1*sqrt(det(Jacobian(M2).T * Jacobian(M2))))'

    expr = LogicalExpr(int_1(plus(u1) * plus(v1)), domain)
    assert str(
        expr
    ) == 'Integral(A|B, PlusInterfaceOperator(u1)*PlusInterfaceOperator(v1)*sqrt(det(Jacobian(M1|M2).T * Jacobian(M1|M2))))'

    expr = LogicalExpr(int_1(minus(u1) * minus(v1)), domain)
    assert str(
        expr
    ) == 'Integral(A|B, MinusInterfaceOperator(u1)*MinusInterfaceOperator(v1)*sqrt(det(Jacobian(M1|M2).T * Jacobian(M1|M2))))'

    expr = LogicalExpr(int_0(dot(u2, v2)), domain)
    assert str(
        expr.args[0]
    ) == 'Integral(A, Dot(u2, v2)*sqrt(det(Jacobian(M1).T * Jacobian(M1))))'
    assert str(
        expr.args[1]
    ) == 'Integral(B, Dot(u2, v2)*sqrt(det(Jacobian(M2).T * Jacobian(M2))))'

    expr = LogicalExpr(int_1(dot(plus(u2), plus(v2))), domain)
    assert str(
        expr
    ) == 'Integral(A|B, Dot(PlusInterfaceOperator(u2), PlusInterfaceOperator(v2))*sqrt(det(Jacobian(M1|M2).T * Jacobian(M1|M2))))'

    expr = LogicalExpr(int_1(dot(minus(u2), minus(v2))), domain)
    assert str(
        expr
    ) == 'Integral(A|B, Dot(MinusInterfaceOperator(u2), MinusInterfaceOperator(v2))*sqrt(det(Jacobian(M1|M2).T * Jacobian(M1|M2))))'

    expr = LogicalExpr(int_1(dot(grad(minus(u2)), grad(minus(v2)))), domain)
    assert str(
        expr
    ) == 'Integral(A|B, Dot((Jacobian(M1)**(-1)).T * Grad(MinusInterfaceOperator(u2)), (Jacobian(M1)**(-1)).T * Grad(MinusInterfaceOperator(v2)))*sqrt(det(Jacobian(M1|M2).T * Jacobian(M1|M2))))'

    expr = LogicalExpr(int_1(dot(grad(plus(u2)), grad(plus(v2)))), domain)
    assert str(
        expr
    ) == 'Integral(A|B, Dot((Jacobian(M2)**(-1)).T * Grad(PlusInterfaceOperator(u2)), (Jacobian(M2)**(-1)).T * Grad(PlusInterfaceOperator(v2)))*sqrt(det(Jacobian(M1|M2).T * Jacobian(M1|M2))))'
コード例 #19
0
def test_domain_join_square():

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

    print(AB)
    print(AB.interior)
    print(AB.interfaces)
    print(AB.connectivity)
    print('')
    # ...

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

    print(ABC)
    print(ABC.interior)
    print(ABC.interfaces)
    print(list(ABC.connectivity.items()))
    print('')
コード例 #20
0
ファイル: test_topology.py プロジェクト: yellalena/sympde
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('')
コード例 #21
0
def test_equation_2d_6():

    domain = Square()
    x, y = domain.coordinates

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

    b1 = 1.
    b2 = 0.
    b = Tuple(b1, b2)

    # right hand side
    f = x * y

    e = ElementDomain()
    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)

    # ...
    expr = kappa * dot(grad(u), grad(v)) + dot(b, grad(u)) * v
    a = BilinearForm((v, u), int_0(expr))
    # ...
    # ...
    expr = f * v
    l0 = LinearForm(v, int_0(expr))
    # ...

    # ...
    expr = (-kappa * laplace(u) + dot(b, grad(u))) * dot(b, grad(v))
    s1 = BilinearForm((v, u), int_0(expr))

    expr = -f * dot(b, grad(v))
    l1 = LinearForm(v, int_0(expr))
    # ...

    # ...
    expr = (-kappa * laplace(u) + dot(b, grad(u))) * (dot(b, grad(v)) -
                                                      kappa * laplace(v))
    s2 = BilinearForm((v, u), int_0(expr))

    expr = -f * (dot(b, grad(v)) - kappa * laplace(v))
    l2 = LinearForm(v, int_0(expr))
    # ...

    # ...
    expr = (-kappa * laplace(u) + dot(b, grad(u))) * (dot(b, grad(v)) +
                                                      kappa * laplace(v))
    s3 = BilinearForm((v, u), int_0(expr))

    expr = -f * (dot(b, grad(v)) + kappa * laplace(v))
    l3 = LinearForm(v, int_0(expr))
    # ...

    # ...
    expr = a(v, u) + mu * area * s1(v, u)
    a1 = BilinearForm((v, u), expr)
    # ...

    # ...
    expr = a(v, u) + mu * area * s2(v, u)
    a2 = BilinearForm((v, u), expr)
    # ...

    # ...
    expr = a(v, u) + mu * area * s3(v, u)
    a3 = BilinearForm((v, u), expr)
    # ...

    bc = EssentialBC(u, 0, domain.boundary)

    # ...
    l = LinearForm(v, l0(v) + mu * area * l1(v))

    eq_1 = Equation(a1, l, tests=v, trials=u, bc=bc)
    # ...

    # ...
    l = LinearForm(v, l0(v) + mu * area * l2(v))

    eq_2 = Equation(a2, l, tests=v, trials=u, bc=bc)
    # ...

    # ...
    l = LinearForm(v, l0(v) + mu * area * l3(v))

    eq_3 = Equation(a3, l, tests=v, trials=u, bc=bc)
コード例 #22
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('')
コード例 #23
0
from nodes import CoefficientBasis
from nodes import StencilMatrixLocalBasis
from nodes import StencilVectorLocalBasis
from nodes import StencilMatrixGlobalBasis
from nodes import StencilVectorGlobalBasis
from nodes import ElementOf
from nodes import WeightedVolumeQuadrature
from nodes import ComputeKernelExpr
from nodes import AST
from nodes import Block
from nodes import Reset

from parser import parse

# ... abstract model
domain = Square()
M      = Mapping('M', domain.dim)

V      = ScalarFunctionSpace('V', domain)
u,v    = elements_of(V, names='u,v')
expr   = dot(grad(v), grad(u))
# ...

# ...
grid    = Grid()
element = Element()
g_quad  = GlobalTensorQuadrature()
l_quad  = LocalTensorQuadrature()
quad    = TensorQuadrature()

g_basis   = GlobalTensorQuadratureTrialBasis(u)
コード例 #24
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)