Salome HOME
Merge from V5_1_4_BR (5_1_4rc2) 09/06/2010
[modules/smesh.git] / src / StdMeshers / StdMeshers_CompositeHexa_3D.cxx
index d489b3d769ae11a332f7b04cc19234316360765a..24a1e3fa9908b6371221bf9a270e9542a17306ca 100644 (file)
@@ -1,29 +1,28 @@
-//  SMESH SMESH : implementaion of SMESH idl descriptions
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
+//  SMESH SMESH : implementaion of SMESH idl descriptions
 // File      : StdMeshers_CompositeHexa_3D.cxx
 // Module    : SMESH
 // Created   : Tue Nov 25 11:04:59 2008
 // Author    : Edward AGAPOV (eap)
-
+//
 #include "StdMeshers_CompositeHexa_3D.hxx"
 
 #include "SMDS_Mesh.hxx"
@@ -206,7 +205,7 @@ public: //** Access to member fields **//
 
 private:
 
-  bool error(std::string& text, int code = COMPERR_ALGO_FAILED)
+  bool error(const std::string& text, int code = COMPERR_ALGO_FAILED)
   { myError = SMESH_ComputeError::New( code, text ); return false; }
 
   bool error(const SMESH_ComputeErrorPtr& err)
@@ -252,7 +251,7 @@ StdMeshers_CompositeHexa_3D::StdMeshers_CompositeHexa_3D(int hypId, int studyId,
   :SMESH_3D_Algo(hypId, studyId, gen)
 {
   _name = "CompositeHexa_3D";
-  _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);      // 1 bit /shape type
+  _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);       // 1 bit /shape type
 }
 
 //================================================================================
@@ -514,7 +513,7 @@ bool StdMeshers_CompositeHexa_3D::Compute(SMESH_Mesh&         theMesh,
 //purpose  : auxilary for Evaluate
 //=======================================================================
 int GetNb2d(_QuadFaceGrid* QFG, SMESH_Mesh& theMesh,
-           MapShapeNbElems& aResMap)
+            MapShapeNbElems& aResMap)
 {
   int nb2d = 0;
   _QuadFaceGrid::TChildIterator aCI = QFG->GetChildren();
@@ -525,7 +524,7 @@ int GetNb2d(_QuadFaceGrid* QFG, SMESH_Mesh& theMesh,
       MapShapeNbElemsItr anIt = aResMap.find(sm);
       if( anIt == aResMap.end() ) continue;
       std::vector<int> aVec = (*anIt).second;
-      nb2d += Max(aVec[5],aVec[6]);
+      nb2d += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
     }
   }
   return nb2d;
@@ -539,8 +538,8 @@ int GetNb2d(_QuadFaceGrid* QFG, SMESH_Mesh& theMesh,
 //================================================================================
 
 bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh& theMesh,
-                                          const TopoDS_Shape& theShape,
-                                          MapShapeNbElems& aResMap)
+                                           const TopoDS_Shape& theShape,
+                                           MapShapeNbElems& aResMap)
 {
   SMESH_MesherHelper aTool(theMesh);
   bool _quadraticMesh = aTool.IsQuadraticSubMesh(theShape);
@@ -636,22 +635,22 @@ bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh& theMesh,
       int nb0 = 0;
       SMESH_subMesh *sm = theMesh.GetSubMesh(exp.Current());
       if( sm ) {
-       MapShapeNbElemsItr anIt = aResMap.find(sm);
-       if( anIt == aResMap.end() ) continue;
-       std::vector<int> aVec = (*anIt).second;
-       nb0 = aVec[0];
+        MapShapeNbElemsItr anIt = aResMap.find(sm);
+        if( anIt == aResMap.end() ) continue;
+        std::vector<int> aVec = (*anIt).second;
+        nb0 = aVec[SMDSEntity_Node];
       }
       int j = 1;
       for(; j<=BndEdges.Length(); j++) {
-       if( BndEdges.Value(j) == exp.Current() ) {
-         // internal edge => remove it
-         BndEdges.Remove(j);
-         nb0d_in += nb0;
-         break;
-       }
+        if( BndEdges.Value(j) == exp.Current() ) {
+          // internal edge => remove it
+          BndEdges.Remove(j);
+          nb0d_in += nb0;
+          break;
+        }
       }
       if( j > BndEdges.Length() ) {
-       BndEdges.Append(exp.Current());
+        BndEdges.Append(exp.Current());
       }
       //if( BndEdges.Contains(exp.Current()) ) {
       //BndEdges.Remove( exp.Current() );
@@ -670,7 +669,7 @@ bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh& theMesh,
       MapShapeNbElemsItr anIt = aResMap.find(sm);
       if( anIt == aResMap.end() ) continue;
       std::vector<int> aVec = (*anIt).second;
-      nb1d += Max(aVec[1],aVec[2]);
+      nb1d += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
     }
   }
 
@@ -689,24 +688,24 @@ bool StdMeshers_CompositeHexa_3D::Evaluate(SMESH_Mesh& theMesh,
       MapShapeNbElemsItr anIt = aResMap.find(sm);
       if( anIt == aResMap.end() ) continue;
       std::vector<int> aVec = (*anIt).second;
-      nb0d += aVec[0];
-      nb2d_3 += Max(aVec[3],aVec[4]);
-      nb2d_4 += Max(aVec[5],aVec[6]);
+      nb0d += aVec[SMDSEntity_Node];
+      nb2d_3 += Max(aVec[SMDSEntity_Triangle],   aVec[SMDSEntity_Quad_Triangle]);
+      nb2d_4 += Max(aVec[SMDSEntity_Quadrangle], aVec[SMDSEntity_Quad_Quadrangle]);
     }
   }
   nb0d += nb0d_in;
 
-  std::vector<int> aResVec(17);
-  for(int i=0; i<17; i++) aResVec[i] = 0;
+  std::vector<int> aResVec(SMDSEntity_Last);
+  for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aResVec[i] = 0;
   if(_quadraticMesh) {
-    aResVec[13] = nb2d_3 * ( nb2d/nb1d );
-    aResVec[15] = nb2d_4 * ( nb2d/nb1d );
-    aResVec[0] = nb0d * ( 2*nb2d/nb1d - 1 );
+    aResVec[SMDSEntity_Quad_Penta] = nb2d_3 * ( nb2d/nb1d );
+    aResVec[SMDSEntity_Quad_Hexa]  = nb2d_4 * ( nb2d/nb1d );
+    aResVec[SMDSEntity_Node] = nb0d * ( 2*nb2d/nb1d - 1 );
   }
   else {
-    aResVec[0] = nb0d * ( nb2d/nb1d - 1 );
-    aResVec[12] = nb2d_3 * ( nb2d/nb1d );
-    aResVec[14] = nb2d_4 * ( nb2d/nb1d );
+    aResVec[SMDSEntity_Node]  = nb0d * ( nb2d/nb1d - 1 );
+    aResVec[SMDSEntity_Penta] = nb2d_3 * ( nb2d/nb1d );
+    aResVec[SMDSEntity_Hexa]  = nb2d_4 * ( nb2d/nb1d );
   }
   SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
   aResMap.insert(std::make_pair(sm,aResVec));
@@ -988,6 +987,13 @@ bool _QuadFaceGrid::LoadGrid( SMESH_Mesh& mesh )
   if ( !myGrid.empty() )
     return true;
 
+  SMESHDS_SubMesh* faceSubMesh = mesh.GetSubMesh( myFace )->GetSubMeshDS();
+  // check that all faces are quadrangular
+  SMDS_ElemIteratorPtr fIt = faceSubMesh->GetElements();
+  while ( fIt->more() )
+    if ( fIt->next()->NbNodes() % 4 > 0 )
+      return error("Non-quadrangular mesh faces are not allowed on sides of a composite block");
+  
   myIndexer._xSize = 1 + mySides.GetSide( Q_BOTTOM )->GetNbSegments( mesh );
   myIndexer._ySize = 1 + mySides.GetSide( Q_LEFT   )->GetNbSegments( mesh );
 
@@ -998,8 +1004,6 @@ bool _QuadFaceGrid::LoadGrid( SMESH_Mesh& mesh )
 
   // store the rest nodes row by row
 
-  SMESHDS_SubMesh* faceSubMesh = mesh.GetSubMesh( myFace )->GetSubMeshDS();
-
   SMDS_MeshNode dummy(0,0,0);
   const SMDS_MeshElement* firstQuad = &dummy;// most left face above the last row of found nodes