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(study, 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 studyId = study._get_StudyId()
37 geompy = geomtools.getGeompy(studyId)
40 radius_int = radius_ext - width
42 CylinderExt = geompy.MakeCylinderRH(radius_ext, length)
43 CylinderInt = geompy.MakeCylinderRH(radius_int, length)
44 Tube = geompy.MakeCut(CylinderExt, CylinderInt)
47 def createGeometryWithPartition(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH):
49 This function create the geometrical shape with a partition so
50 that the hexaedric algorithm could be used for meshing.
52 shape = createGeometry(study,radius,length,width)
54 # We have to create a partition so that we can use an hexaedric
56 studyId = study._get_StudyId()
57 geompy = geomtools.getGeompy(studyId)
59 print "TUBE: creating a partition ..."
60 toolPlane = geompy.MakeFaceHW(2.1*length,2.1*radius,3)
61 partition = geompy.MakePartition([shape], [toolPlane], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
62 entry = geompy.addToStudy( partition, "TubeWithPartition" )
65 def createMesh(study, shape):
66 '''This function creates the mesh of the specified shape on the specified study'''
67 print "TUBE: creating the mesh ..."
69 from salome.smesh import smeshBuilder
70 smesh = smeshBuilder.New(study)
72 mesh = smesh.Mesh(shape)
73 Regular_1D = mesh.Segment()
74 Nb_Segments = Regular_1D.NumberOfSegments(10)
75 Nb_Segments.SetDistrType( 0 )
76 Quadrangle_2D = mesh.Quadrangle()
77 Hexa_3D = mesh.Hexahedron()
79 isDone = mesh.Compute()
81 if salome.sg.hasDesktop():
82 smesh.SetName(mesh.GetMesh(), 'TubeMesh')
83 smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
84 smesh.SetName(Nb_Segments, 'Nb. Segments_1')
85 smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
86 smesh.SetName(Hexa_3D.GetAlgorithm(), 'Hexa_3D')
87 salome.sg.updateObjBrowser(False)
92 def createModel(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH,width=DEFAULT_WIDTH):
94 This function create the geomtrical shape AND the associated mesh.
96 # We first create a shape with a partition so that the hexaedric
97 # algorithm could be used.
98 shape = createGeometryWithPartition(study,radius,length,width)
100 # Then the mesh can be defined and computed
101 mesh = createMesh(study,shape)
103 def exportModel(mesh, filename):
105 This exports the mesh to the specified filename in the med format
107 print "TUBE: exporting mesh to file %s ..."%filename
109 mesh.ExportMED(filename, 0, SMESH.MED_V2_2, 1 )
113 # ===================================================================
114 # Use cases and test functions
115 # ===================================================================
117 def TEST_createGeometry():
119 theStudy=salome.myStudy
120 createGeometry(theStudy)
122 def TEST_createMesh():
124 theStudy=salome.myStudy
125 shape = createGeometryWithPartition(theStudy)
126 mesh = createMesh(theStudy, shape)
128 def TEST_createModel():
130 theStudy=salome.myStudy
131 createModel(theStudy)
133 def TEST_exportModel():
135 theStudy=salome.myStudy
136 shape = createGeometryWithPartition(theStudy)
137 mesh = createMesh(theStudy, shape)
138 exportModel(mesh,"tubemesh.med")
140 if __name__ == "__main__":
141 #TEST_createGeometry()