当前位置: 首页 > news >正文

Gmsh教程

17、各向异性背景网格

import gmsh
import math
import os
import sysgmsh.initialize()gmsh.model.add("t17")gmsh.model.occ.addRectangle(-2, -2, 0, 4, 4)
gmsh.model.occ.synchronize()path = os.path.dirname(os.path.abspath(__file__))
gmsh.merge(os.path.join(path, os.pardir, 't17_bgmesh.pos'))
#设置背景网格字段:
bg_field = gmsh.model.mesh.field.add("PostView")
gmsh.model.mesh.field.setNumber(bg_field, "ViewIndex", 0)
gmsh.model.mesh.field.setAsBackgroundMesh(bg_field)
#设置网格生成选项
gmsh.option.setNumber("Mesh.SmoothRatio", 3)
gmsh.option.setNumber("Mesh.AnisoMax", 1000)
gmsh.option.setNumber("Mesh.Algorithm", 7)gmsh.model.mesh.generate(2)
gmsh.write("t17.msh")if '-nopopup' not in sys.argv:gmsh.fltk.run()gmsh.finalize()

18、周期网格

import gmsh
import math
import os
import sysgmsh.initialize()gmsh.model.add("t18")gmsh.model.occ.addBox(0, 0, 0, 1, 1, 1, 1)
gmsh.model.occ.synchronize()gmsh.model.mesh.setSize(gmsh.model.getEntities(0), 0.1)
gmsh.model.mesh.setSize([(0, 1)], 0.02)translation = [1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
gmsh.model.mesh.setPeriodic(2, [2], [1], translation)gmsh.model.mesh.setPeriodic(2, [6], [5],[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1])
gmsh.model.mesh.setPeriodic(2, [4], [3],[1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1])gmsh.model.occ.addBox(2, 0, 0, 1, 1, 1, 10)
x = 2 - 0.3
y = 0
z = 0
gmsh.model.occ.addSphere(x, y, z, 0.35, 11)
gmsh.model.occ.addSphere(x + 1, y, z, 0.35, 12)
gmsh.model.occ.addSphere(x, y + 1, z, 0.35, 13)
gmsh.model.occ.addSphere(x, y, z + 1, 0.35, 14)
gmsh.model.occ.addSphere(x + 1, y + 1, z, 0.35, 15)
gmsh.model.occ.addSphere(x, y + 1, z + 1, 0.35, 16)
gmsh.model.occ.addSphere(x + 1, y, z + 1, 0.35, 17)
gmsh.model.occ.addSphere(x + 1, y + 1, z + 1, 0.35, 18)out, _ = gmsh.model.occ.fragment([(3, 10)], [(3, i) for i in range(11, 19)])
gmsh.model.occ.synchronize()gmsh.option.setNumber("Geometry.OCCBoundsUseStl", 1)eps = 1e-3
vin = gmsh.model.getEntitiesInBoundingBox(2 - eps, -eps, -eps, 2 + 1 + eps,1 + eps, 1 + eps, 3)
for v in vin:out.remove(v)
gmsh.model.removeEntities(out, True)  p = gmsh.model.getBoundary(vin, False, False, True)  
gmsh.model.mesh.setSize(p, 0.1)
p = gmsh.model.getEntitiesInBoundingBox(2 - eps, -eps, -eps, 2 + eps, eps, eps,0)
gmsh.model.mesh.setSize(p, 0.001)sxmin = gmsh.model.getEntitiesInBoundingBox(2 - eps, -eps, -eps, 2 + eps,1 + eps, 1 + eps, 2)for i in sxmin:xmin, ymin, zmin, xmax, ymax, zmax = gmsh.model.getBoundingBox(i[0], i[1])sxmax = gmsh.model.getEntitiesInBoundingBox(xmin - eps + 1, ymin - eps,zmin - eps, xmax + eps + 1,ymax + eps, zmax + eps, 2)for j in sxmax:xmin2, ymin2, zmin2, xmax2, ymax2, zmax2 = gmsh.model.getBoundingBox(j[0], j[1])xmin2 -= 1xmax2 -= 1if (abs(xmin2 - xmin) < eps and abs(xmax2 - xmax) < eps andabs(ymin2 - ymin) < eps and abs(ymax2 - ymax) < eps andabs(zmin2 - zmin) < eps and abs(zmax2 - zmax) < eps):
#周期网格的相关设置gmsh.model.mesh.setPeriodic(2, [j[1]], [i[1]], translation)gmsh.model.mesh.generate(3)
gmsh.write("t18.msh")if '-nopopup' not in sys.argv:gmsh.fltk.run()gmsh.finalize()

19、穿透、圆角、管道、曲率网格尺寸


import gmsh
import math
import os
import sysgmsh.initialize()gmsh.model.add("t19")gmsh.model.occ.addCircle(0, 0, 0, 0.5, 1)
gmsh.model.occ.addCurveLoop([1], 1)
gmsh.model.occ.addCircle(0.1, 0.05, 1, 0.1, 2)
gmsh.model.occ.addCurveLoop([2], 2)
gmsh.model.occ.addCircle(-0.1, -0.1, 2, 0.3, 3)
gmsh.model.occ.addCurveLoop([3], 3)
gmsh.model.occ.addThruSections([1, 2, 3], 1)
gmsh.model.occ.synchronize()gmsh.model.occ.addCircle(2 + 0, 0, 0, 0.5, 11)
gmsh.model.occ.addCurveLoop([11], 11)
gmsh.model.occ.addCircle(2 + 0.1, 0.05, 1, 0.1, 12)
gmsh.model.occ.addCurveLoop([12], 12)
gmsh.model.occ.addCircle(2 - 0.1, -0.1, 2, 0.3, 13)
gmsh.model.occ.addCurveLoop([13], 13)
gmsh.model.occ.addThruSections([11, 12, 13], 11, True, True)
gmsh.model.occ.synchronize()out = gmsh.model.occ.copy([(3, 1)])
gmsh.model.occ.translate(out, 4, 0, 0)
gmsh.model.occ.synchronize()
e = gmsh.model.getBoundary(gmsh.model.getBoundary(out), False)
gmsh.model.occ.fillet([out[0][1]], [abs(i[1]) for i in e], [0.1])
gmsh.model.occ.synchronize()nturns = 1.
npts = 20
r = 1.
h = 1. * nturns
p = []
for i in range(0, npts):theta = i * 2 * math.pi * nturns / nptsgmsh.model.occ.addPoint(r * math.cos(theta), r * math.sin(theta),i * h / npts, 1, 1000 + i)p.append(1000 + i)
gmsh.model.occ.addSpline(p, 1000)gmsh.model.occ.addWire([1000], 1000)gmsh.model.occ.addDisk(1, 0, 0, 0.2, 0.2, 1000)
gmsh.model.occ.rotate([(2, 1000)], 0, 0, 0, 1, 0, 0, math.pi / 2)gmsh.model.occ.addPipe([(2, 1000)], 1000, 'DiscreteTrihedron')gmsh.model.occ.remove([(2, 1000)])
gmsh.option.setNumber("Geometry.NumSubEdges", 1000)gmsh.model.occ.synchronize()gmsh.option.setNumber("Mesh.MeshSizeFromCurvature", 20)gmsh.option.setNumber("Mesh.MeshSizeMin", 0.001)
gmsh.option.setNumber("Mesh.MeshSizeMax", 0.3)gmsh.model.mesh.generate(3)
gmsh.write("t19.msh")if '-nopopup' not in sys.argv:gmsh.fltk.run()gmsh.finalize()

20、STEP导入和操作、几何分割

import gmsh
import math
import os
import sysgmsh.initialize()gmsh.model.add("t20")
#导入几何体
path = os.path.dirname(os.path.abspath(__file__))
v = gmsh.model.occ.importShapes(os.path.join(path, os.pardir, 't20_data.step'))xmin, ymin, zmin, xmax, ymax, zmax = gmsh.model.occ.getBoundingBox(v[0][0], v[0][1])N = 5  
dir = 'X' # 
surf = False dx = (xmax - xmin)
dy = (ymax - ymin)
dz = (zmax - zmin)
L = dz if (dir == 'X') else dx
H = dz if (dir == 'Y') else dys = []
s.append((2, gmsh.model.occ.addRectangle(xmin, ymin, zmin, L, H)))
if dir == 'X':gmsh.model.occ.rotate([s[0]], xmin, ymin, zmin, 0, 1, 0, -math.pi/2)
elif dir == 'Y':gmsh.model.occ.rotate([s[0]], xmin, ymin, zmin, 1, 0, 0, math.pi/2)
tx = dx / N if (dir == 'X') else 0
ty = dy / N if (dir == 'Y') else 0
tz = dz / N if (dir == 'Z') else 0
gmsh.model.occ.translate([s[0]], tx, ty, tz)for i in range(1, N-1):s.extend(gmsh.model.occ.copy([s[0]]))gmsh.model.occ.translate([s[-1]], i * tx, i * ty, i * tz)gmsh.model.occ.fragment(v, s)gmsh.model.occ.remove(gmsh.model.occ.getEntities(2), True)gmsh.model.occ.synchronize()if surf:eps = 1e-4s = []for i in range(1, N):xx = xmin if (dir == 'X') else xmaxyy = ymin if (dir == 'Y') else ymaxzz = zmin if (dir == 'Z') else zmaxs.extend(gmsh.model.getEntitiesInBoundingBox(xmin - eps + i * tx, ymin - eps + i * ty, zmin - eps + i * tz,xx + eps + i * tx, yy + eps + i * ty, zz + eps + i * tz, 2))dels = gmsh.model.getEntities(2)for e in s:dels.remove(e)gmsh.model.removeEntities(gmsh.model.getEntities(3))gmsh.model.removeEntities(dels)gmsh.model.removeEntities(gmsh.model.getEntities(1))gmsh.model.removeEntities(gmsh.model.getEntities(0))gmsh.option.setNumber("Mesh.MeshSizeMin", 3)
gmsh.option.setNumber("Mesh.MeshSizeMax", 3)
gmsh.model.mesh.generate(3)
gmsh.write("t20.msh")if '-nopopup' not in sys.argv:gmsh.fltk.run()gmsh.finalize()

21、网格划分

import gmsh
import math
import os
import sysgmsh.initialize()gmsh.model.add("t17")gmsh.model.occ.addRectangle(-2, -2, 0, 4, 4)
gmsh.model.occ.synchronize()path = os.path.dirname(os.path.abspath(__file__))
gmsh.merge(os.path.join(path, os.pardir, 't17_bgmesh.pos'))bg_field = gmsh.model.mesh.field.add("PostView")
gmsh.model.mesh.field.setNumber(bg_field, "ViewIndex", 0)
gmsh.model.mesh.field.setAsBackgroundMesh(bg_field)gmsh.option.setNumber("Mesh.SmoothRatio", 3)
gmsh.option.setNumber("Mesh.AnisoMax", 1000)
gmsh.option.setNumber("Mesh.Algorithm", 7)gmsh.model.mesh.generate(2)
gmsh.write("t17.msh")if '-nopopup' not in sys.argv:gmsh.fltk.run()gmsh.finalize()

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 关于dom4j主节点的xmlns无法写入的问题
  • 手机日历如何与Outlook同步
  • 基于PHP+MYSQL开发制作的趣味测试网站源码
  • openlayers请求地图瓦片超时的问题解决
  • SpringBoot 解决 getSession().getAttribute() 在负载均衡环境下无法获取session的问题
  • 【C++PythonJava】字符处理详细解读_字符_ASCLL码_字母数字转换_算法竞赛_开发语言
  • 智能家居和智能家电有什么区别?
  • 深入探讨:Node.js、Vue、SSH服务与SSH免密登录
  • vscode常用组件
  • k8s集群创建devops项目一直等待状态,没有发现host
  • 算法——双指针(day3)
  • 记一下blender的烘焙贴图的UV特殊用法
  • HouseCrafter:平面草稿至3D室内场景的革新之旅
  • 数学基础【俗说矩阵】:矩阵相乘
  • redhat 7服务管理
  • [PHP内核探索]PHP中的哈希表
  • [原]深入对比数据科学工具箱:Python和R 非结构化数据的结构化
  • Apache Pulsar 2.1 重磅发布
  • ComponentOne 2017 V2版本正式发布
  • DOM的那些事
  • Java 23种设计模式 之单例模式 7种实现方式
  • leetcode讲解--894. All Possible Full Binary Trees
  • Less 日常用法
  • mysql innodb 索引使用指南
  • PyCharm搭建GO开发环境(GO语言学习第1课)
  • Python语法速览与机器学习开发环境搭建
  • TiDB 源码阅读系列文章(十)Chunk 和执行框架简介
  • 阿里云容器服务区块链解决方案全新升级 支持Hyperledger Fabric v1.1
  • 工作中总结前端开发流程--vue项目
  • 回顾 Swift 多平台移植进度 #2
  • 盘点那些不知名却常用的 Git 操作
  • 要让cordova项目适配iphoneX + ios11.4,总共要几步?三步
  • AI算硅基生命吗,为什么?
  • 摩拜创始人胡玮炜也彻底离开了,共享单车行业还有未来吗? ...
  • !$boo在php中什么意思,php前戏
  • #FPGA(基础知识)
  • #QT(TCP网络编程-服务端)
  • (Spark3.2.0)Spark SQL 初探: 使用大数据分析2000万KF数据
  • (vue)el-cascader级联选择器按勾选的顺序传值,摆脱层级约束
  • (二) 初入MySQL 【数据库管理】
  • (分类)KNN算法- 参数调优
  • (附源码)spring boot儿童教育管理系统 毕业设计 281442
  • (四)JPA - JQPL 实现增删改查
  • (已解决)Bootstrap精美弹出框模态框modal,实现js向modal传递数据
  • (转)eclipse内存溢出设置 -Xms212m -Xmx804m -XX:PermSize=250M -XX:MaxPermSize=356m
  • .dat文件写入byte类型数组_用Python从Abaqus导出txt、dat数据
  • .NET Core 版本不支持的问题
  • .NET/C# 判断某个类是否是泛型类型或泛型接口的子类型
  • .NET:自动将请求参数绑定到ASPX、ASHX和MVC(菜鸟必看)
  • .w文件怎么转成html文件,使用pandoc进行Word与Markdown文件转化
  • @Autowired 与@Resource的区别
  • @EnableWebSecurity 注解的用途及适用场景
  • [ C++ ] 类和对象( 下 )
  • [④ADRV902x]: Digital Filter Configuration(发射端)
  • [BZOJ] 2006: [NOI2010]超级钢琴