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