Salome HOME
Typo-fix by Kunda
[modules/smesh.git] / src / SMESH_SWIG / SMESH_mechanic_netgen.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 # Quadrangulation of the geometry generated by the Python script
25 # SMESH_mechanic.py
26 # The new Netgen algorithm is used that discretizes baoundaries itself
27 #
28 import salome
29 salome.salome_init()
30 import GEOM
31 from salome.geom import geomBuilder
32 geompy = geomBuilder.New()
33
34 import SMESH, SALOMEDS
35 from salome.smesh import smeshBuilder
36 smesh =  smeshBuilder.New()
37
38 # ---------------------------- GEOM --------------------------------------
39
40 # ---- define contiguous arcs and segment to define a closed wire
41 p1   = geompy.MakeVertex( 100.0,   0.0,  0.0 )
42 p2   = geompy.MakeVertex(  50.0,  50.0,  0.0 )
43 p3   = geompy.MakeVertex( 100.0, 100.0,  0.0 )
44 arc1 = geompy.MakeArc( p1, p2, p3 )
45
46 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
47 seg1 = geompy.MakeVector( p3, p4 )
48
49 p5   = geompy.MakeVertex( 200.0, 70.0, 0.0 )
50 p6   = geompy.MakeVertex( 170.0, 40.0, 0.0 )
51 arc2 = geompy.MakeArc( p4, p5, p6 )
52
53 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
54 arc3 = geompy.MakeArc( p6, p7, p1 )
55
56 # ---- define a closed wire with arcs and segment
57 List1 = []
58 List1.append( arc1 )
59 List1.append( seg1 )
60 List1.append( arc2 )
61 List1.append( arc3 )
62
63 wire1 = geompy.MakeWire( List1 )
64 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
65
66 # ---- define a planar face with wire
67 WantPlanarFace = 1 #True
68 face1 = geompy.MakeFace( wire1, WantPlanarFace )
69 Id_face1 = geompy.addToStudy( face1, "face1" )
70
71 # ---- create a shape by extrusion
72 pO = geompy.MakeVertex( 0.0, 0.0,   0.0 )
73 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
74 vz = geompy.MakeVector( pO, pz )
75
76 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
77 Id_prism1 = geompy.addToStudy( prism1, "prism1")
78
79 # ---- create two cylinders
80
81 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
82 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
83 radius = 20.0
84 height = 180.0
85 cyl1  = geompy.MakeCylinder( pc1, vz, radius, height )
86 cyl2  = geompy.MakeCylinder( pc2, vz, radius, height )
87
88 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
89 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
90
91 # ---- cut with cyl1
92 shape  = geompy.MakeBoolean( prism1, cyl1, 2 )
93
94 # ---- fuse with cyl2 to obtain the final mechanic piece :)
95 mechanic =  geompy.MakeBoolean( shape, cyl2, 3 )
96 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
97
98 # ---- Analysis of the geometry
99
100 print("Analysis of the geometry mechanic :")
101
102 subShellList = geompy.SubShapeAll(mechanic,geompy.ShapeType["SHELL"])
103 subFaceList  = geompy.SubShapeAll(mechanic,geompy.ShapeType["FACE"])
104 subEdgeList  = geompy.SubShapeAll(mechanic,geompy.ShapeType["EDGE"])
105
106 print("number of Shells in mechanic : ",len(subShellList))
107 print("number of Faces in mechanic : ",len(subFaceList))
108 print("number of Edges in mechanic : ",len(subEdgeList))
109
110 ### ---------------------------- SMESH --------------------------------------
111
112 print("-------------------------- create Mesh, algorithm, hypothesis")
113
114 mesh = smesh.Mesh(mechanic, "Mesh_mechanic");
115 netgen = mesh.Triangle(smeshBuilder.NETGEN)
116 netgen.SetMaxSize( 50 )
117 #netgen.SetSecondOrder( 0 )
118 netgen.SetFineness( smeshBuilder.Fine )
119 netgen.SetQuadAllowed( 1 )
120 #netgen.SetOptimize( 1 )
121
122 print("-------------------------- compute mesh")
123 ret = mesh.Compute()
124 print(ret)
125 if ret != 0:
126     print("Information about the MeshcompShel:")
127     print("Number of nodes        : ", mesh.NbNodes())
128     print("Number of edges        : ", mesh.NbEdges())
129     print("Number of faces        : ", mesh.NbFaces())
130     print("Number of triangles    : ", mesh.NbTriangles())
131     print("Number of quadrangles  : ", mesh.NbQuadrangles())
132     print("Number of volumes      : ", mesh.NbVolumes())
133     print("Number of tetrahedrons : ", mesh.NbTetras())
134     
135 else:
136     print("problem when computing the mesh")
137
138 salome.sg.updateObjBrowser()