-class Mesh_Quadrangle(Mesh_Algorithm):
- """
- Class to define a quadrangle 2D algorithm
- """
-
- def __init__(self, mesh, geom=0):
- """
- Private constructor
- """
- self.Create(mesh, geom, "Quadrangle_2D")
-
- def QuadranglePreference(self):
- """
- Define "QuadranglePreference" hypothesis, forcing construction
- of quadrangles if the number of nodes on opposite edges is not the same
- in the case where the global number of nodes on edges is even
- """
- hyp = self.Hypothesis("QuadranglePreference")
- return hyp
-
-# Public class: Mesh_Tetrahedron
-# ------------------------------
-
-class Mesh_Tetrahedron(Mesh_Algorithm):
- """
- Class to define a tetrahedron 3D algorithm
- """
-
- def __init__(self, mesh, algo, geom=0):
- """
- Private constructor
- """
- if algo == NETGEN:
- self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
- elif algo == GHS3D:
- import GHS3DPlugin
- self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
-
- def MaxElementVolume(self, vol):
- """
- Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
- \param vol for the maximum volume of each tetrahedral
- """
- hyp = self.Hypothesis("MaxElementVolume", [vol])
- hyp.SetMaxElementVolume(vol)
- return hyp
-
-# Public class: Mesh_Hexahedron
-# ------------------------------
-
-class Mesh_Hexahedron(Mesh_Algorithm):
- """
- Class to define a hexahedron 3D algorithm
- """
-
- def __init__(self, mesh, geom=0):
- """
- Private constructor
- """
- self.Create(mesh, geom, "Hexa_3D")
-
-# Public class: Mesh
-# ==================
-
-class Mesh:
- """
- Class to define a mesh
- """
-
- geom = 0
- mesh = 0
-
- def __init__(self, geom, name=0):
- """
- Constructor
-
- Creates mesh on the shape \a geom,
- sets GUI name of this mesh to \a name.
- \param geom Shape to be meshed
- \param name Study name of the mesh
- """
- self.geom = geom
- self.mesh = smesh.CreateMesh(geom)
- if name == 0:
- SetName(self.mesh, GetName(geom))
- else:
- SetName(self.mesh, name)
-
- def GetMesh(self):
- """
- Method that returns the mesh
- """
- return self.mesh
-
- def GetShape(self):
- """
- Method that returns the shape associated to the mesh
- """
- return self.geom
-
- def MeshDimension(self):
- """
- Returns mesh dimension depending on shape one
- """
- shells = geompy.SubShapeAllIDs( self.geom, geompy.ShapeType["SHELL"] )
- if len( shells ) > 0 :
- return 3
- elif geompy.NumberOfFaces( self.geom ) > 0 :
- return 2
- elif geompy.NumberOfEdges( self.geom ) > 0 :
- return 1
- else:
- return 0;
- pass
-
- def Segment(self, algo=REGULAR, geom=0):
- """
- Creates a segment discretization 1D algorithm.
- If the optional \a algo parameter is not sets, this algorithm is REGULAR.
- If the optional \a geom parameter is not sets, this algorithm is global.
- Otherwise, this algorithm define a submesh based on \a geom subshape.
- \param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
- \param geom If defined, subshape to be meshed
- """
- ## if Segment(geom) is called by mistake
- if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
- algo, geom = geom, algo
- pass
- if algo == REGULAR:
- return Mesh_Segment(self, geom)
- elif algo == PYTHON:
- return Mesh_Segment_Python(self, geom)
- else:
- return Mesh_Segment(self, geom)
-
- def Triangle(self, geom=0):
- """
- Creates a triangle 2D algorithm for faces.
- If the optional \a geom parameter is not sets, this algorithm is global.
- Otherwise, this algorithm define a submesh based on \a geom subshape.
- \param geom If defined, subshape to be meshed
- """
- return Mesh_Triangle(self, geom)
-
- def Quadrangle(self, geom=0):
- """
- Creates a quadrangle 2D algorithm for faces.
- If the optional \a geom parameter is not sets, this algorithm is global.
- Otherwise, this algorithm define a submesh based on \a geom subshape.
- \param geom If defined, subshape to be meshed
- """
- return Mesh_Quadrangle(self, geom)
-
- def Tetrahedron(self, algo, geom=0):
- """
- Creates a tetrahedron 3D algorithm for solids.
- The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
- If the optional \a geom parameter is not sets, this algorithm is global.
- Otherwise, this algorithm define a submesh based on \a geom subshape.
- \param algo values are: smesh.NETGEN, smesh.GHS3D
- \param geom If defined, subshape to be meshed
- """
- ## if Tetrahedron(geom) is called by mistake
- if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
- algo, geom = geom, algo
- pass
- return Mesh_Tetrahedron(self, algo, geom)
-
- def Hexahedron(self, geom=0):
- """
- Creates a hexahedron 3D algorithm for solids.
- If the optional \a geom parameter is not sets, this algorithm is global.
- Otherwise, this algorithm define a submesh based on \a geom subshape.
- \param geom If defined, subshape to be meshed
- """
- return Mesh_Hexahedron(self, geom)
-
- def Compute(self):
- """
- Compute the mesh and return the status of the computation
- """
- b = smesh.Compute(self.mesh, self.geom)
- if salome.sg.hasDesktop():
- smeshgui = salome.ImportComponentGUI("SMESH")
- smeshgui.Init(salome.myStudyId)
- smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), b )
- salome.sg.updateObjBrowser(1)
- return b
-
- def AutomaticTetrahedralization(self):
- """
- Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
- """
- dim = self.MeshDimension()
- # assign hypotheses
- self.RemoveGlobalHypotheses()
- self.Segment().AutomaticLength()
- if dim > 1 :
- self.Triangle().LengthFromEdges()
- pass
- if dim > 2 :
- self.Tetrahedron(NETGEN)
- pass
- return self.Compute()
-
- def AutomaticHexahedralization(self):
- """
- Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
- """
- dim = self.MeshDimension()
- # assign hypotheses
- self.RemoveGlobalHypotheses()
- self.Segment().AutomaticLength()
- if dim > 1 :
- self.Quadrangle()
- pass
- if dim > 2 :
- self.Hexahedron()
- pass
- return self.Compute()
-
- def RemoveGlobalHypotheses(self):
- """
- Removes all global hypotheses
- """
- current_hyps = self.mesh.GetHypothesisList( self.geom )
- for hyp in current_hyps:
- self.mesh.RemoveHypothesis( self.geom, hyp )
+import geompy
+import SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+#from smeshBuilder import *
+
+# retrieve SMESH engine in try/except block
+# to avoid problems in some cases, e.g. when generating documentation
+try:
+ # get instance of class smeshBuilder
+ engineSmesh = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
+ smesh = smeshBuilder.New(salome.myStudy, engineSmesh)
+except:
+ smesh = None
+ pass
+
+# load plugins and add dynamically generated methods to Mesh class,
+# the same for for global variables declared by plug-ins
+from salome.smesh.smeshBuilder import Mesh, algoCreator
+for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
+ #
+ #print "pluginName: ", pluginName
+ pluginBuilderName = pluginName + "Builder"
+ try:
+ exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
+ except Exception, e:
+ print "Exception while loading %s: %s" % ( pluginBuilderName, e )
+ continue
+ exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
+ plugin = eval( pluginBuilderName )
+
+ # add methods creating algorithms to Mesh
+ for k in dir( plugin ):
+ if k[0] == '_': continue
+ algo = getattr( plugin, k )
+ if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
+ if not hasattr( Mesh, algo.meshMethod ):
+ setattr( Mesh, algo.meshMethod, algoCreator() )
+ pass
+ getattr( Mesh, algo.meshMethod ).add( algo )