From: Anthony Geay Date: Tue, 17 Oct 2017 13:44:15 +0000 (+0200) Subject: Merge part1 of mss/paraspliter X-Git-Tag: V9_0_0~38 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0938088b3bbe54f4e420a5e1ea4b1c0344c8a9a5;p=tools%2Fmedcoupling.git Merge part1 of mss/paraspliter --- diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx index f270ddf16..e07b195c8 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx @@ -20,6 +20,8 @@ #include "MEDCouplingSkyLineArray.hxx" #include +#include +#include using namespace MEDCoupling; @@ -384,8 +386,6 @@ void MEDCouplingSkyLineArray::findPackIds(const std::vector & superPackIndi */ void MEDCouplingSkyLineArray::deletePack(const int superIdx, const int idx) { - using namespace std; - checkSuperIndex("deletePack"); validSuperIndexAndIndex("deletePack", superIdx, idx); @@ -393,12 +393,12 @@ void MEDCouplingSkyLineArray::deletePack(const int superIdx, const int idx) int * siP(_super_index->getPointer()), *iP(_index->getPointer()); const int start = iP[siP[superIdx]+idx], end = iP[siP[superIdx]+idx+1]; // _values - copy(vP+end, vP+_values->getNbOfElems(), vP+start); + std::copy(vP+end, vP+_values->getNbOfElems(), vP+start); _values->reAlloc(_values->getNbOfElems() - (end-start)); // _index int nt = _index->getNbOfElems(); - copy(iP+siP[superIdx]+idx+1, iP+nt, iP+siP[superIdx]+idx); + std::copy(iP+siP[superIdx]+idx+1, iP+nt, iP+siP[superIdx]+idx); _index->reAlloc(nt-1); iP = _index->getPointer(); // better not forget this ... for(int ii = siP[superIdx]+idx; ii < nt-1; ii++) iP[ii] -= (end-start); @@ -408,6 +408,128 @@ void MEDCouplingSkyLineArray::deletePack(const int superIdx, const int idx) (siP[ii])--; } +void MEDCouplingSkyLineArray::deleteSimplePack(const int idx) +{ + validIndex("deleteSimplePack", idx); + + int* iP(_index->getPointer()); + const int start(iP[idx]), end(iP[idx+1]); + + // _values + int initValSz( _values->getNbOfElems() ); + int deltaSz( start-end ); // should be negative + int *vP(_values->getPointer()); + if (deltaSz < 0) + { + std::copy(vP+end, vP+initValSz, vP+start); + _values->reAlloc(initValSz+deltaSz); + } + else + throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::deleteSimplePack"); + // _index + int nt(_index->getNbOfElems()); + std::copy(iP+idx+1, iP+nt, iP+idx); + for(int ii = idx; ii < nt-1; ii++) + iP[ii] += deltaSz; + _index->reAlloc(nt-1); +} + +void MEDCouplingSkyLineArray::replaceSimplePacks(const DataArrayInt* idx, const std::vector& packs) +{ + if (idx->empty()) + return; + + for (const int * id = idx->begin(); id != idx->end(); id++) + validIndex("deleteSimplePacks", *id); + + if (idx->getNbOfElems() != packs.size()) + throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::deleteSimplePacks: size of list of pack is incorrect"); + + // copy _index, _values into a deque> + std::deque< std::set > valuesByIdx; + int* vP(_values->getPointer()); + int* iP(_index->getPointer()); + std::size_t nt ( _index->getNbOfElems() ); + for (int ii = 0; ii < nt-1; ii++) + valuesByIdx.push_back(std::set(vP+iP[ii], vP+iP[ii+1])); + + // modify the deque> according to idx and packs + int ii(0); + for (const int *id = idx->begin(); id != idx->end(); id++) + { + valuesByIdx[*id] = std::set(packs[ii]->begin(), packs[ii]->end()); + ii++; + } + // copy back the deque> into _index, _values + int valSz(0); + *iP = 0; + for (std::deque< std::set >::const_iterator values=valuesByIdx.begin();values!=valuesByIdx.end();values++) + { + valSz += (*values).size(); + *(++iP) = valSz; + } + _values->reAlloc(valSz); + iP = _index->getPointer(); + vP = _values->getPointer(); + for (auto values : valuesByIdx) + { + std::copy(values.begin(), values.end(), vP+(*iP)); + iP++; + } +} + +void MEDCouplingSkyLineArray::deleteSimplePacks(const DataArrayInt* idx) +{ + for (auto id = idx->begin(); id != idx->end(); id++) + validIndex("deleteSimplePacks", *id); + + std::set packsToDelete(idx->begin(), idx->end()); + + // _values + int* iP(_index->getPointer()); + int initValSz = _values->getNbOfElems(); + int *vP(_values->getPointer()); + int end_prec(0),start_prec(0); + for(std::set::const_iterator ii=packsToDelete.begin();ii!=packsToDelete.end();ii++) + { + int start = iP[*ii]; + if (end_prec != 0) + std::copy(vP+end_prec, vP+start, vP+start_prec); + start_prec += start-end_prec; + end_prec = iP[*ii+1]; + } + if (end_prec != 0) + std::copy(vP+end_prec, vP+initValSz, vP+start_prec); + _values->reAlloc(initValSz-(end_prec-start_prec)); + + // _index + int nt = _index->getNbOfElems(); + int offset = 0; + end_prec = 0; + start_prec = 0; + int deleted = 0; + for(std::set::const_iterator ii=packsToDelete.begin();ii!=packsToDelete.end();ii++) + { + if (end_prec != 0) + { + std::copy(iP+end_prec, iP+*ii, iP+start_prec); + for (int i=start_prec; i<*ii; i++) + iP[i] -= offset; + } + offset += iP[*ii+1] - iP[*ii]; + start_prec = *ii-deleted; + end_prec = *ii+1; + deleted += 1; + } + if (end_prec != 0) + { + std::copy(iP+end_prec, iP+nt, iP+start_prec); + for (int i=start_prec; ireAlloc(nt-deleted); +} + /**! * Insert a new pack in super-pack at index 'superIdx'. The pack is inserted at the end of the pack list of the chosen super-pack. */ @@ -448,12 +570,10 @@ void MEDCouplingSkyLineArray::pushBackPack(const int superIdx, const int * packB */ void MEDCouplingSkyLineArray::replaceSimplePack(const int idx, const int * packBg, const int * packEnd) { - using namespace std; - validIndex("replaceSimplePack", idx); int * iP(_index->getPointer()); - int newSz = distance(packBg, packEnd); + int newSz = std::distance(packBg, packEnd); const int start = iP[idx], end = iP[idx+1]; // _values @@ -464,13 +584,13 @@ void MEDCouplingSkyLineArray::replaceSimplePack(const int idx, const int * packB if (deltaSz > 0) _values->reAlloc(initValSz+deltaSz); int *vP(_values->getPointer()); - copy(vP+end, vP+initValSz, vP+end+deltaSz); + std::copy(vP+end, vP+initValSz, vP+end+deltaSz); if (deltaSz < 0) _values->reAlloc(initValSz+deltaSz); } // copy new pack - copy(packBg, packEnd, _values->getPointer()+start); + std::copy(packBg, packEnd, _values->getPointer()+start); // _index for(int ii = idx+1; ii < (int)_index->getNbOfElems(); ii++) @@ -481,15 +601,13 @@ void MEDCouplingSkyLineArray::replaceSimplePack(const int idx, const int * packB * Replace pack with super index 'superIdx' and index 'idx' with the provided new pack. * Function can be used only for 3-level SkyLine. */ -void MEDCouplingSkyLineArray::replacePack(const int superIdx, const int idx, const int * packBg, const int * packEnd) +void MEDCouplingSkyLineArray::replacePack(const int superIdx, const int idx, const int *packBg, const int *packEnd) { - using namespace std; - checkSuperIndex("replacePack"); validSuperIndexAndIndex("replacePack", superIdx, idx); int * siP(_super_index->getPointer()), *iP(_index->getPointer()); - int newSz = distance(packBg, packEnd); + int newSz = std::distance(packBg, packEnd); const int start = iP[siP[superIdx]+idx], end = iP[siP[superIdx]+idx+1]; // _values @@ -500,13 +618,13 @@ void MEDCouplingSkyLineArray::replacePack(const int superIdx, const int idx, con if (deltaSz > 0) _values->reAlloc(initValSz+deltaSz); int *vP(_values->getPointer()); - copy(vP+end, vP+initValSz, vP+end+deltaSz); + std::copy(vP+end, vP+initValSz, vP+end+deltaSz); if (deltaSz < 0) _values->reAlloc(initValSz+deltaSz); } // copy new pack - copy(packBg, packEnd, _values->getPointer()+start); + std::copy(packBg, packEnd, _values->getPointer()+start); // _index for(int ii = siP[superIdx]+idx+1; ii < (int)_index->getNbOfElems(); ii++) diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx index bf5d74cab..7c7d04a03 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx @@ -90,11 +90,15 @@ namespace MEDCoupling std::vector& out) const; void deletePack(const int superIdx, const int idx); + void deleteSimplePack(const int idx); void pushBackPack(const int superIdx, const int * packBg, const int * packEnd); void replaceSimplePack(const int idx, const int * packBg, const int * packEnd); void replacePack(const int superIdx, const int idx, const int * packBg, const int * packEnd); + void deleteSimplePacks(const DataArrayInt* idx); + void replaceSimplePacks(const DataArrayInt* idx, const std::vector& packs); + void convertToPolyhedronConn( MCAuto& c, MCAuto& cI) const; private: diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 87871d83b..b3f97635b 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -975,7 +975,12 @@ void MEDCouplingUMesh::computeEnlargedNeighborsOfNodes(MCAuto &nei { int *neighIdx(neighborsIdx->getPointer()); for(std::vector< std::set >::const_iterator it=st0.begin();it!=st0.end();it++,neighIdx++) - neighIdx[1]=neighIdx[0]+(*it).size()-1; + { + if ((*it).empty()) + neighIdx[1]=neighIdx[0]; + else + neighIdx[1]=neighIdx[0]+(*it).size()-1; + } } neighbors=DataArrayInt::New(); neighbors->alloc(neighborsIdx->back(),1); { diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py index c3a254a15..e25b7c7ba 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py @@ -4620,8 +4620,16 @@ class MEDCouplingBasicsTest5(unittest.TestCase): 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]))) + aExp=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]) + bExp=DataArrayInt([0,3,8,13,16,21,29,37,42,47,55,63,68,71,76,81,84]) + self.assertTrue(a.isEqual(aExp)) + self.assertTrue(b.isEqual(bExp)) + m2=m[[1,2,3]] + c,d=m2.computeEnlargedNeighborsOfNodes() + cExp=DataArrayInt([2,5,6,1,3,5,6,7,2,6,7,5,8,9,1,2,4,6,8,9,1,2,3,5,7,2,3,6,4,5,9,4,5,8]) + dExp=DataArrayInt([0,0,3,8,11,14,20,25,28,31,34,34,34,34,34,34,34]) + self.assertTrue(c.isEqual(cExp)) + self.assertTrue(d.isEqual(dExp)) pass def testDAIfindIdsExt1(self): diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py index 583f96a84..916e9c30c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py @@ -142,7 +142,23 @@ class MEDCouplingBasicsTest6(unittest.TestCase): f2.setArray(DataArrayDouble(list(range(18)))) f2.checkConsistencyLight() pass - + + def testSKLAReplaceDeletePacks(self): + index=DataArrayInt([0,3,5,6,6]) + value=DataArrayInt([1,2,3, 2,3, 3 ]) + sla=MEDCouplingSkyLineArray(index,value) + idx=DataArrayInt([0,3]) + packs=[DataArrayInt([4,5]),DataArrayInt([6,7,8])] + sla.replaceSimplePacks(idx,packs) + self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2,4,5,8]))) + self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([4,5, 2,3, 3, 6,7,8]))) + sla.deleteSimplePacks(idx) + self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2,3]))) + self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([2,3, 3]))) + sla.deleteSimplePack(1) + self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2]))) + self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([2,3]))) + pass pass if __name__ == '__main__': diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 02ce39ffd..bdfc4121e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -1228,6 +1228,9 @@ namespace MEDCoupling void deletePack(const int i, const int j) throw(INTERP_KERNEL::Exception); + void deleteSimplePack(const int i) throw(INTERP_KERNEL::Exception); + void deleteSimplePacks(const DataArrayInt* idx) throw(INTERP_KERNEL::Exception); + %extend { MEDCouplingSkyLineArray() throw(INTERP_KERNEL::Exception) @@ -1311,6 +1314,13 @@ namespace MEDCoupling self->replaceSimplePack(idx, vpack.data(), vpack.data()+vpack.size()); } + void replaceSimplePacks(const DataArrayInt* idx, PyObject *listePacks) throw(INTERP_KERNEL::Exception) + { + std::vector packs; + convertFromPyObjVectorOfObj(listePacks,SWIGTYPE_p_MEDCoupling__DataArrayInt,"DataArrayInt",packs); + self->replaceSimplePacks(idx, packs); + } + void replacePack(const int superIdx, const int idx, PyObject *pack) throw(INTERP_KERNEL::Exception) { std::vector vpack;