Salome HOME
Bug 0020072: GHS3DPRLPLUGIN update. Integrating the attached patch.
[modules/smesh.git] / src / SMESH_SWIG / ex13_hole1partial.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 # ==================================
23 #
24 from geompy import *
25
26 import smesh
27
28 # Geometry
29 # ========
30
31 # With hexahedral, build a box partially holed by a not centered cylinder with a thickness
32
33 # Values
34 # ------
35
36 box_dx = 1000
37 box_dy =  900
38 box_dz =  800
39
40 cyl_x      = 500
41 cyl_y      = 300
42 cyl_dz     = 600
43 cyl_radius = 150
44 cyl_thick  =  30
45
46 # Triangular face
47 # ---------------
48
49 def triangle(p1, p2, p3):
50     l = []
51     l.append(MakeEdge(p1, p2))
52     l.append(MakeEdge(p2, p3))
53     l.append(MakeEdge(p3, p1))
54     w = MakeWire(l)
55     return MakeFace(w, 1)
56
57 # The holed part
58 # ==============
59
60 # Vertex of the holed part
61 # ------------------------
62
63 hole_point_11 = MakeVertex(0     , 0     , 0)
64 hole_point_21 = MakeVertex(box_dx, 0     , 0)
65 hole_point_12 = MakeVertex(0     , box_dy, 0)
66 hole_point_22 = MakeVertex(box_dx, box_dy, 0)
67
68 hole_center   = MakeVertex(cyl_x, cyl_y, 0)
69
70 # Faces of the holed part
71 # -----------------------
72
73 hole_face_1 = triangle(hole_point_11, hole_point_21, hole_center)
74 hole_face_2 = triangle(hole_point_21, hole_point_22, hole_center)
75 hole_face_3 = triangle(hole_point_12, hole_point_22, hole_center)
76 hole_face_4 = triangle(hole_point_11, hole_point_12, hole_center)
77
78 # Solids of the holed part
79 # ------------------------
80
81 cyl_dir = MakeVectorDXDYDZ(0, 0, 1)
82
83 hole_solid_1 = MakePrismVecH(hole_face_1, cyl_dir, cyl_dz)
84 hole_solid_2 = MakePrismVecH(hole_face_2, cyl_dir, cyl_dz)
85 hole_solid_3 = MakePrismVecH(hole_face_3, cyl_dir, cyl_dz)
86 hole_solid_4 = MakePrismVecH(hole_face_4, cyl_dir, cyl_dz)
87
88 hole_internal = MakeCylinder(hole_center, cyl_dir, cyl_radius          , cyl_dz)
89 hole_external = MakeCylinder(hole_center, cyl_dir, cyl_radius+cyl_thick, cyl_dz)
90 hole_median   = MakeCut(hole_external, hole_internal)
91
92 # Boolean operations
93 # ------------------
94
95 blocks = []
96
97 blocks.append(   MakeCut(hole_solid_1, hole_external))
98 blocks.append(MakeCommon(hole_solid_1, hole_median  ))
99
100 blocks.append(   MakeCut(hole_solid_2, hole_external))
101 blocks.append(MakeCommon(hole_solid_2, hole_median  ))
102
103 blocks.append(   MakeCut(hole_solid_3, hole_external))
104 blocks.append(MakeCommon(hole_solid_3, hole_median  ))
105
106 blocks.append(   MakeCut(hole_solid_4, hole_external))
107 blocks.append(MakeCommon(hole_solid_4, hole_median  ))
108
109 # The full part
110 # =============
111
112 # Vertex of the full part
113 # -----------------------
114
115 full_point_11 = MakeVertex(0     , 0     , cyl_dz)
116 full_point_21 = MakeVertex(box_dx, 0     , cyl_dz)
117 full_point_12 = MakeVertex(0     , box_dy, cyl_dz)
118 full_point_22 = MakeVertex(box_dx, box_dy, cyl_dz)
119
120 full_center = MakeVertex(cyl_x, cyl_y, cyl_dz)
121
122 # Faces of the full part
123 # ----------------------
124
125 full_face_1 = triangle(full_point_11, full_point_21, full_center)
126 full_face_2 = triangle(full_point_21, full_point_22, full_center)
127 full_face_3 = triangle(full_point_12, full_point_22, full_center)
128 full_face_4 = triangle(full_point_11, full_point_12, full_center)
129
130 # Solids of the full part
131 # ------------------------
132
133 full_dz = box_dz - cyl_dz
134
135 full_solid_1 = MakePrismVecH(full_face_1, cyl_dir, full_dz)
136 full_solid_2 = MakePrismVecH(full_face_2, cyl_dir, full_dz)
137 full_solid_3 = MakePrismVecH(full_face_3, cyl_dir, full_dz)
138 full_solid_4 = MakePrismVecH(full_face_4, cyl_dir, full_dz)
139
140 full_internal = MakeCylinder(full_center, cyl_dir, cyl_radius          , full_dz)
141 full_external = MakeCylinder(full_center, cyl_dir, cyl_radius+cyl_thick, full_dz)
142 full_median   = MakeCut(full_external, full_internal)
143
144 # Boolean operations
145 # ------------------
146
147 full = []
148
149 full.append(   MakeCut(full_solid_1, full_external))
150 full.append(MakeCommon(full_solid_1, full_median))
151
152 full.append(   MakeCut(full_solid_2, full_external))
153 full.append(MakeCommon(full_solid_2, full_median ))
154
155 full.append(   MakeCut(full_solid_3, full_external))
156 full.append(MakeCommon(full_solid_3, full_median))
157
158 full.append(   MakeCut(full_solid_4, full_external))
159 full.append(MakeCommon(full_solid_4, full_median))
160
161 # Filling the hole
162 # ----------------
163
164 box_d = cyl_radius/3
165
166 x = cyl_x-box_d
167 y = x * cyl_y / cyl_x
168 box_point_11 = MakeVertex(x, y, cyl_dz)
169
170 x = cyl_x+box_d
171 y = (box_dx - x) * cyl_y / (box_dx - cyl_x)
172 box_point_12 = MakeVertex(x, y, cyl_dz)
173
174 x = cyl_x-box_d
175 y = box_dy - x * (box_dy - cyl_y) / cyl_x
176 box_point_21 = MakeVertex(x, y, cyl_dz)
177
178 x = cyl_x+box_d
179 y = box_dy - (box_dx - x) * (box_dy - cyl_y) / (box_dx - cyl_x)
180 box_point_22 = MakeVertex(x, y, cyl_dz)
181
182 box_face = MakeQuad4Vertices(box_point_11, box_point_12, box_point_21, box_point_22)
183
184 box = MakePrismVecH(box_face, cyl_dir, full_dz)
185
186 full.append(box)
187
188 full.append(MakeCut(MakeCommon(full_solid_1, full_internal), box))
189 full.append(MakeCut(MakeCommon(full_solid_2, full_internal), box))
190 full.append(MakeCut(MakeCommon(full_solid_3, full_internal), box))
191 full.append(MakeCut(MakeCommon(full_solid_4, full_internal), box))
192
193 # Cut the cylinder thikness
194 # -------------------------
195
196 full_plan = MakePlane(MakeVertex(0, 0, cyl_dz+cyl_thick), cyl_dir, 5000)
197
198 full_parts = MakePartition(full, [full_plan], [], [], ShapeType["SOLID"])
199
200 # Geometry result
201 # ---------------
202
203 blocks.append(full_parts)
204
205 piece_cpd = MakeCompound(blocks)
206
207 piece_ok = RemoveExtraEdges(piece_cpd)
208
209 piece = MakeGlueFaces(piece_ok, 1.e-3)
210
211 piece_id = addToStudy(piece, "ex13_hole1partial")
212
213 # Meshing
214 # =======
215
216 # Create a mesh
217 # -------------
218
219 hexa = smesh.Mesh(piece, "ex13_hole1partial:hexa")
220
221 algo = hexa.Segment()
222 algo.NumberOfSegments(2)
223
224 hexa.Quadrangle()
225
226 hexa.Hexahedron()
227
228 # Local hypothesis
229 # ----------------
230
231 def local(x, y, z, d):
232     edge = GetEdgeNearPoint(piece, MakeVertex(x, y, z))
233     algo = hexa.Segment(edge)
234     algo.NumberOfSegments(d)
235     algo.Propagation()
236
237 local(0, 0, 100, 40)
238 local(0, 0, 700, 15)
239
240 local(100, 0, 0, 20)
241 local(0, 100, 0, 20)
242
243 local(100, 100, 0, 25)
244
245 d = cyl_radius-3*cyl_thick
246 local(cyl_x+d, cyl_y+d, box_dz, 10)
247
248 # Compute the mesh
249 # ----------------
250
251 hexa.Compute()