]> SALOME platform Git repositories - tools/medcoupling.git/blobdiff - src/MEDCoupling/MEDCouplingStructuredMesh.cxx
Salome HOME
Generalization of unstructured grid supported by the remapper.
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingStructuredMesh.cxx
index 6127b68c6d20109a633794fd9ead08c810ad6183..2c92df2413901e1b4e860adb3e2751b7fcd20cfa 100644 (file)
@@ -125,6 +125,18 @@ DataArrayInt *MEDCouplingStructuredMesh::computeNbOfFacesPerCell() const throw(I
   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 MEDCouplingMesh::computeNbOfNodesPerCell method.
+ * Here for structured mesh it returns exactly as MEDCouplingStructuredMesh::computeNbOfNodesPerCell does.
+ *
+ * \return DataArrayInt * - new object to be deallocated by the caller.
+ */
+DataArrayInt *MEDCouplingStructuredMesh::computeEffectiveNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
+{
+  return computeNbOfNodesPerCell();
+}
+
 void MEDCouplingStructuredMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
 {
   int meshDim=getMeshDimension();
@@ -139,13 +151,13 @@ void MEDCouplingStructuredMesh::getNodeIdsOfCell(int cellId, std::vector<int>& c
       conn.push_back(tmp2[0]); conn.push_back(tmp2[0]+1);
       break;
     case 2:
-      conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]); conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+1);
-      conn.push_back((tmp2[1]+1)*(tmpCell[1]+1)+tmp2[0]+1); conn.push_back((tmp2[1]+1)*(tmpCell[1]+1)+tmp2[0]);
+      conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]); conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+1);
+      conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+1); conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]);
       break;
     case 3:
-      conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+tmp2[2]*tmpNode[2]); conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+1+tmp2[2]*tmpNode[2]);
+      conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+tmp2[2]*tmpNode[2]); conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+1+tmp2[2]*tmpNode[2]);
       conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+1+tmp2[2]*tmpNode[2]); conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+tmp2[2]*tmpNode[2]);
-      conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+(tmp2[2]+1)*tmpNode[2]); conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+1+(tmp2[2]+1)*tmpNode[2]);
+      conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+(tmp2[2]+1)*tmpNode[2]); conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+1+(tmp2[2]+1)*tmpNode[2]);
       conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+1+(tmp2[2]+1)*tmpNode[2]); conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+(tmp2[2]+1)*tmpNode[2]);
       break;
     default:
@@ -232,8 +244,8 @@ DataArrayInt *MEDCouplingStructuredMesh::checkTypeConsistencyAndContig(const std
  */
 void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
 {
-  if(!profile)
-    throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile is NULL !");
+  if(!profile || !profile->isAllocated())
+    throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile is NULL or not allocated !");
   if(profile->getNumberOfComponents()!=1)
     throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile should have exactly one component !");
   int nbTuples=profile->getNumberOfTuples();
@@ -244,35 +256,48 @@ void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile,
   if(profile->isIdentity() && nbTuples==nbOfCells)
     {
       code[2]=-1;
-      idsInPflPerType[0]=const_cast<DataArrayInt *>(profile); idsInPflPerType[0]->incrRef();
-      idsPerType.clear(); 
+      idsInPflPerType[0]=0;
+      idsPerType.clear();
+      return ;
     }
+  code[1]=profile->getNumberOfTuples();
   code[2]=0;
   profile->checkAllIdsInRange(0,nbOfCells);
   idsPerType.resize(1);
-  idsPerType[0]=const_cast<DataArrayInt *>(profile); idsPerType[0]->incrRef();
+  idsPerType[0]=profile->deepCpy();
   idsInPflPerType[0]=DataArrayInt::Range(0,nbTuples,1);
 }
 
 /*!
- * Creates a new unstructured mesh (MEDCouplingUMesh) from \a this structured one.
+ * Creates a new unstructured mesh (MEDCoupling1SGTUMesh) from \a this structured one.
  *  \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
  * delete this array using decrRef() as it is no more needed. 
  *  \throw If \a this->getMeshDimension() is not among [1,2,3].
  */
-MEDCouplingUMesh *MEDCouplingStructuredMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
+MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const throw(INTERP_KERNEL::Exception)
 {
   int meshDim=getMeshDimension(); 
   if(meshDim<0 || meshDim>3)
-    throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::buildUnstructured : meshdim must be in [1,2,3] !");
-  
+    throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTUnstructured : meshdim must be in [1,2,3] !");
   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords(getCoordinatesAndOwner());
   int ns[3];
   getNodeGridStructure(ns);
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(Build1GTNodalConnectivity(ns,ns+meshDim));
-  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim)));
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(getName().c_str(),GetGeoTypeGivenMeshDimension(meshDim)));
   ret->setNodalConnectivity(conn); ret->setCoords(coords);
-  return ret->buildUnstructured();
+  return ret.retn();
+}
+
+/*!
+ * Creates a new unstructured mesh (MEDCouplingUMesh) from \a this structured one.
+ *  \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
+ * delete this array using decrRef() as it is no more needed. 
+ *  \throw If \a this->getMeshDimension() is not among [1,2,3].
+ */
+MEDCouplingUMesh *MEDCouplingStructuredMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
+{
+  MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret0(build1SGTUnstructured());
+  return ret0->buildUnstructured();
 }
 
 /*!
@@ -512,6 +537,7 @@ bool MEDCouplingStructuredMesh::IsPartStructured(const int *startIds, const int
       return true;
     }
   GetPosFromId(startIds[sz-1],dim,&tmp2[0],&tmp3[0]);
+  int szExp(1);
   for(int i=0;i<dim;i++)
     {
       if(tmp3[i]<0 || tmp3[i]>=st[i])
@@ -520,7 +546,10 @@ bool MEDCouplingStructuredMesh::IsPartStructured(const int *startIds, const int
       tmp4[i]=partCompactFormat[i].second-partCompactFormat[i].first;
       if(tmp4[i]<=0)
         return false;
+      szExp*=tmp4[i];
     }
+  if(szExp!=(int)sz)
+    return false;
   const int *w(startIds);
   switch(dim)
     {