Scipy Delaunay三角剖分生成波纹板STL适配OpenFOAM问题
问题背景
- 需求:对三维点集执行三角剖分,生成可供OpenFOAM使用的STL几何文件,建模对象为板式换热器中常见的沿长度方向带波纹结构的换热板片。
- 当前实现方案:采用
numpy-stl库完成STL文件生成,调用scipy库的Delaunay模块实现三角剖分。 - 现存问题:手动定义面片连接关系时可生成符合预期的单波纹结构;但直接调用Delaunay对三维点集做剖分、取
convex_hull生成面片时,算法无法感知波纹结构的边界特征,无法生成正确的波纹形貌。
复现代码
import numpy as np from stl import mesh import stl from mpl_toolkits import mplot3d from matplotlib import pyplot import math as math from scipy.spatial import Delaunay b = 0.5 # width plate d = 0.05 # width corrugation a = 60 # angle corrugation t_1 = -0.01 # depth corrugation ########################## UPPER PLATE WITH CORRUGATION ####################### # vertices of the corrugation as start and reference vertices_upperPlate= np.array([\ [0, 0, 0], [-b/2, -((b/2)/np.tan((a/180)*np.pi)),0], [b/2, -((b/2)/np.tan((a/180)*np.pi)),0], [0,d,0], [-b/2, -((b/2)/np.tan((a/180)*np.pi))+d,0], [b/2, -((b/2)/np.tan((a/180)*np.pi))+d,0]]) # Copy the definitions with z offset (t_1) vertices_upperPlateCorrugation = np.copy(vertices_upperPlate) vertices_upperPlateCorrugation[:,2] = vertices_upperPlateCorrugation[:,2] + t_1 vertices_upperPlate = np.vstack((vertices_upperPlate, vertices_upperPlateCorrugation)) faces_upperPlate = np.array([\ [0,1,6], [6,1,7], [0,2,6], [6,2,8], [3,4,9], [9,4,10], [3,5,9], [9,5,11], [6,7,9], [6,9,8], [9,7,10], [9,8,11]]) # tri = Delaunay(vertices_upperPlate) # faces_upperPlate = tri.convex_hull # Create the mesh upperPlate = mesh.Mesh(np.zeros(faces_upperPlate.shape[0], dtype=mesh.Mesh.dtype)) for i, f in enumerate(faces_upperPlate): for j in range(3): upperPlate.vectors[i][j] = vertices_upperPlate[f[j],:] # Create a new plot figure = pyplot.figure() axes = mplot3d.Axes3D(figure) # Load the STL files and add the vectors to the plot your_mesh = upperPlate axes.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors)) # Auto scale to the mesh size scale = your_mesh.points.flatten() axes.auto_scale_xyz(scale, scale, scale) # Show the plot to the screen pyplot.show() upperPlate.save('toOpenfoam/upperPlate.stl', mode=stl.Mode.ASCII)
核心问题
是否可以调整Delaunay三角剖分的逻辑,使其能够识别平面内的几何尺寸阶跃(即波纹的凹凸边界),从而自动完成包含完整波纹结构的板片三角剖分,生成无几何错误、可被OpenFOAM网格工具正常读取识别的STL文件?
解答
直接使用3D Delaunay剖分取凸包的方案从原理上就不可能实现你的需求。3D Delaunay生成的凸包是包裹所有输入点的最外层封闭凸曲面,波纹的凹陷、台阶类非凸特征本身就不属于凸包范围,算法自然会直接跨接这些内部边界,不可能还原出波纹形貌。
可行的调整方案如下:
- 优先采用2D参数域剖分方案,完全适配你当前的波纹板场景。你建模的换热板属于典型的2.5D结构,所有点都可以无重叠投影到板片所在的基准平面(如x-y平面),不需要做3D空间的Delaunay剖分。操作逻辑为:提取所有三维点的x、y坐标做2D Delaunay剖分,剖分得到的三角面片索引直接对应三维点集,即可生成完全贴合波纹形貌的三角网格,不会出现跨接台阶的几何错误。
对应你现有代码的修改非常简单,替换原有的Delaunay调用逻辑即可:# 提取点的二维平面坐标做2D Delaunay剖分 points_2d = vertices_upperPlate[:, :2] tri = Delaunay(points_2d) # 取所有剖分得到的三角面片,不要用convex_hull(凸包仅保留最外轮廓,会丢失所有内部面) faces_upperPlate = tri.simplices - 如果后续需要建模更复杂、无法直接投影到单一平面的板片结构,需要换用支持约束的三角剖分方案:提前将波纹的棱边定义为约束边界传入剖分算法,强制三角面片不能跨过你定义的阶跃边界。scipy自带的Delaunay模块不支持约束剖分,可以替换为
triangle、pygalmesh等第三方库实现。 - 导出STL前需要做一致性检查:一是删除重复面片、重复顶点,避免出现非流形边;二是统一所有面片的法向量方向,保证法向量指向流场区域外部,否则OpenFOAM的网格工具(如snappyHexMesh)无法正常识别几何。
内容的提问来源于stack exchange,提问作者Nico Su
相关产品推荐
相关产品推荐

