Salome HOME
Update copyrights
[modules/smesh.git] / src / SMESH_SWIG / SMESH_mechanic_editor.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 #  File   : SMESH_withHole.py
25 #  Author : Lucien PIGNOLONI
26 #  Module : SMESH
27 #  $Header$
28 #-------------------------------------------------------------------------
29 #
30 import salome
31 salome.salome_init()
32 import GEOM
33 from salome.geom import geomBuilder
34 geompy = geomBuilder.New()
35
36 import SMESH, SALOMEDS
37 from salome.smesh import smeshBuilder
38 smesh =  smeshBuilder.New()
39
40 # ---------------------------- GEOM --------------------------------------
41
42 # ---- define contiguous arcs and segment to define a closed wire
43 p1   = geompy.MakeVertex( 100.0,   0.0,  0.0 )
44 p2   = geompy.MakeVertex(  50.0,  50.0,  0.0 )
45 p3   = geompy.MakeVertex( 100.0, 100.0,  0.0 )
46 arc1 = geompy.MakeArc( p1, p2, p3 )
47
48 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
49 seg1 = geompy.MakeVector( p3, p4 )
50
51 p5   = geompy.MakeVertex( 200.0, 70.0, 0.0 )
52 p6   = geompy.MakeVertex( 170.0, 40.0, 0.0 )
53 arc2 = geompy.MakeArc( p4, p5, p6 )
54
55 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
56 arc3 = geompy.MakeArc( p6, p7, p1 )
57
58 # ---- define a closed wire with arcs and segment
59 List1 = []
60 List1.append( arc1 )
61 List1.append( seg1 )
62 List1.append( arc2 )
63 List1.append( arc3 )
64
65 wire1 = geompy.MakeWire( List1 )
66 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
67
68 # ---- define a planar face with wire
69 WantPlanarFace = 1 #True
70 face1 = geompy.MakeFace( wire1, WantPlanarFace )
71 Id_face1 = geompy.addToStudy( face1, "face1" )
72
73 # ---- create a shape by extrusion
74 pO = geompy.MakeVertex( 0.0, 0.0,   0.0 )
75 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
76 vz = geompy.MakeVector( pO, pz )
77
78 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
79 Id_prism1 = geompy.addToStudy( prism1, "prism1" )
80
81 # ---- create two cylinders
82 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
83 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
84
85 radius = 20.0
86 height = 180.0
87 cyl1 = geompy.MakeCylinder( pc1, vz, radius, height )
88 cyl2 = geompy.MakeCylinder( pc2, vz, radius, height )
89
90 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
91 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
92
93 # ---- cut with cyl1
94 shape = geompy.MakeBoolean( prism1, cyl1, 2 )
95
96 # ---- fuse with cyl2 to obtain the final mechanic piece :)
97 mechanic = geompy.MakeBoolean( shape, cyl2, 3 )
98 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
99
100 # ---- explode on faces
101 SubFaceL = geompy.SubShapeAllSorted(mechanic, geompy.ShapeType["FACE"])
102
103 # ---- add a face sub-shape in study to be meshed different
104 sub_face1 = SubFaceL[0]
105 name      = geompy.SubShapeName( sub_face1, mechanic )
106
107 Id_SubFace1 = geompy.addToStudyInFather( mechanic, sub_face1, name )
108
109 # ---- add a face sub-shape in study to be meshed different
110 sub_face2 = SubFaceL[4]
111 name      = geompy.SubShapeName( sub_face2, mechanic )
112
113 Id_SubFace2 = geompy.addToStudyInFather( mechanic, sub_face2, name )
114
115 # ---- add a face sub-shape in study to be meshed different
116 sub_face3 = SubFaceL[5]
117 name      = geompy.SubShapeName( sub_face3, mechanic )
118
119 Id_SubFace3 = geompy.addToStudyInFather( mechanic, sub_face3, name )
120
121 # ---- add a face sub-shape in study to be meshed different
122 sub_face4 = SubFaceL[10]
123 name      = geompy.SubShapeName( sub_face4, mechanic )
124
125 Id_SubFace4 = geompy.addToStudyInFather( mechanic, sub_face4, name )
126
127 # ---------------------------- SMESH --------------------------------------
128
129 # -- Init --
130 shape_mesh = salome.IDToObject( Id_mechanic )
131
132 mesh = smesh.Mesh(shape_mesh, "Mesh_mechanic")
133
134 print("-------------------------- NumberOfSegments")
135
136 numberOfSegment = 10
137
138 algo = mesh.Segment()
139 hypNbSeg = algo.NumberOfSegments(numberOfSegment)
140 print(hypNbSeg.GetName())
141 print(hypNbSeg.GetId())
142 print(hypNbSeg.GetNumberOfSegments())
143 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegment))
144
145
146 print("-------------------------- MaxElementArea")
147
148 maxElementArea = 25
149
150 algo = mesh.Triangle()
151 hypArea25 = algo.MaxElementArea(maxElementArea)
152 print(hypArea25.GetName())
153 print(hypArea25.GetId())
154 print(hypArea25.GetMaxElementArea())
155 smesh.SetName(hypArea25, "MaxElementArea_" + str(maxElementArea))
156
157
158 # Create submesh on sub_face1 - sub_face4
159 # ---------------------------------------
160
161 # Set 2D algorithm to submesh on sub_face1
162 algo = mesh.Quadrangle(sub_face1)
163 smesh.SetName(algo.GetSubMesh(), "SubMeshFace1")
164 submesh1 = algo.GetSubMesh()
165
166 # Set 2D algorithm to submesh on sub_face2
167 algo = mesh.Quadrangle(sub_face2)
168 smesh.SetName(algo.GetSubMesh(), "SubMeshFace2")
169 submesh2 = algo.GetSubMesh()
170
171 # Set 2D algorithm to submesh on sub_face3
172 algo = mesh.Quadrangle(sub_face3)
173 smesh.SetName(algo.GetSubMesh(), "SubMeshFace3")
174 submesh3 = algo.GetSubMesh()
175
176 # Set 2D algorithm to submesh on sub_face4
177 algo = mesh.Quadrangle(sub_face4)
178 smesh.SetName(algo.GetSubMesh(), "SubMeshFace4")
179 submesh4 = algo.GetSubMesh()
180
181
182 print("-------------------------- compute the mesh of the mechanic piece")
183
184 mesh.Compute()
185
186 print("Information about the Mesh_mechanic:")
187 print("Number of nodes       : ", mesh.NbNodes())
188 print("Number of edges       : ", mesh.NbEdges())
189 print("Number of faces       : ", mesh.NbFaces())
190 print("Number of triangles   : ", mesh.NbTriangles())
191 print("Number of quadrangles : ", mesh.NbQuadrangles())
192 print("Number of volumes     : ", mesh.NbVolumes())
193 print("Number of tetrahedrons: ", mesh.NbTetras())
194
195
196 #1 cutting of quadrangles of the 'SubMeshFace2' submesh
197 mesh.SplitQuadObject(submesh2, 1)
198
199 #2 cutting of triangles of the group
200 FacesTriToQuad = [ 2391, 2824, 2825, 2826, 2827, 2828, 2832, 2833, 2834, 2835, 2836, 2837, 2838, 2839, 2841, 2844, 2845, 2847, 2854, 2861, 2863, 2922, 2923, 2924, 2925, 2926, 2927, 2928, 2929, 2930, 2931, 2932, 2933, 2934, 2935, 2936, 2937, 2938, 2940, 2941, 2946, 2951, 2970, 2971, 2972, 2973, 2974, 2975, 2976, 2977, 2978, 2979, 2980, 2981, 2982, 2983, 2984, 2985 ]
201 GroupTriToQuad = mesh.MakeGroupByIds("Group of faces (quad)", SMESH.FACE, FacesTriToQuad)
202 mesh.TriToQuadObject(GroupTriToQuad, SMESH.FT_AspectRatio , 1.57)
203
204 #3 extrusion of the group
205 point = SMESH.PointStruct(0, 0, 5)
206 vector = SMESH.DirStruct(point)
207 mesh.ExtrusionSweepObject(GroupTriToQuad, vector, 5)
208
209 #4 mirror object
210 mesh.Mirror([], SMESH.AxisStruct(0, 0, 0, 0, 0, 0), smesh.POINT, 0)
211
212 #5 mesh translation
213 point = SMESH.PointStruct(10, 10, 10)
214 vector = SMESH.DirStruct(point)
215 mesh.Translate([], vector, 0)
216
217 #6 mesh rotation
218 axisXYZ = SMESH.AxisStruct(0, 0, 0, 10, 10, 10)
219 angle180 =  180*3.141/180
220 mesh.Rotate([], axisXYZ, angle180, 0)
221
222 #7 group smoothing
223 FacesSmooth = [864, 933, 941, 950, 1005, 1013]
224 GroupSmooth = mesh.MakeGroupByIds("Group of faces (smooth)", SMESH.FACE, FacesSmooth)
225 mesh.SmoothObject(GroupSmooth, [], 20, 2, smesh.CENTROIDAL_SMOOTH)
226
227 #8 rotation sweep object
228 FacesRotate = [492, 493, 502, 503]
229 GroupRotate = mesh.MakeGroupByIds("Group of faces (rotate)", SMESH.FACE, FacesRotate)
230 angle45 =  45*3.141/180
231 axisXYZ = SMESH.AxisStruct(-38.3128, -73.3658, -133.321, -13.3402, -13.3265, 6.66632)
232 mesh.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5)
233
234 #9 reorientation of the submesh1
235 mesh.ReorientObject(submesh1)
236
237 salome.sg.updateObjBrowser()