1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2010-2016 CEA/DEN, EDF R&D, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Guillaume Boulant (EDF)
28 from salome.geom import geomtools
30 def createGeometry(radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH):
32 This function creates the geometry on the specified study and with
35 print("TUBE: creating the geometry ...")
36 geompy = geomtools.getGeompy()
39 radius_int = radius_ext - width
41 CylinderExt = geompy.MakeCylinderRH(radius_ext, length)
42 CylinderInt = geompy.MakeCylinderRH(radius_int, length)
43 Tube = geompy.MakeCut(CylinderExt, CylinderInt)
46 def createGeometryWithPartition(radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH):
48 This function create the geometrical shape with a partition so
49 that the hexaedric algorithm could be used for meshing.
51 shape = createGeometry(radius,length,width)
53 # We have to create a partition so that we can use an hexaedric
55 geompy = geomtools.getGeompy()
57 print("TUBE: creating a partition ...")
58 toolPlane = geompy.MakeFaceHW(2.1*length,2.1*radius,3)
59 partition = geompy.MakePartition([shape], [toolPlane], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
60 entry = geompy.addToStudy( partition, "TubeWithPartition" )
63 def createMesh(shape):
64 '''This function creates the mesh of the specified shape on the current study'''
65 print("TUBE: creating the mesh ...")
67 from salome.smesh import smeshBuilder
68 smesh = smeshBuilder.New()
70 mesh = smesh.Mesh(shape)
71 Regular_1D = mesh.Segment()
72 Nb_Segments = Regular_1D.NumberOfSegments(10)
73 Nb_Segments.SetDistrType( 0 )
74 Quadrangle_2D = mesh.Quadrangle()
75 Hexa_3D = mesh.Hexahedron()
77 isDone = mesh.Compute()
79 if salome.sg.hasDesktop():
80 smesh.SetName(mesh.GetMesh(), 'TubeMesh')
81 smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
82 smesh.SetName(Nb_Segments, 'Nb. Segments_1')
83 smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
84 smesh.SetName(Hexa_3D.GetAlgorithm(), 'Hexa_3D')
85 salome.sg.updateObjBrowser()
90 def createModel(radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH,width=DEFAULT_WIDTH):
92 This function create the geomtrical shape AND the associated mesh.
94 # We first create a shape with a partition so that the hexaedric
95 # algorithm could be used.
96 shape = createGeometryWithPartition(radius,length,width)
98 # Then the mesh can be defined and computed
99 mesh = createMesh(shape)
101 def exportModel(mesh, filename):
103 This exports the mesh to the specified filename in the med format
105 print("TUBE: exporting mesh to file %s ..."%filename)
107 mesh.ExportMED(filename, 0, SMESH.MED_V2_2, 1 )
111 # ===================================================================
112 # Use cases and test functions
113 # ===================================================================
115 def TEST_createGeometry():
119 def TEST_createMesh():
121 shape = createGeometryWithPartition()
122 mesh = createMesh(shape)
124 def TEST_createModel():
128 def TEST_exportModel():
130 shape = createGeometryWithPartition()
131 mesh = createMesh(shape)
132 exportModel(mesh,"tubemesh.med")
134 if __name__ == "__main__":
135 #TEST_createGeometry()