How to use the meshio.write_points_cells function in meshio

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 / optimesh / test / test_chen_holst_odt.py View on Github external
geom = pygmsh.built_in.Geometry()
        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
github nschloe / optimesh / test / meshes.py View on Github external
def circle_rotated():
    pts, cells = circle_random()
    # 
    theta = numpy.pi / 4
    k = numpy.array([1.0, 0.0, 0.0])
    pts = (
        pts * numpy.cos(theta)
        + numpy.cross(k, pts) * numpy.sin(theta)
        + numpy.outer(numpy.einsum("ij,j->i", pts, k), k) * (1.0 - numpy.cos(theta))
    )
    meshio.write_points_cells("out.vtk", pts, {"triangle": cells})
    return pts, cells
github tianyikillua / paraview-meshio / meshioPlugin.py View on Github external
point_data = _read_data(mesh.GetPointData())
        field_data = _read_data(mesh.GetFieldData())

        # Read cell data
        cell_data_flattened = _read_data(mesh.GetCellData())
        cell_data = {}
        for cell_type in cells:
            vtk_cell_type = meshio_to_vtk_type[cell_type]
            mask_cell_type = cell_types == vtk_cell_type
            cell_data[cell_type] = {}
            for name, array in cell_data_flattened.items():
                cell_data[cell_type][name] = array[mask_cell_type]

        # Use meshio to write mesh
        meshio.write_points_cells(
            self._filename,
            points,
            cells,
            point_data=point_data,
            cell_data=cell_data,
            field_data=field_data,
        )

        return 1
github pyvista / pyvista / pyvista / utilities / fileio.py View on Github external
mapper[cell_type].append(i)
    cells = {vtk_to_meshio_type[k]: np.vstack(v) for k, v in cells.items()}
    mapper = {vtk_to_meshio_type[k]: v for k, v in mapper.items()}

    # Get point data
    point_data = {k.replace(" ", "_"): v for k, v in mesh.point_arrays.items()}

    # Get cell data
    vtk_cell_data = mesh.cell_arrays
    cell_data = {
        k: {kk.replace(" ", "_"): vv[v] for kk, vv in vtk_cell_data.items()}
        for k, v in mapper.items()
    } if vtk_cell_data else {}

    # Save using meshio
    meshio.write_points_cells(
        filename = filename,
        points = np.array(mesh.points),
        cells = cells,
        point_data = point_data,
        cell_data = cell_data,
        file_format = file_format,
        **kwargs
    )
github nschloe / optimesh / examples / compare-gmsh-quality.py View on Github external
def get_poisson_condition(pts, cells):
    # Still can't initialize a mesh from points, cells
    filename = "mesh.xdmf"
    meshio.write_points_cells(filename, pts, {"triangle": cells})
    mesh = Mesh()
    with XDMFFile(filename) as f:
        f.read(mesh)

    # build Laplace matrix with Dirichlet boundary using dolfin
    V = FunctionSpace(mesh, "Lagrange", 1)

    u = TrialFunction(V)
    v = TestFunction(V)
    a = inner(grad(u), grad(v)) * dx
    u0 = Constant(0.0)
    bc = DirichletBC(V, u0, "on_boundary")
    f = Constant(1.0)
    L = f * v * dx

    A = assemble(a)
github nschloe / meshio / tools / paraview-meshio-plugin.py View on Github external
point_data = _read_data(mesh.GetPointData())
        field_data = _read_data(mesh.GetFieldData())

        # Read cell data
        cell_data_flattened = _read_data(mesh.GetCellData())
        cell_data = {}
        for name, array in cell_data_flattened.items():
            cell_data[name] = []
            for cell_type in cells_dict:
                vtk_cell_type = meshio_to_vtk_type[cell_type]
                mask_cell_type = cell_types == vtk_cell_type
                cell_data[name].append(array[mask_cell_type])

        # Use meshio to write mesh
        meshio.write_points_cells(
            self._filename,
            points,
            cells,
            point_data=point_data,
            cell_data=cell_data,
            field_data=field_data,
        )
        return 1
github nschloe / colorio / colorio / _color_space.py View on Github external
import meshio
        import meshzoo

        points, cells = meshzoo.cube(nx=n, ny=n, nz=n)

        if cut_000:
            # cut off [0, 0, 0] to avoid division by 0 in the xyz conversion
            points = points[1:]
            cells = cells[~numpy.any(cells == 0, axis=1)]
            cells -= 1

        srgb_linear = SrgbLinear()
        pts = self.from_xyz100(srgb_linear.to_xyz100(points.T)).T
        assert pts.shape[1] == 3
        rgb = srgb_linear.to_srgb1(points)
        meshio.write_points_cells(
            filename, pts, {"tetra": cells}, point_data={"srgb": rgb}
        )
github nschloe / optimesh / optimesh / cli / main.py View on Github external
)
        else:
            X, cls = method(
                mesh.points,
                cells[cell_idx],
                args.tolerance,
                args.max_num_steps,
                omega=args.omega,
                verbose=~args.quiet,
                step_filename_format=args.step_filename_format,
            )

        cells[cell_idx] = cls

    q = meshplex.MeshTri(X, cls).cell_quality
    meshio.write_points_cells(
        args.output_file,
        X,
        {"triangle": cells},
        cell_data={"triangle": {"cell_quality": q}},
    )
    return