]> SALOME platform Git repositories - tools/medcoupling.git/blobdiff - src/MEDCoupling/MEDCoupling1GTUMesh.cxx
Salome HOME
Generalization of unstructured grid supported by the remapper.
[tools/medcoupling.git] / src / MEDCoupling / MEDCoupling1GTUMesh.cxx
index 9b9a2104d2cb5587ab05cc211b9b1d9271344b1f..484ed7aeab16fd68e23ceca625d94ad43a2d5eef 100644 (file)
@@ -679,6 +679,11 @@ int MEDCoupling1SGTUMesh::getNumberOfCells() const
   return nbOfTuples/nbOfNodesPerCell;
 }
 
+int MEDCoupling1SGTUMesh::getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception)
+{
+  return getNumberOfNodesPerCell();
+}
+
 int MEDCoupling1SGTUMesh::getNumberOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
 {
   checkNonDynamicGeoType();
@@ -1524,16 +1529,10 @@ MEDCoupling1GTUMesh *MEDCoupling1SGTUMesh::computeDualMesh() const throw(INTERP_
 
 MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh3D() const throw(INTERP_KERNEL::Exception)
 {
-  /*static const int DUAL_CONN_TETRA_0[48]={
-    8,5,14,4, 10,4,14,7, 11,7,14,5, 
-    8,4,14,5, 9,6,14,4, 12,5,14,6,
-    10,7,14,4, 9,4,14,6, 13,7,14,6,
-    11,5,14,7, 13,7,14,6, 12,6,14,5
-    };*/
   static const int DUAL_TETRA_0[36]={
     4,1,0, 6,0,3, 7,3,1,
     4,0,1, 5,2,0, 8,1,2,
-    6,3,0, 5,0,2, 9,3,2,
+    6,3,0, 5,0,2, 9,2,3,
     7,1,3, 9,3,2, 8,2,1
   };
   static const int DUAL_TETRA_1[36]={
@@ -1563,7 +1562,7 @@ MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh3D() const throw(INTE
   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> zeArr(DataArrayDouble::Aggregate(v)); baryArr=0; edgesBaryArr=0; facesBaryArr=0;
   std::string name("DualOf_"); name+=getName();
   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(MEDCoupling1DGTUMesh::New(name.c_str(),INTERP_KERNEL::NORM_POLYHED)); ret->setCoords(zeArr);
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cArr(DataArrayInt::New()),ciArr(DataArrayInt::New()); ciArr->alloc(nbOfNodes+1,0); ciArr->setIJ(0,0,0); cArr->alloc(0,1);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cArr(DataArrayInt::New()),ciArr(DataArrayInt::New()); ciArr->alloc(nbOfNodes+1,1); ciArr->setIJ(0,0,0); cArr->alloc(0,1);
   for(int i=0;i<nbOfNodes;i++,revNodI++)
     {
       int nbOfCellsSharingNode(revNodI[1]-revNodI[0]);
@@ -1577,6 +1576,7 @@ MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh3D() const throw(INTE
           int curCellId(revNod[revNodI[0]+j]);
           const int *connOfCurCell(nodal+4*curCellId);
           std::size_t nodePosInCurCell(std::distance(connOfCurCell,std::find(connOfCurCell,connOfCurCell+4,i)));
+          if(j!=0) cArr->pushBackSilent(-1);
           int tmp[14];
           //
           tmp[0]=d1[6*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+0]-4]+offset0; tmp[1]=d2[4*curCellId+DUAL_TETRA_0[nodePosInCurCell*9+1]]+nbOfNodes;
@@ -1591,7 +1591,7 @@ MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh3D() const throw(INTE
           int kk(0);
           for(int k=0;k<4;k++)
             {
-              if(FACEID_NOT_SH_NODE[k]!=(int)nodePosInCurCell)
+              if(FACEID_NOT_SH_NODE[nodePosInCurCell]!=k)
                 {
                   const int *faceId(d2+4*curCellId+k);
                   if(rdi2[*faceId+1]-rdi2[*faceId]==1)
@@ -1606,7 +1606,7 @@ MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh3D() const throw(INTE
                 }
             }
         }
-      ciArr->pushBackSilent(cArr->getNumberOfTuples());
+      ciArr->setIJ(i+1,0,cArr->getNumberOfTuples());
     }
   ret->setNodalConnectivity(cArr,ciArr);
   return ret.retn();
@@ -1614,8 +1614,8 @@ MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh3D() const throw(INTE
 
 MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh2D() const throw(INTERP_KERNEL::Exception)
 {
-  static const int DUAL_TRI_0[6]={2,0, 0,1, 1,2};
-  static const int DUAL_TRI_1[6]={+3,-5, -3,+4, -4,+5};
+  static const int DUAL_TRI_0[6]={0,2, 1,0, 2,1};
+  static const int DUAL_TRI_1[6]={-3,+5, +3,-4, +4,-5};
   static const int FACEID_NOT_SH_NODE[3]={1,2,0};
   if(getCellModelEnum()!=INTERP_KERNEL::NORM_TRI3)
     throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::computeDualMesh2D : only TRI3 supported !");
@@ -1634,7 +1634,7 @@ MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh2D() const throw(INTE
   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> zeArr(DataArrayDouble::Aggregate(v)); baryArr=0; edgesBaryArr=0;
   std::string name("DualOf_"); name+=getName();
   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(MEDCoupling1DGTUMesh::New(name.c_str(),INTERP_KERNEL::NORM_POLYGON)); ret->setCoords(zeArr);
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cArr(DataArrayInt::New()),ciArr(DataArrayInt::New()); ciArr->alloc(nbOfNodes+1,0); ciArr->setIJ(0,0,0); cArr->alloc(0,1);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cArr(DataArrayInt::New()),ciArr(DataArrayInt::New()); ciArr->alloc(nbOfNodes+1,1); ciArr->setIJ(0,0,0); cArr->alloc(0,1);
   for(int i=0;i<nbOfNodes;i++,revNodI++)
     {
       int nbOfCellsSharingNode(revNodI[1]-revNodI[0]);
@@ -1655,7 +1655,7 @@ MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh2D() const throw(INTE
           int kk(0);
           for(int k=0;k<3;k++)
             {
-              if(FACEID_NOT_SH_NODE[k]!=(int)nodePosInCurCell)
+              if(FACEID_NOT_SH_NODE[nodePosInCurCell]!=k)
                 {
                   const int *edgeId(d2+3*curCellId+k);
                   if(rdi2[*edgeId+1]-rdi2[*edgeId]==1)
@@ -1674,7 +1674,7 @@ MEDCoupling1DGTUMesh *MEDCoupling1SGTUMesh::computeDualMesh2D() const throw(INTE
         }
       std::vector<int> zePolyg(MEDCoupling1DGTUMesh::BuildAPolygonFromParts(polyg));
       cArr->insertAtTheEnd(zePolyg.begin(),zePolyg.end());
-      ciArr->pushBackSilent(cArr->getNumberOfTuples());
+      ciArr->setIJ(i+1,0,cArr->getNumberOfTuples());
     }
   ret->setNodalConnectivity(cArr,ciArr);
   return ret.retn();
@@ -2058,7 +2058,7 @@ DataArrayInt *MEDCoupling1DGTUMesh::computeEffectiveNbOfNodesPerCell() const thr
 
 void MEDCoupling1DGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
 {
-  int nbOfCells=getNumberOfCells();//performs checks
+  int nbOfCells(getNumberOfCells());//performs checks
   if(cellId>=0 && cellId<nbOfCells)
     {
       int strt=_conn_indx->getIJ(cellId,0),stp=_conn_indx->getIJ(cellId+1,0);
@@ -2070,7 +2070,23 @@ void MEDCoupling1DGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn)
     }
   else
     {
-      std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsOfCell : request for cellId #" << cellId << " must be in [0," << nbOfCells << ") !";
+      std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getNodeIdsOfCell : request for cellId #" << cellId << " must be in [0," << nbOfCells << ") !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+}
+
+int MEDCoupling1DGTUMesh::getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception)
+{
+  int nbOfCells(getNumberOfCells());//performs checks
+  if(cellId>=0 && cellId<nbOfCells)
+    {
+      const int *conn(_conn->begin());
+      int strt=_conn_indx->getIJ(cellId,0),stp=_conn_indx->getIJ(cellId+1,0);
+      return stp-strt-std::count(conn+strt,conn+stp,-1);
+    }
+  else
+    {
+      std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getNumberOfNodesInCell : request for cellId #" << cellId << " must be in [0," << nbOfCells << ") !";
       throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
 }
@@ -2493,7 +2509,7 @@ DataArrayInt *MEDCoupling1DGTUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const
           int nodeId=conn[conni[0]+j];
           if(nodeId==-1) continue;
           if(nodeId>=0 && nodeId<nbOfNodes)
-            traducer[*conn]=1;
+            traducer[nodeId]=1;
           else
             {
               std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getNodeIdsInUse : In cell #" << i  << " presence of node id " <<  nodeId << " not in [0," << nbOfNodes << ") !";