Back to index

salome-gui  6.5.0
tubebuilder.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # This library is free software; you can redistribute it and/or
00005 # modify it under the terms of the GNU Lesser General Public
00006 # License as published by the Free Software Foundation; either
00007 # version 2.1 of the License.
00008 #
00009 # This library is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 # Lesser General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU Lesser General Public
00015 # License along with this library; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 #
00018 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 #
00020 # Author : Guillaume Boulant (EDF)
00021 
00022 import salome
00023 
00024 DEFAULT_RADIUS = 100
00025 DEFAULT_LENGTH = 300
00026 DEFAULT_WIDTH  = 20
00027 
00028 from salome.geom import geomtools
00029 
00030 def createGeometry(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH):
00031     '''
00032     This function creates the geometry on the specified study and with
00033     given parameters.
00034     '''
00035     print "TUBE: creating the geometry ..."
00036     studyId = study._get_StudyId()
00037     geompy = geomtools.getGeompy(studyId)
00038 
00039     radius_ext = radius
00040     radius_int = radius_ext - width
00041 
00042     CylinderExt = geompy.MakeCylinderRH(radius_ext, length)
00043     CylinderInt = geompy.MakeCylinderRH(radius_int, length)
00044     Tube = geompy.MakeCut(CylinderExt, CylinderInt)
00045     return Tube
00046     
00047 def createGeometryWithPartition(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH):
00048     '''
00049     This function create the geometrical shape with a partition so
00050     that the hexaedric algorithm could be used for meshing.
00051     '''
00052     shape = createGeometry(study,radius,length,width)
00053 
00054     # We have to create a partition so that we can use an hexaedric
00055     # meshing algorithm.
00056     studyId = study._get_StudyId()
00057     geompy = geomtools.getGeompy(studyId)
00058 
00059     print "TUBE: creating a partition ..."
00060     toolPlane = geompy.MakeFaceHW(2.1*length,2.1*radius,3)
00061     partition = geompy.MakePartition([shape], [toolPlane], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
00062     entry = geompy.addToStudy( partition, "TubeWithPartition" )
00063     return partition
00064     
00065 def createMesh(study, shape):
00066     '''This function creates the mesh of the specified shape on the specified study'''
00067     print "TUBE: creating the mesh ..."
00068     import smesh
00069 
00070     smesh.SetCurrentStudy(study)
00071     mesh = smesh.Mesh(shape)
00072     Regular_1D = mesh.Segment()
00073     Nb_Segments = Regular_1D.NumberOfSegments(10)
00074     Nb_Segments.SetDistrType( 0 )
00075     Quadrangle_2D = mesh.Quadrangle()
00076     Hexa_3D = mesh.Hexahedron()
00077 
00078     isDone = mesh.Compute()
00079 
00080     if salome.sg.hasDesktop():
00081         smesh.SetName(mesh.GetMesh(), 'TubeMesh')
00082         smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
00083         smesh.SetName(Nb_Segments, 'Nb. Segments_1')
00084         smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
00085         smesh.SetName(Hexa_3D.GetAlgorithm(), 'Hexa_3D')
00086         salome.sg.updateObjBrowser(0)
00087 
00088     return mesh
00089 
00090 
00091 def createModel(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH,width=DEFAULT_WIDTH):
00092     '''
00093     This function create the geomtrical shape AND the associated mesh.
00094     '''
00095     # We first create a shape with a partition so that the hexaedric
00096     # algorithm could be used.
00097     shape = createGeometryWithPartition(study,radius,length,width)
00098 
00099     # Then the mesh can be defined and computed
00100     mesh = createMesh(study,shape)
00101     
00102 def exportModel(mesh, filename):
00103     '''
00104     This exports the mesh to the specified filename in the med format
00105     '''
00106     print "TUBE: exporting mesh to file %s ..."%filename
00107     import SMESH
00108     mesh.ExportMED(filename, 0, SMESH.MED_V2_2, 1 )
00109 
00110 
00111 #
00112 # ===================================================================
00113 # Use cases and test functions
00114 # ===================================================================
00115 #
00116 def TEST_createGeometry():
00117     salome.salome_init()
00118     theStudy=salome.myStudy
00119     createGeometry(theStudy)
00120 
00121 def TEST_createMesh():
00122     salome.salome_init()
00123     theStudy=salome.myStudy
00124     shape = createGeometryWithPartition(theStudy)
00125     mesh  = createMesh(theStudy, shape)
00126 
00127 def TEST_createModel():
00128     salome.salome_init()
00129     theStudy=salome.myStudy
00130     createModel(theStudy)
00131 
00132 def TEST_exportModel():
00133     salome.salome_init()
00134     theStudy=salome.myStudy
00135     shape = createGeometryWithPartition(theStudy)
00136     mesh  = createMesh(theStudy, shape)
00137     exportModel(mesh,"tubemesh.med")
00138     
00139 if __name__ == "__main__":
00140     #TEST_createGeometry()
00141     #TEST_createMesh()
00142     TEST_createModel()
00143     #TEST_exportModel()