]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
UMesh.computeEnlargedNeighborsOfNodes
authorAnthony Geay <anthony.geay@edf.fr>
Mon, 24 Apr 2017 06:57:24 +0000 (08:57 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 24 Apr 2017 06:57:24 +0000 (08:57 +0200)
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling/MEDCouplingUMesh.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 2757c52aec249dd9cab5e70cea4c85b534480186..5b703368c1306577be440a2ef93ae9632a0ace79 100644 (file)
@@ -589,18 +589,15 @@ void MEDCouplingUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double
 void MEDCouplingUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const
 {
   checkFullyDefined();
-  int nbOfNodes=getNumberOfNodes();
+  int nbOfNodes(getNumberOfNodes());
   int *revNodalIndxPtr=(int *)malloc((nbOfNodes+1)*sizeof(int));
   revNodalIndx->useArray(revNodalIndxPtr,true,C_DEALLOC,nbOfNodes+1,1);
   std::fill(revNodalIndxPtr,revNodalIndxPtr+nbOfNodes+1,0);
-  const int *conn=_nodal_connec->getConstPointer();
-  const int *connIndex=_nodal_connec_index->getConstPointer();
-  int nbOfCells=getNumberOfCells();
-  int nbOfEltsInRevNodal=0;
+  const int *conn(_nodal_connec->begin()),*connIndex(_nodal_connec_index->begin());
+  int nbOfCells(getNumberOfCells()),nbOfEltsInRevNodal(0);
   for(int eltId=0;eltId<nbOfCells;eltId++)
     {
-      const int *strtNdlConnOfCurCell=conn+connIndex[eltId]+1;
-      const int *endNdlConnOfCurCell=conn+connIndex[eltId+1];
+      const int *strtNdlConnOfCurCell(conn+connIndex[eltId]+1),*endNdlConnOfCurCell(conn+connIndex[eltId+1]);
       for(const int *iter=strtNdlConnOfCurCell;iter!=endNdlConnOfCurCell;iter++)
         if(*iter>=0)//for polyhedrons
           {
@@ -838,10 +835,10 @@ void MEDCouplingUMesh::ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, cons
 {
   if(!desc || !descIndx || !revDesc || !revDescIndx)
     throw INTERP_KERNEL::Exception("MEDCouplingUMesh::ComputeNeighborsOfCellsAdv some input array is empty !");
-  const int *descPtr=desc->getConstPointer();
-  const int *descIPtr=descIndx->getConstPointer();
-  const int *revDescPtr=revDesc->getConstPointer();
-  const int *revDescIPtr=revDescIndx->getConstPointer();
+  const int *descPtr=desc->begin();
+  const int *descIPtr=descIndx->begin();
+  const int *revDescPtr=revDesc->begin();
+  const int *revDescIPtr=revDescIndx->begin();
   //
   int nbCells=descIndx->getNumberOfTuples()-1;
   MCAuto<DataArrayInt> out0=DataArrayInt::New();
@@ -863,6 +860,35 @@ void MEDCouplingUMesh::ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, cons
   neighborsIndx=out1.retn();
 }
 
+/*!
+ * Explodes \a this into edges whatever its dimension.
+ */
+MCAuto<MEDCouplingUMesh> MEDCouplingUMesh::explodeIntoEdges(MCAuto<DataArrayInt>& desc, MCAuto<DataArrayInt>& descIndex, MCAuto<DataArrayInt>& revDesc, MCAuto<DataArrayInt>& revDescIndx) const
+{
+  checkFullyDefined();
+  int mdim(getMeshDimension());
+  desc=DataArrayInt::New(); descIndex=DataArrayInt::New(); revDesc=DataArrayInt::New(); revDescIndx=DataArrayInt::New();
+  MCAuto<MEDCouplingUMesh> mesh1D;
+  switch(mdim)
+  {
+    case 3:
+      {
+        mesh1D=explode3DMeshTo1D(desc,descIndex,revDesc,revDescIndx);
+        break;
+      }
+    case 2:
+      {
+        mesh1D=buildDescendingConnectivity(desc,descIndex,revDesc,revDescIndx);
+        break;
+      }
+    default:
+      {
+        throw INTERP_KERNEL::Exception("MEDCouplingUMesh::computeNeighborsOfNodes : Mesh dimension supported are [3,2] !");
+      }
+  }
+  return mesh1D;
+}
+
 /*!
  * \b WARNING this method do the assumption that connectivity lies on the coordinates set.
  * For speed reasons no check of this will be done. This method calls
@@ -877,13 +903,15 @@ void MEDCouplingUMesh::ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, cons
  * The number of tuples is equal to the last values in \b neighborsIndx.
  * \param [out] neighborsIdx is an array of size this->getNumberOfCells()+1 newly allocated and should
  * be dealt by the caller. This arrays allow to use the first output parameter \b neighbors.
+ * 
+ * \sa MEDCouplingUMesh::computeEnlargedNeighborsOfNodes
  */
 void MEDCouplingUMesh::computeNeighborsOfNodes(DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx) const
 {
   checkFullyDefined();
   int mdim(getMeshDimension()),nbNodes(getNumberOfNodes());
   MCAuto<DataArrayInt> desc(DataArrayInt::New()),descIndx(DataArrayInt::New()),revDesc(DataArrayInt::New()),revDescIndx(DataArrayInt::New());
-  MCAuto<MEDCouplingUMesh> mesh1D;
+  MCConstAuto<MEDCouplingUMesh> mesh1D;
   switch(mdim)
   {
     case 3:
@@ -898,8 +926,7 @@ void MEDCouplingUMesh::computeNeighborsOfNodes(DataArrayInt *&neighbors, DataArr
       }
     case 1:
       {
-        mesh1D=const_cast<MEDCouplingUMesh *>(this);
-        mesh1D->incrRef();
+        mesh1D.takeRef(this);
         break;
       }
     default:
@@ -922,6 +949,45 @@ void MEDCouplingUMesh::computeNeighborsOfNodes(DataArrayInt *&neighbors, DataArr
   neighborsIdx=descIndx.retn();
 }
 
+/*!
+ * Computes enlarged neighbors for each nodes in \a this. The behavior of this method is close to MEDCouplingUMesh::computeNeighborsOfNodes except that the neighborhood of each node is wider here.
+ * A node j is considered to be in the neighborhood of i if and only if there is a cell in \a this containing in its nodal connectivity both i and j.
+ * This method is useful to find ghost cells of a part of a mesh with a code based on fields on nodes.
+ * 
+ * \sa MEDCouplingUMesh::computeNeighborsOfNodes
+ */
+void MEDCouplingUMesh::computeEnlargedNeighborsOfNodes(MCAuto<DataArrayInt> &neighbors, MCAuto<DataArrayInt>& neighborsIdx) const
+{
+  checkFullyDefined();
+  int nbOfNodes(getNumberOfNodes());
+  const int *conn(_nodal_connec->begin()),*connIndex(_nodal_connec_index->begin());
+  int nbOfCells(getNumberOfCells());
+  std::vector< std::set<int> > st0(nbOfNodes);
+  for(int eltId=0;eltId<nbOfCells;eltId++)
+    {
+      const int *strtNdlConnOfCurCell(conn+connIndex[eltId]+1),*endNdlConnOfCurCell(conn+connIndex[eltId+1]);
+      std::set<int> s(strtNdlConnOfCurCell,endNdlConnOfCurCell); s.erase(-1); //for polyhedrons
+      for(std::set<int>::const_iterator iter2=s.begin();iter2!=s.end();iter2++)
+        st0[*iter2].insert(s.begin(),s.end());
+    }
+  neighborsIdx=DataArrayInt::New(); neighborsIdx->alloc(nbOfNodes+1,1); neighborsIdx->setIJ(0,0,0);
+  {
+    int *neighIdx(neighborsIdx->getPointer());
+    for(std::vector< std::set<int> >::const_iterator it=st0.begin();it!=st0.end();it++,neighIdx++)
+      neighIdx[1]=neighIdx[0]+(*it).size()-1;
+  }
+  neighbors=DataArrayInt::New(); neighbors->alloc(neighborsIdx->back(),1);
+  {
+    const int *neighIdx(neighborsIdx->begin());
+    int *neigh(neighbors->getPointer()),nodeId(0);
+    for(std::vector< std::set<int> >::const_iterator it=st0.begin();it!=st0.end();it++,neighIdx++,nodeId++)
+      {
+        std::set<int> s(*it); s.erase(nodeId);
+        std::copy(s.begin(),s.end(),neigh+*neighIdx);
+      }
+  }
+}
+
 /*!
  * Converts specified cells to either polygons (if \a this is a 2D mesh) or
  * polyhedrons (if \a this is a 3D mesh). The cells to convert are specified by an
@@ -954,7 +1020,7 @@ void MEDCouplingUMesh::convertToPolyTypes(const int *cellIdsToConvertBg, const i
   int nbOfCells(getNumberOfCells());
   if(dim==2)
     {
-      const int *connIndex=_nodal_connec_index->getConstPointer();
+      const int *connIndex=_nodal_connec_index->begin();
       int *conn=_nodal_connec->getPointer();
       for(const int *iter=cellIdsToConvertBg;iter!=cellIdsToConvertEnd;iter++)
         {
index efab092eb273eaf775524495234eae7c3a2882f3..caf5554d482e9315d162efc33fa94fcc30592303 100644 (file)
@@ -120,6 +120,7 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT bool areCellsIncludedIn(const MEDCouplingUMesh *other, int compType, DataArrayInt *& arr) const;
     MEDCOUPLING_EXPORT bool areCellsIncludedInPolicy7(const MEDCouplingUMesh *other, DataArrayInt *& arr) const;
     MEDCOUPLING_EXPORT void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const;
+    MEDCOUPLING_EXPORT MCAuto<MEDCouplingUMesh> explodeIntoEdges(MCAuto<DataArrayInt>& desc, MCAuto<DataArrayInt>& descIndex, MCAuto<DataArrayInt>& revDesc, MCAuto<DataArrayInt>& revDescIndx) const;
     MEDCOUPLING_EXPORT MEDCouplingUMesh *explode3DMeshTo1D(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const;
     MEDCOUPLING_EXPORT MEDCouplingUMesh *buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const;
     MEDCOUPLING_EXPORT MEDCouplingUMesh *buildDescendingConnectivity2(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const;
@@ -129,6 +130,7 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT static void ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, const DataArrayInt *descI, const DataArrayInt *revDesc, const DataArrayInt *revDescI,
                                                               DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx);
     MEDCOUPLING_EXPORT void computeNeighborsOfNodes(DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx) const;
+    MEDCOUPLING_EXPORT void computeEnlargedNeighborsOfNodes(MCAuto<DataArrayInt> &neighbors, MCAuto<DataArrayInt>& neighborsIdx) const;
     MEDCOUPLING_EXPORT MEDCouplingUMesh *mergeMyselfWithOnSameCoords(const MEDCouplingPointSet *other) const;
     MEDCOUPLING_EXPORT MEDCouplingUMesh *buildPartOfMySelf(const int *begin, const int *end, bool keepCoords=true) const;
     MEDCOUPLING_EXPORT MEDCouplingUMesh *buildPartOfMySelfSlice(int start, int end, int step, bool keepCoords=true) const;
index 474c6ab7c26b32a40061b492268135329e9fb49d..e05a867361d0344076fe8957346d96e42ba7ca58 100644 (file)
@@ -4518,6 +4518,29 @@ class MEDCouplingBasicsTest5(unittest.TestCase):
         d4.sortEachPairToMakeALinkedList()
         self.assertTrue(d4.fromLinkedListOfPairToList().isEqual(zeRes))
         pass
+
+    def testUMeshExplodeIntoEdges1(self):
+        m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured()
+        self.assertEqual(m.getMeshDimension(),3)
+        a0,a1,a2,a3,a4=m.explodeIntoEdges()
+        b0,b1,b2,b3,b4=m.explode3DMeshTo1D()
+        self.assertTrue(a0.isEqual(b0,1e-12))
+        self.assertTrue(a1.isEqual(b1)) ; self.assertTrue(a2.isEqual(b2)) ; self.assertTrue(a3.isEqual(b3)) ; self.assertTrue(a4.isEqual(b4))
+        #
+        m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
+        self.assertEqual(m.getMeshDimension(),2)
+        a0,a1,a2,a3,a4=m.explodeIntoEdges()
+        b0,b1,b2,b3,b4=m.buildDescendingConnectivity()
+        self.assertTrue(a0.isEqual(b0,1e-12))
+        self.assertTrue(a1.isEqual(b1)) ; self.assertTrue(a2.isEqual(b2)) ; self.assertTrue(a3.isEqual(b3)) ; self.assertTrue(a4.isEqual(b4))
+        pass
+
+    def testUMeshComputeEnlargedNeighborsOfNodes(self):
+        m=MEDCouplingCMesh() ; arr=DataArrayDouble(4) ; arr.iota() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
+        a,b=m.computeEnlargedNeighborsOfNodes()
+        self.assertTrue(a.isEqual(DataArrayInt([1,4,5,0,2,4,5,6,1,3,5,6,7,2,6,7,0,1,5,8,9,0,1,2,4,6,8,9,10,1,2,3,5,7,9,10,11,2,3,6,10,11,4,5,9,12,13,4,5,6,8,10,12,13,14,5,6,7,9,11,13,14,15,6,7,10,14,15,8,9,13,8,9,10,12,14,9,10,11,13,15,10,11,14])))
+        self.assertTrue(b.isEqual(DataArrayInt([0,3,8,13,16,21,29,37,42,47,55,63,68,71,76,81,84])))
+        pass
     
     pass
 
index a1a557ecc487f7d8059e1240bd00d53a7d244b70..fb5745154240c5213c84bb29f2dcc84bbab5a766 100644 (file)
@@ -2665,6 +2665,19 @@ namespace MEDCoupling
         return ret;
       }
 
+      PyObject *explodeIntoEdges() const throw(INTERP_KERNEL::Exception)
+      {
+        MCAuto<DataArrayInt> desc,descIndex,revDesc,revDescIndx;
+        MCAuto<MEDCouplingUMesh> m(self->explodeIntoEdges(desc,descIndex,revDesc,revDescIndx));
+        PyObject *ret=PyTuple_New(5);
+        PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(m.retn()),SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 ));
+        PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(desc.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+        PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(descIndex.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+        PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(revDesc.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+        PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(revDescIndx.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+        return ret;
+      }
+
       PyObject *explodeMeshIntoMicroEdges() const throw(INTERP_KERNEL::Exception)
       {
         MCAuto<DataArrayInt> d0=DataArrayInt::New();
@@ -2732,6 +2745,16 @@ namespace MEDCoupling
         PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(neighborsIdx),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
         return ret;
       }
+
+      PyObject *computeEnlargedNeighborsOfNodes() const throw(INTERP_KERNEL::Exception)
+      {
+        MCAuto<DataArrayInt> neighbors,neighborsIdx;
+        self->computeEnlargedNeighborsOfNodes(neighbors,neighborsIdx);
+        PyObject *ret=PyTuple_New(2);
+        PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(neighbors.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+        PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(neighborsIdx.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+        return ret;
+      }
       
       PyObject *computeCellNeighborhoodFromNodesOne(const DataArrayInt *nodeNeigh, const DataArrayInt *nodeNeighI) const throw(INTERP_KERNEL::Exception)
       {