Salome HOME
updated copyright message
[modules/smesh.git] / src / SMESH_SWIG / smesh_algorithm.py
index b8c12430e22f397a0e8d6e7fa6b1f9afabd788bd..86797d65e90af488c1cb84c39877612618acfa13 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -31,43 +31,38 @@ class Mesh_Algorithm:
 
     Note:
         This class should not be used directly, it is supposed to be sub-classed
-    for implementing Python API for specific meshing algorithms
+        for implementing Python API for specific meshing algorithms
 
-    For each meshing algorithm, a python class inheriting from class %Mesh_Algorithm
+    For each meshing algorithm, a python class inheriting from class *Mesh_Algorithm*
     should be defined. This descendant class should have two attributes defining the way
-    it is created by class Mesh (see e.g. class :class:`~StdMeshersBuilder.StdMeshersBuilder_Segment`
-    in StdMeshersBuilder package):
+    it is created by class :class:`~smeshBuilder.Mesh` (see e.g. class :class:`~StdMeshersBuilder.StdMeshersBuilder_Segment`):
 
-        - :code:`meshMethod` attribute defines name of method of class smesh.Mesh by calling which the
-                python class of algorithm is created; this method is dynamically added to the smesh.Mesh class
-                in runtime. For example, if in :code:`class MyPlugin_Algorithm` this attribute is defined as
-                ::
+    - :code:`meshMethod` attribute defines name of method of class :class:`~smeshBuilder.Mesh` by calling which the
+      python class of algorithm is created; this method is dynamically added to the :class:`~smeshBuilder.Mesh` class
+      in runtime. For example, if in :code:`class MyPlugin_Algorithm` this attribute is defined as::
 
-                        meshMethod = "MyAlgorithm"
+          meshMethod = "MyAlgorithm"
 
-                then an instance of :code:`MyPlugin_Algorithm` can be created by the direct invocation of the function
-                of smesh.Mesh class:
-                ::
+      then an instance of :code:`MyPlugin_Algorithm` can be created by the direct invocation of the function
+      of :class:`~smeshBuilder.Mesh` class::
     
-                        my_algo = mesh.MyAlgorithm()
+          my_algo = mesh.MyAlgorithm()
     
-        - :code:`algoType` defines type of algorithm and is used mostly to discriminate
-                algorithms that are created by the same method of class smesh.Mesh. For example, if this attribute
-                is specified in :code:`MyPlugin_Algorithm` class as
-                ::
+    - :code:`algoType` defines type of algorithm and is used mostly to discriminate
+      algorithms that are created by the same method of class :class:`~smeshBuilder.Mesh`. For example, if this attribute
+      is specified in :code:`MyPlugin_Algorithm` class as::
     
-                        algoType = "MyPLUGIN"
+          algoType = "MyPLUGIN"
 
-                then it's creation code can be:
-                ::
+      then it's creation code can be::
 
-                        my_algo = mesh.MyAlgorithm(algo="MyPLUGIN")
+          my_algo = mesh.MyAlgorithm(algo="MyPLUGIN")
     """
     
     
     def __init__(self):
         """
-        Private constuctor
+        Private constructor
         """
         self.mesh = None
         self.geom = None
@@ -78,9 +73,10 @@ class Mesh_Algorithm:
     def FindHypothesis (self, hypname, args, CompareMethod, smeshpyD):
         """
         Finds a hypothesis in the study by its type name and parameters.
-        Finds only the hypotheses created in smeshpyD engine.
+        Finds only the hypotheses created in smeshBuilder engine.
+
         Returns: 
-                SMESH.SMESH_Hypothesis
+                :class:`~SMESH.SMESH_Hypothesis`
         """
         study = salome.myStudy
         if not study: return None
@@ -125,7 +121,7 @@ class Mesh_Algorithm:
     def FindAlgorithm (self, algoname, smeshpyD):
         """
         Finds the algorithm in the study by its type name.
-        Finds only the algorithms, which have been created in smeshpyD engine.
+        Finds only the algorithms, which have been created in smeshBuilder engine.
 
         Returns:
                 SMESH.SMESH_Algo
@@ -170,7 +166,7 @@ class Mesh_Algorithm:
     def GetSubMesh(self):
         """
         If the algorithm is global, returns 0; 
-        else returns the submesh associated to this algorithm.
+        else returns the :class:`~SMESH.SMESH_subMesh` associated to this algorithm.
         """
         return self.subm
 
@@ -294,7 +290,8 @@ class Mesh_Algorithm:
         return shape.GetStudyEntry()
 
     def ViscousLayers(self, thickness, numberOfLayers, stretchFactor,
-                      faces=[], isFacesToIgnore=True, extrMethod=StdMeshers.SURF_OFFSET_SMOOTH ):
+                      faces=[], isFacesToIgnore=True,
+                      extrMethod=StdMeshers.SURF_OFFSET_SMOOTH, groupName=""):
         """
         Defines "ViscousLayers" hypothesis to give parameters of layers of prisms to build
         near mesh boundary. This hypothesis can be used by several 3D algorithms:
@@ -323,8 +320,17 @@ class Mesh_Algorithm:
                         - StdMeshers.NODE_OFFSET method extrudes nodes along average normal of
                                 surrounding mesh faces by the layers thickness. Thickness of
                                 layers can be limited to avoid creation of invalid prisms.
+                groupName: name of a group to contain elements of layers. If not provided,
+                           no group is created. The group is created upon mesh generation.
+                           It can be retrieved by calling
+                           ::
+
+                             group = mesh.GetGroupByName( groupName, SMESH.VOLUME )[0]
+
+        Returns:
+                StdMeshers.StdMeshers_ViscousLayers hypothesis
         """
-        
+
         if not isinstance(self.algo, SMESH._objref_SMESH_3D_Algo):
             raise TypeError("ViscousLayers are supported by 3D algorithms only")
         if not "ViscousLayers" in self.GetCompatibleHypothesis():
@@ -334,9 +340,20 @@ class Mesh_Algorithm:
         if faces and isinstance( faces[0], geomBuilder.GEOM._objref_GEOM_Object ):
             faceIDs = []
             for shape in faces:
-                ff = self.mesh.geompyD.SubShapeAll( shape, self.mesh.geompyD.ShapeType["FACE"] )
-                for f in ff:
+                try:
+                  ff = self.mesh.geompyD.SubShapeAll( shape, self.mesh.geompyD.ShapeType["FACE"] )
+                  for f in ff:
                     faceIDs.append( self.mesh.geompyD.GetSubShapeID(self.mesh.geom, f))
+                except:
+                  # try to get the SHAPERSTUDY engine directly, because GetGen does not work because of
+                  # simplification of access in geomBuilder: omniORB.registerObjref
+                  from SHAPERSTUDY_utils import getEngine
+                  gen = getEngine()
+                  if gen:
+                    aShapeOp = gen.GetIShapesOperations()
+                    ff = aShapeOp.ExtractSubShapes( shape, self.mesh.geompyD.ShapeType["FACE"], False)
+                    for f in ff:
+                      faceIDs.append( aShapeOp.GetSubShapeIndex( self.mesh.geom, f ))
             faces = faceIDs
         hyp = self.Hypothesis("ViscousLayers",
                               [thickness, numberOfLayers, stretchFactor, faces, isFacesToIgnore],
@@ -346,15 +363,16 @@ class Mesh_Algorithm:
         hyp.SetStretchFactor( stretchFactor )
         hyp.SetFaces( faces, isFacesToIgnore )
         hyp.SetMethod( extrMethod )
+        hyp.SetGroupName( groupName )
         self.mesh.AddHypothesis( hyp, self.geom )
         return hyp
 
     def ViscousLayers2D(self, thickness, numberOfLayers, stretchFactor,
-                        edges=[], isEdgesToIgnore=True ):
+                        edges=[], isEdgesToIgnore=True,  groupName="" ):
         """
         Defines "ViscousLayers2D" hypothesis to give parameters of layers of quadrilateral
         elements to build near mesh boundary. This hypothesis can be used by several 2D algorithms:
-        NETGEN 2D, NETGEN 1D-2D, Quadrangle (mapping), MEFISTO, MG-CADSurf
+        NETGEN 2D, NETGEN 1D-2D, Quadrangle (mapping), MG-CADSurf
 
         Parameters:
                 thickness: total thickness of layers of quadrilaterals
@@ -365,6 +383,15 @@ class Mesh_Algorithm:
                         the value of **isEdgesToIgnore** parameter.
                 isEdgesToIgnore: if *True*, the Viscous layers are not generated on the
                         edges specified by the previous parameter (**edges**).
+                groupName: name of a group to contain elements of layers. If not provided,
+                        no group is created. The group is created upon mesh generation.
+                        It can be retrieved by calling
+                        ::
+
+                          group = mesh.GetGroupByName( groupName, SMESH.FACE )[0]
+
+        Returns:
+                StdMeshers.StdMeshers_ViscousLayers2D hypothesis
         """
         
         if not isinstance(self.algo, SMESH._objref_SMESH_2D_Algo):
@@ -376,9 +403,20 @@ class Mesh_Algorithm:
         if edges and isinstance( edges[0], geomBuilder.GEOM._objref_GEOM_Object ):
             edgeIDs = []
             for shape in edges:
+              try:
                 ee = self.mesh.geompyD.SubShapeAll( shape, self.mesh.geompyD.ShapeType["EDGE"])
                 for e in ee:
-                    edgeIDs.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, e ))
+                  edgeIDs.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, e ))
+              except:
+                # try to get the SHAPERSTUDY engine directly, because GetGen does not work because of
+                # simplification of access in geomBuilder: omniORB.registerObjref
+                from SHAPERSTUDY_utils import getEngine
+                gen = getEngine()
+                if gen:
+                  aShapeOp = gen.GetIShapesOperations()
+                  ee = aShapeOp.ExtractSubShapes( shape, self.mesh.geompyD.ShapeType["EDGE"], False)
+                  for e in ee:
+                    edgeIDs.append( aShapeOp.GetSubShapeIndex( self.mesh.geom, e ))
             edges = edgeIDs
         hyp = self.Hypothesis("ViscousLayers2D",
                               [thickness, numberOfLayers, stretchFactor, edges, isEdgesToIgnore],
@@ -387,6 +425,7 @@ class Mesh_Algorithm:
         hyp.SetNumberLayers(numberOfLayers)
         hyp.SetStretchFactor(stretchFactor)
         hyp.SetEdges(edges, isEdgesToIgnore)
+        hyp.SetGroupName( groupName )
         self.mesh.AddHypothesis( hyp, self.geom )
         return hyp
 
@@ -396,12 +435,23 @@ class Mesh_Algorithm:
         into a list acceptable to SetReversedEdges() of some 1D hypotheses
         """
         
-        from salome.smesh.smeshBuilder import FirstVertexOnCurve
         resList = []
         geompy = self.mesh.geompyD
         for i in reverseList:
             if isinstance( i, int ):
-                s = geompy.SubShapes(self.mesh.geom, [i])[0]
+                s = geompy.GetSubShape(self.mesh.geom, [i])
+
+                #bos #20082 begin:
+                if s is None and type(self.geom) != geomBuilder.GEOM._objref_GEOM_Object:
+                    # try to get the SHAPERSTUDY engine directly, as GetGen does not work because of
+                    # simplification of access in geomBuilder: omniORB.registerObjref
+                    from SHAPERSTUDY_utils import getEngine
+                    gen = getEngine()
+                    if gen:
+                        aShapeOp = gen.GetIShapesOperations()
+                        s = aShapeOp.GetSubShape(self.mesh.geom, i)
+                #bos #20082 end
+
                 if s.GetShapeType() != geomBuilder.GEOM.EDGE:
                     raise TypeError("Not EDGE index given")
                 resList.append( i )
@@ -421,7 +471,7 @@ class Mesh_Algorithm:
                 if e.GetShapeType() != geomBuilder.GEOM.EDGE or \
                    v.GetShapeType() != geomBuilder.GEOM.VERTEX:
                     raise TypeError("A list item must be a tuple (edge, 1st_vertex_of_edge)")
-                vFirst = FirstVertexOnCurve( self.mesh, e )
+                vFirst = geompy.GetVertexByIndex( e, 0, False )
                 tol    = geompy.Tolerance( vFirst )[-1]
                 if geompy.MinDistance( v, vFirst ) > 1.5*tol:
                     resList.append( geompy.GetSubShapeID(self.mesh.geom, e ))