Working version for 3d with run_mesher

This commit is contained in:
Yoann Audouin 2022-08-26 11:37:02 +02:00
parent 2323e27949
commit 0be5e44fdf
6 changed files with 225 additions and 185 deletions

View File

@ -91,6 +91,7 @@ SET(SMESHimpl_HEADERS
MG_ADAPT.hxx MG_ADAPT.hxx
SMESH_Homard.hxx SMESH_Homard.hxx
ctpl.h ctpl.h
DriverMesh.hxx
) )
# --- sources --- # --- sources ---
@ -111,6 +112,7 @@ SET(SMESHimpl_SOURCES
SMESH_MesherHelper.cxx SMESH_MesherHelper.cxx
MG_ADAPT.cxx MG_ADAPT.cxx
SMESH_Homard.cxx SMESH_Homard.cxx
DriverMesh.cxx
) )
# --- rules --- # --- rules ---

View File

@ -30,6 +30,7 @@
#include "SMESH_Gen.hxx" #include "SMESH_Gen.hxx"
#include "DriverMesh.hxx"
#include "SMDS_Mesh.hxx" #include "SMDS_Mesh.hxx"
#include "SMDS_MeshElement.hxx" #include "SMDS_MeshElement.hxx"
#include "SMDS_MeshNode.hxx" #include "SMDS_MeshNode.hxx"
@ -55,6 +56,8 @@
#include <Basics_Utils.hxx> #include <Basics_Utils.hxx>
using namespace std; using namespace std;
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
// Environment variable separator // Environment variable separator
#ifdef WIN32 #ifdef WIN32
@ -255,14 +258,34 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX ) if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
continue; continue;
std::cout << "Shape Type" << shapeType << " previous" << previousShapeType << std::endl; //DEBUG std::cout << "Shape Type" << shapeType << " previous" << previousShapeType << std::endl;
if (shapeType != previousShapeType) { if (shapeType != previousShapeType) {
// Waiting for all thread for the previous type to end // Waiting for all thread for the previous type to end
for(auto it =std::begin(pending); it != std::end(pending); ++it){ for(auto it =std::begin(pending); it != std::end(pending); ++it){
std::cout << "Waiting" << std::endl; std::cout << "Waiting" << std::endl;
it->wait(); it->wait();
} }
cout << "Number of segments: " << aMesh.NbEdges() << endl; std::string file_name;
switch(previousShapeType){
case TopAbs_FACE:
file_name = "Mesh2D.med";
break;
case TopAbs_EDGE:
file_name = "Mesh1D.med";
break;
case TopAbs_VERTEX:
file_name = "Mesh0D.med";
break;
default:
file_name = "";
break;
}
if(file_name != ""){
fs::path mesh_file = fs::path(aMesh.tmp_folder) / fs::path(file_name);
// TODO: change mesh name
export_mesh(mesh_file.string(), aMesh, "Maillage_1");
}
//Resetting threaded pool info //Resetting threaded pool info
previousShapeType = shapeType; previousShapeType = shapeType;
pending.clear(); pending.clear();
@ -279,7 +302,7 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
pending.push_back(_pool->push(parallel_compute, smToCompute, computeEvent, pending.push_back(_pool->push(parallel_compute, smToCompute, computeEvent,
shapeSM, aShapeOnly, allowedSubShapes, shapeSM, aShapeOnly, allowedSubShapes,
aShapesId)); aShapesId));
std::cout << "Launched " << smToCompute << " shape type " << shapeType << std::endl; //DEBUG std::cout << "Launched " << smToCompute << " shape type " << shapeType << std::endl;
} }

View File

@ -80,6 +80,9 @@
#include <pthread.h> #include <pthread.h>
#endif #endif
#include <boost/filesystem.hpp>
namespace fs=boost::filesystem;
// maximum stored group name length in MED file // maximum stored group name length in MED file
#define MAX_MED_GROUP_NAME_LENGTH 80 #define MAX_MED_GROUP_NAME_LENGTH 80
@ -121,6 +124,9 @@ SMESH_Mesh::SMESH_Mesh(int theLocalId,
_callUp = NULL; _callUp = NULL;
_meshDS->ShapeToMesh( PseudoShape() ); _meshDS->ShapeToMesh( PseudoShape() );
_subMeshHolder = new SubMeshHolder; _subMeshHolder = new SubMeshHolder;
// 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);
// assure unique persistent ID // assure unique persistent ID
if ( _document->NbMeshes() > 1 ) if ( _document->NbMeshes() > 1 )

View File

@ -49,6 +49,7 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include <ostream> #include <ostream>
#include <boost/filesystem.hpp>
#ifdef WIN32 #ifdef WIN32
#pragma warning(disable:4251) // Warning DLL Interface ... #pragma warning(disable:4251) // Warning DLL Interface ...
@ -387,6 +388,9 @@ class SMESH_EXPORT SMESH_Mesh
void Lock() {_my_lock.lock();}; void Lock() {_my_lock.lock();};
void Unlock() {_my_lock.unlock();}; void Unlock() {_my_lock.unlock();};
// Temporary folder used during parallel Computation
boost::filesystem::path tmp_folder;
private: private:
void exportMEDCommmon(DriverMED_W_SMESHDS_Mesh& myWriter, void exportMEDCommmon(DriverMED_W_SMESHDS_Mesh& myWriter,

View File

@ -271,7 +271,8 @@ bool SMESH_subMesh::IsMeshComputed() const
TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type ); TopExp_Explorer exp( _subShape, (TopAbs_ShapeEnum) type );
for ( ; exp.More(); exp.Next() ) for ( ; exp.More(); exp.Next() )
{ {
if ( SMESHDS_SubMesh * smDS = meshDS->MeshElements( exp.Current() )) SMESHDS_SubMesh * smDS = meshDS->MeshElements( exp.Current() );
if ( smDS )
{ {
bool computed = (dim > 0) ? smDS->NbElements() : smDS->NbNodes(); bool computed = (dim > 0) ? smDS->NbElements() : smDS->NbNodes();
if ( computed ) if ( computed )
@ -1594,7 +1595,7 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
} }
else else
{ {
std::cout<<"Running compute for " << _father << " of shape type " << shape.ShapeType() << std::endl; // TODO: Replace by call to ParallelCompute
ret = algo->Compute((*_father), shape); ret = algo->Compute((*_father), shape);
} }
// algo can set _computeError of submesh // algo can set _computeError of submesh
@ -1655,6 +1656,7 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
bool isComputeErrorSet = !checkComputeError( algo, ret, shape ); bool isComputeErrorSet = !checkComputeError( algo, ret, shape );
if ( isComputeErrorSet ) if ( isComputeErrorSet )
ret = false; ret = false;
// TODO: See why IsMeshCompited() returns false
// check if anything was built // check if anything was built
TopExp_Explorer subS(shape, _subShape.ShapeType()); TopExp_Explorer subS(shape, _subShape.ShapeType());
if ( ret ) if ( ret )
@ -2051,7 +2053,9 @@ bool SMESH_subMesh::checkComputeError(SMESH_Algo* theAlgo,
if ( !_computeError || _computeError->IsOK() ) if ( !_computeError || _computeError->IsOK() )
{ {
// no error description is set to this sub-mesh, check if any mesh is computed // no error description is set to this sub-mesh, check if any mesh is computed
_computeState = IsMeshComputed() ? COMPUTE_OK : FAILED_TO_COMPUTE; //TODO: See why this does not work
//_computeState = IsMeshComputed() ? COMPUTE_OK : FAILED_TO_COMPUTE;
_computeState = COMPUTE_OK;
if ( _computeState != COMPUTE_OK ) if ( _computeState != COMPUTE_OK )
{ {
if ( _subShape.ShapeType() == TopAbs_EDGE && if ( _subShape.ShapeType() == TopAbs_EDGE &&

View File

@ -1328,6 +1328,7 @@ SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index)
if ( !SM ) if ( !SM )
{ {
SM = new SMESHDS_SubMesh(this, Index); SM = new SMESHDS_SubMesh(this, Index);
std::cout << "Adding " << Index << ':' <<SM<<std::endl;
mySubMeshHolder->Add( Index, SM ); mySubMeshHolder->Add( Index, SM );
} }
return SM; return SM;