Salome HOME
DCQ:prepare 2.0.0
[modules/smesh.git] / src / SMESH_SWIG / SMESH_demo_hexa.py
1 #
2 # Tetrahedrization of a geometry (box minus a inner cylinder).
3 # Hypothesis and algorithms for the mesh generation are global
4 #
5
6 import math
7 import salome
8 from salome import sg
9
10 import geompy
11
12 import SMESH
13 import smeshpy
14
15 # -----------------------------------------------------------------------------
16
17 geom = geompy.geom
18 myBuilder = geompy.myBuilder
19
20 ShapeTypeShell     = 3
21 ShapeTypeFace      = 4
22 ShapeTypeEdge      = 6
23
24 a = math.sqrt(2.)/4.
25 ma = - a
26 zero = 0.
27 un = 1.
28 mun= - un
29 demi = 1./2.
30
31 Orig = geom.MakePointStruct(zero,zero,zero)
32 P0 = geom.MakePointStruct(a,a,zero)
33 P1 = geom.MakePointStruct(zero,demi,zero)
34 P2 = geom.MakePointStruct(ma,a,zero)
35 P3 = geom.MakePointStruct(mun,un,zero)
36 P4 = geom.MakePointStruct(un,un,zero)
37 P5 = geom.MakePointStruct(zero,zero,un)
38
39 arc = geompy.MakeArc(P0,P1,P2)
40 e1 = geompy.MakeEdge(P2,P3)
41 e2 = geompy.MakeEdge(P3,P4)
42 e3 = geompy.MakeEdge(P4,P0)
43
44 list = []
45 list.append(arc._get_Name())
46 list.append(e1._get_Name())
47 list.append(e2._get_Name())
48 list.append(e3._get_Name())
49
50 wire = geompy.MakeWire(list)
51 face = geompy.MakeFace(wire,1)
52
53 dir = geompy.MakeVector(Orig,P5)
54 vol1 = geompy.MakePipe(dir,face)
55
56 angle = math.pi/2.
57 dir = geom.MakeAxisStruct(zero,zero,zero,zero,zero,un)
58 vol2 = geompy.MakeRotation(vol1,dir,angle)
59
60 vol3 = geompy.MakeRotation(vol2,dir,angle)
61
62 vol4 = geompy.MakeRotation(vol3,dir,angle)
63
64 list = []
65 list.append(vol1._get_Name())
66 list.append(vol2._get_Name())
67 list.append(vol3._get_Name())
68 list.append(vol4._get_Name())
69
70 volComp = geompy.MakeCompound(list)
71
72 tol3d = 1.e-3
73 vol = geom.MakeGlueFaces(volComp,tol3d)
74 idVol = geompy.addToStudy(vol,"volume")
75
76 print "Analysis of the final volume:"
77 subShellList=geompy.SubShapeAll(vol,ShapeTypeShell)
78 subFaceList=geompy.SubShapeAll(vol,ShapeTypeFace)
79 subEdgeList=geompy.SubShapeAll(vol,ShapeTypeEdge)
80
81 print "number of Shells in the volume : ",len(subShellList)
82 print "number of Faces in the volume : ",len(subFaceList)
83 print "number of Edges in the volume : ",len(subEdgeList)
84
85 # ---- launch SMESH
86
87 smeshgui = salome.ImportComponentGUI("SMESH")
88 smeshgui.Init(salome.myStudyId)
89
90 gen=smeshpy.smeshpy()
91
92 # ---- create Hypothesis
93
94 print "-------------------------- create Hypothesis"
95
96 print "-------------------------- NumberOfSegments"
97
98 numberOfSegments = 10
99
100 hypothesis=gen.CreateHypothesis("NumberOfSegments")
101 hypNbSeg=hypothesis._narrow(SMESH.SMESH_NumberOfSegments)
102 hypNbSeg.SetNumberOfSegments(numberOfSegments)
103 hypNbSegID = hypNbSeg.GetId()
104 print hypNbSeg.GetName()
105 print hypNbSegID
106 print hypNbSeg.GetNumberOfSegments()
107
108 idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg) )
109 smeshgui.SetName(idseg, "NumberOfSegments")
110
111 # ---- create Algorithms
112
113 print "-------------------------- create Algorithms"
114
115 print "-------------------------- Regular_1D"
116
117 hypothesis=gen.CreateHypothesis("Regular_1D")
118 regular1D = hypothesis._narrow(SMESH.SMESH_Regular_1D)
119 regularID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(regular1D) )
120 smeshgui.SetName(regularID, "Wire Discretisation")
121
122 print "-------------------------- Quadrangle_2D"
123
124 hypothesis=gen.CreateHypothesis("Quadrangle_2D")
125 quad2D = hypothesis._narrow(SMESH.SMESH_Quadrangle_2D)
126 quadID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(quad2D) )
127 smeshgui.SetName(quadID, "Quadrangle_2D")
128
129 print "-------------------------- Hexa_3D"
130
131 hypothesis=gen.CreateHypothesis("Hexa_3D")
132 hexa3D = hypothesis._narrow(SMESH.SMESH_Hexa_3D)
133 hexaID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(hexa3D) )
134 smeshgui.SetName(hexaID, "Hexa_3D")
135
136 # ---- init a Mesh with the volume
137
138 mesh=gen.Init(idVol)
139 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
140 smeshgui.SetName(idmesh, "meshVolume")
141 smeshgui.SetShape(idVol, idmesh)
142
143 # ---- add hypothesis to the volume
144
145 print "-------------------------- add hypothesis to the volume"
146
147 ret=mesh.AddHypothesis(vol,regular1D)
148 print ret
149 ret=mesh.AddHypothesis(vol,hypNbSeg)
150 print ret
151 ret=mesh.AddHypothesis(vol,quad2D)
152 print ret
153 ret=mesh.AddHypothesis(vol,hexa3D)
154 print ret
155
156 print "-------------------------- set algoritms"
157
158 smeshgui.SetAlgorithms( idmesh, regularID)
159 smeshgui.SetHypothesis( idmesh, idseg )
160 smeshgui.SetAlgorithms( idmesh, quadID )
161 smeshgui.SetAlgorithms( idmesh, hexaID )
162
163 sg.updateObjBrowser(1)
164
165 print "-------------------------- compute the mesh of the volume"
166 ret=gen.Compute(mesh,idVol)
167 print ret
168 if ret != 0:
169     log=mesh.GetLog(0) # no erase trace
170     for linelog in log:
171         print linelog
172 else:
173     print "problem when Computing the mesh"
174
175 sg.updateObjBrowser(1)