Salome HOME
activateModule/deactivateModule functions are made "bool".
[modules/smesh.git] / src / SMESH_SWIG / SMESH_Sphere.py
1 #  GEOM GEOM_SWIG : binding of C++ omplementaion with Python
2 #
3 #  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 #
22 #
23 #
24 #  File   : GEOM_Sphere.py
25 #  Author : Damien COQUERET, Open CASCADE
26 #  Module : GEOM
27 #  $Header: 
28
29 from geompy import *
30 from math import *
31
32 import smesh
33
34 # It is an example of creating a hexahedrical mesh on a sphere.
35 #
36 # Used approach allows to avoid problems with degenerated and
37 # seam edges without special processing of geometrical shapes
38
39 #-----------------------------------------------------------------------
40 #Variables
41 Radius  = 100.
42 Dist    = Radius / 2.
43 Factor  = 2.5
44 Angle90 = pi / 2.
45 NbSeg   = 10
46
47 PointsList = []
48 ShapesList = []
49
50 #Basic Elements
51 P0 = MakeVertex(0., 0., 0.)
52 P1 = MakeVertex(-Dist, -Dist, -Dist)
53 P2 = MakeVertex(-Dist, -Dist, Dist)
54 P3 = MakeVertex(-Dist, Dist, Dist)
55 P4 = MakeVertex(-Dist, Dist, -Dist)
56
57 VZ = MakeVectorDXDYDZ(0., 0., 1.)
58
59 #Construction Elements
60 PointsList.append(P1)
61 PointsList.append(P2)
62 PointsList.append(P3)
63 PointsList.append(P4)
64 PointsList.append(P1)
65
66 PolyLine = MakePolyline(PointsList)
67
68 Face1 = MakeFace(PolyLine, 1)
69 Face2 = MakeScaleTransform(Face1, P0, Factor)
70 Face3 = MakeScaleTransform(Face1, P0, -1.)
71
72 #Models
73 Sphere = MakeSphereR(Radius)
74
75 Block = MakeHexa2Faces(Face1, Face2)
76 Cube  = MakeHexa2Faces(Face1, Face3)
77
78 Common1 = MakeBoolean(Sphere, Block, 1)
79 Common2 = MakeRotation(Common1, VZ, Angle90)
80
81 MultiBlock1 = MakeMultiTransformation1D(Common1, 21, -1, 3)
82 MultiBlock2 = MakeMultiTransformation1D(Common2, 31, -1, 3)
83
84 #Reconstruct sphere from several blocks
85 ShapesList.append(Cube)
86 ShapesList.append(MultiBlock1)
87 ShapesList.append(MultiBlock2)
88 Compound = MakeCompound(ShapesList)
89
90 Result = MakeGlueFaces(Compound, 0.1)
91
92 #addToStudy
93 Id_Sphere      = addToStudy(Sphere, "Sphere")
94 Id_Cube        = addToStudy(Cube, "Cube")
95
96 Id_Common1     = addToStudy(Common1, "Common1")
97 Id_Common2     = addToStudy(Common2, "Common2")
98
99 Id_MultiBlock1 = addToStudy(MultiBlock1, "MultiBlock1")
100 Id_MultiBlock2 = addToStudy(MultiBlock2, "MultiBlock2")
101
102 Id_Result      = addToStudy(Result, "Result")
103
104 #-----------------------------------------------------------------------
105 #Meshing
106 my_hexa = smesh.Mesh(Result, "Sphere_Mesh")
107 algo = my_hexa.Segment()
108 algo.NumberOfSegments(NbSeg)
109 my_hexa.Quadrangle()
110 my_hexa.Hexahedron()
111 my_hexa.Compute()