def test_jacobian_type_1d(): m = UnitIntervalMesh(2) J = m.jacobian(1) assert isinstance(J, np.ndarray), \ "Jacobian must be a numpy array, not a %s" % type(J)
def test_jacobian_shape_1d(): m = UnitIntervalMesh(2) J = m.jacobian(1) assert J.shape == (1, 1), \ "Jacobian must have shape (1, 1), not %s" % str(J.shape)
choices=(1, 2), help="Dimension of the domain.") parser.add_argument("resolution", type=int, nargs=1, help="The number of cells in each direction of the mesh.") if __name__ == "__main__": args = parser.parse_args() resolution = args.resolution[0] cell = (None, ReferenceInterval, ReferenceTriangle)[args.dimension[0]] if cell is ReferenceTriangle: mesh = UnitSquareMesh(resolution, resolution) else: mesh = UnitIntervalMesh(resolution) fig = plt.figure() ax = fig.add_subplot(111) if cell is ReferenceTriangle: for e in mesh.edge_vertices: plt.plot(mesh.vertex_coords[e, 0], mesh.vertex_coords[e, 1], 'k') else: for e in mesh.adjacency(1, 0): plt.plot(mesh.vertex_coords[e, 0], 0. * mesh.vertex_coords[e, 0], 'k') colours = ["black", "red", "blue"] for i, x in enumerate(mesh.vertex_coords):
'''Test integration of a function in a finite element space over a mesh.''' import pytest from fe_utils import UnitSquareMesh, UnitIntervalMesh, \ FunctionSpace, LagrangeElement, Function @pytest.mark.parametrize('degree, mesh', [(d, m) for d in range(1, 8) for m in (UnitIntervalMesh(2), UnitSquareMesh(2, 2))] ) def test_integrate_result_type(degree, mesh): fe = LagrangeElement(mesh.cell, degree) fs = FunctionSpace(mesh, fe) f = Function(fs) i = f.integrate() assert isinstance(i, float), "Integrate must return a float, not a %s" % \ str(type(i)) @pytest.mark.parametrize('degree, mesh', [(d, m) for d in range(1, 8) for m in (UnitIntervalMesh(2), UnitSquareMesh(2, 2))] ) def test_integrate_function(degree, mesh): fe = LagrangeElement(mesh.cell, degree) fs = FunctionSpace(mesh, fe)
def test_jacobian_1d(): m = UnitIntervalMesh(2) assert (np.abs(np.linalg.det(m.jacobian(1))) - .5).round(12) == 0