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