From e95c24855ecc7fc1984428d55e5be867d316a3e2 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 14 Apr 2015 11:45:24 +0200 Subject: [PATCH] Addition of MEDFileAnyTypeFieldMultiTS.pushBackTimeSteps to ease life of users with more than 10000 time steps. --- src/MEDLoader/MEDFileField.cxx | 12 +++++ src/MEDLoader/MEDFileField.hxx | 1 + src/MEDLoader/Swig/MEDLoaderCommon.i | 15 ++++-- src/MEDLoader/Swig/MEDLoaderTest3.py | 76 ++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 3 deletions(-) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index a7deeaf43..d89c3ea9d 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -8379,6 +8379,18 @@ void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vectorgetNumberOfTS()); + for(int i=0;i elt(fmts->getTimeStepAtPos(i)); + pushBackTimeStep(elt); + } +} + void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts) { if(!f1ts) diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 125bb8162..bf0e31351 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -968,6 +968,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT std::vector< std::pair > getTimeSteps(std::vector& ret1) const; MEDLOADER_EXPORT std::vector< std::pair > getIterations() const; MEDLOADER_EXPORT void pushBackTimeSteps(const std::vector& f1ts); + MEDLOADER_EXPORT void pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts); MEDLOADER_EXPORT void pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts); MEDLOADER_EXPORT void synchronizeNameScope(); MEDLOADER_EXPORT int getPosOfTimeStep(int iteration, int order) const; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 9228a2e6e..122db995c 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -2090,9 +2090,18 @@ namespace ParaMEDMEM void pushBackTimeSteps(PyObject *li) throw(INTERP_KERNEL::Exception) { - std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDFileAnyTypeField1TS,"MEDFileAnyTypeField1TS",tmp); - self->pushBackTimeSteps(tmp); + void *argp(0); + int status(SWIG_ConvertPtr(li,&argp,SWIGTYPE_p_ParaMEDMEM__MEDFileAnyTypeFieldMultiTS,0|0)); + if(SWIG_IsOK(status)) + { + self->pushBackTimeSteps(reinterpret_cast(argp)); + } + else + { + std::vector tmp; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDFileAnyTypeField1TS,"MEDFileAnyTypeField1TS",tmp); + self->pushBackTimeSteps(tmp); + } } static PyObject *MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(PyObject *li) throw(INTERP_KERNEL::Exception) diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index e6d18ecc7..3a8a1daf1 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -4103,6 +4103,82 @@ class MEDLoaderTest(unittest.TestCase): self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs4[fieldName][i].getUndergroundDataArray(),1e-12)) pass pass + + def testMEDFileLotsOfTSRW1(self): + nbNodes=11 + fieldName="myField" + fileName="out.med" + nbPdt=300 # <- perftest = 30000 + meshName="Mesh" + # + maxPdt=100 # <- optimum = 500 + m=MEDCouplingCMesh() + arr=DataArrayDouble(nbNodes) ; arr.iota() + m.setCoords(arr) + m=m.buildUnstructured() + m.setName(meshName) + # + nbOfField=nbPdt/maxPdt + fs=MEDFileFields() + for j in xrange(nbOfField): + fmts=MEDFileFieldMultiTS() + s=DataArray.GetSlice(slice(0,nbPdt,1),j,nbOfField) + for i in xrange(s.start,s.stop,s.step): + f=MEDCouplingFieldDouble(ON_NODES) + f.setMesh(m) + arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i + f.setArray(arr) + f.setName("%s_%d"%(fieldName,j)) + f.setTime(float(i),i,0) + fmts.appendFieldNoProfileSBT(f) + pass + fs.pushField(fmts) + pass + # + mm=MEDFileUMesh() ; mm[0]=m + fs.write(fileName,2) + mm.write(fileName,0) + ############ + def appendInDict(d,key,val): + if key in d: + d[key].append(val) + else: + d[key]=[val] + pass + import re + allFields=MEDLoader.GetAllFieldNames(fileName) + allFieldsDict={} + pat=re.compile("([\d]+)([\s\S]+)$") + for st in allFields: + stRev=st[::-1] + m=pat.match(stRev) + if m: + appendInDict(allFieldsDict,m.group(2)[::-1],m.group(1)[::-1]) + pass + else: + appendInDict(allFieldsDict,st,'') + pass + pass + fs2=MEDFileFields() + for k in allFieldsDict: + if allFieldsDict[k]!=['']: + allFieldsDict[k]=sorted(allFieldsDict[k],key=lambda x: int(x)) + pass + fmts2=[] + for it in allFieldsDict[k]: + fmts2.append(MEDFileFieldMultiTS.LoadSpecificEntities(fileName,k+it,[(ON_NODES,NORM_ERROR)])) + pass + fmts2.reverse() + zeResu=fmts2.pop() + nbIter=len(fmts2) + for ii in xrange(nbIter): + zeResu.pushBackTimeSteps(fmts2.pop()) + pass + zeResu.setName(k) + fs2.pushField(zeResu) + pass + self.assertEqual(fs2[0].getTimeSteps(),[(i,0,float(i)) for i in xrange(nbPdt)]) + pass pass unittest.main() -- 2.39.2