Esempio n. 1
0
def test_calculus_2d_1():
    domain = Domain('Omega', dim=2)

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

    alpha, beta, gamma = [Constant(i) for i in ['alpha', 'beta', 'gamma']]

    f, g, h = elements_of(V, names='f, g, h')
    F, G, H = elements_of(W, names='F, G, H')

    # ... scalar gradient properties
    assert (grad(f + g) == grad(f) + grad(g))
    assert (grad(alpha * h) == alpha * grad(h))
    assert (grad(alpha * f + beta * g) == alpha * grad(f) + beta * grad(g))

    assert (grad(f * g) == f * grad(g) + g * grad(f))
    assert (grad(f / g) == -f * grad(g) / g**2 + grad(f) / g)

    assert (expand(grad(f * g * h)) == f * g * grad(h) + f * h * grad(g) +
            g * h * grad(f))
    # ...

    # ... vector gradient properties
    assert (grad(F + G) == grad(F) + grad(G))
    assert (grad(alpha * H) == alpha * grad(H))
    assert (grad(alpha * F + beta * G) == alpha * grad(F) + beta * grad(G))

    assert (grad(dot(F, G)) == convect(F, G) + convect(G, F) +
            cross(F, curl(G)) - cross(curl(F), G))
    # ...

    # ... curl properties
    assert (curl(f + g) == curl(f) + curl(g))
    assert (curl(alpha * h) == alpha * curl(h))
    assert (curl(alpha * f + beta * g) == alpha * curl(f) + beta * curl(g))
    # ...

    # ... laplace properties
    assert (laplace(f + g) == laplace(f) + laplace(g))
    assert (laplace(alpha * h) == alpha * laplace(h))
    assert (laplace(alpha * f + beta * g) == alpha * laplace(f) +
            beta * laplace(g))
    # ...

    # ... divergence properties
    assert (div(F + G) == div(F) + div(G))
    assert (div(alpha * H) == alpha * div(H))
    assert (div(alpha * F + beta * G) == alpha * div(F) + beta * div(G))

    assert (div(cross(F, G)) == -dot(F, curl(G)) + dot(G, curl(F)))
    # ...

    # ... rot properties
    assert (rot(F + G) == rot(F) + rot(G))
    assert (rot(alpha * H) == alpha * rot(H))
    assert (rot(alpha * F + beta * G) == alpha * rot(F) + beta * rot(G))
Esempio n. 2
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 = element_of(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)
Esempio n. 3
0
def test_Cross(dim):

    domain = Domain('Omega', dim=dim)
    W = VectorFunctionSpace('W', domain)
    a, b, c = elements_of(W, names='a, b, c')
    r = Constant('r')

    # Anti-commutativity (anti-symmetry)
    assert cross(a, b) == -cross(b, a)

    # Bilinearity: vector addition
    assert cross(a, b + c) == cross(a, b) + cross(a, c)
    assert cross(a + b, c) == cross(a, c) + cross(b, c)

    # Bilinearity: scalar multiplication
    assert cross(a, r * b) == r * cross(a, b)
    assert cross(r * a, b) == r * cross(a, b)

    # Special case: null vector
    assert cross(a, 0) == 0
    assert cross(0, a) == 0

    # Special case: two arguments are the same
    assert cross(a, a) == 0