From 7ef17c68f4eb099188320b9b217b8bf6f85e4437 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 4 Mar 2020 18:00:25 +0100 Subject: [PATCH] Take advantage of med4.1 capabilities. --- src/MEDCoupling_Swig/MEDCouplingMemArray.i | 6 ++-- src/MEDLoader/MEDFileEntities.cxx | 15 ++++++++++ src/MEDLoader/MEDFileEntities.hxx | 4 +++ src/MEDLoader/MEDFileField1TS.cxx | 6 ++-- src/MEDLoader/MEDFileField1TS.hxx | 2 +- src/MEDLoader/MEDFileFieldMultiTS.cxx | 34 +++++++++++++++++++-- src/MEDLoader/MEDFileMesh.cxx | 4 ++- src/MEDLoader/MEDFileUtilities.cxx | 35 +++++++++++----------- src/MEDLoader/MEDFileUtilities.hxx | 13 ++++++++ src/MEDLoader/MEDLoader.cxx | 14 +++++++++ src/MEDLoader/Swig/MEDLoaderCommon.i | 1 + 11 files changed, 107 insertions(+), 27 deletions(-) diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 4c988d334..6d7020b4b 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -674,7 +674,8 @@ typedef DataArrayInt64 DataArrayIdType; GetIndicesOfSliceExplicitely(slic,&strt,&stp,&step,"DataArray::GetSlice (wrap) : the input slice is invalid !"); mcIdType a,b; DataArray::GetSlice(ToIdType(strt),ToIdType(stp),ToIdType(step),sliceId,nbOfSlices,a,b); - return PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(step)); + AutoPyPtr ap(PyInt_FromLong(a)),bp(PyInt_FromLong(b)),stepp(PyInt_FromLong(step)); + return PySlice_New(ap,bp,stepp); } PyObject *getSlice(PyObject *slic, mcIdType sliceId, mcIdType nbOfSlices) const @@ -685,7 +686,8 @@ typedef DataArrayInt64 DataArrayIdType; GetIndicesOfSlice(slic,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getSlice (wrap) : the input slice is invalid !"); mcIdType a,b; DataArray::GetSlice(ToIdType(strt),ToIdType(stp),ToIdType(step),sliceId,nbOfSlices,a,b); - return PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(step)); + AutoPyPtr ap(PyInt_FromLong(a)),bp(PyInt_FromLong(b)),stepp(PyInt_FromLong(step)); + return PySlice_New(ap,bp,stepp); } static mcIdType GetNumberOfItemGivenBES(PyObject *slic) diff --git a/src/MEDLoader/MEDFileEntities.cxx b/src/MEDLoader/MEDFileEntities.cxx index b6e96938c..dd8398d34 100644 --- a/src/MEDLoader/MEDFileEntities.cxx +++ b/src/MEDLoader/MEDFileEntities.cxx @@ -54,6 +54,11 @@ bool MEDFileStaticEntities::areAllStaticTypesPresent() const return false; } +bool MEDFileStaticEntities::areAllStaticPresentAndNoDyn() const +{ + return false; +} + ////////////// @@ -67,6 +72,11 @@ bool MEDFileAllStaticEntites::areAllStaticTypesPresent() const return true; } +bool MEDFileAllStaticEntites::areAllStaticPresentAndNoDyn() const +{ + return true; +} + ////////////// MEDFileAllStaticEntitiesPlusDyn::MEDFileAllStaticEntitiesPlusDyn(const MEDFileStructureElements *se):_se(se) @@ -85,6 +95,11 @@ bool MEDFileAllStaticEntitiesPlusDyn::areAllStaticTypesPresent() const return true; } +bool MEDFileAllStaticEntitiesPlusDyn::areAllStaticPresentAndNoDyn() const +{ + return false; +} + const MEDFileStructureElement *MEDFileAllStaticEntitiesPlusDyn::getWithGT(int idGT) const { return _se->getWithGT(idGT); diff --git a/src/MEDLoader/MEDFileEntities.hxx b/src/MEDLoader/MEDFileEntities.hxx index 7b7bcbcfc..6192660da 100644 --- a/src/MEDLoader/MEDFileEntities.hxx +++ b/src/MEDLoader/MEDFileEntities.hxx @@ -37,6 +37,7 @@ namespace MEDCoupling static MEDFileEntities *BuildFrom(const MEDFileStructureElements& se); virtual std::vector getDynGTAvail() const = 0; virtual bool areAllStaticTypesPresent() const = 0; + virtual bool areAllStaticPresentAndNoDyn() const = 0; virtual ~MEDFileEntities(); }; @@ -47,6 +48,7 @@ namespace MEDCoupling const std::vector< std::pair >& getEntries() const { return _entities; } std::vector getDynGTAvail() const; bool areAllStaticTypesPresent() const; + bool areAllStaticPresentAndNoDyn() const override; private: std::vector< std::pair > _entities; }; @@ -57,6 +59,7 @@ namespace MEDCoupling MEDFileAllStaticEntites() { } std::vector getDynGTAvail() const; bool areAllStaticTypesPresent() const; + bool areAllStaticPresentAndNoDyn() const override; }; class MEDLOADER_EXPORT MEDFileAllStaticEntitiesPlusDyn : public MEDFileEntities @@ -65,6 +68,7 @@ namespace MEDCoupling MEDFileAllStaticEntitiesPlusDyn(const MEDFileStructureElements *se); std::vector getDynGTAvail() const; bool areAllStaticTypesPresent() const; + bool areAllStaticPresentAndNoDyn() const override; const MEDFileStructureElement *getWithGT(int idGT) const; const MEDFileUMesh *getSupMeshWithName(const std::string& name) const; private: diff --git a/src/MEDLoader/MEDFileField1TS.cxx b/src/MEDLoader/MEDFileField1TS.cxx index dc51ad550..ea2514be5 100644 --- a/src/MEDLoader/MEDFileField1TS.cxx +++ b/src/MEDLoader/MEDFileField1TS.cxx @@ -739,19 +739,19 @@ bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFrom throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !"); } -void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities) +void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities, const MEDFileCapability *capability) { med_int numdt,numit; med_float dt; - med_int meshnumdt,meshnumit; + med_int meshnumdt(-1),meshnumit(-1); MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt)); + if(!capability || !capability->isFastReader()) { med_bool localMesh; med_int nmesh; INTERP_KERNEL::AutoPtr meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit)); // to check with Adrien for legacy MED files } - //MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt,&meshnumdt,&meshnumit)); if(_iteration!=numdt || _order!=numit) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !"); _field_per_mesh.resize(1); diff --git a/src/MEDLoader/MEDFileField1TS.hxx b/src/MEDLoader/MEDFileField1TS.hxx index 924ef6ee3..f88d5a6ab 100644 --- a/src/MEDLoader/MEDFileField1TS.hxx +++ b/src/MEDLoader/MEDFileField1TS.hxx @@ -116,7 +116,7 @@ namespace MEDCoupling public: MEDLOADER_EXPORT void allocNotFromFile(mcIdType newNbOfTuples); MEDLOADER_EXPORT bool allocIfNecessaryTheArrayToReceiveDataFromFile(); - MEDLOADER_EXPORT void loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities); + MEDLOADER_EXPORT void loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities, const MEDFileCapability *capability = nullptr); MEDLOADER_EXPORT void loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc); MEDLOADER_EXPORT void loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc); MEDLOADER_EXPORT void loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities); diff --git a/src/MEDLoader/MEDFileFieldMultiTS.cxx b/src/MEDLoader/MEDFileFieldMultiTS.cxx index 3f19a60c9..00c118f74 100644 --- a/src/MEDLoader/MEDFileFieldMultiTS.cxx +++ b/src/MEDLoader/MEDFileFieldMultiTS.cxx @@ -42,6 +42,8 @@ template class MEDCoupling::MEDFileTemplateFieldMultiTS; template class MEDCoupling::MEDFileNDTemplateFieldMultiTS; template class MEDCoupling::MEDFileNDTemplateFieldMultiTS; +extern INTERP_KERNEL::NormalizedCellType ConvertGeometryType(med_geometry_type geotype); + //= MEDFileAnyTypeFieldMultiTSWithoutSDA MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA() @@ -484,6 +486,32 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope() void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities) { _time_steps.resize(nbPdt); + // + INTERP_KERNEL::AutoCppPtr entitiesFast; + const MEDFileEntities *entitiesForSubInstances(entities); + MEDFileCapability mfcap(fid); + if( ( !entities || entities->areAllStaticPresentAndNoDyn() ) && mfcap.isFastReader()) + {// no entities + 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); + } + } + entitiesFast=new MEDFileStaticEntities(entitiesFastP); + entitiesForSubInstances=entitiesFast; + } for(int i=0;i > ts; @@ -519,11 +547,11 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysR throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32, FLOAT32 !"); } if(loadAll) - _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities); + _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entitiesForSubInstances); else - _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities); - synchronizeNameScope(); + _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entitiesForSubInstances,&mfcap); } + synchronizeNameScope(); } void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index b74224efb..f1dd3771c 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -7763,9 +7763,11 @@ TypeOfField MEDFileMesh::ConvertFromMEDFileEntity(med_entity_type etype) return ON_NODES; case MED_CELL: return ON_CELLS; + case MED_NODE_ELEMENT: + return ON_GAUSS_NE; default: { - std::ostringstream oss; oss << "EDFileMesh::ConvertFromMEDFileEntity : not recognized entity " << etype << " !"; + std::ostringstream oss; oss << "MEDFileMesh::ConvertFromMEDFileEntity : not recognized entity " << etype << " !"; throw INTERP_KERNEL::Exception(oss.str()); } } diff --git a/src/MEDLoader/MEDFileUtilities.cxx b/src/MEDLoader/MEDFileUtilities.cxx index d30377eae..026905a00 100644 --- a/src/MEDLoader/MEDFileUtilities.cxx +++ b/src/MEDLoader/MEDFileUtilities.cxx @@ -192,26 +192,22 @@ void MEDCoupling::MEDFileWritableStandAlone::write(const std::string& fileName, void MEDCoupling::MEDFileWritableStandAlone::write33(const std::string& fileName, int mode) const { + this->writeXX(fileName,mode,3,3,1); +} + +void MEDCoupling::MEDFileWritableStandAlone::write30(const std::string& fileName, int mode) const +{ + this->writeXX(fileName,mode,3,0,6); +} + +void MEDCoupling::MEDFileWritableStandAlone::writeXX(const std::string& fileName, int mode, med_int maj, med_int min, med_int rel) const +{ +#if ( MED_NUM_MAJEUR>4 || ( MED_NUM_MAJEUR==4 && MED_NUM_MINEUR>=1 ) ) med_access_mode medmod(MEDFileUtilities::TraduceWriteMode(mode)); - static const unsigned char EMPTY_FILE_3_3[]={0x89,0x48,0x44,0x46,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0x0,0x0,0x8,0x8,0x0,0x4,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd0,0x7,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x60,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x88,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa8,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x1,0x0,0x1,0x0,0x0,0x0,0x18,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x11,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x88,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa8,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x54,0x52,0x45,0x45,0x0,0x0,0x1,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0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0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}; -#if MED_NUM_MAJEUR>3 - med_bool fileexist,accessok; - MEDFILESAFECALLERRD0(MEDfileExist,(fileName.c_str(),medmod,&fileexist,&accessok)); - if(!accessok) - { - std::ostringstream oss; oss << "MEDFileWritableStandAlone::write33 : requested access to file \"" << fileName << "\" !"; - throw INTERP_KERNEL::Exception(oss.str()); - } - if(medmod==MED_ACC_CREAT || !fileexist) - { - std::ofstream ofs(fileName); - ofs.write(reinterpret_cast(EMPTY_FILE_3_3),sizeof(EMPTY_FILE_3_3)); - medmod=MEDFileUtilities::TraduceWriteMode(0); - } - MEDFileUtilities::AutoFid fid(MEDfileVersionOpen(fileName.c_str(),medmod,3,3,1)); + MEDFileUtilities::AutoFid fid(MEDfileVersionOpen(fileName.c_str(),medmod,maj,min,rel)); writeLL(fid); #else - std::ostringstream oss; oss << "MEDFileWritableStandAlone::write33 : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1."; + std::ostringstream oss; oss << "MEDFileWritableStandAlone::write" << maj << min << " : the MED version used to compile medcoupling is " << MEDFileVersionStr() << " ! If you need this feature please use version >= 4.1."; throw INTERP_KERNEL::Exception(oss.str()); #endif } @@ -239,3 +235,8 @@ std::string MEDCoupling::MEDFileWritableStandAlone::GenerateUniqueDftFileNameInM std::ostringstream oss; oss << DFT_FILENAME_IN_MEM << "_" << ii++; return oss.str(); } + +MEDCoupling::MEDFileCapability::MEDFileCapability(med_idt fid) +{ + MEDFILESAFECALLERRD0(MEDfileNumVersionRd,(fid,&_maj,&_min,&_rel)); +} diff --git a/src/MEDLoader/MEDFileUtilities.hxx b/src/MEDLoader/MEDFileUtilities.hxx index 501a6d5e5..7f82bae32 100644 --- a/src/MEDLoader/MEDFileUtilities.hxx +++ b/src/MEDLoader/MEDFileUtilities.hxx @@ -71,14 +71,27 @@ namespace MEDCoupling MEDLOADER_EXPORT virtual void writeLL(med_idt fid) const = 0; MEDLOADER_EXPORT virtual void write(const std::string& fileName, int mode) const; MEDLOADER_EXPORT virtual void write33(const std::string& fileName, int mode) const; + MEDLOADER_EXPORT virtual void write30(const std::string& fileName, int mode) const; MEDLOADER_EXPORT MCAuto serialize() const; MEDLOADER_EXPORT static std::string GenerateUniqueDftFileNameInMem(); public: MEDLOADER_EXPORT static const char DFT_FILENAME_IN_MEM[]; template static T *BuildFromMemoryChunk(DataArrayByte *db); + private: + void writeXX(const std::string& fileName, int mode, med_int maj, med_int min, med_int rel) const; }; + class MEDFileCapability + { + public: + MEDFileCapability(med_idt fid); + bool isFastReader() const { return _maj>=4 && _min >=1; } + private: + med_int _maj; + med_int _min; + med_int _rel; + }; MEDFileUtilities::AutoFid OpenMEDFileForRead(const std::string& fileName); } diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 597b25fc1..7f1a4d3a3 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -146,6 +146,20 @@ using namespace MEDCoupling; /// @cond INTERNAL +INTERP_KERNEL::NormalizedCellType ConvertGeometryType(med_geometry_type geotype) +{ + INTERP_KERNEL::NormalizedCellType result=INTERP_KERNEL::NORM_ERROR; + for(int i=0; i