Exemple #1
0
def test_distribute_mesh(subset_comm, tempdir, mesh_factory,
                         graph_partitioner):
    func, args = mesh_factory
    mesh = func(*args)

    if not is_simplex(mesh.topology.cell_type):
        return

    encoding = XDMFFile.Encoding.HDF5
    ghost_mode = cpp.mesh.GhostMode.none
    filename = os.path.join(tempdir, "mesh.xdmf")
    comm = mesh.mpi_comm()
    parts = comm.size

    with XDMFFile(mesh.mpi_comm(), filename, encoding) as file:
        file.write(mesh)

    # Use the subset_comm to read and partition mesh, then distribute to all
    # available processes
    with XDMFFile(subset_comm, filename) as file:
        cell_type, points, cells, indices = file.read_mesh_data(subset_comm)

    partition_data = cpp.mesh.partition_cells(subset_comm, parts, cell_type,
                                              cells, graph_partitioner)

    dist_mesh = cpp.mesh.build_from_partition(MPI.comm_world, cell_type,
                                              points, cells, indices,
                                              ghost_mode, partition_data)

    assert (mesh.topology.cell_type == dist_mesh.topology.cell_type)
    assert mesh.num_entities_global(0) == dist_mesh.num_entities_global(0)
    dim = dist_mesh.topology.dim
    assert mesh.num_entities_global(dim) == dist_mesh.num_entities_global(dim)
Exemple #2
0
def test_custom_partition(tempdir, mesh_factory):
    func, args = mesh_factory
    mesh = func(*args)

    if not is_simplex(mesh.topology.cell_type):
        return

    comm = mesh.mpi_comm()
    filename = os.path.join(tempdir, "mesh.xdmf")
    encoding = XDMFFile.Encoding.HDF5
    ghost_mode = cpp.mesh.GhostMode.none

    with XDMFFile(comm, filename, encoding) as file:
        file.write(mesh)

    with XDMFFile(comm, filename) as file:
        cell_type, points, cells, global_indices = file.read_mesh_data(comm)

    # Create a custom partition array
    part = np.zeros(cells.shape[0], dtype=np.int32)
    part[:] = comm.rank

    ghost_procs = cpp.mesh.ghost_cell_mapping(comm, part, cell_type, cells)
    cell_partition = cpp.mesh.PartitionData(part, ghost_procs)
    dist_mesh = cpp.mesh.build_from_partition(comm, cell_type, points, cells,
                                              global_indices, ghost_mode,
                                              cell_partition)

    assert (mesh.topology.cell_type == dist_mesh.topology.cell_type)
    assert mesh.num_entities_global(0) == dist_mesh.num_entities_global(0)
    dim = dist_mesh.topology.dim
    assert mesh.num_entities_global(dim) == dist_mesh.num_entities_global(dim)
Exemple #3
0
def test_mesh_topology_against_basix(mesh_factory, ghost_mode):
    """Test that mesh cells have topology matching to Basix reference
    cell they were created from.
    """
    func, args = mesh_factory
    xfail_ghosted_quads_hexes(func, ghost_mode)
    mesh = func(*args)
    if not is_simplex(mesh.topology.cell_type):
        return

    # Create basix cell
    cell_name = cpp.mesh.to_string(mesh.topology.cell_type)
    basix_celltype = getattr(basix.CellType, cell_name)

    # Initialize all mesh entities and connectivities
    mesh.topology.create_connectivity_all()

    map = mesh.topology.index_map(mesh.topology.dim)
    num_cells = map.size_local + map.num_ghosts
    for i in range(num_cells):
        # Get indices of cell vertices
        vertex_global_indices = mesh.topology.connectivity(
            mesh.topology.dim, 0).links(i)

        # Loop over all dimensions of reference cell topology
        for d, d_topology in enumerate(basix.topology(basix_celltype)):

            # Get entities of dimension d on the cell
            entities = mesh.topology.connectivity(mesh.topology.dim,
                                                  d).links(i)
            if len(entities) == 0:  # Fixup for highest dimension
                entities = (i, )

            # Loop over all entities of fixed dimension d
            for entity_index, entity_topology in enumerate(d_topology):

                # Check that entity vertices map to cell vertices in correct order
                vertices = mesh.topology.connectivity(d, 0).links(
                    entities[entity_index])
                vertices_dolfin = np.sort(vertices)
                vertices2 = np.sort(
                    vertex_global_indices[np.array(entity_topology)])
                assert all(vertices2 == vertices_dolfin)
Exemple #4
0
def test_mesh_topology_against_fiat(mesh_factory,
                                    ghost_mode=cpp.mesh.GhostMode.none):
    """Test that mesh cells have topology matching to FIAT reference
    cell they were created from.
    """
    func, args = mesh_factory
    xfail_ghosted_quads_hexes(func, ghost_mode)
    mesh = func(*args)
    if not is_simplex(mesh.topology.cell_type):
        return

    # Create FIAT cell
    cell_name = cpp.mesh.to_string(mesh.topology.cell_type)
    fiat_cell = FIAT.ufc_cell(cell_name)

    # Initialize all mesh entities and connectivities
    mesh.topology.create_connectivity_all()

    map = mesh.topology.index_map(mesh.topology.dim)
    num_cells = map.size_local + map.num_ghosts
    for i in range(num_cells):
        cell = MeshEntity(mesh, mesh.topology.dim, i)
        # Get mesh-global (MPI-local) indices of cell vertices
        vertex_global_indices = cell.entities(0)

        # Loop over all dimensions of reference cell topology
        for d, d_topology in fiat_cell.get_topology().items():

            # Get entities of dimension d on the cell
            entities = cell.entities(d)
            if len(entities) == 0:  # Fixup for highest dimension
                entities = (i, )

            # Loop over all entities of fixed dimension d
            for entity_index, entity_topology in d_topology.items():

                # Check that entity vertices map to cell vertices in correct order
                entity = MeshEntity(mesh, d, entities[entity_index])
                vertices_dolfin = np.sort(entity.entities(0))
                vertices_fiat = np.sort(
                    vertex_global_indices[np.array(entity_topology)])
                assert all(vertices_fiat == vertices_dolfin)