Salome HOME
54462: Hexa(ijk) fails on a composite block with a degenerated edge (note 0509712)
[modules/smesh.git] / src / StdMeshers / StdMeshers_CompositeHexa_3D.cxx
index cb0512d1ff1ce07bf0df98853a47621bab89125f..3d3a28d6afc0b5f4bd8964ebf1aa23f3be6a3ee1 100644 (file)
@@ -17,7 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-//  SMESH SMESH : implementaion of SMESH idl descriptions
+//  SMESH SMESH : implementation of SMESH idl descriptions
 // File      : StdMeshers_CompositeHexa_3D.cxx
 // Module    : SMESH
 // Created   : Tue Nov 25 11:04:59 2008
@@ -28,6 +28,8 @@
 #include "SMDS_Mesh.hxx"
 #include "SMDS_MeshNode.hxx"
 #include "SMDS_SetIterator.hxx"
+#include "SMESHDS_Mesh.hxx"
+#include "SMESHDS_SubMesh.hxx"
 #include "SMESH_Block.hxx"
 #include "SMESH_Comment.hxx"
 #include "SMESH_ComputeError.hxx"
@@ -83,7 +85,7 @@ enum EAxes{ COO_X=1, COO_Y, COO_Z };
 
 //================================================================================
 /*!
- * \brief Convertor of a pair of integers to a sole index
+ * \brief Converter of a pair of integers to a sole index
  */
 struct _Indexer
 {
@@ -265,8 +267,8 @@ private:
  */
 //================================================================================
 
-StdMeshers_CompositeHexa_3D::StdMeshers_CompositeHexa_3D(int hypId, int studyId, SMESH_Gen* gen)
-  :SMESH_3D_Algo(hypId, studyId, gen)
+StdMeshers_CompositeHexa_3D::StdMeshers_CompositeHexa_3D(int hypId, SMESH_Gen* gen)
+  :SMESH_3D_Algo(hypId, gen)
 {
   _name = "CompositeHexa_3D";
   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);       // 1 bit /shape type
@@ -310,13 +312,15 @@ namespace
     if ( !TopExp::CommonVertex( E1, E2, V )) return false;
 
     const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
-    if ( !n ) return false;
+    if ( !n ) return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
 
     SMESHDS_SubMesh* sm = mesh.GetSubMeshContaining( F )->GetSubMeshDS();
     if ( !sm ) return false;
 
     int nbQuads = 0;
     SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face);
+    if ( !fIt->more() )
+      return SMESH_Algo::IsContinuous( E1, E2 ); // meshed by "composite segment"
     while ( fIt->more() )
     {
       const SMDS_MeshElement* f = fIt->next();
@@ -330,6 +334,28 @@ namespace
     return nbQuads == 2;
   }
 
+  //================================================================================
+  /*!
+   * \brief Return true if a vertex holds a node and this node is used by some quadrangle
+   */
+  //================================================================================
+
+  // bool isMeshedVertex( TopoDS_Vertex&     V,
+  //                      const SMESH_Mesh&  mesh )
+  // {
+  //   const SMDS_MeshNode* n = SMESH_Algo::VertexNode( V, mesh.GetMeshDS() );
+  //   if ( !n ) return false;
+    
+  //   SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator(SMDSAbs_Face);
+  //   while ( fIt->more() )
+  //   {
+  //     const SMDS_MeshElement* f = fIt->next();
+  //     if ( f->NbCornerNodes() == 4 )
+  //       return true;
+  //   }
+  //   return false;
+  // }
+
   //================================================================================
   /*!
    * \brief Finds VERTEXes located at block corners
@@ -562,7 +588,7 @@ bool StdMeshers_CompositeHexa_3D::findBoxFaces( const TopoDS_Shape&    shape,
   if ( !fTop )
     return error(COMPERR_BAD_SHAPE);
 
-  // orient bottom egde of faces along axes of the unit box
+  // orient bottom edge of faces along axes of the unit box
   fBottom->ReverseEdges();
   fBack  ->ReverseEdges();
   fLeft  ->ReverseEdges();
@@ -575,7 +601,7 @@ bool StdMeshers_CompositeHexa_3D::findBoxFaces( const TopoDS_Shape&    shape,
  * \brief Computes hexahedral mesh on a box with composite sides
  *  \param aMesh - mesh to compute
  *  \param aShape - shape to mesh
- *  \retval bool - succes sign
+ *  \retval bool - success sign
  */
 //================================================================================
 
@@ -800,7 +826,7 @@ bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh&         theMesh,
       nbSeg1 += Max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
   }
 
-  // Get an 1D size of a box side ortogonal to lessComplexSide
+  // Get an 1D size of a box side orthogonal to lessComplexSide
   int nbSeg2 = 0;
   _QuadFaceGrid* ortoSide =
     lessComplexSide->FindAdjacentForSide( Q_LEFT, boxFaceContainer, B_UNDEFINED );
@@ -813,7 +839,7 @@ bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh&         theMesh,
       nbSeg2 += Max( nbElems[ SMDSEntity_Edge ], nbElems[ SMDSEntity_Quad_Edge ]);
   }
 
-  // Get an 2D size of a box side ortogonal to lessComplexSide
+  // Get an 2D size of a box side orthogonal to lessComplexSide
   int nbFaces = 0, nbQuadFace = 0;
   list< TopoDS_Face > sideFaces;
   if ( ortoSide->IsComplex() )
@@ -891,14 +917,10 @@ bool _QuadFaceGrid::Init(const TopoDS_Face& f, SMESH_Mesh& mesh)
     while ( !edges.empty()) {
       sideEdges.clear();
       sideEdges.splice( sideEdges.end(), edges, edges.begin());// edges.front()->sideEdges.back()
+      if ( SMESH_Algo::isDegenerated( sideEdges.back() ))
+        continue;
       while ( !edges.empty() ) {
-        if ( SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() )) {
-          sideEdges.splice( sideEdges.end(), edges, edges.begin());
-        }
-        else if ( SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() )) {
-          sideEdges.splice( sideEdges.begin(), edges, --edges.end());
-        }
-        else if ( isContinuousMesh( sideEdges.back(), edges.front(), f, mesh )) {
+        if ( isContinuousMesh( sideEdges.back(), edges.front(), f, mesh )) {
           sideEdges.splice( sideEdges.end(), edges, edges.begin());
         }
         else if ( isContinuousMesh( sideEdges.front(), edges.back(), f, mesh )) {
@@ -1156,7 +1178,7 @@ bool _QuadFaceGrid::LoadGrid( SMESH_Mesh& mesh )
 
   myGrid.resize( myIndexer.size() );
 
-  // strore nodes bound to the bottom edge
+  // store nodes bound to the bottom edge
   mySides.GetSide( Q_BOTTOM )->StoreNodes( mesh, myGrid, myReverse );
 
   // store the rest nodes row by row
@@ -1942,6 +1964,13 @@ bool _FaceSide::StoreNodes(SMESH_Mesh&                   mesh,
                                                 nodes);
     if ( !ok ) return false;
 
+    // skip nodes on VERTEXes not included in faces
+    if ( !nodes.begin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
+      nodes.erase( nodes.begin() );
+    if ( !nodes.empty() &&
+         !nodes.rbegin()->second->GetInverseElementIterator(SMDSAbs_Face)->more() )
+      nodes.erase( --nodes.end() );
+
     bool forward = ( edge->Orientation() == TopAbs_FORWARD );
     if ( reverse ) forward = !forward;
     if ( forward )