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