Example #1
0
def demo_3d_divergence(mesh, u_exact, divu_exact):
    # Compute the divergence with Gauss theorem
    cr_divu = gauss_divergence(u_exact, mesh=mesh)

    # Represent the exact divergence on DG
    rank = divu_exact.value_rank()
    if rank == 0:
        DG = FunctionSpace(mesh, 'DG', 0)
    elif rank in [1, 2]:
        DG = VectorFunctionSpace(mesh, 'DG', 0)
    divu = interpolate(divu_exact, DG)

    # Compute the l^oo and l^1 norms
    divu.vector().axpy(-1, cr_divu.vector())
    error_Loo = divu.vector().norm('linf') / DG.dim()
    error_L2 = divu.vector().norm('l2') / DG.dim()
    h = mesh.hmin()

    # Create global measure of h and errors
    comm = mpi_comm_world()
    h = MPI.min(comm, mesh.hmin())
    error_Loo = MPI.max(comm, error_Loo)
    error_L2 = MPI.max(comm, error_L2)

    return h, error_Loo, error_L2
def demo_3d_divergence(mesh, u_exact, divu_exact):
    # Compute the divergence with Gauss theorem
    cr_divu = gauss_divergence(u_exact, mesh=mesh)

    # Represent the exact divergence on DG
    rank = divu_exact.value_rank()
    if rank == 0:
        DG = FunctionSpace(mesh, 'DG', 0)
    elif rank in [1, 2]:
        DG = VectorFunctionSpace(mesh, 'DG', 0)
    divu = interpolate(divu_exact, DG)

    # Compute the l^oo and l^1 norms
    divu.vector().axpy(-1, cr_divu.vector())
    error_Loo = divu.vector().norm('linf')/DG.dim()
    error_L2 = divu.vector().norm('l2')/DG.dim()
    h = mesh.hmin()

    # Create global measure of h and errors
    comm = mpi_comm_world()
    h = MPI.min(comm, mesh.hmin())
    error_Loo = MPI.max(comm, error_Loo)
    error_L2 = MPI.max(comm, error_L2)

    return h, error_Loo, error_L2
Example #3
0
def test_GaussDivergence(mesh):
    dim = mesh.topology().dim()
    expr = ["%s*x[%s]" % (dim, i) for i in range(dim)]
    V = VectorFunctionSpace(mesh, 'CG', 1)
    u = interpolate(Expression(tuple(expr)), V)
    divu = gauss_divergence(u)
    DIVU = divu.vector().array()
    point_0 = all(abs(DIVU - dim * dim) < 1E-13)
    if MPI.rank(mpi_comm_world()) == 0:
        assert point_0
def test_GaussDivergence(mesh):
    dim = mesh.topology().dim()
    expr = ["%s*x[%s]" % (dim, i) for i in range(dim)]
    V = VectorFunctionSpace(mesh, "CG", 1)
    u = interpolate(Expression(tuple(expr)), V)
    divu = gauss_divergence(u)
    DIVU = divu.vector().array()
    point_0 = all(abs(DIVU - dim * dim) < 1e-13)
    if MPI.rank(mpi_comm_world()) == 0:
        assert point_0
def test_GaussDivergence(mesh):
    dim = mesh.topology().dim()
    expr = ["%s*x[%s]" % (dim,i) for i in range(dim)]
    V = VectorFunctionSpace(mesh, 'CG', 1)
    u = interpolate(Expression(tuple(expr), degree=1), V)
    divu = gauss_divergence(u)
    DIVU = divu.vector().get_local()
    point_0 = all(abs(DIVU - dim*dim) < 1E-13)
    if MPI.rank(MPI.comm_world) == 0:
        assert point_0