用于gmsh的python前端
pygmsh的Python项目详细描述
用于python的gmsh。
Gmsh是一个强大的网格生成工具,使用脚本语言 这是出了名的难写。
pygmsh的目标是将gmsh的强大功能与python的多功能性结合起来,并 从gmsh脚本语言中提供有用的抽象,以便您可以创建复杂的 几何图形更容易。
详情见here 文档。
内置
要创建上述网格,只需执行
import pygmsh import numpy as np geom = pygmsh.built_in.Geometry() # Draw a cross. poly = geom.add_polygon([ [ 0.0, 0.5, 0.0], [-0.1, 0.1, 0.0], [-0.5, 0.0, 0.0], [-0.1, -0.1, 0.0], [ 0.0, -0.5, 0.0], [ 0.1, -0.1, 0.0], [ 0.5, 0.0, 0.0], [ 0.1, 0.1, 0.0] ], lcar=0.05 ) axis = [0, 0, 1] geom.extrude( poly, translation_axis=axis, rotation_axis=axis, point_on_axis=[0, 0, 0], angle=2.0 / 6.0 * np.pi ) mesh = pygmsh.generate_mesh(geom) # mesh.points, mesh.cells, ...
检索指定几何体的网格的所有点和单元。储存 mesh,您可以使用meshio;例如
importmeshiomeshio.write("test.vtk",mesh)
输出文件可以用各种工具可视化,例如, ParaView。
你可以在目录中找到上面的网格
^{
打开级联
从3.0版开始,gmsh支持opencascade,允许使用cad样式的几何图形 规范。
示例:
import pygmsh geom = pygmsh.opencascade.Geometry( characteristic_length_min=0.1, characteristic_length_max=0.1, ) rectangle = geom.add_rectangle([-1.0, -1.0, 0.0], 2.0, 2.0) disk1 = geom.add_disk([-1.2, 0.0, 0.0], 0.5) disk2 = geom.add_disk([+1.2, 0.0, 0.0], 0.5) union = geom.boolean_union([rectangle, disk1, disk2]) disk3 = geom.add_disk([0.0, -0.9, 0.0], 0.5) disk4 = geom.add_disk([0.0, +0.9, 0.0], 0.5) flat = geom.boolean_difference([union], [disk3, disk4]) geom.extrude(flat, [0, 0, 0.3]) mesh = pygmsh.generate_mesh(geom)
安装
侏儒是available from the Python Package Index, 所以只需键入
pip3 install pygmsh --user
安装。还要确保安装了gmsh。
使用量
只是
import pygmsh as pg
利用模块提供的所有优点。这个
documentation和下面的示例
^{
测试
要运行pygmsh单元测试,请签出此存储库并键入
pytest
建筑文档
文档是使用Sphinx生成的。
构建运行
sphinx-build -b html doc doc/_build
许可证
pygmsh是在MIT license下发布的。