Back to index

salome-smesh  6.5.0
SMESH_Nut.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 #####################################################################
00025 #Created                :17/02/2005
00026 #Auhtor                 :MASLOV Eugeny, KOVALTCHUK Alexey 
00027 #####################################################################
00028 #
00029 import geompy
00030 import salome
00031 import smesh
00032 import os
00033 import math
00034 
00035 #Sketcher_1 creation
00036 print "Sketcher creation..."
00037 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") 
00038 geompy.addToStudy(Sketcher_1, "Sketcher_1")
00039 Face_1 = geompy.MakeFace(Sketcher_1, 1)
00040 geompy.addToStudy(Face_1, "Face_1")
00041 
00042 #Line creation
00043 print "Line  creation..."
00044 Line_1 = geompy.MakeLineTwoPnt(geompy.MakeVertex(0,0,0), geompy.MakeVertex(0,0,100))
00045 geompy.addToStudy(Line_1, "Line_1")
00046 
00047 #Prism creation
00048 print "Prism creation..."
00049 Prism_1 = geompy.MakePrismVecH(Face_1, Line_1, 100)
00050 geompy.addToStudy(Prism_1, "Prism_1")
00051 
00052 #Sketcher_2 creation
00053 print "Sketcher creation..."
00054 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]) 
00055 geompy.addToStudy(Sketcher_2, "Sketcher_2")
00056 Face_2 = geompy.MakeFace(Sketcher_2, 1)
00057 geompy.addToStudy(Face_2, "Face_2")
00058 
00059 #Revolution creation
00060 print "Revolution creation..."
00061 Revolution_1 = geompy.MakeRevolution(Face_2, Line_1, 2*math.pi)
00062 geompy.addToStudy(Revolution_1, "Revolution_1")
00063 
00064 #Common applying
00065 print "Common of Revolution and Prism..."
00066 Common_1 = geompy.MakeBoolean(Revolution_1, Prism_1, 1)
00067 geompy.addToStudy(Common_1, "Common_1")
00068 
00069 #Explode Common_1 on edges
00070 CommonExplodedListEdges = geompy.SubShapeAll(Common_1, geompy.ShapeType["EDGE"])
00071 for i in range(0, len(CommonExplodedListEdges)):
00072     name = "Edge_"+str(i+1)
00073     geompy.addToStudyInFather(Common_1, CommonExplodedListEdges[i], name)
00074 
00075 #Fillet applying
00076 print "Fillet creation..."
00077 Fillet_1 = geompy.MakeFillet(Common_1, 10, geompy.ShapeType["EDGE"], [5])
00078 geompy.addToStudy(Fillet_1, "Fillet_1")
00079 
00080 #Chamfer applying
00081 print "Chamfer creation..."
00082 Chamfer_1 = geompy.MakeChamferEdge(Fillet_1, 10, 10, 16, 50 )
00083 geompy.addToStudy(Chamfer_1, "Chamfer_1")
00084 Chamfer_2 = geompy.MakeChamferEdge(Chamfer_1, 10, 10, 21, 31 )
00085 geompy.addToStudy(Chamfer_2, "Chamfer_2")
00086 
00087 #Import of the shape from "slots.brep"
00088 print "Import multi-rotation from the DATA_DIR/Shapes/Brep/slots.brep"
00089 thePath = os.getenv("DATA_DIR")
00090 theFileName = os.path.join( thePath,"Shapes","Brep","slots.brep")
00091 theShapeForCut = geompy.ImportBREP(theFileName)
00092 geompy.addToStudy(theShapeForCut, "slot.brep_1")
00093 
00094 #Cut applying
00095 print "Cut..."
00096 Cut_1 = geompy.MakeBoolean(Chamfer_2, theShapeForCut, 2)
00097 Cut_1_ID = geompy.addToStudy(Cut_1, "Cut_1")
00098 
00099 #Mesh creation
00100 
00101 smesh.SetCurrentStudy(salome.myStudy)
00102 
00103 # -- Init --
00104 shape_mesh = salome.IDToObject( Cut_1_ID )
00105 
00106 mesh = smesh.Mesh(shape_mesh, "Nut")
00107 
00108 #HYPOTHESIS CREATION
00109 print "-------------------------- Average length"
00110 theAverageLength = 5
00111 algoReg1D = mesh.Segment()
00112 hAvLength = algoReg1D.LocalLength(theAverageLength)
00113 print hAvLength.GetName()
00114 print hAvLength.GetId()
00115 print hAvLength.GetLength()
00116 smesh.SetName(hAvLength, "AverageLength_"+str(theAverageLength))
00117 
00118 print "-------------------------- MaxElementArea"
00119 theMaxElementArea = 20
00120 algoMef = mesh.Triangle(smesh.MEFISTO)
00121 hArea = algoMef.MaxElementArea( theMaxElementArea )
00122 print hArea.GetName()
00123 print hArea.GetId()
00124 print hArea.GetMaxElementArea()
00125 smesh.SetName(hArea, "MaxElementArea_"+str(theMaxElementArea))
00126 
00127 print "-------------------------- MaxElementVolume"
00128 theMaxElementVolume = 150
00129 algoNg = mesh.Tetrahedron(smesh.NETGEN)
00130 hVolume = algoNg.MaxElementVolume( theMaxElementVolume )
00131 print hVolume.GetName()
00132 print hVolume.GetId()
00133 print hVolume.GetMaxElementVolume()
00134 smesh.SetName(hVolume, "MaxElementVolume_"+str(theMaxElementVolume))
00135 
00136 
00137 print "-------------------------- compute the mesh of the mechanic piece"
00138 mesh.Compute()
00139 
00140 print "Information about the Nut:"
00141 print "Number of nodes       : ", mesh.NbNodes()
00142 print "Number of edges       : ", mesh.NbEdges()
00143 print "Number of faces       : ", mesh.NbFaces()
00144 print "Number of triangles   : ", mesh.NbTriangles()
00145 print "Number of quadrangles : ", mesh.NbQuadrangles()
00146 print "Number of volumes     : ", mesh.NbVolumes()
00147 print "Number of tetrahedrons: ", mesh.NbTetras()
00148 
00149 salome.sg.updateObjBrowser(1)