Salome HOME
d32e9b0bd1012101f445f6c4708bd39df041be28
[modules/smesh.git] / src / SMESH_SWIG / SMESH_hexaedre.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #==============================================================================
23 #  Info.
24 #  Bug (from script, bug)   : hexaedre_modified.py, PAL6194, PAL7153
25 #  Modified                 : 25/11/2004
26 #  Author                   : Kovaltchuk Alexey
27 #  Project                  : PAL/SALOME
28 #==============================================================================
29 #
30 import salome
31 import geompy
32 import smesh
33
34 import math
35
36 # -----------------------------------------------------------------------------
37
38 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
39 myBuilder = salome.myStudy.NewBuilder()
40 gg = salome.ImportComponentGUI("GEOM")
41
42 ShapeTypeCompSolid = 1
43 ShapeTypeSolid     = 2
44 ShapeTypeShell     = 3
45 ShapeTypeFace      = 4
46 ShapeTypeWire      = 5
47 ShapeTypeEdge      = 6
48 ShapeTypeVertex    = 7
49
50 Boolop_common = 1
51 Boolop_cut = 2
52 Boolop_fuse = 3
53 Boolop_section = 4
54
55 p0 = geompy.MakeVertex(0., 0., 0.)
56 px = geompy.MakeVertex(100., 0., 0.)
57 py = geompy.MakeVertex(0., 100., 0.)
58 pz = geompy.MakeVertex(0., 0., 100.)
59 vx = geompy.MakeVector(p0, px)
60 vy = geompy.MakeVector(p0, py)
61 vz = geompy.MakeVector(p0, pz)
62
63 sphereExt = geompy.MakeSphere(    0.,  0.,  0., 400.)
64 sphereInt = geompy.MakeSphere(    0.,-50.,  0., 350.)
65 sphereA   = geompy.MakeSphere( -400., 50., 50., 400.)
66 sphereB   = geompy.MakeSphere(  350.,-50.,-50., 350.)
67 ptcyle    = geompy.MakeVertex(0., -300., -450.)
68 cylindre  = geompy.MakeCylinder(ptcyle,vz,500.,900.)
69
70 vol1=geompy.MakeCut(sphereExt,sphereA)
71 vol2=geompy.MakeCut(vol1,sphereB)
72 vol3=geompy.MakeCut(vol2,cylindre)
73 blob=geompy.MakeCut(vol3,sphereInt)
74
75 idblob = geompy.addToStudy(blob,"blob")
76
77 aretes = []
78 aretes = geompy.SubShapeAllSorted(blob, ShapeTypeEdge)
79 eid=0
80
81 # -------------------------------
82 # --- numerotation des aretes
83 ##for edge in aretes:
84 ##    edname="arete%d"%eid
85 ##    idedge=geompy.addToStudy(edge,edname)
86 ##    eid=eid+1
87
88 salome.sg.updateObjBrowser(1)
89
90 # --- epaisseur 0 2 8 10
91 # --- hauteur   1 3 9 11
92 # --- largeur   4 5 6 7
93
94 # -----------------------------------------------------------------------------
95
96 print "-------------------------- mesh"
97
98 # ---- init a Mesh with the geom shape
99 shape_mesh = blob
100 mesh=smesh.Mesh(shape_mesh, "MeshBlob")
101
102 # ---- add hypothesis and algorithms to mesh
103 print "-------------------------- add hypothesis to mesh"
104 algo1 = mesh.Segment()
105 algo2 = mesh.Quadrangle()
106 algo3 = mesh.Hexahedron()
107
108 numberOfSegmentsA = 4
109
110 algo = mesh.Segment(aretes[0])
111 algo.NumberOfSegments(numberOfSegmentsA)
112 algo = mesh.Segment(aretes[2])
113 algo.NumberOfSegments(numberOfSegmentsA)
114 algo = mesh.Segment(aretes[8])
115 algo.NumberOfSegments(numberOfSegmentsA)
116 algo = mesh.Segment(aretes[10])
117 algo.NumberOfSegments(numberOfSegmentsA)
118
119
120 numberOfSegmentsC = 15
121
122 algo = mesh.Segment(aretes[1])
123 algo.NumberOfSegments(numberOfSegmentsC)
124 algo = mesh.Segment(aretes[3])
125 algo.NumberOfSegments(numberOfSegmentsC)
126 algo = mesh.Segment(aretes[9])
127 algo.NumberOfSegments(numberOfSegmentsC)
128 algo = mesh.Segment(aretes[11])
129 algo.NumberOfSegments(numberOfSegmentsC)
130
131
132 numberOfSegmentsB = 10
133 algo = mesh.Segment(aretes[4])
134 algo.NumberOfSegments(numberOfSegmentsB)
135 algo = mesh.Segment(aretes[5])
136 algo.NumberOfSegments(numberOfSegmentsB)
137 algo = mesh.Segment(aretes[6])
138 algo.NumberOfSegments(numberOfSegmentsB)
139 algo = mesh.Segment(aretes[7])
140 algo.NumberOfSegments(numberOfSegmentsB)
141
142
143 # ---- compute mesh
144
145 print "-------------------------- compute mesh"
146 ret=mesh.Compute()
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 Mesh:"
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 quadrangles : ", mesh.NbQuadrangles()
157     print "Number of volumes     : ", mesh.NbVolumes()
158     print "Number of hexahedrons : ", mesh.NbHexas()
159 else:
160     print "problem when Computing the mesh"
161
162 salome.sg.updateObjBrowser(1)