Salome HOME
Update copyright information
[modules/smesh.git] / src / SMESH_SWIG / batchmode_mefisto.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
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.
10 #
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.
15 #
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
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 import os
23 import re
24
25 import batchmode_salome
26 import batchmode_geompy
27 import batchmode_smesh
28 import StdMeshers
29
30 smesh = batchmode_smesh.smesh
31 smesh.SetCurrentStudy(batchmode_salome.myStudy)
32
33 def CreateMesh (theFileName, area, len = None, nbseg = None):
34     
35     if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
36         print "Incorrect file name !"
37         return
38
39     if (len is None) and (nbseg is None):
40         print "Define length or number of segments !"
41         return
42
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 !"
45         return
46
47     
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")
51
52
53     # ---- SMESH
54     print "-------------------------- create mesh"
55     mesh = smesh.Mesh(shape_mesh)
56       
57     print "-------------------------- create Hypothesis"
58     if (len is not None):
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()
65     
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()
73
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()
81        
82     else:
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()
89               
90     
91     print "-------------------------- Regular_1D"
92     listHyp = algoReg.GetCompatibleHypothesis()
93     for hyp in listHyp:
94         print hyp
95     
96     print "Algo name: ", algoReg.GetName()
97     print "Algo ID  : ", algoReg.GetId()
98    
99     print "-------------------------- MEFISTO_2D"
100     listHyp = algoMef.GetCompatibleHypothesis()
101     for hyp in listHyp:
102         print hyp
103         
104     print "Algo name: ", algoMef.GetName()
105     print "Algo ID  : ", algoMef.GetId()
106
107
108     # ---- add hypothesis to shape
109
110     print "-------------------------- compute mesh"
111     ret = mesh.Compute()
112     print  "Compute Mesh .... ", 
113     print ret
114     log = mesh.GetLog(0); # no erase trace
115     #for linelog in log:
116     #    print linelog
117
118     print "------------ INFORMATION ABOUT MESH ------------"
119     
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()
124
125     return mesh