예제 #1
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))
예제 #2
0
def test_projector_2d_1():

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

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

    v, w = Field(V * W, ['v', 'w'])

    # ...
    P_V = Projector(V)
    assert (P_V.space == V)

    Pv = P_V(v)
    assert (isinstance(Pv, ScalarField))
    assert (Pv == v)
    assert (grad(Pv**2) == 2 * v * grad(v))

    Pdiv_w = P_V(div(w))
    assert (isinstance(Pdiv_w, ScalarField))
    # ...

    # ...
    P_W = Projector(W)
    assert (P_W.space == W)

    Pw = P_W(w)
    assert (isinstance(Pw, VectorField))
    assert (Pw == w)

    Pgrad_v = P_W(grad(v))
    assert (isinstance(Pgrad_v, VectorField))
    assert (P_W(Pgrad_v) == Pgrad_v)
예제 #3
0
파일: graph.py 프로젝트: yellalena/sympde
def test_linearize_form_2d_3():
    """steady Euler equation."""
    domain = Domain('Omega', dim=2)
    x, y = domain.coordinates

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

    v = VectorTestFunction(U, name='v')
    phi = TestFunction(W, name='phi')
    q = TestFunction(W, name='q')

    U_0 = VectorField(U, name='U_0')
    Rho_0 = Field(W, name='Rho_0')
    P_0 = Field(W, name='P_0')

    # ...
    expr = div(Rho_0 * U_0) * phi
    l1 = LinearForm(phi, expr)

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

    expr = dot(U_0, grad(P_0)) * q + P_0 * div(U_0) * q
    l3 = LinearForm(q, expr)
    # ...

    a1 = linearize(l1, [Rho_0, U_0], trials=['d_rho', 'd_u'])
    print(a1)
    print('')

    a2 = linearize(l2, [Rho_0, U_0, P_0], trials=['d_rho', 'd_u', 'd_p'])
    print(a2)
    print('')

    a3 = linearize(l3, [P_0, U_0], trials=['d_p', 'd_u'])
    print(a3)
    print('')

    l = LinearForm((phi, v, q), l1(phi) + l2(v) + l3(q))
    a = linearize(l, [Rho_0, U_0, P_0], trials=['d_rho', 'd_u', 'd_p'])
    print(a)

    export(a, 'steady_euler.png')
예제 #4
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('')
예제 #5
0
def test_linearize_2d_1():
    domain = Domain('Omega', dim=DIM)
    x, y = domain.coordinates

    V1 = FunctionSpace('V1', domain)
    W1 = VectorFunctionSpace('W1', domain)

    v1 = TestFunction(V1, name='v1')
    w1 = VectorTestFunction(W1, name='w1')

    alpha = Constant('alpha')

    F = Field('F', space=V1)
    G = VectorField(W1, 'G')

    # ...
    l = LinearForm(v1, F**2 * v1, check=True)
    a = linearize(l, F, trials='u1')
    print(a)
    # ...

    # ...
    l = LinearForm(v1, dot(grad(F), grad(F)) * v1, check=True)
    a = linearize(l, F, trials='u1')
    print(a)
    # ...

    # ...
    l = LinearForm(v1, exp(-F) * v1, check=True)
    a = linearize(l, F, trials='u1')
    print(a)
    # ...

    # ...
    l = LinearForm(v1, cos(F) * v1, check=True)
    a = linearize(l, F, trials='u1')
    print(a)
    # ...

    # ...
    l = LinearForm(v1, cos(F**2) * v1, check=True)
    a = linearize(l, F, trials='u1')
    print(a)
    # ...

    # ...
    l = LinearForm(v1, F**2 * dot(grad(F), grad(v1)), check=True)
    a = linearize(l, F, trials='u1')
    print(a)
    # ...

    # ...
    l = LinearForm(w1, dot(rot(G), grad(G)) * w1, check=True)
    a = linearize(l, G, trials='u1')
    print(a)
예제 #6
0
def test_linearize_2d_2():
    domain = Domain('Omega', dim=DIM)
    x, y = domain.coordinates

    V1 = FunctionSpace('V1', domain)

    v1 = TestFunction(V1, name='v1')

    alpha = Constant('alpha')

    F = Field('F', space=V1)
    G = Field('G', space=V1)

    # ...
    l1 = LinearForm(v1, F**2 * v1, check=True)
    l = LinearForm(v1, l1(v1))

    a = linearize(l, F, trials='u1')
    print(a)

    expected = linearize(l1, F, trials='u1')
    assert (linearize(l, F, trials='u1') == expected)
예제 #7
0
def test_compiler_3d_2():

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

    H1    = ScalarFunctionSpace('V0', domain, kind='H1')
    Hcurl = VectorFunctionSpace('V1', domain, kind='Hcurl')
    Hdiv  = VectorFunctionSpace('V2', domain, kind='Hdiv')
    L2    = ScalarFunctionSpace('V3', domain, kind='L2')
    V     = VectorFunctionSpace('V', domain)

    X = H1 * Hcurl * Hdiv * L2

    v = element_of(X, name='v0, v1, v2, v3')
    u = element_of(X, name='u0, u1, u2, u3')

    beta = Field(V, 'beta')

#    # ... Dot operator
#    expr = dot(u1, v1)
#    print(ExteriorCalculusExpr(expr, tests=[v1]))
#
#    expr = dot(u2, v2)
#    print(ExteriorCalculusExpr(expr, tests=[v2]))
#
#    expr = dot(grad(v0), u1)
#    print(ExteriorCalculusExpr(expr, tests=[v0]))
#
#    expr = dot(grad(u0), v1)
#    print(ExteriorCalculusExpr(expr, tests=[v1]))
#
#    expr = dot(curl(u1), v2)
#    print(ExteriorCalculusExpr(expr, tests=[v2]))
#
#    expr = dot(curl(v1), u2)
#    print(ExteriorCalculusExpr(expr, tests=[v1]))
#    # ...

    # ... Mul operator
    expr = u[0] * v[0]
    print(ExteriorCalculusExpr(expr, tests=[v[0]]))

    expr = u[0] * div(v[2])
    print(ExteriorCalculusExpr(expr, tests=[v[2]]))

    expr = v[0] * div(u[2])
    print(ExteriorCalculusExpr(expr, tests=[v[0]]))
예제 #8
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))
예제 #9
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))
예제 #10
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('')
예제 #11
0
def test_compiler_3d_1():

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

    H1    = ScalarFunctionSpace('V0', domain, kind='H1')
    Hcurl = VectorFunctionSpace('V1', domain, kind='Hcurl')
    Hdiv  = VectorFunctionSpace('V2', domain, kind='Hdiv')
    L2    = ScalarFunctionSpace('V3', domain, kind='L2')
    V     = VectorFunctionSpace('V', domain)

    X = H1 * Hcurl * Hdiv * L2

    v0, v1, v2, v3 = element_of(X, name='v0, v1, v2, v3')

    beta = Field(V, 'beta')

#    # ...
#    expr = grad(v0)
#    expected = d(DifferentialForm('v0', index=0, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr) == expected)
#    # ...
#
#    # ...
#    expr = curl(v1)
#    expected = d(DifferentialForm('v1', index=1, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr) == expected)
#    # ...
#
#    # ...
#    expr = div(v2)
#    expected = d(DifferentialForm('v2', index=2, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr) == expected)
#    # ...
#
#    # ...
#    expr = grad(v0)
#    expected = - delta(DifferentialForm('v0', index=3, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr, tests=[v0]) == expected)
#    # ...
#
#    # ...
#    expr = curl(v1)
#    expected = delta(DifferentialForm('v1', index=2, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr, tests=[v1]) == expected)
#    # ...
#
#    # ...
#    expr = div(v2)
#    expected = -delta(DifferentialForm('v2', index=1, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr, tests=[v2]) == expected)
#    # ...
#
#    # ...
#    expr = dot(beta, v1)
#    expected = ip(beta, DifferentialForm('v1', index=1, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr) == expected)
#    # ...
#
#    # ...
#    expr = cross(beta, v2)
#    expected = ip(beta, DifferentialForm('v2', index=2, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr) == expected)
#    # ...
#
#    # ...
#    expr = beta*v3
#    expected = ip(beta, DifferentialForm('v3', index=3, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr) == expected)
#    # ...
#
#    # ...
#    expr = dot(beta, v1)
#    expected = jp(beta, DifferentialForm('v1', index=3, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr, tests=[v1]) == expected)
#    # ...
#
#    # ...
#    expr = cross(beta, v2)
#    expected = -jp(beta, DifferentialForm('v2', index=2, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr, tests=[v2]) == expected)
#    # ...
#
#    # ...
#    expr = beta*v3
#    expected = jp(beta, DifferentialForm('v3', index=1, dim=domain.dim))
#
#    assert(ExteriorCalculusExpr(expr, tests=[v3]) == expected)
#    # ...

    # ..................................................
    #     LIE DERIVATIVES
    # ..................................................
    # ...
    expr = dot(beta, grad(v0))
    expected = ld(beta, DifferentialForm('v0', index=0, dim=domain.dim))

    assert(ExteriorCalculusExpr(expr) == expected)
    # ...

    # ...
    expr = grad(dot(beta,v1)) + cross(curl(v1), beta)
    expected = ld(beta, DifferentialForm('v1', index=1, dim=domain.dim))

    assert(ExteriorCalculusExpr(expr) == expected)
    # ...

    # ...
    expr = curl(cross(v2, beta)) + div(v2)*beta
    expected = ld(beta, DifferentialForm('v2', index=2, dim=domain.dim))

    assert(ExteriorCalculusExpr(expr) == expected)
    # ...

    # ...
    expr = div(beta*v3)
    expected = ld(beta, DifferentialForm('v3', index=3, dim=domain.dim))

    assert(ExteriorCalculusExpr(expr) == expected)
예제 #12
0
def test_linearity_2d_2():
    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')

    V = ProductSpace(V1, V2)
    U = ProductSpace(U1, U2)

    x, y = V1.coordinates

    alpha = Constant('alpha')

    F = Field('F', space=V1)

    # ...
    l1 = LinearForm(v1, x * y * v1, check=True)

    l = LinearForm(v2, l1(v2), check=True)
    # ...

    # ...
    l1 = LinearForm(v1, x * y * v1, check=True)
    l2 = LinearForm(v2, cos(x + y) * v2, check=True)

    l = LinearForm((u1, u2), l1(u1) + l2(u2), check=True)
    # ...

    # ...
    l1 = LinearForm(v1, x * y * v1, check=True)
    l2 = LinearForm(v2, cos(x + y) * v2, check=True)

    l = LinearForm((u1, u2), l1(u1) + alpha * l2(u2), check=True)
    # ...

    # ...
    l1 = LinearForm(v1, x * y * v1, check=True)
    l2 = LinearForm(w1, div(w1), check=True)

    l = LinearForm((v2, w2), l1(v2) + l2(w2), check=True)
    # ...

    ################################
    #    non bilinear forms
    ################################
    # ...
    with pytest.raises(UnconsistentLinearExpressionError):
        l = LinearForm(v1, x * y * v1**2, check=True)
    # ...

    # ...
    with pytest.raises(UnconsistentLinearExpressionError):
        l = LinearForm(v1, x * y, check=True)
예제 #13
0
def test_norm_2d():
    domain = Domain('Omega', dim=DIM)

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

    # ...
    expr = x * y
    l2_norm_u = Norm(expr, domain, kind='l2')
    h1_norm_u = Norm(expr, domain, kind='h1')

    print('> l2 norm = ', evaluate(l2_norm_u))
    print('> h1 norm = ', evaluate(h1_norm_u))
    print('')
    # ...

    # ...
    expr = sin(pi * x) * sin(pi * y)
    l2_norm_u = Norm(expr, domain, kind='l2')
    h1_norm_u = Norm(expr, domain, kind='h1')

    print('> l2 norm = ', evaluate(l2_norm_u))
    print('> h1 norm = ', evaluate(h1_norm_u))
    print('')
    # ...

    # ...
    expr = F - x * y
    l2_norm_u = Norm(expr, domain, kind='l2')
    h1_norm_u = Norm(expr, domain, kind='h1')

    print('> l2 norm = ', evaluate(l2_norm_u))
    print('> h1 norm = ', evaluate(h1_norm_u))
    print('')
    # ...

    # ...
    expr = F - sin(pi * x) * sin(pi * y)
    l2_norm_u = Norm(expr, domain, kind='l2')
    h1_norm_u = Norm(expr, domain, kind='h1')

    print('> l2 norm = ', evaluate(l2_norm_u))
    print('> h1 norm = ', evaluate(h1_norm_u))
    print('')
    # ...

    # ...
    expr = F - sin(0.5 * pi * (1. - x)) * sin(pi * y)
    l2_norm_u = Norm(expr, domain, kind='l2')
    h1_norm_u = Norm(expr, domain, kind='h1')

    print('> l2 norm = ', evaluate(l2_norm_u))
    print('> h1 norm = ', evaluate(h1_norm_u))
    print('')
    # ...

    # ...
    expr = F - cos(0.5 * pi * x) * sin(pi * y)
    l2_norm_u = Norm(expr, domain, kind='l2')
    h1_norm_u = Norm(expr, domain, kind='h1')

    print('> l2 norm = ', evaluate(l2_norm_u))
    print('> h1 norm = ', evaluate(h1_norm_u))
    print('')
예제 #14
0
def test_calls_2d():
    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')

    V = ProductSpace(V1, V2)
    U = ProductSpace(U1, U2)

    x, y = V1.coordinates

    alpha = Constant('alpha')

    F = Field('F', space=V1)

    # ...
    a1 = BilinearForm((v1, u1), u1 * v1, name='a1')
    print(a1)
    print(atomize(a1))
    print(evaluate(a1))
    print('')

    expr = a1(v2, u2)
    a = BilinearForm((v2, u2), expr, name='a')
    print(a)
    print(atomize(a))
    print(evaluate(a))
    print('')
    # ...

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

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

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

    expr = a1(v2, u2)
    a = BilinearForm((v2, u2), expr, name='a')
    print(a)
    print(atomize(a))
    print(evaluate(a))
    print('')
    # ...

    # ...
    a1 = BilinearForm((v1, u1), u1 * v1, name='a1')
    a2 = BilinearForm((v1, u1), dx(u1) * dx(v1), name='a2')

    expr = a1(v2, u2) + a2(v2, u2)
    a = BilinearForm((v2, u2), expr, name='a')
    print(a)
    print(atomize(a))
    print(evaluate(a))
    print('')
    # ...

    # ...
    a1 = BilinearForm((v1, u1), u1 * v1, name='a1')
    a2 = BilinearForm((v1, u1), dx(u1) * dx(v1), name='a2')

    expr = a1(v1, u2)
    print('> before = ', expr)
    expr = expr.subs(u2, u1)
    print('> after  = ', expr)
    print('')

    expr = a1(v1, u2) + a1(v2, u2)
    print('> before = ', expr)
    expr = expr.subs(u2, u1)
    print('> after  = ', expr)
    print('')
    # ...

    # ...
    a1 = BilinearForm((v1, u1), u1 * v1, name='a1')
    a2 = BilinearForm((v1, u1), dx(u1) * dx(v1), name='a2')

    expr = a1(v1, u2) + a2(v2, u1)
    a = BilinearForm(((v1, v2), (u1, u2)), expr, name='a')
    print(a)
    print(atomize(a))
    print(evaluate(a))
    print('')
    # ...

    # ...
    a = BilinearForm((w1, t1), rot(w1) * rot(t1) + div(w1) * div(t1), name='a')
    print(a)
    print(atomize(a))
    print(evaluate(a))
    # ...

    # ...
    a1 = BilinearForm((v1, u1), u1 * v1, name='a1')
    a2 = BilinearForm((v1, u1), dx(u1) * dx(v1), name='a2')
    a3 = BilinearForm((w1, t1),
                      rot(w1) * rot(t1) + div(w1) * div(t1),
                      name='a3')
    a4 = BilinearForm((w1, u1), div(w1) * u1, name='a4')

    expr = a3(w2, t2) + a2(v2, u2) + a4(w2, u2)
    a = BilinearForm(((w2, v2), (t2, u2)), expr, name='a')
    print(a)
    print(atomize(a))
    print(evaluate(a))
    # ...

    # ...
    a1 = BilinearForm((v1, u1), laplace(u1) * laplace(v1), name='a1')
    print(a1)
    print(atomize(a1))
    print(evaluate(a1))
    print('')
    # ...

    # ...
    a1 = BilinearForm((v1, u1), inner(hessian(u1), hessian(v1)), name='a1')
    print('================================')
    print(a1)
    print(atomize(a1))
    print(evaluate(a1))
    print('')
    # ...

    # ...
    l1 = LinearForm(v1, x * y * v1, name='11')

    expr = l1(v2)
    l = LinearForm(v2, expr, name='1')
    print(l)
    print(atomize(l))
    print(evaluate(l))
    # ...

    # ...
    l1 = LinearForm(v1, x * y * v1, name='l1')
    l2 = LinearForm(v2, cos(x + y) * v2, name='l2')

    expr = l1(u1) + l2(u2)
    l = LinearForm((u1, u2), expr, name='1')
    print(l)
    print(atomize(l))
    print(evaluate(l))
    # ...

    # ...
    l1 = LinearForm(v1, x * y * v1, name='l1')
    l2 = LinearForm(v2, cos(x + y) * v2, name='l2')

    expr = l1(u1) + alpha * l2(u2)
    l = LinearForm((u1, u2), expr, name='1')
    print(l)
    print(atomize(l))
    print(evaluate(l))
    # ...

    # ...
    l1 = LinearForm(v1, x * y * v1, name='l1')
    l2 = LinearForm(w1, div(w1), name='l2')

    expr = l1(v2) + l2(w2)
    l = LinearForm((v2, w2), expr, name='1')
    print(l)
    print(atomize(l))
    print(evaluate(l))
    # ...

    # ...
    I1 = Integral(x * y, domain, name='I1')

    print(I1)
    print(atomize(I1))
    print(evaluate(I1))
    # ...

    # ...
    expr = F - cos(2 * pi * x) * cos(3 * pi * y)
    expr = dot(grad(expr), grad(expr))
    I2 = Integral(expr, domain, name='I2')

    print(I2)
    print(atomize(I2))
    print(evaluate(I2))
    # ...

    # ...
    expr = F - cos(2 * pi * x) * cos(3 * pi * y)
    expr = dot(grad(expr), grad(expr))
    I2 = Integral(expr, domain, name='I2')

    print(I2)
    print(atomize(I2))
    print(evaluate(I2))
    # ...

    # ... stokes
    V = VectorFunctionSpace('V', domain)
    W = FunctionSpace('W', domain)

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

    a = BilinearForm((v, u), inner(grad(v), grad(u)), name='a')
    b = BilinearForm((v, p), div(v) * p, name='b')
    A = BilinearForm(((v, q), (u, p)), a(v, u) - b(v, p) + b(u, q), name='A')

    print(A)
    print(atomize(A))
    print(evaluate(A))
예제 #15
0
def test_bilinearity_2d_2():
    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')

    V = ProductSpace(V1, V2)
    U = ProductSpace(U1, U2)

    x, y = V1.coordinates

    alpha = Constant('alpha')

    F = Field('F', space=V1)

    # ...
    a1 = BilinearForm((v1, u1), u1 * v1, check=True)
    a = BilinearForm((v2, u2), a1(v2, u2), check=True)
    # ...

    # ...
    a = BilinearForm((v1, u1), dot(grad(v1), grad(u1)), check=True)
    # ...

    # ...
    a1 = BilinearForm((v1, u1), dot(grad(v1), grad(u1)), check=True)
    a = BilinearForm((v2, u2), a1(v2, u2), check=True)
    # ...

    # ...
    a1 = BilinearForm((v1, u1), u1 * v1)
    a2 = BilinearForm((v1, u1), dx(u1) * dx(v1), check=True)
    a = BilinearForm((v2, u2), a1(v2, u2) + a2(v2, u2), check=True)
    # ...

    # ...
    a1 = BilinearForm((v1, u1), u1 * v1, check=True)
    a2 = BilinearForm((v1, u1), dx(u1) * dx(v1), check=True)
    # ...

    # ...
    a1 = BilinearForm((v1, u1), u1 * v1, check=True)
    a2 = BilinearForm((v1, u1), dx(u1) * dx(v1), check=True)
    a = BilinearForm(((v1, v2), (u1, u2)), a1(v1, u2) + a2(v2, u1), check=True)
    # ...

    # ...
    a = BilinearForm((w1, t1),
                     rot(w1) * rot(t1) + div(w1) * div(t1),
                     check=True)
    # ...

    # ...
    a1 = BilinearForm((v1, u1), u1 * v1, check=True)
    a2 = BilinearForm((v1, u1), dx(u1) * dx(v1), check=True)
    a3 = BilinearForm((w1, t1),
                      rot(w1) * rot(t1) + div(w1) * div(t1),
                      check=True)
    a4 = BilinearForm((w1, u1), div(w1) * u1, check=True)

    a = BilinearForm(((w2, v2), (t2, u2)),
                     a3(w2, t2) + a2(v2, u2) + a4(w2, u2),
                     check=True)
    # ...

    # ...
    a1 = BilinearForm((v1, u1), laplace(u1) * laplace(v1), check=True)
    # ...

    # ...
    a1 = BilinearForm((v1, u1), inner(hessian(u1), hessian(v1)), check=True)
    # ...

    # ... stokes
    V = VectorFunctionSpace('V', domain)
    W = FunctionSpace('W', domain)

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

    a = BilinearForm((v, u), inner(grad(v), grad(u)), check=True)
    b = BilinearForm((v, p), div(v) * p, check=True)
    A = BilinearForm(((v, q), (u, p)), a(v, u) - b(v, p) + b(u, q), check=True)
    # ...

    ################################
    #    non bilinear forms
    ################################
    # ...
    with pytest.raises(UnconsistentLinearExpressionError):
        a = BilinearForm((v1, u1), dot(grad(v1), grad(u1)) + v1, check=True)
    # ...

    # ...
    with pytest.raises(UnconsistentLinearExpressionError):
        a = BilinearForm((v1, u1), v1**2 * u1, check=True)
    # ...

    # ...
    with pytest.raises(UnconsistentLinearExpressionError):
        a = BilinearForm((v1, u1), dot(grad(v1), grad(v1)), check=True)