Salome HOME
IPAL9153, IPAL9148, IPAL9150
[modules/smesh.git] / src / SMESH_SWIG / SMESH_Nut.py
1 #####################################################################
2 #Created                :17/02/2005
3 #Auhtor                 :MASLOV Eugeny, KOVALTCHUK Alexey 
4 #####################################################################
5
6 import geompy
7 import salome
8 import os
9 import math
10 import StdMeshers
11 import SMESH
12
13 #Sketcher_1 creation
14 print "Sketcher creation..."
15 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") 
16 geompy.addToStudy(Sketcher_1, "Sketcher_1")
17 Face_1 = geompy.MakeFace(Sketcher_1, 1)
18 geompy.addToStudy(Face_1, "Face_1")
19
20 #Line creation
21 print "Line  creation..."
22 Line_1 = geompy.MakeLineTwoPnt(geompy.MakeVertex(0,0,0), geompy.MakeVertex(0,0,100))
23 geompy.addToStudy(Line_1, "Line_1")
24
25 #Prism creation
26 print "Prism creation..."
27 Prism_1 = geompy.MakePrismVecH(Face_1, Line_1, 100)
28 geompy.addToStudy(Prism_1, "Prism_1")
29
30 #Sketcher_2 creation
31 print "Sketcher creation..."
32 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]) 
33 geompy.addToStudy(Sketcher_2, "Sketcher_2")
34 Face_2 = geompy.MakeFace(Sketcher_2, 1)
35 geompy.addToStudy(Face_2, "Face_2")
36
37 #Revolution creation
38 print "Revolution creation..."
39 Revolution_1 = geompy.MakeRevolution(Face_2, Line_1, 2*math.pi)
40 geompy.addToStudy(Revolution_1, "Revolution_1")
41
42 #Common applying
43 print "Common of Revolution and Prism..."
44 Common_1 = geompy.MakeBoolean(Revolution_1, Prism_1, 1)
45 geompy.addToStudy(Common_1, "Common_1")
46
47 #Explode Common_1 on edges
48 CommonExplodedListEdges = geompy.SubShapeAll(Common_1, geompy.ShapeType["EDGE"])
49 for i in range(0, len(CommonExplodedListEdges)):
50     name = "Edge_"+str(i+1)
51     geompy.addToStudyInFather(Common_1, CommonExplodedListEdges[i], name)
52
53 #Fillet applying
54 print "Fillet creation..."
55 Fillet_1 = geompy.MakeFillet(Common_1, 10, geompy.ShapeType["EDGE"], [6])
56 geompy.addToStudy(Fillet_1, "Fillet_1")
57
58 #Chamfer applying
59 print "Chamfer creation..."
60 Chamfer_1 = geompy.MakeChamferEdge(Fillet_1, 10, 10, 16, 50 )
61 geompy.addToStudy(Chamfer_1, "Chamfer_1")
62 Chamfer_2 = geompy.MakeChamferEdge(Chamfer_1, 10, 10, 21, 31 )
63 geompy.addToStudy(Chamfer_2, "Chamfer_2")
64
65 #Import of the shape from "slots.brep"
66 print "Import multi-rotation from the KERNEL_ROOT_DIR/examples/slots.brep"
67 thePath = os.getenv("KERNEL_ROOT_DIR")
68 theFileName = thePath + "/examples/slots.brep"
69 theShapeForCut = geompy.ImportBREP(theFileName)
70 geompy.addToStudy(theShapeForCut, "slot.brep_1")
71
72 #Cut applying
73 print "Cut..."
74 Cut_1 = geompy.MakeBoolean(Chamfer_2, theShapeForCut, 2)
75 Cut_1_ID = geompy.addToStudy(Cut_1, "Cut_1")
76
77 #Mesh creation
78 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
79
80 # -- Init --
81 shape_mesh = salome.IDToObject( Cut_1_ID )
82 smesh.SetCurrentStudy(salome.myStudy)
83 mesh = smesh.CreateMesh(shape_mesh)
84 smeshgui = salome.ImportComponentGUI("SMESH")
85 smeshgui.Init(salome.myStudyId)
86 idmesh = salome.ObjectToID(mesh)
87 smeshgui.SetName( idmesh, "Nut" )
88
89 #HYPOTHESIS CREATION
90 print "-------------------------- Average length"
91 theAverageLength = 5
92 hAvLength = smesh.CreateHypothesis( "LocalLength", "libStdMeshersEngine.so" )
93 hAvLength.SetLength( theAverageLength )
94 print hAvLength.GetName()
95 print hAvLength.GetId()
96 smeshgui.SetName(salome.ObjectToID(hAvLength), "AverageLength_5")
97
98 print "-------------------------- MaxElementArea"
99 theMaxElementArea = 20
100 hArea20 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
101 hArea20.SetMaxElementArea( theMaxElementArea )
102 print hArea20.GetName()
103 print hArea20.GetId()
104 print hArea20.GetMaxElementArea()
105 smeshgui.SetName(salome.ObjectToID(hArea20), "MaxElementArea_20")
106
107 print "-------------------------- MaxElementVolume"
108 theMaxElementVolume = 150
109 hVolume150 = smesh.CreateHypothesis( "MaxElementVolume", "libStdMeshersEngine.so" )
110 hVolume150.SetMaxElementVolume( theMaxElementVolume )
111 print hVolume150.GetName()
112 print hVolume150.GetId()
113 print hVolume150.GetMaxElementVolume()
114 smeshgui.SetName(salome.ObjectToID(hVolume150), "MaxElementVolume_150")
115
116 mesh.AddHypothesis(shape_mesh, hAvLength)
117 mesh.AddHypothesis(shape_mesh, hArea20)
118 mesh.AddHypothesis(shape_mesh, hVolume150)
119
120 print "-------------------------- Regular_1D"
121
122 algoReg1D = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" )
123 listHyp = algoReg1D.GetCompatibleHypothesis()
124 for hyp in listHyp:
125     print hyp
126 print algoReg1D.GetName()
127 print algoReg1D.GetId()
128 smeshgui.SetName(salome.ObjectToID(algoReg1D), "Wire discretisation")
129
130 print "-------------------------- MEFISTO_2D"
131 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" )
132 listHyp = algoMef.GetCompatibleHypothesis()
133 for hyp in listHyp:
134     print hyp
135 print algoMef.GetName()
136 print algoMef.GetId()
137 smeshgui.SetName(salome.ObjectToID(algoMef), "Triangle (Mefisto)")
138
139 print "-------------------------- NETGEN_3D"
140
141 algoNg = smesh.CreateHypothesis( "NETGEN_3D", "libNETGENEngine.so" )
142 print algoNg.GetName()
143 print algoNg.GetId()
144 smeshgui.SetName(salome.ObjectToID(algoNg), "Tetrahedron (NETGEN)")
145 mesh.AddHypothesis(shape_mesh, algoReg1D)
146 mesh.AddHypothesis(shape_mesh, algoMef)
147 mesh.AddHypothesis(shape_mesh, algoNg)
148
149 print "-------------------------- compute the mesh of the mechanic piece"
150 smesh.Compute(mesh,shape_mesh)
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(1)