self.assertTrue(NodeField.getArray().isUniform(0.,1e-12))
pass
+ def testSwigFieldOperationOpen1(self):
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__add__,2)
+ self.assertRaises(InterpKernelException,f.__add__,range(5))
+ self.assertRaises(InterpKernelException,f.__add__,arr)
+ self.assertRaises(InterpKernelException,f.__add__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__add__,2)
+ self.assertRaises(InterpKernelException,f.__add__,range(5))
+ self.assertRaises(InterpKernelException,f.__add__,arr)
+ self.assertRaises(InterpKernelException,f.__add__,f2)
+ self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ ff=f+2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2, 9), (3, 10), (4, 11), (5, 12), (6, 13)]),1e-12))
+ ff=f+arr
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0, 7), (2, 10), (4, 13), (6, 16), (8, 19)]),1e-12))
+ self.assertRaises(InterpKernelException,f.__add__,f2)
+ f2.setArray(arr)
+ ff=f+f2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0, 7), (2, 10), (4, 13), (6, 16), (8, 19)]),1e-12))
+ ff=f+[5,8]
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5, 15), (6, 16), (7, 17), (8, 18), (9, 19)]),1e-12))
+ pass
+
def setUp(self):
pass
pass
%newobject ParaMEDMEM::MEDCouplingFieldDouble::getIdsInRange;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::__getitem__;
-%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator+;
+%newobject ParaMEDMEM::MEDCouplingFieldDouble::__add__;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator-;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator*;
%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator/;
static MEDCouplingFieldDouble *MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception);
static MEDCouplingFieldDouble *DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception);
- MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *operator*(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception);
return self->extractSlice3D(orig,vect,eps);
}
+ MEDCouplingFieldDouble *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__add__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
+ const char msg2[]="in MEDCouplingFieldDouble.__add__ : 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<double> bb;
+ int sw;
+ convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
+ switch(sw)
+ {
+ case 1:
+ {
+ if(!self->getArray())
+ throw INTERP_KERNEL::Exception(msg2);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=self->getArray()->deepCpy();
+ ret->applyLin(1.,val);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret2=self->clone(false);
+ ret2->setArray(ret);
+ return ret2.retn();
+ }
+ case 2:
+ {
+ if(!self->getArray())
+ throw INTERP_KERNEL::Exception(msg2);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::Add(self->getArray(),a);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret2=self->clone(false);
+ ret2->setArray(ret);
+ return ret2.retn();
+ }
+ case 3:
+ {
+ if(!self->getArray())
+ throw INTERP_KERNEL::Exception(msg2);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::Add(self->getArray(),aaa);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret2=self->clone(false);
+ ret2->setArray(ret);
+ return ret2.retn();
+ }
+ 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());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::Add(self->getArray(),aaa);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> 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;
static DataArrayDouble *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception)
{
- const char *msg="ParaMEDMEM::DataArrayDouble::New : Available API are : \n-DataArrayDouble.New()\n--DataArrayDouble.New([1.,3.,4.])\n-DataArrayDouble.New([1.,3.,4.],3)\n-DataArrayDouble.New([1.,3.,4.,5.],2,2)\n-DataArrayDouble.New(5)\n-DataArrayDouble.New(5,2) !";
+ const char *msg="ParaMEDMEM::DataArrayDouble::New : Available API are : \n-DataArrayDouble.New()\n-DataArrayDouble.New([1.,3.,4.])\n-DataArrayDouble.New([1.,3.,4.],3)\n-DataArrayDouble.New([1.,3.,4.,5.],2,2)\n-DataArrayDouble.New([1.,3.,4.,5.,7,8.],3,2)\n-DataArrayDouble.New(5)\n-DataArrayDouble.New(5,2) !";
if(PyList_Check(elt0) || PyTuple_Check(elt0))
{
if(nbOfTuples)
static DataArrayInt *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception)
{
- const char *msg="ParaMEDMEM::DataArrayInt::New : Available API are : \n-DataArrayInt.New()\n--DataArrayInt.New([1,3,4])\n-DataArrayInt.New([1,3,4],3)\n-DataArrayInt.New([1,3,4,5],2,2)\n-DataArrayInt.New(5)\n-DataArrayInt.New(5,2) !";
+ const char *msg="ParaMEDMEM::DataArrayInt::New : Available API are : \n-DataArrayInt.New()\n-DataArrayInt.New([1,3,4])\n-DataArrayInt.New([1,3,4],3)\n-DataArrayInt.New([1,3,4,5],2,2)\n-DataArrayInt.New([1,3,4,5,7,8],3,2)\n-DataArrayInt.New(5)\n-DataArrayInt.New(5,2) !";
if(PyList_Check(elt0) || PyTuple_Check(elt0))
{
if(nbOfTuples)