def test_b_mesh_orientation(celltype): """ Test orientation of boundary facets on 3D meshes """ mesh = dolfinx.BoxMesh( MPI.COMM_WORLD, [np.array([-0.5, -0.5, -0.5]), np.array([0.5, 0.5, 0.5])], [2, 2, 2], cell_type=celltype) b_mesh, bndry_to_mesh = create_boundary_mesh(mesh, MPI.COMM_SELF, True) bdim = b_mesh.topology.dim b_mesh.topology.create_connectivity(bdim, bdim - 1) b_mesh.topology.create_connectivity(bdim - 1, bdim) b_mesh.topology.create_connectivity(bdim, 0) num_cells = b_mesh.topology.index_map(bdim).size_local num_cell_vertices = \ cmesh.cell_num_vertices(cmesh.cell_entity_type(celltype, bdim)) entity_geometry = np.zeros((num_cells, num_cell_vertices), dtype=np.int32) xdofs = b_mesh.geometry.dofmap for i in range(num_cells): xc = xdofs.links(i) for j in range(num_cell_vertices): entity_geometry[i, j] = xc[j] # Compute dot(p0, cross(p1-p0, p2-p0)) for every facet # to check that the orientation is correct # p0 is vector from centre of mesh for i in range(num_cells): p = b_mesh.geometry.x[entity_geometry[i, :]] p[1] -= p[0] p[2] -= p[0] assert (np.linalg.det(p) > 0)
def test_custom_partitioner(tempdir, Nx, cell_type): mpi_comm = MPI.COMM_WORLD Lx = mpi_comm.size points = [np.array([0, 0, 0]), np.array([Lx, Lx, Lx])] mesh = dolfinx.BoxMesh(mpi_comm, points, [Nx, Nx, Nx], cell_type, GhostMode.shared_facet) filename = os.path.join(tempdir, "u1_.xdmf") with XDMFFile(mpi_comm, filename, "w") as file: file.write_mesh(mesh) # Read all geometry data on all processes with XDMFFile(MPI.COMM_SELF, filename, "r") as file: x_global = file.read_geometry_data() # Read topology data with XDMFFile(MPI.COMM_WORLD, filename, "r") as file: cell_type = file.read_cell_type() x = file.read_geometry_data() topo = file.read_topology_data() num_local_coor = x.shape[0] all_sizes = mpi_comm.allgather(num_local_coor) all_sizes.insert(0, 0) all_ranges = np.cumsum(all_sizes) # Testing the premise: coordinates are read contiguously in chunks rank = mpi_comm.rank assert (np.all(x_global[all_ranges[rank]:all_ranges[rank + 1]] == x)) cell = ufl.Cell(dolfinx.cpp.mesh.to_string(cell_type[0])) domain = ufl.Mesh(ufl.VectorElement("Lagrange", cell, cell_type[1])) # Partition mesh in layers, capture geometrical data and topological # data from outer scope def partitioner(*args): midpoints = np.mean(x_global[topo], axis=1) dest = np.floor(midpoints[:, 0] % mpi_comm.size) return dolfinx.cpp.graph.AdjacencyList_int32(dest) ghost_mode = GhostMode.none new_mesh = dolfinx.mesh.create_mesh(mpi_comm, topo, x, domain, ghost_mode, partitioner) new_mesh.topology.create_connectivity_all() tdim = new_mesh.topology.dim assert mesh.topology.index_map( tdim).size_global == new_mesh.topology.index_map(tdim).size_global num_cells = new_mesh.topology.index_map(tdim).size_local cell_midpoints = dolfinx.cpp.mesh.midpoints(new_mesh, tdim, range(num_cells)) assert num_cells > 0 assert np.all(cell_midpoints[:, 0] >= mpi_comm.rank) assert np.all(cell_midpoints[:, 0] <= mpi_comm.rank + 1)
def test_partition_box_mesh(partitioner, Nx, cell_type): mesh = dolfinx.BoxMesh( MPI.COMM_WORLD, [np.array([0, 0, 0]), np.array([1, 1, 1])], [Nx, Nx, Nx], cell_type, GhostMode.shared_facet, partitioner) tdim = mesh.topology.dim c = 6 if cell_type == CellType.tetrahedron else 1 assert mesh.topology.index_map(tdim).size_global == Nx**3 * c assert mesh.topology.index_map(tdim).size_local != 0 assert mesh.topology.index_map(0).size_global == (Nx + 1)**3