Salome HOME
Imported using TkCVS
[samples/datafiles.git] / Superv / Python / InLine_Nut.py
1 #####################################################################
2 #Created                :17/02/2005
3 #Auhtor                 :KOVALTCHUK Alexey 
4 #####################################################################
5
6 def Geometry(y1=50, y2=90):
7     from batchmode_geompy import *
8     import  math 
9     import os
10     #Sketcher_1 creation
11     Sketcher_1 = 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") 
12     addToStudy(Sketcher_1, "Sketcher_1")
13     Face_1 = MakeFace(Sketcher_1, 1)
14     addToStudy(Face_1, "Face_1")
15     #Line creation
16     Line_1 = MakeLineTwoPnt(MakeVertex(0,0,0), MakeVertex(0,0,100))
17     addToStudy(Line_1, "Line_1")
18     #Prism creation
19     Prism_1 = MakePrismVecH(Face_1, Line_1, 100)
20     addToStudy(Prism_1, "Prism_1")
21     #Sketcher_2 creation
22     #"Sketcher:F 50 0:TT 80 0:TT 112 13:TT 112 48:TT 80 63:TT 80 90:TT 50 90:WW"
23     command = "Sketcher:F " + str(y1)+ " 0:TT 80 0:TT 112 13:TT 112 48:TT 80 63:TT 80 " + str(y2)+ ":TT " + str(y1) + " " + str(y2) + ":WW"
24     Sketcher_2 = MakeSketcher(command, [0,0,0, 1,0,0, 0,1,0])
25     addToStudy(Sketcher_2, "Sketcher_2")
26     Face_2 = MakeFace(Sketcher_2, 1)
27     addToStudy(Face_2, "Face_2")
28     #Revolution creation
29     Revolution_1 = MakeRevolution(Face_2, Line_1, 2*math.pi)
30     addToStudy(Revolution_1, "Revolution_1")
31     #Common applying
32     Common_1 = MakeBoolean(Revolution_1, Prism_1, 1)
33     addToStudy(Common_1, "Common_1")
34     #Explode Common_1 on edges
35     CommonExplodedListEdges = SubShapeAll(Common_1, ShapeType["EDGE"])
36     for i in range(0, len(CommonExplodedListEdges)):
37         name = "Edge_"+str(i+1)
38         addToStudyInFather(Common_1, CommonExplodedListEdges[i], name)
39     #Fillet applying
40     ID = GetSubShapeID(Common_1, CommonExplodedListEdges[0])
41     Fillet_1 = MakeFillet(Common_1, 10, ShapeType["EDGE"], [6])
42     addToStudy(Fillet_1, "Fillet_1")
43     #Chamfer applying
44     Chamfer_1 = MakeChamferEdge(Fillet_1, 10, 10, 16, 50 )
45     addToStudy(Chamfer_1, "Chamfer_1")
46     Chamfer_2 = MakeChamferEdge(Chamfer_1, 10, 10, 21, 31 )
47     addToStudy(Chamfer_2, "Chamfer_2")
48     #Import of the shape from "slots.brep"
49     thePath = os.getenv("KERNEL_ROOT_DIR")
50     theFileName = thePath + "/examples/slots.brep"
51     theShapeForCut = ImportBREP(theFileName)
52     addToStudy(theShapeForCut, "slot.brep_1")
53     #Cut applying
54     Cut_1 = MakeBoolean(Chamfer_2, theShapeForCut, 2)
55     addToStudy(Cut_1, "Cut_1")
56     return Cut_1
57     
58
59 def Mesh(theNameOfTheShape = "Cut_1", theAverageLength = 5, theMaxElementArea = 20, theMaxElementVolume = 150):
60     #Format of the <theNameOfTheShape> parameter is: "[[first level object/[second level object/[.../]]]Name"
61     from batchmode_smesh import *
62     import StdMeshers
63     smesh.SetCurrentStudy(myStudy)
64     theNameOfTheShape = "/Geometry/"+ str(theNameOfTheShape)
65     SObject = myStudy.FindObjectByPath(theNameOfTheShape)
66     if SObject == None:
67         raise RuntimeError, "It is an incorrect object name..."
68     shape_mesh = IDToObject( SObject.GetID() )
69     mesh = smesh.CreateMesh(shape_mesh)
70     idmesh = ObjectToID(mesh)
71     SetName( idmesh, "Mesh" )
72
73     #HYPOTHESIS CREATION
74     print "-------------------------- Average length"
75     theName = "AverageLength" + str(theAverageLength)
76     hAvLength = smesh.CreateHypothesis( "LocalLength", "libStdMeshersEngine.so" )
77     hAvLength.SetLength( theAverageLength )
78     print hAvLength.GetName()
79     print hAvLength.GetId()
80     SetName(ObjectToID(hAvLength), theName)
81
82     print "-------------------------- MaxElementArea"
83     theName = "MaxElementArea" + str( theMaxElementArea )
84     hArea = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
85     hArea.SetMaxElementArea( theMaxElementArea )
86     print hArea.GetName()
87     print hArea.GetId()
88     print hArea.GetMaxElementArea()
89     SetName(ObjectToID(hArea), theName)
90     
91     print "-------------------------- MaxElementVolume"
92     theName = "MaxElementVolume" + str( theMaxElementVolume )
93     hVolume = smesh.CreateHypothesis( "MaxElementVolume", "libStdMeshersEngine.so" )
94     hVolume.SetMaxElementVolume( theMaxElementVolume )
95     print hVolume.GetName()
96     print hVolume.GetId()
97     print hVolume.GetMaxElementVolume()
98     SetName(ObjectToID(hVolume), theName)
99     
100     mesh.AddHypothesis(shape_mesh, hAvLength)
101     mesh.AddHypothesis(shape_mesh, hArea)
102     mesh.AddHypothesis(shape_mesh, hVolume)
103     
104     print "-------------------------- Regular_1D"
105     
106     algoReg1D = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" )
107     listHyp = algoReg1D.GetCompatibleHypothesis()
108     for hyp in listHyp:
109         print hyp
110         print algoReg1D.GetName()
111         print algoReg1D.GetId()
112     SetName(ObjectToID(algoReg1D), "Wire discretisation")
113         
114     print "-------------------------- MEFISTO_2D"
115     algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" )
116     listHyp = algoMef.GetCompatibleHypothesis()
117     for hyp in listHyp:
118         print hyp
119         print algoMef.GetName()
120         print algoMef.GetId()
121     SetName(ObjectToID(algoMef), "Triangle (Mefisto)")
122
123     print "-------------------------- NETGEN_3D"        
124     algoNg = smesh.CreateHypothesis( "NETGEN_3D", "libNETGENEngine.so" )
125     for hyp in listHyp:
126         print hyp
127         print algoNg.GetName()
128         print algoNg.GetId()
129     SetName(ObjectToID(algoNg), "Tetrahedron (NETGEN)")
130     mesh.AddHypothesis(shape_mesh, algoReg1D)
131     mesh.AddHypothesis(shape_mesh, algoMef)
132     mesh.AddHypothesis(shape_mesh, algoNg)
133     smesh.Compute(mesh,shape_mesh)
134             
135     print "Information about the mesh:"
136     print "Number of nodes       : ", mesh.NbNodes()
137     print "Number of edges       : ", mesh.NbEdges()
138     print "Number of faces       : ", mesh.NbFaces()
139     print "Number of triangles   : ", mesh.NbTriangles()
140     print "Number of quadrangles : ", mesh.NbQuadrangles()
141     print "Number of volumes     : ", mesh.NbVolumes()
142     print "Number of tetrahedrons: ", mesh.NbTetras()
143             
144