Salome HOME
Mesh redesine. New fields added to specify whether hypothesis is main or additional...
[modules/smesh.git] / src / SMESH_SWIG / batchmode_mefisto.py
1 import os
2 import re
3
4 import batchmode_salome
5 import batchmode_geompy
6 import batchmode_smesh
7 import StdMeshers
8
9 smesh = batchmode_smesh.smesh
10 smesh.SetCurrentStudy(batchmode_salome.myStudy)
11
12 def CreateMesh (theFileName, area, len = None, nbseg = None):
13     
14     if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
15         print "Incorrect file name !"
16         return
17
18     if (len is None) and (nbseg is None):
19         print "Define length or number of segments !"
20         return
21
22     if (len is not None) and (nbseg is not None):
23         print "Only one Hypothesis (from length and number of segments) can be defined !"
24         return
25
26     
27     # ----  Import shape from BREP file and add it to the study  
28     shape_mesh = batchmode_geompy.Import(theFileName, "BREP")
29     Id_shape = batchmode_geompy.addToStudy(shape_mesh, "shape_mesh")
30
31
32     # ---- SMESH
33       
34     print "-------------------------- create Hypothesis"
35     if (len is not None):
36         print "-------------------------- LocalLength"
37         hypLength1 = smesh.CreateHypothesis("LocalLength", "libStdMeshersEngine.so")
38         hypLength1.SetLength(len)
39         print "Hypothesis type : ", hypLength1.GetName()
40         print "Hypothesis ID   : ", hypLength1.GetId()
41         print "Hypothesis Value: ", hypLength1.GetLength()
42     
43     if (nbseg is not None):   
44         print "-------------------------- NumberOfSegments"
45         hypNbSeg1 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
46         hypNbSeg1.SetNumberOfSegments(nbseg)
47         print "Hypothesis type : ", hypNbSeg1.GetName()
48         print "Hypothesis ID   : ", hypNbSeg1.GetId()
49         print "Hypothesis Value: ", hypNbSeg1.GetNumberOfSegments()
50
51     if (area == "LengthFromEdges"):
52         print "-------------------------- LengthFromEdges"
53         hypLengthFromEdges = smesh.CreateHypothesis("LengthFromEdges", "libStdMeshersEngine.so")
54         hypLengthFromEdges.SetMode(1)
55         print "Hypothesis type     : ", hypLengthFromEdges.GetName()
56         print "Hypothesis ID       : ", hypLengthFromEdges.GetId()
57         print "LengthFromEdges Mode: ", hypLengthFromEdges.GetMode()
58        
59     else:
60         print "-------------------------- MaxElementArea"
61         hypArea1 = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
62         hypArea1.SetMaxElementArea(area)
63         print "Hypothesis type : ", hypArea1.GetName()
64         print "Hypothesis ID   : ", hypArea1.GetId()
65         print "Hypothesis Value: ", hypArea1.GetMaxElementArea()
66               
67     
68     print "-------------------------- Regular_1D"
69     algoReg = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
70    
71     listHyp = algoReg.GetCompatibleHypothesis()
72     for hyp in listHyp:
73         print hyp
74     
75     print "Algo name: ", algoReg.GetName()
76     print "Algo ID  : ", algoReg.GetId()
77    
78     print "-------------------------- MEFISTO_2D"
79     algoMef = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
80     
81     listHyp = algoMef.GetCompatibleHypothesis()
82     for hyp in listHyp:
83         print hyp
84         
85     print "Algo name: ", algoMef.GetName()
86     print "Algo ID  : ", algoMef.GetId()
87
88
89     # ---- add hypothesis to shape
90
91     print "-------------------------- add hypothesis to shape"
92     mesh = smesh.CreateMesh(shape_mesh) 
93
94     ret = mesh.AddHypothesis(shape_mesh, algoReg)
95     print "Add Regular_1D algo .... ", 
96     print ret
97     
98     if (nbseg is not None):
99         ret = mesh.AddHypothesis(shape_mesh, hypNbSeg1)
100         print "Add Number Of Segements algo .... ", 
101         print ret
102
103     if (len is not None):
104         ret = mesh.AddHypothesis(shape_mesh,hypLength1)
105         print "Add  Local Length algo .... ", 
106         print ret
107
108     ret = mesh.AddHypothesis(shape_mesh, algoMef)
109     print "Add MEFISTO_2D algo....", 
110     print ret
111     
112     if (area == "LengthFromEdges"):
113         ret = mesh.AddHypothesis( shape_mesh, hypLengthFromEdges)    # length from edge 
114         print "Add Length From Edges algo .... ",
115         print ret
116     else:
117         ret = mesh.AddHypothesis(shape_mesh, hypArea1)
118         print "Add Max Triangle Area algo .... ", 
119         print ret
120     
121     print "-------------------------- compute mesh"
122     ret = smesh.Compute(mesh,shape_mesh)
123     print  "Compute Mesh .... ", 
124     print ret
125     log = mesh.GetLog(0); # no erase trace
126     #for linelog in log:
127     #    print linelog
128
129     print "------------ INFORMATION ABOUT MESH ------------"
130     
131     print "Number of nodes    : ", mesh.NbNodes()
132     print "Number of edges    : ", mesh.NbEdges()
133     print "Number of faces    : ", mesh.NbFaces()
134     print "Number of triangles: ", mesh.NbTriangles()
135
136     return mesh