Working version of Sequential/Parallel Mesh class

This commit is contained in:
Yoann Audouin 2023-01-10 09:38:52 +01:00
parent 38ce511dfe
commit 0aef1e314f
14 changed files with 348 additions and 140 deletions

View File

@ -242,6 +242,16 @@ module SMESH
SMESH_Mesh CreateMesh( in GEOM::GEOM_Object theObject ) SMESH_Mesh CreateMesh( in GEOM::GEOM_Object theObject )
raises ( SALOME::SALOME_Exception ); 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 * Create an empty mesh object
*/ */

View File

@ -1108,6 +1108,9 @@ module SMESH
long GetId(); long GetId();
}; };
interface SMESH_SequentialMesh:SMESH_Mesh{};
interface SMESH_ParallelMesh:SMESH_Mesh{};
}; };
#endif #endif

View File

@ -27,9 +27,6 @@
// //
//#define CHRONODEF //#define CHRONODEF
// //
#ifndef WIN32
#include <boost/asio.hpp>
#endif
#include "SMESH_Gen.hxx" #include "SMESH_Gen.hxx"
#include "SMESH_DriverMesh.hxx" #include "SMESH_DriverMesh.hxx"
@ -39,6 +36,8 @@
#include "SMESHDS_Document.hxx" #include "SMESHDS_Document.hxx"
#include "SMESH_HypoFilter.hxx" #include "SMESH_HypoFilter.hxx"
#include "SMESH_Mesh.hxx" #include "SMESH_Mesh.hxx"
#include "SMESH_SequentialMesh.hxx"
#include "SMESH_ParallelMesh.hxx"
#include "SMESH_MesherHelper.hxx" #include "SMESH_MesherHelper.hxx"
#include "SMESH_subMesh.hxx" #include "SMESH_subMesh.hxx"
@ -58,6 +57,10 @@
#include <Basics_Utils.hxx> #include <Basics_Utils.hxx>
#ifndef WIN32
#include <boost/asio.hpp>
#endif
using namespace std; using namespace std;
#ifndef WIN32 #ifndef WIN32
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@ -154,7 +157,8 @@ SMESH_Mesh* SMESH_Gen::CreateMesh(bool theIsEmbeddedMode)
Unexpect aCatch(SalomeException); Unexpect aCatch(SalomeException);
// create a new SMESH_mesh object // create a new SMESH_mesh object
SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++, SMESH_Mesh *aMesh = new SMESH_SequentialMesh(
_localId++,
this, this,
theIsEmbeddedMode, theIsEmbeddedMode,
_studyContext->myDocument); _studyContext->myDocument);
@ -163,6 +167,27 @@ SMESH_Mesh* SMESH_Gen::CreateMesh(bool theIsEmbeddedMode)
return aMesh; 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; continue;
// check for preview dimension limitations // 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 // clear compute state not to show previous compute errors
// if preview invoked less dimension less than previous // 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 * 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_subMeshIteratorPtr smIt;
SMESH_subMesh *shapeSM = aMesh.GetSubMesh(aShape); 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; TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX;
int nbThreads = aMesh.GetNbThreads(); int nbThreads = aMesh.GetNbThreads();
MESSAGE("Compute submeshes with threads: " << nbThreads); MESSAGE("Compute submeshes with threads: " << nbThreads);
@ -340,15 +361,14 @@ bool SMESH_Gen::parallelComputeSubMeshes(
if(file_name != "") if(file_name != "")
{ {
fs::path mesh_file = fs::path(aMesh.tmp_folder) / fs::path(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 //Resetting threaded pool info
previousShapeType = shapeType; previousShapeType = shapeType;
} }
// check for preview dimension limitations // 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 // clear compute state not to show previous compute errors
// if preview invoked less dimension less than previous // if preview invoked less dimension less than previous
@ -364,7 +384,6 @@ bool SMESH_Gen::parallelComputeSubMeshes(
aMesh.wait(); aMesh.wait();
aMesh.GetMeshDS()->Modified(); aMesh.GetMeshDS()->Modified();
aMesh.DeleteTmpFolder();
return ret; return ret;
#endif #endif
@ -416,22 +435,14 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
// =============================================== // ===============================================
// Mesh all the sub-shapes starting from vertices // Mesh all the sub-shapes starting from vertices
// =============================================== // ===============================================
if (aMesh.IsParallel()) aMesh.ComputeSubMeshes(
ret = parallelComputeSubMeshes( this,
aMesh, aShape, aDim, aMesh, aShape, aDim,
aShapesId, allowedSubShapes, aShapesId, allowedSubShapes,
computeEvent, computeEvent,
includeSelf, includeSelf,
complexShapeFirst, complexShapeFirst,
aShapeOnly); aShapeOnly);
else
ret = sequentialComputeSubMeshes(
aMesh, aShape, aDim,
aShapesId, allowedSubShapes,
computeEvent,
includeSelf,
complexShapeFirst,
aShapeOnly);
return ret; return ret;
} }

View File

@ -70,6 +70,7 @@ public:
~SMESH_Gen(); ~SMESH_Gen();
SMESH_Mesh* CreateMesh(bool theIsEmbeddedMode); SMESH_Mesh* CreateMesh(bool theIsEmbeddedMode);
SMESH_Mesh* CreateParallelMesh(bool theIsEmbeddedMode);
enum ComputeFlags enum ComputeFlags
{ {
@ -167,9 +168,7 @@ public:
int GetANewId(); int GetANewId();
private: public:
bool parallelComputeSubMeshes( bool parallelComputeSubMeshes(
SMESH_Mesh & aMesh, SMESH_Mesh & aMesh,
const TopoDS_Shape & aShape, const TopoDS_Shape & aShape,
@ -191,6 +190,11 @@ private:
const bool includeSelf, const bool includeSelf,
const bool complexShapeFirst, const bool complexShapeFirst,
const bool aShapeOnly); const bool aShapeOnly);
private:
int _localId; // unique Id of created objects, within SMESH_Gen entity int _localId; // unique Id of created objects, within SMESH_Gen entity
StudyContextStruct* _studyContext; StudyContextStruct* _studyContext;

View File

@ -232,8 +232,6 @@ SMESH_Mesh::~SMESH_Mesh()
int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_meshDS); int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_meshDS);
#endif #endif
} }
if(_pool)
DeletePoolThreads();
} }
//================================================================================ //================================================================================
@ -2564,30 +2562,3 @@ void SMESH_Mesh::getAncestorsSubMeshes (const TopoDS_Shape& theSubSha
// sort submeshes according to stored mesh order // sort submeshes according to stored mesh order
SortByMeshOrder( theSubMeshes ); 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
}

View File

@ -33,6 +33,7 @@
#include "SMESH_ComputeError.hxx" #include "SMESH_ComputeError.hxx"
#include "SMESH_Controls.hxx" #include "SMESH_Controls.hxx"
#include "SMESH_Hypothesis.hxx" #include "SMESH_Hypothesis.hxx"
#include "SMESH_subMesh.hxx"
#include "SMDS_Iterator.hxx" #include "SMDS_Iterator.hxx"
#include "Utils_SALOME_Exception.hxx" #include "Utils_SALOME_Exception.hxx"
@ -72,6 +73,7 @@ class TopoDS_Solid;
class DriverMED_W_SMESHDS_Mesh; class DriverMED_W_SMESHDS_Mesh;
typedef std::set<int> TSetOfInt;
typedef std::list<int> TListOfInt; typedef std::list<int> TListOfInt;
typedef std::list<TListOfInt> TListOfListOfInt; typedef std::list<TListOfInt> TListOfListOfInt;
@ -390,47 +392,33 @@ class SMESH_EXPORT SMESH_Mesh
// Parallel computation functions // Parallel computation functions
#ifdef WIN32 virtual void Lock(){};
virtual void Lock() {}; virtual void Unlock(){};
virtual void Unlock() {};
virtual int GetNbThreads(){return _NbThreads;}; virtual int GetNbThreads(){return 0;};
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 SetNbThreads(long nbThreads){(void) nbThreads;};
virtual void InitPoolThreads(){}; virtual void InitPoolThreads(){std::cout << "Should not pass here" << std::endl;};
virtual void DeletePoolThreads(){}; virtual void DeletePoolThreads(){std::cout << "Should not pass here" << std::endl;};
virtual void wait(){} virtual void wait(){std::cout << "Should not pass here" << std::endl;};
virtual bool IsParallel(){return _NbThreads > 0;} virtual bool IsParallel(){std::cout << "Should not pass here" << std::endl;return false;};
#else
virtual void Lock() {_my_lock.lock();};
virtual void Unlock() {_my_lock.unlock();};
virtual int GetNbThreads(){return _NbThreads;}; virtual bool ComputeSubMeshes(
virtual void SetNbThreads(long nbThreads){_NbThreads=nbThreads;}; 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;};
virtual void InitPoolThreads(){_pool = new boost::asio::thread_pool(_NbThreads);}; // TODO: Remove from SMESH_Mesh
virtual void DeletePoolThreads(){delete _pool;};
virtual void wait(){_pool->join(); DeletePoolThreads(); InitPoolThreads(); }
virtual bool IsParallel(){return _NbThreads > 0;}
#endif
//TODO: to remove only used by ParallelMesh
void CreateTmpFolder();
void DeleteTmpFolder();
// Temporary folder used during parallel Computation
#ifndef WIN32
boost::filesystem::path tmp_folder; boost::filesystem::path tmp_folder;
boost::asio::thread_pool * _pool = nullptr; //thread pool for computation boost::asio::thread_pool * _pool = nullptr; //thread pool for computation
#else
std::string tmp_folder;
bool _pool = false;
#endif
private: private:
void exportMEDCommmon(DriverMED_W_SMESHDS_Mesh& myWriter, void exportMEDCommmon(DriverMED_W_SMESHDS_Mesh& myWriter,

View File

@ -26,3 +26,93 @@
// //
#include "SMESH_ParallelMesh.hxx" #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);
}

View File

@ -29,6 +29,9 @@
#include "SMESH_Mesh.hxx" #include "SMESH_Mesh.hxx"
#include "SMESH_Gen.hxx"
#include "SMESH_subMesh.hxx"
class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh
{ {
public: public:
@ -45,18 +48,26 @@ class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh
int GetNbThreads() override{return _NbThreads;}; int GetNbThreads() override{return _NbThreads;};
void SetNbThreads(long nbThreads) override{_NbThreads=nbThreads;}; void SetNbThreads(long nbThreads) override{_NbThreads=nbThreads;};
void InitPoolThreads() override{_pool = new boost::asio::thread_pool(_NbThreads);}; void InitPoolThreads() override {_pool = new boost::asio::thread_pool(_NbThreads);};
void DeletePoolThreads() override{delete _pool;}; 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 CreateTmpFolder();
void DeleteTmpFolder(); void DeleteTmpFolder();
private: bool ComputeSubMeshes(
boost::filesystem::path tmp_folder; SMESH_Gen* gen,
boost::asio::thread_pool * _pool = nullptr; //thread pool for computation 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 #endif

View File

@ -25,3 +25,44 @@
// Module : SMESH // Module : SMESH
// //
#include "SMESH_SequentialMesh.hxx" #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);
};

View File

@ -29,6 +29,9 @@
#include "SMESH_Mesh.hxx" #include "SMESH_Mesh.hxx"
#include "SMESH_Gen.hxx"
#include "SMESH_subMesh.hxx"
class SMESH_EXPORT SMESH_SequentialMesh: public SMESH_Mesh class SMESH_EXPORT SMESH_SequentialMesh: public SMESH_Mesh
{ {
public: public:
@ -43,12 +46,25 @@ class SMESH_EXPORT SMESH_SequentialMesh: public SMESH_Mesh
void Unlock() override {}; void Unlock() override {};
int GetNbThreads() override {return 0;}; int GetNbThreads() override {return 0;};
void SetNbThreads(long nbThreads) {}; void SetNbThreads(long nbThreads) {(void) nbThreads;};
void InitPoolThreads() override {}; void InitPoolThreads() override {};
void DeletePoolThreads() override {}; void DeletePoolThreads() override {};
void wait() override {}; void wait() override {};
bool IsParallel() override {return false;}; 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 #endif

View File

@ -67,7 +67,7 @@ SET(_link_LIBRARIES
${KERNEL_Registry} ${KERNEL_Registry}
${KERNEL_SalomeHDFPersist} ${KERNEL_SalomeHDFPersist}
${KERNEL_SalomeLifeCycleCORBA} ${KERNEL_SalomeLifeCycleCORBA}
${KERNEL_TOOLSDS} ${KERNEL_TOOLSDS}
${KERNEL_SalomeGenericObj} ${KERNEL_SalomeGenericObj}
${KERNEL_SalomeIDLKERNEL} ${KERNEL_SalomeIDLKERNEL}
${KERNEL_SALOMELocalTrace} ${KERNEL_SALOMELocalTrace}
@ -115,6 +115,8 @@ SET(SMESHEngine_HEADERS
SMESH.hxx SMESH.hxx
MG_ADAPT_i.hxx MG_ADAPT_i.hxx
SMESH_Homard_i.hxx SMESH_Homard_i.hxx
SMESH_SequentialMesh_i.hxx
SMESH_ParallelMesh_i.hxx
) )
# --- sources --- # --- sources ---

View File

@ -107,6 +107,8 @@
#include "SMESH_PythonDump.hxx" #include "SMESH_PythonDump.hxx"
#include "SMESH_ControlsDef.hxx" #include "SMESH_ControlsDef.hxx"
#include <SMESH_BoostTxtArchive.hxx> #include <SMESH_BoostTxtArchive.hxx>
#include <SMESH_SequentialMesh_i.hxx>
#include <SMESH_ParallelMesh_i.hxx>
// to pass CORBA exception through SMESH_TRY // to pass CORBA exception through SMESH_TRY
#define SMY_OWN_CATCH catch( SALOME::SALOME_Exception& se ) { throw se; } #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); Unexpect aCatch(SALOME_SalomeException);
MESSAGE( "SMESH_Gen_i::createMesh" ); 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 ); SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this );
// create a new mesh object // create a new mesh object
MESSAGE("myIsEmbeddedMode " << myIsEmbeddedMode); 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 // activate the CORBA servant of Mesh
SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() ); 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(); 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 * SMESH_Gen_i::CreateEmptyMesh

View File

@ -231,6 +231,9 @@ public:
// Create empty mesh on a shape // Create empty mesh on a shape
SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject ); 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 // Create empty mesh
SMESH::SMESH_Mesh_ptr CreateEmptyMesh(); SMESH::SMESH_Mesh_ptr CreateEmptyMesh();
@ -631,7 +634,7 @@ private:
SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName, SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
const char* theLibName); const char* theLibName);
// Create empty mesh on shape // Create empty mesh on shape
SMESH::SMESH_Mesh_ptr createMesh(); SMESH::SMESH_Mesh_ptr createMesh(bool parallel=false);
// Check mesh icon // Check mesh icon
bool isGeomModifIcon( SMESH::SMESH_Mesh_ptr mesh ); bool isGeomModifIcon( SMESH::SMESH_Mesh_ptr mesh );

View File

@ -1592,7 +1592,7 @@ class Mesh(metaclass = MeshMeta):
mesh = 0 mesh = 0
editor = 0 editor = 0
def __init__(self, smeshpyD, geompyD, obj=0, name=0): def __init__(self, smeshpyD, geompyD, obj=0, name=0, parallel=False):
""" """
Constructor Constructor
@ -1625,7 +1625,10 @@ class Mesh(metaclass = MeshMeta):
else: else:
geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100) geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
geompyD.addToStudy( self.geom, geo_name ) 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): elif isinstance(obj, SMESH._objref_SMESH_Mesh):
self.SetMesh(obj) self.SetMesh(obj)
@ -7537,6 +7540,49 @@ class ParallelMesh(Mesh):
Surcharge on Mesh for parallel computation of a mesh Surcharge on Mesh for parallel computation of a mesh
""" """
def __split_geom(self, geompyD, geom):
"""
Splitting geometry into n solids and a 2D/1D compound
Parameters:
geom: geometrical object for meshing
"""
# Splitting geometry into 3D elements and all the 2D/1D into one compound
object_solids = geompyD.ExtractShapes(geom, geompyD.ShapeType["SOLID"],
True)
solids = []
isolid = 0
for solid in object_solids:
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
for isolid, solid in enumerate(solids):
solid_faces = geompyD.ExtractShapes(solid, geompyD.ShapeType["FACE"],
True)
for face in solid_faces:
faces.append(face)
iface += 1
geompyD.addToStudyInFather(solid, face,
'Face_{}'.format(iface))
# Creating submesh for edges 1D/2D part
all_faces = geompyD.MakeCompound(faces)
geompyD.addToStudy(all_faces, 'Compound_1')
all_faces = geompyD.MakeGlueEdges(all_faces, 1e-07)
all_faces = geompyD.MakeGlueFaces(all_faces, 1e-07)
geompyD.addToStudy(all_faces, 'global2D')
return all_faces, solids
def __init__(self, smeshpyD, geompyD, geom, param, nbThreads, name=0): def __init__(self, smeshpyD, geompyD, geom, param, nbThreads, name=0):
""" """
Create a parallel mesh. Create a parallel mesh.
@ -7560,37 +7606,9 @@ class ParallelMesh(Mesh):
if nbThreads < 1: if nbThreads < 1:
raise ValueError("Number of threads must be stricly greater than 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 all_faces, solids = self.__split_geom(geompyD, geom)
object_solids = geompyD.ExtractShapes(geom, geompyD.ShapeType["SOLID"],
True)
solids = [] super(ParallelMesh, self).__init__(smeshpyD, geompyD, geom, name, parallel=True)
isolid = 0
for solid in object_solids:
isolid += 1
geompyD.addToStudyInFather( geom, solid, 'Solid_{}'.format(isolid) )
solids.append(solid)
faces = []
iface = 0
for isolid, solid in enumerate(solids):
solid_faces = geompyD.ExtractShapes(solid, geompyD.ShapeType["FACE"],
True)
for face in solid_faces:
faces.append(face)
iface += 1
geompyD.addToStudyInFather(solid, face,
'Face_{}'.format(iface))
# Creating submesh for edges 1D/2D part
all_faces = geompyD.MakeCompound(faces)
geompyD.addToStudy(all_faces, 'Compound_1')
all_faces = geompyD.MakeGlueEdges(all_faces, 1e-07)
all_faces = geompyD.MakeGlueFaces(all_faces, 1e-07)
geompyD.addToStudy(all_faces, 'global2D')
super(ParallelMesh, self).__init__(smeshpyD, geompyD, geom, name)
self.mesh.SetNbThreads(nbThreads) self.mesh.SetNbThreads(nbThreads)