Salome HOME
23368: [CEA 1865] Possibility to define faces to mesh as a single one: transpatch...
[modules/smesh.git] / src / SMESH_SWIG / SMESH_Sphere.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  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, or (at your option) any later version.
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 import salome
31 salome.salome_init()
32 import GEOM
33 from salome.geom import geomBuilder
34 geompy = geomBuilder.New(salome.myStudy)
35
36 import SMESH, SALOMEDS
37 from salome.smesh import smeshBuilder
38 smesh =  smeshBuilder.New(salome.myStudy)
39
40 import math
41
42 # It is an example of creating a hexahedrical mesh on a sphere.
43 #
44 # Used approach allows to avoid problems with degenerated and
45 # seam edges without special processing of geometrical shapes
46
47 #-----------------------------------------------------------------------
48 #Variables
49 Radius  = 100.
50 Dist    = Radius / 2.
51 Factor  = 2.5
52 Angle90 = math.pi / 2.
53 NbSeg   = 10
54
55 PointsList = []
56 ShapesList = []
57
58 #Basic Elements
59 P0 = geompy.MakeVertex(0., 0., 0.)
60 P1 = geompy.MakeVertex(-Dist, -Dist, -Dist)
61 P2 = geompy.MakeVertex(-Dist, -Dist, Dist)
62 P3 = geompy.MakeVertex(-Dist, Dist, Dist)
63 P4 = geompy.MakeVertex(-Dist, Dist, -Dist)
64
65 VZ = geompy.MakeVectorDXDYDZ(0., 0., 1.)
66
67 #Construction Elements
68 PointsList.append(P1)
69 PointsList.append(P2)
70 PointsList.append(P3)
71 PointsList.append(P4)
72 PointsList.append(P1)
73
74 PolyLine = geompy.MakePolyline(PointsList)
75
76 Face1 = geompy.MakeFace(PolyLine, 1)
77 Face2 = geompy.MakeScaleTransform(Face1, P0, Factor)
78 Face3 = geompy.MakeScaleTransform(Face1, P0, -1.)
79
80 #Models
81 Sphere = geompy.MakeSphereR(Radius)
82
83 Block = geompy.MakeHexa2Faces(Face1, Face2)
84 Cube  = geompy.MakeHexa2Faces(Face1, Face3)
85
86 Common1 = geompy.MakeBoolean(Sphere, Block, 1)
87 Common2 = geompy.MakeRotation(Common1, VZ, Angle90)
88
89 MultiBlock1 = geompy.MakeMultiTransformation1D(Common1, 20, -1, 3)
90 MultiBlock2 = geompy.MakeMultiTransformation1D(Common2, 30, -1, 3)
91
92 #Reconstruct sphere from several blocks
93 ShapesList.append(Cube)
94 ShapesList.append(MultiBlock1)
95 ShapesList.append(MultiBlock2)
96 Compound = geompy.MakeCompound(ShapesList)
97
98 Result = geompy.MakeGlueFaces(Compound, 0.1)
99
100 #addToStudy
101 Id_Sphere      = geompy.addToStudy(Sphere, "Sphere")
102 Id_Cube        = geompy.addToStudy(Cube, "Cube")
103
104 Id_Common1     = geompy.addToStudy(Common1, "Common1")
105 Id_Common2     = geompy.addToStudy(Common2, "Common2")
106
107 Id_MultiBlock1 = geompy.addToStudy(MultiBlock1, "MultiBlock1")
108 Id_MultiBlock2 = geompy.addToStudy(MultiBlock2, "MultiBlock2")
109
110 Id_Result      = geompy.addToStudy(Result, "Result")
111
112 #-----------------------------------------------------------------------
113 #Meshing
114 my_hexa = smesh.Mesh(Result, "Sphere_Mesh")
115 algo = my_hexa.Segment()
116 algo.NumberOfSegments(NbSeg)
117 my_hexa.Quadrangle()
118 my_hexa.Hexahedron()
119 my_hexa.Compute()
120
121 salome.sg.updateObjBrowser(True)