From: Anthony Geay Date: Wed, 22 Apr 2020 05:07:23 +0000 (+0200) Subject: WIP X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9a2c0514a938c1b4bd87a30522a9fc1f2e0eb645;p=tools%2Fmedcoupling.git WIP --- diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx index 28dd21de0..8ab51c2d6 100755 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx @@ -213,6 +213,19 @@ DataArrayIdType* MEDCouplingSkyLineArray::getValuesArray() const return const_cast(this)->_values; } +MEDCouplingSkyLineArray *MEDCouplingSkyLineArray::deepCopy() const +{ + MCAuto indexCpy(this->_index->deepCopy()); + MCAuto valuesCpy(this->_values->deepCopy()); + MCAuto ret(MEDCouplingSkyLineArray::New(indexCpy,valuesCpy)); + if(_super_index.isNotNull()) + { + MCAuto superIndexCpy(this->_super_index->deepCopy()); + ret->_super_index = superIndexCpy; + } + return ret.retn(); +} + void MEDCouplingSkyLineArray::checkSuperIndex(const std::string& func) const { if (!_super_index->getNbOfElems()) @@ -361,7 +374,7 @@ MEDCouplingSkyLineArray *MEDCouplingSkyLineArray::AggregatePacks(const std::vect constexpr char MSG[]="MEDCouplingSkyLineArray::AggregatePacks : "; for(auto sk : sks) { - if(!sk) + if(sk) { mcIdType curNbPacks(sk->getNumberOf()); if(sksEff.empty()) @@ -386,15 +399,23 @@ MEDCouplingSkyLineArray *MEDCouplingSkyLineArray::AggregatePacks(const std::vect for( mcIdType packId = 0 ; packId < nbOfPacks ; ++packId, ++indexPtr ) { mcIdType nbOfAggPacks(0); - std::for_each(indicesIn.begin(),indicesIn.end(),[packId,&nbOfPacks](const mcIdType *elt) { nbOfPacks+=elt[packId]; }); + std::for_each(indicesIn.begin(),indicesIn.end(),[packId,&nbOfAggPacks](const mcIdType *elt) { nbOfAggPacks+=elt[packId+1]-elt[packId]; }); indexPtr[1] = indexPtr[0] + nbOfAggPacks; } mcIdType nbOfTuplesOut(index->back()); MCAuto values(DataArrayIdType::New()); values->alloc(nbOfTuplesOut,1); mcIdType *valuesPtr(values->getPointer()); + // let's go to populate values array std::vector valuesIn(SkyLineArrayValuesIterator(0,&sksEff),SkyLineArrayValuesIterator(sksEff.size(),&sksEff)); + for( mcIdType packId = 0 ; packId < nbOfPacks ; ++packId ) + { + std::size_t pos(0); + std::for_each(valuesIn.begin(),valuesIn.end(),[packId,&indicesIn,&valuesPtr,&pos](const mcIdType *elt) + { valuesPtr=std::copy(elt+indicesIn[pos][packId],elt+indicesIn[pos][packId+1],valuesPtr); ++pos; } + ); + } // - MCAuto ret; + MCAuto ret(MEDCouplingSkyLineArray::New(index,values)); return ret.retn(); } diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx index 74a63fea7..b4f0d2509 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx @@ -17,8 +17,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef __PARAMEDMEM_MEDCOUPLINGSKYLINEARRAY_HXX__ -#define __PARAMEDMEM_MEDCOUPLINGSKYLINEARRAY_HXX__ +#pragma once #include "MEDCoupling.hxx" #include "MEDCouplingMemArray.hxx" @@ -105,6 +104,8 @@ namespace MEDCoupling DataArrayIdType* getIndexArray() const; DataArrayIdType* getValuesArray() const; + MEDCouplingSkyLineArray *deepCopy() const; + std::string simpleRepr() const; MEDCouplingSkyLineArray *groupPacks(const DataArrayIdType *indexedPacks) const; @@ -163,4 +164,3 @@ namespace MEDCoupling using SkyLineArrayValuesIterator = SkyLineArrayGenIterator; } -# endif diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py index ed473e56b..77ef9ecaf 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2007-2020 CEA/DEN, EDF R&D +# Copyright (C) 2007-2020 CEA/DEN,EDF R&D # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. +# version 2.1 of the License,or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -12,8 +12,8 @@ # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# License along with this library; if not,write to the Free Software +# Foundation,Inc.,59 Temple Place,Suite 330,Boston,MA 02111-1307 USA # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # @@ -28,7 +28,7 @@ import unittest from math import pi,e,sqrt,cos,sin from datetime import datetime from MEDCouplingDataForTest import MEDCouplingDataForTest -import rlcompleter,readline # this line has to be here, to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr +import rlcompleter,readline # this line has to be here,to ensure a usability of MEDCoupling/MEDLoader. B4 removing it please notify to anthony.geay@cea.fr class MEDCouplingBasicsTest7(unittest.TestCase): @@ -184,7 +184,7 @@ class MEDCouplingBasicsTest7(unittest.TestCase): def testDAIAggregateMulti1(self): a=DataArrayInt64.New() - a.setValues(list(range(4)), 2, 2) + a.setValues(list(range(4)),2, 2) a.setName("aa") b=DataArrayInt64.New() b.setValues(list(range(6)), 3, 2) @@ -785,6 +785,19 @@ class MEDCouplingBasicsTest7(unittest.TestCase): sk2 = sk.uniqueNotSortedByPack() self.assertTrue(sk2.getIndexArray().isEqual(DataArrayInt([0,3,8,13,16,21,29,37,42]))) self.assertTrue(sk2.getValuesArray().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]))) + + def testSkyLineAggregatePacks1(self): + arr = DataArrayDouble(3) ; arr.iota() + m = MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m = m.buildUnstructured() + a,b = m.computeEnlargedNeighborsOfNodes() + sk = MEDCouplingSkyLineArray(b,a) + sk1 = sk.deepCopy() + sk1.getValuesArray()[:] *= 2 + sk2 = sk.deepCopy() + sk2.getValuesArray()[:] *= 3 + skOut = MEDCouplingSkyLineArray.AggregatePacks([sk,sk1,sk2]) + self.assertTrue(skOut.getIndexArray().isEqual(DataArrayInt([0,9,24,33,48,72,87,96,111,120]))) + self.assertTrue(skOut.getValuesArray().isEqual(DataArrayInt([1,3,4,2,6,8,3,9,12,0,2,3,4,5,0,4,6,8,10,0,6,9,12,15,1,4,5,2,8,10,3,12,15,0,1,4,6,7,0,2,8,12,14,0,3,12,18,21,0,1,2,3,5,6,7,8,0,2,4,6,10,12,14,16,0,3,6,9,15,18,21,24,1,2,4,7,8,2,4,8,14,16,3,6,12,21,24,3,4,7,6,8,14,9,12,21,3,4,5,6,8,6,8,10,12,16,9,12,15,18,24,4,5,7,8,10,14,12,15,21]))) pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index d2143962a..6fc12afea 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -468,6 +468,8 @@ typedef long int mcIdType; %newobject MEDCoupling::MEDCouplingSkyLineArray::getValuesArray; %newobject MEDCoupling::MEDCouplingSkyLineArray::groupPacks; %newobject MEDCoupling::MEDCouplingSkyLineArray::uniqueNotSortedByPack; +%newobject MEDCoupling::MEDCouplingSkyLineArray::AggregatePacks; +%newobject MEDCoupling::MEDCouplingSkyLineArray::deepCopy; %feature("unref") MEDCouplingPointSet "$this->decrRef();" %feature("unref") MEDCouplingMesh "$this->decrRef();" @@ -1301,6 +1303,8 @@ namespace MEDCoupling MEDCouplingSkyLineArray *groupPacks(const DataArrayIdType *indexedPacks) const; MEDCouplingSkyLineArray *uniqueNotSortedByPack() const; + + MEDCouplingSkyLineArray *deepCopy() const; %extend { @@ -1391,6 +1395,13 @@ namespace MEDCoupling convertFromPyObjVectorOfObj(listePacks,SWIGTITraits::TI,"DataArrayIdType",packs); self->replaceSimplePacks(idx, packs); } + + static MEDCouplingSkyLineArray *AggregatePacks(PyObject *sks) + { + std::vector sksCpp; + convertFromPyObjVectorOfObj(sks,SWIGTYPE_p_MEDCoupling__MEDCouplingSkyLineArray,"MEDCouplingSkyLineArray",sksCpp); + return MEDCoupling::MEDCouplingSkyLineArray::AggregatePacks(sksCpp); + } void replacePack(const mcIdType superIdx, const mcIdType idx, PyObject *pack) {