Parallel version for 1d mesher number of segment

This commit is contained in:
Yoann Audouin 2022-07-25 10:35:21 +02:00
parent 6a94434123
commit 2323e27949
5 changed files with 80 additions and 24 deletions

View File

@ -281,6 +281,9 @@ SMESH_Algo::GetUsedHypothesis(SMESH_Mesh & aMesh,
if ( _usedHypList == savedHyps ) if ( _usedHypList == savedHyps )
savedHyps.swap( me->_usedHypList ); savedHyps.swap( me->_usedHypList );
for(auto hyp:_usedHypList){
std::cout << hyp << std::endl;
}
return _usedHypList; return _usedHypList;
} }

View File

@ -262,6 +262,7 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
std::cout << "Waiting" << std::endl; std::cout << "Waiting" << std::endl;
it->wait(); it->wait();
} }
cout << "Number of segments: " << aMesh.NbEdges() << endl;
//Resetting threaded pool info //Resetting threaded pool info
previousShapeType = shapeType; previousShapeType = shapeType;
pending.clear(); pending.clear();

View File

@ -65,6 +65,7 @@ using namespace std;
//#define PRINT_WHO_COMPUTE_WHAT //#define PRINT_WHO_COMPUTE_WHAT
#endif #endif
#define PRINT_WHO_COMPUTE_WHAT
//============================================================================= //=============================================================================
/*! /*!
* \brief Allocate some memory at construction and release it at destruction. * \brief Allocate some memory at construction and release it at destruction.
@ -206,6 +207,20 @@ SMESH_Algo* SMESH_subMesh::GetAlgo() const
return _algo; return _algo;
} }
//================================================================================
/*!
* \brief Returns a current algorithm
*/
//================================================================================
SMESH_Algo* SMESH_subMesh::CopyAlgo() const
{
//SMESH_Algo* algo = (SMESH_Algo*) new StdMeshers_Regular_1D(666, _father->GetGent());
SMESH_Algo* algo;
return algo;
}
//================================================================================ //================================================================================
/*! /*!
* \brief Allow algo->Compute() if a sub-shape of lower dim is meshed but * \brief Allow algo->Compute() if a sub-shape of lower dim is meshed but
@ -1392,6 +1407,7 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
else if (( event == COMPUTE || event == COMPUTE_SUBMESH ) else if (( event == COMPUTE || event == COMPUTE_SUBMESH )
&& !_alwaysComputed ) && !_alwaysComputed )
{ {
// LOCK: Adding node to mesh
_father->Lock(); _father->Lock();
const TopoDS_Vertex & V = TopoDS::Vertex( _subShape ); const TopoDS_Vertex & V = TopoDS::Vertex( _subShape );
gp_Pnt P = BRep_Tool::Pnt(V); gp_Pnt P = BRep_Tool::Pnt(V);
@ -1400,6 +1416,7 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
_computeState = COMPUTE_OK; _computeState = COMPUTE_OK;
} }
_father->Unlock(); _father->Unlock();
// UNLOCK
} }
if ( event == MODIF_ALGO_STATE ) if ( event == MODIF_ALGO_STATE )
cleanDependants(); cleanDependants();
@ -1502,10 +1519,13 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
case COMPUTE: case COMPUTE:
case COMPUTE_SUBMESH: case COMPUTE_SUBMESH:
{ {
_father->Lock();
algo = GetAlgo(); algo = GetAlgo();
SMESH_Algo* algo2 = CopyAlgo();
cout << "Algo2" << algo2;
ASSERT(algo); ASSERT(algo);
ret = algo->CheckHypothesis((*_father), _subShape, hyp_status); //_father->Lock();
//ret = algo->CheckHypothesis((*_father), _subShape, hyp_status);
//_father->Unlock();
if (!ret) if (!ret)
{ {
MESSAGE("***** verify compute state *****"); MESSAGE("***** verify compute state *****");
@ -1516,7 +1536,9 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
TopoDS_Shape shape = _subShape; TopoDS_Shape shape = _subShape;
algo->SubMeshesToCompute().assign( 1, this ); algo->SubMeshesToCompute().assign( 1, this );
// check submeshes needed // check submeshes needed
if (_father->HasShapeToMesh() ) { // Forcing to false for parallel run
// TODO: Remove forced false
if (_father->HasShapeToMesh() && false) {
bool subComputed = false, subFailed = false; bool subComputed = false, subFailed = false;
if (!algo->OnlyUnaryInput()) { if (!algo->OnlyUnaryInput()) {
// --- commented for bos#22320 to compute all sub-shapes at once if possible; // --- commented for bos#22320 to compute all sub-shapes at once if possible;
@ -1544,7 +1566,6 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
break; // goto exit break; // goto exit
} }
} }
_father->Unlock();
// Compute // Compute
// to restore cout that may be redirected by algo // to restore cout that may be redirected by algo
@ -1647,8 +1668,10 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
#ifdef PRINT_WHO_COMPUTE_WHAT #ifdef PRINT_WHO_COMPUTE_WHAT
for (subS.ReInit(); subS.More(); subS.Next()) for (subS.ReInit(); subS.More(); subS.Next())
{ {
const std::list <const SMESHDS_Hypothesis *> & hyps = _father->Lock();
const std::list <const SMESHDS_Hypothesis *> hyps =
_algo->GetUsedHypothesis( *_father, _subShape ); _algo->GetUsedHypothesis( *_father, _subShape );
_father->Unlock();
SMESH_Comment hypStr; SMESH_Comment hypStr;
if ( !hyps.empty() ) if ( !hyps.empty() )
{ {
@ -1734,9 +1757,9 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
updateDependantsState( SUBMESH_COMPUTED ); updateDependantsState( SUBMESH_COMPUTED );
} }
// let algo clear its data gathered while algo->Compute() // let algo clear its data gathered while algo->Compute()
_father->Lock(); //_father->Lock();
algo->CheckHypothesis((*_father), _subShape, hyp_status); //algo->CheckHypothesis((*_father), _subShape, hyp_status);
_father->Unlock(); //_father->Unlock();
} }
break; break;
case COMPUTE_CANCELED: // nothing to do case COMPUTE_CANCELED: // nothing to do
@ -2172,8 +2195,10 @@ TopoDS_Shape SMESH_subMesh::getCollection(SMESH_Gen * /*theGen*/,
return _subShape; return _subShape;
const bool skipAuxHyps = false; const bool skipAuxHyps = false;
_father->Lock();
list<const SMESHDS_Hypothesis*> usedHyps = list<const SMESHDS_Hypothesis*> usedHyps =
theAlgo->GetUsedHypothesis( *_father, _subShape, skipAuxHyps ); // copy theAlgo->GetUsedHypothesis( *_father, _subShape, skipAuxHyps ); // copy
_father->Lock();
std::list < TopoDS_Shape > assiShapes = theAlgo->GetAssignedShapes(); std::list < TopoDS_Shape > assiShapes = theAlgo->GetAssignedShapes();
// put in a compound all shapes with the same hypothesis assigned // put in a compound all shapes with the same hypothesis assigned
@ -2201,6 +2226,7 @@ TopoDS_Shape SMESH_subMesh::getCollection(SMESH_Gen * /*theGen*/,
} }
else if ( subMesh->GetComputeState() == READY_TO_COMPUTE ) else if ( subMesh->GetComputeState() == READY_TO_COMPUTE )
{ {
_father->Lock();
SMESH_Algo* anAlgo = subMesh->GetAlgo(); SMESH_Algo* anAlgo = subMesh->GetAlgo();
if (( anAlgo->IsSameName( *theAlgo )) && // same algo if (( anAlgo->IsSameName( *theAlgo )) && // same algo
( anAlgo->GetUsedHypothesis( *_father, S, skipAuxHyps ) == usedHyps ) && // same hyps ( anAlgo->GetUsedHypothesis( *_father, S, skipAuxHyps ) == usedHyps ) && // same hyps
@ -2212,6 +2238,7 @@ TopoDS_Shape SMESH_subMesh::getCollection(SMESH_Gen * /*theGen*/,
theSubComputed = false; theSubComputed = false;
theSubs.push_back( subMesh ); theSubs.push_back( subMesh );
} }
_father->Unlock();
} }
} }

View File

@ -79,6 +79,7 @@ class SMESH_EXPORT SMESH_subMesh
SMESH_subMesh *GetFirstToCompute(); SMESH_subMesh *GetFirstToCompute();
SMESH_Algo* GetAlgo() const; SMESH_Algo* GetAlgo() const;
SMESH_Algo* CopyAlgo() const;
const std::map < int, SMESH_subMesh * >& DependsOn(); const std::map < int, SMESH_subMesh * >& DependsOn();
bool DependsOn( const SMESH_subMesh* other ) const; bool DependsOn( const SMESH_subMesh* other ) const;

View File

@ -126,14 +126,22 @@ bool StdMeshers_Regular_1D::CheckHypothesis( SMESH_Mesh& aMesh,
_onlyUnaryInput = true; _onlyUnaryInput = true;
// check propagation in a redefined GetUsedHypothesis() // check propagation in a redefined GetUsedHypothesis()
const list <const SMESHDS_Hypothesis * > & hyps = const list <const SMESHDS_Hypothesis * > hyps =
GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliaryHyps=*/false); GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliaryHyps=*/false);
const SMESH_HypoFilter & propagFilter = StdMeshers_Propagation::GetFilter(); const SMESH_HypoFilter & propagFilter = StdMeshers_Propagation::GetFilter();
// find non-auxiliary hypothesis // find non-auxiliary hypothesis
const SMESHDS_Hypothesis *theHyp = 0; const SMESHDS_Hypothesis *theHyp = 0;
set< string > propagTypes; set< string > propagTypes;
std::cout << "For shape " << aShape.HashCode(1) << " of type "<< aShape.ShapeType() <<
"CheckHypothesis" << std::endl;
for(auto hyp:hyps){
SMESH_Comment hypStr;
hypStr << hyp << " " << hyp->GetName() << " ";
((SMESHDS_Hypothesis*)hyp)->SaveTo( hypStr.Stream() );
hypStr << " ";
std::cout << hypStr << std::endl;
}
list <const SMESHDS_Hypothesis * >::const_iterator h = hyps.begin(); list <const SMESHDS_Hypothesis * >::const_iterator h = hyps.begin();
for ( ; h != hyps.end(); ++h ) { for ( ; h != hyps.end(); ++h ) {
if ( static_cast<const SMESH_Hypothesis*>(*h)->IsAuxiliary() ) { if ( static_cast<const SMESH_Hypothesis*>(*h)->IsAuxiliary() ) {
@ -848,8 +856,12 @@ bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh & theMesh,
{ {
// Number Of Segments hypothesis // Number Of Segments hypothesis
nbSegments = _ivalue[ NB_SEGMENTS_IND ]; nbSegments = _ivalue[ NB_SEGMENTS_IND ];
if ( nbSegments < 1 ) return false; if ( nbSegments < 1 ) {
if ( nbSegments == 1 ) return true; return false;
}
if ( nbSegments == 1 ) {
return true;
}
switch (_ivalue[ DISTR_TYPE_IND ]) switch (_ivalue[ DISTR_TYPE_IND ])
{ {
@ -1170,10 +1182,16 @@ bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh & theMesh,
bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & theShape) bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & theShape)
{ {
if ( _hypType == NONE ) SMESH_Hypothesis::Hypothesis_Status hyp_status;
theMesh.Lock();
bool ret = this->CheckHypothesis(theMesh, theShape, hyp_status);
int hypType = _hypType;
theMesh.Unlock();
if ( hypType == NONE )
return false; return false;
if ( _hypType == ADAPTIVE ) if ( hypType == ADAPTIVE )
{ {
_adaptiveHyp->GetAlgo()->InitComputeError(); _adaptiveHyp->GetAlgo()->InitComputeError();
_adaptiveHyp->GetAlgo()->Compute( theMesh, theShape ); _adaptiveHyp->GetAlgo()->Compute( theMesh, theShape );
@ -1183,6 +1201,7 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
SMESHDS_Mesh * meshDS = theMesh.GetMeshDS(); SMESHDS_Mesh * meshDS = theMesh.GetMeshDS();
theMesh.Lock(); theMesh.Lock();
const TopoDS_Edge & EE = TopoDS::Edge(theShape); const TopoDS_Edge & EE = TopoDS::Edge(theShape);
TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD)); TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
int shapeID = meshDS->ShapeToIndex( E ); int shapeID = meshDS->ShapeToIndex( E );
@ -1199,6 +1218,7 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
const SMDS_MeshNode * nLast = SMESH_Algo::VertexNode( VLast, meshDS ); const SMDS_MeshNode * nLast = SMESH_Algo::VertexNode( VLast, meshDS );
if ( !nFirst || !nLast ){ if ( !nFirst || !nLast ){
theMesh.Unlock(); theMesh.Unlock();
std::cout << "exit no node" << std::endl;
return error( COMPERR_BAD_INPUT_MESH, "No node on vertex"); return error( COMPERR_BAD_INPUT_MESH, "No node on vertex");
} }
// remove elements created by e.g. pattern mapping (PAL21999) // remove elements created by e.g. pattern mapping (PAL21999)
@ -1232,7 +1252,7 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
// take into account reversing the edge the hypothesis is propagated from // take into account reversing the edge the hypothesis is propagated from
// (_mainEdge.Orientation() marks mutual orientation of EDGEs in propagation chain) // (_mainEdge.Orientation() marks mutual orientation of EDGEs in propagation chain)
reversed = ( _mainEdge.Orientation() == TopAbs_REVERSED ); reversed = ( _mainEdge.Orientation() == TopAbs_REVERSED );
if ( _hypType != DISTRIB_PROPAGATION ) { if ( hypType != DISTRIB_PROPAGATION ) {
int mainID = meshDS->ShapeToIndex(_mainEdge); int mainID = meshDS->ShapeToIndex(_mainEdge);
if ( std::find( _revEdgesIDs.begin(), _revEdgesIDs.end(), mainID) != _revEdgesIDs.end()) if ( std::find( _revEdgesIDs.begin(), _revEdgesIDs.end(), mainID) != _revEdgesIDs.end())
reversed = !reversed; reversed = !reversed;
@ -1245,6 +1265,8 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
BRepAdaptor_Curve C3d( E ); BRepAdaptor_Curve C3d( E );
if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, reversed, true )) { if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, reversed, true )) {
theMesh.Unlock(); theMesh.Unlock();
std::cout << "exit Compute internal failed" << std::endl;
return false; return false;
} }
redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast ); redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
@ -1336,6 +1358,8 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
} }
} }
theMesh.Unlock(); theMesh.Unlock();
std::cout << "exit normal" << std::endl;
return true; return true;
} }