コード例 #1
0
def to_pyvista(unknown_mesh):
    if isinstance(unknown_mesh, str):
        if unknown_mesh.endswith('dxf'):
            pv_mesh = pyvista.wrap(from_dxf(unknown_mesh))
        else:
            pv_mesh = pyvista.read_meshio(unknown_mesh)
    elif isinstance(unknown_mesh, pyvista.Common):
        pv_mesh = unknown_mesh
    elif isinstance(unknown_mesh, meshio.Mesh):
        pv_mesh = pyvista.from_meshio(unknown_mesh)
    elif isinstance(unknown_mesh, vtk.vtkDataSet):
        pv_mesh = pyvista.wrap(unknown_mesh)
    elif isinstance(unknown_mesh, Mesh):
        pv_mesh = unknown_mesh.pyvista
    elif isinstance(unknown_mesh, pymesh.Mesh):
        # TODO: handle line and volume cells
        cell_array = []
        for cell in unknown_mesh.faces:
            cell_array.append(len(cell))
            cell_array.extend(cell)
        pv_mesh = pyvista.PolyData(unknown_mesh.vertices, np.array(cell_array))
    elif isinstance(unknown_mesh, dict):
        pass

    return pv_mesh
コード例 #2
0
def test_pathlib_read_write(tmpdir, sphere):
    path = pathlib.Path(str(tmpdir.mkdir("tmpdir").join('tmp.vtk')))
    pyvista.save_meshio(path, sphere)
    assert path.is_file()

    mesh = pyvista.read_meshio(path)
    assert isinstance(mesh, pyvista.UnstructuredGrid)
    assert mesh.points.shape == sphere.points.shape
コード例 #3
0
def test_file_format():
    from meshio._exceptions import ReadError, WriteError
    with pytest.raises(ReadError):
        _ = pyvista.read_meshio(examples.hexbeamfile, file_format="bar")

    with pytest.raises((KeyError, WriteError)):
        pyvista.save_meshio("foo.bar", beam, file_format="bar")

    with pytest.raises((KeyError, WriteError)):
        pyvista.save_meshio("foo.npy", beam, file_format="npy")
コード例 #4
0
def test_meshio(mesh_in, tmpdir):
    # Save and read reference mesh using meshio
    filename = tmpdir.mkdir("tmpdir").join("test_mesh.vtk")
    pyvista.save_meshio(filename, mesh_in)
    mesh = pyvista.read_meshio(filename)

    # Assert mesh is still the same
    assert np.allclose(mesh_in.points, mesh.points)
    if (mesh_in.celltypes == 11).all():
        cells = mesh_in.cells.reshape((mesh_in.n_cells, 9))[:,[0,1,2,4,3,5,6,8,7]].ravel()
        assert np.allclose(cells, mesh.cells)
    else:
        assert np.allclose(mesh_in.cells, mesh.cells)
    for k, v in mesh_in.point_arrays.items():
        assert np.allclose(v, mesh.point_arrays[k.replace(" ", "_")])
    for k, v in mesh_in.cell_arrays.items():
        assert np.allclose(v, mesh.cell_arrays[k.replace(" ", "_")])
コード例 #5
0
ファイル: mesh_converter.py プロジェクト: runlevel0/pymapdl
"""
This script convert the file in `gmsh` format to ANSYS `CDB` format.
"""

import pyvista as pv
from ansys.mapdl.reader import save_as_archive

filename = 'from_gmsh.msh'
mesh = pv.read_meshio(filename)
# mesh.plot()  # optionally plot the mesh
mesh.points /= 1000
save_as_archive('archive.cdb', mesh)