Salome HOME
Debug algorithms and hypotheses assignment
[modules/smesh.git] / src / SMESH_SWIG / ex13_hole1partial.py
1 # CEA/LGLS 2005, Francis KLOSS (OCC)
2 # ==================================
3
4 from geompy import *
5
6 import smesh
7
8 # Geometry
9 # ========
10
11 # With hexahedral, build a box partially holed by a not centered cylinder with a thickness
12
13 # Values
14 # ------
15
16 box_dx = 1000
17 box_dy =  900
18 box_dz =  800
19
20 cyl_x      = 500
21 cyl_y      = 300
22 cyl_dz     = 600
23 cyl_radius = 150
24 cyl_thick  =  30
25
26 # Triangular face
27 # ---------------
28
29 def triangle(p1, p2, p3):
30     l = []
31     l.append(MakeEdge(p1, p2))
32     l.append(MakeEdge(p2, p3))
33     l.append(MakeEdge(p3, p1))
34     w = MakeWire(l)
35     return MakeFace(w, 1)
36
37 # The holed part
38 # ==============
39
40 # Vertex of the holed part
41 # ------------------------
42
43 hole_point_11 = MakeVertex(0     , 0     , 0)
44 hole_point_21 = MakeVertex(box_dx, 0     , 0)
45 hole_point_12 = MakeVertex(0     , box_dy, 0)
46 hole_point_22 = MakeVertex(box_dx, box_dy, 0)
47
48 hole_center   = MakeVertex(cyl_x, cyl_y, 0)
49
50 # Faces of the holed part
51 # -----------------------
52
53 hole_face_1 = triangle(hole_point_11, hole_point_21, hole_center)
54 hole_face_2 = triangle(hole_point_21, hole_point_22, hole_center)
55 hole_face_3 = triangle(hole_point_12, hole_point_22, hole_center)
56 hole_face_4 = triangle(hole_point_11, hole_point_12, hole_center)
57
58 # Solids of the holed part
59 # ------------------------
60
61 cyl_dir = MakeVectorDXDYDZ(0, 0, 1)
62
63 hole_solid_1 = MakePrismVecH(hole_face_1, cyl_dir, cyl_dz)
64 hole_solid_2 = MakePrismVecH(hole_face_2, cyl_dir, cyl_dz)
65 hole_solid_3 = MakePrismVecH(hole_face_3, cyl_dir, cyl_dz)
66 hole_solid_4 = MakePrismVecH(hole_face_4, cyl_dir, cyl_dz)
67
68 hole_internal = MakeCylinder(hole_center, cyl_dir, cyl_radius          , cyl_dz)
69 hole_external = MakeCylinder(hole_center, cyl_dir, cyl_radius+cyl_thick, cyl_dz)
70 hole_median   = MakeCut(hole_external, hole_internal)
71
72 # Boolean operations
73 # ------------------
74
75 blocks = []
76
77 blocks.append(   MakeCut(hole_solid_1, hole_external))
78 blocks.append(MakeCommon(hole_solid_1, hole_median  ))
79
80 blocks.append(   MakeCut(hole_solid_2, hole_external))
81 blocks.append(MakeCommon(hole_solid_2, hole_median  ))
82
83 blocks.append(   MakeCut(hole_solid_3, hole_external))
84 blocks.append(MakeCommon(hole_solid_3, hole_median  ))
85
86 blocks.append(   MakeCut(hole_solid_4, hole_external))
87 blocks.append(MakeCommon(hole_solid_4, hole_median  ))
88
89 # The full part
90 # =============
91
92 # Vertex of the full part
93 # -----------------------
94
95 full_point_11 = MakeVertex(0     , 0     , cyl_dz)
96 full_point_21 = MakeVertex(box_dx, 0     , cyl_dz)
97 full_point_12 = MakeVertex(0     , box_dy, cyl_dz)
98 full_point_22 = MakeVertex(box_dx, box_dy, cyl_dz)
99
100 full_center = MakeVertex(cyl_x, cyl_y, cyl_dz)
101
102 # Faces of the full part
103 # ----------------------
104
105 full_face_1 = triangle(full_point_11, full_point_21, full_center)
106 full_face_2 = triangle(full_point_21, full_point_22, full_center)
107 full_face_3 = triangle(full_point_12, full_point_22, full_center)
108 full_face_4 = triangle(full_point_11, full_point_12, full_center)
109
110 # Solids of the full part
111 # ------------------------
112
113 full_dz = box_dz - cyl_dz
114
115 full_solid_1 = MakePrismVecH(full_face_1, cyl_dir, full_dz)
116 full_solid_2 = MakePrismVecH(full_face_2, cyl_dir, full_dz)
117 full_solid_3 = MakePrismVecH(full_face_3, cyl_dir, full_dz)
118 full_solid_4 = MakePrismVecH(full_face_4, cyl_dir, full_dz)
119
120 full_internal = MakeCylinder(full_center, cyl_dir, cyl_radius          , full_dz)
121 full_external = MakeCylinder(full_center, cyl_dir, cyl_radius+cyl_thick, full_dz)
122 full_median   = MakeCut(full_external, full_internal)
123
124 # Boolean operations
125 # ------------------
126
127 full = []
128
129 full.append(   MakeCut(full_solid_1, full_external))
130 full.append(MakeCommon(full_solid_1, full_median))
131
132 full.append(   MakeCut(full_solid_2, full_external))
133 full.append(MakeCommon(full_solid_2, full_median ))
134
135 full.append(   MakeCut(full_solid_3, full_external))
136 full.append(MakeCommon(full_solid_3, full_median))
137
138 full.append(   MakeCut(full_solid_4, full_external))
139 full.append(MakeCommon(full_solid_4, full_median))
140
141 # Filling the hole
142 # ----------------
143
144 box_d = cyl_radius/3
145
146 x = cyl_x-box_d
147 y = x * cyl_y / cyl_x
148 box_point_11 = MakeVertex(x, y, cyl_dz)
149
150 x = cyl_x+box_d
151 y = (box_dx - x) * cyl_y / (box_dx - cyl_x)
152 box_point_12 = MakeVertex(x, y, cyl_dz)
153
154 x = cyl_x-box_d
155 y = box_dy - x * (box_dy - cyl_y) / cyl_x
156 box_point_21 = MakeVertex(x, y, cyl_dz)
157
158 x = cyl_x+box_d
159 y = box_dy - (box_dx - x) * (box_dy - cyl_y) / (box_dx - cyl_x)
160 box_point_22 = MakeVertex(x, y, cyl_dz)
161
162 box_face = MakeQuad4Vertices(box_point_11, box_point_12, box_point_21, box_point_22)
163
164 box = MakePrismVecH(box_face, cyl_dir, full_dz)
165
166 full.append(box)
167
168 full.append(MakeCut(MakeCommon(full_solid_1, full_internal), box))
169 full.append(MakeCut(MakeCommon(full_solid_2, full_internal), box))
170 full.append(MakeCut(MakeCommon(full_solid_3, full_internal), box))
171 full.append(MakeCut(MakeCommon(full_solid_4, full_internal), box))
172
173 # Cut the cylinder thikness
174 # -------------------------
175
176 full_plan = MakePlane(MakeVertex(0, 0, cyl_dz+cyl_thick), cyl_dir, 5000)
177
178 full_parts = MakePartition(full, [full_plan], [], [], ShapeType["SOLID"])
179
180 # Geometry result
181 # ---------------
182
183 blocks.append(full_parts)
184
185 piece_cpd = MakeCompound(blocks)
186
187 piece_ok = RemoveExtraEdges(piece_cpd)
188
189 piece = MakeGlueFaces(piece_ok, 1.e-3)
190
191 piece_id = addToStudy(piece, "ex13_hole1partial")
192
193 # Meshing
194 # =======
195
196 # Create a mesh
197 # -------------
198
199 hexa = smesh.Mesh(piece, "ex13_hole1partial:hexa")
200
201 algo = hexa.Segment()
202 algo.NumberOfSegments(2)
203
204 hexa.Quadrangle()
205
206 hexa.Hexahedron()
207
208 # Local hypothesis
209 # ----------------
210
211 def local(x, y, z, d):
212     edge = GetEdgeNearPoint(piece, MakeVertex(x, y, z))
213     algo = hexa.Segment(edge)
214     algo.NumberOfSegments(d)
215     algo.Propagation()
216
217 local(0, 0, 100, 40)
218 local(0, 0, 700, 15)
219
220 local(100, 0, 0, 20)
221 local(0, 100, 0, 20)
222
223 local(100, 100, 0, 25)
224
225 d = cyl_radius-3*cyl_thick
226 local(cyl_x+d, cyl_y+d, box_dz, 10)
227
228 # Compute the mesh
229 # ----------------
230
231 hexa.Compute()