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