def foo(mesh, family, degree):
    V = FunctionSpace(mesh, family, 1)
    u = TrialFunction(V)
    v = TestFunction(V)

    a = inner(grad(u), grad(v)) * dx
    L = inner(f, v) * dx
    bc = DirichletBC(V, Constant(0.), DomainBoundary())

    u = Function(V)
    solve(a == L, u, bc)

    VV = VectorFunctionSpace(mesh,
                             family,
                             degree=1 if family == 'CR' else degree)
    gradu = Function(VV)
    for i in range(VV.num_sub_spaces()):
        GRAD = weighted_gradient_matrix(mesh, i, family, degree)
        gradu.vector()[VV.sub(i).dofmap().dofs()] = GRAD * u.vector()

    h = mesh.hmin()
    e_l2 = errornorm(u_, u, 'l2')
    grade_l2 = errornorm(u_, u, 'h10')
    grade_w_l2 = errornorm(gradu_, gradu, 'l2')

    return h, e_l2, grade_l2, grade_w_l2
def test_WeightedGradient(V2):
    expr = "+".join(["%d*x[%d]" % (i+1,i) for i in range(2)])
    u = interpolate(Expression(expr, degree=3), V2)
    du = Function(V2)
    wx = weighted_gradient_matrix(V2.mesh(), tuple(range(2)))
    for i in range(2):
        du.vector()[:] = wx[i] * u.vector()
        assert round(du.vector().min() - (i+1), 7) == 0
Example #3
0
def test_WeightedGradient(V2):
    expr = "+".join(["%d*x[%d]" % (i+1,i) for i in range(2)])
    u = interpolate(Expression(expr, degree=3), V2)
    du = Function(V2)
    wx = weighted_gradient_matrix(V2.mesh(), tuple(range(2)))
    for i in range(2):
        du.vector()[:] = wx[i] * u.vector()
        assert round(du.vector().min() - (i+1), 7) == 0
Example #4
0
def divergence_test(mesh):
    V = FunctionSpace(mesh, 'CG', 1)
    W = VectorFunctionSpace(mesh, 'CG', 1)

    u = interpolate(u_, W)
    divu_p = project(div(u), V)                # projected divergence
    e_p = errornorm(divu_, divu_p, 'l2')

    divu_w = Function(V)
    d = mesh.geometry().dim()
    u_i = Function(V)
    for i in range(d):
        u_i.vector()[:] = u.vector()[W.sub(i).dofmap().dofs()]
        GRADi = weighted_gradient_matrix(mesh, i, 'CG', 1)
        # weighted interpolated divergence
        divu_w.vector()[:] += GRADi * u_i.vector()
    e_w = errornorm(divu_, divu_w, 'l2')

    return mesh.hmin(), e_p, e_w
Example #5
0
def divergence_test(mesh):
    V = FunctionSpace(mesh, "CG", 1)
    W = VectorFunctionSpace(mesh, "CG", 1)

    u = interpolate(u_, W)
    divu_p = project(div(u), V)  # projected divergence
    e_p = errornorm(divu_, divu_p, "l2")

    divu_w = Function(V)
    d = mesh.geometry().dim()
    u_i = Function(V)
    for i in range(d):
        u_i.vector()[:] = u.vector()[W.sub(i).dofmap().dofs()]
        GRADi = weighted_gradient_matrix(mesh, i, "CG", 1)
        # weighted interpolated divergence
        divu_w.vector()[:] += GRADi * u_i.vector()
    e_w = errornorm(divu_, divu_w, "l2")

    return mesh.hmin(), e_p, e_w
Example #6
0
def foo(mesh, family, degree):
    V = FunctionSpace(mesh, family, 1)
    u = TrialFunction(V)
    v = TestFunction(V)

    a = inner(grad(u), grad(v))*dx
    L = inner(f, v)*dx
    bc = DirichletBC(V, Constant(0.), DomainBoundary())

    u = Function(V)
    solve(a == L, u, bc)

    VV = VectorFunctionSpace(mesh, family, degree=1 if family == 'CR' else degree)
    gradu = Function(VV)
    for i in range(VV.num_sub_spaces()):
        GRAD = weighted_gradient_matrix(mesh, i, family, degree)
        gradu.vector()[VV.sub(i).dofmap().dofs()] = GRAD*u.vector()

    h = mesh.hmin()
    e_l2 = errornorm(u_, u, 'l2')
    grade_l2 = errornorm(u_, u, 'h10')
    grade_w_l2 = errornorm(gradu_, gradu, 'l2')

    return h, e_l2, grade_l2, grade_w_l2