Salome HOME
Urgent debug. agy/BugStMeshSetFieldPflFalse
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 29 Apr 2015 15:57:45 +0000 (17:57 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 29 Apr 2015 15:57:45 +0000 (17:57 +0200)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/MEDCouplingStructuredMesh.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingMemArray.i
src/MEDLoader/Swig/MEDLoaderTest3.py

index 1fd6ba6846e5340383f9555d7b801b56a0f7650e..ee514548315a710085ad4ca73fd66512bcc491a8 100644 (file)
@@ -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;i<nbOfTuples;i++,pt++)
     if(*pt!=i)
@@ -7747,6 +7750,25 @@ bool DataArrayInt::isIdentity() const
   return true;
 }
 
+/*!
+ * This method is stronger than isIdentity method. This method checks than \a this can be considered as an identity function
+ * of a set having \a sizeExpected elements into itself.
+ *
+ * \param [in] sizeExpected - The number of elements
+ * \return bool - \a true if \a this array contents == \a range( \a this->getNumberOfTuples()) 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.
index 3bbdc372297bd1dc78c985e77d07d29b24dd0759..1fc39204c7441939393795170fdd4ecdf662ed35 100644 (file)
@@ -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);
index c6923804a534c05b51ce87640015f99c6adde8c8..ceec537123752580137af2d4b7451b64e46608a6 100644 (file)
@@ -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 ;
     }
index bcfa2c8635baedf4645ee872124f29c165f36a85..e8681a913bcc7bdeee79f445d3e4cbafc04644e2 100644 (file)
@@ -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)
index 29d4aa914ae30d239b3da7393974c4bd469eb53d..3e4010867a2cb4537847020b86776a334c68ed88 100644 (file)
@@ -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);
index a3a26455ef1bc7dd36d3b1852b6009c8918221fb..9e2e48cc0384e38bbc69f1ab568573ecb9d2dbba 100644 (file)
@@ -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()