]> SALOME platform Git repositories - tools/medcoupling.git/blobdiff - src/MEDCoupling/MEDCoupling1GTUMesh.cxx
Salome HOME
Tests again and again
[tools/medcoupling.git] / src / MEDCoupling / MEDCoupling1GTUMesh.cxx
index 002298a14829ccd5696bd475c6a1cbd9716fe655..193b34f2fac44a4789f240039801c6a0c9bfbff2 100644 (file)
@@ -46,6 +46,20 @@ MEDCoupling1GTUMesh *MEDCoupling1GTUMesh::New(const char *name, INTERP_KERNEL::N
     return MEDCoupling1DGTUMesh::New(name,type);
 }
 
+MEDCoupling1GTUMesh *MEDCoupling1GTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
+{
+  if(!m)
+    throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : input mesh is null !");
+  std::set<INTERP_KERNEL::NormalizedCellType> gts(m->getAllGeoTypes());
+  if(gts.size()!=1)
+    throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : input mesh must have exactly one geometric type !");
+  const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*gts.begin());
+  if(!cm.isDynamic())
+    return MEDCoupling1SGTUMesh::New(m);
+  else
+    return MEDCoupling1DGTUMesh::New(m);
+}
+
 const INTERP_KERNEL::CellModel& MEDCoupling1GTUMesh::getCellModel() const throw(INTERP_KERNEL::Exception)
 {
   return *_cm;
@@ -120,13 +134,13 @@ std::set<INTERP_KERNEL::NormalizedCellType> MEDCoupling1GTUMesh::getAllGeoTypes(
  * This method returns in the same format as code (see MEDCouplingUMesh::checkTypeConsistencyAndContig or MEDCouplingUMesh::splitProfilePerType) how
  * \a this is composed in cell types.
  * The returned array is of size 3*n where n is the number of different types present in \a this. 
- * For every k in [0,n] ret[3*k+2]==0 because it has no sense here. 
+ * For every k in [0,n] ret[3*k+2]==-1 because it has no sense here. 
  * This parameter is kept only for compatibility with other methode listed above.
  */
 std::vector<int> MEDCoupling1GTUMesh::getDistributionOfTypes() const throw(INTERP_KERNEL::Exception)
 {
   std::vector<int> ret(3);
-  ret[0]=(int)getCellModelEnum(); ret[1]=getNumberOfCells(); ret[2]=0;
+  ret[0]=(int)getCellModelEnum(); ret[1]=getNumberOfCells(); ret[2]=-1;
   return ret;
 }
 
@@ -350,6 +364,91 @@ void MEDCoupling1GTUMesh::findCommonCells(int compType, int startCellId, DataArr
   m->findCommonCells(compType,startCellId,commonCellsArr,commonCellsIArr);
 }
 
+int MEDCoupling1GTUMesh::getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception)
+{
+  const DataArrayInt *c1(getNodalConnectivity());
+  if(!c1)
+    throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : no connectivity set !");
+  if(c1->getNumberOfComponents()!=1)
+    throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : Nodal connectivity array set must have exactly one component !");
+  if(!c1->isAllocated())
+    throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : Nodal connectivity array must be allocated !");
+  return c1->getNumberOfTuples();
+}
+
+/*!
+ * This method aggregates all the meshes in \a parts to put them in a single unstructured mesh (those returned).
+ * The order of cells is the returned instance is those in the order of instances in \a parts.
+ *
+ * \param [in] parts - all not null parts of single geo type meshes to be aggreagated having the same mesh dimension and same coordinates.
+ * \return MEDCouplingUMesh * - new object to be dealt by the caller.
+ *
+ * \throw If one element is null in \a parts.
+ * \throw If not all the parts do not have the same mesh dimension.
+ * \throw If not all the parts do not share the same coordinates.
+ * \throw If not all the parts have their connectivity set properly.
+ * \throw If \a parts is empty.
+ */
+MEDCouplingUMesh *MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(const std::vector< const MEDCoupling1GTUMesh *>& parts) throw(INTERP_KERNEL::Exception)
+{
+  if(parts.empty())
+    throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : input parts vector is empty !");
+  const MEDCoupling1GTUMesh *firstPart(parts[0]);
+  if(!firstPart)
+    throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : the first instance in input parts is null !");
+  const DataArrayDouble *coords(firstPart->getCoords());
+  int meshDim(firstPart->getMeshDimension());
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret(MEDCouplingUMesh::New(firstPart->getName().c_str(),meshDim)); ret->setDescription(firstPart->getDescription().c_str());
+  ret->setCoords(coords);
+  int nbOfCells(0),connSize(0);
+  for(std::vector< const MEDCoupling1GTUMesh *>::const_iterator it=parts.begin();it!=parts.end();it++)
+    {
+      if(!(*it))
+        throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : presence of null pointer in input vector !");
+      if((*it)->getMeshDimension()!=meshDim)
+        throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : all the instances in input vector must have same mesh dimension !");
+      if((*it)->getCoords()!=coords)
+        throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : all the instances must share the same coordinates pointer !");
+      nbOfCells+=(*it)->getNumberOfCells();
+      connSize+=(*it)->getNodalConnectivityLength();
+    }
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New()),connI(DataArrayInt::New());
+  connI->alloc(nbOfCells+1,1); conn->alloc(connSize+nbOfCells,1);
+  int *c(conn->getPointer()),*ci(connI->getPointer()); *ci=0;
+  for(std::vector< const MEDCoupling1GTUMesh *>::const_iterator it=parts.begin();it!=parts.end();it++)
+    {
+      int curNbCells((*it)->getNumberOfCells());
+      int geoType((int)(*it)->getCellModelEnum());
+      const int *cinPtr((*it)->getNodalConnectivity()->begin());
+      const MEDCoupling1SGTUMesh *ps(dynamic_cast<const MEDCoupling1SGTUMesh *>(*it));
+      const MEDCoupling1DGTUMesh *pd(dynamic_cast<const MEDCoupling1DGTUMesh *>(*it));
+      if(ps && !pd)
+        {
+          int nNodesPerCell(ps->getNumberOfNodesPerCell());
+          for(int i=0;i<curNbCells;i++,ci++,cinPtr+=nNodesPerCell)
+            {
+              *c++=geoType;
+              c=std::copy(cinPtr,cinPtr+nNodesPerCell,c);
+              ci[1]=ci[0]+nNodesPerCell+1;
+            }
+        }
+      else if(!ps && pd)
+        {
+          const int *ciinPtr(pd->getNodalConnectivityIndex()->begin());
+          for(int i=0;i<curNbCells;i++,ci++,ciinPtr++)
+            {
+              *c++=geoType;
+              c=std::copy(cinPtr+ciinPtr[0],cinPtr+ciinPtr[1],c);
+              ci[1]=ci[0]+ciinPtr[1]-ciinPtr[0]+1;
+            }
+        }
+      else
+        throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : presence of instance which type is not in [MEDCoupling1SGTUMesh,MEDCoupling1DGTUMesh] !");
+    }
+  ret->setConnectivity(conn,connI,true);
+  return ret.retn();
+}
+
 //==
 
 MEDCoupling1SGTUMesh::MEDCoupling1SGTUMesh(const MEDCoupling1SGTUMesh& other, bool recDeepCpy):MEDCoupling1GTUMesh(other,recDeepCpy),_conn(other._conn)
@@ -379,6 +478,43 @@ MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New(const char *name, INTERP_KERNEL:
   return new MEDCoupling1SGTUMesh(name,cm);
 }
 
+MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
+{
+  if(!m)
+    throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::New : input mesh is null !");
+  std::set<INTERP_KERNEL::NormalizedCellType> gts(m->getAllGeoTypes());
+  if(gts.size()!=1)
+    throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::New : input mesh must have exactly one geometric type !");
+  int geoType((int)*gts.begin());
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(m->getName().c_str(),*gts.begin()));
+  ret->setCoords(m->getCoords()); ret->setDescription(m->getDescription().c_str());
+  int nbCells(m->getNumberOfCells());
+  int nbOfNodesPerCell(ret->getNumberOfNodesPerCell());
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New()); conn->alloc(nbCells*nbOfNodesPerCell,1);
+  int *c(conn->getPointer());
+  const int *cin(m->getNodalConnectivity()->begin()),*ciin(m->getNodalConnectivityIndex()->begin());
+  for(int i=0;i<nbCells;i++,ciin++)
+    {
+      if(cin[ciin[0]]==geoType)
+        {
+          if(ciin[1]-ciin[0]==nbOfNodesPerCell+1)
+            c=std::copy(cin+ciin[0]+1,cin+ciin[1],c);
+          else
+            {
+              std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The size of cell is not those expected (" << nbOfNodesPerCell << ") !";
+              throw INTERP_KERNEL::Exception(oss.str().c_str());
+            }
+        }
+      else
+        {
+          std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The geometric type is not those expected !";
+          throw INTERP_KERNEL::Exception(oss.str().c_str());
+        }
+    }
+  ret->setNodalConnectivity(conn);
+  return ret.retn();
+}
+
 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::clone(bool recDeepCpy) const
 {
   return new MEDCoupling1SGTUMesh(*this,recDeepCpy);
@@ -480,9 +616,8 @@ bool MEDCoupling1SGTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *o
   return true;
 }
 
-void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
+void MEDCoupling1SGTUMesh::checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception)
 {
-  MEDCouplingPointSet::checkCoherency();
   const DataArrayInt *c1(_conn);
   if(c1)
     {
@@ -496,6 +631,12 @@ void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception
     throw INTERP_KERNEL::Exception("Nodal connectivity array not defined !");
 }
 
+void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
+{
+  MEDCouplingPointSet::checkCoherency();
+  checkCoherencyOfConnectivity();
+}
+
 void MEDCoupling1SGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
 {
   checkCoherency();
@@ -544,18 +685,6 @@ int MEDCoupling1SGTUMesh::getNumberOfNodesPerCell() const throw(INTERP_KERNEL::E
   return (int)_cm->getNumberOfNodes();
 }
 
-int MEDCoupling1SGTUMesh::getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception)
-{
-  const DataArrayInt *c1(_conn);
-  if(!c1)
-    throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::getNodalConnectivityLength : no connectivity set !");
-  if(c1->getNumberOfComponents()!=1)
-    throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::getNodalConnectivityLength : Nodal connectivity array set must have exactly one component !");
-  if(!c1->isAllocated())
-    throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::getNodalConnectivityLength : Nodal connectivity array must be allocated !");
-  return c1->getNumberOfTuples();
-}
-
 DataArrayInt *MEDCoupling1SGTUMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
 {
   checkNonDynamicGeoType();
@@ -574,6 +703,23 @@ DataArrayInt *MEDCoupling1SGTUMesh::computeNbOfFacesPerCell() const throw(INTERP
   return ret.retn();
 }
 
+DataArrayInt *MEDCoupling1SGTUMesh::computeEffectiveNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
+{
+  checkNonDynamicGeoType();
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
+  int nbCells(getNumberOfCells());
+  ret->alloc(nbCells,1);
+  int *retPtr(ret->getPointer());
+  int nbNodesPerCell(getNumberOfNodesPerCell());
+  const int *conn(_conn->begin());
+  for(int i=0;i<nbCells;i++,conn+=nbNodesPerCell,retPtr++)
+    {
+      std::set<int> s(conn,conn+nbNodesPerCell);
+      *retPtr=(int)s.size();
+    }
+  return ret.retn();
+}
+
 void MEDCoupling1SGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
 {
   int sz=getNumberOfNodesPerCell();
@@ -778,7 +924,7 @@ MEDCouplingMesh *MEDCoupling1SGTUMesh::mergeMyselfWith(const MEDCouplingMesh *ot
 
 MEDCouplingUMesh *MEDCoupling1SGTUMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
 {
-  MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName(),getMeshDimension());
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName().c_str(),getMeshDimension());
   ret->setCoords(getCoords());
   const int *nodalConn=_conn->begin();
   int nbCells=getNumberOfCells();
@@ -998,7 +1144,7 @@ MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesLL(std::vector<const
 MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const
 {
   int ncell=getNumberOfCells();
-  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName().c_str(),*_cm));
   ret->setCoords(_coords);
   std::size_t nbOfElemsRet=std::distance(begin,end);
   const int *inConn=_conn->getConstPointer();
@@ -1024,7 +1170,7 @@ MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2(int star
 {
   int ncell=getNumberOfCells();
   int nbOfElemsRet=DataArray::GetNumberOfItemGivenBESRelative(start,end,step,"MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2 : ");
-  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName().c_str(),*_cm));
   ret->setCoords(_coords);
   const int *inConn=_conn->getConstPointer();
   int sz=getNumberOfNodesPerCell();
@@ -1046,9 +1192,28 @@ MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2(int star
   return ret.retn();
 }
 
+void MEDCoupling1SGTUMesh::computeNodeIdsAlg(std::vector<bool>& nodeIdsInUse) const throw(INTERP_KERNEL::Exception)
+{
+  int sz((int)nodeIdsInUse.size());
+  int nbCells(getNumberOfCells());
+  int nbOfNodesPerCell(getNumberOfNodesPerCell());
+  const int *w(_conn->begin());
+  for(int i=0;i<nbCells;i++)
+    for(int j=0;j<nbOfNodesPerCell;j++,w++)
+      {
+        if(*w>=0 && *w<sz)
+          nodeIdsInUse[*w]=true;
+        else
+          {
+            std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::computeNodeIdsAlg : At cell #" << i << " presence of node id #" << *w << " should be in [0," << sz << ") !";
+            throw INTERP_KERNEL::Exception(oss.str().c_str());
+          }
+      }
+}
+
 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception)
 {
-  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName().c_str(),*_cm));
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1;
   const DataArrayInt *nodalConn(_conn);
   if(!nodalConn)
@@ -1200,7 +1365,7 @@ void MEDCoupling1SGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, do
   MEDCouplingPointSet::checkFastEquivalWith(other,prec);
   const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
   if(!otherC)
-    throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : Two meshes are not not unstructured with single static geometric type !");
+    throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : Two meshes are not unstructured with single static geometric type !");
   const DataArrayInt *c1(_conn),*c2(otherC->_conn);
   if(c1==c2)
     return;
@@ -1333,7 +1498,7 @@ void MEDCoupling1SGTUMesh::insertNextCell(const int *nodalConnOfCellBg, const in
     }
 }
 
-//== find static tony
+//== 
 
 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
 {
@@ -1498,7 +1663,7 @@ void MEDCoupling1DGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, do
   MEDCouplingPointSet::checkFastEquivalWith(other,prec);
   const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
   if(!otherC)
-    throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : Two meshes are not not unstructured with single static geometric type !");
+    throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : Two meshes are not unstructured with single dynamic geometric type !");
   const DataArrayInt *c1(_conn),*c2(otherC->_conn);
   if(c1!=c2)
     {
@@ -1525,14 +1690,8 @@ void MEDCoupling1DGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, do
     }
 }
 
-/*!
- * If \a this pass this method, you are sure that connectivity arrays are not null, with exactly one component, no name, no component name, allocated.
- * In addition you are sure that the length of nodal connectivity index array is bigger than or equal to one.
- * In addition you are also sure that length of nodal connectivity is coherent with the content of the last value in the index array.
- */
-void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
+void MEDCoupling1DGTUMesh::checkCoherencyOfConnectivity() const throw(INTERP_KERNEL::Exception)
 {
-  MEDCouplingPointSet::checkCoherency();
   const DataArrayInt *c1(_conn);
   if(c1)
     {
@@ -1578,11 +1737,22 @@ void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception
   int szOfC1Exp=_conn_indx->back();
   if(sz2<szOfC1Exp)
     {
-      std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::checkCoherency : The expected length of nodal connectivity array regarding index is " << szOfC1Exp << " but the actual size of it is " << c1->getNumberOfTuples() << " !";
+      std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::checkCoherencyOfConnectivity : The expected length of nodal connectivity array regarding index is " << szOfC1Exp << " but the actual size of it is " << c1->getNumberOfTuples() << " !";
       throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
 }
 
+/*!
+ * If \a this pass this method, you are sure that connectivity arrays are not null, with exactly one component, no name, no component name, allocated.
+ * In addition you are sure that the length of nodal connectivity index array is bigger than or equal to one.
+ * In addition you are also sure that length of nodal connectivity is coherent with the content of the last value in the index array.
+ */
+void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
+{
+  MEDCouplingPointSet::checkCoherency();
+  checkCoherencyOfConnectivity();
+}
+
 void MEDCoupling1DGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
 {
   checkCoherency();
@@ -1611,7 +1781,7 @@ void MEDCoupling1DGTUMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL
 
 int MEDCoupling1DGTUMesh::getNumberOfCells() const
 {
-  checkCoherency();//do not remove
+  checkCoherencyOfConnectivity();//do not remove
   return _conn_indx->getNumberOfTuples()-1;
 }
 
@@ -1669,6 +1839,41 @@ DataArrayInt *MEDCoupling1DGTUMesh::computeNbOfFacesPerCell() const throw(INTERP
   return ret.retn();
 }
 
+/*!
+ * This method computes effective number of nodes per cell. That is to say nodes appearing several times in nodal connectivity of a cell,
+ * will be counted only once here whereas it will be counted several times in MEDCoupling1DGTUMesh::computeNbOfNodesPerCell method.
+ *
+ * \return DataArrayInt * - new object to be deallocated by the caller.
+ * \sa MEDCoupling1DGTUMesh::computeNbOfNodesPerCell
+ */
+DataArrayInt *MEDCoupling1DGTUMesh::computeEffectiveNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
+{
+  checkCoherency();
+  _conn_indx->checkMonotonic(true);
+  int nbOfCells(_conn_indx->getNumberOfTuples()-1);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
+  ret->alloc(nbOfCells,1);
+  int *retPtr(ret->getPointer());
+  const int *ci(_conn_indx->begin()),*c(_conn->begin());
+  if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
+    {
+      for(int i=0;i<nbOfCells;i++,retPtr++,ci++)
+        {
+          std::set<int> s(c+ci[0],c+ci[1]);
+          *retPtr=(int)s.size();
+        }
+    }
+  else
+    {
+      for(int i=0;i<nbOfCells;i++,retPtr++,ci++)
+        {
+          std::set<int> s(c+ci[0],c+ci[1]); s.erase(-1);
+          *retPtr=(int)s.size();
+        }
+    }
+  return ret.retn();
+}
+
 void MEDCoupling1DGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
 {
   int nbOfCells=getNumberOfCells();//performs checks
@@ -1884,7 +2089,7 @@ MEDCouplingMesh *MEDCoupling1DGTUMesh::mergeMyselfWith(const MEDCouplingMesh *ot
 
 MEDCouplingUMesh *MEDCoupling1DGTUMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
 {
-  MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName(),getMeshDimension());
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName().c_str(),getMeshDimension());
   ret->setCoords(getCoords());
   const int *nodalConn=_conn->begin(),*nodalConnI=_conn_indx->begin();
   int nbCells=getNumberOfCells();//checkCoherency
@@ -1970,7 +2175,7 @@ MEDCouplingPointSet *MEDCoupling1DGTUMesh::mergeMyselfWithOnSameCoords(const MED
 MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const
 {
   checkCoherency();
-  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm));
   ret->setCoords(_coords);
   DataArrayInt *c=0,*ci=0;
   MEDCouplingUMesh::ExtractFromIndexedArrays(begin,end,_conn,_conn_indx,c,ci);
@@ -1982,7 +2187,7 @@ MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords(const int
 MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords2(int start, int end, int step) const
 {
   checkCoherency();
-  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm));
   ret->setCoords(_coords);
   DataArrayInt *c=0,*ci=0;
   MEDCouplingUMesh::ExtractFromIndexedArrays2(start,end,step,_conn,_conn_indx,c,ci);
@@ -1991,6 +2196,25 @@ MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords2(int star
   return ret.retn();
 }
 
+void MEDCoupling1DGTUMesh::computeNodeIdsAlg(std::vector<bool>& nodeIdsInUse) const throw(INTERP_KERNEL::Exception)
+{
+  int sz((int)nodeIdsInUse.size());
+  int nbCells(getNumberOfCells());
+  const int *w(_conn->begin()),*wi(_conn_indx->begin());
+  for(int i=0;i<nbCells;i++,wi++)
+    for(const int *pt=w+wi[0];pt!=w+wi[1];pt++)
+      if(*pt!=-1)
+        {
+          if(*pt>=0 && *pt<sz)
+            nodeIdsInUse[*pt]=true;
+          else
+            {
+              std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeNodeIdsAlg : At cell #" << i << " presence of node id #" << *pt << " should be in [0," << sz << ") !";
+              throw INTERP_KERNEL::Exception(oss.str().c_str());
+            }
+        }
+}
+
 void MEDCoupling1DGTUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception)
 {
   checkFullyDefined();
@@ -2269,7 +2493,7 @@ DataArrayInt *MEDCoupling1DGTUMesh::getNodalConnectivityIndex() const throw(INTE
  */
 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::copyWithNodalConnectivityPacked(bool& isShallowCpyOfNodalConnn) const throw(INTERP_KERNEL::Exception)
 {
-  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm));
   DataArrayInt *nc=0,*nci=0;
   isShallowCpyOfNodalConnn=retrievePackedNodalConnectivity(nc,nci);
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ncs(nc),ncis(nci);
@@ -2452,7 +2676,7 @@ MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshesLL(std::vector<const
 
 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception)
 {
-  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName().c_str(),*_cm));
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1,tmp2;
   const DataArrayInt *nodalConn(_conn),*nodalConnI(_conn_indx);
   if(!nodalConn)
@@ -2530,3 +2754,43 @@ DataArrayInt *MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds(const std:
     }
   return ret.retn();
 }
+
+MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
+{
+  if(!m)
+    throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : input mesh is null !");
+  std::set<INTERP_KERNEL::NormalizedCellType> gts(m->getAllGeoTypes());
+  if(gts.size()!=1)
+    throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : input mesh must have exactly one geometric type !");
+  int geoType((int)*gts.begin());
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(MEDCoupling1DGTUMesh::New(m->getName().c_str(),*gts.begin()));
+  ret->setCoords(m->getCoords()); ret->setDescription(m->getDescription().c_str());
+  int nbCells(m->getNumberOfCells());
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New()),connI(DataArrayInt::New());
+  conn->alloc(m->getMeshLength()-nbCells,1); connI->alloc(nbCells+1,1);
+  int *c(conn->getPointer()),*ci(connI->getPointer()); *ci=0;
+  const int *cin(m->getNodalConnectivity()->begin()),*ciin(m->getNodalConnectivityIndex()->begin());
+  for(int i=0;i<nbCells;i++,ciin++,ci++)
+    {
+      if(cin[ciin[0]]==geoType)
+        {
+          if(ciin[1]-ciin[0]>=1)
+            {
+              c=std::copy(cin+ciin[0]+1,cin+ciin[1],c);
+              ci[1]=ci[0]+ciin[1]-ciin[0]-1;
+            }
+          else
+            {
+              std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The size of cell is not >=0 !";
+              throw INTERP_KERNEL::Exception(oss.str().c_str());
+            }
+        }
+      else
+        {
+          std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The geometric type is not those expected !";
+          throw INTERP_KERNEL::Exception(oss.str().c_str());
+        }
+    }
+  ret->setNodalConnectivity(conn,connI);
+  return ret.retn();
+}