From: ageay Date: Thu, 21 Mar 2013 16:16:55 +0000 (+0000) Subject: swig of computeMeshRestrictionFromTupleIds X-Git-Tag: V6_main_FINAL~251 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=88e53e75a63fb69326b7ba9d930b64540bfea44e;p=tools%2Fmedcoupling.git swig of computeMeshRestrictionFromTupleIds --- diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 9ce55a581..50e840015 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -1188,7 +1188,13 @@ void MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds(con { if(!mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeMeshRestrictionFromTupleIds : NULL input mesh !"); - throw INTERP_KERNEL::Exception("Not implemented yet !"); + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayInt::New(); tmp->alloc((int)std::distance(tupleIdsBg,tupleIdsEnd),1); + std::copy(tupleIdsBg,tupleIdsEnd,tmp->getPointer()); + tmp->sort(true); + tmp=tmp->buildUnique(); + MEDCouplingAutoRefCountObjectPtr nbOfNodesPerCell=buildNbOfGaussPointPerCellField(); + nbOfNodesPerCell->computeOffsets2(); + nbOfNodesPerCell->searchRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction); } /*! @@ -1897,31 +1903,8 @@ void MEDCouplingFieldDiscretizationGaussNE::computeMeshRestrictionFromTupleIds(c tmp->sort(true); tmp=tmp->buildUnique(); MEDCouplingAutoRefCountObjectPtr nbOfNodesPerCell=mesh->computeNbOfNodesPerCell(); - MEDCouplingAutoRefCountObjectPtr ret0=DataArrayInt::New(); ret0->alloc(0,1); - MEDCouplingAutoRefCountObjectPtr ret1=DataArrayInt::New(); ret1->alloc(0,1); nbOfNodesPerCell->computeOffsets2(); - // - const int *tupEnd(tmp->end()),*offBg(nbOfNodesPerCell->begin()),*offEnd(nbOfNodesPerCell->end()-1); - const int *tupPtr(tmp->begin()),*offPtr(offBg); - while(tupPtr!=tupEnd && offPtr!=offEnd) - { - if(*tupPtr==*offPtr) - { - int i=offPtr[0]; - while(ipushBackSilent((int)std::distance(offBg,offPtr)); - ret1->pushBackValsSilent(tupPtr-(offPtr[1]-offPtr[0]),tupPtr); - offPtr++; - } - } - else - { if(*tupPtr<*offPtr) tupPtr++; else offPtr++; } - } - // - cellRestriction=ret0.retn(); - trueTupleRestriction=ret1.retn(); + nbOfNodesPerCell->searchRangesInListOfIds(tmp,cellRestriction,trueTupleRestriction); } void MEDCouplingFieldDiscretizationGaussNE::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index a4f968c6f..c76049e98 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -8548,6 +8548,60 @@ void DataArrayInt::computeOffsets2() throw(INTERP_KERNEL::Exception) declareAsNew(); } +/*! + * Returns two new DataArrayInt instances whose contents is computed from that of \a this and \a listOfIds arrays as follows. + * \a this is expected to be an offset format ( as returned by DataArrayInt::computeOffsets2 ) that is to say with one component + * and ** sorted strictly increasingly **. \a listOfIds is expected to be sorted ascendingly (not strictly needed for \a listOfIds). + * This methods searches in \a this, considered as a set of contiguous \c this->getNumberOfComponents() ranges, all ids in \a listOfIds + * filling completely one of the ranges in \a this. + * + * \param [in] listOfIds a list of ids that has to be sorted ascendingly. + * \param [out] rangeIdsFetched the range ids fetched + * \param [out] idsInInputListThatFetch contains the list of ids in \a listOfIds that are \b fully included in a range in \a this. So + * \a idsInInputListThatFetch is a part of input \a listOfIds. + * + * \sa DataArrayInt::computeOffsets2 + * + * \b Example:
+ * - \a this : [0,3,7,9,15,18] + * - \a listOfIds contains [0,1,2,3,7,8,15,16,17] + * - \a rangeIdsFetched result array: [0,2,4] + * - \a idsInInputListThatFetch result array: [0,1,2,7,8,15,16,17] + * In this example id 3 in input \a listOfIds is alone so it do not appear in output \a idsInInputListThatFetch. + *
+ */ +void DataArrayInt::searchRangesInListOfIds(const DataArrayInt *listOfIds, DataArrayInt *& rangeIdsFetched, DataArrayInt *& idsInInputListThatFetch) const throw(INTERP_KERNEL::Exception) +{ + if(!listOfIds) + throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : input list of ids is null !"); + listOfIds->checkAllocated(); checkAllocated(); + if(listOfIds->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : input list of ids must have exactly one component !"); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : this must have exactly one component !"); + MEDCouplingAutoRefCountObjectPtr ret0=DataArrayInt::New(); ret0->alloc(0,1); + MEDCouplingAutoRefCountObjectPtr ret1=DataArrayInt::New(); ret1->alloc(0,1); + const int *tupEnd(listOfIds->end()),*offBg(begin()),*offEnd(end()-1); + const int *tupPtr(listOfIds->begin()),*offPtr(offBg); + while(tupPtr!=tupEnd && offPtr!=offEnd) + { + if(*tupPtr==*offPtr) + { + int i=offPtr[0]; + while(ipushBackSilent((int)std::distance(offBg,offPtr)); + ret1->pushBackValsSilent(tupPtr-(offPtr[1]-offPtr[0]),tupPtr); + offPtr++; + } + } + else + { if(*tupPtr<*offPtr) tupPtr++; else offPtr++; } + } + rangeIdsFetched=ret0.retn(); + idsInInputListThatFetch=ret1.retn(); +} /*! * Returns a new DataArrayInt whose contents is computed from that of \a this and \a diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index def94305c..741c334b8 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -510,6 +510,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *deltaShiftIndex() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void computeOffsets() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void computeOffsets2() throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void searchRangesInListOfIds(const DataArrayInt *listOfIds, DataArrayInt *& rangeIdsFetched, DataArrayInt *& idsInInputListThatFetch) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *findRangeIdForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *findIdInRangeForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index a7228bd95..c8c12558c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -11644,6 +11644,41 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(DataArrayDouble(f.normL2()).isEqual(DataArrayDouble([58.16846378340898,1046.1241521947334]),1e-12)) pass + def testSwig2FieldDiscretizationComputeMeshRestrictionFromTupleIds1(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1() + f=MEDCouplingFieldDouble(ON_GAUSS_NE) + f.setMesh(m) + a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[3,4,5,6,8,9,10,14,15,16,17]) + self.assertTrue(a.isEqual(DataArrayInt([1,4]))) + self.assertTrue(b.isEqual(DataArrayInt([4,5,6,14,15,16,17]))) + a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),DataArrayInt([0,1,2,3,5,7,8,9,10,11,12,18])) + self.assertTrue(a.isEqual(DataArrayInt([0,2]))) + self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,7,8,9]))) + # + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[3,4]) + self.assertTrue(a.isEqual(DataArrayInt([3,4]))) + self.assertTrue(b.isEqual(DataArrayInt([3,4]))) + # + f=MEDCouplingFieldDouble(ON_NODES) + f.setMesh(m) + a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[1,2,3,4]) + self.assertTrue(a.isEqual(DataArrayInt([1]))) + self.assertTrue(b.isEqual(DataArrayInt([1,2,4]))) + # + f=MEDCouplingDataForTest.buildFieldOnGauss_1() + a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[0,11,12,13,14,15,17,18,19,36,37,38,115,117,118,119,120,121,122,123,124,125]) + self.assertTrue(a.isEqual(DataArrayInt([0,11,12,18,35]))) + self.assertTrue(b.isEqual(DataArrayInt([0,11,12,13,14,15,36,37,38,117,118,119,120,121,122,123,124,125]))) + # + d=DataArrayInt([0,3,7,9,15,18]) + e=DataArrayInt([0,1,2,3,7,8,15,16,17]) + a,b=d.searchRangesInListOfIds(e) + self.assertTrue(a.isEqual(DataArrayInt([0,2,4]))) + self.assertTrue(b.isEqual(DataArrayInt([0,1,2,7,8,15,16,17]))) + pass + def setUp(self): pass pass