Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/smesh.git] / src / SMESH_SWIG / SMESH_box3_tetra.py
1 #
2 # Tetrahedrization of the geometry union of 3 boxes aligned where the middle
3 # one has a race in common with the two others.
4 # Hypothesis and algorithms for the mesh generation are global
5 #
6
7 import salome
8 import geompy
9
10 import StdMeshers
11 import NETGENPlugin
12
13 geom  = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
14 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
15
16 smeshgui = salome.ImportComponentGUI("SMESH")
17 smeshgui.Init(salome.myStudyId);
18
19 ShapeTypeShell     = 3
20 ShapeTypeFace      = 4
21 ShapeTypeEdge      = 6
22
23 # ---- define 3 boxes box1, box2 and box3
24
25 box1 = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
26
27 idbox1 = geompy.addToStudy(box1,"box1")
28
29 print "Analysis of the geometry box1 :"
30 subShellList=geompy.SubShapeAll(box1,ShapeTypeShell)
31 subFaceList=geompy.SubShapeAll(box1,ShapeTypeFace)
32 subEdgeList=geompy.SubShapeAll(box1,ShapeTypeEdge)
33
34 print "number of Shells in box1 : ",len(subShellList)
35 print "number of Faces in box1 : ",len(subFaceList)
36 print "number of Edges in box1 : ",len(subEdgeList)
37
38 box2 = geompy.MakeBox(100., 0., 0., 200., 200., 300.)
39
40 idbox2 = geompy.addToStudy(box2,"box2")
41
42 print "Analysis of the geometry box2 :"
43 subShellList=geompy.SubShapeAll(box2,ShapeTypeShell)
44 subFaceList=geompy.SubShapeAll(box2,ShapeTypeFace)
45 subEdgeList=geompy.SubShapeAll(box2,ShapeTypeEdge)
46
47 print "number of Shells in box2 : ",len(subShellList)
48 print "number of Faces in box2 : ",len(subFaceList)
49 print "number of Edges in box2 : ",len(subEdgeList)
50
51 box3 = geompy.MakeBox(0., 0., 300., 200., 200., 500.)
52
53 idbox3 = geompy.addToStudy(box3,"box3")
54
55 print "Analysis of the geometry box3 :"
56 subShellList=geompy.SubShapeAll(box3,ShapeTypeShell)
57 subFaceList=geompy.SubShapeAll(box3,ShapeTypeFace)
58 subEdgeList=geompy.SubShapeAll(box3,ShapeTypeEdge)
59
60 print "number of Shells in box3 : ",len(subShellList)
61 print "number of Faces in box3 : ",len(subFaceList)
62 print "number of Edges in box3 : ",len(subEdgeList)
63
64 blocs = []
65 blocs.append(box1._get_Name())
66 blocs.append(box2._get_Name())
67 blocs.append(box3._get_Name())
68
69 shell = geompy.Partition(blocs)
70 idshell = geompy.addToStudy(shell,"shell")
71
72 print "Analysis of the geometry shell (union of box1, box2 and box3) :"
73 subShellList=geompy.SubShapeAll(shell,ShapeTypeShell)
74 subFaceList=geompy.SubShapeAll(shell,ShapeTypeFace)
75 subEdgeList=geompy.SubShapeAll(shell,ShapeTypeEdge)
76
77 print "number of Shells in shell : ",len(subShellList)
78 print "number of Faces in shell : ",len(subFaceList)
79 print "number of Edges in shell : ",len(subEdgeList)
80
81
82 ### ---------------------------- SMESH --------------------------------------
83
84 # ---- create Hypothesis
85
86 print "-------------------------- create Hypothesis"
87
88 print "-------------------------- NumberOfSegments"
89
90 numberOfSegments = 10
91
92 hypNbSeg=smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
93 hypNbSeg.SetNumberOfSegments(numberOfSegments)
94
95 print hypNbSeg.GetName()
96 print hypNbSeg.GetId()
97 print hypNbSeg.GetNumberOfSegments()
98
99 smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")
100
101 print "-------------------------- MaxElementArea"
102
103 maxElementArea = 500
104
105 hypArea=smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
106 hypArea.SetMaxElementArea(maxElementArea)
107
108 print hypArea.GetName()
109 print hypArea.GetId()
110 print hypArea.GetMaxElementArea()
111
112 smeshgui.SetName(salome.ObjectToID(hypArea), "MaxElementArea_500")
113
114 print "-------------------------- MaxElementVolume"
115
116 maxElementVolume = 500
117
118 hypVolume=smesh.CreateHypothesis("MaxElementVolume", "libStdMeshersEngine.so")
119 hypVolume.SetMaxElementVolume(maxElementVolume)
120
121 print hypVolume.GetName()
122 print hypVolume.GetId()
123 print hypVolume.GetMaxElementVolume()
124
125 smeshgui.SetName(salome.ObjectToID(hypVolume), "MaxElementVolume_500")
126
127 # ---- create Algorithms
128
129 print "-------------------------- create Algorithms"
130
131 print "-------------------------- Regular_1D"
132
133 regular1D=smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
134 smeshgui.SetName(salome.ObjectToID(regular1D), "Wire Discretisation")
135
136 print "-------------------------- MEFISTO_2D"
137
138 mefisto2D=smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
139 smeshgui.SetName(salome.ObjectToID(mefisto2D), "MEFISTO_2D")
140
141 print "-------------------------- NETGEN_3D"
142
143 netgen3D=smesh.CreateHypothesis("NETGEN_3D", "libNETGENEngine.so")
144 smeshgui.SetName(salome.ObjectToID(netgen3D), "NETGEN_3D")
145
146 # ---- init a Mesh with the shell
147
148 mesh = smesh.CreateMesh(shell)
149 smeshgui.SetName(salome.ObjectToID(mesh), "MeshBox3")
150
151 # ---- add hypothesis to shell
152
153 print "-------------------------- add hypothesis to shell"
154
155 mesh.AddHypothesis(shell,regular1D)
156 mesh.AddHypothesis(shell,hypNbSeg)
157
158 mesh.AddHypothesis(shell,mefisto2D)
159 mesh.AddHypothesis(shell,hypArea)
160
161 mesh.AddHypothesis(shell,netgen3D)
162 mesh.AddHypothesis(shell,hypVolume)
163
164 salome.sg.updateObjBrowser(1)
165
166 print "-------------------------- compute shell"
167 ret= smesh.Compute(mesh,shell)
168 print ret
169 if ret != 0:
170     log=mesh.GetLog(0) # no erase trace
171     for linelog in log:
172         print linelog
173     print "Information about the MeshBox3:"
174     print "Number of nodes       : ", mesh.NbNodes()
175     print "Number of edges       : ", mesh.NbEdges()
176     print "Number of faces       : ", mesh.NbFaces()
177     print "Number of triangles   : ", mesh.NbTriangles()
178     print "Number of volumes     : ", mesh.NbVolumes()
179     print "Number of tetrahedrons: ", mesh.NbTetras()
180 else:
181     print "probleme when computing the mesh"