Back to index

salome-smesh  6.5.0
Functions
Constructing meshes
Creating meshes
Collaboration diagram for Constructing meshes:

Functions

def smeshDC.smeshDC.Mesh
 Creates an empty Mesh.
def smeshDC.Mesh.__init__
 Constructor.
def smeshDC.Mesh.SetMesh
 Initializes the Mesh object from an instance of SMESH_Mesh interface.
def smeshDC.Mesh.GetMesh
 Returns the mesh, that is an instance of SMESH_Mesh interface.
def smeshDC.Mesh.GetName
 Gets the name of the mesh.
def smeshDC.Mesh.SetName
 Sets a name to the mesh.
def smeshDC.Mesh.GetShape
 Returns the shape associated to the mesh.
def smeshDC.Mesh.SetShape
 Associates the given shape to the mesh (entails the recreation of the mesh)
def smeshDC.Mesh.IsReadyToCompute
 Returns true if the hypotheses are defined well.
def smeshDC.Mesh.GetAlgoState
 Returns errors of hypotheses definition.
def smeshDC.Mesh.GetGeometryByMeshElement
 Returns a geometrical object on which the given element was built.
def smeshDC.Mesh.Compute
 Computes the mesh and returns the status of the computation.
def smeshDC.Mesh.GetMeshOrder
 Return submesh objects list in meshing order.
def smeshDC.Mesh.SetMeshOrder
 Return submesh objects list in meshing order.
def smeshDC.Mesh.Clear
 Removes all nodes and elements.
def smeshDC.Mesh.ClearSubMesh
 Removes all nodes and elements of indicated shape.

Function Documentation

def smeshDC.Mesh.__init__ (   self,
  smeshpyD,
  geompyD,
  obj = 0,
  name = 0 
)

Constructor.

Creates a mesh on the shape obj (or an empty mesh if obj is equal to 0) and sets the GUI name of this mesh to name.

Parameters:
smeshpyDan instance of smeshDC class
geompyDan instance of geompyDC class
objShape to be meshed or SMESH_Mesh object
nameStudy name of the mesh

Definition at line 961 of file smeshDC.py.

00961 
00962     def __init__(self, smeshpyD, geompyD, obj=0, name=0):
00963         self.smeshpyD=smeshpyD
00964         self.geompyD=geompyD
00965         if obj is None:
00966             obj = 0
00967         if obj != 0:
00968             objHasName = True
00969             if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
00970                 self.geom = obj
00971                 # publish geom of mesh (issue 0021122)
00972                 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
00973                     objHasName = False
00974                     studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
00975                     if studyID != geompyD.myStudyId:
00976                         geompyD.init_geom( smeshpyD.GetCurrentStudy())
00977                         pass
00978                     geo_name = "%s_%s_for_meshing"%(self.geom.GetShapeType(), id(self.geom)%100)
00979                     geompyD.addToStudy( self.geom, geo_name )
00980                 self.mesh = self.smeshpyD.CreateMesh(self.geom)
00981 
00982             elif isinstance(obj, SMESH._objref_SMESH_Mesh):
00983                 self.SetMesh(obj)
00984         else:
00985             self.mesh = self.smeshpyD.CreateEmptyMesh()
00986         if name != 0:
00987             self.smeshpyD.SetName(self.mesh, name)
00988         elif obj != 0 and objHasName:
00989             self.smeshpyD.SetName(self.mesh, GetName(obj))
00990 
00991         if not self.geom:
00992             self.geom = self.mesh.GetShapeToMesh()
00993 
00994         self.editor = self.mesh.GetMeshEditor()
00995 
00996         # set self to algoCreator's
00997         for attrName in dir(self):
00998             attr = getattr( self, attrName )
00999             if isinstance( attr, algoCreator ):
01000                 setattr( self, attrName, attr.copy( self ))

def smeshDC.Mesh.Clear (   self)

Removes all nodes and elements.

Definition at line 1250 of file smeshDC.py.

01250 
01251     def Clear(self):
01252         self.mesh.Clear()
01253         if salome.sg.hasDesktop():
01254             smeshgui = salome.ImportComponentGUI("SMESH")
01255             smeshgui.Init(self.mesh.GetStudyId())
01256             smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
01257             salome.sg.updateObjBrowser(1)

def smeshDC.Mesh.ClearSubMesh (   self,
  geomId 
)

Removes all nodes and elements of indicated shape.

Definition at line 1260 of file smeshDC.py.

01260 
01261     def ClearSubMesh(self, geomId):
01262         self.mesh.ClearSubMesh(geomId)
01263         if salome.sg.hasDesktop():
01264             smeshgui = salome.ImportComponentGUI("SMESH")
01265             smeshgui.Init(self.mesh.GetStudyId())
01266             smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
01267             salome.sg.updateObjBrowser(1)

def smeshDC.Mesh.Compute (   self,
  geom = 0,
  discardModifs = False 
)

Computes the mesh and returns the status of the computation.

Parameters:
geomgeomtrical shape on which mesh data should be computed
discardModifsif True and the mesh has been edited since a last total re-compute and that may prevent successful partial re-compute, then the mesh is cleaned before Compute()
Returns:
True or False

Definition at line 1114 of file smeshDC.py.

01114 
01115     def Compute(self, geom=0, discardModifs=False):
01116         if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
01117             if self.geom == 0:
01118                 geom = self.mesh.GetShapeToMesh()
01119             else:
01120                 geom = self.geom
01121         ok = False
01122         try:
01123             if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
01124                 self.mesh.Clear()
01125             ok = self.smeshpyD.Compute(self.mesh, geom)
01126         except SALOME.SALOME_Exception, ex:
01127             print "Mesh computation failed, exception caught:"
01128             print "    ", ex.details.text
01129         except:
01130             import traceback
01131             print "Mesh computation failed, exception caught:"
01132             traceback.print_exc()
01133         if True:#not ok:
01134             allReasons = ""
01135 
01136             # Treat compute errors
01137             computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
01138             for err in computeErrors:
01139                 shapeText = ""
01140                 if self.mesh.HasShapeToMesh():
01141                     try:
01142                         mainIOR  = salome.orb.object_to_string(geom)
01143                         for sname in salome.myStudyManager.GetOpenStudies():
01144                             s = salome.myStudyManager.GetStudyByName(sname)
01145                             if not s: continue
01146                             mainSO = s.FindObjectIOR(mainIOR)
01147                             if not mainSO: continue
01148                             if err.subShapeID == 1:
01149                                 shapeText = ' on "%s"' % mainSO.GetName()
01150                             subIt = s.NewChildIterator(mainSO)
01151                             while subIt.More():
01152                                 subSO = subIt.Value()
01153                                 subIt.Next()
01154                                 obj = subSO.GetObject()
01155                                 if not obj: continue
01156                                 go = obj._narrow( geompyDC.GEOM._objref_GEOM_Object )
01157                                 if not go: continue
01158                                 ids = go.GetSubShapeIndices()
01159                                 if len(ids) == 1 and ids[0] == err.subShapeID:
01160                                     shapeText = ' on "%s"' % subSO.GetName()
01161                                     break
01162                         if not shapeText:
01163                             shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
01164                             if shape:
01165                                 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
01166                             else:
01167                                 shapeText = " on subshape #%s" % (err.subShapeID)
01168                     except:
01169                         shapeText = " on subshape #%s" % (err.subShapeID)
01170                 errText = ""
01171                 stdErrors = ["OK",                 #COMPERR_OK
01172                              "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
01173                              "std::exception",     #COMPERR_STD_EXCEPTION
01174                              "OCC exception",      #COMPERR_OCC_EXCEPTION
01175                              "SALOME exception",   #COMPERR_SLM_EXCEPTION
01176                              "Unknown exception",  #COMPERR_EXCEPTION
01177                              "Memory allocation problem", #COMPERR_MEMORY_PB
01178                              "Algorithm failed",   #COMPERR_ALGO_FAILED
01179                              "Unexpected geometry"]#COMPERR_BAD_SHAPE
01180                 if err.code > 0:
01181                     if err.code < len(stdErrors): errText = stdErrors[err.code]
01182                 else:
01183                     errText = "code %s" % -err.code
01184                 if errText: errText += ". "
01185                 errText += err.comment
01186                 if allReasons != "":allReasons += "\n"
01187                 allReasons += '-  "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
01188                 pass
01189 
01190             # Treat hyp errors
01191             errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
01192             for err in errors:
01193                 if err.isGlobalAlgo:
01194                     glob = "global"
01195                 else:
01196                     glob = "local"
01197                     pass
01198                 dim = err.algoDim
01199                 name = err.algoName
01200                 if len(name) == 0:
01201                     reason = '%s %sD algorithm is missing' % (glob, dim)
01202                 elif err.state == HYP_MISSING:
01203                     reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
01204                               % (glob, dim, name, dim))
01205                 elif err.state == HYP_NOTCONFORM:
01206                     reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
01207                 elif err.state == HYP_BAD_PARAMETER:
01208                     reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
01209                               % ( glob, dim, name ))
01210                 elif err.state == HYP_BAD_GEOMETRY:
01211                     reason = ('%s %sD algorithm "%s" is assigned to mismatching'
01212                               'geometry' % ( glob, dim, name ))
01213                 else:
01214                     reason = "For unknown reason."+\
01215                              " Revise Mesh.Compute() implementation in smeshDC.py!"
01216                     pass
01217                 if allReasons != "":allReasons += "\n"
01218                 allReasons += "-  " + reason
01219                 pass
01220             if not ok or allReasons != "":
01221                 msg = '"' + GetName(self.mesh) + '"'
01222                 if ok: msg += " has been computed with warnings"
01223                 else:  msg += " has not been computed"
01224                 if allReasons != "": msg += ":"
01225                 else:                msg += "."
01226                 print msg
01227                 print allReasons
01228             pass
01229         if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
01230             smeshgui = salome.ImportComponentGUI("SMESH")
01231             smeshgui.Init(self.mesh.GetStudyId())
01232             smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
01233             salome.sg.updateObjBrowser(1)
01234             pass
01235         return ok

Here is the call graph for this function:

Here is the caller graph for this function:

def smeshDC.Mesh.GetAlgoState (   self,
  theSubObject 
)

Returns errors of hypotheses definition.

The list of errors is empty if everything is OK.

Parameters:
theSubObjecta sub-shape of a mesh shape
Returns:
a list of errors

Definition at line 1066 of file smeshDC.py.

01066 
01067     def GetAlgoState(self, theSubObject):
01068         return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)

def smeshDC.Mesh.GetGeometryByMeshElement (   self,
  theElementID,
  theGeomName 
)

Returns a geometrical object on which the given element was built.

The returned geometrical object, if not nil, is either found in the study or published by this method with the given name

Parameters:
theElementIDthe id of the mesh element
theGeomNamethe user-defined name of the geometrical object
Returns:
GEOM::GEOM_Object instance

Definition at line 1076 of file smeshDC.py.

01076 
01077     def GetGeometryByMeshElement(self, theElementID, theGeomName):
01078         return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )

def smeshDC.Mesh.GetMesh (   self)

Returns the mesh, that is an instance of SMESH_Mesh interface.

Returns:
a SMESH_Mesh object

Definition at line 1011 of file smeshDC.py.

01011 
01012     def GetMesh(self):
01013         return self.mesh

Here is the caller graph for this function:

def smeshDC.Mesh.GetMeshOrder (   self)

Return submesh objects list in meshing order.

Returns:
list of list of submesh objects

Definition at line 1239 of file smeshDC.py.

01239 
01240     def GetMeshOrder(self):
01241         return self.mesh.GetMeshOrder()

def smeshDC.Mesh.GetName (   self)

Gets the name of the mesh.

Returns:
the name of the mesh as a string

Definition at line 1017 of file smeshDC.py.

01017 
01018     def GetName(self):
01019         name = GetName(self.GetMesh())
01020         return name

Here is the call graph for this function:

Here is the caller graph for this function:

def smeshDC.Mesh.GetShape (   self)

Returns the shape associated to the mesh.

Returns:
a GEOM_Object

Definition at line 1041 of file smeshDC.py.

01041 
01042     def GetShape(self):
01043         return self.geom

def smeshDC.Mesh.IsReadyToCompute (   self,
  theSubObject 
)

Returns true if the hypotheses are defined well.

Parameters:
theSubObjecta sub-shape of a mesh shape
Returns:
True or False

Definition at line 1058 of file smeshDC.py.

01058 
01059     def IsReadyToCompute(self, theSubObject):
01060         return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)

def smeshDC.smeshDC.Mesh (   self,
  obj = 0,
  name = 0 
)

Creates an empty Mesh.

This mesh can have an underlying geometry.

Parameters:
objthe Geometrical object on which the mesh is built. If not defined, the mesh will have no underlying geometry.
namethe name for the new mesh.
Returns:
an instance of Mesh class.

Definition at line 328 of file smeshDC.py.

00328 
00329     def Mesh(self, obj=0, name=0):
00330         if isinstance(obj,str):
00331             obj,name = name,obj
00332         return Mesh(self,self.geompyD,obj,name)

def smeshDC.Mesh.SetMesh (   self,
  theMesh 
)

Initializes the Mesh object from an instance of SMESH_Mesh interface.

Parameters:
theMesha SMESH_Mesh object

Definition at line 1004 of file smeshDC.py.

01004 
01005     def SetMesh(self, theMesh):
01006         self.mesh = theMesh
01007         self.geom = self.mesh.GetShapeToMesh()

def smeshDC.Mesh.SetMeshOrder (   self,
  submeshes 
)

Return submesh objects list in meshing order.

Returns:
list of list of submesh objects

Definition at line 1245 of file smeshDC.py.

01245 
01246     def SetMeshOrder(self, submeshes):
01247         return self.mesh.SetMeshOrder(submeshes)

def smeshDC.Mesh.SetName (   self,
  name 
)

Sets a name to the mesh.

Parameters:
namea new name of the mesh

Definition at line 1024 of file smeshDC.py.

01024 
01025     def SetName(self, name):
01026         self.smeshpyD.SetName(self.GetMesh(), name)

Here is the call graph for this function:

def smeshDC.Mesh.SetShape (   self,
  geom 
)

Associates the given shape to the mesh (entails the recreation of the mesh)

Parameters:
geomthe shape to be meshed (GEOM_Object)

Definition at line 1047 of file smeshDC.py.

01047 
01048     def SetShape(self, geom):
01049         self.mesh = self.smeshpyD.CreateMesh(geom)