Salome HOME
Merge branch 'V8_4_BR'
[modules/smesh.git] / src / SMESH_SWIG / SMESH_Nut.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  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 #####################################################################
25 #Created                :17/02/2005
26 #Auhtor                 :MASLOV Eugeny, KOVALTCHUK Alexey 
27 #####################################################################
28 #
29 import salome
30 salome.salome_init()
31 import GEOM
32 from salome.geom import geomBuilder
33 geompy = geomBuilder.New(salome.myStudy)
34
35 import SMESH, SALOMEDS
36 from salome.smesh import smeshBuilder
37 smesh =  smeshBuilder.New(salome.myStudy)
38
39 import os
40 import math
41
42 #Sketcher_1 creation
43 print "Sketcher creation..."
44 Sketcher_1 = geompy.MakeSketcher("Sketcher:F 100 -57.7:TT 100 57.7:TT 0 115.47:TT -100 57.7:TT -100 -57.7:TT 0 -115.47:WW") 
45 geompy.addToStudy(Sketcher_1, "Sketcher_1")
46 Face_1 = geompy.MakeFace(Sketcher_1, 1)
47 geompy.addToStudy(Face_1, "Face_1")
48
49 #Line creation
50 print "Line  creation..."
51 Line_1 = geompy.MakeLineTwoPnt(geompy.MakeVertex(0,0,0), geompy.MakeVertex(0,0,100))
52 geompy.addToStudy(Line_1, "Line_1")
53
54 #Prism creation
55 print "Prism creation..."
56 Prism_1 = geompy.MakePrismVecH(Face_1, Line_1, 100)
57 geompy.addToStudy(Prism_1, "Prism_1")
58
59 #Sketcher_2 creation
60 print "Sketcher creation..."
61 Sketcher_2 = geompy.MakeSketcher("Sketcher:F 50 0:TT 80 0:TT 112 13:TT 112 48:TT 80 63:TT 80 90:TT 50 90:WW", [0,0,0, 1,0,0, 0,1,0]) 
62 geompy.addToStudy(Sketcher_2, "Sketcher_2")
63 Face_2 = geompy.MakeFace(Sketcher_2, 1)
64 geompy.addToStudy(Face_2, "Face_2")
65
66 #Revolution creation
67 print "Revolution creation..."
68 Revolution_1 = geompy.MakeRevolution(Face_2, Line_1, 2*math.pi)
69 geompy.addToStudy(Revolution_1, "Revolution_1")
70
71 #Common applying
72 print "Common of Revolution and Prism..."
73 Common_1 = geompy.MakeBoolean(Revolution_1, Prism_1, 1)
74 geompy.addToStudy(Common_1, "Common_1")
75
76 #Explode Common_1 on edges
77 CommonExplodedListEdges = geompy.SubShapeAll(Common_1, geompy.ShapeType["EDGE"])
78 for i in range(0, len(CommonExplodedListEdges)):
79     name = "Edge_"+str(i+1)
80     geompy.addToStudyInFather(Common_1, CommonExplodedListEdges[i], name)
81
82 #Fillet applying
83 print "Fillet creation..."
84 Fillet_1 = geompy.MakeFillet(Common_1, 10, geompy.ShapeType["EDGE"], [5])
85 geompy.addToStudy(Fillet_1, "Fillet_1")
86
87 #Chamfer applying
88 print "Chamfer creation..."
89 cyl_face = geompy.GetFaceNearPoint( Fillet_1, geompy.MakeVertex( 50, 0, 45 ), theName='cyl_face')
90 cyl_face_id = geompy.GetSubShapeID( Fillet_1, cyl_face )
91 top_face = geompy.GetFaceNearPoint( Fillet_1, geompy.MakeVertex( 60, 0, 90 ), theName='top_face')
92 top_face_id = geompy.GetSubShapeID( Fillet_1, top_face )
93 Chamfer_1 = geompy.MakeChamferEdge(Fillet_1, 10, 10, cyl_face_id, top_face_id, theName='Chamfer_1' )
94
95 cyl_face = geompy.GetFaceNearPoint( Chamfer_1, geompy.MakeVertex( 80, 0, 85 ), theName='cyl_face')
96 cyl_face_id = geompy.GetSubShapeID( Chamfer_1, cyl_face )
97 top_face = geompy.GetFaceNearPoint( Chamfer_1, geompy.MakeVertex( 65, 0, 90 ), theName='top_face')
98 top_face_id = geompy.GetSubShapeID( Chamfer_1, top_face )
99 Chamfer_2 = geompy.MakeChamferEdge(Chamfer_1, 10, 10, cyl_face_id, top_face_id, theName='Chamfer_2' )
100
101 #Import of the shape from "slots.brep"
102 print "Import multi-rotation from the DATA_DIR/Shapes/Brep/slots.brep"
103 thePath = os.getenv("DATA_DIR")
104 theFileName = os.path.join( thePath,"Shapes","Brep","slots.brep")
105 theShapeForCut = geompy.ImportBREP(theFileName)
106 geompy.addToStudy(theShapeForCut, "slot.brep_1")
107
108 #Cut applying
109 print "Cut..."
110 Cut_1 = geompy.MakeBoolean(Chamfer_2, theShapeForCut, 2)
111 Cut_1_ID = geompy.addToStudy(Cut_1, "Cut_1")
112
113 #Mesh creation
114
115 # -- Init --
116 shape_mesh = salome.IDToObject( Cut_1_ID )
117
118 mesh = smesh.Mesh(shape_mesh, "Nut")
119
120 #HYPOTHESIS CREATION
121 print "-------------------------- Average length"
122 theAverageLength = 5
123 algoReg1D = mesh.Segment()
124 hAvLength = algoReg1D.LocalLength(theAverageLength)
125 print hAvLength.GetName()
126 print hAvLength.GetId()
127 print hAvLength.GetLength()
128 smesh.SetName(hAvLength, "AverageLength_"+str(theAverageLength))
129
130 print "-------------------------- MaxElementArea"
131 theMaxElementArea = 20
132 algoMef = mesh.Triangle(smeshBuilder.MEFISTO)
133 hArea = algoMef.MaxElementArea( theMaxElementArea )
134 print hArea.GetName()
135 print hArea.GetId()
136 print hArea.GetMaxElementArea()
137 smesh.SetName(hArea, "MaxElementArea_"+str(theMaxElementArea))
138
139 print "-------------------------- MaxElementVolume"
140 theMaxElementVolume = 150
141 algoNg = mesh.Tetrahedron(smeshBuilder.NETGEN)
142 hVolume = algoNg.MaxElementVolume( theMaxElementVolume )
143 print hVolume.GetName()
144 print hVolume.GetId()
145 print hVolume.GetMaxElementVolume()
146 smesh.SetName(hVolume, "MaxElementVolume_"+str(theMaxElementVolume))
147
148
149 print "-------------------------- compute the mesh of the mechanic piece"
150 mesh.Compute()
151
152 print "Information about the Nut:"
153 print "Number of nodes       : ", mesh.NbNodes()
154 print "Number of edges       : ", mesh.NbEdges()
155 print "Number of faces       : ", mesh.NbFaces()
156 print "Number of triangles   : ", mesh.NbTriangles()
157 print "Number of quadrangles : ", mesh.NbQuadrangles()
158 print "Number of volumes     : ", mesh.NbVolumes()
159 print "Number of tetrahedrons: ", mesh.NbTetras()
160
161 salome.sg.updateObjBrowser(True)