1 #####################################################################
3 #Auhtor :KOVALTCHUK Alexey
4 #####################################################################
6 def Geometry(y1=50, y2=90):
7 from batchmode_geompy import *
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")
16 Line_1 = MakeLineTwoPnt(MakeVertex(0,0,0), MakeVertex(0,0,100))
17 addToStudy(Line_1, "Line_1")
19 Prism_1 = MakePrismVecH(Face_1, Line_1, 100)
20 addToStudy(Prism_1, "Prism_1")
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")
29 Revolution_1 = MakeRevolution(Face_2, Line_1, 2*math.pi)
30 addToStudy(Revolution_1, "Revolution_1")
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)
40 ID = GetSubShapeID(Common_1, CommonExplodedListEdges[0])
41 Fillet_1 = MakeFillet(Common_1, 10, ShapeType["EDGE"], [6])
42 addToStudy(Fillet_1, "Fillet_1")
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")
54 Cut_1 = MakeBoolean(Chamfer_2, theShapeForCut, 2)
55 addToStudy(Cut_1, "Cut_1")
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 *
63 smesh.SetCurrentStudy(myStudy)
64 theNameOfTheShape = "/Geometry/"+ str(theNameOfTheShape)
65 SObject = myStudy.FindObjectByPath(theNameOfTheShape)
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" )
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)
82 print "-------------------------- MaxElementArea"
83 theName = "MaxElementArea" + str( theMaxElementArea )
84 hArea = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
85 hArea.SetMaxElementArea( theMaxElementArea )
88 print hArea.GetMaxElementArea()
89 SetName(ObjectToID(hArea), theName)
91 print "-------------------------- MaxElementVolume"
92 theName = "MaxElementVolume" + str( theMaxElementVolume )
93 hVolume = smesh.CreateHypothesis( "MaxElementVolume", "libStdMeshersEngine.so" )
94 hVolume.SetMaxElementVolume( theMaxElementVolume )
95 print hVolume.GetName()
97 print hVolume.GetMaxElementVolume()
98 SetName(ObjectToID(hVolume), theName)
100 mesh.AddHypothesis(shape_mesh, hAvLength)
101 mesh.AddHypothesis(shape_mesh, hArea)
102 mesh.AddHypothesis(shape_mesh, hVolume)
104 print "-------------------------- Regular_1D"
106 algoReg1D = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" )
107 listHyp = algoReg1D.GetCompatibleHypothesis()
110 print algoReg1D.GetName()
111 print algoReg1D.GetId()
112 SetName(ObjectToID(algoReg1D), "Wire discretisation")
114 print "-------------------------- MEFISTO_2D"
115 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" )
116 listHyp = algoMef.GetCompatibleHypothesis()
119 print algoMef.GetName()
120 print algoMef.GetId()
121 SetName(ObjectToID(algoMef), "Triangle (Mefisto)")
123 print "-------------------------- NETGEN_3D"
124 algoNg = smesh.CreateHypothesis( "NETGEN_3D", "libNETGENEngine.so" )
127 print algoNg.GetName()
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)
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()