From e6ad258c0ab99e4ef4e1fe622c75c61b7e52dee1 Mon Sep 17 00:00:00 2001 From: geay Date: Fri, 18 Apr 2014 19:16:25 +0200 Subject: [PATCH] new method MEDCouplingUMesh::computeNeighborsOfNodes --- src/MEDCoupling/MEDCouplingUMesh.cxx | 58 ++++++++++++++++++- src/MEDCoupling/MEDCouplingUMesh.hxx | 1 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 21 +++++++ src/MEDCoupling_Swig/MEDCouplingCommon.i | 10 ++++ 4 files changed, 88 insertions(+), 2 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index e0113eba9..039031123 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -809,7 +809,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildDescendingConnectivity2(DataArrayInt *d * \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 MEDCouplingUMesh::buildDescendingConnectivity to compute the result. * This method lists cell by cell in \b this which are its neighbors. To compute the result only connectivities are considered. - * The a cell with id 'cellId' its neighbors are neighbors[neighborsIndx[cellId]:neighborsIndx[cellId+1]]. + * The neighbor cells of cell having id 'cellId' are neighbors[neighborsIndx[cellId]:neighborsIndx[cellId+1]]. * * \param [out] neighbors is an array storing all the neighbors of all cells in \b this. This array is newly allocated and should be dealt by the caller. \b neighborsIndx 2nd output * parameter allows to select the right part in this array. The number of tuples is equal to the last values in \b neighborsIndx. @@ -832,7 +832,7 @@ void MEDCouplingUMesh::computeNeighborsOfCells(DataArrayInt *&neighbors, DataArr * excluding a set of meshdim-1 cells in input descending connectivity. * Typically \b desc, \b descIndx, \b revDesc and \b revDescIndx input params are the result of MEDCouplingUMesh::buildDescendingConnectivity. * This method lists cell by cell in \b this which are its neighbors. To compute the result only connectivities are considered. - * The a cell with id 'cellId' its neighbors are neighbors[neighborsIndx[cellId]:neighborsIndx[cellId+1]]. + * The neighbor cells of cell having id 'cellId' are neighbors[neighborsIndx[cellId]:neighborsIndx[cellId+1]]. * * \param [in] desc descending connectivity array. * \param [in] descIndx descending connectivity index array used to walk through \b desc. @@ -872,6 +872,60 @@ void MEDCouplingUMesh::ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, cons neighborsIndx=out1.retn(); } +/*! + * \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 MEDCouplingUMesh::buildDescendingConnectivity to compute the result. + * This method lists node by node in \b this which are its neighbors. To compute the result only connectivities are considered. + * The neighbor nodes of node having id 'nodeId' are neighbors[neighborsIndx[cellId]:neighborsIndx[cellId+1]]. + * + * \param [out] neighbors is an array storing all the neighbors of all nodes in \b this. This array is newly allocated and should be dealt by the caller. \b neighborsIndx 2nd output + * parameter allows to select the right part in this array. The number of tuples is equal to the last values in \b neighborsIndx. + * \param [out] neighborsIndx 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. + */ +void MEDCouplingUMesh::computeNeighborsOfNodes(DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx) const +{ + checkFullyDefined(); + int mdim(getMeshDimension()),nbNodes(getNumberOfNodes()); + MEDCouplingAutoRefCountObjectPtr desc(DataArrayInt::New()),descIndx(DataArrayInt::New()),revDesc(DataArrayInt::New()),revDescIndx(DataArrayInt::New()); + MEDCouplingAutoRefCountObjectPtr mesh1D; + switch(mdim) + { + case 3: + { + mesh1D=explode3DMeshTo1D(desc,descIndx,revDesc,revDescIndx); + break; + } + case 2: + { + mesh1D=buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); + break; + } + case 1: + { + mesh1D=const_cast(this); + mesh1D->incrRef(); + break; + } + default: + { + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::computeNeighborsOfNodes : Mesh dimension supported are [3,2,1] !"); + } + } + desc=DataArrayInt::New(); descIndx=DataArrayInt::New(); revDesc=0; revDescIndx=0; + mesh1D->getReverseNodalConnectivity(desc,descIndx); + MEDCouplingAutoRefCountObjectPtr ret0(DataArrayInt::New()); + ret0->alloc(desc->getNumberOfTuples(),1); + int *r0Pt(ret0->getPointer()); + const int *c1DPtr(mesh1D->getNodalConnectivity()->begin()),*rn(desc->begin()),*rni(descIndx->begin()); + for(int i=0;icomputeNeighborsOfNodes(neighbors,neighborsIdx); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(neighbors),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(neighborsIdx),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + static PyObject *ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, const DataArrayInt *descI, const DataArrayInt *revDesc, const DataArrayInt *revDescI) throw(INTERP_KERNEL::Exception) { DataArrayInt *neighbors=0,*neighborsIdx=0; -- 2.39.2