forked from SofaDefrost/SofaGym
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_board.py
88 lines (63 loc) · 2.25 KB
/
create_board.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
"""Create the mesh of the board.
"""
__authors__ = ("emenager")
__contact__ = ("[email protected]")
__version__ = "1.0.0"
__copyright__ = "(c) 2021, Inria"
__date__ = "December 1 2021"
import gmsh
def init_gmsh(name="Scene"):
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
gmsh.model.add(name)
gmsh.logger.start()
def _addPoint(X, Y, Z, lc=3):
return [gmsh.model.occ.addPoint(XValue, YValue, ZValue, lc) for (XValue, YValue, ZValue) in zip(X, Y, Z)]
def _addLine(src, end, loop=True):
LineTags = []
NPoints = len(src)
for i in range(NPoints):
LineTags.append(gmsh.model.occ.addLine(src[i], end[i]))
return LineTags
init_gmsh("Board")
BOARD_DIM = 8
HIGHEDGE = 3
SPACE = 0.15
# Step 1: Create board and cavity
BoxInTag = gmsh.model.occ.addBox(0, 0, 0, BOARD_DIM+2, BOARD_DIM+2, HIGHEDGE)
BoxOutTag = gmsh.model.occ.addBox(1, 1, 1, BOARD_DIM, BOARD_DIM, HIGHEDGE-1)
# Note: (dim, tag)
Board = gmsh.model.occ.cut([(3, BoxInTag)], [(3, BoxOutTag)])
BoardTag = Board[0][0][1]
cavity_len = (BOARD_DIM-4*SPACE)/3 # len_box - 4* interval / nb_cavity
X = [1+SPACE, 1+2*SPACE+cavity_len, 1+3*SPACE+2*cavity_len] # edge + (n+1)*sepration + n*cavity_len
Y = [1+SPACE, 1+2*SPACE+cavity_len, 1+3*SPACE+2*cavity_len]
Z = 0.25
for i in range(3):
for j in range(3):
BoxTag = gmsh.model.occ.addBox(X[i], Y[j], Z, cavity_len, cavity_len, 0.65)
CavityTag = gmsh.model.occ.cut([(3, BoardTag)], [(3, BoxTag)])
gmsh.option.setNumber("Mesh.MeshSizeFactor", 1.5)
# Step 2: volumetric and surfacic mesh of the board
gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(3)
gmsh.model.occ.synchronize()
gmsh.write("./mesh/Board_Volumetric.vtk")
gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(2)
gmsh.model.occ.synchronize()
gmsh.write("./mesh/Board_Surface.stl")
# Step 3: surfacic mesh of a cavity
id = 0
for i in range(3):
for j in range(3):
gmsh.clear()
BoxTag = gmsh.model.occ.addBox(X[i], Y[j], Z, cavity_len, cavity_len, 0.65)
gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(2)
gmsh.model.occ.synchronize()
gmsh.write("./mesh/Cavity_Surface_"+str(id)+".stl")
id += 1
gmsh.model.occ.synchronize()
gmsh.fltk.run()