-
Notifications
You must be signed in to change notification settings - Fork 8
/
MoldGeneration.py
263 lines (200 loc) · 12.6 KB
/
MoldGeneration.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# -*- coding: utf-8 -*-
"""Mold generation for the SensorFinger"""
__authors__ = "sescaidanavarro, tnavez"
__contact__ = "[email protected], [email protected]"
__version__ = "1.0.0"
__copyright__ = "(c) 2020, Inria"
__date__ = "Oct 28 2022"
import gmsh
import numpy as np
from Generation import createFinger, createCavitySketch
def dimTagz2Tagz(DimTagz, dimension):
Tagz = [tag for (dim, tag) in DimTagz]
return Tagz
def hide_all():
ent = gmsh.model.getEntities()
for x in ent:
gmsh.model.setVisibility((x,), False)
def createFingerMold(ThicknessMold, MoldWallThickness, HeightMold, LengthMold, CableHeight, CableRadius,
Length, Height, OuterRadius, TeethRadius, PlateauHeight, JointHeight,
Thickness, JointSlopeAngle, FixationWidth, BellowHeight, NBellows, WallThickness,
CenterThickness, CavityCorkThickness, lc, Stage1Mod=False):
FingerDimTag = createFinger(Length, Height, OuterRadius, TeethRadius, PlateauHeight, JointHeight,
Thickness, JointSlopeAngle, FixationWidth, BellowHeight, NBellows, WallThickness,
CenterThickness, CavityCorkThickness, lc, Stage1Mod=Stage1Mod)
MoldBoxDimTag = (3,gmsh.model.occ.addBox(-ThicknessMold/2,
0,
MoldWallThickness,
ThicknessMold,
HeightMold,
-LengthMold))
CableLength = LengthMold+2*MoldWallThickness
CableDimTag = (3,gmsh.model.occ.addCylinder(0,CableHeight,2*MoldWallThickness,0,0,-CableLength,CableRadius))
CutOut = gmsh.model.occ.cut([MoldBoxDimTag],[FingerDimTag, CableDimTag])
MoldBaseDimTag = CutOut[0][0]
AllCavitiesDimTags = CutOut[0][1:]
MoldBoxOuterRimDimTag = (3,gmsh.model.occ.addBox(-ThicknessMold/2,
0,
MoldWallThickness,
ThicknessMold,
-MoldWallThickness,
-LengthMold))
MoldBoxInnerRimDimTag = (3,gmsh.model.occ.addBox(-ThicknessMold/2+MoldWallThickness,
0,
0,
ThicknessMold-2*MoldWallThickness,
-MoldWallThickness,
-LengthMold+2*MoldWallThickness))
CutOut = gmsh.model.occ.cut([MoldBoxOuterRimDimTag],[MoldBoxInnerRimDimTag])
MoldRim = CutOut[0][0]
FuseOut = gmsh.model.occ.fuse([MoldBaseDimTag],[MoldRim])
MoldDimTag = FuseOut[0][0]
gmsh.model.occ.synchronize()
return MoldDimTag, AllCavitiesDimTags
def createMoldLid(Length, OuterRadius, BellowHeight, WallThickness, TeethRadius, CenterThickness, PlateauHeight,
CavityCorkThickness, ThicknessMold, MoldWallThickness, LengthMold,
MoldCoverTolerance, AllCavitiesDimTags):
#-----------------
# Create mold lid
#-----------------
MoldLidTopDimTag = (3,gmsh.model.occ.addBox(-ThicknessMold/2,
-MoldWallThickness,
MoldWallThickness,
ThicknessMold,
-MoldWallThickness,
-LengthMold))
gmsh.model.occ.synchronize()
SurfaceBorderDimTags = gmsh.model.getBoundary([MoldLidTopDimTag],oriented=False)
LineBorderDimTags = gmsh.model.getBoundary(SurfaceBorderDimTags[0:], combined=False, oriented=False)
BorderTagz = dimTagz2Tagz(LineBorderDimTags,1)
gmsh.model.occ.fillet([MoldLidTopDimTag[1]], BorderTagz, [0.7])
gmsh.model.occ.synchronize()
MoldLidInteriorDimTag = (3,gmsh.model.occ.addBox(-ThicknessMold/2+MoldWallThickness+MoldCoverTolerance,
0,
MoldCoverTolerance,
ThicknessMold-2*MoldWallThickness-2*MoldCoverTolerance,
-MoldWallThickness,
-LengthMold+2*MoldWallThickness+2*MoldCoverTolerance))
#-----------------
# Create cavity cork
#-----------------
CorkBellowHeight = BellowHeight+2
CorkWallThickness = WallThickness-1
CavityCorkSketchDimTag = (2, createCavitySketch(OuterRadius, CorkBellowHeight, TeethRadius, CorkWallThickness, CenterThickness, PlateauHeight))
ExtrudeDimTags = gmsh.model.occ.extrude([CavityCorkSketchDimTag],0,CavityCorkThickness,0)
HalfDimTag = ExtrudeDimTags[1]
CavityCorkDimTags = [HalfDimTag]
gmsh.model.occ.translate(CavityCorkDimTags,0,0,-Length-CorkBellowHeight/2)
CavityCork2DimTags = gmsh.model.occ.copy(CavityCorkDimTags)
CavityCork3DimTags = gmsh.model.occ.copy(CavityCorkDimTags)
CavityCork4DimTags = gmsh.model.occ.copy(CavityCorkDimTags)
gmsh.model.occ.affineTransform(CavityCork2DimTags, [-1,0,0,0, 0,1,0,0, 0,0,1,0])
gmsh.model.occ.translate(CavityCork3DimTags,0,0,-Length)
gmsh.model.occ.affineTransform(CavityCork4DimTags, [-1,0,0,0, 0,1,0,0, 0,0,1,0])
gmsh.model.occ.translate(CavityCork4DimTags,0,0,-Length)
gmsh.model.occ.synchronize()
AllCavitiesCorkDimTags = CavityCorkDimTags + CavityCork2DimTags + CavityCork3DimTags + CavityCork4DimTags
FuseOut = gmsh.model.occ.fuse([MoldLidTopDimTag],[MoldLidInteriorDimTag]+AllCavitiesCorkDimTags+AllCavitiesDimTags)
LidDimTag = FuseOut[0][0]
return LidDimTag
#################################
### Mesh Generation Functions ###
#################################
def MoldBox(ThicknessMold, MoldWallThickness, HeightMold, LengthMold, CableHeight, CableRadius,
Length, Height, OuterRadius, TeethRadius, PlateauHeight, JointHeight,
Thickness, JointSlopeAngle, FixationWidth, BellowHeight, NBellows, WallThickness,
CenterThickness, CavityCorkThickness, lc, Stage1Mod=False):
MoldDimTag, AllCavitiesDimTags = createFingerMold(ThicknessMold, MoldWallThickness, HeightMold, LengthMold, CableHeight, CableRadius,
Length, Height, OuterRadius, TeethRadius, PlateauHeight, JointHeight,
Thickness, JointSlopeAngle, FixationWidth, BellowHeight, NBellows, WallThickness,
CenterThickness, CavityCorkThickness, lc, Stage1Mod=Stage1Mod)
# Remove cavities
CutOut = gmsh.model.occ.cut([MoldDimTag], AllCavitiesDimTags)
return MoldDimTag
def MoldLid(ThicknessMold, MoldWallThickness, HeightMold, LengthMold, CableHeight, CableRadius,
Length, Height, OuterRadius, TeethRadius, PlateauHeight, JointHeight,
Thickness, JointSlopeAngle, FixationWidth, BellowHeight, NBellows, WallThickness,
CenterThickness, CavityCorkThickness, lc, MoldCoverTolerance, Stage1Mod=False):
MoldDimTag, AllCavitiesDimTags = createFingerMold(ThicknessMold, MoldWallThickness, HeightMold, LengthMold, CableHeight, CableRadius,
Length, Height, OuterRadius, TeethRadius, PlateauHeight, JointHeight,
Thickness, JointSlopeAngle, FixationWidth, BellowHeight, NBellows, WallThickness,
CenterThickness, CavityCorkThickness, lc, Stage1Mod=Stage1Mod)
LidDimTag = createMoldLid(Length, OuterRadius, BellowHeight, WallThickness, TeethRadius, CenterThickness, PlateauHeight,
CavityCorkThickness, ThicknessMold, MoldWallThickness, LengthMold,
MoldCoverTolerance, AllCavitiesDimTags)
# hide_all(gmsh)
# gmsh.model.setVisibility((LidDimTag,),False, True)
# gmsh.model.setVisibility((MoldDimTag,),False, True)
# Remove Box
CutOut = gmsh.model.occ.cut([LidDimTag], [MoldDimTag])
return LidDimTag
def MoldForCork(OuterRadius, BellowHeight, NBellows, WallThickness, TeethRadius,
CenterThickness, PlateauHeight, CavityCorkThickness):
CorkBellowHeight = BellowHeight+2
CorkWallThickness = WallThickness-1
CavityCorkSketchDimTag = (2, createCavitySketch(OuterRadius, CorkBellowHeight, TeethRadius, CorkWallThickness, CenterThickness, PlateauHeight))
Tolerance = 2
TotalBellowHeight = NBellows * BellowHeight
CorkMoldHeight = TotalBellowHeight + 2 * Tolerance
CorkMoldThickness = (OuterRadius+Tolerance) * 2
ExtrudeDimTags = gmsh.model.occ.extrude([CavityCorkSketchDimTag],0,CavityCorkThickness,0)
HalfDimTag = ExtrudeDimTags[1]
CavityCorkDimTag = HalfDimTag
gmsh.model.occ.translate([CavityCorkDimTag],0,0,-TotalBellowHeight/2)
CavityCork2DimTags = gmsh.model.occ.copy([CavityCorkDimTag])
gmsh.model.occ.affineTransform(CavityCork2DimTags, [-1,0,0,0, 0,1,0,0, 0,0,1,0])
FuseOut = gmsh.model.occ.fuse([CavityCorkDimTag],CavityCork2DimTags)
CompleteCorkDimTag = FuseOut[0][0]
CavityMoldBoxDimTag = (3,gmsh.model.occ.addBox(-CorkMoldThickness/2,
-Tolerance,
-CorkMoldHeight/2,
CorkMoldThickness,
CavityCorkThickness+Tolerance,
CorkMoldHeight+Tolerance))
CutOut = gmsh.model.occ.cut([CavityMoldBoxDimTag],[CompleteCorkDimTag])
return CutOut
def FingerClamp(MoldWallThickness, LengthMold, CableHeight, CableRadius,
Length, Height, OuterRadius, TeethRadius, PlateauHeight, JointHeight,
Thickness, JointSlopeAngle, FixationWidth, BellowHeight, NBellows, WallThickness,
CenterThickness, CavityCorkThickness, lc, Stage1Mod=False):
FingerDimTags = [createFinger(Length, Height, OuterRadius, TeethRadius, PlateauHeight, JointHeight,
Thickness, JointSlopeAngle, FixationWidth, BellowHeight, NBellows, WallThickness,
CenterThickness, CavityCorkThickness, lc, Stage1Mod=Stage1Mod)]
ClampBoxWidth = 4*FixationWidth+Thickness
ClampBoxLength = 4*FixationWidth
ClampBoxHeight = Height + 2 * FixationWidth
ClampBoxDimDag = (3,gmsh.model.occ.addBox(-ClampBoxWidth/2,
0,
-ClampBoxLength/2,
ClampBoxWidth,
ClampBoxHeight,
ClampBoxLength))
ClampBoxCablePassDimTag = (3,gmsh.model.occ.addBox(-Thickness/2,
0,
0,
Thickness,
5,
10
))
ScrewRadius = 1.7
ScrewEarWidth = 6
ScrewEarHeight = 3
ScrewEarLength = ScrewEarWidth
ScrewEarBoxDimDag = (3,gmsh.model.occ.addBox(ClampBoxWidth/2,
0,
-ScrewEarLength/2,
ScrewEarWidth,
ScrewEarHeight,
ScrewEarLength))
ScrewLength = 6
ScrewCylinderDimTag = (3,gmsh.model.occ.addCylinder(ClampBoxWidth/2+ScrewEarWidth/2,-ScrewLength/3,0, 0,ScrewLength,0,ScrewRadius))
ScrewEarBox2DimTags = gmsh.model.occ.copy([ScrewEarBoxDimDag])
gmsh.model.occ.affineTransform(ScrewEarBox2DimTags, [-1,0,0,0, 0,1,0,0, 0,0,1,0])
ScrewCylinder2DimTags = gmsh.model.occ.copy([ScrewCylinderDimTag])
gmsh.model.occ.affineTransform(ScrewCylinder2DimTags, [-1,0,0,0, 0,1,0,0, 0,0,1,0])
CableLength = LengthMold+2*MoldWallThickness
CableDimTag = (3,gmsh.model.occ.addCylinder(0,CableHeight,2*MoldWallThickness,0,0,-CableLength,CableRadius))
FuseOut = gmsh.model.occ.fuse([ClampBoxDimDag],[ScrewEarBoxDimDag]+ScrewEarBox2DimTags)
PositiveBoxDimTag = FuseOut[0][0]
gmsh.model.occ.cut([PositiveBoxDimTag],FingerDimTags+ScrewCylinder2DimTags + [ScrewCylinderDimTag,CableDimTag]+[ClampBoxCablePassDimTag])
return 0