1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2010-2013 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.
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 ..."
70 smesh.SetCurrentStudy(study)
71 mesh = smesh.Mesh(shape)
72 Regular_1D = mesh.Segment()
73 Nb_Segments = Regular_1D.NumberOfSegments(10)
74 Nb_Segments.SetDistrType( 0 )
75 Quadrangle_2D = mesh.Quadrangle()
76 Hexa_3D = mesh.Hexahedron()
78 isDone = mesh.Compute()
80 if salome.sg.hasDesktop():
81 smesh.SetName(mesh.GetMesh(), 'TubeMesh')
82 smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
83 smesh.SetName(Nb_Segments, 'Nb. Segments_1')
84 smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
85 smesh.SetName(Hexa_3D.GetAlgorithm(), 'Hexa_3D')
86 salome.sg.updateObjBrowser(0)
91 def createModel(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH,width=DEFAULT_WIDTH):
93 This function create the geomtrical shape AND the associated mesh.
95 # We first create a shape with a partition so that the hexaedric
96 # algorithm could be used.
97 shape = createGeometryWithPartition(study,radius,length,width)
99 # Then the mesh can be defined and computed
100 mesh = createMesh(study,shape)
102 def exportModel(mesh, filename):
104 This exports the mesh to the specified filename in the med format
106 print "TUBE: exporting mesh to file %s ..."%filename
108 mesh.ExportMED(filename, 0, SMESH.MED_V2_2, 1 )
112 # ===================================================================
113 # Use cases and test functions
114 # ===================================================================
116 def TEST_createGeometry():
118 theStudy=salome.myStudy
119 createGeometry(theStudy)
121 def TEST_createMesh():
123 theStudy=salome.myStudy
124 shape = createGeometryWithPartition(theStudy)
125 mesh = createMesh(theStudy, shape)
127 def TEST_createModel():
129 theStudy=salome.myStudy
130 createModel(theStudy)
132 def TEST_exportModel():
134 theStudy=salome.myStudy
135 shape = createGeometryWithPartition(theStudy)
136 mesh = createMesh(theStudy, shape)
137 exportModel(mesh,"tubemesh.med")
139 if __name__ == "__main__":
140 #TEST_createGeometry()