2 # Tetrahedrization of a geometry (box minus a inner cylinder).
3 # Hypothesis and algorithms for the mesh generation are not
4 # global: the mesh of some edges is thinner.
15 # -----------------------------------------------------------------------------
18 myBuilder = geompy.myBuilder
24 # ---- define a boxe and a cylinder
33 P0 = geom.MakePointStruct(0.,-1.,0.)
34 P1 = geom.MakePointStruct(0.,1.,0.)
35 Vect = geom.MakeDirection(P1)
39 boxe = geompy.MakeBox(x0,y0,z0,x1,y1,z1)
41 cylinder = geompy.MakeCylinder(P0,Vect,radius,height)
43 shape = geompy.MakeBoolean(boxe,cylinder,2)
44 idshape = geompy.addToStudy(shape,"shape")
46 print "Analysis of the shape :"
47 subShellList=geompy.SubShapeAllSorted(shape,ShapeTypeShell)
48 subFaceList=geompy.SubShapeAllSorted(shape,ShapeTypeFace)
49 subEdgeList=geompy.SubShapeAllSorted(shape,ShapeTypeEdge)
51 print "number of Shells in the shape : ",len(subShellList)
52 print "number of Faces in the shape : ",len(subFaceList)
53 print "number of Edges in the shape : ",len(subEdgeList)
56 for k in range(len(subEdgeList)):
57 idSubEdge.append(geompy.addToStudyInFather(shape,subEdgeList[k],"SubEdge"+str(k)))
59 circle1 = subEdgeList[5]
60 idCircle1 = geompy.addToStudyInFather(shape,circle1,"circle1")
62 circle2 = subEdgeList[9]
63 idCircle2 = geompy.addToStudyInFather(shape,circle2,"circle2")
65 height = subEdgeList[7]
66 idHeight = geompy.addToStudyInFather(shape,height,"height")
70 smeshgui = salome.ImportComponentGUI("SMESH")
71 smeshgui.Init(salome.myStudyId)
75 # ---- create Hypothesis
77 print "-------------------------- create Hypothesis"
79 print "-------------------------- NumberOfSegments Edge of the boxe"
81 numberOfSegmentsBoxe = 10
83 hypothesis=gen.CreateHypothesis("NumberOfSegments")
84 hypNbSegBoxe=hypothesis._narrow(SMESH.SMESH_NumberOfSegments)
85 hypNbSegBoxe.SetNumberOfSegments(numberOfSegmentsBoxe)
86 hypNbSegID = hypNbSegBoxe.GetId()
87 print hypNbSegBoxe.GetName()
89 print hypNbSegBoxe.GetNumberOfSegments()
91 idSegBoxe = smeshgui.AddNewHypothesis(salome.orb.object_to_string(hypNbSegBoxe))
92 smeshgui.SetName(idSegBoxe, "NumberOfSegmentsBoxe")
94 print "-------------------------- NumberOfSegments Edge of the cylinder"
96 numberOfSegmentsCylinder = 40
98 hypothesis=gen.CreateHypothesis("NumberOfSegments")
99 hypNbSegCylinder=hypothesis._narrow(SMESH.SMESH_NumberOfSegments)
100 hypNbSegCylinder.SetNumberOfSegments(numberOfSegmentsCylinder)
101 hypNbSegID = hypNbSegCylinder.GetId()
102 print hypNbSegCylinder.GetName()
104 print hypNbSegCylinder.GetNumberOfSegments()
106 idSegCylinder = smeshgui.AddNewHypothesis(salome.orb.object_to_string(hypNbSegCylinder))
107 smeshgui.SetName(idSegCylinder, "NumberOfSegmentsCylinder")
109 print "-------------------------- LengthFromEdges"
111 hypothesis=gen.CreateHypothesis("LengthFromEdges")
112 hypLengthFromEdge=hypothesis._narrow(SMESH.SMESH_LengthFromEdges)
113 hypLengthFromEdgeID = hypLengthFromEdge.GetId()
114 print hypLengthFromEdge.GetName()
115 print hypLengthFromEdgeID
117 idlenfromedge = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypLengthFromEdge) )
118 smeshgui.SetName(idlenfromedge, "LengthFromEdge")
120 print "-------------------------- MaxElementVolume"
122 maxElementVolume = 0.5
124 hypothesis=gen.CreateHypothesis("MaxElementVolume")
125 hypVolume=hypothesis._narrow(SMESH.SMESH_MaxElementVolume)
126 hypVolume.SetMaxElementVolume(maxElementVolume)
127 print hypVolume.GetName()
128 print hypVolume.GetId()
129 print hypVolume.GetMaxElementVolume()
131 idvolume = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypVolume) )
132 smeshgui.SetName(idvolume, "MaxElementVolume")
134 # ---- create Algorithms
136 print "-------------------------- create Algorithms"
138 print "-------------------------- Regular_1D"
140 hypothesis=gen.CreateHypothesis("Regular_1D")
141 regular1D = hypothesis._narrow(SMESH.SMESH_Regular_1D)
142 regularID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(regular1D) )
143 smeshgui.SetName(regularID, "Wire Discretisation")
145 print "-------------------------- MEFISTO_2D"
147 hypothesis=gen.CreateHypothesis("MEFISTO_2D")
148 mefisto2D = hypothesis._narrow(SMESH.SMESH_MEFISTO_2D)
149 mefistoID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(mefisto2D) )
150 smeshgui.SetName(mefistoID, "MEFISTO_2D")
152 print "-------------------------- NETGEN_3D"
154 hypothesis=gen.CreateHypothesis("NETGEN_3D")
155 netgen3D = hypothesis._narrow(SMESH.SMESH_NETGEN_3D)
156 netgenID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(netgen3D) )
157 smeshgui.SetName(netgenID, "NETGEN_3D")
159 # ---- init a Mesh with the shell
161 mesh=gen.Init(idshape)
162 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
163 smeshgui.SetName(idmesh, "MeshShape")
164 smeshgui.SetShape(idshape, idmesh)
166 # ---- add hypothesis to flight
168 print "-------------------------- add hypothesis to the shape"
170 ret=mesh.AddHypothesis(shape,regular1D)
172 ret=mesh.AddHypothesis(shape,hypNbSegBoxe)
174 ret=mesh.AddHypothesis(shape,mefisto2D)
176 ret=mesh.AddHypothesis(shape,hypLengthFromEdge)
178 ret=mesh.AddHypothesis(shape,netgen3D)
180 ret=mesh.AddHypothesis(shape,hypVolume)
183 print "-------------------------- set algoritms"
185 smeshgui.SetAlgorithms( idmesh, regularID)
186 smeshgui.SetHypothesis( idmesh, idSegBoxe )
187 smeshgui.SetAlgorithms( idmesh, mefistoID )
188 smeshgui.SetHypothesis( idmesh, idlenfromedge)
189 smeshgui.SetAlgorithms( idmesh, netgenID )
190 smeshgui.SetHypothesis( idmesh, idvolume )
192 print "-------------------------- add hypothesis to the first circle"
194 subMeshEdgeCircle1 = mesh.GetElementsOnShape(circle1)
195 retCircle1 = mesh.AddHypothesis(circle1,hypNbSegCylinder)
196 print " add hyp to C1 ", retCircle1
198 idsmCircle1 = smeshgui.AddSubMeshOnShape(
199 idmesh,idCircle1,salome.orb.object_to_string(subMeshEdgeCircle1),
202 smeshgui.SetName(idsmCircle1, "SubMeshEdgeCircle1")
203 smeshgui.SetHypothesis(idsmCircle1, idSegCylinder)
205 print "-------------------------- add hypothesis to the second circle"
207 subMeshEdgeCircle2 = mesh.GetElementsOnShape(circle2)
208 retCircle2 = mesh.AddHypothesis(circle2,hypNbSegCylinder)
209 print " add hyp to C2 ", retCircle2
211 idsmCircle2 = smeshgui.AddSubMeshOnShape(
212 idmesh,idCircle2,salome.orb.object_to_string(subMeshEdgeCircle2),
215 smeshgui.SetName(idsmCircle2, "SubMeshEdgeCircle2")
216 smeshgui.SetHypothesis(idsmCircle2, idSegCylinder)
218 print "-------------------------- add hypothesis to the height of the cylinder"
220 subMeshEdgeHeight = mesh.GetElementsOnShape(height)
221 retHeight = mesh.AddHypothesis(height,hypNbSegCylinder)
222 print " add hyp to H ", retHeight
224 idsmHeight = smeshgui.AddSubMeshOnShape(
225 idmesh,idHeight,salome.orb.object_to_string(subMeshEdgeHeight),
228 smeshgui.SetName(idsmHeight, "SubMeshEdgeHeight")
229 smeshgui.SetHypothesis(idsmHeight, idSegCylinder)
231 sg.updateObjBrowser(1)
233 print "-------------------------- compute the mesh of the shape"
234 ret=gen.Compute(mesh,idshape)
237 log=mesh.GetLog(0) # no erase trace
241 print "probleme when computing the mesh"
243 sg.updateObjBrowser(1)