Back to index

salome-smesh  6.5.0
batchmode_mefisto.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 import os
00025 import re
00026 
00027 import batchmode_salome
00028 import batchmode_geompy
00029 import batchmode_smesh
00030 import StdMeshers
00031 
00032 smesh = batchmode_smesh.smesh
00033 smesh.SetCurrentStudy(batchmode_salome.myStudy)
00034 
00035 def CreateMesh (theFileName, area, len = None, nbseg = None):
00036     
00037     if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
00038         print "Incorrect file name !"
00039         return
00040 
00041     if (len is None) and (nbseg is None):
00042         print "Define length or number of segments !"
00043         return
00044 
00045     if (len is not None) and (nbseg is not None):
00046         print "Only one Hypothesis (from length and number of segments) can be defined !"
00047         return
00048 
00049     
00050     # ----  Import shape from BREP file and add it to the study  
00051     shape_mesh = batchmode_geompy.Import(theFileName, "BREP")
00052     Id_shape = batchmode_geompy.addToStudy(shape_mesh, "shape_mesh")
00053 
00054 
00055     # ---- SMESH
00056     print "-------------------------- create mesh"
00057     mesh = smesh.Mesh(shape_mesh)
00058       
00059     print "-------------------------- create Hypothesis"
00060     if (len is not None):
00061         print "-------------------------- LocalLength"
00062         algoReg = mesh.Segment()
00063         hypLength1 = algoReg.LocalLength(len)
00064         print "Hypothesis type : ", hypLength1.GetName()
00065         print "Hypothesis ID   : ", hypLength1.GetId()
00066         print "Hypothesis Value: ", hypLength1.GetLength()
00067     
00068     if (nbseg is not None):   
00069         print "-------------------------- NumberOfSegments"
00070         algoReg = mesh.Segment()
00071         hypNbSeg1 = algoReg.NumberOfSegments(nbseg)
00072         print "Hypothesis type : ", hypNbSeg1.GetName()
00073         print "Hypothesis ID   : ", hypNbSeg1.GetId()
00074         print "Hypothesis Value: ", hypNbSeg1.GetNumberOfSegments()
00075 
00076     if (area == "LengthFromEdges"):
00077         print "-------------------------- LengthFromEdges"
00078         algoMef = mesh.Triangle()
00079         hypLengthFromEdges = algoMef.LengthFromEdges(1)
00080         print "Hypothesis type     : ", hypLengthFromEdges.GetName()
00081         print "Hypothesis ID       : ", hypLengthFromEdges.GetId()
00082         print "LengthFromEdges Mode: ", hypLengthFromEdges.GetMode()
00083        
00084     else:
00085         print "-------------------------- MaxElementArea"
00086         algoMef = mesh.Triangle()
00087         hypArea1 = algoMef.MaxElementArea(area)
00088         print "Hypothesis type : ", hypArea1.GetName()
00089         print "Hypothesis ID   : ", hypArea1.GetId()
00090         print "Hypothesis Value: ", hypArea1.GetMaxElementArea()
00091               
00092     
00093     print "-------------------------- Regular_1D"
00094     listHyp = algoReg.GetCompatibleHypothesis()
00095     for hyp in listHyp:
00096         print hyp
00097     
00098     print "Algo name: ", algoReg.GetName()
00099     print "Algo ID  : ", algoReg.GetId()
00100    
00101     print "-------------------------- MEFISTO_2D"
00102     listHyp = algoMef.GetCompatibleHypothesis()
00103     for hyp in listHyp:
00104         print hyp
00105         
00106     print "Algo name: ", algoMef.GetName()
00107     print "Algo ID  : ", algoMef.GetId()
00108 
00109 
00110     # ---- add hypothesis to shape
00111 
00112     print "-------------------------- compute mesh"
00113     ret = mesh.Compute()
00114     print  "Compute Mesh .... ", 
00115     print ret
00116     log = mesh.GetLog(0); # no erase trace
00117     #for linelog in log:
00118     #    print linelog
00119 
00120     print "------------ INFORMATION ABOUT MESH ------------"
00121     
00122     print "Number of nodes    : ", mesh.NbNodes()
00123     print "Number of edges    : ", mesh.NbEdges()
00124     print "Number of faces    : ", mesh.NbFaces()
00125     print "Number of triangles: ", mesh.NbTriangles()
00126 
00127     return mesh