Salome HOME
Mesh redesine. New fields added to specify whether hypothesis is main or additional...
[modules/smesh.git] / src / SMESH_SWIG / SMESH_demo_hexa2_upd.py
1 #==============================================================================
2 #  Info.
3 #  Bug (from script, bug)   : SMESH_demo_hexa2_upd.py, PAL6781
4 #  Modified                 : 25/11/2004
5 #  Author                   : Kovaltchuk Alexey
6 #  Project                  : PAL/SALOME
7 #==============================================================================
8 # Tetrahedrization of a geometry (box minus a inner cylinder).
9 # Hypothesis and algorithms for the mesh generation are not global:
10 # the mesh of some edges is thinner
11 #
12
13 import salome
14 import geompy
15
16 import StdMeshers
17 import NETGENPlugin
18
19 geom  = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
20 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
21
22 smeshgui = salome.ImportComponentGUI("SMESH")
23 smeshgui.Init(salome.myStudyId);
24
25 import math
26
27 # -----------------------------------------------------------------------------
28
29 ShapeTypeShell     = 3
30 ShapeTypeFace      = 4
31 ShapeTypeEdge      = 6
32
33 a = math.sqrt(2.)/4.
34 ma = - a
35 zero = 0.
36 un = 1.
37 mun= - un
38 demi = 1./2.
39
40 Orig = geompy.MakeVertex(zero,zero,zero)
41 P0 = geompy.MakeVertex(a,a,zero)
42 P1 = geompy.MakeVertex(zero,demi,zero)
43 P2 = geompy.MakeVertex(ma,a,zero)
44 P3 = geompy.MakeVertex(mun,un,zero)
45 P4 = geompy.MakeVertex(un,un,zero)
46 P5 = geompy.MakeVertex(zero,zero,un)
47
48 arc = geompy.MakeArc(P0,P1,P2)
49 e1 = geompy.MakeEdge(P2,P3)
50 e2 = geompy.MakeEdge(P3,P4)
51 e3 = geompy.MakeEdge(P4,P0)
52
53 list = []
54 list.append(arc)
55 list.append(e1)
56 list.append(e2)
57 list.append(e3)
58
59 wire = geompy.MakeWire(list)
60 face = geompy.MakeFace(wire,1)
61
62 dir = geompy.MakeVector(Orig,P5)
63 vol1 = geompy.MakePipe(face,dir)
64
65 angle = math.pi/2.
66 #dir = geom.MakeVector(Orig,P5)
67 vol2 = geompy.MakeRotation(vol1,dir,angle)
68
69 vol3 = geompy.MakeRotation(vol2,dir,angle)
70
71 vol4 = geompy.MakeRotation(vol3,dir,angle)
72
73 list = []
74 list.append(vol1)
75 list.append(vol2)
76 list.append(vol3)
77 list.append(vol4)
78
79 volComp = geompy.MakeCompound(list)
80
81 tol3d = 1.e-3
82 vol = geompy.MakeGlueFaces(volComp,tol3d)
83 idVol = geompy.addToStudy(vol,"volume")
84
85 print "Analysis of the final volume:"
86 subShellList = geompy.SubShapeAllSorted(vol,ShapeTypeShell)
87 subFaceList = geompy.SubShapeAllSorted(vol,ShapeTypeFace)
88 subEdgeList = geompy.SubShapeAllSorted(vol,ShapeTypeEdge)
89
90 print "number of Shells in the volume : ",len(subShellList)
91 print "number of Faces in the volume : ",len(subFaceList)
92 print "number of Edges in the volume : ",len(subEdgeList)
93
94 idSubEdge = []
95 for k in range(len(subEdgeList)):
96     idSubEdge.append(geompy.addToStudyInFather(vol,subEdgeList[k],"SubEdge"+str(k)))
97
98 edgeZ = []
99 edgeZ.append(subEdgeList[0])
100 edgeZ.append(subEdgeList[3])
101 edgeZ.append(subEdgeList[10])
102 edgeZ.append(subEdgeList[11])
103 edgeZ.append(subEdgeList[20])
104 edgeZ.append(subEdgeList[21])
105 edgeZ.append(subEdgeList[28])
106 edgeZ.append(subEdgeList[31])
107
108 idEdgeZ = []
109 for i in range(8):
110     idEdgeZ.append(geompy.addToStudyInFather(vol,edgeZ[i],"EdgeZ"+str(i+1)))
111
112 ### ---------------------------- SMESH --------------------------------------
113
114 # ---- create Hypothesis
115
116 print "-------------------------- create Hypothesis"
117
118 print "-------------------------- NumberOfSegments the global one"
119
120 numberOfSegments = 10
121
122 hypNbSeg=smesh.CreateHypothesis("NumberOfSegments","libStdMeshersEngine.so")
123 hypNbSeg.SetNumberOfSegments(numberOfSegments)
124 hypNbSegID = hypNbSeg.GetId()
125 print hypNbSeg.GetName()
126 print hypNbSegID
127 print hypNbSeg.GetNumberOfSegments()
128
129 smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments")
130
131 print "-------------------------- NumberOfSegments in the Z direction"
132
133 numberOfSegmentsZ = 40
134
135 hypNbSegZ=smesh.CreateHypothesis("NumberOfSegments","libStdMeshersEngine.so")
136 hypNbSegZ.SetNumberOfSegments(numberOfSegmentsZ)
137 hypNbSegZID = hypNbSegZ.GetId()
138 print hypNbSegZ.GetName()
139 print hypNbSegZID
140 print hypNbSegZ.GetNumberOfSegments()
141
142 smeshgui.SetName(salome.ObjectToID(hypNbSegZ), "NumberOfSegmentsZ")
143
144 # ---- create Algorithms
145
146 print "-------------------------- create Algorithms"
147
148 print "-------------------------- Regular_1D"
149
150 regular1D=smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
151 smeshgui.SetName(salome.ObjectToID(regular1D), "Wire Discretisation")
152
153 print "-------------------------- Quadrangle_2D"
154
155 quad2D=smesh.CreateHypothesis("Quadrangle_2D", "libStdMeshersEngine.so")
156 smeshgui.SetName(salome.ObjectToID(quad2D), "Quadrangle_2D")
157
158 print "-------------------------- Hexa_3D"
159
160 hexa3D=smesh.CreateHypothesis("Hexa_3D", "libStdMeshersEngine.so")
161 smeshgui.SetName(salome.ObjectToID(hexa3D), "Hexa_3D")
162
163 # ---- init a Mesh with the volume
164
165 mesh = smesh.CreateMesh(vol)
166 smeshgui.SetName(salome.ObjectToID(mesh), "meshVolume")
167
168 # ---- add hypothesis to the volume
169
170 print "-------------------------- add hypothesis to the volume"
171
172 ret=mesh.AddHypothesis(vol,regular1D)
173 print ret
174 ret=mesh.AddHypothesis(vol,hypNbSeg)
175 print ret
176 ret=mesh.AddHypothesis(vol,quad2D)
177 print ret
178 ret=mesh.AddHypothesis(vol,hexa3D)
179 print ret
180
181 for i in range(8):
182     print "-------------------------- add hypothesis to edge in the Z directions", (i+1)
183
184     subMeshEdgeZ = mesh.GetSubMesh(edgeZ[i],"SubMeshEdgeZ_"+str(i+1))
185
186     retZ = mesh.AddHypothesis(edgeZ[i],hypNbSegZ)
187     print " add hyp Z ", retZ
188
189 salome.sg.updateObjBrowser(1)
190
191 print "-------------------------- compute the mesh of the volume"
192
193 ret=smesh.Compute(mesh,vol)
194
195 print ret
196 if ret != 0:
197 ##    log=mesh.GetLog(0) # no erase trace
198 ##    for linelog in log:
199 ##        print linelog
200     print "Information about the MeshBox :"
201     print "Number of nodes       : ", mesh.NbNodes()
202     print "Number of edges       : ", mesh.NbEdges()
203     print "Number of faces       : ", mesh.NbFaces()
204     print "Number of triangles   : ", mesh.NbTriangles()
205     print "Number of volumes     : ", mesh.NbVolumes()
206     print "Number of tetrahedrons: ", mesh.NbTetras()
207 else:
208     print "problem when Computing the mesh"
209
210 salome.sg.updateObjBrowser(1)