Salome HOME
Movement of examples to CVS EXAMPLES SAMPLES_SRC.
[modules/smesh.git] / src / SMESH_SWIG / SMESH_reg.py
1 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3
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. 
8
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. 
13
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 
17
18 #  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19 #
20 #
21 #
22 #  File   : SMESH_reg.py
23 #  Module : SMESH
24
25 import salome
26 import geompy
27
28 import StdMeshers
29
30 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
31 smesh.SetCurrentStudy(salome.myStudy)
32
33 # ---- define a box
34 print "Define box"
35 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
36 idbox = geompy.addToStudy(box, "box")
37
38 # ---- add faces of box to study
39 print "Add faces to study"
40 idface = []
41 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
42 for f in subShapeList:
43   name = geompy.SubShapeName(f, box)
44   print name
45   idface.append( geompy.addToStudyInFather(box, f, name) )
46
47 # ---- add edges of box to study
48 print "Add edges to study"
49 idedge = []
50 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["EDGE"])
51 for f in subShapeList:
52   name = geompy.SubShapeName(f, box)
53   print name
54   idedge.append( geompy.addToStudyInFather(box, f, name) )
55
56 salome.sg.updateObjBrowser(1);
57
58 # ---- launch SMESH
59 smeshgui = salome.ImportComponentGUI("SMESH")
60 smeshgui.Init(salome.myStudyId)
61
62
63 print "-------------------------- create Hypothesis"
64
65 print "-------------------------- LocalLength"
66 hypLen1 = smesh.CreateHypothesis("LocalLength", "libStdMeshersEngine.so")
67 hypLen1.SetLength(100)
68 print hypLen1.GetName()
69 print hypLen1.GetId()
70 print hypLen1.GetLength()
71
72 idlength = salome.ObjectToID(hypLen1)
73 smeshgui.SetName(idlength, "Local_Length_100");
74
75 hypNbSeg = []
76 print "-------------------------- NumberOfSegments"
77 hypNbSeg1 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
78 hypNbSeg1.SetDistrType(0)
79 hypNbSeg1.SetNumberOfSegments(7)
80 print hypNbSeg1.GetName()
81 print hypNbSeg1.GetId()
82 print hypNbSeg1.GetNumberOfSegments()
83 idseg1 = salome.ObjectToID(hypNbSeg1)
84 smeshgui.SetName(idseg1, "NumberOfSegmentsReg");
85 hypNbSeg.append(hypNbSeg1)
86
87 hypNbSeg2 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
88 hypNbSeg2.SetDistrType(1)
89 hypNbSeg2.SetNumberOfSegments(7)
90 hypNbSeg2.SetScaleFactor(2)
91 print hypNbSeg2.GetName()
92 print hypNbSeg2.GetId()
93 print hypNbSeg2.GetNumberOfSegments()
94 idseg2 = salome.ObjectToID(hypNbSeg2)
95 smeshgui.SetName(idseg2, "NumberOfSegmentsScale");
96 hypNbSeg.append(hypNbSeg2)
97
98 hypNbSeg3 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
99 hypNbSeg3.SetDistrType(2)
100 hypNbSeg3.SetNumberOfSegments(7)
101 hypNbSeg3.SetTableFunction( [0.25, 0.5, 0.5, 0.25] )
102 print hypNbSeg3.GetName()
103 print hypNbSeg3.GetId()
104 print hypNbSeg3.GetNumberOfSegments()
105 idseg3 = salome.ObjectToID(hypNbSeg3)
106 smeshgui.SetName(idseg3, "NumberOfSegmentsTable");
107 hypNbSeg.append(hypNbSeg3)
108
109 hypNbSeg4 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
110 hypNbSeg4.SetDistrType(3)
111 hypNbSeg4.SetNumberOfSegments(7)
112 hypNbSeg4.SetExpressionFunction("sin(t)")
113 print hypNbSeg4.GetName()
114 print hypNbSeg4.GetId()
115 print hypNbSeg4.GetNumberOfSegments()
116 idseg4 = salome.ObjectToID(hypNbSeg4)
117 smeshgui.SetName(idseg4, "NumberOfSegmentsExpr");
118 hypNbSeg.append(hypNbSeg4)
119
120 print "-------------------------- MaxElementArea"
121 hypArea1 = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
122 hypArea1.SetMaxElementArea(2500)
123 print hypArea1.GetName()
124 print hypArea1.GetId()
125 print hypArea1.GetMaxElementArea()
126
127 idarea1 = salome.ObjectToID(hypArea1)
128 smeshgui.SetName(idarea1, "MaxElementArea_2500");
129
130 print "-------------------------- MaxElementArea"
131 hypArea2 = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
132 hypArea2.SetMaxElementArea(500)
133 print hypArea2.GetName()
134 print hypArea2.GetId()
135 print hypArea2.GetMaxElementArea()
136
137 idarea2 = salome.ObjectToID(hypArea2)
138 smeshgui.SetName(idarea2, "MaxElementArea_500");
139
140 print "-------------------------- Regular_1D"
141 algoReg = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
142 listHyp = algoReg.GetCompatibleHypothesis()
143 for hyp in listHyp:
144     print hyp
145 print algoReg.GetName()
146 print algoReg.GetId()
147
148 idreg = salome.ObjectToID(algoReg)
149 smeshgui.SetName(idreg, "Regular_1D");
150
151 print "-------------------------- MEFISTO_2D"
152 algoMef = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
153 listHyp = algoMef.GetCompatibleHypothesis()
154 for hyp in listHyp:
155     print hyp
156 print algoMef.GetName()
157 print algoMef.GetId()
158
159 idmef = salome.ObjectToID(algoMef)
160 smeshgui.SetName(idmef, "MEFISTO_2D");
161
162 salome.sg.updateObjBrowser(1);
163
164 # ---- Init a Mesh with the box
165
166 box = salome.IDToObject(idbox)
167 names = [ "MeshBoxReg", "MeshBoxScale", "MeshBoxTable", "MeshBoxExpr" ];
168 j = 0
169 for i in range(4):
170   mesh = smesh.CreateMesh(box)
171   idmesh = salome.ObjectToID(mesh)
172   smeshgui.SetName(idmesh, names[j]);
173   print "-------------------------- add hypothesis to box"
174   mesh.AddHypothesis(box,algoReg)
175   mesh.AddHypothesis(box,hypNbSeg[j])
176   mesh.AddHypothesis(box,algoMef)
177   mesh.AddHypothesis(box,hypArea1)
178   j=j+1
179
180 salome.sg.updateObjBrowser(1);
181