How to use meshio - 10 common examples

To help you get started, we’ve selected a few meshio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / meshio / meshio / stl / _stl.py View on Github external
# )

    # numpy.loadtxt is super slow
    # data = numpy.loadtxt(
    #     f,
    #     comments=["solid", "facet", "outer loop", "endloop", "endfacet", "endsolid"],
    #     usecols=(1, 2, 3),
    # )
    data = iter_loadtxt(
        f,
        comments=("solid", "outer loop", "endloop", "endfacet", "endsolid"),
        # usecols=(1, 2, 3),
    )

    if data.shape[0] % 4 != 0:
        raise ReadError()

    # split off the facet normals
    facet_rows = numpy.zeros(len(data), dtype=bool)
    facet_rows[0::4] = True
    facet_normals = data[facet_rows]
    data = data[~facet_rows]

    facets = numpy.split(data, data.shape[0] // 3)
    points, cells = data_from_facets(facets)
    return Mesh(points, cells, cell_data={"facet_normals": [facet_normals]})
github nschloe / meshio / meshio / flac3d / _flac3d.py View on Github external
labels[0] = "None"
    if field_data:
        labels.update({v[0]: k for k, v in field_data.items() if v[1] == 3})
    return zgroups, labels


def _write_table(f, data, ncol=20):
    """Write zone group data table."""
    nrow = len(data) // ncol
    lines = numpy.split(data, numpy.full(nrow, ncol).cumsum())
    for line in lines:
        if len(line):
            f.write(" {}\n".format(" ".join([str(l) for l in line])))


register("flac3d", [".f3grid"], read, {"flac3d": write})
github nschloe / meshio / meshio / flac3d / _flac3d.py View on Github external
return zgroups, labels


def _write_zgroup(f, data, ncol=20):
    """
    Write zone group data.
    """
    nrow = len(data) // ncol
    lines = numpy.reshape(data[: nrow * ncol], (nrow, ncol)).tolist()
    if data[nrow * ncol :]:
        lines.append(data[nrow * ncol :])
    for line in lines:
        f.write(" {}\n".format(" ".join([str(l) for l in line])))


register("flac3d", [".f3grid"], read, {"flac3d": write})
github nschloe / pygmsh / test / test_rectangle.py View on Github external
def test():
    geom = pygmsh.built_in.Geometry()

    geom.add_rectangle(0.0, 1.0, 0.0, 1.0, 0.0, 0.1)

    ref = 1.0
    mesh = pygmsh.generate_mesh(geom, mesh_file_type="vtk")
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh


if __name__ == "__main__":
    import meshio

    meshio.write("rectangle.vtu", test())
github nschloe / pygmsh / test / test_rotated_layers.py View on Github external
point_on_axis=[0.0, 0.0, 0.0],
        angle=0.5 * pi,
        num_layers=5,
        recombine=True,
    )

    ref = 3.98156496566
    mesh = pygmsh.generate_mesh(geom)
    assert abs(compute_volume(mesh) - ref) < 1.0e-2 * ref
    return mesh


if __name__ == "__main__":
    import meshio

    meshio.write("rotated_layers.vtu", test())
github nschloe / meshio / test / test_vtu.py View on Github external
def test(mesh, data_type):
    binary, compression = data_type

    def writer(*args, **kwargs):
        return meshio.vtu.write(*args, binary=binary, compression=compression, **kwargs)

    # ASCII files are only meant for debugging, VTK stores only 11 digits
    # 
    tol = 1.0e-15 if binary else 1.0e-10
    helpers.write_read(writer, meshio.vtu.read, mesh, tol)
github nschloe / meshio / test / test_helpers.py View on Github external
def test_write_buffer(mesh, tmpdir):
    tmp_path = str(tmpdir.join("tmp.obj"))
    with open(tmp_path, "w") as f:
        meshio.write(f, mesh, "obj")
    assert Path(tmp_path).is_file()
github nschloe / meshio / test / performance.py View on Github external
def generate_mesh():
    """Generates a fairly large mesh.
    """
    # import meshzoo
    # points, cells = meshzoo.rectangle(nx=300, ny=300)
    # return meshio.Mesh(points, {"triangle": cells})
    if os.path.isfile("cache.xdmf"):
        mesh = meshio.read("cache.xdmf")
    else:
        s = pygalmesh.Ball([0, 0, 0], 1.0)
        mesh = pygalmesh.generate_mesh(s, cell_size=2.0e-2, verbose=True)
        # mesh = pygalmesh.generate_mesh(s, cell_size=1.0e-1, verbose=True)
        mesh.cells = {"tetra": mesh.cells["tetra"]}
        mesh.point_data = []
        mesh.cell_data = {"tetra": {}}
        mesh.write("cache.xdmf")
    print(mesh)
    return mesh
github nschloe / optimesh / test / meshes.py View on Github external
def pacman():
    this_dir = os.path.dirname(os.path.realpath(__file__))
    mesh = meshio.read(os.path.join(this_dir, "meshes", "pacman.vtk"))
    return mesh.points[:, :2], mesh.get_cells_type("triangle")
github nschloe / optimesh / test / test_chen_holst_odt.py View on Github external
geom.add_circle(
            [0.0, 0.0, 0.0],
            1.0,
            5.0e-3,
            num_sections=4,
            # If compound==False, the section borders have to be points of the
            # discretization. If using a compound circle, they don't; gmsh can
            # choose by itself where to point the circle points.
            compound=True,
        )
        X, cells, _, _, _ = pygmsh.generate_mesh(
            geom, fast_conversion=True, remove_faces=True
        )
        meshio.write_points_cells(filename, X, cells)

    mesh = meshio.read(filename)
    c = mesh.cells["triangle"].astype(numpy.int)

    X, cells = optimesh.chen_holst.odt(mesh.points, c, 1.0e-3, 100)
    return