Exemple #1
0
def test_separate_by_order():
    u, v = Variables('u v')
    c, f = Constants('c f')
    strong_form = StrongForm(c*grad(div(u)) + div(v) - f + dot(c, grad(u)))

    order_dict = strong_form.separate_by_order()
    assert(order_dict[0] == -f)
    assert(order_dict[1] == div(v) + dot(c, grad(u)))
    assert(order_dict[2] == c*grad(div(u)))
Exemple #2
0
def test_extract_transport_coefficients():
    u = Variable('u', rank=0)
    a, b, d = Coefficients('a b d', rank=0)
    b, e = Coefficients('b e', rank=1)
    c, = Coefficients('c', rank=2)

    eqn = Dt(a*u) + div(b*u + c*grad(u)) + d*u + dot(e, grad(u))
    strong_form = StrongForm(eqn)

    coeffs = {'diffusion': c,
              'reaction': d*u,
              'hamiltonian': dot(e, grad(u)),
              'potential': u,
              'mass': Dt(a*u),
              'advection': b*u,
              }
    sf_coeffs = strong_form.extract_transport_coefficients()
    assert(coeffs == sf_coeffs)
    eqn =  d*u + dot(e, grad(u)) + Dt(a*u) + div(b*u) + div(c*grad(u))
    strong_form = StrongForm(eqn)
    sf_coeffs = strong_form.extract_transport_coefficients()
    assert(coeffs == sf_coeffs)