2 # Hexahedrization of a simple box. Hypothesis and algorithms for
3 # the mesh generation are not global: the mesh of some edges is thinner
14 # -----------------------------------------------------------------------------
17 myBuilder = geompy.myBuilder
25 box = geompy.MakeBox(0., 0., 0., 1., 1., 1.)
27 idbox = geompy.addToStudy(box,"box")
29 print "Analysis of the geometry box :"
30 subShellList=geompy.SubShapeAllSorted(box,ShapeTypeShell)
31 subFaceList=geompy.SubShapeAllSorted(box,ShapeTypeFace)
32 subEdgeList=geompy.SubShapeAllSorted(box,ShapeTypeEdge)
34 print "number of Shells in box : ",len(subShellList)
35 print "number of Faces in box : ",len(subFaceList)
36 print "number of Edges in box : ",len(subEdgeList)
39 for k in range(len(subEdgeList)):
40 idSubEdge.append(geompy.addToStudyInFather(box,subEdgeList[k],"SubEdge"+str(k)))
43 edgeX.append(subEdgeList[4])
44 edgeX.append(subEdgeList[5])
45 edgeX.append(subEdgeList[6])
46 edgeX.append(subEdgeList[7])
49 edgeY.append(subEdgeList[1])
50 edgeY.append(subEdgeList[2])
51 edgeY.append(subEdgeList[9])
52 edgeY.append(subEdgeList[10])
55 edgeZ.append(subEdgeList[0])
56 edgeZ.append(subEdgeList[3])
57 edgeZ.append(subEdgeList[8])
58 edgeZ.append(subEdgeList[11])
64 idEdgeX.append(geompy.addToStudyInFather(box,edgeX[i],"EdgeX"+str(i+1)))
65 idEdgeY.append(geompy.addToStudyInFather(box,edgeY[i],"EdgeY"+str(i+1)))
66 idEdgeZ.append(geompy.addToStudyInFather(box,edgeZ[i],"EdgeZ"+str(i+1)))
70 smeshgui = salome.ImportComponentGUI("SMESH")
71 smeshgui.Init(salome.myStudyId)
75 # ---- create Hypothesis
77 print "-------------------------- create Hypothesis"
79 print "-------------------------- NumberOfSegments in X, Y, Z direction"
81 numberOfSegmentsX = 10
83 hyp1=gen.CreateHypothesis("NumberOfSegments")
84 hypNbSegX=hyp1._narrow(SMESH.SMESH_NumberOfSegments)
85 hypNbSegX.SetNumberOfSegments(numberOfSegmentsX)
86 hypNbSegXID = hypNbSegX.GetId()
87 print hypNbSegX.GetName()
89 print hypNbSegX.GetNumberOfSegments()
91 idsegX = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSegX) )
92 smeshgui.SetName(idsegX, "NumberOfSegmentsX")
96 numberOfSegmentsY = 20
98 hyp1=gen.CreateHypothesis("NumberOfSegments")
99 hypNbSegY=hyp1._narrow(SMESH.SMESH_NumberOfSegments)
100 hypNbSegY.SetNumberOfSegments(numberOfSegmentsY)
101 hypNbSegYID = hypNbSegY.GetId()
102 print hypNbSegY.GetName()
104 print hypNbSegY.GetNumberOfSegments()
106 idsegY = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSegY) )
107 smeshgui.SetName(idsegY, "NumberOfSegmentsY")
111 numberOfSegmentsZ = 40
113 hyp1=gen.CreateHypothesis("NumberOfSegments")
114 hypNbSegZ=hyp1._narrow(SMESH.SMESH_NumberOfSegments)
115 hypNbSegZ.SetNumberOfSegments(numberOfSegmentsZ)
116 hypNbSegZID = hypNbSegZ.GetId()
117 print hypNbSegZ.GetName()
119 print hypNbSegZ.GetNumberOfSegments()
121 idsegZ = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSegZ) )
122 smeshgui.SetName(idsegZ, "NumberOfSegmentsZ")
124 # ---- create Algorithms
126 print "-------------------------- create Algorithms"
128 print "-------------------------- Regular_1D"
130 hypothesis=gen.CreateHypothesis("Regular_1D")
131 regular1D = hypothesis._narrow(SMESH.SMESH_Regular_1D)
132 regularID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(regular1D) )
133 smeshgui.SetName(regularID, "Wire Discretisation")
135 print "-------------------------- Quadrangle_2D"
137 hypothesis=gen.CreateHypothesis("Quadrangle_2D")
138 quad2D = hypothesis._narrow(SMESH.SMESH_Quadrangle_2D)
139 quadID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(quad2D) )
140 smeshgui.SetName(quadID, "Quadrangle_2D")
142 print "-------------------------- Hexa_3D"
144 hypothesis=gen.CreateHypothesis("Hexa_3D")
145 hexa3D = hypothesis._narrow(SMESH.SMESH_Hexa_3D)
146 hexaID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(hexa3D) )
147 smeshgui.SetName(hexaID, "Hexa_3D")
149 # ---- init a Mesh with the boxe
152 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
153 smeshgui.SetName(idmesh, "MeshBox")
154 smeshgui.SetShape(idbox, idmesh)
156 # ---- add hypothesis to the boxe
158 print "-------------------------- add hypothesis to the boxe"
159 print " the number of segments is globally set to"
160 print " NumberOfSegmentsX = ", numberOfSegmentsX
162 ret=mesh.AddHypothesis(box,regular1D)
164 ret=mesh.AddHypothesis(box,hypNbSegX)
166 ret=mesh.AddHypothesis(box,quad2D)
168 ret=mesh.AddHypothesis(box,hexa3D)
171 print "-------------------------- set algoritms"
173 smeshgui.SetAlgorithms( idmesh, regularID)
174 smeshgui.SetHypothesis( idmesh, idsegX )
175 smeshgui.SetAlgorithms( idmesh, quadID )
176 smeshgui.SetAlgorithms( idmesh, hexaID )
179 print "-------------------------- add hypothesis to edge in the Y and Z directions", (i+1)
181 subMeshEdgeY = mesh.GetElementsOnShape(edgeY[i])
182 subMeshEdgeZ = mesh.GetElementsOnShape(edgeZ[i])
184 retY = mesh.AddHypothesis(edgeY[i],hypNbSegY)
185 retZ = mesh.AddHypothesis(edgeZ[i],hypNbSegZ)
186 print " add hyp Y ", retY, " Z ", retZ
188 idsmY = smeshgui.AddSubMeshOnShape(
189 idmesh,idEdgeY[i],salome.orb.object_to_string(subMeshEdgeY),
191 idsmZ = smeshgui.AddSubMeshOnShape(
192 idmesh,idEdgeZ[i],salome.orb.object_to_string(subMeshEdgeZ),
195 smeshgui.SetName(idsmY, "SubMeshEdgeY_"+str(i+1))
196 smeshgui.SetName(idsmZ, "SubMeshEdgeZ_"+str(i+1))
198 smeshgui.SetHypothesis(idsmY, idsegY)
199 smeshgui.SetHypothesis(idsmZ, idsegZ)
201 sg.updateObjBrowser(1)
203 print "-------------------------- compute the mesh of the boxe"
204 ret=gen.Compute(mesh,idbox)
207 log=mesh.GetLog(0) # no erase trace
211 print "problem when Computing the mesh"
213 sg.updateObjBrowser(1)