smesh/src/SMESH_SWIG/batchmode_mefisto.py

128 lines
4.4 KiB
Python
Raw Normal View History

2012-08-09 16:03:55 +06:00
# -*- coding: iso-8859-1 -*-
2013-04-01 19:05:47 +06:00
# Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
2009-02-17 10:27:49 +05:00
#
2012-08-09 16:03:55 +06:00
# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#
2012-08-09 16:03:55 +06:00
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License.
#
2012-08-09 16:03:55 +06:00
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
2012-08-09 16:03:55 +06:00
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
2012-08-09 16:03:55 +06:00
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
2012-08-09 16:03:55 +06:00
2004-06-18 14:34:31 +06:00
import os
import re
import batchmode_salome
import batchmode_geompy
import batchmode_smesh
2004-12-01 15:48:31 +05:00
import StdMeshers
2004-06-18 14:34:31 +06:00
smesh = batchmode_smesh.smesh
smesh.SetCurrentStudy(batchmode_salome.myStudy)
def CreateMesh (theFileName, area, len = None, nbseg = None):
if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
print "Incorrect file name !"
return
if (len is None) and (nbseg is None):
print "Define length or number of segments !"
return
if (len is not None) and (nbseg is not None):
print "Only one Hypothesis (from length and number of segments) can be defined !"
return
# ---- Import shape from BREP file and add it to the study
2004-12-01 15:48:31 +05:00
shape_mesh = batchmode_geompy.Import(theFileName, "BREP")
Id_shape = batchmode_geompy.addToStudy(shape_mesh, "shape_mesh")
2004-06-18 14:34:31 +06:00
# ---- SMESH
print "-------------------------- create mesh"
mesh = smesh.Mesh(shape_mesh)
2004-06-18 14:34:31 +06:00
print "-------------------------- create Hypothesis"
if (len is not None):
print "-------------------------- LocalLength"
algoReg = mesh.Segment()
hypLength1 = algoReg.LocalLength(len)
2004-12-01 15:48:31 +05:00
print "Hypothesis type : ", hypLength1.GetName()
print "Hypothesis ID : ", hypLength1.GetId()
2004-06-18 14:34:31 +06:00
print "Hypothesis Value: ", hypLength1.GetLength()
if (nbseg is not None):
print "-------------------------- NumberOfSegments"
algoReg = mesh.Segment()
hypNbSeg1 = algoReg.NumberOfSegments(nbseg)
2004-12-01 15:48:31 +05:00
print "Hypothesis type : ", hypNbSeg1.GetName()
print "Hypothesis ID : ", hypNbSeg1.GetId()
2004-06-18 14:34:31 +06:00
print "Hypothesis Value: ", hypNbSeg1.GetNumberOfSegments()
if (area == "LengthFromEdges"):
print "-------------------------- LengthFromEdges"
algoMef = mesh.Triangle()
hypLengthFromEdges = algoMef.LengthFromEdges(1)
2004-12-01 15:48:31 +05:00
print "Hypothesis type : ", hypLengthFromEdges.GetName()
print "Hypothesis ID : ", hypLengthFromEdges.GetId()
2004-06-18 14:34:31 +06:00
print "LengthFromEdges Mode: ", hypLengthFromEdges.GetMode()
else:
print "-------------------------- MaxElementArea"
algoMef = mesh.Triangle()
hypArea1 = algoMef.MaxElementArea(area)
2004-12-01 15:48:31 +05:00
print "Hypothesis type : ", hypArea1.GetName()
print "Hypothesis ID : ", hypArea1.GetId()
2004-06-18 14:34:31 +06:00
print "Hypothesis Value: ", hypArea1.GetMaxElementArea()
print "-------------------------- Regular_1D"
listHyp = algoReg.GetCompatibleHypothesis()
for hyp in listHyp:
print hyp
print "Algo name: ", algoReg.GetName()
2004-12-01 15:48:31 +05:00
print "Algo ID : ", algoReg.GetId()
2004-06-18 14:34:31 +06:00
print "-------------------------- MEFISTO_2D"
2004-12-01 15:48:31 +05:00
listHyp = algoMef.GetCompatibleHypothesis()
2004-06-18 14:34:31 +06:00
for hyp in listHyp:
print hyp
print "Algo name: ", algoMef.GetName()
2004-12-01 15:48:31 +05:00
print "Algo ID : ", algoMef.GetId()
2004-06-18 14:34:31 +06:00
# ---- add hypothesis to shape
print "-------------------------- compute mesh"
ret = mesh.Compute()
2004-06-18 14:34:31 +06:00
print "Compute Mesh .... ",
print ret
2004-12-01 15:48:31 +05:00
log = mesh.GetLog(0); # no erase trace
2004-06-18 14:34:31 +06:00
#for linelog in log:
# print linelog
print "------------ INFORMATION ABOUT MESH ------------"
2004-12-01 15:48:31 +05:00
print "Number of nodes : ", mesh.NbNodes()
print "Number of edges : ", mesh.NbEdges()
print "Number of faces : ", mesh.NbFaces()
2004-06-18 14:34:31 +06:00
print "Number of triangles: ", mesh.NbTriangles()
return mesh