Пример #1
0
def test_higher_order_coordinate_map(points, celltype):
    """
    Computes physical coordinates of a cell, based on the coordinate map.
    """
    cells = np.array([range(len(points))])
    mesh = Mesh(MPI.comm_world, celltype, points, cells, [], GhostMode.none)
    V = FunctionSpace(mesh, ("Lagrange", mesh.degree()))

    X = V.element.dof_reference_coordinates()
    coord_dofs = mesh.coordinate_dofs().entity_points()
    x_g = mesh.geometry.points

    cmap = fem.create_coordinate_map(mesh.ufl_domain())
    x_coord_new = np.zeros([len(points), mesh.geometry.dim])

    i = 0
    for node in range(len(points)):
        x_coord_new[i] = x_g[coord_dofs[0, node], :mesh.geometry.dim]
        i += 1

    x = np.zeros(X.shape)
    cmap.push_forward(x, X, x_coord_new)

    assert (np.allclose(x[:, 0], X[:, 0]))
    assert (np.allclose(x[:, 1], 2 * X[:, 1]))

    if mesh.geometry.dim == 3:
        assert (np.allclose(x[:, 2], 3 * X[:, 2]))
Пример #2
0
def test_higher_order_tetra_coordinate_map(order):
    """
    Computes physical coordinates of a cell, based on the coordinate map.
    """
    celltype = CellType.tetrahedron
    points = np.array([[0, 0, 0], [1, 0, 0], [0, 2, 0], [0, 0, 3],
                       [0, 4 / 3, 1], [0, 2 / 3, 2], [2 / 3, 0, 1],
                       [1 / 3, 0, 2], [2 / 3, 2 / 3, 0], [1 / 3, 4 / 3, 0],
                       [0, 0, 1], [0, 0, 2], [0, 2 / 3, 0], [0, 4 / 3, 0],
                       [1 / 3, 0, 0], [2 / 3, 0, 0], [1 / 3, 2 / 3, 1],
                       [0, 2 / 3, 1], [1 / 3, 0, 1], [1 / 3, 2 / 3, 0]])

    if order == 1:
        points = np.array(
            [points[0, :], points[1, :], points[2, :], points[3, :]])
    elif order == 2:
        points = np.array([
            points[0, :], points[1, :], points[2, :], points[3, :],
            [0, 1, 3 / 2], [1 / 2, 0, 3 / 2], [1 / 2, 1, 0], [0, 0, 3 / 2],
            [0, 1, 0], [1 / 2, 0, 0]
        ])
    cells = np.array([range(len(points))])
    mesh = Mesh(MPI.comm_world, celltype, points, cells, [], GhostMode.none)
    V = FunctionSpace(mesh, ("Lagrange", order))
    X = V.element.dof_reference_coordinates()
    coord_dofs = mesh.coordinate_dofs().entity_points()
    x_g = mesh.geometry.points

    cmap = fem.create_coordinate_map(mesh.ufl_domain())
    x_coord_new = np.zeros([len(points), mesh.geometry.dim])

    i = 0
    for node in range(len(points)):
        x_coord_new[i] = x_g[coord_dofs[0, node], :mesh.geometry.dim]
        i += 1

    x = np.zeros(X.shape)
    cmap.push_forward(x, X, x_coord_new)
    assert (np.allclose(x[:, 0], X[:, 0]))
    assert (np.allclose(x[:, 1], 2 * X[:, 1]))
    assert (np.allclose(x[:, 2], 3 * X[:, 2]))