Exemplo n.º 1
0
def _(V: fem.FunctionSpace, entities=None):
    """Creates a vtk mesh topology (topology array and array of cell
    types) that is based on degree of freedom coordinate. Note that this
    function supports Lagrange elements (continuous and discontinuous)
    only.

    """
    family = V.ufl_element().family()
    if not (family in ['Discontinuous Lagrange', "Lagrange", "DQ", "Q"]):
        raise RuntimeError(
            "Can only create meshes from Continuous or Discontinuous function-spaces"
        )
    if V.ufl_element().degree() == 0:
        raise RuntimeError("Cannot create topology from cellwise constants.")

    mesh = V.mesh
    if entities is None:
        num_cells = mesh.topology.index_map(mesh.topology.dim).size_local
        entities = np.arange(num_cells, dtype=np.int32)
    else:
        num_cells = entities.size

    dofmap = V.dofmap
    num_dofs_per_cell = V.dofmap.dof_layout.num_dofs
    degree = V.ufl_element().degree()
    cell_type = mesh.topology.cell_type
    if family == "Discontinuous Lagrange":
        perm = np.array(_perm_dg[cell_type][degree], dtype=np.int32)
    elif family == "DQ":
        perm = np.array(_perm_dq[cell_type][degree], dtype=np.int32)
    else:
        perm = np.argsort(cpp.io.perm_vtk(cell_type, num_dofs_per_cell))

    if degree == 1:
        cell_types = np.full(num_cells,
                             _first_order_vtk[mesh.topology.cell_type])
    else:
        warnings.warn("Plotting of higher order functions is experimental.")
        cell_types = np.full(num_cells,
                             cpp.io.get_vtk_cell_type(mesh, mesh.topology.dim))

    topology = np.zeros((num_cells, num_dofs_per_cell + 1), dtype=np.int32)
    topology[:, 0] = num_dofs_per_cell
    dofmap_ = dofmap.list.array.reshape(dofmap.list.num_nodes,
                                        num_dofs_per_cell)

    topology[:, 1:] = dofmap_[:num_cells, perm]
    return topology.reshape(1, -1)[0], cell_types
Exemplo n.º 2
0
def _(V: fem.FunctionSpace, entities=None):
    """Creates a VTK mesh topology (topology array and array of cell
    types) that is based on the degree-of-freedom coordinates. Note that
    this function supports Lagrange elements (continuous and
    discontinuous) only.

    """
    if not (V.ufl_element().family()
            in ['Discontinuous Lagrange', "Lagrange", "DQ", "Q"]):
        raise RuntimeError(
            "Can only create meshes from continuous or discontinuous Lagrange spaces"
        )

    degree = V.ufl_element().degree()
    if degree == 0:
        raise RuntimeError("Cannot create topology from cellwise constants.")

    # Use all local cells if not supplied
    msh = V.mesh
    tdim = msh.topology.dim
    if entities is None:
        entities = range(msh.topology.index_map(tdim).size_local)

    dofmap = V.dofmap
    num_dofs_per_cell = V.dofmap.dof_layout.num_dofs
    cell_type = msh.topology.cell_type
    perm = np.argsort(_cpp.io.perm_vtk(cell_type, num_dofs_per_cell))

    vtk_type = _first_order_vtk[
        cell_type] if degree == 1 else _cpp.io.get_vtk_cell_type(
            cell_type, tdim)
    cell_types = np.full(len(entities), vtk_type)

    topology = np.zeros((len(entities), num_dofs_per_cell + 1), dtype=np.int32)
    topology[:, 0] = num_dofs_per_cell
    dofmap_ = dofmap.list.array.reshape(dofmap.list.num_nodes,
                                        num_dofs_per_cell)

    topology[:, 1:] = dofmap_[:len(entities), perm]
    return topology.reshape(1, -1)[0], cell_types, V.tabulate_dof_coordinates()