def test_meshparts(): full_mesh = freefem_reader('test/files/test_parts.msh') part = MeshPart(full_mesh, labels=(1,)) for i_s in [4,5,6,7]: assert (full_mesh.shapes[i_s] == part.shapes[i_s-4]).all() for ii, i_e in enumerate([3,4,5,6,9,10,11,14,15]): assert (full_mesh.edges[i_e]==part.edges[ii]).all() nodes = list(part.iter_nodes()) for ii, i_n in enumerate([3,4,5,6,7,8]): assert (full_mesh.nodes[i_n]==nodes[ii]).all()
def test_reading(): mesh = freefem_reader('test/files/test.msh') expected_nodes = list( map(np.array, [[0.0, 0.0], [0.5, 0.0], [1.0, 0.0], [0.0, 0.5], [0.5, 0.5], [1.0, 0.5], [0.0, 1.0], [0.5, 1.0], [1.0, 1.0]])) expected_nodes_labels = [1, 0, 0, 0, 1, 0, 0, 0, 1] for i in range(len(expected_nodes)): assert (mesh.nodes[i] == expected_nodes[i]).all() assert mesh.nodes_labels == expected_nodes_labels assert mesh.nb['nodes'] == 9 assert mesh.nb['shapes'] == 8 assert mesh.nb['edges'] == 16
def __init__(self, meshfile, labels): if not os.path.exists(meshfile): raise IOError('Unable to locate file {}'.format(meshfile)) self.meshfile = meshfile self.mesh = freefem_reader(meshfile) self.labels = labels self.media = self._identify_media() self.domains = self._identify_domains() dof_per_domain = [_.nb_dof for _ in self.domains] self.domains_dof = [(sum(dof_per_domain[:i_nb]), nb) for i_nb, nb in enumerate(dof_per_domain)] # compute the maximum size of the global matrix self.max_nb_dof = sum(dof_per_domain)
def test_wrong_limits(): full_mesh = freefem_reader('test/files/test_parts.msh') with pytest.raises(ValueError): part = MeshPart(full_mesh, weird_name=None)
def test_unreadablefile(): inexistent_path = 'files/inexistent' with pytest.raises(FileNotFoundError): freefem_reader(inexistent_path)