From: Anthony Geay Date: Wed, 16 Jun 2021 11:59:08 +0000 (+0200) Subject: [EDF23724] : Get rid of DataArrayMedInt class not castable into DataArrayInt32 nor... X-Git-Tag: V9_8_0a1~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a3cd65d26d1d52eeea6312efae181cae00b34ce2;p=tools%2Fmedcoupling.git [EDF23724] : Get rid of DataArrayMedInt class not castable into DataArrayInt32 nor DataArrayInt64 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cbdccb0a8..1bce32afd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,6 +17,10 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +if(MED_INT_IS_LONG) + add_definitions(-DMED_INT_IS_LONG) +endif(MED_INT_IS_LONG) + # InterpKERNEL ADD_SUBDIRECTORY(INTERP_KERNEL) IF(MEDCOUPLING_BUILD_TESTS) diff --git a/src/MEDLoader/MEDFileBasis.hxx b/src/MEDLoader/MEDFileBasis.hxx index 32888e774..7fc94555e 100644 --- a/src/MEDLoader/MEDFileBasis.hxx +++ b/src/MEDLoader/MEDFileBasis.hxx @@ -66,30 +66,21 @@ namespace MEDCoupling namespace MEDCoupling { +#ifdef MED_INT_IS_LONG + using DataArrayMedInt = DataArrayInt64; +#else + using DataArrayMedInt = DataArrayInt32; +#endif - class DataArrayMedInt : public DataArrayDiscreteSigned< med_int > + template + DataArrayMedInt * DataArrayMedInt_Copy( const INTARRAY* intArray ) { - friend class DataArrayDiscrete; - public: - template - static DataArrayMedInt *Copy( const INTARRAY* array ); - static DataArrayMedInt *New() { return new DataArrayMedInt(); } - std::string getClassName() const override { return std::string("DataArrayMedInt"); } - DataArrayMedInt *deepCopy() const { return new DataArrayMedInt(*this); } - //DataArrayMedInt *buildNewEmptyInstance() const { return new DataArrayMedInt(); }//ko - DataArray *buildNewEmptyInstance() const { if ( sizeof(med_int)==sizeof(int)) return DataArrayInt32::New(); return DataArrayInt64::New(); } - public: - DataArrayMedInt *copySorted(bool asc=true) const override { MCAuto ret(this->deepCopy()); ret->sort(); return ret.retn(); } - DataArray *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); } - DataArray *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); } - DataArray *selectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleIdSafe(new2OldBg,new2OldEnd); } - DataArray *keepSelectedComponents(const std::vector& compoIds) const { return this->myKeepSelectedComponents(compoIds); } - DataArray *selectByTupleIdSafeSlice(mcIdType bg, mcIdType end2, mcIdType step) const { return this->mySelectByTupleIdSafeSlice(bg,end2,step); } - DataArray *selectByTupleRanges(const std::vector >& ranges) const { return this->mySelectByTupleRanges(ranges); } - private: - ~DataArrayMedInt() { } - DataArrayMedInt() { } - }; + DataArrayMedInt* medIntArray = DataArrayMedInt::New(); + medIntArray->alloc( intArray->getNumberOfTuples(), intArray->getNumberOfComponents() ); + medIntArray->copyStringInfoFrom( *intArray ); + std::copy( intArray->begin(), intArray->end(), medIntArray->getPointer() ); + return medIntArray; + } template< class T1, class T2 > MCAuto StaticCast( const MCAuto< T2 >& array ) @@ -106,7 +97,7 @@ namespace MEDCoupling { if ( sizeof( med_int ) == sizeof( typename INTARRAY::Type )) return StaticCast< DataArrayMedInt >( intArray ); - return DataArrayMedInt::Copy((const INTARRAY*) intArray ); + return DataArrayMedInt_Copy((const INTARRAY*) intArray ); } template< class INT > @@ -119,7 +110,7 @@ namespace MEDCoupling ia->incrRef(); return StaticCast< DataArrayMedInt >( ia ); } - return DataArrayMedInt::Copy( intArray ); + return DataArrayMedInt_Copy( intArray ); } template< class INT > @@ -164,15 +155,6 @@ namespace MEDCoupling return static_cast< INT >( mi ); } - template - DataArrayMedInt * DataArrayMedInt::Copy( const INTARRAY* intArray ) - { - DataArrayMedInt* medIntArray = DataArrayMedInt::New(); - medIntArray->alloc( intArray->getNumberOfTuples(), intArray->getNumberOfComponents() ); - medIntArray->copyStringInfoFrom( *intArray ); - std::copy( intArray->begin(), intArray->end(), medIntArray->getPointer() ); - return medIntArray; - } } #endif diff --git a/src/MEDLoader/MEDFileEquivalence.cxx b/src/MEDLoader/MEDFileEquivalence.cxx index 034d89582..58640f6d1 100644 --- a/src/MEDLoader/MEDFileEquivalence.cxx +++ b/src/MEDLoader/MEDFileEquivalence.cxx @@ -512,7 +512,7 @@ void MEDFileEquivalenceData::writeAdvanced(med_idt fid, med_entity_type medtype, INTERP_KERNEL::AutoPtr name(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_NAME_SIZE,meshName2,getFather()->getMesh()->getTooLongStrPolicy()); MEDLoaderBase::safeStrCpy(equName.c_str(),MED_NAME_SIZE,name,getFather()->getMesh()->getTooLongStrPolicy()); - MCAuto da2(DataArrayMedInt::Copy(da)); da2->rearrange(1); da2->applyLin(1,1); da2->rearrange(2); + MCAuto da2(DataArrayMedInt_Copy(da)); da2->rearrange(1); da2->applyLin(1,1); da2->rearrange(2); MEDFILESAFECALLERWR0(MEDequivalenceCorrespondenceWr,(fid,meshName2,name,dt,it,medtype,medgt,ToMedInt(da2->getNumberOfTuples()),da2->begin())); } diff --git a/src/MEDLoader/MEDFileFieldGlobs.cxx b/src/MEDLoader/MEDFileFieldGlobs.cxx index 52dcafb5c..3dfcebd2f 100644 --- a/src/MEDLoader/MEDFileFieldGlobs.cxx +++ b/src/MEDLoader/MEDFileFieldGlobs.cxx @@ -74,7 +74,7 @@ void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) co std::size_t nbOfPfls=_pfls.size(); for(std::size_t i=0;i cpy=DataArrayMedInt::Copy((const DataArrayIdType*)_pfls[i]); + MCAuto cpy=DataArrayMedInt_Copy((const DataArrayIdType*)_pfls[i]); cpy->applyLin(1,1,0); INTERP_KERNEL::AutoPtr pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy()); diff --git a/src/MEDLoader/MEDFileFieldMultiTS.cxx b/src/MEDLoader/MEDFileFieldMultiTS.cxx index 62a98ce78..8376767e7 100644 --- a/src/MEDLoader/MEDFileFieldMultiTS.cxx +++ b/src/MEDLoader/MEDFileFieldMultiTS.cxx @@ -496,18 +496,18 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysR MEDFileCapability mfcap(fid); if( ( !entities || entities->areAllStaticPresentAndNoDyn() ) && mfcap.isFastReader()) {// no entities - int nentitype(MEDfieldnEntityType(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT)); + med_int nentitype(MEDfieldnEntityType(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT)); INTERP_KERNEL::AutoPtr types(new med_entity_type[nentitype]); med_int usedbyncs; MEDFILESAFECALLERRD0(MEDfieldEntityType,(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT,types,&usedbyncs)); std::vector< std::pair > entitiesFastP; for(int i=0;i geotypes(new med_geometry_type[ngeotype]); med_int geousedbyncs; MEDFILESAFECALLERRD0(MEDfieldGeometryType,(fid,_name.c_str(),MED_ALL_DT,MED_ALL_IT,types[i],geotypes,&geousedbyncs)); - for(int j=0;j p(MEDFileMesh::ConvertFromMEDFileEntity(types[i]),ConvertGeometryType(geotypes[j])); entitiesFastP.push_back(p); diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx index 8ba0edfcc..7beaf1d10 100644 --- a/src/MEDLoader/MEDFileMeshElt.cxx +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -362,7 +362,7 @@ void MEDFileUMeshPerType::Write(med_idt fid, const std::string& mname, int mdim, const MEDCoupling1SGTUMesh *m0(dynamic_cast(m)); if(!m0) throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #1 !"); - MCAuto arr(DataArrayMedInt::Copy(m0->getNodalConnectivity())); + MCAuto arr(DataArrayMedInt_Copy(m0->getNodalConnectivity())); std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind(std::plus(),std::placeholders::_1,1)); MEDFILESAFECALLERWR0(MEDmeshElementConnectivityWr,(fid,mname.c_str(),dt,it,timm,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,ToMedInt(nbOfCells),arr->begin())); } @@ -373,7 +373,7 @@ void MEDFileUMeshPerType::Write(med_idt fid, const std::string& mname, int mdim, throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::Write : internal error #2 !"); if(ikt==INTERP_KERNEL::NORM_POLYGON || ikt==INTERP_KERNEL::NORM_QPOLYG) { - MCAuto arr(DataArrayMedInt::Copy(m0->getNodalConnectivity())),arrI(DataArrayMedInt::Copy(m0->getNodalConnectivityIndex())); + MCAuto arr(DataArrayMedInt_Copy(m0->getNodalConnectivity())),arrI(DataArrayMedInt_Copy(m0->getNodalConnectivityIndex())); std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind(std::plus(),std::placeholders::_1,1)); std::transform(arrI->begin(),arrI->end(),arrI->getPointer(),std::bind(std::plus(),std::placeholders::_1,1)); MEDFILESAFECALLERWR0(MEDmeshPolygon2Wr,(fid,mname.c_str(),dt,it,timm,MED_CELL,ikt==INTERP_KERNEL::NORM_POLYGON?MED_POLYGON:MED_POLYGON2,MED_NODAL,ToMedInt(nbOfCells+1),arrI->begin(),arr->begin())); diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index c992c4df0..6720c9503 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -522,9 +522,9 @@ void MEDCoupling::GetFamiliesGroupsInfo(const std::string& fileName, const std:: char nomfam[MED_NAME_SIZE+1]; for(med_int i=0;i(i+1))),famId; std::unique_ptr gro{new char[MED_LNAME_SIZE*nbGrps+1]}; - MEDFILESAFECALLERRD0(MEDfamilyInfo,(fid,meshName.c_str(),i+1,nomfam,&famId,gro.get())); + MEDFILESAFECALLERRD0(MEDfamilyInfo,(fid,meshName.c_str(),FromMedInt(i+1),nomfam,&famId,gro.get())); std::string fam(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE)); families[fam] = FromMedInt(famId); std::vector v(nbGrps); diff --git a/src/MEDLoader/Swig/MEDLoaderTest4.py b/src/MEDLoader/Swig/MEDLoaderTest4.py index 13d291198..59df1555d 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest4.py +++ b/src/MEDLoader/Swig/MEDLoaderTest4.py @@ -5627,6 +5627,25 @@ class MEDLoaderTest4(unittest.TestCase): self.assertTrue(v.isEqual(DataArrayDouble([0.0]),1e-14)) pass + @WriteInTmpDir + def test43(self): + """ + EDF23724 : point to error during 64bit convertion into medcoupling a DataArrayMedInt class was created. + This class is not dynamic_castable to DataArrayInt32 nor DataArrayInt64. It lead previously to strange behaviour + """ + fname = "tessss.med" + arr=DataArrayDouble(10) ; arr.iota() + m = MEDCouplingCMesh() ; m.setCoords(arr) + m = m.buildUnstructured() + m.setName("mesh") + mm = MEDFileUMesh() ; mm[0] = m + mm.setGlobalNumFieldAtLevel(1,DataArrayInt([0,4,5,6,10,12,16,17,19,20])) + mm.write(fname,2) + mm_reload = MEDFileMesh.New(fname) + # DataArrayMedInt class no more exists. Check that. + self.assertNotEqual(mm_reload.getGlobalNumFieldAtLevel(1).getClassName() , "DataArrayMedInt") + pass + pass if __name__ == "__main__":