From: ageay Date: Tue, 18 Dec 2012 08:39:46 +0000 (+0000) Subject: Improvement of perf of zipConnectivityTraducer. X-Git-Tag: V6_main_FINAL~450 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e03a502127eafc82fbcc23a4fcd8a515c0d257fb;p=tools%2Fmedcoupling.git Improvement of perf of zipConnectivityTraducer. --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index e2db30e71..6c40db13e 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -4208,8 +4208,6 @@ void DataArrayInt::changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, Data */ DataArrayInt *DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const int *arr, const int *arrIBg, const int *arrIEnd, int &newNbOfTuples) throw(INTERP_KERNEL::Exception) { - if(!arr || !arrIBg || !arrIEnd) - throw INTERP_KERNEL::Exception("DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2 : presence of NULL ref of DataArrayInt in input !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfOldTuples,1); int *pt=ret->getPointer(); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 20a77bf5f..588456b08 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1466,21 +1466,21 @@ void MEDCouplingUMesh::findCommonCellsBase(int startCellId, int compType, std::v } /*! - * This method could potentially modify 'this'. This method merges cells if there are cells equal in 'this'. The comparison is specified by 'compType'. - * This method keeps the coordiantes of 'this'. + * This method find cells that are cells equal (regarding \a compType) in \a this. The comparison is specified by \a compType. + * This method keeps the coordiantes of \a this. This method is time consuming and is called * - * @param compType input specifying the technique used to compare cells each other. + * \param [in] compType input specifying the technique used to compare cells each other. * - 0 : exactly. A cell is detected to be the same if and only if the connectivity is exactly the same without permutation and types same too. This is the strongest policy. * - 1 : permutation same orientation. cell1 and cell2 are considered equal if the connectivity of cell2 can be deduced by those of cell1 by direct permutation (with exactly the same orientation) * and their type equal. For 1D mesh the policy 1 is equivalent to 0. * - 2 : nodal. cell1 and cell2 are equal if and only if cell1 and cell2 have same type and have the same nodes constituting connectivity. This is the laziest policy. This policy * can be used for users not sensitive to orientation of cell - * @return the correspondance array old to new. + * \param [in] startCellId specifies the cellId starting from which the equality computation will be carried out. By default it is 0, which it means that all cells in \a this will be scanned. + * \param [out] newNbOfCells + * \return the correspondance array old to new in a newly allocated array. * - * \warning This method modifies can modify significantly the geometric type order in \a this. - * In view of the MED file writing, a renumbering of cells in \a this (using MEDCouplingUMesh::sortCellsInMEDFileFrmt) should be necessary. */ -DataArrayInt *MEDCouplingUMesh::zipConnectivityTraducer(int compType, int startCellId) throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingUMesh::findEqualCells(int compType, int startCellId, int& newNbOfCells) const throw(INTERP_KERNEL::Exception) { checkConnectivityFullyDefined(); int nbOfCells=getNumberOfCells(); @@ -1559,46 +1559,36 @@ DataArrayInt *MEDCouplingUMesh::zipConnectivityTraducer(int compType, int startC } } } - // BuildOld2NewArrayFromSurjectiveFormat2(); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc(nbOfCells,1); - int *retPtr=ret->getPointer(); - std::fill(retPtr,retPtr+nbOfCells,0); - const std::size_t nbOfTupleSmCells=commonCellsI.size()-1; - int id=-1; - std::vector cellsToKeep; - for(std::size_t i=0;i::const_iterator it=commonCells.begin()+commonCellsI[i];it!=commonCells.begin()+commonCellsI[i+1];it++) - retPtr[*it]=id; - id--; - } - id=0; - std::map m; - for(int i=0;i::const_iterator iter=m.find(val); - if(iter==m.end()) - { - m[val]=id; - retPtr[i]=id++; - cellsToKeep.push_back(i); - } - else - retPtr[i]=(*iter).second; - } - } - MEDCouplingUMesh *self=(MEDCouplingUMesh *)buildPartOfMySelf(&cellsToKeep[0],&cellsToKeep[0]+cellsToKeep.size(),true); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(nbOfCells,&commonCells[0],&commonCellsI[0], + &commonCellsI[0]+commonCellsI.size(),newNbOfCells); + ret->incrRef(); + return ret; +} + +/*! + * This method could potentially modify \a this. This method merges cells if there are cells equal in \a this. The comparison is specified by \a compType. + * This method keeps the coordiantes of \a this. + * + * \param [in] compType input specifying the technique used to compare cells each other. + * - 0 : exactly. A cell is detected to be the same if and only if the connectivity is exactly the same without permutation and types same too. This is the strongest policy. + * - 1 : permutation same orientation. cell1 and cell2 are considered equal if the connectivity of cell2 can be deduced by those of cell1 by direct permutation (with exactly the same orientation) + * and their type equal. For 1D mesh the policy 1 is equivalent to 0. + * - 2 : nodal. cell1 and cell2 are equal if and only if cell1 and cell2 have same type and have the same nodes constituting connectivity. This is the laziest policy. This policy + * can be used for users not sensitive to orientation of cell + * \param [in] startCellId specifies the cellId starting from which the equality computation will be carried out. By default it is 0, which it means that all cells in \a this will be scanned + * \return the correspondance array old to new in a newly allocated array. + * + * \warning This method modifies can modify significantly the geometric type order in \a this. + * In view of the MED file writing, a renumbering of cells in \a this (using MEDCouplingUMesh::sortCellsInMEDFileFrmt) should be necessary. + */ +DataArrayInt *MEDCouplingUMesh::zipConnectivityTraducer(int compType, int startCellId) throw(INTERP_KERNEL::Exception) +{ + int newNbOfCells=-1; + MEDCouplingAutoRefCountObjectPtr ret=findEqualCells(compType,startCellId,newNbOfCells); + MEDCouplingAutoRefCountObjectPtr ret2=ret->invertArrayO2N2N2O(newNbOfCells); + MEDCouplingAutoRefCountObjectPtr self=static_cast(buildPartOfMySelf(ret2->begin(),ret2->end(),true)); setConnectivity(self->getNodalConnectivity(),self->getNodalConnectivityIndex(),true); - self->decrRef(); + ret->incrRef(); return ret; } diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 99033bf51..4811eb666 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -109,6 +109,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *zipConnectivityTraducer(int compType, int startCellId=0) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *findEqualCells(int compType, int startCellId, int& newNbOfCells) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool areCellsIncludedIn(const MEDCouplingUMesh *other, int compType, DataArrayInt *& arr) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool areCellsIncludedIn2(const MEDCouplingUMesh *other, DataArrayInt *& arr) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index bc1b34711..fdfbffe9f 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -1676,6 +1676,17 @@ namespace ParaMEDMEM PyList_SetItem(res,i,PyInt_FromLong(*iL)); return res; } + + PyObject *findEqualCells(int compType, int startCellId=0) const throw(INTERP_KERNEL::Exception) + { + int newNbOfCells=-1; + DataArrayInt *ret0=self->findEqualCells(compType,startCellId,newNbOfCells); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_From_int(newNbOfCells)); + return res; + } + PyObject *mergeNodes(double precision) throw(INTERP_KERNEL::Exception) { bool ret1;