def test_local_assembler_1D(): mesh = UnitIntervalMesh(MPI.comm_world, 20) V = FunctionSpace(mesh, 'CG', 1) u = TrialFunction(V) v = TestFunction(V) c = Cell(mesh, 0) a_scalar = 1.0 * dx(domain=mesh) a_vector = v * dx a_matrix = u * v * dx A_scalar = assemble_local(a_scalar, c) A_vector = assemble_local(a_vector, c) A_matrix = assemble_local(a_matrix, c) assert isinstance(A_scalar, float) assert numpy.isclose(A_scalar, 0.05) assert isinstance(A_vector, numpy.ndarray) assert A_vector.shape == (2,) assert numpy.isclose(A_vector[0], 0.025) assert numpy.isclose(A_vector[1], 0.025) assert isinstance(A_matrix, numpy.ndarray) assert A_matrix.shape == (2, 2) assert numpy.isclose(A_matrix[0, 0], 1 / 60) assert numpy.isclose(A_matrix[0, 1], 1 / 120) assert numpy.isclose(A_matrix[1, 0], 1 / 120) assert numpy.isclose(A_matrix[1, 1], 1 / 60)
def test_local_assembler_on_facet_integrals(): mesh = UnitSquareMesh(MPI.comm_world, 4, 4, 'right') Vdgt = FunctionSpace(mesh, 'DGT', 1) v = TestFunction(Vdgt) x = SpatialCoordinate(mesh) w = (1.0 + x[0] ** 2.2 + 1. / (0.1 + x[1] ** 3)) * 300 # Define form that tests that the correct + and - values are used L = w('-') * v('+') * dS # Compile form. This is collective L = Form(L) # Get global cell 10. This will return a cell only on one of the # processes c = get_cell_at(mesh, 5 / 12, 1 / 3, 0) if c: # Assemble locally on the selected cell b_e = assemble_local(L, c) # Compare to values from phonyx (fully independent # implementation) b_phonyx = numpy.array([266.55210302, 266.55210302, 365.49000122, 365.49000122, 0.0, 0.0]) error = sum((b_e - b_phonyx)**2)**0.5 error = float(error) # MPI.max does strange things to numpy.float64 else: error = 0.0 error = MPI.max(MPI.comm_world, float(error)) assert error < 1e-8
def test_local_assembler_on_facet_integrals2(): mesh = UnitSquareMesh(MPI.comm_world, 4, 4) Vu = VectorFunctionSpace(mesh, 'DG', 1) Vv = FunctionSpace(mesh, 'DGT', 1) u = TrialFunction(Vu) v = TestFunction(Vv) n = FacetNormal(mesh) # Define form a = dot(u, n) * v * ds for R in '+-': a += dot(u(R), n(R)) * v(R) * dS # Compile form. This is collective a = Form(a) # Get global cell 0. This will return a cell only on one of the # processes c = get_cell_at(mesh, 1 / 6, 1 / 12, 0) if c: A_e = assemble_local(a, c) A_correct = numpy.array([[0, 1 / 12, 1 / 24, 0, 0, 0], [0, 1 / 24, 1 / 12, 0, 0, 0], [-1 / 12, 0, -1 / 24, 1 / 12, 0, 1 / 24], [-1 / 24, 0, -1 / 12, 1 / 24, 0, 1 / 12], [0, 0, 0, -1 / 12, -1 / 24, 0], [0, 0, 0, -1 / 24, -1 / 12, 0]]) error = ((A_e - A_correct)**2).sum()**0.5 error = float(error) # MPI.max does strange things to numpy.float64 else: error = 0.0 error = MPI.max(MPI.comm_world, float(error)) assert error < 1e-16