Salome HOME
update.
[modules/smesh.git] / src / SMESH_SWIG / SMESH_box2_tetra.py
1 #
2 # Tetrahedrization of the geometry union of 2 boxes having a face in common
3 # Hypothesis and algorithms for the mesh generation are global
4 #
5
6 import salome
7 from salome import sg
8
9 import geompy
10
11 import SMESH
12 import smeshpy
13
14 geom = geompy.geom
15 myBuilder = geompy.myBuilder
16
17 ShapeTypeShell     = 3
18 ShapeTypeFace      = 4
19 ShapeTypeEdge      = 6
20
21 # ---- define 2 boxes box1 and box2
22
23 box1 = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
24
25 idbox1 = geompy.addToStudy(box1,"box1")
26
27 print "Analysis of the geometry box1 :"
28 subShellList=geompy.SubShapeAll(box1,ShapeTypeShell)
29 subFaceList=geompy.SubShapeAll(box1,ShapeTypeFace)
30 subEdgeList=geompy.SubShapeAll(box1,ShapeTypeEdge)
31
32 print "number of Shells in box1 : ",len(subShellList)
33 print "number of Faces in box1 : ",len(subFaceList)
34 print "number of Edges in box1 : ",len(subEdgeList)
35
36 box2 = geompy.MakeBox(100., 0., 0., 200., 200., 300.)
37
38 idbox2 = geompy.addToStudy(box2,"box2")
39
40 print "Analysis of the geometry box2 :"
41 subShellList=geompy.SubShapeAll(box2,ShapeTypeShell)
42 subFaceList=geompy.SubShapeAll(box2,ShapeTypeFace)
43 subEdgeList=geompy.SubShapeAll(box2,ShapeTypeEdge)
44
45 print "number of Shells in box2 : ",len(subShellList)
46 print "number of Faces in box2 : ",len(subFaceList)
47 print "number of Edges in box2 : ",len(subEdgeList)
48
49 blocs = []
50 blocs.append(box1._get_Name())
51 blocs.append(box2._get_Name())
52
53 # append the tow boxes to make ine shel, referrencing only once
54 # the internal interface
55
56 shell = geompy.Partition(blocs)
57 idshell = geompy.addToStudy(shell,"shell")
58
59 print "Analysis of the geometry shell (union of box1 and box2) :"
60 subShellList=geompy.SubShapeAll(shell,ShapeTypeShell)
61 subFaceList=geompy.SubShapeAll(shell,ShapeTypeFace)
62 subEdgeList=geompy.SubShapeAll(shell,ShapeTypeEdge)
63
64 print "number of Shells in shell : ",len(subShellList)
65 print "number of Faces in shell : ",len(subFaceList)
66 print "number of Edges in shell : ",len(subEdgeList)
67
68 # ---- launch SMESH
69
70 smeshgui = salome.ImportComponentGUI("SMESH")
71 smeshgui.Init(salome.myStudyId)
72
73 gen=smeshpy.smeshpy()
74
75 # ---- create Hypothesis
76
77 print "-------------------------- create Hypothesis"
78
79 print "-------------------------- NumberOfSegments"
80
81 numberOfSegments = 10
82
83 hyp1=gen.CreateHypothesis("NumberOfSegments")
84 hypNbSeg=hyp1._narrow(SMESH.SMESH_NumberOfSegments)
85 hypNbSeg.SetNumberOfSegments(numberOfSegments)
86 hypNbSegID = hypNbSeg.GetId()
87 print hypNbSeg.GetName()
88 print hypNbSegID
89 print hypNbSeg.GetNumberOfSegments()
90
91 idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg) )
92 smeshgui.SetName(idseg, "NumberOfSegments")
93
94 print "-------------------------- MaxElementArea"
95
96 maxElementArea = 500
97
98 hyp2=gen.CreateHypothesis("MaxElementArea")
99 hypArea=hyp2._narrow(SMESH.SMESH_MaxElementArea)
100 hypArea.SetMaxElementArea(maxElementArea)
101 print hypArea.GetName()
102 print hypArea.GetId()
103 print hypArea.GetMaxElementArea()
104
105 idarea = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea) )
106 smeshgui.SetName(idarea, "MaxElementArea")
107
108 print "-------------------------- MaxElementVolume"
109
110 maxElementVolume = 500
111
112 hyp3=gen.CreateHypothesis("MaxElementVolume")
113 hypVolume=hyp3._narrow(SMESH.SMESH_MaxElementVolume)
114 hypVolume.SetMaxElementVolume(maxElementVolume)
115 print hypVolume.GetName()
116 print hypVolume.GetId()
117 print hypVolume.GetMaxElementVolume()
118
119 idvolume = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypVolume) )
120 smeshgui.SetName(idvolume, "MaxElementVolume")
121
122 # ---- create Algorithms
123
124 print "-------------------------- create Algorithms"
125
126 print "-------------------------- Regular_1D"
127
128 hypothesis=gen.CreateHypothesis("Regular_1D")
129 regular1D = hypothesis._narrow(SMESH.SMESH_Regular_1D)
130 regularID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(regular1D) )
131 smeshgui.SetName(regularID, "Wire Discretisation")
132
133 print "-------------------------- MEFISTO_2D"
134
135 hypothesis=gen.CreateHypothesis("MEFISTO_2D")
136 mefisto2D = hypothesis._narrow(SMESH.SMESH_MEFISTO_2D)
137 mefistoID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(mefisto2D) )
138 smeshgui.SetName(mefistoID, "MEFISTO_2D")
139
140 print "-------------------------- NETGEN_3D"
141
142 hypothesis=gen.CreateHypothesis("NETGEN_3D")
143 netgen3D = hypothesis._narrow(SMESH.SMESH_NETGEN_3D)
144 netgenID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(netgen3D) )
145 smeshgui.SetName(netgenID, "NETGEN_3D")
146
147 # ---- init a Mesh with the shell
148
149 mesh=gen.Init(idshell)
150 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
151 smeshgui.SetName(idmesh, "MeshBox2")
152 smeshgui.SetShape(idshell, idmesh)
153
154 # ---- add hypothesis to shell
155
156 print "-------------------------- add hypothesis to shell"
157
158 ret=mesh.AddHypothesis(shell,regular1D)
159 print ret
160 ret=mesh.AddHypothesis(shell,hypNbSeg)
161 print ret
162 ret=mesh.AddHypothesis(shell,mefisto2D)
163 print ret
164 ret=mesh.AddHypothesis(shell,hypArea)
165 print ret
166 ret=mesh.AddHypothesis(shell,netgen3D)
167 print ret
168 ret=mesh.AddHypothesis(shell,hypVolume)
169 print ret
170
171 smeshgui.SetAlgorithms( idmesh, regularID)
172 smeshgui.SetHypothesis( idmesh, idseg )
173 smeshgui.SetAlgorithms( idmesh, mefistoID )
174 smeshgui.SetHypothesis( idmesh, idarea )
175 smeshgui.SetAlgorithms( idmesh, netgenID )
176 smeshgui.SetHypothesis( idmesh, idvolume )
177
178 sg.updateObjBrowser(1)
179
180
181 print "-------------------------- compute shell"
182 ret=gen.Compute(mesh,idshell)
183 print ret
184 log=mesh.GetLog(0) # no erase trace
185 for linelog in log:
186     print linelog
187
188
189 sg.updateObjBrowser(1)