-# Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#
# This library is free software; you can redistribute it and/or
# File : smesh.py
# Author : Francis KLOSS, OCC
# Module : SMESH
-
+#
"""
\namespace smesh
\brief Module smesh
REGULAR = 1
PYTHON = 2
COMPOSITE = 3
+SOLE = 0
+SIMPLE = 1
MEFISTO = 3
NETGEN = 4
## Sets a name to the object
def SetName(obj, name):
+ if isinstance( obj, Mesh ):
+ obj = obj.GetMesh()
+ elif isinstance( obj, Mesh_Algorithm ):
+ obj = obj.GetAlgorithm()
ior = salome.orb.object_to_string(obj)
sobj = salome.myStudy.FindObjectIOR(ior)
if not sobj is None:
reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
elif status == HYP_HIDING_ALGO:
reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
+ elif status == HYP_NEED_SHAPE:
+ reason = "Algorithm can't work without shape"
else:
return
hypName = '"' + hypName + '"'
## Sets the current study and Geometry component
# @ingroup l1_auxiliary
def init_smesh(self,theStudy,geompyD):
- self.geompyD=geompyD
- self.SetGeomEngine(geompyD)
- self.SetCurrentStudy(theStudy)
+ self.SetCurrentStudy(theStudy,geompyD)
## Creates an empty Mesh. This mesh can have an underlying geometry.
# @param obj the Geometrical object on which the mesh is built. If not defined,
## Sets the current study
# @ingroup l1_auxiliary
- def SetCurrentStudy( self, theStudy ):
+ def SetCurrentStudy( self, theStudy, geompyD = None ):
#self.SetCurrentStudy(theStudy)
+ if not geompyD:
+ import geompy
+ geompyD = geompy.geom
+ pass
+ self.geompyD=geompyD
+ self.SetGeomEngine(geompyD)
SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
## Gets the current study
aMesh = Mesh(self, self.geompyD, aSmeshMesh)
return aMesh
+ ## Concatenate the given meshes into one mesh.
+ # @return an instance of Mesh class
+ # @param meshes the meshes to combine into one mesh
+ # @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
+ # @param mergeNodesAndElements if true, equal nodes and elements aremerged
+ # @param mergeTolerance tolerance for merging nodes
+ # @param allGroups forces creation of groups of all elements
+ def Concatenate( self, meshes, uniteIdenticalGroups,
+ mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False):
+ if allGroups:
+ aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
+ self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
+ else:
+ aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
+ self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
+ aMesh = Mesh(self, self.geompyD, aSmeshMesh)
+ return aMesh
+
## From SMESH_Gen interface
# @return the list of integer values
# @ingroup l1_auxiliary
elif obj != 0:
SetName(self.mesh, GetName(obj))
+ if not self.geom:
+ self.geom = self.mesh.GetShapeToMesh()
+
self.editor = self.mesh.GetMeshEditor()
## Initializes the Mesh object from an instance of SMESH_Mesh interface
if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
CompareMethod=self.CompareMaxElementArea)
- hyp.SetMaxElementArea(area)
- return hyp
elif self.algoType == NETGEN:
- print "Netgen 1D-2D algo doesn't support this hypothesis"
- return None
+ hyp = self.Parameters(SIMPLE)
+ hyp.SetMaxElementArea(area)
+ return hyp
## Checks if the given "MaxElementArea" hypothesis has the same parameters as the given arguments
def CompareMaxElementArea(self, hyp, args):
hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
return hyp
elif self.algoType == NETGEN:
- print "Netgen 1D-2D algo doesn't support this hypothesis"
- return None
+ hyp = self.Parameters(SIMPLE)
+ hyp.LengthFromEdges()
+ return hyp
## Sets a way to define size of mesh elements to generate.
# @param thePhysicalMesh is: DefaultSize or Custom.
self.params.SetQuadAllowed(toAllow)
return
- ## Defines "Netgen 2D Parameters" hypothesis
+ ## Defines hypothesis having several parameters
#
# @ingroup l3_hypos_netgen
- def Parameters(self):
- # Only for algoType == NETGEN
+ def Parameters(self, which=SOLE):
if self.params:
return self.params
if self.algoType == NETGEN:
- self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
- "libNETGENEngine.so", UseExisting=0)
+ if which == SIMPLE:
+ self.params = self.Hypothesis("NETGEN_SimpleParameters_2D", [],
+ "libNETGENEngine.so", UseExisting=0)
+ else:
+ self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
+ "libNETGENEngine.so", UseExisting=0)
return self.params
elif self.algoType == MEFISTO:
- print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
+ print "Mefisto algo support no multi-parameter hypothesis"
return None
elif self.algoType == NETGEN_2D:
- print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
+ print "NETGEN_2D_ONLY algo support no multi-parameter hypothesis"
print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
return None
elif self.algoType == BLSURF:
self.params = self.Hypothesis("BLSURF_Parameters", [],
"libBLSURFEngine.so", UseExisting=0)
return self.params
+ else:
+ print "Mesh_Triangle with algo type %s does not have such a parameter, check algo type"%self.algoType
return None
## Sets MaxSize
if self.Parameters():
self.params.SetNbSegPerRadius(theVal)
+ ## Sets number of segments overriding value set by SetLocalLength()
+ #
+ # Only for algoType == NETGEN
+ # @ingroup l3_hypos_netgen
+ def SetNumberOfSegments(self, theVal):
+ self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
+
+ ## Sets number of segments overriding value set by SetNumberOfSegments()
+ #
+ # Only for algoType == NETGEN
+ # @ingroup l3_hypos_netgen
+ def SetLocalLength(self, theVal):
+ self.Parameters(SIMPLE).SetLocalLength(theVal)
+
pass
CompareMethod=self.CompareEqualHyp)
return hyp
+ ## Defines "TrianglePreference" hypothesis, forcing construction
+ # of triangles in the refinement area if the number of nodes
+ # on the opposite edges is not the same
+ #
+ # @ingroup l3_hypos_additi
+ def TrianglePreference(self):
+ hyp = self.Hypothesis("TrianglePreference", UseExisting=1,
+ CompareMethod=self.CompareEqualHyp)
+ return hyp
+
# Public class: Mesh_Tetrahedron
# ------------------------------
# the same parameters, else (default) - creates a new one
# @ingroup l3_hypos_maxvol
def MaxElementVolume(self, vol, UseExisting=0):
- hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
- CompareMethod=self.CompareMaxElementVolume)
- hyp.SetMaxElementVolume(vol)
- return hyp
+ if self.algoType == NETGEN:
+ hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
+ CompareMethod=self.CompareMaxElementVolume)
+ hyp.SetMaxElementVolume(vol)
+ return hyp
+ elif self.algoType == FULL_NETGEN:
+ self.Parameters(SIMPLE).SetMaxElementVolume(vol)
+ return None
## Checks if the given "MaxElementVolume" hypothesis has the same parameters as the given arguments
def CompareMaxElementVolume(self, hyp, args):
return IsEqual(hyp.GetMaxElementVolume(), args[0])
- ## Defines "Netgen 3D Parameters" hypothesis
+ ## Defines hypothesis having several parameters
+ #
# @ingroup l3_hypos_netgen
- def Parameters(self):
+ def Parameters(self, which=SOLE):
if self.params:
return self.params
- if (self.algoType == FULL_NETGEN):
- self.params = self.Hypothesis("NETGEN_Parameters", [],
- "libNETGENEngine.so", UseExisting=0)
+ if self.algoType == FULL_NETGEN:
+ if which == SIMPLE:
+ self.params = self.Hypothesis("NETGEN_SimpleParameters_3D", [],
+ "libNETGENEngine.so", UseExisting=0)
+ else:
+ self.params = self.Hypothesis("NETGEN_Parameters", [],
+ "libNETGENEngine.so", UseExisting=0)
return self.params
- if (self.algoType == GHS3D):
+ if self.algoType == GHS3D:
self.params = self.Hypothesis("GHS3D_Parameters", [],
"libGHS3DEngine.so", UseExisting=0)
return self.params
- print "Algo doesn't support this hypothesis"
+ print "Algo supports no multi-parameter hypothesis"
return None
## Sets MaxSize
def SetNbSegPerRadius(self, theVal):
self.Parameters().SetNbSegPerRadius(theVal)
+ ## Sets number of segments overriding value set by SetLocalLength()
+ # Only for algoType == NETGEN_FULL
+ # @ingroup l3_hypos_netgen
+ def SetNumberOfSegments(self, theVal):
+ self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
+
+ ## Sets number of segments overriding value set by SetNumberOfSegments()
+ # Only for algoType == NETGEN_FULL
+ # @ingroup l3_hypos_netgen
+ def SetLocalLength(self, theVal):
+ self.Parameters(SIMPLE).SetLocalLength(theVal)
+
+ ## Defines "MaxElementArea" parameter of NETGEN_SimpleParameters_3D hypothesis.
+ # Overrides value set by LengthFromEdges()
+ # Only for algoType == NETGEN_FULL
+ # @ingroup l3_hypos_netgen
+ def MaxElementArea(self, area):
+ self.Parameters(SIMPLE).SetMaxElementArea(area)
+
+ ## Defines "LengthFromEdges" parameter of NETGEN_SimpleParameters_3D hypothesis
+ # Overrides value set by MaxElementArea()
+ # Only for algoType == NETGEN_FULL
+ # @ingroup l3_hypos_netgen
+ def LengthFromEdges(self):
+ self.Parameters(SIMPLE).LengthFromEdges()
+
+ ## Defines "LengthFromFaces" parameter of NETGEN_SimpleParameters_3D hypothesis
+ # Overrides value set by MaxElementVolume()
+ # Only for algoType == NETGEN_FULL
+ # @ingroup l3_hypos_netgen
+ def LengthFromFaces(self):
+ self.Parameters(SIMPLE).LengthFromFaces()
+
## To mesh "holes" in a solid or not. Default is to mesh.
# @ingroup l3_hypos_ghs3dh
def SetToMeshHoles(self, toMesh):
if not mesh is None and isinstance(mesh, Mesh):
mesh = mesh.GetMesh()
hyp.SetSourceMesh( mesh )
- hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
+ if srcV1 and srcV2 and tgtV1 and tgtV2:
+ hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
+ #elif srcV1 or srcV2 or tgtV1 or tgtV2:
return hyp
## Checks if the given "SourceShape3D" hypothesis has the same parameters as given arguments