]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Working version of Sequential/Parallel Mesh class
authorYoann Audouin <yoann.audouin@edf.fr>
Tue, 10 Jan 2023 08:38:52 +0000 (09:38 +0100)
committerYoann Audouin <yoann.audouin@edf.fr>
Tue, 10 Jan 2023 08:42:09 +0000 (09:42 +0100)
14 files changed:
idl/SMESH_Gen.idl
idl/SMESH_Mesh.idl
src/SMESH/SMESH_Gen.cxx
src/SMESH/SMESH_Gen.hxx
src/SMESH/SMESH_Mesh.cxx
src/SMESH/SMESH_Mesh.hxx
src/SMESH/SMESH_ParallelMesh.cxx
src/SMESH/SMESH_ParallelMesh.hxx
src/SMESH/SMESH_SequentialMesh.cxx
src/SMESH/SMESH_SequentialMesh.hxx
src/SMESH_I/CMakeLists.txt
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Gen_i.hxx
src/SMESH_SWIG/smeshBuilder.py

index a5b48aaa6bf75f81c3e09fd8a28488e0f9a5b8ae..a36e30d3e39457945b8fad057832747472adb85c 100644 (file)
@@ -242,6 +242,16 @@ module SMESH
     SMESH_Mesh CreateMesh( in GEOM::GEOM_Object theObject )
       raises ( SALOME::SALOME_Exception );
 
+    /*!
+     * Create a Mesh object, given a geometry shape.
+     * Mesh is created empty (no points, no elements).
+     * Shape is explored via GEOM_Client to create local copies.
+     * of TopoDS_Shapes and bind CORBA references of shape & subshapes
+     * with TopoDS_Shapes
+     * The mesh is a parallel one
+     */
+    SMESH_Mesh CreateParallelMesh( in GEOM::GEOM_Object theObject )
+      raises ( SALOME::SALOME_Exception );
     /*!
      * Create an empty mesh object
      */
index 7b86361d83a2604744924452312f18e7dd354ca2..d4bc7fb5732eb7a9a1b0e39b2eaa4e7366fe3cd5 100644 (file)
@@ -1108,6 +1108,9 @@ module SMESH
     long GetId();
   };
 
+  interface SMESH_SequentialMesh:SMESH_Mesh{};
+  interface SMESH_ParallelMesh:SMESH_Mesh{};
+
 };
 
 #endif
index bd8098302799dd02da9a79d535955a57b4cef769..48be3b2d72fe6bf601dabe8fd61819003be00147 100644 (file)
@@ -27,9 +27,6 @@
 //
 //#define CHRONODEF
 //
-#ifndef WIN32
-#include <boost/asio.hpp>
-#endif
 #include "SMESH_Gen.hxx"
 
 #include "SMESH_DriverMesh.hxx"
@@ -39,6 +36,8 @@
 #include "SMESHDS_Document.hxx"
 #include "SMESH_HypoFilter.hxx"
 #include "SMESH_Mesh.hxx"
+#include "SMESH_SequentialMesh.hxx"
+#include "SMESH_ParallelMesh.hxx"
 #include "SMESH_MesherHelper.hxx"
 #include "SMESH_subMesh.hxx"
 
 
 #include <Basics_Utils.hxx>
 
+#ifndef WIN32
+#include <boost/asio.hpp>
+#endif
+
 using namespace std;
 #ifndef WIN32
 #include <boost/filesystem.hpp>
@@ -154,7 +157,8 @@ SMESH_Mesh* SMESH_Gen::CreateMesh(bool theIsEmbeddedMode)
   Unexpect aCatch(SalomeException);
 
   // create a new SMESH_mesh object
-  SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
+  SMESH_Mesh *aMesh = new SMESH_SequentialMesh(
+                                     _localId++,
                                      this,
                                      theIsEmbeddedMode,
                                      _studyContext->myDocument);
@@ -163,6 +167,27 @@ SMESH_Mesh* SMESH_Gen::CreateMesh(bool theIsEmbeddedMode)
   return aMesh;
 }
 
+//=============================================================================
+/*!
+ * Creates a parallel mesh in a study.
+ * if (theIsEmbeddedMode) { mesh modification commands are not logged }
+ */
+//=============================================================================
+
+SMESH_Mesh* SMESH_Gen::CreateParallelMesh(bool theIsEmbeddedMode)
+{
+  Unexpect aCatch(SalomeException);
+
+  // create a new SMESH_mesh object
+  SMESH_Mesh *aMesh = new SMESH_ParallelMesh(
+                                     _localId++,
+                                     this,
+                                     theIsEmbeddedMode,
+                                     _studyContext->myDocument);
+  _studyContext->mapMesh[_localId-1] = aMesh;
+
+  return aMesh;
+}
 
 //=============================================================================
 /*!
@@ -200,7 +225,7 @@ bool SMESH_Gen::sequentialComputeSubMeshes(
       continue;
 
     // check for preview dimension limitations
-    if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
+    if ( aShapesId && SMESH_Gen::GetShapeDim( shapeType ) > (int)aDim )
     {
       // clear compute state not to show previous compute errors
       //  if preview invoked less dimension less than previous
@@ -264,6 +289,7 @@ const std::function<void(SMESH_subMesh*,
 
 });
 
+
 //=============================================================================
 /*!
  * Algo to run the computation of all the submeshes of a mesh in parallel
@@ -290,11 +316,6 @@ bool SMESH_Gen::parallelComputeSubMeshes(
   SMESH_subMeshIteratorPtr smIt;
   SMESH_subMesh *shapeSM = aMesh.GetSubMesh(aShape);
 
-  // Pool of thread for computation
-  // TODO: move when parallelMesh created
-  aMesh.InitPoolThreads();
-  aMesh.CreateTmpFolder();
-
   TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX;
   int nbThreads = aMesh.GetNbThreads();
   MESSAGE("Compute submeshes with threads: " << nbThreads);
@@ -340,15 +361,14 @@ bool SMESH_Gen::parallelComputeSubMeshes(
       if(file_name != "")
       {
         fs::path mesh_file = fs::path(aMesh.tmp_folder) / fs::path(file_name);
-       SMESH_DriverMesh::exportMesh(mesh_file.string(), aMesh, "MESH");
-
+             SMESH_DriverMesh::exportMesh(mesh_file.string(), aMesh, "MESH");
       }
       //Resetting threaded pool info
       previousShapeType = shapeType;
     }
 
     // check for preview dimension limitations
-    if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
+    if ( aShapesId && SMESH_Gen::GetShapeDim( shapeType ) > (int)aDim )
     {
       // clear compute state not to show previous compute errors
       //  if preview invoked less dimension less than previous
@@ -364,7 +384,6 @@ bool SMESH_Gen::parallelComputeSubMeshes(
   aMesh.wait();
 
   aMesh.GetMeshDS()->Modified();
-  aMesh.DeleteTmpFolder();
 
   return ret;
 #endif
@@ -416,22 +435,14 @@ bool SMESH_Gen::Compute(SMESH_Mesh &                aMesh,
     // ===============================================
     // Mesh all the sub-shapes starting from vertices
     // ===============================================
-    if (aMesh.IsParallel())
-      ret = parallelComputeSubMeshes(
-              aMesh, aShape, aDim,
-              aShapesId, allowedSubShapes,
-              computeEvent,
-              includeSelf,
-              complexShapeFirst,
-              aShapeOnly);
-    else
-      ret = sequentialComputeSubMeshes(
-              aMesh, aShape, aDim,
-              aShapesId, allowedSubShapes,
-              computeEvent,
-              includeSelf,
-              complexShapeFirst,
-              aShapeOnly);
+    aMesh.ComputeSubMeshes(
+            this,
+            aMesh, aShape, aDim,
+            aShapesId, allowedSubShapes,
+            computeEvent,
+            includeSelf,
+            complexShapeFirst,
+            aShapeOnly);
 
     return ret;
   }
index 94058184e5e83a7af853b3a8b13884bb0484c6e6..40e92ca37e146e330d1a282626b74cda22edc590 100644 (file)
@@ -70,6 +70,7 @@ public:
   ~SMESH_Gen();
 
   SMESH_Mesh* CreateMesh(bool theIsEmbeddedMode);
+  SMESH_Mesh* CreateParallelMesh(bool theIsEmbeddedMode);
 
   enum ComputeFlags
   {
@@ -167,9 +168,7 @@ public:
 
   int GetANewId();
 
-private:
-
-
+public:
   bool parallelComputeSubMeshes(
           SMESH_Mesh & aMesh,
           const TopoDS_Shape & aShape,
@@ -191,6 +190,11 @@ private:
           const bool includeSelf,
           const bool complexShapeFirst,
           const bool aShapeOnly);
+
+private:
+
+
+
   int _localId;                         // unique Id of created objects, within SMESH_Gen entity
   StudyContextStruct* _studyContext;
 
index 0796cbd8a54cdf595dc4e2e414bc98c2ecf5d917..d46e6d83c5fc410b37c0eb063c4fa0c843eb5cdb 100644 (file)
@@ -232,8 +232,6 @@ SMESH_Mesh::~SMESH_Mesh()
     int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_meshDS);
 #endif
   }
-  if(_pool)
-    DeletePoolThreads();
 }
 
 //================================================================================
@@ -2564,30 +2562,3 @@ void SMESH_Mesh::getAncestorsSubMeshes (const TopoDS_Shape&            theSubSha
   // sort submeshes according to stored mesh order
   SortByMeshOrder( theSubMeshes );
 }
-
-
-//=============================================================================
-/*!
- * \brief Build folder for parallel computation
- */
-//=============================================================================
-void SMESH_Mesh::CreateTmpFolder()
-{
-#ifndef WIN32
-  // Temporary folder that will be used by parallel computation
-  tmp_folder = fs::temp_directory_path()/fs::unique_path(fs::path("SMESH_%%%%-%%%%"));
-  fs::create_directories(tmp_folder);
-#endif
-}
-//
-//=============================================================================
-/*!
- * \brief Delete temporary folder used for parallel computation
- */
-//=============================================================================
-void SMESH_Mesh::DeleteTmpFolder()
-{
-#ifndef WIN32
-    fs::remove_all(tmp_folder);
-#endif
-}
index e2e6644fe987bf0ade68ae1e9abaf36fbc1b6140..50f6210a172cea514f013b021b620d67e0f1a411 100644 (file)
@@ -33,6 +33,7 @@
 #include "SMESH_ComputeError.hxx"
 #include "SMESH_Controls.hxx"
 #include "SMESH_Hypothesis.hxx"
+#include "SMESH_subMesh.hxx"
 #include "SMDS_Iterator.hxx"
 
 #include "Utils_SALOME_Exception.hxx"
@@ -72,6 +73,7 @@ class TopoDS_Solid;
 
 class DriverMED_W_SMESHDS_Mesh;
 
+typedef std::set<int> TSetOfInt;
 typedef std::list<int> TListOfInt;
 typedef std::list<TListOfInt> TListOfListOfInt;
 
@@ -390,47 +392,33 @@ class SMESH_EXPORT SMESH_Mesh
 
   // Parallel computation functions
 
-#ifdef WIN32
-  virtual void Lock() {};
-  virtual void Unlock() {};
-
-  virtual int GetNbThreads(){return _NbThreads;};
-  virtual void SetNbThreads(long nbThreads){std::cout << "Warning Parallel Meshing is disabled on Windows it will behave as a slower normal compute" << std::endl;_NbThreads=nbThreads;};
-
-  virtual void InitPoolThreads(){};
-  virtual void DeletePoolThreads(){};
-  virtual void wait(){}
-
-  virtual bool IsParallel(){return _NbThreads > 0;}
-#else
-  virtual void Lock() {_my_lock.lock();};
-  virtual void Unlock() {_my_lock.unlock();};
-
-  virtual int GetNbThreads(){return _NbThreads;};
-  virtual void SetNbThreads(long nbThreads){_NbThreads=nbThreads;};
+  virtual void Lock(){};
+  virtual void Unlock(){};
 
-  virtual void InitPoolThreads(){_pool = new boost::asio::thread_pool(_NbThreads);};
-  virtual void DeletePoolThreads(){delete _pool;};
+  virtual int GetNbThreads(){return 0;};
+  virtual void SetNbThreads(long nbThreads){(void) nbThreads;};
 
-  virtual void wait(){_pool->join(); DeletePoolThreads(); InitPoolThreads(); }
+  virtual void InitPoolThreads(){std::cout << "Should not pass here" << std::endl;};
+  virtual void DeletePoolThreads(){std::cout << "Should not pass here" << std::endl;};
+  virtual void wait(){std::cout << "Should not pass here" << std::endl;};
 
-  virtual bool IsParallel(){return _NbThreads > 0;}
-#endif
+  virtual bool IsParallel(){std::cout << "Should not pass here" << std::endl;return false;};
 
-  //TODO: to remove only used by ParallelMesh
-  void CreateTmpFolder();
-  void DeleteTmpFolder();
+  virtual bool ComputeSubMeshes(
+            SMESH_Gen* gen,
+            SMESH_Mesh & aMesh,
+            const TopoDS_Shape & aShape,
+            const ::MeshDimension       aDim,
+            TSetOfInt*                  aShapesId /*=0*/,
+            TopTools_IndexedMapOfShape* allowedSubShapes,
+            SMESH_subMesh::compute_event &computeEvent,
+            const bool includeSelf,
+            const bool complexShapeFirst,
+            const bool   aShapeOnly){(void) gen;(void) aMesh;(void) aShape;(void) aDim;(void) aShapesId;(void) allowedSubShapes;(void) computeEvent;(void) includeSelf;(void) complexShapeFirst;(void) aShapeOnly;std::cout << "Should not pass here" << std::endl;return false;};
 
-  // Temporary folder used during parallel Computation
-#ifndef WIN32
+  // TODO: Remove from SMESH_Mesh
   boost::filesystem::path tmp_folder;
   boost::asio::thread_pool *     _pool = nullptr; //thread pool for computation
-#else
-  std::string tmp_folder;
-  bool _pool = false;
-#endif
-
-
 private:
 
   void exportMEDCommmon(DriverMED_W_SMESHDS_Mesh& myWriter,
index 3fabf7b389eaaccfa79216d3b5dc41ef64a7e4f1..f90f6bd1b84a87ee2cd1532e272a15409010bced 100644 (file)
 //
 #include "SMESH_ParallelMesh.hxx"
 
+#include "SMESH_Gen.hxx"
+
+#ifdef WIN32
+  #include <windows.h>
+#endif
+
+#ifndef WIN32
+#include <boost/filesystem.hpp>
+namespace fs=boost::filesystem;
+#endif
+
+#ifndef WIN32
+#include <boost/asio.hpp>
+#endif
+
+#include <utilities.h>
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+SMESH_ParallelMesh::SMESH_ParallelMesh(int               theLocalId,
+                       SMESH_Gen*        theGen,
+                       bool              theIsEmbeddedMode,
+                       SMESHDS_Document* theDocument) :SMESH_Mesh(theLocalId,
+                                                                  theGen,
+                                                                  theIsEmbeddedMode,
+                                                                  theDocument)
+{
+  InitPoolThreads();
+  CreateTmpFolder();
+};
+
+SMESH_ParallelMesh::~SMESH_ParallelMesh()
+{
+  DeletePoolThreads();
+  if(!MYDEBUG)
+    DeleteTmpFolder();
+};
+
+
+
+//=============================================================================
+/*!
+ * \brief Build folder for parallel computation
+ */
+//=============================================================================
+void SMESH_ParallelMesh::CreateTmpFolder()
+{
+#ifndef WIN32
+  // Temporary folder that will be used by parallel computation
+  tmp_folder = fs::temp_directory_path()/fs::unique_path(fs::path("SMESH_%%%%-%%%%"));
+  fs::create_directories(tmp_folder);
+#endif
+}
+//
+//=============================================================================
+/*!
+ * \brief Delete temporary folder used for parallel computation
+ */
+//=============================================================================
+void SMESH_ParallelMesh::DeleteTmpFolder()
+{
+#ifndef WIN32
+    fs::remove_all(tmp_folder);
+#endif
+}
+
+bool SMESH_ParallelMesh::ComputeSubMeshes(
+          SMESH_Gen* gen,
+          SMESH_Mesh & aMesh,
+          const TopoDS_Shape & aShape,
+          const ::MeshDimension       aDim,
+          TSetOfInt*                  aShapesId /*=0*/,
+          TopTools_IndexedMapOfShape* allowedSubShapes,
+          SMESH_subMesh::compute_event &computeEvent,
+          const bool includeSelf,
+          const bool complexShapeFirst,
+          const bool   aShapeOnly)
+{
+  return gen->parallelComputeSubMeshes(
+            aMesh, aShape, aDim,
+            aShapesId, allowedSubShapes,
+            computeEvent,
+            includeSelf,
+            complexShapeFirst,
+            aShapeOnly);
+}
index c5938424dc7590df622f24ffa17591394e151675..bb56599cb80bcb0a5dc16853fe7d3cf6b7359ea8 100644 (file)
@@ -29,6 +29,9 @@
 
 #include "SMESH_Mesh.hxx"
 
+#include "SMESH_Gen.hxx"
+#include "SMESH_subMesh.hxx"
+
 class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh
 {
  public:
@@ -45,18 +48,26 @@ class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh
   int GetNbThreads() override{return _NbThreads;};
   void SetNbThreads(long nbThreads) override{_NbThreads=nbThreads;};
 
-  void InitPoolThreads() override{_pool = new boost::asio::thread_pool(_NbThreads);};
-  void DeletePoolThreads() override{delete _pool;};
+  void InitPoolThreads() override {_pool = new boost::asio::thread_pool(_NbThreads);};
+  void DeletePoolThreads() override {delete _pool;};
 
-  void wait() override{_pool->join(); DeletePoolThreads(); InitPoolThreads(); };
+  void wait() override {_pool->join(); DeletePoolThreads(); InitPoolThreads(); };
 
-  bool IsParallel() override{return _NbThreads > 0;};
+  bool IsParallel() override {return _NbThreads > 0;};
 
   void CreateTmpFolder();
   void DeleteTmpFolder();
 
- private:
-  boost::filesystem::path tmp_folder;
-  boost::asio::thread_pool *     _pool = nullptr; //thread pool for computation
+  bool ComputeSubMeshes(
+            SMESH_Gen* gen,
+            SMESH_Mesh & aMesh,
+            const TopoDS_Shape & aShape,
+            const ::MeshDimension       aDim,
+            TSetOfInt*                  aShapesId /*=0*/,
+            TopTools_IndexedMapOfShape* allowedSubShapes,
+            SMESH_subMesh::compute_event &computeEvent,
+            const bool includeSelf,
+            const bool complexShapeFirst,
+            const bool   aShapeOnly) override;
 };
 #endif
index 3b556403f419c6a2ac49db91b1a4f737553b1b96..a619c41cd5de856246d16a1f2d41a487defd8f56 100644 (file)
 //  Module : SMESH
 //
 #include "SMESH_SequentialMesh.hxx"
+
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Iterator.hxx>
+
+#include <utilities.h>
+
+SMESH_SequentialMesh::SMESH_SequentialMesh(int               theLocalId,
+                       SMESH_Gen*        theGen,
+                       bool              theIsEmbeddedMode,
+                       SMESHDS_Document* theDocument) :SMESH_Mesh(theLocalId,
+                                                                  theGen,
+                                                                  theIsEmbeddedMode,
+                                                                  theDocument)
+{
+};
+
+SMESH_SequentialMesh::~SMESH_SequentialMesh()
+{
+};
+
+bool SMESH_SequentialMesh::ComputeSubMeshes(
+          SMESH_Gen* gen,
+          SMESH_Mesh & aMesh,
+          const TopoDS_Shape & aShape,
+          const ::MeshDimension       aDim,
+          TSetOfInt*                  aShapesId /*=0*/,
+          TopTools_IndexedMapOfShape* allowedSubShapes,
+          SMESH_subMesh::compute_event &computeEvent,
+          const bool includeSelf,
+          const bool complexShapeFirst,
+          const bool   aShapeOnly)
+{
+    return gen->sequentialComputeSubMeshes(
+            aMesh, aShape, aDim,
+            aShapesId, allowedSubShapes,
+            computeEvent,
+            includeSelf,
+            complexShapeFirst,
+            aShapeOnly);
+};
index 24bfc82196b111f7a747cbf9205cdea374b0df20..fc31dd0ac71272ade541fe6e4a20842dbfeff138 100644 (file)
@@ -29,6 +29,9 @@
 
 #include "SMESH_Mesh.hxx"
 
+#include "SMESH_Gen.hxx"
+#include "SMESH_subMesh.hxx"
+
 class SMESH_EXPORT SMESH_SequentialMesh: public SMESH_Mesh
 {
  public:
@@ -43,12 +46,25 @@ class SMESH_EXPORT SMESH_SequentialMesh: public SMESH_Mesh
   void Unlock() override {};
 
   int GetNbThreads() override {return 0;};
-  void SetNbThreads(long nbThreads) {};
+  void SetNbThreads(long nbThreads) {(void) nbThreads;};
 
   void InitPoolThreads() override {};
   void DeletePoolThreads() override {};
   void wait() override {};
 
   bool IsParallel() override {return false;};
+
+  bool ComputeSubMeshes (
+            SMESH_Gen* gen,
+            SMESH_Mesh & aMesh,
+            const TopoDS_Shape & aShape,
+            const ::MeshDimension       aDim,
+            TSetOfInt*                  aShapesId /*=0*/,
+            TopTools_IndexedMapOfShape* allowedSubShapes,
+            SMESH_subMesh::compute_event &computeEvent,
+            const bool includeSelf,
+            const bool complexShapeFirst,
+            const bool   aShapeOnly) override;
+
 };
 #endif
index 218cb915e7cdf100cb4716e669479b8f6357b097..f525f022c7a69ddcb0f036c14766e6252353f3a5 100644 (file)
@@ -67,7 +67,7 @@ SET(_link_LIBRARIES
   ${KERNEL_Registry}
   ${KERNEL_SalomeHDFPersist}
   ${KERNEL_SalomeLifeCycleCORBA}
-  ${KERNEL_TOOLSDS}  
+  ${KERNEL_TOOLSDS}
   ${KERNEL_SalomeGenericObj}
   ${KERNEL_SalomeIDLKERNEL}
   ${KERNEL_SALOMELocalTrace}
@@ -115,6 +115,8 @@ SET(SMESHEngine_HEADERS
   SMESH.hxx
   MG_ADAPT_i.hxx
   SMESH_Homard_i.hxx
+  SMESH_SequentialMesh_i.hxx
+  SMESH_ParallelMesh_i.hxx
 )
 
 # --- sources ---
index 32265c51435a7f721af90321bdb6021d7707d6a3..30e8f8f80932140ba7d2f8b5fa1851117475a6db 100644 (file)
 #include "SMESH_PythonDump.hxx"
 #include "SMESH_ControlsDef.hxx"
 #include <SMESH_BoostTxtArchive.hxx>
+#include <SMESH_SequentialMesh_i.hxx>
+#include <SMESH_ParallelMesh_i.hxx>
 
 // to pass CORBA exception through SMESH_TRY
 #define SMY_OWN_CATCH catch( SALOME::SALOME_Exception& se ) { throw se; }
@@ -560,7 +562,7 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName
  */
 //=============================================================================
 
-SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
+SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh(bool parallel /*=false*/)
 {
   Unexpect aCatch(SALOME_SalomeException);
   MESSAGE( "SMESH_Gen_i::createMesh" );
@@ -571,7 +573,11 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
     SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this );
     // create a new mesh object
     MESSAGE("myIsEmbeddedMode " << myIsEmbeddedMode);
-    meshServant->SetImpl( myGen.CreateMesh( myIsEmbeddedMode ));
+    if(parallel) {
+      meshServant->SetImpl( dynamic_cast<SMESH_Mesh*>(myGen.CreateParallelMesh( myIsEmbeddedMode )));
+    }else{
+      meshServant->SetImpl( dynamic_cast<SMESH_Mesh*>(myGen.CreateMesh( myIsEmbeddedMode )));
+    }
 
     // activate the CORBA servant of Mesh
     SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
@@ -1221,6 +1227,40 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObj
   return mesh._retn();
 }
 
+//=============================================================================
+/*!
+ *  SMESH_Gen_i::CreateParallelMesh
+ *
+ *  Create empty parallel mesh on a shape and publish it in the study
+ */
+//=============================================================================
+
+SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateParallelMesh( GEOM::GEOM_Object_ptr theShapeObject )
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateParallelMesh" );
+  // create mesh
+  SMESH::SMESH_Mesh_var mesh = this->createMesh(true);
+  // set shape
+  SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
+  ASSERT( meshServant );
+  meshServant->SetShape( theShapeObject );
+
+  // publish mesh in the study
+  if ( CanPublishInStudy( mesh ) ) {
+    SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
+    aStudyBuilder->NewCommand();  // There is a transaction
+    SALOMEDS::SObject_wrap aSO = PublishMesh( mesh.in() );
+    aStudyBuilder->CommitCommand();
+    if ( !aSO->_is_nil() ) {
+      // Update Python script
+      TPythonDump(this) << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
+    }
+  }
+
+  return mesh._retn();
+}
+
 //=============================================================================
 /*!
  *  SMESH_Gen_i::CreateEmptyMesh
index 822e71f2e51c96ca2a0cf6cdd6d8e9f38e2f8b1f..f793d4f1bb613cc478404639a80835868a966763 100644 (file)
@@ -231,6 +231,9 @@ public:
   // Create empty mesh on a shape
   SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject );
 
+  // Create empty parallel mesh on a shape
+  SMESH::SMESH_Mesh_ptr CreateParallelMesh( GEOM::GEOM_Object_ptr theShapeObject );
+
   // Create empty mesh
   SMESH::SMESH_Mesh_ptr CreateEmptyMesh();
 
@@ -631,7 +634,7 @@ private:
   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
                                                 const char* theLibName);
   // Create empty mesh on shape
-  SMESH::SMESH_Mesh_ptr createMesh();
+  SMESH::SMESH_Mesh_ptr createMesh(bool parallel=false);
 
   // Check mesh icon
   bool isGeomModifIcon( SMESH::SMESH_Mesh_ptr mesh );
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)