1 # Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/
23 import batchmode_salome
24 import batchmode_geompy
25 import batchmode_smesh
28 smesh = batchmode_smesh.smesh
29 smesh.SetCurrentStudy(batchmode_salome.myStudy)
31 def CreateMesh (theFileName, area, len = None, nbseg = None):
33 if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
34 print "Incorrect file name !"
37 if (len is None) and (nbseg is None):
38 print "Define length or number of segments !"
41 if (len is not None) and (nbseg is not None):
42 print "Only one Hypothesis (from length and number of segments) can be defined !"
46 # ---- Import shape from BREP file and add it to the study
47 shape_mesh = batchmode_geompy.Import(theFileName, "BREP")
48 Id_shape = batchmode_geompy.addToStudy(shape_mesh, "shape_mesh")
53 print "-------------------------- create Hypothesis"
55 print "-------------------------- LocalLength"
56 hypLength1 = smesh.CreateHypothesis("LocalLength", "libStdMeshersEngine.so")
57 hypLength1.SetLength(len)
58 print "Hypothesis type : ", hypLength1.GetName()
59 print "Hypothesis ID : ", hypLength1.GetId()
60 print "Hypothesis Value: ", hypLength1.GetLength()
62 if (nbseg is not None):
63 print "-------------------------- NumberOfSegments"
64 hypNbSeg1 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
65 hypNbSeg1.SetNumberOfSegments(nbseg)
66 print "Hypothesis type : ", hypNbSeg1.GetName()
67 print "Hypothesis ID : ", hypNbSeg1.GetId()
68 print "Hypothesis Value: ", hypNbSeg1.GetNumberOfSegments()
70 if (area == "LengthFromEdges"):
71 print "-------------------------- LengthFromEdges"
72 hypLengthFromEdges = smesh.CreateHypothesis("LengthFromEdges", "libStdMeshersEngine.so")
73 hypLengthFromEdges.SetMode(1)
74 print "Hypothesis type : ", hypLengthFromEdges.GetName()
75 print "Hypothesis ID : ", hypLengthFromEdges.GetId()
76 print "LengthFromEdges Mode: ", hypLengthFromEdges.GetMode()
79 print "-------------------------- MaxElementArea"
80 hypArea1 = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
81 hypArea1.SetMaxElementArea(area)
82 print "Hypothesis type : ", hypArea1.GetName()
83 print "Hypothesis ID : ", hypArea1.GetId()
84 print "Hypothesis Value: ", hypArea1.GetMaxElementArea()
87 print "-------------------------- Regular_1D"
88 algoReg = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
90 listHyp = algoReg.GetCompatibleHypothesis()
94 print "Algo name: ", algoReg.GetName()
95 print "Algo ID : ", algoReg.GetId()
97 print "-------------------------- MEFISTO_2D"
98 algoMef = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
100 listHyp = algoMef.GetCompatibleHypothesis()
104 print "Algo name: ", algoMef.GetName()
105 print "Algo ID : ", algoMef.GetId()
108 # ---- add hypothesis to shape
110 print "-------------------------- add hypothesis to shape"
111 mesh = smesh.CreateMesh(shape_mesh)
113 ret = mesh.AddHypothesis(shape_mesh, algoReg)
114 print "Add Regular_1D algo .... ",
117 if (nbseg is not None):
118 ret = mesh.AddHypothesis(shape_mesh, hypNbSeg1)
119 print "Add Number Of Segements algo .... ",
122 if (len is not None):
123 ret = mesh.AddHypothesis(shape_mesh,hypLength1)
124 print "Add Local Length algo .... ",
127 ret = mesh.AddHypothesis(shape_mesh, algoMef)
128 print "Add MEFISTO_2D algo....",
131 if (area == "LengthFromEdges"):
132 ret = mesh.AddHypothesis( shape_mesh, hypLengthFromEdges) # length from edge
133 print "Add Length From Edges algo .... ",
136 ret = mesh.AddHypothesis(shape_mesh, hypArea1)
137 print "Add Max Triangle Area algo .... ",
140 print "-------------------------- compute mesh"
141 ret = smesh.Compute(mesh,shape_mesh)
142 print "Compute Mesh .... ",
144 log = mesh.GetLog(0); # no erase trace
148 print "------------ INFORMATION ABOUT MESH ------------"
150 print "Number of nodes : ", mesh.NbNodes()
151 print "Number of edges : ", mesh.NbEdges()
152 print "Number of faces : ", mesh.NbFaces()
153 print "Number of triangles: ", mesh.NbTriangles()