1 # Copyright (C) 2007-2008 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.
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
25 import batchmode_salome
26 import batchmode_geompy
27 import batchmode_smesh
30 smesh = batchmode_smesh.smesh
31 smesh.SetCurrentStudy(batchmode_salome.myStudy)
33 def CreateMesh (theFileName, area, len = None, nbseg = None):
35 if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
36 print "Incorrect file name !"
39 if (len is None) and (nbseg is None):
40 print "Define length or number of segments !"
43 if (len is not None) and (nbseg is not None):
44 print "Only one Hypothesis (from length and number of segments) can be defined !"
48 # ---- Import shape from BREP file and add it to the study
49 shape_mesh = batchmode_geompy.Import(theFileName, "BREP")
50 Id_shape = batchmode_geompy.addToStudy(shape_mesh, "shape_mesh")
54 print "-------------------------- create mesh"
55 mesh = smesh.Mesh(shape_mesh)
57 print "-------------------------- create Hypothesis"
59 print "-------------------------- LocalLength"
60 algoReg = mesh.Segment()
61 hypLength1 = algoReg.LocalLength(len)
62 print "Hypothesis type : ", hypLength1.GetName()
63 print "Hypothesis ID : ", hypLength1.GetId()
64 print "Hypothesis Value: ", hypLength1.GetLength()
66 if (nbseg is not None):
67 print "-------------------------- NumberOfSegments"
68 algoReg = mesh.Segment()
69 hypNbSeg1 = algoReg.NumberOfSegments(nbseg)
70 print "Hypothesis type : ", hypNbSeg1.GetName()
71 print "Hypothesis ID : ", hypNbSeg1.GetId()
72 print "Hypothesis Value: ", hypNbSeg1.GetNumberOfSegments()
74 if (area == "LengthFromEdges"):
75 print "-------------------------- LengthFromEdges"
76 algoMef = mesh.Triangle()
77 hypLengthFromEdges = algoMef.LengthFromEdges(1)
78 print "Hypothesis type : ", hypLengthFromEdges.GetName()
79 print "Hypothesis ID : ", hypLengthFromEdges.GetId()
80 print "LengthFromEdges Mode: ", hypLengthFromEdges.GetMode()
83 print "-------------------------- MaxElementArea"
84 algoMef = mesh.Triangle()
85 hypArea1 = algoMef.MaxElementArea(area)
86 print "Hypothesis type : ", hypArea1.GetName()
87 print "Hypothesis ID : ", hypArea1.GetId()
88 print "Hypothesis Value: ", hypArea1.GetMaxElementArea()
91 print "-------------------------- Regular_1D"
92 listHyp = algoReg.GetCompatibleHypothesis()
96 print "Algo name: ", algoReg.GetName()
97 print "Algo ID : ", algoReg.GetId()
99 print "-------------------------- MEFISTO_2D"
100 listHyp = algoMef.GetCompatibleHypothesis()
104 print "Algo name: ", algoMef.GetName()
105 print "Algo ID : ", algoMef.GetId()
108 # ---- add hypothesis to shape
110 print "-------------------------- compute mesh"
112 print "Compute Mesh .... ",
114 log = mesh.GetLog(0); # no erase trace
118 print "------------ INFORMATION ABOUT MESH ------------"
120 print "Number of nodes : ", mesh.NbNodes()
121 print "Number of edges : ", mesh.NbEdges()
122 print "Number of faces : ", mesh.NbFaces()
123 print "Number of triangles: ", mesh.NbTriangles()