How to use the meshio._mesh.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 / meshio / meshio / off / _off.py View on Github external
# This next line contains:
    #   
    num_verts, num_faces, _ = line.split(" ")
    num_verts = int(num_verts)
    num_faces = int(num_faces)

    verts = numpy.fromfile(f, dtype=float, count=3 * num_verts, sep=" ").reshape(
        num_verts, 3
    )

    data = numpy.fromfile(f, dtype=int, count=4 * num_faces, sep=" ").reshape(
        num_faces, 4
    )
    if not numpy.all(data[:, 0] == 3):
        raise ReadError("Can only read triangular faces")
    cells = [Cells("triangle", data[:, 1:])]

    return verts, cells
github nschloe / meshio / meshio / avsucd / _avsucd.py View on Github external
cells = []
    cell_ids = {}
    cell_data = {"avsucd:material": []}
    count = 0
    for _ in range(num_cells):
        line = f.readline().strip().split()
        cell_id = int(line[0])
        cell_mat = int(line[1])
        cell_type = avsucd_to_meshio_type[line[2]]
        corner = [point_ids[int(pid)] for pid in line[3:]]

        if len(cells) > 0 and cells[-1].type == cell_type:
            cells[-1].data.append(corner)
            cell_data["avsucd:material"][-1].append(cell_mat)
        else:
            cells.append(Cells(cell_type, [corner]))
            cell_data["avsucd:material"].append([cell_mat])

        cell_ids[cell_id] = count
        count += 1

    # Convert to numpy arrays
    for k, c in enumerate(cells):
        cells[k] = Cells(c.type, numpy.array(c.data)[:, avsucd_to_meshio_order[c.type]])
        cell_data["avsucd:material"][k] = numpy.array(cell_data["avsucd:material"][k])
    return cell_ids, cells, cell_data
github nschloe / meshio / meshio / h5m / _h5m.py View on Github external
point_data[name] = dataset[()]

    # # Assert that the GLOBAL_IDs are contiguous.
    # point_gids = dset['nodes']['tags']['GLOBAL_ID'][()]
    # point_start_gid = dset['nodes']['coordinates'].attrs['start_id']
    # point_end_gid = point_start_gid + len(point_gids) - 1
    # assert all(point_gids == range(point_start_gid, point_end_gid + 1))

    h5m_to_meshio_type = {"Edge2": "line", "Tri3": "triangle", "Tet4": "tetra"}
    cells = []
    cell_data = {}
    for h5m_type, data in dset["elements"].items():
        meshio_type = h5m_to_meshio_type[h5m_type]
        conn = data["connectivity"]
        # Note that the indices are off by 1 in h5m.
        cells.append(Cells(meshio_type, conn[()] - 1))

        # TODO bring cell data back
        # if 'tags' in data:
        #     for name, dataset in data['tags'].items():
        #         cell_data[name] = dataset[()]

    # The `sets` in H5M are special in that they represent a segration of data
    # in the current file, particularly by a load balancer (Metis, Zoltan,
    # etc.). This segregation has no equivalent in other data types, but is
    # certainly worthwhile visualizing.
    # Hence, we will translate the sets into cell data with the prefix "set::"
    # here.
    field_data = {}
    # TODO deal with sets
    # if 'sets' in dset and 'contents' in dset['sets']:
    #     # read sets
github nschloe / meshio / meshio / avsucd / _avsucd.py View on Github external
cell_type = avsucd_to_meshio_type[line[2]]
        corner = [point_ids[int(pid)] for pid in line[3:]]

        if len(cells) > 0 and cells[-1].type == cell_type:
            cells[-1].data.append(corner)
            cell_data["avsucd:material"][-1].append(cell_mat)
        else:
            cells.append(Cells(cell_type, [corner]))
            cell_data["avsucd:material"].append([cell_mat])

        cell_ids[cell_id] = count
        count += 1

    # Convert to numpy arrays
    for k, c in enumerate(cells):
        cells[k] = Cells(c.type, numpy.array(c.data)[:, avsucd_to_meshio_order[c.type]])
        cell_data["avsucd:material"][k] = numpy.array(cell_data["avsucd:material"][k])
    return cell_ids, cells, cell_data
github nschloe / meshio / meshio / wkt / _wkt.py View on Github external
if tri_point_idxs[-1] != tri_point_idxs[0]:
            raise ValueError("Triangle is not a closed linestring")

        tri_idxs.append(tri_point_idxs[:-1])

    try:
        point_arr = np.array(list(point_idxs), np.float64)
    except ValueError as e:
        if len({len(p) for p in point_idxs}) > 1:
            raise ReadError("Points have mixed dimensionality")
        else:
            raise e

    tri_arr = np.array(tri_idxs, np.uint64)

    return Mesh(point_arr, [Cells("triangle", tri_arr)])
github nschloe / meshio / meshio / ugrid / _ugrid.py View on Github external
cell_data["ugrid:ref"].append(out)

    for key in ["tetra", "pyramid", "wedge", "hexahedron"]:
        nitems = ugrid_counts[key][0]
        nvertices = ugrid_counts[key][1]
        if nitems == 0:
            continue
        out = _read_section(
            f, file_type, count=nitems * nvertices, dtype=itype
        ).reshape(nitems, nvertices)

        if key == "pyramid":
            out = out[:, [1, 0, 3, 4, 2]]

        # UGRID is one-based
        cells.append(Cells(key, out - 1))

        # fill volume element attributes with zero
        cell_data["ugrid:ref"].append(numpy.zeros(nitems, dtype=int))

    if file_type["type"] == "F":
        _read_section(f, file_type, count=1, dtype=itype)

    return Mesh(points, cells, cell_data=cell_data)