Salome HOME
Generalize "Cancel Compute" mechanism to be able to report
authoreap <eap@opencascade.com>
Fri, 20 Jul 2012 16:13:19 +0000 (16:13 +0000)
committereap <eap@opencascade.com>
Fri, 20 Jul 2012 16:13:19 +0000 (16:13 +0000)
"Computation canceled" instead of "Algorithm failed" as failure reason

+    if ( _computeCanceled ) return false;

src/StdMeshers/StdMeshers_Cartesian_3D.cxx

index b22843958ce647a57ac52b964290dbd3a426d25b..c1e57198fe17fc844001e1a5533358c17b9e3981 100644 (file)
@@ -1610,7 +1610,7 @@ namespace
     intHexInd.resize( nbIntHex );
     tbb::parallel_for ( tbb::blocked_range<size_t>( 0, nbIntHex ),
                         ParallelHexahedron( intersectedHex, intHexInd ),
-                        tbb::simple_partitioner());
+                        tbb::simple_partitioner()); // ComputeElements() is called here
     for ( size_t i = 0; i < intHexInd.size(); ++i )
       if ( Hexahedron * hex = intersectedHex[ intHexInd[ i ]] )
         nbAdded += hex->addElements( helper );
@@ -1636,6 +1636,7 @@ namespace
    */
   int Hexahedron::addElements(SMESH_MesherHelper& helper)
   {
+    int nbAdded = 0;
     // add elements resulted from hexahedron intersection
     //for ( size_t i = 0; i < _volumeDefs.size(); ++i )
     {
@@ -1661,9 +1662,10 @@ namespace
           break;
         }
       }
+      nbAdded += int ( _volumeDefs._nodes.size() > 0 );
     }
 
-    return 1;//(int) _volumeDefs.size();
+    return nbAdded;
   }
   //================================================================================
   /*!
@@ -1915,6 +1917,9 @@ bool StdMeshers_Cartesian_3D::Compute(SMESH_Mesh &         theMesh,
   // - skip a cell, if it is too small according to the size threshold
   // - add a hexahedron in the mesh, if all nodes are inside
   // - add a polyhedron in the mesh, if some nodes are inside and some outside
+
+  _computeCanceled = false;
+
   try
   {
     Grid grid;
@@ -1960,6 +1965,7 @@ bool StdMeshers_Cartesian_3D::Compute(SMESH_Mesh &         theMesh,
 #endif
         }
     }
+    if ( _computeCanceled ) return false;
 
 #ifdef WITH_TBB
     { // copy partner faces and curves of not thread-safe types
@@ -1994,9 +2000,13 @@ bool StdMeshers_Cartesian_3D::Compute(SMESH_Mesh &         theMesh,
     helper.SetSubShape( solidExp.Current() );
     helper.SetElementsOnShape( true );
 
+    if ( _computeCanceled ) return false;
+
     // create nodes on the geometry
     grid.ComputeNodes(helper);
 
+    if ( _computeCanceled ) return false;
+
     // create volume elements
     Hexahedron hex( _hyp->GetSizeThreshold(), &grid );
     int nbAdded = hex.MakeElements( helper );