From 2df21dedba8e19c159b21c1eaae3ebecb5601f39 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 28 Aug 2018 16:05:53 +0200 Subject: [PATCH] Test of renumberNodesInConn with optimized map --- src/MEDCoupling/MEDCouplingMemArray.cxx | 26 +++++++++++++- src/MEDCoupling/MEDCouplingMemArray.hxx | 1 + .../MEDCouplingBasicsTest6.py | 34 +++++++++++++++++++ src/MEDCoupling_Swig/MEDCouplingMemArray.i | 1 + 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 0343614a8..f7bcef009 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -4234,7 +4234,7 @@ DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const * \ref cpp_mcdataarrayint_invertarrayn2o2o2n "Here is a C++ example". * * \ref py_mcdataarrayint_invertarrayn2o2o2n "Here is a Python example". - * \sa invertArrayN2O2O2N + * \sa invertArrayN2O2O2N, giveN2OOptimized, MEDCouplingPointSet::renumberNodesInConn * \endif */ MCAuto< MapKeyVal > DataArrayInt32::invertArrayN2O2O2NOptimized() const @@ -4254,6 +4254,30 @@ MCAuto< MapKeyVal > DataArrayInt32::invertArrayN2O2O2NOptimized() const return ret; } +/*! + * Creates a map, whose contents are computed + * from values of \a this array, which is supposed to contain a renumbering map in + * "New to Old" mode. The result array contains a renumbering map in "New to Old" mode as C++ map for performance reasons. + * + * \sa invertArrayN2O2O2NOptimized, MEDCouplingPointSet::renumberNodesInConn + */ +MCAuto< MapKeyVal > DataArrayInt32::giveN2OOptimized() const +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt32::giveN2OOptimized : single component expected !"); + MCAuto< MapKeyVal > ret(MapKeyVal::New()); + std::map& m(ret->data()); + const int *new2Old(begin()); + std::size_t nbOfNewElems(this->getNumberOfTuples()); + for(std::size_t i=0;i > invertArrayN2O2O2NOptimized() const; + MEDCOUPLING_EXPORT MCAuto< MapKeyVal > giveN2OOptimized() const; MEDCOUPLING_EXPORT DataArrayInt32 *invertArrayO2N2N2OBis(int newNbOfElem) const; MEDCOUPLING_EXPORT DataArrayInt32 *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate::mySelectByTupleId(new2OldBg,new2OldEnd); } MEDCOUPLING_EXPORT DataArrayInt32 *selectByTupleId(const DataArrayInt32& di) const { return DataArrayTemplate::mySelectByTupleId(di); } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py index 30b4af304..4e92707eb 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py @@ -210,6 +210,40 @@ class MEDCouplingBasicsTest6(unittest.TestCase): ptsPosExp=DataArrayDouble([6.+a,3.+b,3.+a,6.+a,3.,3.+b,6.+b,3.+b,3.+b,7.,3.+b,3.+b,6.+a,6.+a,3.+a,6.+b,6.+a,3.+b,7.,6.+a,3.+b,6.+a,7.,3.+b,6.+a,3.+b,3.,6.+a,6.+a,3.],10,3) self.assertTrue(m.getCoords()[ptsExpToBeModified].isEqual(ptsPosExp,1e-12)) pass + + def testRenumberNodesInConnOpt(self): + m=MEDCouplingUMesh("mesh",2) + m.allocateCells() + m.insertNextCell(NORM_QUAD4,[10000,10002,10001,10003]) + coo=DataArrayDouble([(0,0),(1,1),(1,0),(0,1)]) + m.setCoords(coo) + m.checkConsistencyLight() + # + d=DataArrayInt([10000,10001,10002,10003]) + myMap=d.invertArrayN2O2O2NOptimized() + myMap2=d.giveN2OOptimized() + m.checkConsistencyLight() + # + m.renumberNodesInConn(myMap) # <- test is here for UMesh + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([4,0,2,1,3]))) + m.renumberNodesInConn(myMap2) # <- test is here for UMesh + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([4,10000,10002,10001,10003]))) + # + m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) + m.setNodalConnectivity(DataArrayInt([10000,10002,10001,10003])) + m.setCoords(coo) + m.checkConsistencyLight() + m.renumberNodesInConn(myMap) # <- test is here for 1SGTUMesh + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([0,2,1,3]))) + # + m=MEDCoupling1DGTUMesh("mesh",NORM_POLYGON) + m.setCoords(coo) + m.setNodalConnectivity(DataArrayInt([10000,10002,10001,10003]),DataArrayInt([0,4])) + m.checkConsistencyLight() + m.renumberNodesInConn(myMap) # <- test is here for 1DGTUMesh + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([0,2,1,3]))) + self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4]))) + pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 8637c98fd..9ef614e64 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -2290,6 +2290,7 @@ namespace MEDCoupling DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const throw(INTERP_KERNEL::Exception); DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception); MCAuto< MapII > invertArrayN2O2O2NOptimized() const throw(INTERP_KERNEL::Exception); + MCAuto< MapII > giveN2OOptimized() const throw(INTERP_KERNEL::Exception); DataArrayInt *indicesOfSubPart(const DataArrayInt& partOfThis) const throw(INTERP_KERNEL::Exception); DataArrayInt *fromNoInterlace() const throw(INTERP_KERNEL::Exception); DataArrayInt *toNoInterlace() const throw(INTERP_KERNEL::Exception); -- 2.39.2