问题描述
开源CFD软件“OpenFOAM”可以导出几种网格文件类型:
- ansys fluent 软件“.msh”
- Starmesh 软件“.vrt”用于顶点,“.cel”用于元素,“.bnd”用于边界
- “.VTK”格式
我需要将其中一种类型转换为 gmsh 格式,该格式可以由 FiPy 库在 python 中使用,'".msh2" 格式'。
如果您能帮我解决这个问题,我将不胜感激。导出的文件附在下面的链接中,点击“دریافت لینک دانلود”将显示下载链接:
https://s17.picofile.com/file/8426414576/OF_Cylinder.msh.html
https://s17.picofile.com/file/8426414642/meshExport.vrt.html
https://s17.picofile.com/file/8426414676/meshExport.cel.html
https://s17.picofile.com/file/8426414684/SandPro7_0.vtk.html
我用过这个库,但是有一些问题。 当我尝试打开为 fluent 导出的“.msh”文件时,出现以下错误:
因为它是在linke https://pypi.org/project/meshio/1.8.9/
中写的,Ansys mesh可以被“meshio”读取和转换,但出现以下错误:
mesh = meshio.read("OF_Cylinder.msh",file_format= "ansys-ascii")
ERROR:
Traceback (most recent call last):
File "C:/Users/Ali/Desktop/mesh change.py",line 5,in <module>
mesh = meshio.read("OF_Cylinder.msh",file_format= "ansys-ascii")
File "C:\Python27\lib\site-packages\meshio\helpers.py",line 176,in read
return format_to_reader[file_format].read(filename)
File "C:\Python27\lib\site-packages\meshio\ansys_io.py",line 318,in read
key,data = _read_cells(f,line)
File "C:\Python27\lib\site-packages\meshio\ansys_io.py",line 131,in _read_cells
assert key != "mixed"
AssertionError
mesh = meshio.read("OF_Cylinder.msh")
ERROR=
Traceback (most recent call last):
File "C:/Users/Ali/Desktop/mesh change.py",in <module>
mesh = meshio.read("OF_Cylinder.msh")
File "C:\Python27\lib\site-packages\meshio\helpers.py",in read
return format_to_reader[file_format].read(filename)
File "C:\Python27\lib\site-packages\meshio\msh_io\main.py",line 15,in read
mesh = read_buffer(f)
File "C:\Python27\lib\site-packages\meshio\msh_io\main.py",line 31,in read_buffer
assert line == "$MeshFormat"
AssertionError
对于 Starmesh 网格类型文件,节点和元素有两个单独的文件,无法直接转换。
".VTK"格式已经被meshio读取了,但是如何转成-2格式一,直接
mesh = meshio.read("SandPro.vtk")
msh = meshio.write("mesh.msh",mesh,file_format="gmsh2-ascii") worked
meshio-convert SandPro.vtk SandPro.msh didn't work
File "C:/Users/Ali/Desktop/mesh change.py",line 12
meshio-convert SandPro.vtk SandPro.msh
^
SyntaxError: invalid Syntax
解决方法
查看meshio。它可以在多种不同格式之间进行转换。
,VTK 格式更适合导出和转换为其他格式,尤其是对于 OpenFOAM。看来,您正在使用旧版本的 meshio。您使用其他格式的问题很可能会被新版本的 meshio 解决。对于最后一部分,它必须从命令行运行,而不是从 python 脚本中运行。