1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 import batchmode_salome
27 import batchmode_geompy
28 import batchmode_smesh
31 smesh = batchmode_smesh.smesh
32 smesh.SetCurrentStudy(batchmode_salome.myStudy)
34 def CreateMesh (theFileName, area, len = None, nbseg = None):
36 if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
37 print "Incorrect file name !"
40 if (len is None) and (nbseg is None):
41 print "Define length or number of segments !"
44 if (len is not None) and (nbseg is not None):
45 print "Only one Hypothesis (from length and number of segments) can be defined !"
49 # ---- Import shape from BREP file and add it to the study
50 shape_mesh = batchmode_geompy.Import(theFileName, "BREP")
51 Id_shape = batchmode_geompy.addToStudy(shape_mesh, "shape_mesh")
55 print "-------------------------- create mesh"
56 mesh = smesh.Mesh(shape_mesh)
58 print "-------------------------- create Hypothesis"
60 print "-------------------------- LocalLength"
61 algoReg = mesh.Segment()
62 hypLength1 = algoReg.LocalLength(len)
63 print "Hypothesis type : ", hypLength1.GetName()
64 print "Hypothesis ID : ", hypLength1.GetId()
65 print "Hypothesis Value: ", hypLength1.GetLength()
67 if (nbseg is not None):
68 print "-------------------------- NumberOfSegments"
69 algoReg = mesh.Segment()
70 hypNbSeg1 = algoReg.NumberOfSegments(nbseg)
71 print "Hypothesis type : ", hypNbSeg1.GetName()
72 print "Hypothesis ID : ", hypNbSeg1.GetId()
73 print "Hypothesis Value: ", hypNbSeg1.GetNumberOfSegments()
75 if (area == "LengthFromEdges"):
76 print "-------------------------- LengthFromEdges"
77 algoMef = mesh.Triangle()
78 hypLengthFromEdges = algoMef.LengthFromEdges(1)
79 print "Hypothesis type : ", hypLengthFromEdges.GetName()
80 print "Hypothesis ID : ", hypLengthFromEdges.GetId()
81 print "LengthFromEdges Mode: ", hypLengthFromEdges.GetMode()
84 print "-------------------------- MaxElementArea"
85 algoMef = mesh.Triangle()
86 hypArea1 = algoMef.MaxElementArea(area)
87 print "Hypothesis type : ", hypArea1.GetName()
88 print "Hypothesis ID : ", hypArea1.GetId()
89 print "Hypothesis Value: ", hypArea1.GetMaxElementArea()
92 print "-------------------------- Regular_1D"
93 listHyp = algoReg.GetCompatibleHypothesis()
97 print "Algo name: ", algoReg.GetName()
98 print "Algo ID : ", algoReg.GetId()
100 print "-------------------------- MEFISTO_2D"
101 listHyp = algoMef.GetCompatibleHypothesis()
105 print "Algo name: ", algoMef.GetName()
106 print "Algo ID : ", algoMef.GetId()
109 # ---- add hypothesis to shape
111 print "-------------------------- compute mesh"
113 print "Compute Mesh .... ",
115 log = mesh.GetLog(0); # no erase trace
119 print "------------ INFORMATION ABOUT MESH ------------"
121 print "Number of nodes : ", mesh.NbNodes()
122 print "Number of edges : ", mesh.NbEdges()
123 print "Number of faces : ", mesh.NbFaces()
124 print "Number of triangles: ", mesh.NbTriangles()