From f7d02840b72f0b678924722d17c6fdc0329e8989 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 22 Mar 2016 10:15:20 +0100 Subject: [PATCH] Little refactoring for extractPart. --- src/MEDLoader/MEDFileField.cxx | 52 +++++++++++++++++----------- src/MEDLoader/MEDFileField.hxx | 11 ++++-- src/MEDLoader/Swig/MEDLoaderCommon.i | 20 ++++++----- 3 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 89784e20f..bbb30fc38 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -6890,6 +6890,11 @@ DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto& ar return arrC; } +MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map >& extractDef, MEDFileMesh *mm) const +{ + throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !"); +} + /*! * Returns a new MEDCouplingFieldDouble of a given type lying on * the top level cells of the first mesh in MED file. If \a this field @@ -8959,6 +8964,27 @@ int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiT return nts; } +/*! + * Return an extraction of \a this using \a extractDef map to specify the extraction. + * The keys of \a extractDef is level relative to max ext of \a mm mesh. + * + * \return A new object that the caller is responsible to deallocate. + */ +MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map >& extractDef, MEDFileMesh *mm) const +{ + if(!mm) + throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !"); + MCAuto fmtsOut(buildNewEmpty()); + int nbTS(getNumberOfTS()); + for(int i=0;i f1ts(getTimeStepAtPos(i)); + MCAuto f1tsOut(f1ts->extractPart(extractDef,mm)); + fmtsOut->pushBackTimeStep(f1tsOut); + } + return fmtsOut.retn(); +} + MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator() { return new MEDFileAnyTypeFieldMultiTSIterator(this); @@ -9389,25 +9415,9 @@ DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, return static_cast(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries)); } -/*! - * Return an extraction of \a this using \a extractDef map to specify the extraction. - * The keys of \a extractDef is level relative to max ext of \a mm mesh. - * - * \return A new object that the caller is responsible to deallocate. - */ -MEDFileFieldMultiTS *MEDFileFieldMultiTS::extractPart(const std::map >& extractDef, MEDFileMesh *mm) const +MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const { - if(!mm) - throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !"); - MCAuto fmtsOut(MEDFileFieldMultiTS::New()); - int nbTS(getNumberOfTS()); - for(int i=0;i f1ts(getTimeStepAtPos(i)); - MCAuto f1tsOut(f1ts->extractPart(extractDef,mm)); - fmtsOut->pushBackTimeStep(f1tsOut); - } - return fmtsOut.retn(); + return MEDFileFieldMultiTS::New(); } //= MEDFileAnyTypeFieldMultiTSIterator @@ -9853,9 +9863,9 @@ DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int return static_cast(contentNotNull()->getUndergroundDataArray(iteration,order)); } -MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::extractPart(const std::map >& extractDef, MEDFileMesh *mm) const +MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const { - throw INTERP_KERNEL::Exception("*MEDFileIntFieldMultiTS::extractPart : not implemented yet for int !"); + return MEDFileIntFieldMultiTS::New(); } //= MEDFileFields @@ -10362,7 +10372,7 @@ MEDFileFields *MEDFileFields::extractPart(const std::map fmts(getFieldAtPos(i)); if(!fmts) { std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !"; diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 8b8133866..fe9570f91 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -701,6 +701,8 @@ namespace MEDCoupling public: MEDLOADER_EXPORT static int LocateField2(med_idt fid, const std::string& fileName, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector& infos, std::string& dtunitOut); MEDLOADER_EXPORT static int LocateField(med_idt fid, const std::string& fileName, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector& infos, std::string& dtunitOut); + public: + MEDLOADER_EXPORT virtual MEDFileAnyTypeField1TS *extractPart(const std::map >& extractDef, MEDFileMesh *mm) const = 0; public: MEDLOADER_EXPORT virtual med_field_type getMEDFileFieldType() const = 0; MEDLOADER_EXPORT MEDFileAnyTypeField1TSWithoutSDA *contentNotNullBase(); @@ -782,6 +784,8 @@ namespace MEDCoupling MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArray() const; public: MEDLOADER_EXPORT static DataArrayInt *ReturnSafelyDataArrayInt(MCAuto& arr); + public: + MEDLOADER_EXPORT MEDFileIntField1TS *extractPart(const std::map >& extractDef, MEDFileMesh *mm) const; private: med_field_type getMEDFileFieldType() const { return MED_INT32; } const MEDFileIntField1TSWithoutSDA *contentNotNull() const; @@ -986,7 +990,8 @@ namespace MEDCoupling MEDLOADER_EXPORT std::vector< std::vector< std::pair > > getFieldSplitedByType(int iteration, int order, const std::string& mname, std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const; MEDLOADER_EXPORT MCAuto getContent(); public: - MEDLOADER_EXPORT virtual MEDFileAnyTypeFieldMultiTS *extractPart(const std::map >& extractDef, MEDFileMesh *mm) const = 0; + MEDLOADER_EXPORT virtual MEDFileAnyTypeFieldMultiTS *buildNewEmpty() const = 0; + MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *extractPart(const std::map >& extractDef, MEDFileMesh *mm) const; public: MEDLOADER_EXPORT std::vector getPflsReallyUsed() const; MEDLOADER_EXPORT std::vector getLocsReallyUsed() const; @@ -1037,7 +1042,7 @@ namespace MEDCoupling MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArray(int iteration, int order) const; MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair,std::pair > >& entries) const; public: - MEDLOADER_EXPORT MEDFileFieldMultiTS *extractPart(const std::map >& extractDef, MEDFileMesh *mm) const; + MEDLOADER_EXPORT MEDFileFieldMultiTS *buildNewEmpty() const; private: const MEDFileFieldMultiTSWithoutSDA *contentNotNull() const; MEDFileFieldMultiTSWithoutSDA *contentNotNull(); @@ -1077,7 +1082,7 @@ namespace MEDCoupling // MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArray(int iteration, int order) const; public: - MEDLOADER_EXPORT MEDFileIntFieldMultiTS *extractPart(const std::map >& extractDef, MEDFileMesh *mm) const; + MEDLOADER_EXPORT MEDFileIntFieldMultiTS *buildNewEmpty() const; private: const MEDFileIntFieldMultiTSWithoutSDA *contentNotNull() const; MEDFileIntFieldMultiTSWithoutSDA *contentNotNull(); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index a9d85eeb0..9b6c6c38e 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -156,6 +156,7 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime; %newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::__iter__; %newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::extractPart; +%newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::buildNewEmpty; %newobject MEDCoupling::MEDFileFieldMultiTS::New; %newobject MEDCoupling::MEDFileFieldMultiTS::LoadSpecificEntities; %newobject MEDCoupling::MEDFileFieldMultiTS::getFieldAtLevel; @@ -172,6 +173,7 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileAnyTypeField1TS::New; %newobject MEDCoupling::MEDFileAnyTypeField1TS::shallowCpy; %newobject MEDCoupling::MEDFileAnyTypeField1TS::deepCopy; +%newobject MEDCoupling::MEDFileAnyTypeField1TS::extractPart; %newobject MEDCoupling::MEDFileField1TS::New; %newobject MEDCoupling::MEDFileField1TS::getFieldAtLevel; %newobject MEDCoupling::MEDFileField1TS::getFieldAtTopLevel; @@ -179,7 +181,6 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileField1TS::getFieldAtLevelOld; %newobject MEDCoupling::MEDFileField1TS::getUndergroundDataArray; %newobject MEDCoupling::MEDFileField1TS::convertToInt; -%newobject MEDCoupling::MEDFileField1TS::extractPart; %newobject MEDCoupling::MEDFileIntField1TS::New; %newobject MEDCoupling::MEDFileIntField1TS::getUndergroundDataArray; @@ -1972,6 +1973,13 @@ namespace MEDCoupling PyList_SetItem(retPy,i,convertMEDFileField1TS(ret[i].retn(), SWIG_POINTER_OWN | 0 )); return retPy; } + + MEDFileAnyTypeField1TS *extractPart(PyObject *extractDef, MEDFileMesh *mm) const throw(INTERP_KERNEL::Exception) + { + std::map > extractDefCpp; + convertToMapIntDataArrayInt(extractDef,extractDefCpp); + return self->extractPart(extractDefCpp,mm); + } } }; @@ -2106,13 +2114,6 @@ namespace MEDCoupling PyTuple_SetItem(ret,1,elt); return ret; } - - MEDFileField1TS *extractPart(PyObject *extractDef, MEDFileMesh *mm) const - { - std::map > extractDefCpp; - convertToMapIntDataArrayInt(extractDef,extractDefCpp); - return self->extractPart(extractDefCpp,mm); - } } }; @@ -2274,6 +2275,7 @@ namespace MEDCoupling MEDFileAnyTypeField1TS *getTimeStepGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception); void pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts) throw(INTERP_KERNEL::Exception); void synchronizeNameScope() throw(INTERP_KERNEL::Exception); + MEDFileAnyTypeFieldMultiTS *buildNewEmpty() const throw(INTERP_KERNEL::Exception); %extend { int __len__() const throw(INTERP_KERNEL::Exception) @@ -2559,7 +2561,7 @@ namespace MEDCoupling } } - MEDFileAnyTypeFieldMultiTS *extractPart(PyObject *extractDef, MEDFileMesh *mm) const + MEDFileAnyTypeFieldMultiTS *extractPart(PyObject *extractDef, MEDFileMesh *mm) const throw(INTERP_KERNEL::Exception) { std::map > extractDefCpp; convertToMapIntDataArrayInt(extractDef,extractDefCpp); -- 2.39.2