コード例 #1
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('')
コード例 #2
0
ファイル: graph.py プロジェクト: yellalena/sympde
def test_bilinear_form_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)

    V = FunctionSpace('V', domain)

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

    # ...
    d_forms = {}

    d_forms['a1'] = BilinearForm((u, v), u * v)
    d_forms['a2'] = BilinearForm((u, v), u * v + dot(grad(u), grad(v)))
    d_forms['a3'] = BilinearForm((u, v), v * trace_1(grad(u), B1))

    # Poisson with Nitsch method
    a0 = BilinearForm((u, v), dot(grad(u), grad(v)))
    a_B1 = BilinearForm(
        (u, v), -kappa * u * trace_1(grad(v), B1) - v * trace_1(grad(u), B1) +
        trace_0(u, B1) * trace_0(v, B1) / eps)
    a = BilinearForm((u, v), a0(u, v) + a_B1(u, v))

    d_forms['a4'] = a
    # ...

    # ... calls
    d_calls = {}
    for name, a in d_forms.items():
        d_calls[name] = a(u1, v1)
    # ...

    # ... export forms
    for name, expr in d_forms.items():
        export(expr, 'biform_2d_{}.png'.format(name))
    # ...

    # ... export calls
    for name, expr in d_calls.items():
        export(expr, 'biform_2d_call_{}.png'.format(name))
コード例 #3
0
def test_evaluation_2d_1():
    domain = Domain('Omega', dim=2)
    B_neumann = Boundary(r'\Gamma_1', domain)

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

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

    alpha = Constant('alpha')

    x, y = V.coordinates
    F = Field('F', space=V)

    a1 = BilinearForm((p, q), dot(grad(p), grad(q)))
    m = BilinearForm((p, q), p * q)
    a2 = BilinearForm((p, q), a1(p, q) + alpha * m(p, q))
    a3 = BilinearForm((u, v), rot(u) * rot(v) + alpha * div(u) * div(v))

    a11 = BilinearForm((v, u), inner(grad(v), grad(u)))
    a12 = BilinearForm((v, p), div(v) * p)
    a4 = BilinearForm(((v, q), (u, p)), a11(v, u) - a12(v, p) + a12(u, q))

    l0 = LinearForm(p, F * p)
    l_neu = LinearForm(p, p * trace_1(grad(F), B_neumann))
    l = LinearForm(p, l0(p) + l_neu(p))

    # ...
    print(a1)
    print(evaluate(a1))
    print('')
    # ...

    # ...
    print(a2)
    print(evaluate(a2))
    print('')
    # ...

    # ...
    print(a3)
    print(evaluate(a3))
    print('')
    # ...

    # ...
    print(a4)
    print(evaluate(a4))
    print('')
    # ...

    # ...
    print(l)
    print(evaluate(l))
    print('')
コード例 #4
0
ファイル: graph.py プロジェクト: yellalena/sympde
def test_linear_form_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)

    V = FunctionSpace('V', domain)

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

    g = Tuple(x**2, y**2)

    # ...
    d_forms = {}

    d_forms['l1'] = LinearForm(v, x * y * v)
    d_forms['l2'] = LinearForm(v, v * trace_1(g, B1))
    d_forms['l3'] = LinearForm(v, v * trace_1(g, B1) + x * y * v)

    # nitsche
    f = Function('f')
    g = Function('g')

    l0 = LinearForm(v, f(x, y) * v)
    l_B1 = LinearForm(
        v,
        g(x, y) * trace_0(v, B1) / eps -
        kappa * g(x, y) * trace_1(grad(v), B1))

    d_forms['l4'] = LinearForm(v, l0(v) + l_B1(v))
    # ...

    # ...
    for name, expr in d_forms.items():
        export(expr, 'linform_2d_{}.png'.format(name))
コード例 #5
0
def test_bilinear_form_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)

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

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

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

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

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

    assert (a.domain == B1)
    assert (a(u1, v1) == int_1(v1 * trace_1(grad(u1), B1)))
    # ...

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

    # TODO a.domain are not ordered
    assert (len(a.domain.args) == 2)
    for i in a.domain.args:
        assert (i in [domain.interior, B1])

    assert (a(u1, v1) == int_0(u1 * v1) + int_1(v1 * trace_1(grad(u1), B1)))
    # ...

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

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

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

    assert (a.domain == domain.interior)
    assert (a(u, v) == int_0(u * v) + int_0(kappa * dot(grad(u), grad(v))))
コード例 #6
0
def test_linear_form_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)
    W = VectorFunctionSpace('W', 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))

    assert (l.domain == domain.interior)
    assert (l(v1) == int_0(x * y * v1))
    # ...

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

    assert (l.domain == B1)
    assert (l(v1) == int_1(v1 * trace_1(g, B1)))
    # ...

    # ...
    g = Tuple(x**2, y**2)
    l = LinearForm(v, int_1(v * dot(g, nn)) + int_0(x * y * v))

    assert (len(l.domain.args) == 2)
    for i in l.domain.args:
        assert (i in [domain.interior, B1])

    assert (l(v1) == int_1(v1 * trace_1(g, B1)) + int_0(x * y * v1))
    # ...

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

    assert (l.domain == domain.interior)
    assert (l(u1) == int_0(x * y * u1))
    # ...

    # ...
    g = Tuple(x, y)
    l1 = LinearForm(u1, int_0(x * y * u1))
    l2 = LinearForm(u2, int_0(dot(grad(u2), g)))

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

    assert (l.domain == domain.interior)
    assert (l(v1) == int_0(x * y * v1) + int_0(dot(grad(v1), g)))
    # ...

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

    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)

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

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

    assert (l.domain == domain.interior)
    assert (l(u1,
              u2).expand() == int_0(-1.0 * dt * dot(grad(u1), grad(wn)) / Re) +
            int_0(dt * u1 * bracket(pn, wn)))
コード例 #7
0
def test_boundary_2d_1():
    domain = Domain('Omega', dim=DIM)

    V1 = FunctionSpace('V1', domain)
    V2 = FunctionSpace('V2', domain)
    U1 = FunctionSpace('U1', domain)
    U2 = FunctionSpace('U2', domain)
    W1 = VectorFunctionSpace('W1', domain)
    W2 = VectorFunctionSpace('W2', domain)
    T1 = VectorFunctionSpace('T1', domain)
    T2 = VectorFunctionSpace('T2', domain)

    v1 = TestFunction(V1, name='v1')
    v2 = TestFunction(V2, name='v2')
    u1 = TestFunction(U1, name='u1')
    u2 = TestFunction(U2, name='u2')
    w1 = VectorTestFunction(W1, name='w1')
    w2 = VectorTestFunction(W2, name='w2')
    t1 = VectorTestFunction(T1, name='t1')
    t2 = VectorTestFunction(T2, name='t2')

    x, y = V1.coordinates

    alpha = Constant('alpha')

    B1 = Boundary(r'\Gamma_1', domain)
    B2 = Boundary(r'\Gamma_2', domain)
    B3 = Boundary(r'\Gamma_3', domain)

    # ...
    with pytest.raises(UnconsistentError):
        expr = dot(grad(v1), grad(u1)) + v1 * trace_0(u1, B1)
        a = BilinearForm((v1, u1), expr, name='a')
    # ...

    # ...
    with pytest.raises(UnconsistentError):
        expr = v1 * trace_0(u1, B3) + v1 * trace_1(grad(u1),
                                                   B3) + u1 * trace_0(v1, B2)
        a1 = BilinearForm((v1, u1), expr, name='a1')
    # ...

    # ...
    expr = dot(grad(v1), grad(u1))
    a_0 = BilinearForm((v1, u1), expr, name='a_0')

    expr = v1 * trace_0(u1, B1)
    a_bnd = BilinearForm((v1, u1), expr, name='a_bnd')

    expr = a_0(v1, u1) + a_bnd(v1, u1)
    a = BilinearForm((v1, u1), expr, name='a')
    print(a)
    print(evaluate(a, verbose=True))
    print('')
    #    import sys; sys.exit(0)
    # ...

    # ...
    expr = v1 * trace_0(u1, B1) + v1 * trace_1(grad(u1), B1)
    a1 = BilinearForm((v1, u1), expr, name='a1')

    expr = u1 * trace_1(grad(v1), B2)
    a2 = BilinearForm((v1, u1), expr, name='a2')

    expr = a1(v2, u2) + a2(v2, u2)
    # as expected, we can define the form call, but we cannot create a Bilinear
    # form out of it.
    # TODO add assert on exception type
    #    a = BilinearForm((v2, u2), expr, name='a')

    print(expr)
    print('')
    # ...

    # ...
    expr = v1 * trace_0(u1, B1)
    a0 = BilinearForm((v1, u1), expr, name='a0')

    expr = v1 * trace_1(grad(u1), B1)
    a1 = BilinearForm((v1, u1), expr, name='a1')

    expr = v1 * trace_1(grad(u1), B2)
    a2 = BilinearForm((v1, u1), expr, name='a2')

    expr = dot(grad(u1), grad(v1))
    a3 = BilinearForm((v1, u1), expr, name='a3')

    expr = u1 * v1
    a4 = BilinearForm((v1, u1), expr, name='a4')

    # TODO Mul not treated yet
    #    expr = a0(v2, u2) + a1(v2, u2) + alpha * a2(v2, u2) + a3(v2, u2) + alpha*a4(v2, u2)
    #    a = BilinearForm((v2, u2), expr, name='a')
    ##    print(expr)
    #    print(evaluate(expr, verbose=True))
    #    print('')
    #
    #    print(evaluate(a, verbose=True))
    #    print('')

    #    expr = a(v2, u2) + a1(v2, u2)
    #    b = BilinearForm((v2, u2), expr, name='b')
    #    print(b)
    #    print(evaluate(b, verbose=True))
    # ...

    # ...
    g = Tuple(x**2, y**2)
    expr = v1 * trace_1(g, B1)
    l1 = LinearForm(v1, expr, name='l1')
    print(l1)
    #    print(atomize(l1))
    #    print(evaluate(l1))
    print('')