]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Addition of MEDFileAnyTypeFieldMultiTS.pushBackTimeSteps to ease life of users with... V7_6_0b1
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 14 Apr 2015 09:45:24 +0000 (11:45 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 14 Apr 2015 09:45:24 +0000 (11:45 +0200)
src/MEDLoader/MEDFileField.cxx
src/MEDLoader/MEDFileField.hxx
src/MEDLoader/Swig/MEDLoaderCommon.i
src/MEDLoader/Swig/MEDLoaderTest3.py

index a7deeaf431a62c6eb7ec2c88d33c7d133a6085f6..d89c3ea9d097fc049da16ca8d468d065d2cd5704 100644 (file)
@@ -8379,6 +8379,18 @@ void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyT
     pushBackTimeStep(*it);
 }
 
+void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
+{
+  if(!fmts)
+    throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
+  int nbOfTS(fmts->getNumberOfTS());
+  for(int i=0;i<nbOfTS;i++)
+    {
+      MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
+      pushBackTimeStep(elt);
+    }
+}
+
 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
 {
   if(!f1ts)
index 125bb8162e76650ca249099d4c339e101d413542..bf0e3135189a83ae2a42d0d643b4271a711a8e7b 100644 (file)
@@ -968,6 +968,7 @@ namespace ParaMEDMEM
     MEDLOADER_EXPORT std::vector< std::pair<int,int> > getTimeSteps(std::vector<double>& ret1) const;
     MEDLOADER_EXPORT std::vector< std::pair<int,int> > getIterations() const;
     MEDLOADER_EXPORT void pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& 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;
index 9228a2e6e5a83d5ec44c76a7baa5576938cecac5..122db995c49e413413119129f8e19984ef20ba03 100644 (file)
@@ -2090,9 +2090,18 @@ namespace ParaMEDMEM
 
       void pushBackTimeSteps(PyObject *li) throw(INTERP_KERNEL::Exception)
       {
-        std::vector<MEDFileAnyTypeField1TS *> tmp;
-        convertFromPyObjVectorOfObj<ParaMEDMEM::MEDFileAnyTypeField1TS *>(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<MEDFileAnyTypeFieldMultiTS *>(argp));
+          }
+        else
+          {
+            std::vector<MEDFileAnyTypeField1TS *> tmp;
+            convertFromPyObjVectorOfObj<ParaMEDMEM::MEDFileAnyTypeField1TS *>(li,SWIGTYPE_p_ParaMEDMEM__MEDFileAnyTypeField1TS,"MEDFileAnyTypeField1TS",tmp);
+            self->pushBackTimeSteps(tmp);
+          }
       }
 
       static PyObject *MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(PyObject *li) throw(INTERP_KERNEL::Exception)
index e6d18ecc7d75dbf9ecf9ec516ffb0aba78f46c86..3a8a1daf1aa24ebb12993ba7cd946dd476115fc1 100644 (file)
@@ -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()