[Meshio] 基本使用方法

发布于 2022-11-23  1117 次阅读


Please refresh the page if equations are not rendered correctly.
---------------------------------------------------------------

meshio可以解决各种标准格式网格之间的读取,写入和转换。
There are various mesh formats available for representing unstructured meshes. meshio can read and write all of the following and smoothly converts between them:
Abaqus、ANSYS msh、DOLFIN XML、Exodus、FLAC3D、H5M、Kratos/MDPA、Medit、MED/Salome、Nastran (bulk data)、Gmsh (versions 2 and 4)、OFF、PERMAS、STL、TetGen .node/.ele、SVG (2D only, output only)、VTK、VTU、XDMF

reference: https://github.com/nschloe/meshio/blob/main/README.md

安装

pip3 install meshio[all] --user
Spyder:!pip install meshio

读取

import meshio
mesh=meshio.read('H://20221123.inp')

meshio主要是字典操作,存储的数据及source code可见下图

节点

points=mesh.points #节点坐标
Nodes=np.column_stack((np.arange(1,len(points)+1),points))#节点编号及坐标,从1开始

cells

#***Attention!!!节点编号及坐标,从1开始
cell=mesh.cells[0].data #原始数据里节点编号从0开始
cell=mesh.get_cells_type('triangle')
cell=mesh.cell_data['auto3'] #*ELEMENT,TYPE=S3,ELSET=auto3
####################################
Elements=np.column_stack((np.arange(1,len(cell)+1),cell+1))#让单元从1开始编号

写入

points = numpy.array([
    [0.0, 0.0, 0.0],
    [0.0, 1.0, 0.0],
    [0.0, 0.0, 1.0],
    ])
cells = {
    "triangle": numpy.array([
        [0, 1, 2]
        ])
    }
meshio.write_points_cells(
    "foo.vtk",
    points,
    cells,
    # Optionally provide extra data on points, cells, etc.
    # point_data=point_data,
    # cell_data=cell_data,
    # field_data=field_data
    )

转换

mesh = meshio.Mesh(points, cells)
meshio.write("foo.vtk", mesh)

Time series

Time series
The XDMF format supports time series with a shared mesh. You can write times series data using meshio with

writer = meshio.XdmfTimeSeriesWriter(filename)
writer.write_points_cells(points, cells)
for t in [0.0, 0.1, 0.21]:
    writer.write_data(t, point_data={"phi": data})

and read it with

reader = meshio.XdmfTimeSeriesReader(filename)
points, cells = reader.read_points_cells()
for k in range(reader.num_steps):
    t, point_data, cell_data = reader.read_data(k)
届ける言葉を今は育ててる
最后更新于 2023-06-11