Salome HOME
0020464: EDF 1100 SMESH: Performance issue of the function MoveNode
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.cxx
index d116d5a77afca5bb1c308ff7097f795116512443..d1c66c4e05482ad379dd6220b565d376b175a9d5 100644 (file)
@@ -1395,6 +1395,8 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
     SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
     ASSERT( meshServant );
     if ( meshServant ) {
+      // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
+      meshServant->CheckGeomGroupModif();
       // get local TopoDS_Shape
       TopoDS_Shape myLocShape;
       if(theMesh->HasShapeToMesh())
@@ -1508,10 +1510,10 @@ SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh
              if ( aNbNode > 4 )
                aNbNode /= 2; // do not take into account additional middle nodes
 
-             SMDS_MeshNode* node1 = (SMDS_MeshNode*)face->GetNode( 1 );
-             for ( int nIndx = 1; nIndx <= aNbNode; nIndx++ )
+             SMDS_MeshNode* node1 = (SMDS_MeshNode*)face->GetNode( 0 );
+             for ( int nIndx = 0; nIndx < aNbNode; nIndx++ )
              {
-               SMDS_MeshNode* node2 = (SMDS_MeshNode*)face->GetNode( nIndx < aNbNode ? nIndx+1 : 1 );
+               SMDS_MeshNode* node2 = (SMDS_MeshNode*)face->GetNode( nIndx+1 < aNbNode ? nIndx+1 : 0 );
                if ( setOfEdge.insert( SMESH_TLink ( node1, node2 ) ).second )
                {
                  listOfElemType.push_back( SMDSAbs_Edge );
@@ -1605,6 +1607,84 @@ SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh
   return result._retn();
 }
 
+
+//=============================================================================
+/*!
+ *  SMESH_Gen_i::Evaluate
+ *
+ *  Evaluate mesh on a shape
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
+                                        GEOM::GEOM_Object_ptr theShapeObject)
+//                                     SMESH::long_array& theNbElems)
+     throw ( SALOME::SALOME_Exception )
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Evaluate" );
+
+  if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
+    THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", 
+                                  SALOME::BAD_PARAM );
+
+  if ( CORBA::is_nil( theMesh ) )
+    THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
+                                  SALOME::BAD_PARAM );
+
+  SMESH::long_array_var nbels = new SMESH::long_array;
+  nbels->length(SMESH::Entity_Last);
+  int i = SMESH::Entity_Node;
+  for (; i < SMESH::Entity_Last; i++)
+    nbels[i] = 0;
+
+  // Update Python script
+  TPythonDump() << "theNbElems = " << this << ".Evaluate( "
+                << theMesh << ", " << theShapeObject << ")";
+
+  try {
+    // get mesh servant
+    SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
+    ASSERT( meshServant );
+    if ( meshServant ) {
+      // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
+      meshServant->CheckGeomGroupModif();
+      // get local TopoDS_Shape
+      TopoDS_Shape myLocShape;
+      if(theMesh->HasShapeToMesh())
+        myLocShape = GeomObjectToShape( theShapeObject );
+      else
+        myLocShape = SMESH_Mesh::PseudoShape();
+      // call implementation compute
+      ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
+      MapShapeNbElems aResMap;
+      /*CORBA::Boolean ret =*/ myGen.Evaluate( myLocMesh, myLocShape, aResMap);
+      MapShapeNbElemsItr anIt = aResMap.begin();
+      for(; anIt!=aResMap.end(); anIt++) {
+       const vector<int>& aVec = (*anIt).second;
+       for(i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++) {
+         nbels[i] += aVec[i];
+       }
+      }
+#ifdef _DEBUG_
+      cout<<endl;
+#endif
+      return nbels._retn();
+    }
+  }
+  catch ( std::bad_alloc ) {
+    INFOS( "Evaluate(): lack of memory" );
+  }
+  catch ( SALOME_Exception& S_ex ) {
+    INFOS( "Evaluate(): catch exception "<< S_ex.what() );
+  }
+  catch ( ... ) {
+    INFOS( "Evaluate(): unknown exception " );
+  }
+
+  return nbels._retn();
+}
+
 //================================================================================
 /*!
  * \brief Return geometrical object the given element is built on
@@ -3741,7 +3821,9 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
               // -- Most probably a bad study was saved when there were
               // not fixed bugs in SMDS_MeshInfo
               if ( elemSet.size() < nbElems ) {
+#ifdef _DEBUG_
                 cout << "SMESH_Gen_i::Load(), warning: Node position data is invalid" << endl;
+#endif
                 nbElems = elemSet.size();
               }
               // add elements to submeshes
@@ -3750,8 +3832,13 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
               {
                 int smID = smIDs[ i ];
                 if ( smID == 0 ) continue;
-                ASSERT( smID <= maxID );
                 const SMDS_MeshElement* elem = *iE;
+                if( smID > maxID ) {
+                  // corresponding subshape no longer exists: maybe geom group has been edited
+                  if ( myNewMeshImpl->HasShapeToMesh() )
+                    mySMESHDSMesh->RemoveElement( elem );
+                  continue;
+                }
                 // get or create submesh
                 SMESHDS_SubMesh* & sm = subMeshes[ smID ];
                 if ( ! sm ) {
@@ -3856,28 +3943,28 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
             for ( int iNode = 0; iNode < nbNodes; iNode++ )
             {
               const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
-              ASSERT( node );
+              if ( !node ) continue; // maybe removed while Loading() if geometry changed
               SMDS_PositionPtr aPos = node->GetPosition();
-              ASSERT( aPos )
-                if ( onFace ) {
-                  // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );-- issue 20182
-                  // -- Most probably a bad study was saved when there were
-                  // not fixed bugs in SMDS_MeshInfo
-                  if ( aPos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
-                    SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
-                      ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
-                    fPos->SetUParameter( aUPos[ iNode ]);
-                    fPos->SetVParameter( aVPos[ iNode ]);
-                  }
+              ASSERT( aPos );
+              if ( onFace ) {
+                // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );-- issue 20182
+                // -- Most probably a bad study was saved when there were
+                // not fixed bugs in SMDS_MeshInfo
+                if ( aPos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
+                  SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
+                    ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
+                  fPos->SetUParameter( aUPos[ iNode ]);
+                  fPos->SetVParameter( aVPos[ iNode ]);
                 }
-                else {
-                  // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );-- issue 20182
-                  if ( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE ) {
-                    SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
-                      ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
-                    fPos->SetUParameter( aUPos[ iNode ]);
-                  }
+              }
+              else {
+                // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );-- issue 20182
+                if ( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE ) {
+                  SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
+                    ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
+                  fPos->SetUParameter( aUPos[ iNode ]);
                 }
+              }
             }
           }
           if ( aEids ) delete [] aEids;