def test_save_and_read_mesh_3D(tempdir): filename = os.path.join(tempdir, "mesh3d.h5") # Write to file mesh0 = UnitCubeMesh(MPI.comm_world, 10, 10, 10) mesh_file = HDF5File(mesh0.mpi_comm(), filename, "w") mesh_file.write(mesh0, "/my_mesh") mesh_file.close() # Read from file mesh_file = HDF5File(mesh0.mpi_comm(), filename, "r") mesh1 = mesh_file.read_mesh("/my_mesh", False, cpp.mesh.GhostMode.none) mesh_file.close() assert mesh0.num_entities_global(0) == mesh1.num_entities_global(0) dim = mesh0.topology.dim assert mesh0.num_entities_global(dim) == mesh1.num_entities_global(dim) # Read from file, and use partition from file mesh_file = HDF5File(mesh0.mpi_comm(), filename, "r") mesh2 = mesh_file.read_mesh("/my_mesh", True, cpp.mesh.GhostMode.none) mesh_file.close() assert mesh0.num_cells() == mesh2.num_cells() dim = mesh0.topology.dim assert mesh0.num_entities_global(dim) == mesh1.num_entities_global(dim)
def test_save_and_load_3d_mesh(tempdir, encoding, cell_type): filename = os.path.join(tempdir, "mesh_3D.xdmf") mesh = UnitCubeMesh(MPI.comm_world, 4, 4, 4, cell_type) with XDMFFile(mesh.mpi_comm(), filename, encoding=encoding) as file: file.write(mesh) with XDMFFile(MPI.comm_world, filename) as file: mesh2 = file.read_mesh(cpp.mesh.GhostMode.none) assert mesh.num_entities_global(0) == mesh2.num_entities_global(0) dim = mesh.topology.dim assert mesh.num_entities_global(dim) == mesh2.num_entities_global(dim)
def test_UnitHexMesh(): mesh = UnitCubeMesh(MPI.comm_world, 5, 7, 9, CellType.hexahedron) assert mesh.num_entities_global(0) == 480 assert mesh.num_entities_global(3) == 315 assert mesh.geometry.dim == 3 assert MPI.sum(mesh.mpi_comm(), mesh.topology.index_map(0).size_local) == 480
def test_UnitCubeMeshDistributed(): """Create mesh of unit cube.""" mesh = UnitCubeMesh(MPI.comm_world, 5, 7, 9) assert mesh.num_entities_global(0) == 480 assert mesh.num_entities_global(3) == 1890 assert mesh.geometry.dim == 3 assert MPI.sum(mesh.mpi_comm(), mesh.topology.index_map(0).size_local) == 480
def test_RefineUnitCubeMesh_keep_partition(): """Refine mesh of unit cube.""" mesh = UnitCubeMesh(MPI.comm_world, 5, 7, 9) mesh.create_entities(1) mesh = refine(mesh, False) assert mesh.num_entities_global(0) == 3135 assert mesh.num_entities_global(3) == 15120 Q = FunctionSpace(mesh, ("CG", 1)) assert(Q)
def test_small_mesh(): mesh3d = UnitCubeMesh(MPI.comm_world, 1, 1, 1) gdim = mesh3d.geometry.dim assert mesh3d.num_entities_global(gdim) == 6 mesh2d = UnitSquareMesh(MPI.comm_world, 1, 1) gdim = mesh2d.geometry.dim assert mesh2d.num_entities_global(gdim) == 2 mesh1d = UnitIntervalMesh(MPI.comm_world, 2) gdim = mesh1d.geometry.dim assert mesh1d.num_entities_global(gdim) == 2