Salome HOME
Intersec bug fix: point not added properly inserted in splitting.
[tools/medcoupling.git] / src / MEDLoader / SauvMedConvertor.cxx
index a075af9e4ede7f3ed1c72dca521fbc18fff7b869..f2cc8e82a2002b71e8ddffd7b2f41168da543126 100644 (file)
@@ -235,11 +235,11 @@ namespace
       isRelocated = ( c2oIt->second != newOrder );
 
     if ( isRelocated )
-    {
-      grp->_relocTable.resize( cell2order.size() );
-      for ( newOrder = 0, c2oIt = cell2order.begin(); c2oIt != c2oEnd; ++c2oIt, ++newOrder )
-        grp->_relocTable[ c2oIt->second ] = newOrder;
-    }
+      {
+        grp->_relocTable.resize( cell2order.size() );
+        for ( newOrder = 0, c2oIt = cell2order.begin(); c2oIt != c2oEnd; ++c2oIt, ++newOrder )
+          grp->_relocTable[ c2oIt->second ] = newOrder;
+      }
   }
 }
 
@@ -281,9 +281,9 @@ namespace // define default GAUSS points
      *  \param geomType - element geometry (EGeometrieElement or med_geometrie_element)
      *  \param nbPoints - nb gauss point
      *  \param variant - [1-3] to choose the variant of definition
-     * 
+     *
      * Throws in case of invalid parameters
-     * variant == 1 refers to "Fonctions de forme et points d'integration 
+     * variant == 1 refers to "Fonctions de forme et points d'integration
      *              des elements finis" v7.4 by J. PELLET, X. DESROCHES, 15/09/05
      * variant == 2 refers to the same doc v6.4 by J.P. LEFEBVRE, X. DESROCHES, 03/07/03
      * variant == 3 refers to the same doc v6.4, second variant for 2D elements
@@ -877,7 +877,7 @@ namespace // define default GAUSS points
     TInt aNbRef = myRefCoord.size();
     for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
-      switch(aRefId){        
+      switch(aRefId){
       case  0: aCoord[0] =  1.0;  aCoord[1] =  0.0;  aCoord[2] =  0.0; break;
       case  3: aCoord[0] =  0.0;  aCoord[1] =  1.0;  aCoord[2] =  0.0; break;
       case  2: aCoord[0] = -1.0;  aCoord[1] =  0.0;  aCoord[2] =  0.0; break;
@@ -966,7 +966,7 @@ namespace // define default GAUSS points
         const double P1 = 1./1.8;
         const double P2 = 1./1.125;
         add( -a,  P1 );
-        add(  0,  P2 ); 
+        add(  0,  P2 );
         add(  a,  P1 ); break;
       }
       case 4: {
@@ -974,7 +974,7 @@ namespace // define default GAUSS points
         const double P1 = 0.652145154862546, P2 = 0.347854845137454 ;
         add(  a,  P1 );
         add( -a,  P1 );
-        add(  b,  P2 ); 
+        add(  b,  P2 );
         add( -b,  P2 ); break;
       }
       default:
@@ -1006,11 +1006,11 @@ namespace // define default GAUSS points
         case 6: { // FPG6
           const double P1 = 0.11169079483905, P2 = 0.0549758718227661;
           const double a  = 0.445948490915965, b = 0.091576213509771;
-          add(     b,     b, P2 ); 
+          add(     b,     b, P2 );
           add( 1-2*b,     b, P2 );
           add(     b, 1-2*b, P2 );
           add(     a, 1-2*a, P1 );
-          add(     a,     a, P1 ); 
+          add(     a,     a, P1 );
           add( 1-2*a,     a, P1 ); break;
         }
         case 7: { // FPG7
@@ -1018,11 +1018,11 @@ namespace // define default GAUSS points
           const double B  = 0.101286507323456;
           const double P1 = 0.066197076394253;
           const double P2 = 0.062969590272413;
-          add(  1/3.,  1/3., 9/80. ); 
-          add(     A,     A, P1 ); 
+          add(  1/3.,  1/3., 9/80. );
+          add(     A,     A, P1 );
           add( 1-2*A,     A, P1 );
           add(     A, 1-2*A, P1 );
-          add(     B,     B, P2 ); 
+          add(     B,     B, P2 );
           add( 1-2*B,     B, P2 );
           add(     B, 1-2*B, P2 ); break;
         }
@@ -1034,10 +1034,10 @@ namespace // define default GAUSS points
           const double P1 = 0.025422453185103;
           const double P2 = 0.058393137863189;
           const double P3 = 0.041425537809187;
-          add(     A,     A, P1 ); 
+          add(     A,     A, P1 );
           add( 1-2*A,     A, P1 );
           add(     A, 1-2*A, P1 );
-          add(     B,     B, P2 ); 
+          add(     B,     B, P2 );
           add( 1-2*B,     B, P2 );
           add(     B, 1-2*B, P2 );
           add(     C,     D, P3 );
@@ -1049,7 +1049,7 @@ namespace // define default GAUSS points
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for TRIA, variant 1: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       else if ( variant == 2 ) {
@@ -1067,16 +1067,16 @@ namespace // define default GAUSS points
         case 6: {
           const double P1 = 0.11169079483905, P2 = 0.0549758718227661;
           const double A  = 0.445948490915965, B = 0.091576213509771;
-          add( 2*B-1, 1-4*B, 4*P2 ); 
+          add( 2*B-1, 1-4*B, 4*P2 );
           add( 2*B-1, 2*B-1, 4*P2 );
           add( 1-4*B, 2*B-1, 4*P2 );
           add( 1-4*A, 2*A-1, 4*P1 );
-          add( 2*A-1, 1-4*A, 4*P1 ); 
+          add( 2*A-1, 1-4*A, 4*P1 );
           add( 2*A-1, 2*A-1, 4*P1 ); break;
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for TRIA, variant 2: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       else if ( variant == 3 ) {
@@ -1091,7 +1091,7 @@ namespace // define default GAUSS points
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for TRIA, variant 3: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       break;
@@ -1134,7 +1134,7 @@ namespace // define default GAUSS points
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for QUAD, variant 1: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       else if ( variant == 2 ) {
@@ -1162,7 +1162,7 @@ namespace // define default GAUSS points
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for QUAD, variant 1: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       else if ( variant == 3 ) {
@@ -1191,7 +1191,7 @@ namespace // define default GAUSS points
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for QUAD, variant 3: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       break;
@@ -1274,12 +1274,12 @@ namespace // define default GAUSS points
         add( 0., 0.,  h3,  p3 ); break;
       }
       case 27: { // FPG27
-        const double a1  = 0.788073483; 
-        const double b6  = 0.499369002; 
-        const double b1  = 0.848418011; 
-        const double c8  = 0.478508449; 
-        const double c1  = 0.652816472; 
-        const double d12 = 0.032303742; 
+        const double a1  = 0.788073483;
+        const double b6  = 0.499369002;
+        const double b1  = 0.848418011;
+        const double c8  = 0.478508449;
+        const double c1  = 0.652816472;
+        const double d12 = 0.032303742;
         const double d1  = 1.106412899;
         double z = 1/2., fz = b1/2*(1 - z);
         add(  0.,  0.,   z,  a1 ); // 1
@@ -1443,7 +1443,7 @@ namespace // define default GAUSS points
       THROW_IK_EXCEPTION("TGaussDef: Not all gauss points defined");
   }
 }
-  
+
 //================================================================================
 /*!
  * \brief Return dimension for the given cell type
@@ -1473,16 +1473,16 @@ const int * SauvUtilities::getGibi2MedQuadraticInterlace( INTERP_KERNEL::Normali
   static const int tria6  [] = {0,2,4, 1,3,5};
   static const int seg3   [] = {0,2,1};
   if ( conn.empty() )
-  {
-    conn.resize( MaxMedCellType + 1, 0 );
-    conn[ NORM_HEXA20 ] = hexa20;
-    conn[ NORM_PENTA15] = penta15;
-    conn[ NORM_PYRA13 ] = pyra13;
-    conn[ NORM_TETRA10] = tetra10;
-    conn[ NORM_SEG3   ] = seg3;
-    conn[ NORM_TRI6   ] = tria6;
-    conn[ NORM_QUAD8  ] = quad8;
-  }
+    {
+      conn.resize( MaxMedCellType + 1, 0 );
+      conn[ NORM_HEXA20 ] = hexa20;
+      conn[ NORM_PENTA15] = penta15;
+      conn[ NORM_PYRA13 ] = pyra13;
+      conn[ NORM_TETRA10] = tetra10;
+      conn[ NORM_SEG3   ] = seg3;
+      conn[ NORM_TRI6   ] = tria6;
+      conn[ NORM_QUAD8  ] = quad8;
+    }
   return conn[ type ];
 }
 
@@ -1526,14 +1526,14 @@ SauvUtilities::Link Cell::link(int i) const
 const TID* Cell::getSortedNodes() const
 {
   if ( !_sortedNodeIDs )
-  {
-    size_t l=_nodes.size();
-    _sortedNodeIDs = new int[ l ];
+    {
+      size_t l=_nodes.size();
+      _sortedNodeIDs = new int[ l ];
 
-    for (size_t i=0; i!=l; ++i)
-      _sortedNodeIDs[i]=_nodes[i]->_number;
-    std::sort( _sortedNodeIDs, _sortedNodeIDs + l );
-  }
+      for (size_t i=0; i!=l; ++i)
+        _sortedNodeIDs[i]=_nodes[i]->_number;
+      std::sort( _sortedNodeIDs, _sortedNodeIDs + l );
+    }
   return _sortedNodeIDs;
 }
 
@@ -1925,7 +1925,7 @@ int ASCIIReader::getInt() const
   // 53619905   |       1       2       6       8
   // 53619906   |                                                                SCALAIRE
   // 53619907   |    -63312600499       1       0       0       0      -2       0       2
-  //   where -63312600499 is actualy -633 and 12600499
+  //   where -63312600499 is actually -633 and 12600499
   char hold=_curPos[_width];
   _curPos[_width] = '\0';
   int result = atoi( _curPos );
@@ -1972,7 +1972,7 @@ double ASCIIReader::getDouble() const
   //0123456789012345678901234567890123456789012345678901234567890123456789
   const size_t posE = 18;
   std::string aStr (_curPos);
-  if ( aStr.find('E') < 0 && aStr.find('e') < 0 )
+  if ( aStr.find('E') == std::string::npos && aStr.find('e') == std::string::npos )
     {
       if ( aStr.size() < posE+1 )
         THROW_IK_EXCEPTION("No more doubles (line #" << lineNb() << ")");
@@ -2014,7 +2014,7 @@ XDRReader::XDRReader(const char* fileName) :FileReader(fileName), _xdrs_file(NUL
 
 XDRReader::~XDRReader()
 {
-#ifdef HAS_XDR  
+#ifdef HAS_XDR
   if ( _xdrs_file )
     {
       xdr_destroy((XDR*)_xdrs);
@@ -2048,29 +2048,29 @@ bool XDRReader::open()
 #ifdef HAS_XDR
 #ifdef WIN32
   if ((_xdrs_file = ::fopen(_fileName.c_str(), "rb")))
-#else 
-  if ((_xdrs_file = ::fopen(_fileName.c_str(), "r")))
+#else
+    if ((_xdrs_file = ::fopen(_fileName.c_str(), "r")))
 #endif
-    {
-      _xdrs = (XDR *)malloc(sizeof(XDR));
-      xdrstdio_create((XDR*)_xdrs, _xdrs_file, XDR_DECODE);
+      {
+        _xdrs = (XDR *)malloc(sizeof(XDR));
+        xdrstdio_create((XDR*)_xdrs, _xdrs_file, XDR_DECODE);
 
-      const int maxsize = 10;
-      char icha[maxsize+1];
-      char* icha2 = icha;
-      if (( xdr_ok = xdr_string((XDR*)_xdrs, &icha2, maxsize)))
-        {
-          icha[maxsize] = '\0';
-          xdr_ok = (strcmp(icha, "CASTEM XDR") == 0);
-        }
-      if ( !xdr_ok )
-        {
-          xdr_destroy((XDR*)_xdrs);
-          free((XDR*)_xdrs);
-          fclose(_xdrs_file);
-          _xdrs_file = NULL;
-        }
-    }
+        const int maxsize = 10;
+        char icha[maxsize+1];
+        char* icha2 = icha;
+        if (( xdr_ok = xdr_string((XDR*)_xdrs, &icha2, maxsize)))
+          {
+            icha[maxsize] = '\0';
+            xdr_ok = (strcmp(icha, "CASTEM XDR") == 0);
+          }
+        if ( !xdr_ok )
+          {
+            xdr_destroy((XDR*)_xdrs);
+            free((XDR*)_xdrs);
+            fclose(_xdrs_file);
+            _xdrs_file = NULL;
+          }
+      }
 #endif
   return xdr_ok;
 }
@@ -2311,7 +2311,7 @@ void IntermediateMED::checkDataAvailability() const
 
 Group* IntermediateMED::addNewGroup(std::vector<SauvUtilities::Group*>* groupsToFix)
 {
-  if ( _groups.size() == _groups.capacity() ) // re-allocation would occure
+  if ( _groups.size() == _groups.capacity() ) // re-allocation would occur
     {
       std::vector<Group> newGroups( _groups.size() );
       newGroups.push_back( Group() );
@@ -2587,28 +2587,28 @@ void IntermediateMED::setFieldLongNames(std::set< std::string >& usedNames)
 void IntermediateMED::decreaseHierarchicalDepthOfSubgroups()
 {
   for (size_t i=0; i!=_groups.size(); ++i)
-  {
-    Group& grp = _groups[i];
-    for (size_t j = 0; j < grp._groups.size(); ++j )
     {
-      Group & sub_grp = *grp._groups[j];
-      if ( !sub_grp._groups.empty() )
-      {
-        // replace j with its 1st subgroup
-        grp._groups[j] = sub_grp._groups[0];
-        // push back the rest subs
-        grp._groups.insert( grp._groups.end(), ++sub_grp._groups.begin(), sub_grp._groups.end() );
-      }
+      Group& grp = _groups[i];
+      for (size_t j = 0; j < grp._groups.size(); ++j )
+        {
+          Group & sub_grp = *grp._groups[j];
+          if ( !sub_grp._groups.empty() )
+            {
+              // replace j with its 1st subgroup
+              grp._groups[j] = sub_grp._groups[0];
+              // push back the rest subs
+              grp._groups.insert( grp._groups.end(), ++sub_grp._groups.begin(), sub_grp._groups.end() );
+            }
+        }
+      // remove empty sub-_groups
+      std::vector< Group* > newSubGroups;
+      newSubGroups.reserve( grp._groups.size() );
+      for (size_t j = 0; j < grp._groups.size(); ++j )
+        if ( !grp._groups[j]->empty() )
+          newSubGroups.push_back( grp._groups[j] );
+      if ( newSubGroups.size() < grp._groups.size() )
+        grp._groups.swap( newSubGroups );
     }
-    // remove empty sub-_groups
-    std::vector< Group* > newSubGroups;
-    newSubGroups.reserve( grp._groups.size() );
-    for (size_t j = 0; j < grp._groups.size(); ++j )
-      if ( !grp._groups[j]->empty() )
-        newSubGroups.push_back( grp._groups[j] );
-    if ( newSubGroups.size() < grp._groups.size() )
-      grp._groups.swap( newSubGroups );
-  }
 }
 
 //================================================================================
@@ -2630,32 +2630,32 @@ void IntermediateMED::eraseUselessGroups()
   std::set<Group*> groups2convert;
   // keep not named sub-groups of field supports
   for (size_t i=0; i!=_groups.size(); ++i)
-  {
-    Group& grp = _groups[i];
-    if ( grp._isProfile && !grp._groups.empty() )
-      groups2convert.insert( grp._groups.begin(), grp._groups.end() );
-  }
+    {
+      Group& grp = _groups[i];
+      if ( grp._isProfile && !grp._groups.empty() )
+        groups2convert.insert( grp._groups.begin(), grp._groups.end() );
+    }
 
   // keep named groups and their subgroups
   for (size_t i=0; i!=_groups.size(); ++i)
-  {
-    Group& grp = _groups[i];
-    if ( !grp._name.empty() && !grp.empty() )
     {
-      groups2convert.insert( &grp );
-      groups2convert.insert( grp._groups.begin(), grp._groups.end() );
+      Group& grp = _groups[i];
+      if ( !grp._name.empty() && !grp.empty() )
+        {
+          groups2convert.insert( &grp );
+          groups2convert.insert( grp._groups.begin(), grp._groups.end() );
+        }
     }
-  }
   // erase groups that are not in groups2convert and not _isProfile
   for (size_t i=0; i!=_groups.size(); ++i)
-  {
-    Group* grp = &_groups[i];
-    if ( !grp->_isProfile && !groups2convert.count( grp ) )
     {
-      grp->_cells.clear();
-      grp->_groups.clear();
+      Group* grp = &_groups[i];
+      if ( !grp->_isProfile && !groups2convert.count( grp ) )
+        {
+          grp->_cells.clear();
+          grp->_groups.clear();
+        }
     }
-  }
 }
 
 //================================================================================
@@ -2668,26 +2668,26 @@ void IntermediateMED::detectMixDimGroups()
 {
   //hasMixedCells = false;
   for ( size_t i=0; i < _groups.size(); ++i )
-  {
-    Group& grp = _groups[i];
-    if ( grp._groups.size() < 2 )
-      continue;
-
-    // check if sub-groups have different dimension
-    unsigned dim1 = getDim( &grp );
-    for ( size_t j = 1; j  < grp._groups.size(); ++j )
     {
-      unsigned dim2 = getDim( grp._groups[j] );
-      if ( dim1 != dim2 )
-      {
-        grp._cells.clear();
-        grp._groups.clear();
-        if ( !grp._name.empty() )
-          std::cout << "Erase a group with elements of different dim |" << grp._name << "|"<< std::endl;
-        break;
-      }
+      Group& grp = _groups[i];
+      if ( grp._groups.size() < 2 )
+        continue;
+
+      // check if sub-groups have different dimension
+      unsigned dim1 = getDim( &grp );
+      for ( size_t j = 1; j  < grp._groups.size(); ++j )
+        {
+          unsigned dim2 = getDim( grp._groups[j] );
+          if ( dim1 != dim2 )
+            {
+              grp._cells.clear();
+              grp._groups.clear();
+              if ( !grp._name.empty() )
+                std::cout << "Erase a group with elements of different dim |" << grp._name << "|"<< std::endl;
+              break;
+            }
+        }
     }
-  }
 }
 
 //================================================================================
@@ -2741,7 +2741,7 @@ void IntermediateMED::orientElements2D()
       //       if (( x = nodeCoords( elemIt->_nodes[ iNode ])[ 0 ]) < minX )
       //         minX = x, iLeft = iNode;
 
-      //     // indeces of the nodes neighboring the most left one
+      //     // indices of the nodes neighboring the most left one
       //     int iPrev = ( iLeft - 1 < 0 ) ? nbNodes - 1 : iLeft - 1;
       //     int iNext = ( iLeft + 1 == nbNodes ) ? 0 : iLeft + 1;
       //     // find components of prev-left and left-next vectors
@@ -2790,27 +2790,27 @@ void IntermediateMED::orientElements3D()
   std::vector< std::pair<int,int> > swapVec;
 
   for ( int dim = 1; dim <= 3; ++dim )
-  {
-    CellsByDimIterator cellsIt( *this, dim );
-    while ( const std::set<Cell > * elems = cellsIt.nextType() )
     {
-      TCellType cellType = cellsIt.type();
-      bool isQuadratic = getGibi2MedQuadraticInterlace( cellType );
-      getReverseVector( cellType, swapVec );
+      CellsByDimIterator cellsIt( *this, dim );
+      while ( const std::set<Cell > * elems = cellsIt.nextType() )
+        {
+          TCellType cellType = cellsIt.type();
+          bool isQuadratic = getGibi2MedQuadraticInterlace( cellType );
+          getReverseVector( cellType, swapVec );
 
-      elemIt = elems->begin(), elemEnd = elems->end();
-      for ( ; elemIt != elemEnd; elemIt++ )
-      {
-        // GIBI connectivity -> MED one
-        if( isQuadratic )
-          ConvertQuadratic( cellType, *elemIt );
+          elemIt = elems->begin(), elemEnd = elems->end();
+          for ( ; elemIt != elemEnd; elemIt++ )
+            {
+              // GIBI connectivity -> MED one
+              if( isQuadratic )
+                ConvertQuadratic( cellType, *elemIt );
 
-        // reverse faces
-        if ( elemIt->_reverse )
-          reverse ( *elemIt, swapVec );
-      }
+              // reverse faces
+              if ( elemIt->_reverse )
+                reverse ( *elemIt, swapVec );
+            }
+        }
     }
-  }
 
   // COMMENTED for issue 0022612 note 17739
   //orientVolumes();
@@ -2854,7 +2854,7 @@ void IntermediateMED::orientFaces3D()
   // Each oriented link must appear in one face only, else a face is reversed.
 
   std::queue<const Cell*> faceQueue; /* the queue contains well oriented faces
-                                     whose neighbors orientation is to be checked */
+                                        whose neighbors orientation is to be checked */
   bool manifold = true;
   while ( !linkFacesMap.empty() )
     {
@@ -3101,12 +3101,11 @@ void IntermediateMED::numberElements()
           TID typeSize = typeCells->size();
           if ( typeSize != maxNumber - minNumber + 1 )
             ok = false;
-          if ( prevNbElems != 0 ) {
-            if ( minNumber == 1 )
-              renumEntity = true;
-            else if ( prevNbElems+1 != (int)minNumber )
-              ok = false;
-          }
+          if ( prevNbElems+1 != (int)minNumber )
+            ok = false;
+          if ( prevNbElems != 0 && minNumber == 1 )
+            renumEntity = true;
+
           prevNbElems += typeSize;
         }
 
@@ -3173,54 +3172,54 @@ void IntermediateMED::setConnectivity( MEDCoupling::MEDFileUMesh*    mesh,
 
   std::set<Cell>::const_iterator elemIt, elemEnd;
   for ( int dim = 3; dim > 0; --dim )
-  {
-    CellsByDimIterator dimCells( *this, dim );
+    {
+      CellsByDimIterator dimCells( *this, dim );
 
-    int nbOfCells = 0;
-    while ( const std::set<Cell > * cells = dimCells.nextType() )
-      nbOfCells += cells->size();
-    if ( nbOfCells == 0 )
-      continue;
+      int nbOfCells = 0;
+      while ( const std::set<Cell > * cells = dimCells.nextType() )
+        nbOfCells += cells->size();
+      if ( nbOfCells == 0 )
+        continue;
 
-    if ( !meshDim ) meshDim = dim;
+      if ( !meshDim ) meshDim = dim;
 
-    MEDCouplingUMesh* dimMesh = MEDCouplingUMesh::New();
-    dimMesh->setCoords( coords );
-    dimMesh->setMeshDimension( dim );
-    dimMesh->allocateCells( nbOfCells );
+      MEDCouplingUMesh* dimMesh = MEDCouplingUMesh::New();
+      dimMesh->setCoords( coords );
+      dimMesh->setMeshDimension( dim );
+      dimMesh->allocateCells( nbOfCells );
 
-    int prevNbCells = 0;
-    dimCells.init( dim );
-    while ( const std::set<Cell > * cells = dimCells.nextType() )
-      {
-        // fill connectivity array to take into account order of elements in the sauv file
-        const int nbCellNodes = cells->begin()->_nodes.size();
-        std::vector< TID > connectivity( cells->size() * nbCellNodes );
-        int * nodalConnOfCell;
-        for ( elemIt = cells->begin(), elemEnd = cells->end(); elemIt != elemEnd; ++elemIt )
-          {
-            const Cell& cell = *elemIt;
-            const int index = cell._number - 1 - prevNbCells;
-            nodalConnOfCell = &connectivity[ index * nbCellNodes ];
-            if ( cell._reverse )
-              for ( int i = nbCellNodes-1; i >= 0; --i )
-                *nodalConnOfCell++ = cell._nodes[i]->_number - 1;
-            else
-              for ( int i = 0; i < nbCellNodes; ++i )
-                *nodalConnOfCell++ = cell._nodes[i]->_number - 1;
-          }
-        prevNbCells += cells->size();
+      int prevNbCells = 0;
+      dimCells.init( dim );
+      while ( const std::set<Cell > * cells = dimCells.nextType() )
+        {
+          // fill connectivity array to take into account order of elements in the sauv file
+          const int nbCellNodes = cells->begin()->_nodes.size();
+          std::vector< TID > connectivity( cells->size() * nbCellNodes );
+          int * nodalConnOfCell;
+          for ( elemIt = cells->begin(), elemEnd = cells->end(); elemIt != elemEnd; ++elemIt )
+            {
+              const Cell& cell = *elemIt;
+              const int index = cell._number - 1 - prevNbCells;
+              nodalConnOfCell = &connectivity[ index * nbCellNodes ];
+              if ( cell._reverse )
+                for ( int i = nbCellNodes-1; i >= 0; --i )
+                  *nodalConnOfCell++ = cell._nodes[i]->_number - 1;
+              else
+                for ( int i = 0; i < nbCellNodes; ++i )
+                  *nodalConnOfCell++ = cell._nodes[i]->_number - 1;
+            }
+          prevNbCells += cells->size();
 
-        // fill dimMesh
-        TCellType cellType = dimCells.type();
-        nodalConnOfCell = &connectivity[0];
-        for ( size_t i = 0; i < cells->size(); ++i, nodalConnOfCell += nbCellNodes )
-          dimMesh->insertNextCell( cellType, nbCellNodes, nodalConnOfCell );
-      }
-    dimMesh->finishInsertingCells();
-    mesh->setMeshAtLevel( dim - meshDim, dimMesh );
-    dimMesh->decrRef();
-  }
+          // fill dimMesh
+          TCellType cellType = dimCells.type();
+          nodalConnOfCell = &connectivity[0];
+          for ( size_t i = 0; i < cells->size(); ++i, nodalConnOfCell += nbCellNodes )
+            dimMesh->insertNextCell( cellType, nbCellNodes, nodalConnOfCell );
+        }
+      dimMesh->finishInsertingCells();
+      mesh->setMeshAtLevel( dim - meshDim, dimMesh );
+      dimMesh->decrRef();
+    }
 }
 
 //================================================================================
@@ -3440,7 +3439,7 @@ void IntermediateMED::setFields( SauvUtilities::DoubleField* fld,
           fld->setValues( valPtr, iSub );
           setTS( fld, values, medFields, mesh, iSub++ );
 
-          std::cout << fld->_name << " with compoments";
+          std::cout << fld->_name << " with components";
           for ( size_t i = 0; i < (size_t)fld->_sub[iSub-1].nbComponents(); ++i )
             std::cout << " " << fld->_sub[iSub-1]._comp_names[ i ];
           std::cout << std::endl;
@@ -3688,14 +3687,14 @@ bool DoubleField::hasSameComponentsBySupport() const
   std::vector< _Sub_data >::const_iterator sub_data = _sub.begin();
   const _Sub_data& first_sub_data = *sub_data;
   for ( ++sub_data ; sub_data != _sub.end(); ++sub_data )
-  {
-    if ( first_sub_data._comp_names != sub_data->_comp_names )
-      return false; // diff names of components
+    {
+      if ( first_sub_data._comp_names != sub_data->_comp_names )
+        return false; // diff names of components
 
-    if ( first_sub_data._nb_gauss != sub_data->_nb_gauss &&
-         first_sub_data._support->_cellType == sub_data->_support->_cellType)
-      return false; // diff nb of gauss points on same cell type
-  }
+      if ( first_sub_data._nb_gauss != sub_data->_nb_gauss &&
+           first_sub_data._support->_cellType == sub_data->_support->_cellType)
+        return false; // diff nb of gauss points on same cell type
+    }
   return true;
 }
 
@@ -3844,7 +3843,7 @@ CellsByDimIterator::CellsByDimIterator( const IntermediateMED & medi, int dimm)
   init( dimm );
 }
 /*!
- * \brief Initialize iteration on cells of given dimention
+ * \brief Initialize iteration on cells of given dimension
  */
 void CellsByDimIterator::init(const int  dimm)
 {
@@ -3874,4 +3873,3 @@ int CellsByDimIterator::dim(const bool last) const
   return typp < myTypeEnd ? getDimension( TCellType( typp )) : 4;
 }
 // END CellsByDimIterator ========================================================
-