From: ageay Date: Tue, 9 Apr 2013 12:47:15 +0000 (+0000) Subject: Extend operator __pow__ of MEDCouplingFieldDouble X-Git-Tag: V6_main_FINAL~176 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f13d2cd793e92ed6400465e53f033f1e22487479;p=tools%2Fmedcoupling.git Extend operator __pow__ of MEDCouplingFieldDouble --- diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index ce398cb0b..f4e7f69b8 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -136,6 +136,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingFieldDouble::__sub__; %newobject ParaMEDMEM::MEDCouplingFieldDouble::__mul__; %newobject ParaMEDMEM::MEDCouplingFieldDouble::__div__; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__pow__; %newobject ParaMEDMEM::MEDCouplingFieldDouble::clone; %newobject ParaMEDMEM::MEDCouplingFieldDouble::cloneWithMesh; %newobject ParaMEDMEM::MEDCouplingFieldDouble::deepCpy; @@ -3605,6 +3606,73 @@ namespace ParaMEDMEM } } + MEDCouplingFieldDouble *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__pow__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__pow__ : 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) + return (*self)^(*other); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyPow(val); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Pow(self->getArray(),a); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Pow(self->getArray(),aaa); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Pow(self->getArray(),aaa); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } + } + PyObject *___iadd___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) { *self+=other;