Salome HOME
For med file version, no more use of static macro but use dynamic lib for users using...
[tools/medcoupling.git] / src / MEDLoader / MEDFileMeshLL.cxx
index cf6177bebd19549aab5fe0654c51dfa18426def3..0a34f8ad7ac8448de1da9defc33cddb5ba7fa0b9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include "CellModel.hxx"
 
 #include <set>
+#include <iomanip>
 
 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
 extern med_geometry_type typmainoeud[1];
 
-using namespace ParaMEDMEM;
+using namespace MEDCoupling;
+
+const char MEDFileMeshL2::ZE_SEP_FOR_FAMILY_KILLERS[]="!/__\\!";//important start by - because ord('!')==33 the smallest (!=' ') to preserve orders at most.
+
+int MEDFileMeshL2::ZE_SEP2_FOR_FAMILY_KILLERS=4;
 
 MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_univ_name(MED_LNAME_SIZE),_dt_unit(MED_LNAME_SIZE)
 {
@@ -51,7 +56,7 @@ std::vector<const BigMemoryObject *> MEDFileMeshL2::getDirectChildrenWithNull()
   return std::vector<const BigMemoryObject *>();
 }
 
-int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1)
+int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& dt, int& it, std::string& dtunit1)
 {
   med_mesh_type type_maillage;
   char maillage_description[MED_COMMENT_SIZE+1];
@@ -70,7 +75,7 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, Para
       int naxis(MEDmeshnAxis(fid,i+1));
       INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
       INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
-      MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
+      MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));      
       dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit));
       std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
       ms.push_back(cur);
@@ -87,6 +92,7 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, Para
       std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
       throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
+  axType=TraduceAxisType(axistype);
   switch(type_maillage)
   {
     case MED_UNSTRUCTURED_MESH:
@@ -104,13 +110,16 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, Para
           case MED_CURVILINEAR_GRID:
             meshType=CURVE_LINEAR;
             break;
+          case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
+            meshType=CARTESIAN;
+            break;
           default:
-            throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
+            throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
         }
         break;
       }
     default:
-      throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !");
+      throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
   }
   med_int numdt,numit;
   med_float dtt;
@@ -128,8 +137,9 @@ double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const std::string& mName, i
   for(int i=0;i<nstep;i++)
     {
       MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),i+1,&numdt,&numit,&dtt));
-      p[i]=std::make_pair(numdt,numit);
-      found=(numdt==dt) && (numit==numit);
+      p[i]=std::make_pair((int)numdt,(int)numit);
+      found=(numdt==dt) && (numit==it);
+      if (found) break;
     }
   if(!found)
     {
@@ -142,7 +152,10 @@ double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const std::string& mName, i
   return dtt;
 }
 
-std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim)
+/*!
+ * non static and non const method because _description, _dt_unit... are set in this method.
+ */
+std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim)
 {
   med_mesh_type type_maillage;
   med_int spaceDim;
@@ -157,6 +170,7 @@ std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId,
       &stype,&nstep,&axistype,axisname,axisunit)!=0)
     throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
   MEDmeshUniversalNameRd(fid,nameTmp,_univ_name.getPointer());// do not protect  MEDFILESAFECALLERRD0 call : Thanks to fra.med.
+  axType=TraduceAxisType(axistype);
   switch(type_maillage)
   {
     case MED_UNSTRUCTURED_MESH:
@@ -174,13 +188,16 @@ std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId,
           case MED_CURVILINEAR_GRID:
             meshType=CURVE_LINEAR;
             break;
+        case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
+            meshType=CARTESIAN;
+            break;
           default:
-            throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
+            throw INTERP_KERNEL::Exception("MEDFileMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
         }
         break;
       }
     default:
-      throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !");
+      throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
   }
   //
   std::vector<std::string> infosOnComp(naxis);
@@ -199,6 +216,7 @@ void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const std::string& meshName
   char nomfam[MED_NAME_SIZE+1];
   med_int numfam;
   int nfam=MEDnFamily(fid,meshName.c_str());
+  std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > > crudeFams(nfam);
   for(int i=0;i<nfam;i++)
     {
       int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
@@ -208,19 +226,26 @@ void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const std::string& meshName
       INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
       INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
       MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
-      std::string famName=MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE);
-      fams[famName]=numfam;
+      std::string famName(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE));
+      std::vector<std::string> grps(ngro);
       for(int j=0;j<ngro;j++)
-        {
-          std::string groupname=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
-          grps[groupname].push_back(famName);
-        }
+        grps[j]=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
+      crudeFams[i]=std::pair<std::string,std::pair<int,std::vector<std::string> > >(famName,std::pair<int,std::vector<std::string> >(numfam,grps));
+    }
+  RenameFamiliesFromFileToMemInternal(crudeFams);
+  for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::const_iterator it0=crudeFams.begin();it0!=crudeFams.end();it0++)
+    {
+      fams[(*it0).first]=(*it0).second.first;
+      for(std::vector<std::string>::const_iterator it1=(*it0).second.second.begin();it1!=(*it0).second.second.end();it1++)
+        grps[*it1].push_back((*it0).first);
     }
 }
 
 void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const std::string& mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol)
 {
-  for(std::map<std::string,int>::const_iterator it=fams.begin();it!=fams.end();it++)
+  std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > > crudeFams(fams.size());
+  std::size_t ii(0);
+  for(std::map<std::string,int>::const_iterator it=fams.begin();it!=fams.end();it++,ii++)
     {
       std::vector<std::string> grpsOfFam;
       for(std::map<std::string, std::vector<std::string> >::const_iterator it1=grps.begin();it1!=grps.end();it1++)
@@ -228,18 +253,193 @@ void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const std::string& mname,
           if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end())
             grpsOfFam.push_back((*it1).first);
         }
-      int ngro=grpsOfFam.size();
+      crudeFams[ii]=std::pair<std::string,std::pair<int,std::vector<std::string> > >((*it).first,std::pair<int,std::vector<std::string> >((*it).second,grpsOfFam));
+    }
+  RenameFamiliesFromMemToFileInternal(crudeFams);
+  for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++)
+    {
+      int ngro((*it).second.second.size());
       INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
       int i=0;
-      for(std::vector<std::string>::const_iterator it2=grpsOfFam.begin();it2!=grpsOfFam.end();it2++,i++)
+      for(std::vector<std::string>::const_iterator it2=(*it).second.second.begin();it2!=(*it).second.second.end();it2++,i++)
         MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,tooLongStrPol);
       INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
       MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_NAME_SIZE,famName,tooLongStrPol);
-      int ret=MEDfamilyCr(fid,mname.c_str(),famName,(*it).second,ngro,groName);
+      int ret=MEDfamilyCr(fid,mname.c_str(),famName,(*it).second.first,ngro,groName);
       ret++;
     }
 }
 
+void MEDFileMeshL2::RenameFamiliesPatternInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams, RenameFamiliesPatternFunc func)
+{
+  std::size_t ii(0);
+  std::vector<std::string> fams(crudeFams.size());
+  for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++)
+    fams[ii]=(*it).first;
+  if(!func(fams))
+    return ;
+  ii=0;
+  for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++)
+    (*it).first=fams[ii];
+}
+
+/*!
+ * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
+ * So this method renames families (if needed generaly not !) in order to have a discriminant name for families.
+ */
+void MEDFileMeshL2::RenameFamiliesFromFileToMemInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams)
+{
+  RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromFileToMem);
+}
+
+bool MEDFileMeshL2::RenameFamiliesFromFileToMem(std::vector< std::string >& famNames)
+{
+  std::map<std::string,int> m;
+  std::set<std::string> s;
+  for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
+    {
+      if(s.find(*it)!=s.end())
+        m[*it]=0;
+      s.insert(*it);
+    }
+  if(m.empty())
+    return false;// the general case !
+  for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++)
+    {
+      std::map<std::string,int>::iterator it2(m.find(*it));
+      if(it2!=m.end())
+        {
+          std::ostringstream oss; oss << *it << ZE_SEP_FOR_FAMILY_KILLERS << std::setfill('0') << std::setw(ZE_SEP2_FOR_FAMILY_KILLERS) << (*it2).second++;
+          *it=oss.str();
+        }
+    }
+  return true;
+}
+
+/*!
+ * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
+ * So this method renames families (if needed generaly not !) in order to have a discriminant name for families.
+ */
+void MEDFileMeshL2::RenameFamiliesFromMemToFileInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams)
+{
+  RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromMemToFile);
+}
+
+bool MEDFileMeshL2::RenameFamiliesFromMemToFile(std::vector< std::string >& famNames)
+{
+  bool isSmthingStrange(false);
+  for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
+    {
+      std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS));
+      if(found!=std::string::npos)
+        isSmthingStrange=true;
+    }
+  if(!isSmthingStrange)
+    return false;
+  // pattern matching
+  std::map< std::string, std::vector<std::string> > m;
+  for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
+    {
+      std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS));
+      if(found!=std::string::npos && found>=1)
+        {
+          std::string s1((*it).substr(found+sizeof(ZE_SEP_FOR_FAMILY_KILLERS)-1));
+          if(s1.size()!=ZE_SEP2_FOR_FAMILY_KILLERS)
+            continue;
+          int k(-1);
+          std::istringstream iss(s1);
+          iss >> k;
+          bool isOK((iss.rdstate() & ( std::istream::failbit | std::istream::eofbit)) == std::istream::eofbit);
+          if(isOK && k>=0)
+            {
+              std::string s0((*it).substr(0,found));
+              m[s0].push_back(*it);
+            }
+        }
+    }
+  if(m.empty())
+    return false;
+  // filtering
+  std::map<std::string,std::string> zeMap;
+  for(std::map< std::string, std::vector<std::string> >::const_iterator it=m.begin();it!=m.end();it++)
+    {
+      if((*it).second.size()==1)
+        continue;
+      for(std::vector<std::string>::const_iterator it1=(*it).second.begin();it1!=(*it).second.end();it1++)
+        zeMap[*it1]=(*it).first;
+    }
+  if(zeMap.empty())
+    return false;
+  // traduce
+  for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++)
+    {
+      std::map<std::string,std::string>::iterator it1(zeMap.find(*it));
+      if(it1!=zeMap.end())
+        *it=(*it1).second;
+    }    
+  return true;
+}
+
+MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisType(med_axis_type at)
+{
+  switch(at)
+    {
+    case MED_CARTESIAN:
+      return AX_CART;
+    case MED_CYLINDRICAL:
+      return AX_CYL;
+    case MED_SPHERICAL:
+      return AX_SPHER;
+    case MED_UNDEF_AXIS_TYPE:
+      return AX_CART;
+    default:
+      throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisType : unrecognized axis type !");
+    }
+}
+
+MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisTypeStruct(med_grid_type gt)
+{
+  switch(gt)
+    {
+    case MED_CARTESIAN_GRID:
+      return AX_CART;
+    case MED_POLAR_GRID:
+      return AX_CYL;
+    default:
+      throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeStruct : only Cartesian and Cylindrical supported by MED file !");
+    }
+}
+
+med_axis_type MEDFileMeshL2::TraduceAxisTypeRev(MEDCoupling::MEDCouplingAxisType at)
+{
+  switch(at)
+    {
+    case AX_CART:
+      return MED_CARTESIAN;
+    case AX_CYL:
+      return MED_CYLINDRICAL;
+    case AX_SPHER:
+      return MED_SPHERICAL;
+    default:
+      throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRev : unrecognized axis type !");
+    }
+}
+
+med_grid_type MEDFileMeshL2::TraduceAxisTypeRevStruct(MEDCoupling::MEDCouplingAxisType at)
+{
+  switch(at)
+    {
+    case AX_CART:
+      return MED_CARTESIAN_GRID;
+    case AX_CYL:
+      return MED_POLAR_GRID;
+    case AX_SPHER:
+      return MED_POLAR_GRID;
+    default:
+      throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRevStruct : unrecognized axis type !");
+    }
+}
+
 MEDFileUMeshL2::MEDFileUMeshL2()
 {
 }
@@ -249,8 +449,9 @@ std::vector<std::string> MEDFileUMeshL2::loadCommonPart(med_idt fid, int mId, co
   Mdim=-3;
   _name.set(mName.c_str());
   int nstep;
-  ParaMEDMEM::MEDCouplingMeshType meshType;
-  std::vector<std::string> ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,nstep,Mdim));
+  MEDCoupling::MEDCouplingMeshType meshType;
+  MEDCoupling::MEDCouplingAxisType dummy3;
+  std::vector<std::string> ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim));
   if(nstep==0)
     {
       Mdim=-4;
@@ -284,14 +485,14 @@ void MEDFileUMeshL2::loadPart(med_idt fid, int mId, const std::string& mName, co
   med_bool changement,transformation;
   int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
   std::vector<bool> fetchedNodeIds(nCoords,false);
-  for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
-    for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
+  for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
+    for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
       (*it1)->getMesh()->computeNodeIdsAlg(fetchedNodeIds);
   int nMin(std::distance(fetchedNodeIds.begin(),std::find(fetchedNodeIds.begin(),fetchedNodeIds.end(),true)));
   int nMax(std::distance(fetchedNodeIds.rbegin(),std::find(fetchedNodeIds.rbegin(),fetchedNodeIds.rend(),true)));
   nMax=nCoords-nMax;
-  for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
-    for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
+  for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
+    for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
       (*it1)->getMesh()->renumberNodesWithOffsetInConn(-nMin);
   loadPartCoords(fid,mId,infosOnComp,mName,dt,it,nMin,nMax);
 }
@@ -322,7 +523,7 @@ void MEDFileUMeshL2::loadPartOfConnectivity(med_idt fid, int mdim, const std::st
   for(std::size_t ii=0;ii<nbOfTypes;ii++)
     {
       int strt(slicPerTyp[3*ii+0]),stp(slicPerTyp[3*ii+1]),step(slicPerTyp[3*ii+2]);
-      MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> tmp(MEDFileUMeshPerType::NewPart(fid,mName.c_str(),dt,it,mdim,types[ii],strt,stp,step,mrs));
+      MCAuto<MEDFileUMeshPerType> tmp(MEDFileUMeshPerType::NewPart(fid,mName.c_str(),dt,it,mdim,types[ii],strt,stp,step,mrs));
       _per_type_mesh[0].push_back(tmp);
     }
   sortTypes();
@@ -416,9 +617,9 @@ void MEDFileUMeshL2::loadPartCoords(med_idt fid, int mId, const std::vector<std:
 void MEDFileUMeshL2::sortTypes()
 {
   std::set<int> mdims;
-  std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
+  std::vector< MCAuto<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
   _per_type_mesh.clear();
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
+  for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
     mdims.insert((*it)->getDim());
   if(mdims.empty())
     return;
@@ -426,15 +627,15 @@ void MEDFileUMeshL2::sortTypes()
   _per_type_mesh.resize(mdim+1);
   for(int dim=mdim+1;dim!=0;dim--)
     {
-      std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
-      for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
+      std::vector< MCAuto<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
+      for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
         if((*it)->getDim()==dim-1)
           elt.push_back(*it);
     }
   // suppression of contiguous empty levels at the end of _per_type_mesh.
   int nbOfUselessLev=0;
   bool isFirst=true;
-  for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++)
+  for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++)
     {
       if((*it2).empty() && isFirst)
         {
@@ -469,7 +670,7 @@ void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt,
 
 bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
 {
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
+  for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
     if((*it)->getFam()==0)
       return false;
   return true;
@@ -477,7 +678,7 @@ bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
 
 bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const
 {
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
+  for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
     if((*it)->getNum()==0)
       return false;
   return true;
@@ -485,13 +686,13 @@ bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const
 
 bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const
 {
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
+  for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
     if((*it)->getNames()==0)
       return false;
   return true;
 }
 
-MEDFileCMeshL2::MEDFileCMeshL2()
+MEDFileCMeshL2::MEDFileCMeshL2():_ax_type(AX_CART)
 {
 }
 
@@ -500,8 +701,9 @@ void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int
   _name.set(mName.c_str());
   int nstep;
   int Mdim;
-  ParaMEDMEM::MEDCouplingMeshType meshType;
-  std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,nstep,Mdim);
+  MEDCoupling::MEDCouplingMeshType meshType;
+  MEDCoupling::MEDCouplingAxisType dummy3;
+  std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim);
   if(meshType!=CARTESIAN)
     throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
   _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
@@ -510,15 +712,16 @@ void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int
   //
   med_grid_type gridtype;
   MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gridtype));
-  if(gridtype!=MED_CARTESIAN_GRID)
-    throw INTERP_KERNEL::Exception("Invalid structured mesh ! Expected cartesian mesh type !");
+  if(gridtype!=MED_CARTESIAN_GRID && gridtype!=MED_POLAR_GRID)
+    throw INTERP_KERNEL::Exception("Invalid rectilinear mesh ! Only cartesian and polar are supported !");
+  _ax_type=TraduceAxisTypeStruct(gridtype);
   _cmesh=MEDCouplingCMesh::New();
   for(int i=0;i<Mdim;i++)
     {
       med_data_type dataTypeReq=GetDataTypeCorrespondingToSpaceId(i);
       med_bool chgt=MED_FALSE,trsf=MED_FALSE;
       int nbOfElt(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,dataTypeReq,MED_NO_CMODE,&chgt,&trsf));
-      MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=DataArrayDouble::New();
+      MCAuto<DataArrayDouble> da=DataArrayDouble::New();
       da->alloc(nbOfElt,1);
       da->setInfoOnComponent(0,infosOnComp[i]);
       MEDFILESAFECALLERRD0(MEDmeshGridIndexCoordinateRd,(fid,mName.c_str(),dt,it,i+1,da->getPointer()));
@@ -550,8 +753,9 @@ void MEDFileCLMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, in
   _name.set(mName.c_str());
   int nstep;
   int Mdim;
-  ParaMEDMEM::MEDCouplingMeshType meshType;
-  std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim);
+  MEDCoupling::MEDCouplingMeshType meshType;
+  MEDCoupling::MEDCouplingAxisType dummy3;
+  std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,dummy3,nstep,Mdim);
   if(meshType!=CURVE_LINEAR)
     throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
   _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
@@ -564,7 +768,7 @@ void MEDFileCLMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, in
   _clmesh->setNodeGridStructure(stGrid,((int *)stGrid)+Mdim);
   med_bool chgt=MED_FALSE,trsf=MED_FALSE;
   int nbNodes(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf));
-  MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=DataArrayDouble::New();
+  MCAuto<DataArrayDouble> da=DataArrayDouble::New();
   da->alloc(nbNodes,infosOnComp.size());
   da->setInfoOnComponents(infosOnComp);
   MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,da->getPointer()));
@@ -584,7 +788,7 @@ MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
   if((MEDCouplingUMesh *)_m==0)
     {
       updateTime();
-      _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCpy());
+      _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
       _m->renumberCells(_st->_num->getConstPointer(),true);
       return _m.retn();
     }
@@ -595,7 +799,7 @@ MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
       else
         {
           updateTime();
-          _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCpy());
+          _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
           _m->renumberCells(_st->_num->getConstPointer(),true);
           return _m.retn();
         }
@@ -631,7 +835,7 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other):RefCo
 
 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id):_m(this)
 {
-  const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& v=l2.getLev(id);
+  const std::vector< MCAuto<MEDFileUMeshPerType> >& v=l2.getLev(id);
   if(v.empty())
     return;
   int sz=v.size();
@@ -642,7 +846,7 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::st
   for(int i=0;i<sz;i++)
     {
       MEDCoupling1GTUMesh *elt(v[i]->getMesh());
-      MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp2=l2.getCoords();
+      MCAuto<DataArrayDouble> tmp2=l2.getCoords();
       elt->setCoords(tmp2);
       ms[i]=elt;
       pds[i]=v[i]->getPartDef();
@@ -721,21 +925,52 @@ std::vector<const BigMemoryObject *> MEDFileUMeshSplitL1::getDirectChildrenWithN
   return ret;
 }
 
-MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy(DataArrayDouble *coords) const
+MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::shallowCpyUsingCoords(DataArrayDouble *coords) const
 {
-  MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> ret=new MEDFileUMeshSplitL1(*this);
-  ret->_m_by_types=_m_by_types.deepCpy(coords);
+  MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1(*this));
+  ret->_m_by_types.shallowCpyMeshes();
+  ret->_m_by_types.setCoords(coords);
+  return ret.retn();
+}
+
+MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCopy(DataArrayDouble *coords) const
+{
+  MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1(*this));
+  ret->_m_by_types=_m_by_types.deepCopy(coords);
   if((const DataArrayInt *)_fam)
-    ret->_fam=_fam->deepCpy();
+    ret->_fam=_fam->deepCopy();
   if((const DataArrayInt *)_num)
-    ret->_num=_num->deepCpy();
+    ret->_num=_num->deepCopy();
   if((const DataArrayInt *)_rev_num)
-    ret->_rev_num=_rev_num->deepCpy();
+    ret->_rev_num=_rev_num->deepCopy();
   if((const DataArrayAsciiChar *)_names)
-    ret->_names=_names->deepCpy();
+    ret->_names=_names->deepCopy();
   return ret.retn();
 }
 
+void MEDFileUMeshSplitL1::checkConsistency() const
+{
+  if (!_fam || _fam->getNumberOfTuples() != getSize())
+    throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): internal family array has an invalid size!");
+  int nbCells = getSize();
+  if (_num)
+    {
+      _num->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array!");
+      int pos;
+      int maxValue=_num->getMaxValue(pos);
+      if (!_rev_num || _rev_num->getNumberOfTuples() != (maxValue+1))
+        throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal revert node numbering array!");
+    }
+  if ((_num && !_rev_num) || (!_num && _rev_num))
+    throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal numbering arrays (one is null)!");
+  if (_num && !_num->hasUniqueValues())
+    throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array: duplicates found!");
+  if (_names)
+    _names->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): internal cell naming array has an invalid size!");
+
+  _m_by_types.checkConsistency();
+}
+
 bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const
 {
   if(!_m_by_types.isEqual(other->_m_by_types,eps,what))
@@ -813,9 +1048,9 @@ void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld)
     {
       m->incrRef();
       _m=m;
-      _m_by_types.assignUMesh(dynamic_cast<MEDCouplingUMesh *>(m->deepCpy()));
-      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
-      if(!da->isIdentity())
+      _m_by_types.assignUMesh(dynamic_cast<MEDCouplingUMesh *>(m->deepCopy()));
+      MCAuto<DataArrayInt> da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
+      if(!da->isIota(m->getNumberOfCells()))
         {
           _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
           _m.updateTime();
@@ -826,7 +1061,7 @@ void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld)
   else
     {
       if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
-        throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh : the mode of mesh setting expects to follow the MED file numbering convention ! it is not the case !");
+        throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh(): the mesh does not follow the MED file numbering convention! Invoke sortCellsInMEDFileFrmt() first!");
       m->incrRef();
       _m_by_types.assignUMesh(m);
     }
@@ -891,7 +1126,7 @@ int MEDFileUMeshSplitL1::getSize() const
 
 MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const
 {
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> eltsToKeep=_fam->getIdsEqualList(idsBg,idsEnd);
+  MCAuto<DataArrayInt> eltsToKeep=_fam->findIdsEqualList(idsBg,idsEnd);
   MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true);
   if(renum)
     return renumIfNeeded(m,eltsToKeep->getConstPointer());
@@ -900,7 +1135,7 @@ MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int
 
 DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const
 {
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam->getIdsEqualList(idsBg,idsEnd);
+  MCAuto<DataArrayInt> da=_fam->findIdsEqualList(idsBg,idsEnd);
   if(renum)
     return renumIfNeededArr(da);
   return da.retn();
@@ -911,9 +1146,14 @@ std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshSplitL1::getGeoTypes(
   return _m_by_types.getGeoTypes();
 }
 
+int MEDFileUMeshSplitL1::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
+{
+  return _m_by_types.getNumberOfCellsWithType(ct);
+}
+
 MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
 {
-  MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp;
+  MCAuto<MEDCouplingUMesh> tmp;
   if(renum && ((const DataArrayInt *)_num))
     tmp=_m;
   else
@@ -933,7 +1173,7 @@ DataArrayInt *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::No
     return 0;
   int start(0),stop(0);
   _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
-  return fam->selectByTupleId2(start,stop,1);
+  return fam->selectByTupleIdSafeSlice(start,stop,1);
 }
 
 DataArrayInt *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
@@ -943,7 +1183,7 @@ DataArrayInt *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::No
     return 0;
   int start(0),stop(0);
   _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
-  return num->selectByTupleId2(start,stop,1);
+  return num->selectByTupleIdSafeSlice(start,stop,1);
 }
 
 DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField()
@@ -993,7 +1233,7 @@ void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<const MEDCoupli
 {
   std::vector< DataArrayInt * > corr;
   _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr);
-  std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corrMSafe(corr.begin(),corr.end());
+  std::vector< MCAuto<DataArrayInt> > corrMSafe(corr.begin(),corr.end());
   std::vector< std::vector<int> > fidsOfGroups;
   std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
   _fam=DataArrayInt::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups);
@@ -1014,14 +1254,14 @@ void MEDFileUMeshSplitL1::write(med_idt fid, const std::string& mName, int mdim)
     {
       int nbCells=(*it)->getNumberOfCells();
       int end=start+nbCells;
-      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam,num;
-      MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> names;
+      MCAuto<DataArrayInt> fam,num;
+      MCAuto<DataArrayAsciiChar> names;
       if((const DataArrayInt *)_fam)
-        fam=_fam->substr(start,end);
+        fam=_fam->subArray(start,end);
       if((const DataArrayInt *)_num)
-        num=_num->substr(start,end);
+        num=_num->subArray(start,end);
       if((const DataArrayAsciiChar *)_names)
-        names=static_cast<DataArrayAsciiChar *>(_names->substr(start,end));
+        names=static_cast<DataArrayAsciiChar *>(_names->subArray(start,end));
       MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names);
       start=end;
     }
@@ -1032,14 +1272,14 @@ void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N)
   _m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N);
 }
 
-void MEDFileUMeshSplitL1::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
+void MEDFileUMeshSplitL1::serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const
 {
   bigArraysI.push_back(_fam);
   bigArraysI.push_back(_num);
   _m_by_types.serialize(tinyInt,bigArraysI);
 }
 
-void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
+void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI)
 {
   _fam=bigArraysI.back(); bigArraysI.pop_back();
   _num=bigArraysI.back(); bigArraysI.pop_back();
@@ -1107,15 +1347,15 @@ MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDC
     m->renumberCells(renum->getConstPointer(),true);
   else
     {
-      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
+      MCAuto<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
       m->renumberCells(locnum->getConstPointer(),true);
     }
   return m;
 }
 
-MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
+MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI)
 {
-  MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1);
+  MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1);
   ret->unserialize(name,coo,tinyInt,bigArraysI);
   return ret.retn();
 }
@@ -1183,7 +1423,7 @@ void MEDFileUMeshAggregateCompute::setName(const std::string& name)
     }
   if(_mp_time>=_m_time)
     {
-      for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+      for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
         {
           MEDCoupling1GTUMesh *tmp(*it);
           if(tmp)
@@ -1195,7 +1435,7 @@ void MEDFileUMeshAggregateCompute::setName(const std::string& name)
 void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
 {
   std::size_t sz(mParts.size());
-  std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > ret(sz);
+  std::vector< MCAuto<MEDCoupling1GTUMesh> > ret(sz);
   for(std::size_t i=0;i<sz;i++)
     {
       const MEDCoupling1GTUMesh *elt(mParts[i]);
@@ -1249,7 +1489,7 @@ int MEDFileUMeshAggregateCompute::getNumberOfCells() const
   if(_mp_time<=_m_time)
     return _m->getNumberOfCells();
   int ret(0);
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+  for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
     ret+=(*it)->getNumberOfCells();
   return ret;
 }
@@ -1268,6 +1508,22 @@ std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshAggregateCompute::get
     return _m->getAllGeoTypesSorted();
 }
 
+int MEDFileUMeshAggregateCompute::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
+{
+  if(_mp_time>=_m_time)
+    {
+      for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+        {
+          const MEDCoupling1GTUMesh *elt(*it);
+          if(elt && elt->getCellModelEnum()==ct)
+            return elt->getNumberOfCells();
+        }
+      return 0;
+    }
+  else
+    return _m->getNumberOfCellsWithType(ct);
+}
+
 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::retrievePartsWithoutComputation() const
 {
   if(_mp_time<_m_time)
@@ -1275,7 +1531,7 @@ std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::retrievePartsWi
   //
   std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
   std::size_t i(0);
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
+  for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
     {
       const MEDCoupling1GTUMesh *elt(*it);
       ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
@@ -1328,7 +1584,7 @@ void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const i
 {
   if(_mp_time>_m_time)
     {
-      for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+      for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
         {
           MEDCoupling1GTUMesh *m(*it);
           if(m)
@@ -1355,7 +1611,7 @@ void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
         return ;// no needs to compte parts they are already here !
     }
   std::vector<MEDCouplingUMesh *> ms(m->splitByType());
-  std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
+  std::vector< MCAuto<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
   std::size_t sz(msMSafe.size());
   _m_parts.resize(sz);
   for(std::size_t i=0;i<sz;i++)
@@ -1382,7 +1638,7 @@ const PartDefinition *MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputati
   throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !");
 }
 
-void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
+void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const
 {
   if(_mp_time<_m_time)
     throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : the parts require a computation !");
@@ -1401,7 +1657,7 @@ void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vec
           DataArrayInt *elt(mesh1->getNodalConnectivity());
           if(elt)
             elt->incrRef();
-          MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt1(elt);
+          MCAuto<DataArrayInt> elt1(elt);
           bigArraysI.push_back(elt1);
         }
       else if(mesh2)
@@ -1411,7 +1667,7 @@ void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vec
             elt1->incrRef();
           if(elt2)
             elt2->incrRef();
-          MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt11(elt1),elt22(elt2);
+          MCAuto<DataArrayInt> elt11(elt1),elt22(elt2);
           bigArraysI.push_back(elt11); bigArraysI.push_back(elt22);
         }
       else
@@ -1429,7 +1685,7 @@ void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vec
     }
 }
 
-void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
+void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI)
 {
   int nbParts(tinyInt.back()); tinyInt.pop_back();
   _part_def.clear(); _part_def.resize(nbParts);
@@ -1437,7 +1693,7 @@ void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArra
   for(int i=0;i<nbParts;i++)
     {
       INTERP_KERNEL::NormalizedCellType tp((INTERP_KERNEL::NormalizedCellType) tinyInt.back()); tinyInt.pop_back();
-      MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> mesh(MEDCoupling1GTUMesh::New(name,tp));
+      MCAuto<MEDCoupling1GTUMesh> mesh(MEDCoupling1GTUMesh::New(name,tp));
       mesh->setCoords(coo);
       MEDCoupling1SGTUMesh *mesh1(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
       MEDCoupling1DGTUMesh *mesh2(dynamic_cast<MEDCoupling1DGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
@@ -1447,7 +1703,7 @@ void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArra
         }
       else if(mesh2)
         {
-          MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt0,elt1;
+          MCAuto<DataArrayInt> elt0,elt1;
           elt0=bigArraysI.back(); bigArraysI.pop_back();
           elt1=bigArraysI.back(); bigArraysI.pop_back();
           mesh2->setNodalConnectivity(elt0,elt1);
@@ -1482,7 +1738,7 @@ std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const
 std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const
 {
   std::size_t ret(0);
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+  for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
     {
       const MEDCoupling1GTUMesh *elt(*it);
       if(!elt)
@@ -1504,20 +1760,20 @@ std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const
 
 std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySizeWithoutChildren() const
 {
-  std::size_t ret(_m_parts.size()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>));
+  std::size_t ret(_m_parts.size()*sizeof(MCAuto<MEDCoupling1GTUMesh>));
   return ret;
 }
 
 std::vector<const BigMemoryObject *> MEDFileUMeshAggregateCompute::getDirectChildrenWithNull() const
 {
   std::vector<const BigMemoryObject *> ret;
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+  for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
     ret.push_back((const MEDCoupling1GTUMesh *)*it);
   ret.push_back((const MEDCouplingUMesh *)_m);
   return ret;
 }
 
-MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDouble *coords) const
+MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCopy(DataArrayDouble *coords) const
 {
   MEDFileUMeshAggregateCompute ret;
   ret._m_parts.resize(_m_parts.size());
@@ -1526,14 +1782,14 @@ MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDoub
       const MEDCoupling1GTUMesh *elt(_m_parts[i]);
       if(elt)
         {
-          ret._m_parts[i]=static_cast<ParaMEDMEM::MEDCoupling1GTUMesh*>(elt->deepCpy());
+          ret._m_parts[i]=static_cast<MEDCoupling::MEDCoupling1GTUMesh*>(elt->deepCopy());
           ret._m_parts[i]->setCoords(coords);
         }
     }
   ret._mp_time=_mp_time; ret._m_time=_m_time;
   if((const MEDCouplingUMesh *)_m)
     {
-      ret._m=static_cast<ParaMEDMEM::MEDCouplingUMesh*>(_m->deepCpy());
+      ret._m=static_cast<MEDCoupling::MEDCouplingUMesh*>(_m->deepCopy());
       ret._m->setCoords(coords);
     }
   std::size_t sz(_part_def.size());
@@ -1542,11 +1798,27 @@ MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDoub
     {
       const PartDefinition *elt(_part_def[i]);
       if(elt)
-        ret._part_def[i]=elt->deepCpy();
+        ret._part_def[i]=elt->deepCopy();
     }
   return ret;
 }
 
+void MEDFileUMeshAggregateCompute::shallowCpyMeshes()
+{
+  for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+    {
+      const MEDCoupling1GTUMesh *elt(*it);
+      if(elt)
+        {
+          MCAuto<MEDCouplingMesh> elt2(elt->clone(false));
+          *it=DynamicCastSafe<MEDCouplingMesh,MEDCoupling1GTUMesh>(elt2);
+        }
+    }
+  const MEDCouplingUMesh *m(_m);
+  if(m)
+    _m=m->clone(false);
+}
+
 bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const
 {
   const MEDCouplingUMesh *m1(getUmesh());
@@ -1588,16 +1860,26 @@ bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& o
   return true;
 }
 
+void MEDFileUMeshAggregateCompute::checkConsistency() const
+{
+  if(_mp_time >= _m_time)
+    for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();
+        it!=_m_parts.end(); it++)
+      (*it)->checkConsistency();
+  else
+    _m->checkConsistency();
+}
+
 void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const
 {
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+  for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
     MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it);
   MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m);
 }
 
 void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const
 {
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+  for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
     {
       const MEDCoupling1GTUMesh *tmp(*it);
       if(tmp)
@@ -1658,7 +1940,7 @@ std::vector<int> MEDFileUMeshAggregateCompute::getDistributionOfTypes() const
   else
     {
       std::vector<int> ret;
-      for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+      for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
         {
           const MEDCoupling1GTUMesh *tmp(*it);
           if(!tmp)
@@ -1682,7 +1964,7 @@ int MEDFileUMeshAggregateCompute::getSize() const
   else
     {
       int ret=0;
-      for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+      for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
         {
           const MEDCoupling1GTUMesh *m(*it);
           if(!m)
@@ -1695,7 +1977,7 @@ int MEDFileUMeshAggregateCompute::getSize() const
 
 void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords)
 {
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+  for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
     {
       MEDCoupling1GTUMesh *tmp(*it);
       if(tmp)