smesh/test/SMESH_Nut.py

164 lines
6.0 KiB
Python
Raw Normal View History

2012-08-09 16:03:55 +06:00
# -*- coding: iso-8859-1 -*-
2022-05-05 18:51:12 +05:00
# Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
2009-02-17 10:27:49 +05:00
#
2012-08-09 16:03:55 +06:00
# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#
2012-08-09 16:03:55 +06:00
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
2014-02-20 18:25:37 +06:00
# version 2.1 of the License, or (at your option) any later version.
#
2012-08-09 16:03:55 +06:00
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
2012-08-09 16:03:55 +06:00
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
2012-08-09 16:03:55 +06:00
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
2012-08-09 16:03:55 +06:00
2005-03-09 18:05:16 +05:00
#####################################################################
#Created :17/02/2005
#Author :MASLOV Eugeny, KOVALTCHUK Alexey
2005-03-09 18:05:16 +05:00
#####################################################################
2009-02-17 10:27:49 +05:00
#
2005-03-09 18:05:16 +05:00
import salome
salome.salome_init()
import GEOM
from salome.geom import geomBuilder
2017-06-13 15:01:10 +05:00
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.smesh import smeshBuilder
2017-06-13 15:01:10 +05:00
smesh = smeshBuilder.New()
2005-03-09 18:05:16 +05:00
import os
import math
#Sketcher_1 creation
2017-03-20 17:27:30 +05:00
print("Sketcher creation...")
2005-03-09 18:05:16 +05:00
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")
geompy.addToStudy(Sketcher_1, "Sketcher_1")
Face_1 = geompy.MakeFace(Sketcher_1, 1)
geompy.addToStudy(Face_1, "Face_1")
#Line creation
2017-03-20 17:27:30 +05:00
print("Line creation...")
2005-03-09 18:05:16 +05:00
Line_1 = geompy.MakeLineTwoPnt(geompy.MakeVertex(0,0,0), geompy.MakeVertex(0,0,100))
geompy.addToStudy(Line_1, "Line_1")
#Prism creation
2017-03-20 17:27:30 +05:00
print("Prism creation...")
2005-03-09 18:05:16 +05:00
Prism_1 = geompy.MakePrismVecH(Face_1, Line_1, 100)
geompy.addToStudy(Prism_1, "Prism_1")
#Sketcher_2 creation
2017-03-20 17:27:30 +05:00
print("Sketcher creation...")
2005-03-09 18:05:16 +05:00
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])
geompy.addToStudy(Sketcher_2, "Sketcher_2")
Face_2 = geompy.MakeFace(Sketcher_2, 1)
geompy.addToStudy(Face_2, "Face_2")
#Revolution creation
2017-03-20 17:27:30 +05:00
print("Revolution creation...")
2005-03-09 18:05:16 +05:00
Revolution_1 = geompy.MakeRevolution(Face_2, Line_1, 2*math.pi)
geompy.addToStudy(Revolution_1, "Revolution_1")
#Common applying
2017-03-20 17:27:30 +05:00
print("Common of Revolution and Prism...")
2005-03-09 18:05:16 +05:00
Common_1 = geompy.MakeBoolean(Revolution_1, Prism_1, 1)
geompy.addToStudy(Common_1, "Common_1")
#Explode Common_1 on edges
CommonExplodedListEdges = geompy.SubShapeAll(Common_1, geompy.ShapeType["EDGE"])
for i in range(0, len(CommonExplodedListEdges)):
name = "Edge_"+str(i+1)
geompy.addToStudyInFather(Common_1, CommonExplodedListEdges[i], name)
#Fillet applying
2017-03-20 17:27:30 +05:00
print("Fillet creation...")
2012-08-09 16:03:55 +06:00
Fillet_1 = geompy.MakeFillet(Common_1, 10, geompy.ShapeType["EDGE"], [5])
2005-03-09 18:05:16 +05:00
geompy.addToStudy(Fillet_1, "Fillet_1")
#Chamfer applying
2017-03-20 17:27:30 +05:00
print("Chamfer creation...")
cyl_face = geompy.GetFaceNearPoint( Fillet_1, geompy.MakeVertex( 50, 0, 45 ), theName='cyl_face')
cyl_face_id = geompy.GetSubShapeID( Fillet_1, cyl_face )
top_face = geompy.GetFaceNearPoint( Fillet_1, geompy.MakeVertex( 60, 0, 90 ), theName='top_face')
top_face_id = geompy.GetSubShapeID( Fillet_1, top_face )
Chamfer_1 = geompy.MakeChamferEdge(Fillet_1, 10, 10, cyl_face_id, top_face_id, theName='Chamfer_1' )
cyl_face = geompy.GetFaceNearPoint( Chamfer_1, geompy.MakeVertex( 80, 0, 85 ), theName='cyl_face')
cyl_face_id = geompy.GetSubShapeID( Chamfer_1, cyl_face )
top_face = geompy.GetFaceNearPoint( Chamfer_1, geompy.MakeVertex( 65, 0, 90 ), theName='top_face')
top_face_id = geompy.GetSubShapeID( Chamfer_1, top_face )
Chamfer_2 = geompy.MakeChamferEdge(Chamfer_1, 10, 10, cyl_face_id, top_face_id, theName='Chamfer_2' )
2005-03-09 18:05:16 +05:00
#Import of the shape from "slots.brep"
2017-03-20 17:27:30 +05:00
print("Import multi-rotation from the DATA_DIR/Shapes/Brep/slots.brep")
thePath = os.getenv("DATA_DIR")
2012-08-09 16:03:55 +06:00
theFileName = os.path.join( thePath,"Shapes","Brep","slots.brep")
2005-03-09 18:05:16 +05:00
theShapeForCut = geompy.ImportBREP(theFileName)
geompy.addToStudy(theShapeForCut, "slot.brep_1")
#Cut applying
2017-03-20 17:27:30 +05:00
print("Cut...")
2005-03-09 18:05:16 +05:00
Cut_1 = geompy.MakeBoolean(Chamfer_2, theShapeForCut, 2)
Cut_1_ID = geompy.addToStudy(Cut_1, "Cut_1")
#Mesh creation
# -- Init --
shape_mesh = salome.IDToObject( Cut_1_ID )
mesh = smesh.Mesh(shape_mesh, "Nut")
2005-03-09 18:05:16 +05:00
#HYPOTHESIS CREATION
2017-03-20 17:27:30 +05:00
print("-------------------------- Average length")
2005-03-09 18:05:16 +05:00
theAverageLength = 5
algoReg1D = mesh.Segment()
hAvLength = algoReg1D.LocalLength(theAverageLength)
2017-03-20 17:27:30 +05:00
print(hAvLength.GetName())
print(hAvLength.GetId())
print(hAvLength.GetLength())
smesh.SetName(hAvLength, "AverageLength_"+str(theAverageLength))
2005-03-09 18:05:16 +05:00
2017-03-20 17:27:30 +05:00
print("-------------------------- MaxElementArea")
2005-03-09 18:05:16 +05:00
theMaxElementArea = 20
2022-04-15 20:49:22 +05:00
algoTri = mesh.Triangle()
hArea = algoTri.MaxElementArea( theMaxElementArea )
2017-03-20 17:27:30 +05:00
print(hArea.GetName())
print(hArea.GetId())
print(hArea.GetMaxElementArea())
smesh.SetName(hArea, "MaxElementArea_"+str(theMaxElementArea))
2005-03-09 18:05:16 +05:00
2017-03-20 17:27:30 +05:00
print("-------------------------- MaxElementVolume")
2005-03-09 18:05:16 +05:00
theMaxElementVolume = 150
algoNg = mesh.Tetrahedron(smeshBuilder.NETGEN)
hVolume = algoNg.MaxElementVolume( theMaxElementVolume )
2017-03-20 17:27:30 +05:00
print(hVolume.GetName())
print(hVolume.GetId())
print(hVolume.GetMaxElementVolume())
smesh.SetName(hVolume, "MaxElementVolume_"+str(theMaxElementVolume))
2005-03-09 18:05:16 +05:00
2017-03-20 17:27:30 +05:00
print("-------------------------- compute the mesh of the mechanic piece")
isDone = mesh.Compute()
if not isDone:
raise Exception("Error when computing Mesh")
2005-03-09 18:05:16 +05:00
2017-03-20 17:27:30 +05:00
print("Information about the Nut:")
print("Number of nodes : ", mesh.NbNodes())
print("Number of edges : ", mesh.NbEdges())
print("Number of faces : ", mesh.NbFaces())
print("Number of triangles : ", mesh.NbTriangles())
print("Number of quadrangles : ", mesh.NbQuadrangles())
print("Number of volumes : ", mesh.NbVolumes())
print("Number of tetrahedrons: ", mesh.NbTetras())
2005-03-09 18:05:16 +05:00
2017-06-13 15:01:10 +05:00
salome.sg.updateObjBrowser()