2026/4/4 5:31:05
网站建设
项目流程
做网站去青鸟学什么专业,重庆网站seo好不好,北京工商注册网官网,手机网站设计论文四参数随机生长法 QSGS算法 随机孔隙结构 微观孔隙优化处理 多孔介质 随机生长软件 生成图片#xff0c;可完美处理为CAD图#xff0c; 可导入abaqus、ansys、comsol、fluent最近在折腾多孔介质仿真的时候#xff0c;发现生成靠谱的随机孔隙结构真是门玄学。试过一堆方法可完美处理为CAD图 可导入abaqus、ansys、comsol、fluent最近在折腾多孔介质仿真的时候发现生成靠谱的随机孔隙结构真是门玄学。试过一堆方法最后被四参数随机生长法QSGS算法惊艳到了——这玩意儿就像玩我的世界造地形几个参数就能搞出千变万化的孔隙结构。先甩段Python代码热热身import numpy as np import matplotlib.pyplot as plt def qsgs_generator(size100, porosity0.6, pd0.5, pg0.3, iter_max20): grid np.zeros((size, size)) seeds np.random.choice([0,1], sizegrid.shape, p[1-pd, pd]) grid[seeds1] 1 for _ in range(iter_max): new_grid grid.copy() for i in range(1, size-1): for j in range(1, size-1): if grid[i,j] 0: neighbors grid[i-1:i2, j-1:j2] if np.sum(neighbors) 1: if np.random.rand() pg: new_grid[i,j] 1 grid new_grid # 孔隙率校准 current_porosity 1 - np.sum(grid)/grid.size adjust_factor (porosity / current_porosity) ** 0.5 threshold np.percentile(grid, 100*(1-adjust_factor)) return (grid threshold).astype(int)这段代码最骚的是生长概率pg的控制——就像病毒扩散的传染率pg越大孔隙长得越奔放。跑出来的效果可以直接用matplotlib可视化porous qsgs_generator(size200, porosity0.65) plt.imshow(porous, cmapbinary) plt.axis(off) plt.savefig(pore_structure.png, dpi300, bbox_inchestight)生成二维切片只是开胃菜用numpy的跨步技巧能轻松扩展到三维# 三维版本核心生长逻辑 def grow_3d(grid, pg): new_grid grid.copy() # 用三维卷积核加速计算 kernel np.ones((3,3,3)) neighbor_count convolve(grid, kernel, modeconstant) growth_mask (grid 0) (neighbor_count 1) (np.random.rand(*grid.shape) pg) new_grid[growth_mask] 1 return new_grid重点来了——怎么让这些像素图变成工程师能用的CAD模型我的野路子是把二值图像转成SVG路径再用FreeCAD批量拉伸。这里有个取巧的矢量化方法from skimage import measure contours measure.find_contours(porous, 0.5) with open(pore.svg, w) as f: f.write(svg) for contour in contours: f.write(fpath dM { L .join(f{x},{y} for x,y in contour)} Z/) f.write(/svg)导入COMSOL做流固耦合分析时发现直接扔STL文件进去会报错。血泪教训一定要在导出前做网格光顺处理用trimesh库预处理下能救命import trimesh mesh trimesh.Trimesh(verticesvertices, facesfaces) mesh.merge_vertices() mesh.remove_duplicate_faces() mesh.export(smoothed.stl)玩到最后发现这算法最神的不是生成效果而是参数调整像调鸡尾酒——孔隙率控制基酒量分布概率pd决定冰块分布生长概率pg是气泡活跃度。想要仿生骨结构就把pg调低多迭代几次想要泡沫金属就把pd拉高比玩化学实验还上瘾。代码文件建议扔到GitHub配个Actions自动化流程半夜跑参数扫描第二天直接收菜亲测比咖啡提神