From a25fc7c3173633c8eec4a4db9cda520f947317b7 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 29 Apr 2015 17:57:45 +0200 Subject: [PATCH] Urgent debug. --- src/MEDCoupling/MEDCouplingMemArray.cxx | 26 +++++++++++- src/MEDCoupling/MEDCouplingMemArray.hxx | 1 + src/MEDCoupling/MEDCouplingStructuredMesh.cxx | 6 +-- src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 2 +- src/MEDCoupling_Swig/MEDCouplingMemArray.i | 1 + src/MEDLoader/Swig/MEDLoaderTest3.py | 40 +++++++++++++++++++ 6 files changed, 70 insertions(+), 6 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 1fd6ba684..ee5145483 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -7729,17 +7729,20 @@ DataArrayInt *DataArrayInt::buildPermArrPerLevel() const /*! * Checks if contents of \a this array are equal to that of an array filled with * iota(). This method is particularly useful for DataArrayInt instances that represent - * a renumbering array to check the real need in renumbering. + * a renumbering array to check the real need in renumbering. In this case it is better to use isIdentity2 + * method of isIdentity method. + * * \return bool - \a true if \a this array contents == \a range( \a this->getNumberOfTuples()) * \throw If \a this is not allocated. * \throw If \a this->getNumberOfComponents() != 1. + * \sa isIdentity2 */ bool DataArrayInt::isIdentity() const { checkAllocated(); if(getNumberOfComponents()!=1) return false; - int nbOfTuples=getNumberOfTuples(); + int nbOfTuples(getNumberOfTuples()); const int *pt=getConstPointer(); for(int i=0;igetNumberOfTuples()) and if \a this has \a sizeExpected tuples in it. + * + * \throw If \a this is not allocated. + * \throw If \a this->getNumberOfComponents() != 1. + * \sa isIdentity + */ +bool DataArrayInt::isIdentity2(int sizeExpected) const +{ + bool ret0(isIdentity()); + if(!ret0) + return false; + return getNumberOfTuples()==sizeExpected; +} + /*! * Checks if all values in \a this array are equal to \a val. * \param [in] val - value to check equality of array values to. diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 3bbdc3722..1fc39204c 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -511,6 +511,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static DataArrayInt *BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const int *arr, const int *arrIBg, const int *arrIEnd, int &newNbOfTuples); MEDCOUPLING_EXPORT DataArrayInt *buildPermArrPerLevel() const; MEDCOUPLING_EXPORT bool isIdentity() const; + MEDCOUPLING_EXPORT bool isIdentity2(int sizeExpected) const; MEDCOUPLING_EXPORT bool isUniform(int val) const; MEDCOUPLING_EXPORT DataArrayInt *substr(int tupleIdBg, int tupleIdEnd=-1) const; MEDCOUPLING_EXPORT void rearrange(int newNbOfCompo); diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx index c6923804a..ceec53712 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx @@ -316,15 +316,15 @@ void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile, throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile is NULL or not allocated !"); if(profile->getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile should have exactly one component !"); - int nbTuples=profile->getNumberOfTuples(); + int nbTuples(profile->getNumberOfTuples()); int nbOfCells=getNumberOfCells(); code.resize(3); idsInPflPerType.resize(1); code[0]=(int)getTypeOfCell(0); code[1]=nbOfCells; idsInPflPerType.resize(1); - if(profile->isIdentity() && nbTuples==nbOfCells) + if(profile->isIdentity2(nbOfCells)) { code[2]=-1; - idsInPflPerType[0]=0; + idsInPflPerType[0]=profile->deepCpy(); idsPerType.clear(); return ; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index bcfa2c863..e8681a913 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -16538,7 +16538,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): m=MEDCoupling1SGTUMesh("mesh",NORM_TETRA4) ; m.setCoords(coo) exp8=1.7131322579364157 self.assertAlmostEqual(exp8,coo.buildEuclidianDistanceDenseMatrix().getMaxValue()[0],12)# <- the definition of diameter - for c in [[0,1,2,3],[0,1,3,2],[0,3,2,1],[0,3,1,2]]: + for c in [[0,1,2,3],[0,3,2,1],[0,1,3,2],[0,2,3,1],[0,3,1,2],[0,2,1,3]]: for i in xrange(4): m.setNodalConnectivity(DataArrayInt([(elt+i)%4 for elt in c])) self.assertAlmostEqual(m.computeDiameterField().getArray()[0],exp8,12) diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 29d4aa914..3e4010867 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -2612,6 +2612,7 @@ namespace ParaMEDMEM DataArrayInt *checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception); DataArrayInt *buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception); bool isIdentity() const throw(INTERP_KERNEL::Exception); + bool isIdentity2(int sizeExpected) const throw(INTERP_KERNEL::Exception); bool isUniform(int val) const throw(INTERP_KERNEL::Exception); DataArrayInt *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); void transpose() throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index a3a26455e..9e2e48cc0 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -4239,6 +4239,46 @@ class MEDLoaderTest(unittest.TestCase): self.assertEqual(mm.getFamilyId(elt),eltId) pass + def testNonRegrCMeshSetFieldPfl1(self): + """ Non regression test. For structured mesh, push a false partial field in MEDFileField1TS using setFieldProfile.""" + ff=MEDFileField1TS() + meshName="mesh" + mm=MEDFileCMesh() + m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() + m.setCoords(arr) + m.setName(meshName) + mm.setMesh(m) + field=MEDCouplingFieldDouble(ON_CELLS) + field.setMesh(m) + field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5])) + field.setName("Field") + field.checkCoherency() + pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU") #<- false profile because defined on all cells ! + ff.setFieldProfile(field,mm,0,pfl) # <- bug was revealed here ! + self.assertEqual(ff.getPfls(),()) + field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm) + self.assertTrue(field.isEqual(field2,1e-12,1e-12)) + del ff,mm,field,field2,pfl + # same with unstructured mesh + ff=MEDFileField1TS() + meshName="mesh" + mm=MEDFileUMesh() + m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() + m.setCoords(arr) + m.setName(meshName) + m=m.buildUnstructured() + mm[0]=m + field=MEDCouplingFieldDouble(ON_CELLS) + field.setMesh(m) + field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5])) + field.setName("Field") + field.checkCoherency() + pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU") + ff.setFieldProfile(field,mm,0,pfl) + self.assertEqual(ff.getPfls(),()) + field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm) + self.assertTrue(field.isEqual(field2,1e-12,1e-12)) + pass pass unittest.main() -- 2.39.2