/*!
* 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)
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.
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);
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 ;
}
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)
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);
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()