Salome HOME
Working version of Sequential/Parallel Mesh class
[modules/smesh.git] / src / SMESH_SWIG / smeshBuilder.py
index 972a4507cfd320f06247840433c9b4a1116cc7b9..1b84f446216787a73d3ad3aea86d8bdfcaa0de98 100644 (file)
@@ -1592,7 +1592,7 @@ class Mesh(metaclass = MeshMeta):
     mesh = 0
     editor = 0
 
-    def __init__(self, smeshpyD, geompyD, obj=0, name=0):
+    def __init__(self, smeshpyD, geompyD, obj=0, name=0, parallel=False):
 
         """
         Constructor
@@ -1625,7 +1625,10 @@ class Mesh(metaclass = MeshMeta):
                     else:
                         geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
                     geompyD.addToStudy( self.geom, geo_name )
-                self.SetMesh( self.smeshpyD.CreateMesh(self.geom) )
+                if parallel and isinstance(self, ParallelMesh):
+                    self.SetMesh( self.smeshpyD.CreateParallelMesh(self.geom) )
+                else:
+                    self.SetMesh( self.smeshpyD.CreateMesh(self.geom) )
 
             elif isinstance(obj, SMESH._objref_SMESH_Mesh):
                 self.SetMesh(obj)
@@ -7537,29 +7540,14 @@ class ParallelMesh(Mesh):
     Surcharge on Mesh for parallel computation of a mesh
     """
 
-    def __init__(self, smeshpyD, geompyD, geom, param, nbThreads, name=0):
+    def __split_geom(self, geompyD, geom):
         """
-        Create a parallel mesh.
+        Splitting geometry into n solids and a 2D/1D compound
 
         Parameters:
             geom: geometrical object for meshing
-            param: full mesh parameters
-            nbThreads: Number of threads for parallelisation.
-            name: the name for the new mesh.
 
-        Returns:
-            an instance of class :class:`ParallelMesh`.
         """
-
-        if not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
-            raise ValueError("geom argument must be a geometry")
-
-        if not isinstance(param, NETGENPlugin._objref_NETGENPlugin_Hypothesis):
-            raise ValueError("param must come from NETGENPlugin")
-
-        if nbThreads < 1:
-            raise ValueError("Number of threads must be stricly greater than 1")
-
         # Splitting geometry into 3D elements and all the 2D/1D into one compound
         object_solids = geompyD.ExtractShapes(geom, geompyD.ShapeType["SOLID"],
                                               True)
@@ -7570,6 +7558,9 @@ class ParallelMesh(Mesh):
             isolid += 1
             geompyD.addToStudyInFather( geom, solid, 'Solid_{}'.format(isolid) )
             solids.append(solid)
+        # If geom is a solid ExtractShapes will return nothin in that case geom is the solids
+        if isolid == 0:
+           solids = [geom]
 
         faces = []
         iface = 0
@@ -7590,7 +7581,34 @@ class ParallelMesh(Mesh):
         all_faces = geompyD.MakeGlueFaces(all_faces, 1e-07)
         geompyD.addToStudy(all_faces, 'global2D')
 
-        super(ParallelMesh, self).__init__(smeshpyD, geompyD, geom, name)
+        return all_faces, solids
+
+    def __init__(self, smeshpyD, geompyD, geom, param, nbThreads, name=0):
+        """
+        Create a parallel mesh.
+
+        Parameters:
+            geom: geometrical object for meshing
+            param: full mesh parameters
+            nbThreads: Number of threads for parallelisation.
+            name: the name for the new mesh.
+
+        Returns:
+            an instance of class :class:`ParallelMesh`.
+        """
+
+        if not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
+            raise ValueError("geom argument must be a geometry")
+
+        if not isinstance(param, NETGENPlugin._objref_NETGENPlugin_Hypothesis):
+            raise ValueError("param must come from NETGENPlugin")
+
+        if nbThreads < 1:
+            raise ValueError("Number of threads must be stricly greater than 1")
+
+        all_faces, solids = self.__split_geom(geompyD, geom)
+
+        super(ParallelMesh, self).__init__(smeshpyD, geompyD, geom, name, parallel=True)
 
         self.mesh.SetNbThreads(nbThreads)