]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
__getitem__ MEDFileFieldMultiTS.
authorageay <ageay>
Fri, 22 Jun 2012 09:41:47 +0000 (09:41 +0000)
committerageay <ageay>
Fri, 22 Jun 2012 09:41:47 +0000 (09:41 +0000)
API modification for unification getTime, setTime and getTimeSteps
in MEDLoader all is now normalized to iteration,order,valTime.
MEDCoupling is normalized valTime,iteration,order.

src/MEDLoader/Swig/MEDLoader.i
src/MEDLoader/Swig/MEDLoaderTest3.py

index 8fae00c9cd81d7c2a09fba300994c1d05e912231..b1e3bb8762bb019ed5699f26c69c1176b657e8a6 100644 (file)
@@ -88,6 +88,10 @@ using namespace ParaMEDMEM;
 %newobject ParaMEDMEM::MEDFileFields::getFieldAtPos;
 %newobject ParaMEDMEM::MEDFileFields::__getitem__;
 %newobject ParaMEDMEM::MEDFileFieldMultiTS::New;
+%newobject ParaMEDMEM::MEDFileFieldMultiTS::getTimeStepAtPos;
+%newobject ParaMEDMEM::MEDFileFieldMultiTS::getTimeStep;
+%newobject ParaMEDMEM::MEDFileFieldMultiTS::getTimeStepGivenTime;
+%newobject ParaMEDMEM::MEDFileFieldMultiTS::__getitem__;
 %newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldAtLevel;
 %newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldAtTopLevel;
 %newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldOnMeshAtLevel;
@@ -329,7 +333,7 @@ namespace ParaMEDMEM
     void setIteration(int it);
     int getIteration();
     void setTimeValue(double time);
-    void setTime(double time, int dt, int it);
+    void setTime(int dt, int it, double time);
     double getTimeValue() const;
     void setTimeUnit(const char *unit);
     const char *getTimeUnit() const;
@@ -404,9 +408,9 @@ namespace ParaMEDMEM
            int tmp1,tmp2;
            double tmp0=self->getTime(tmp1,tmp2);
            PyObject *res = PyList_New(3);
-           PyList_SetItem(res,0,SWIG_From_double(tmp0));
-           PyList_SetItem(res,1,SWIG_From_int(tmp1));
-           PyList_SetItem(res,2,SWIG_From_int(tmp2));
+           PyList_SetItem(res,0,SWIG_From_int(tmp1));
+           PyList_SetItem(res,1,SWIG_From_int(tmp2));
+           PyList_SetItem(res,2,SWIG_From_double(tmp0));
            return res;
          }
 
@@ -791,7 +795,7 @@ namespace ParaMEDMEM
     int getNumberOfComponents() const;
     bool isDealingTS(int iteration, int order) const;
     const std::vector<std::string>& getInfo() const;
-    void setTime(double val, int iteration, int order);
+    void setTime(int iteration, int order, double val);
     %extend
        {
           PyObject *getTime()
@@ -799,9 +803,9 @@ namespace ParaMEDMEM
            int tmp1,tmp2;
            double tmp0=self->getTime(tmp1,tmp2);
            PyObject *res = PyList_New(3);
-           PyList_SetItem(res,0,SWIG_From_double(tmp0));
-           PyList_SetItem(res,1,SWIG_From_int(tmp1));
-           PyList_SetItem(res,2,SWIG_From_int(tmp2));
+           PyList_SetItem(res,0,SWIG_From_int(tmp1));
+           PyList_SetItem(res,1,SWIG_From_int(tmp2));
+           PyList_SetItem(res,2,SWIG_From_double(tmp0));
            return res;
          }
 
@@ -988,6 +992,9 @@ namespace ParaMEDMEM
   {
   public:
     int getNumberOfTS() const;
+    void eraseEmptyTS() throw(INTERP_KERNEL::Exception);
+    int getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception);
+    int getPosGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception);
     std::string getName() const;
     void setName(const char *name);
     std::string getMeshName() const throw(INTERP_KERNEL::Exception);
@@ -1158,6 +1165,11 @@ namespace ParaMEDMEM
   public:
     static MEDFileFieldMultiTS *New();
     static MEDFileFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception);
+    //
+    MEDFileField1TS *getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception);
+    MEDFileField1TS *getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception);
+    MEDFileField1TS *getTimeStepGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception);
+    //
     void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const throw(INTERP_KERNEL::Exception);
@@ -1174,6 +1186,40 @@ namespace ParaMEDMEM
              return self->simpleRepr();
            }
 
+         MEDFileField1TS *__getitem__(PyObject *elt0) const throw(INTERP_KERNEL::Exception)
+         {
+           if(elt0 && PyInt_Check(elt0))
+             {//fmts[3]
+               int pos=PyInt_AS_LONG(elt0);
+               return self->getTimeStepAtPos(pos);
+             }
+           else if(elt0 && PyTuple_Check(elt0))
+             {
+               if(PyTuple_Size(elt0)==2)
+                 {
+                   PyObject *o0=PyTuple_GetItem(elt0,0);
+                   PyObject *o1=PyTuple_GetItem(elt0,1);
+                   if(PyInt_Check(o0) && PyInt_Check(o1))
+                     {//fmts(1,-1)
+                       int iter=PyInt_AS_LONG(o0);
+                       int order=PyInt_AS_LONG(o1);
+                       return self->getTimeStep(iter,order);
+                     }
+                   else
+                     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::__getitem__ : invalid input param ! input is a tuple of size 2 but two integers are expected in this tuple to request a time steps !");
+                 }
+               else
+                 throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::__getitem__ : invalid input param ! input is a tuple of size != 2 ! two integers are expected in this tuple to request a time steps !");
+             }
+           else if(elt0 && PyFloat_Check(elt0))
+             {
+               double val=PyFloat_AS_DOUBLE(elt0);
+               return self->getTimeStepGivenTime(val);
+             }
+           else
+             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::__getitem__ : invalid input params ! expected fmts[int], fmts[int,int] or fmts[double] to request time step !");
+         }
+
          PyObject *getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception)
            {
              DataArrayInt *ret1=0;
index f1afe9e3303a6c3d3233add689ea76f56a35b9e4..f0eb1fd1e56cc24fc9107107ba2eea2fb142bf87 100644 (file)
@@ -295,7 +295,7 @@ class MEDLoaderTest(unittest.TestCase):
     def testMEDMesh6(self):
         outFileName="MEDFileMesh5.med"
         m=MEDFileCMesh.New()
-        m.setTime(2.3,-1,-1)
+        m.setTime(-1,-1,2.3)
         m1=MEDCouplingCMesh.New();
         da=DataArrayDouble.New()
         da.setValues([0.,1.,2.],3,1)
@@ -327,7 +327,7 @@ class MEDLoaderTest(unittest.TestCase):
         self.assertEqual(expected1,mm.getFamilyArr(1,"family1").getValues())
         m2=mm.getMesh()
         tt=m.getTime()
-        m1.setTime(tt[0],tt[1],tt[2])
+        m1.setTime(tt[2],tt[0],tt[1])
         m1.setName(m.getName())
         m1.setTimeUnit(m.getTimeUnit())
         m1.setDescription(m.getDescription())
@@ -378,6 +378,9 @@ class MEDLoaderTest(unittest.TestCase):
         mm=MEDFileMesh.New("Pyfile17.med")
         mm.write("Pyfile17_bis.med",2)
         ff=MEDFileFieldMultiTS.New("Pyfile17.med","MeasureOfMesh_Extruded")
+        self.assertEqual([3,4],ff[1].getTime()[:-1])
+        self.assertEqual([3,4],ff[3,4].getTime()[:-1])
+        self.assertEqual([3,4],ff[0.01].getTime()[:-1])
         ff.write("Pyfile17_bis.med",0)
         pass
 
@@ -475,11 +478,11 @@ class MEDLoaderTest(unittest.TestCase):
         ff1.setFieldNoProfileSBT(f1)
         ff1.write(fname,0)
         f2=MEDLoader.ReadFieldCell(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2]);
-        ti,itt,orr=ff1.getTime()
+        itt,orr,ti=ff1.getTime()
         self.assertEqual(0,itt); self.assertEqual(1,orr); self.assertAlmostEqual(2.,ti,14);
         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
-        ff1.setTime(2.3,3,4)
-        ti,itt,orr=ff1.getTime()
+        ff1.setTime(3,4,2.3)
+        itt,orr,ti=ff1.getTime()
         self.assertEqual(3,itt); self.assertEqual(4,orr); self.assertAlmostEqual(2.3,ti,14);
         da,infos=ff1.getUndergroundDataArrayExt()
         f2.getArray().setName(da.getName())#da has the same name than f2
@@ -595,10 +598,10 @@ class MEDLoaderTest(unittest.TestCase):
         m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0)
         self.assertTrue(m1.isEqual(m1bis,1e-12))
         self.assertEqual(('f1', 'f21', 'f22'),d2.getFields().getFieldsNames())
-        self.assertEqual([(-1, -1, 0.0)],d2.getFields().getFieldAtPos(2).getTimeSteps())
-        self.assertEqual([(-1, -1, 0.0)],d2.getFields()[2].getTimeSteps())
-        self.assertEqual([(-1, -1, 0.0)],d2.getFields().getFieldWithName("f21").getTimeSteps())
-        self.assertEqual([(-1, -1, 0.0)],d2.getFields()["f21"].getTimeSteps())
+        self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldAtPos(2).getTimeSteps())
+        self.assertEqual([(-1,-1,0.0)],d2.getFields()[2].getTimeSteps())
+        self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldWithName("f21").getTimeSteps())
+        self.assertEqual([(-1,-1,0.0)],d2.getFields()["f21"].getTimeSteps())
         pass
     
     def testMEDField9(self):
@@ -662,7 +665,7 @@ class MEDLoaderTest(unittest.TestCase):
         self.assertTrue(vals.isEqual(d,1e-14))
         #
         ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
-        self.assertEqual([(-1, -1, 0.0), (1, 2, 1.2)],ff2.getTimeSteps())
+        self.assertEqual([(-1,-1,0.0), (1,2,1.2)],ff2.getTimeSteps())
         vals,pfl=ff2.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
         self.assertTrue(vals.isEqual(e,1e-14))