From: ageay Date: Thu, 20 Jan 2011 14:50:48 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V6_main_FINAL~1098 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bebf60e79f1cdfca4b79df65dfccdad09cb3eea8;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index be053dc68..42656389e 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -1921,6 +1921,55 @@ DataArrayInt *DataArrayInt::checkAndPreparePermutation() const throw(INTERP_KERN return ret; } +/*! + * This method makes the assumption that 'this' is correctly set, and has exactly one component. If not an exception will be thrown. + * Given a sujective application defined by 'this' from a set of size this->getNumberOfTuples() to a set of size targetNb. + * 'targetNb'getNumberOfTuples(). 'this' should be surjective that is to say for each id in [0,'targetNb') it exists at least one tupleId tid + * so that this->getIJ(tid,0)==id. + * If not an exception will be thrown. + * This method returns 2 newly allocated arrays 'arr' and 'arrI', corresponding respectively to array and its corresponding index. + * This method is usefull for methods that returns old2New numbering concecutive to a reduction ( MEDCouplingUMesh::zipConnectivityTraducer, MEDCouplingUMesh::zipConnectivityTraducer for example) + * Example : if 'this' equals [0,3,2,3,2,2,1,2] this method will return arrI=[0,1,2,6,8] arr=[0, 6, 2,4,5,7, 1,3] + * That is to say elt id 2 has arrI[2+1]-arrI[2]=4 places in 'this'. The corresponding tuple ids are [2,4,5,7]. + */ +void DataArrayInt::changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : number of components must == 1 !"); + int nbOfTuples=getNumberOfTuples(); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); + MEDCouplingAutoRefCountObjectPtr retI(DataArrayInt::New()); + retI->alloc(targetNb+1,1); + const int *input=getConstPointer(); + std::vector< std::vector > tmp(targetNb); + for(int i=0;igetPointer(); + *retIPtr=0; + for(std::vector< std::vector >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++,retIPtr++) + retIPtr[1]=retIPtr[0]+(*it1).size(); + if(nbOfTuples!=retI->getIJ(targetNb,0)) + throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : big problem should never happen !"); + ret->alloc(nbOfTuples,1); + int *retPtr=ret->getPointer(); + for(std::vector< std::vector >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++) + retPtr=std::copy((*it1).begin(),(*it1).end(),retPtr); + ret->incrRef(); + retI->incrRef(); + arr=ret; + arrI=retI; +} + /*! * This method checks that 'this' is with numberofcomponents == 1 and that it is equal to * stdext::iota() of size getNumberOfTuples. This method is particalary usefull for DataArrayInt instances diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 3298a5b2f..1cfa057f5 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -259,6 +259,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const; MEDCOUPLING_EXPORT DataArrayInt *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isIdentity() const; MEDCOUPLING_EXPORT bool isUniform(int val) const; MEDCOUPLING_EXPORT DataArrayInt *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 032459f89..c4eaa6456 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1150,11 +1150,28 @@ DataArrayInt *MEDCouplingUMesh::findCellsIdsOnBoundary() const throw(INTERP_KERN DataArrayInt *revDescIndx=DataArrayInt::New(); // MEDCouplingUMesh *meshDM1=buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); + meshDM1->decrRef(); + desc->decrRef(); + descIndx->decrRef(); + // + DataArrayInt *tmp=revDescIndx->deltaShiftIndex(); + DataArrayInt *faceIds=tmp->getIdsEqual(1); + tmp->decrRef(); + int nbOfFaces=faceIds->getNumberOfTuples(); + const int *faces=faceIds->getConstPointer(); + std::set ret; + for(const int *w=faces;w!=faces+nbOfFaces;w++) + ret.insert(revDesc->getIJ(revDescIndx->getIJ(*w,0),0)); + faceIds->decrRef(); // revDescIndx->decrRef(); revDesc->decrRef(); - desc->decrRef(); - descIndx->decrRef(); + // + DataArrayInt *ret2=DataArrayInt::New(); + ret2->alloc(ret.size(),1); + std::copy(ret.begin(),ret.end(),ret2->getPointer()); + ret2->setName("BoundaryCells"); + return ret2; } /*! diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 5d1ec045f..c4436e57a 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -1711,6 +1711,17 @@ namespace ParaMEDMEM return convertIntArrToPyList(tmp,sz); } + PyObject *changeSurjectiveFormat(int targetNb) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *arr=0; + DataArrayInt *arrI=0; + self->changeSurjectiveFormat(targetNb,arr,arrI); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj((void*)arr,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); + PyList_SetItem(res,1,SWIG_NewPointerObj((void*)arrI,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); + return res; + } + static DataArrayInt *Meld(PyObject *li) throw(INTERP_KERNEL::Exception) { std::vector tmp; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index eec76d26a..ca605d6af 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -6032,6 +6032,47 @@ class MEDCouplingBasicsTest(unittest.TestCase): da.setValues(vals2,8,1); self.assertRaises(InterpKernelException,da.checkAndPreparePermutation); pass + + def testDAIChangeSurjectiveFormat1(self): + vals1=[0,3,2,3,2,2,1,2] + expected1=[0,1,2,6,8] + expected2=[0, 6, 2,4,5,7, 1,3] + da=DataArrayInt.New(); + da.setValues(vals1,8,1); + # + da2,da2I=da.changeSurjectiveFormat(4); + self.assertEqual(5,da2I.getNumberOfTuples()); + self.assertEqual(8,da2.getNumberOfTuples()); + self.assertEqual(expected1,da2I.getValues()); + self.assertEqual(expected2,da2.getValues()); + # + self.assertRaises(InterpKernelException,da.changeSurjectiveFormat,3); + # + pass + + def testUMeshGetCellIdsLyingOnNodes1(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + nodeIds1=[1,2,3,4,6] + nodeIds2=[6,7] + da=m.getCellIdsLyingOnNodes(nodeIds1,True); + self.assertEqual(1,da.getNumberOfTuples()); + self.assertEqual(1,da.getNumberOfComponents()); + self.assertEqual(1,da.getIJ(0,0)); + da2=DataArrayInt.New() + da2.setValues(nodeIds2,2,1) + da=m.getCellIdsLyingOnNodes(da2,False); + self.assertEqual(2,da.getNumberOfTuples()); + self.assertEqual(1,da.getNumberOfComponents()); + self.assertEqual(3,da.getIJ(0,0)); + self.assertEqual(4,da.getIJ(1,0)); + pass + + def testUMeshFindCellsIdsOnBoundary1(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + da5=m.findCellsIdsOnBoundary(); + self.assertEqual(5,da5.getNumberOfTuples()); + self.assertTrue(da5->isIdentity()); + pass def setUp(self): pass