1 # Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #####################################################################
25 #Auhtor :KOVALTCHUK Alexey
26 #####################################################################
28 def Geometry(y1=50, y2=90):
29 from batchmode_geompy import *
33 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")
34 addToStudy(Sketcher_1, "Sketcher_1")
35 Face_1 = MakeFace(Sketcher_1, 1)
36 addToStudy(Face_1, "Face_1")
38 Line_1 = MakeLineTwoPnt(MakeVertex(0,0,0), MakeVertex(0,0,100))
39 addToStudy(Line_1, "Line_1")
41 Prism_1 = MakePrismVecH(Face_1, Line_1, 100)
42 addToStudy(Prism_1, "Prism_1")
44 #"Sketcher:F 50 0:TT 80 0:TT 112 13:TT 112 48:TT 80 63:TT 80 90:TT 50 90:WW"
45 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"
46 Sketcher_2 = MakeSketcher(command, [0,0,0, 1,0,0, 0,1,0])
47 addToStudy(Sketcher_2, "Sketcher_2")
48 Face_2 = MakeFace(Sketcher_2, 1)
49 addToStudy(Face_2, "Face_2")
51 Revolution_1 = MakeRevolution(Face_2, Line_1, 2*math.pi)
52 addToStudy(Revolution_1, "Revolution_1")
54 Common_1 = MakeBoolean(Revolution_1, Prism_1, 1)
55 addToStudy(Common_1, "Common_1")
56 #Explode Common_1 on edges
57 CommonExplodedListEdges = SubShapeAll(Common_1, ShapeType["EDGE"])
58 for i in range(0, len(CommonExplodedListEdges)):
59 name = "Edge_"+str(i+1)
60 addToStudyInFather(Common_1, CommonExplodedListEdges[i], name)
62 ID = GetSubShapeID(Common_1, CommonExplodedListEdges[0])
63 Fillet_1 = MakeFillet(Common_1, 10, ShapeType["EDGE"], [6])
64 addToStudy(Fillet_1, "Fillet_1")
66 Chamfer_1 = MakeChamferEdge(Fillet_1, 10, 10, 16, 50 )
67 addToStudy(Chamfer_1, "Chamfer_1")
68 Chamfer_2 = MakeChamferEdge(Chamfer_1, 10, 10, 21, 31 )
69 addToStudy(Chamfer_2, "Chamfer_2")
70 #Import of the shape from "slots.brep"
71 thePath = os.getenv("DATA_DIR")
72 theFileName = thePath + "/Shapes/Brep/slots.brep"
73 theShapeForCut = ImportBREP(theFileName)
74 addToStudy(theShapeForCut, "slot.brep_1")
76 Cut_1 = MakeBoolean(Chamfer_2, theShapeForCut, 2)
77 addToStudy(Cut_1, "Cut_1")
81 def Mesh(theNameOfTheShape = "Cut_1", theAverageLength = 5, theMaxElementArea = 20, theMaxElementVolume = 150):
82 #Format of the <theNameOfTheShape> parameter is: "[[first level object/[second level object/[.../]]]Name"
83 from batchmode_smesh import *
85 smesh.SetCurrentStudy(myStudy)
86 theNameOfTheShape = "/Geometry/"+ str(theNameOfTheShape)
87 SObject = myStudy.FindObjectByPath(theNameOfTheShape)
89 raise RuntimeError, "It is an incorrect object name..."
90 shape_mesh = IDToObject( SObject.GetID() )
91 mesh = smesh.CreateMesh(shape_mesh)
92 idmesh = ObjectToID(mesh)
93 SetName( idmesh, "Mesh" )
96 print "-------------------------- Average length"
97 theName = "AverageLength" + str(theAverageLength)
98 hAvLength = smesh.CreateHypothesis( "LocalLength", "libStdMeshersEngine.so" )
99 hAvLength.SetLength( theAverageLength )
100 print hAvLength.GetName()
101 print hAvLength.GetId()
102 SetName(ObjectToID(hAvLength), theName)
104 print "-------------------------- MaxElementArea"
105 theName = "MaxElementArea" + str( theMaxElementArea )
106 hArea = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
107 hArea.SetMaxElementArea( theMaxElementArea )
108 print hArea.GetName()
110 print hArea.GetMaxElementArea()
111 SetName(ObjectToID(hArea), theName)
113 print "-------------------------- MaxElementVolume"
114 theName = "MaxElementVolume" + str( theMaxElementVolume )
115 hVolume = smesh.CreateHypothesis( "MaxElementVolume", "libStdMeshersEngine.so" )
116 hVolume.SetMaxElementVolume( theMaxElementVolume )
117 print hVolume.GetName()
118 print hVolume.GetId()
119 print hVolume.GetMaxElementVolume()
120 SetName(ObjectToID(hVolume), theName)
122 mesh.AddHypothesis(shape_mesh, hAvLength)
123 mesh.AddHypothesis(shape_mesh, hArea)
124 mesh.AddHypothesis(shape_mesh, hVolume)
126 print "-------------------------- Regular_1D"
128 algoReg1D = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" )
129 listHyp = algoReg1D.GetCompatibleHypothesis()
132 print algoReg1D.GetName()
133 print algoReg1D.GetId()
134 SetName(ObjectToID(algoReg1D), "Wire discretisation")
136 print "-------------------------- MEFISTO_2D"
137 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" )
138 listHyp = algoMef.GetCompatibleHypothesis()
141 print algoMef.GetName()
142 print algoMef.GetId()
143 SetName(ObjectToID(algoMef), "Triangle (Mefisto)")
145 print "-------------------------- NETGEN_3D"
146 algoNg = smesh.CreateHypothesis( "NETGEN_3D", "libNETGENEngine.so" )
149 print algoNg.GetName()
151 SetName(ObjectToID(algoNg), "Tetrahedron (NETGEN)")
152 mesh.AddHypothesis(shape_mesh, algoReg1D)
153 mesh.AddHypothesis(shape_mesh, algoMef)
154 mesh.AddHypothesis(shape_mesh, algoNg)
155 smesh.Compute(mesh,shape_mesh)
157 print "Information about the mesh:"
158 print "Number of nodes : ", mesh.NbNodes()
159 print "Number of edges : ", mesh.NbEdges()
160 print "Number of faces : ", mesh.NbFaces()
161 print "Number of triangles : ", mesh.NbTriangles()
162 print "Number of quadrangles : ", mesh.NbQuadrangles()
163 print "Number of volumes : ", mesh.NbVolumes()
164 print "Number of tetrahedrons: ", mesh.NbTetras()