]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Extend operator __imul,isub,idiv,ipow__ of MEDCouplingFieldDouble
authorageay <ageay>
Tue, 9 Apr 2013 15:46:03 +0000 (15:46 +0000)
committerageay <ageay>
Tue, 9 Apr 2013 15:46:03 +0000 (15:46 +0000)
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 7349f9d8b35877625316a5c3a31e314ae5378982..528ab96a5354da00b03dc71426993ae6f65717e1 100644 (file)
@@ -3746,33 +3746,271 @@ namespace ParaMEDMEM
             { throw INTERP_KERNEL::Exception(msg); }
           }
       }
-      
-      PyObject *___isub___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
+
+      PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
       {
-        *self-=other;
-        Py_XINCREF(trueSelf);
-        return trueSelf;
+        const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__isub__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
+        const char msg2[]="in MEDCouplingFieldDouble.__isub__ : self field has no Array of values set !";
+        void *argp;
+        //
+        if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
+          {
+            MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
+            if(other)
+              {
+                *self-=*other;
+                Py_XINCREF(trueSelf);
+                return trueSelf;
+              }
+            else
+              throw INTERP_KERNEL::Exception(msg);
+          }
+        //
+        double val;
+        DataArrayDouble *a;
+        DataArrayDoubleTuple *aa;
+        std::vector<double> bb;
+        int sw;
+        convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+        switch(sw)
+          {
+          case 1:
+            {
+              if(!self->getArray())
+                throw INTERP_KERNEL::Exception(msg2);
+              self->getArray()->applyLin(1.,-val);
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 2:
+            {
+              MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret2=self->clone(false);
+              ret2->setArray(a);
+              *self-=*ret2;
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 3:
+            {
+              MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
+              MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret2=self->clone(false);
+              ret2->setArray(aaa);
+              *self-=*ret2;
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 4:
+            {
+              if(!self->getArray())
+                throw INTERP_KERNEL::Exception(msg2);
+              MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size());
+              self->getArray()->substractEqual(aaa);
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          default:
+            { throw INTERP_KERNEL::Exception(msg); }
+          }
       }
 
-      PyObject *___imul___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
+      PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
       {
-        *self*=other;
-        Py_XINCREF(trueSelf);
-        return trueSelf;
+        const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__imul__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
+        const char msg2[]="in MEDCouplingFieldDouble.__imul__ : self field has no Array of values set !";
+        void *argp;
+        //
+        if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
+          {
+            MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
+            if(other)
+              {
+                *self*=*other;
+                Py_XINCREF(trueSelf);
+                return trueSelf;
+              }
+            else
+              throw INTERP_KERNEL::Exception(msg);
+          }
+        //
+        double val;
+        DataArrayDouble *a;
+        DataArrayDoubleTuple *aa;
+        std::vector<double> bb;
+        int sw;
+        convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+        switch(sw)
+          {
+          case 1:
+            {
+              if(!self->getArray())
+                throw INTERP_KERNEL::Exception(msg2);
+              self->getArray()->applyLin(val,0);
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 2:
+            {
+              MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret2=self->clone(false);
+              ret2->setArray(a);
+              *self*=*ret2;
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 3:
+            {
+              MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
+              MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret2=self->clone(false);
+              ret2->setArray(aaa);
+              *self*=*ret2;
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 4:
+            {
+              if(!self->getArray())
+                throw INTERP_KERNEL::Exception(msg2);
+              MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size());
+              self->getArray()->multiplyEqual(aaa);
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          default:
+            { throw INTERP_KERNEL::Exception(msg); }
+          }
       }
 
-      PyObject *___idiv___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
+      PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
       {
-        *self/=other;
-        Py_XINCREF(trueSelf);
-        return trueSelf;
+        const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__idiv__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
+        const char msg2[]="in MEDCouplingFieldDouble.__idiv__ : self field has no Array of values set !";
+        void *argp;
+        //
+        if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
+          {
+            MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
+            if(other)
+              {
+                *self/=*other;
+                Py_XINCREF(trueSelf);
+                return trueSelf;
+              }
+            else
+              throw INTERP_KERNEL::Exception(msg);
+          }
+        //
+        double val;
+        DataArrayDouble *a;
+        DataArrayDoubleTuple *aa;
+        std::vector<double> bb;
+        int sw;
+        convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+        switch(sw)
+          {
+          case 1:
+            {
+              if(val==0.)
+                throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble.__idiv__ : trying to divide by zero !");
+              if(!self->getArray())
+                throw INTERP_KERNEL::Exception(msg2);
+              self->getArray()->applyLin(1./val,0);
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 2:
+            {
+              MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret2=self->clone(false);
+              ret2->setArray(a);
+              *self/=*ret2;
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 3:
+            {
+              MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
+              MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret2=self->clone(false);
+              ret2->setArray(aaa);
+              *self/=*ret2;
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 4:
+            {
+              if(!self->getArray())
+                throw INTERP_KERNEL::Exception(msg2);
+              MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size());
+              self->getArray()->divideEqual(aaa);
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          default:
+            { throw INTERP_KERNEL::Exception(msg); }
+          }
       }
 
-      PyObject *___ipow___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
+      PyObject *___ipow___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
       {
-        *self^=other;
-        Py_XINCREF(trueSelf);
-        return trueSelf;
+        const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__ipow__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
+        const char msg2[]="in MEDCouplingFieldDouble.__ipow__ : self field has no Array of values set !";
+        void *argp;
+        //
+        if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
+          {
+            MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
+            if(other)
+              {
+                *self^=*other;
+                Py_XINCREF(trueSelf);
+                return trueSelf;
+              }
+            else
+              throw INTERP_KERNEL::Exception(msg);
+          }
+        //
+        double val;
+        DataArrayDouble *a;
+        DataArrayDoubleTuple *aa;
+        std::vector<double> bb;
+        int sw;
+        convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+        switch(sw)
+          {
+          case 1:
+            {
+              if(!self->getArray())
+                throw INTERP_KERNEL::Exception(msg2);
+              self->getArray()->applyPow(val);
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 2:
+            {
+              MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret2=self->clone(false);
+              ret2->setArray(a);
+              *self^=*ret2;
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 3:
+            {
+              MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
+              MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret2=self->clone(false);
+              ret2->setArray(aaa);
+              *self^=*ret2;
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          case 4:
+            {
+              if(!self->getArray())
+                throw INTERP_KERNEL::Exception(msg2);
+              MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size());
+              self->getArray()->powEqual(aaa);
+              Py_XINCREF(trueSelf);
+              return trueSelf;
+            }
+          default:
+            { throw INTERP_KERNEL::Exception(msg); }
+          }
       }
 
       static MEDCouplingFieldDouble *MergeFields(PyObject *li) throw(INTERP_KERNEL::Exception)