#include "SMESH_Gen.hxx"
-#include "DriverMesh.hxx"
#include "SMDS_Mesh.hxx"
#include "SMDS_MeshElement.hxx"
#include "SMDS_MeshNode.hxx"
#include <Basics_Utils.hxx>
using namespace std;
-#include <boost/filesystem.hpp>
-namespace fs = boost::filesystem;
// Environment variable separator
#ifdef WIN32
return aMesh;
}
-//=============================================================================
-/*
- * Parallel compute of a submesh
- * This function is used to pass to thread_pool
- */
-//=============================================================================
-const std::function<void(int,
- SMESH_subMesh*,
- SMESH_subMesh::compute_event,
- SMESH_subMesh*,
- bool,
- TopTools_IndexedMapOfShape *,
- TSetOfInt*)>
- parallel_compute([&] (int id,
- SMESH_subMesh* sm,
- SMESH_subMesh::compute_event event,
- SMESH_subMesh *shapeSM,
- bool aShapeOnly,
- TopTools_IndexedMapOfShape *allowedSubShapes,
- TSetOfInt* aShapesId) -> void
-{
- if (sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
- {
- sm->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
- //setCurrentSubMesh( sm );
- sm->ComputeStateEngine(event);
- //setCurrentSubMesh( nullptr );
- sm->SetAllowedSubShapes( nullptr );
- }
-
- if ( aShapesId )
- aShapesId->insert( sm->GetId() );
-
-});
-
//=============================================================================
/*
* Compute a mesh
const bool complexShapeFirst = true;
const int globalAlgoDim = 100;
- // Pool of thread for computation
- if (!_pool){
- _pool = new ctpl::thread_pool(2);
- }
-
SMESH_subMeshIteratorPtr smIt;
// Fix of Issue 22150. Due to !BLSURF->OnlyUnaryInput(), BLSURF computes edges
// Mesh all the sub-shapes starting from vertices
// ===============================================
- TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX;
smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
- std::vector<std::future<void>> pending;
while ( smIt->more() )
{
SMESH_subMesh* smToCompute = smIt->next();
if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
continue;
- //DEBUG std::cout << "Shape Type" << shapeType << " previous" << previousShapeType << std::endl;
- if (shapeType != previousShapeType) {
- // Waiting for all thread for the previous type to end
- for(auto it =std::begin(pending); it != std::end(pending); ++it){
- std::cout << "Waiting" << std::endl;
- it->wait();
- }
- 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
- previousShapeType = shapeType;
- pending.clear();
- }
-
// check for preview dimension limitations
if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
{
smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
continue;
}
- pending.push_back(_pool->push(parallel_compute, smToCompute, computeEvent,
- shapeSM, aShapeOnly, allowedSubShapes,
- aShapesId));
- //DEBUG std::cout << "Launched " << smToCompute << " shape type " << shapeType << std::endl;
-
- }
+ if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
+ {
+ if (_compute_canceled)
+ return false;
+ smToCompute->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
+ setCurrentSubMesh( smToCompute );
+ smToCompute->ComputeStateEngine( computeEvent );
+ setCurrentSubMesh( nullptr );
+ smToCompute->SetAllowedSubShapes( nullptr );
+ }
- for(auto it =std::begin(pending); it != std::end(pending); ++it){
- it->wait();
+ // we check all the sub-meshes here and detect if any of them failed to compute
+ if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
+ ( shapeType != TopAbs_EDGE || !SMESH_Algo::isDegenerated( TopoDS::Edge( shape ))))
+ ret = false;
+ else if ( aShapesId )
+ aShapesId->insert( smToCompute->GetId() );
}
- pending.clear();
//aMesh.GetMeshDS()->Modified();
return ret;
}
const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
const int aShapeDim = GetShapeDim( aSubShape );
if ( aShapeDim < 1 ) break;
-
+
SMESH_Algo* algo = GetAlgo( smToCompute );
if ( algo && !algo->NeedDiscreteBoundary() ) {
if ( algo->SupportSubmeshes() ) {