1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "InterpKernelAutoPtr.hxx"
23 #include <numpy/arrayobject.h>
25 void numarrdeal(void *pt, void *wron)
27 void **wronc=(void **)wron;
28 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
29 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
33 PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
34 objC->flags|=NPY_OWNDATA;
35 Py_XDECREF(weakRefOnOwner);
40 typedef void (*MyDeallocator)(void *,void *);
41 MyDeallocator deall=(MyDeallocator)wronc[1];
47 template<class MCData>
48 struct PyCallBackDataArraySt {
53 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayInt> PyCallBackDataArrayInt;
54 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayDouble> PyCallBackDataArrayDouble;
58 static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
60 static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
62 PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
63 return (PyObject *)self;
66 static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
68 PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
69 return (PyObject *)self;
72 static void callbackmcdataarray_dealloc(PyObject *self)
74 Py_TYPE(self)->tp_free(self);
77 static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
81 ParaMEDMEM::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
88 static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
92 ParaMEDMEM::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
100 PyTypeObject PyCallBackDataArrayInt_RefType = {
101 PyVarObject_HEAD_INIT(&PyType_Type, 0)
102 "callbackmcdataarrayint",
103 sizeof(PyCallBackDataArrayInt),
105 callbackmcdataarray_dealloc, /*tp_dealloc*/
112 0, /*tp_as_sequence*/
115 (ternaryfunc)callbackmcdataarrayint_call, /*tp_call*/
120 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
124 0, /*tp_richcompare*/
125 0, /*tp_weaklistoffset*/
136 callbackmcdataarray___init__, /*tp_init*/
137 PyType_GenericAlloc, /*tp_alloc*/
138 callbackmcdataarrayint___new__, /*tp_new*/
139 PyObject_GC_Del, /*tp_free*/
142 PyTypeObject PyCallBackDataArrayDouble_RefType = {
143 PyVarObject_HEAD_INIT(&PyType_Type, 0)
144 "callbackmcdataarraydouble",
145 sizeof(PyCallBackDataArrayDouble),
147 callbackmcdataarray_dealloc, /*tp_dealloc*/
154 0, /*tp_as_sequence*/
157 (ternaryfunc)callbackmcdataarraydouble_call, /*tp_call*/
162 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
166 0, /*tp_richcompare*/
167 0, /*tp_weaklistoffset*/
178 callbackmcdataarray___init__, /*tp_init*/
179 PyType_GenericAlloc, /*tp_alloc*/
180 callbackmcdataarraydouble___new__, /*tp_new*/
181 PyObject_GC_Del, /*tp_free*/
184 template<class MCData>
185 void numarrdeal2(void *pt, void *obj)
187 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
188 void **obj1=(void **)obj;
189 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
190 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
192 Py_XDECREF(weakRefOnOwner);
197 template<class MCData, class T>
198 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
200 int ndim=PyArray_NDIM(elt0);
202 throw INTERP_KERNEL::Exception("Input numpy array has not 1 dimension !");//to do 1 or 2.
203 if(PyArray_ObjectType(elt0,0)!=npyObjectType)
205 std::ostringstream oss; oss << "Input numpy array has not of type " << msg << " !";
206 throw INTERP_KERNEL::Exception(oss.str().c_str());//to do 1 or 2.
208 npy_intp stride=PyArray_STRIDE(elt0,0);
209 int itemSize=PyArray_ITEMSIZE(elt0);
211 throw INTERP_KERNEL::Exception("Input numpy array has item size < stride !");
212 if(stride!=sizeof(T))
214 std::ostringstream oss; oss << "Input numpy array has not stride set to " << sizeof(T) << " !";
215 throw INTERP_KERNEL::Exception(oss.str().c_str());
217 npy_intp sz=PyArray_DIM(elt0,0);
218 const char *data=PyArray_BYTES(elt0);
219 typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<MCData> ret=MCData::New();
220 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
222 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
223 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & NPY_OWNDATA)?elt0C:NULL;
224 int mask=NPY_OWNDATA; mask=~mask;
226 PyObject *deepestObj=elt0;
227 PyObject *base=elt0C->base;
228 if(base) deepestObj=base;
231 if(PyArray_Check(base))
233 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
234 eltOwning=(PyArray_FLAGS(baseC) & NPY_OWNDATA)?baseC:eltOwning;
237 if(base) deepestObj=base;
242 typename ParaMEDMEM::MemArray<T>& mma=ret->accessToMemArray();
245 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
247 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz,1);
248 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
249 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
250 mma.setParameterForDeallocator(objs);
251 mma.setSpecificDeallocator(numarrdeal2<MCData>);
252 //"Impossible to share this numpy array chunk of data, because already shared by an another non numpy array object (maybe an another DataArrayInt instance) ! Release it, or perform a copy on the input array !");
256 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz,1);
257 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
258 void **objs=new void *[2]; objs[0]=ref; objs[1]=(void*) ParaMEDMEM::MemArray<T>::CDeallocator;
259 mma.setParameterForDeallocator(objs);
260 mma.setSpecificDeallocator(numarrdeal);
263 else if(PyArray_ISBEHAVED_RO(elt0))
264 ret->useArray(reinterpret_cast<const T *>(data),false,ParaMEDMEM::CPP_DEALLOC,sz,1);
268 template<class MCData, class T>
269 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
271 if(!self->isAllocated())
273 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
274 throw INTERP_KERNEL::Exception(oss.str().c_str());
276 ParaMEDMEM::MemArray<T>& mem=self->accessToMemArray();
277 int nbComp=self->getNumberOfComponents();
278 if(nbComp!=1 && nbComp!=2)
280 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is " << nbComp << " ! Should 1 or 2 !";
281 throw INTERP_KERNEL::Exception(oss.str().c_str());
283 std::size_t sz=self->getNbOfElems();
285 dim[0]=(npy_intp)self->getNumberOfTuples(); dim[1]=2;
286 const T *bg=self->getConstPointer();
287 PyObject *ret=PyArray_SimpleNewFromData(nbComp,dim,npyObjectType,const_cast<T *>(bg));
288 if(mem.isDeallocatorCalled())
290 if(mem.getDeallocator()!=ParaMEDMEM::MemArray<T>::CDeallocator)
292 int mask=NPY_OWNDATA; mask=~mask;
293 (reinterpret_cast<PyArrayObject *>(ret))->flags&=mask;
298 PyObject *ref=PyWeakref_NewRef(ret,NULL);
299 void **objs=new void *[2]; objs[0]=ref; objs[1]=(void*) ParaMEDMEM::MemArray<T>::CDeallocator;
300 mem.setParameterForDeallocator(objs);
301 mem.setSpecificDeallocator(numarrdeal);
310 static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception)
313 if(dynamic_cast<ParaMEDMEM::MEDCouplingUMesh *>(mesh))
314 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner);
315 if(dynamic_cast<ParaMEDMEM::MEDCouplingExtrudedMesh *>(mesh))
316 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
317 if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(mesh))
318 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner);
319 if(dynamic_cast<ParaMEDMEM::MEDCouplingCurveLinearMesh *>(mesh))
320 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner);
322 throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
326 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
329 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP0 *>(fd))
330 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner);
331 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP1 *>(fd))
332 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner);
333 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGauss *>(fd))
334 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner);
335 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE *>(fd))
336 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner);
337 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationKriging *>(fd))
338 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner);
340 throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
344 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
347 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
348 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
349 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
350 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
352 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
356 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
359 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
360 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
362 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
366 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
368 PyObject *ret=PyList_New(size);
369 for(int i=0;i<size;i++)
370 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
374 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
377 PyObject *ret=PyList_New(size);
378 for(int i=0;i<size;i++)
379 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
383 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
386 PyObject *ret=PyList_New(size);
387 std::set<int>::const_iterator it=v.begin();
388 for(int i=0;i<size;i++,it++)
389 PyList_SetItem(ret,i,PyInt_FromLong(*it));
393 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
395 PyObject *ret=PyList_New(nbOfTuples);
396 for(int i=0;i<nbOfTuples;i++)
398 PyObject *t=PyTuple_New(nbOfComp);
399 for(int j=0;j<nbOfComp;j++)
400 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
401 PyList_SetItem(ret,i,t);
406 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
408 if(PyList_Check(pyLi))
410 *size=PyList_Size(pyLi);
411 int *tmp=new int[*size];
412 for(int i=0;i<*size;i++)
414 PyObject *o=PyList_GetItem(pyLi,i);
417 int val=(int)PyInt_AS_LONG(o);
423 throw INTERP_KERNEL::Exception("list must contain integers only");
428 else if(PyTuple_Check(pyLi))
430 *size=PyTuple_Size(pyLi);
431 int *tmp=new int[*size];
432 for(int i=0;i<*size;i++)
434 PyObject *o=PyTuple_GetItem(pyLi,i);
437 int val=(int)PyInt_AS_LONG(o);
443 throw INTERP_KERNEL::Exception("tuple must contain integers only");
450 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
454 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
456 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
457 if(PyList_Check(pyLi))
459 int size=PyList_Size(pyLi);
461 for(int i=0;i<size;i++)
463 PyObject *o=PyList_GetItem(pyLi,i);
466 int sz2=PyTuple_Size(o);
468 throw INTERP_KERNEL::Exception(msg);
469 PyObject *o_0=PyTuple_GetItem(o,0);
470 if(!PyInt_Check(o_0))
471 throw INTERP_KERNEL::Exception(msg);
472 PyObject *o_1=PyTuple_GetItem(o,1);
473 if(!PyInt_Check(o_1))
474 throw INTERP_KERNEL::Exception(msg);
475 arr[i].first=(int)PyInt_AS_LONG(o_0);
476 arr[i].second=(int)PyInt_AS_LONG(o_1);
479 throw INTERP_KERNEL::Exception(msg);
482 else if(PyTuple_Check(pyLi))
484 int size=PyTuple_Size(pyLi);
486 for(int i=0;i<size;i++)
488 PyObject *o=PyTuple_GetItem(pyLi,i);
491 int sz2=PyTuple_Size(o);
493 throw INTERP_KERNEL::Exception(msg);
494 PyObject *o_0=PyTuple_GetItem(o,0);
495 if(!PyInt_Check(o_0))
496 throw INTERP_KERNEL::Exception(msg);
497 PyObject *o_1=PyTuple_GetItem(o,1);
498 if(!PyInt_Check(o_1))
499 throw INTERP_KERNEL::Exception(msg);
500 arr[i].first=(int)PyInt_AS_LONG(o_0);
501 arr[i].second=(int)PyInt_AS_LONG(o_1);
504 throw INTERP_KERNEL::Exception(msg);
508 throw INTERP_KERNEL::Exception(msg);
511 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
513 if(PyList_Check(pyLi))
515 int size=PyList_Size(pyLi);
517 for(int i=0;i<size;i++)
519 PyObject *o=PyList_GetItem(pyLi,i);
522 int val=(int)PyInt_AS_LONG(o);
526 throw INTERP_KERNEL::Exception("list must contain integers only");
529 else if(PyTuple_Check(pyLi))
531 int size=PyTuple_Size(pyLi);
533 for(int i=0;i<size;i++)
535 PyObject *o=PyTuple_GetItem(pyLi,i);
538 int val=(int)PyInt_AS_LONG(o);
542 throw INTERP_KERNEL::Exception("tuple must contain integers only");
547 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
551 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
554 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
556 if(PyList_Check(pyLi))
558 int size=PyList_Size(pyLi);
559 for(int i=0;i<size;i++)
561 PyObject *o=PyList_GetItem(pyLi,i);
564 int val=(int)PyInt_AS_LONG(o);
569 std::vector<int> arr2;
570 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
571 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
573 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
574 throw INTERP_KERNEL::Exception(oss.str().c_str());
576 arr.insert(arr.end(),arr2.begin(),arr2.end());
580 else if(PyTuple_Check(pyLi))
582 int size=PyTuple_Size(pyLi);
583 for(int i=0;i<size;i++)
585 PyObject *o=PyTuple_GetItem(pyLi,i);
588 int val=(int)PyInt_AS_LONG(o);
593 std::vector<int> arr2;
594 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
595 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
597 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
598 throw INTERP_KERNEL::Exception(oss.str().c_str());
600 arr.insert(arr.end(),arr2.begin(),arr2.end());
605 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
608 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
612 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
613 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
615 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
616 oss << " whereas nb of components expected is " << nbOfComp << " !";
617 throw INTERP_KERNEL::Exception(oss.str().c_str());
624 if((nbOfTuples!=size1 || nbOfComp!=size2))
626 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
628 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
629 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
630 throw INTERP_KERNEL::Exception(oss.str().c_str());
636 if(nbOfTuples==size1)
640 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
641 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
642 throw INTERP_KERNEL::Exception(oss.str().c_str());
648 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
650 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
651 if(PyInt_Check(pyLi))
653 long val=PyInt_AS_LONG(pyLi);
658 throw INTERP_KERNEL::Exception(MSG);
661 else if(PyList_Check(pyLi))
663 int size=PyList_Size(pyLi);
665 for(int i=0;i<size;i++)
667 PyObject *o=PyList_GetItem(pyLi,i);
669 fillArrayWithPyListInt3(o,tmp1,ret);
677 throw INTERP_KERNEL::Exception(MSG);
680 else if(PyTuple_Check(pyLi))
682 int size=PyTuple_Size(pyLi);
684 for(int i=0;i<size;i++)
686 PyObject *o=PyTuple_GetItem(pyLi,i);
688 fillArrayWithPyListInt3(o,tmp1,ret);
696 throw INTERP_KERNEL::Exception(MSG);
700 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
703 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
705 std::vector<int> ret;
706 int size1=-1,size2=-1;
707 if(PyList_Check(pyLi))
709 size1=PyList_Size(pyLi);
710 for(int i=0;i<size1;i++)
712 PyObject *o=PyList_GetItem(pyLi,i);
713 fillArrayWithPyListInt3(o,size2,ret);
718 else if(PyTuple_Check(pyLi))
720 size1=PyTuple_Size(pyLi);
721 for(int i=0;i<size1;i++)
723 PyObject *o=PyTuple_GetItem(pyLi,i);
724 fillArrayWithPyListInt3(o,size2,ret);
730 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
732 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
736 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
738 if(PyList_Check(pyLi))
740 Py_ssize_t sz=PyList_Size(pyLi);
742 for(int i=0;i<sz;i++)
744 PyObject *o=PyList_GetItem(pyLi,i);
745 if(PyString_Check(o))
746 vec[i]=PyString_AsString(o);
752 else if(PyTuple_Check(pyLi))
754 Py_ssize_t sz=PyTuple_Size(pyLi);
756 for(int i=0;i<sz;i++)
758 PyObject *o=PyTuple_GetItem(pyLi,i);
759 if(PyString_Check(o))
760 vec[i]=PyString_AsString(o);
770 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
772 PyObject *ret=PyList_New(size);
773 for(int i=0;i<size;i++)
774 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
778 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
781 PyObject *ret=PyList_New(size);
782 for(int i=0;i<size;i++)
783 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
787 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
789 PyObject *ret=PyList_New(nbOfTuples);
790 for(int i=0;i<nbOfTuples;i++)
792 PyObject *t=PyTuple_New(nbOfComp);
793 for(int j=0;j<nbOfComp;j++)
794 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
795 PyList_SetItem(ret,i,t);
800 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
802 PyObject *ret=PyList_New(nbOfTuples);
803 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
804 for(int i=0;i<nbOfTuples;i++)
806 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
807 PyList_SetItem(ret,i,PyString_FromString(tmp));
812 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
814 if(PyList_Check(pyLi))
816 *size=PyList_Size(pyLi);
817 double *tmp=new double[*size];
818 for(int i=0;i<*size;i++)
820 PyObject *o=PyList_GetItem(pyLi,i);
823 double val=PyFloat_AS_DOUBLE(o);
826 else if(PyInt_Check(o))
828 long val0=PyInt_AS_LONG(o);
835 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
840 else if(PyTuple_Check(pyLi))
842 *size=PyTuple_Size(pyLi);
843 double *tmp=new double[*size];
844 for(int i=0;i<*size;i++)
846 PyObject *o=PyTuple_GetItem(pyLi,i);
849 double val=PyFloat_AS_DOUBLE(o);
852 else if(PyInt_Check(o))
854 long val0=PyInt_AS_LONG(o);
861 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
867 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
870 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
872 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
873 if(PyFloat_Check(pyLi))
879 throw INTERP_KERNEL::Exception(MSG);
880 double val=PyFloat_AS_DOUBLE(pyLi);
883 else if(PyInt_Check(pyLi))
885 long val0=PyInt_AS_LONG(pyLi);
891 throw INTERP_KERNEL::Exception(MSG);
894 else if(PyList_Check(pyLi))
896 int size=PyList_Size(pyLi);
898 for(int i=0;i<size;i++)
900 PyObject *o=PyList_GetItem(pyLi,i);
902 fillArrayWithPyListDbl3(o,tmp1,ret);
910 throw INTERP_KERNEL::Exception(MSG);
913 else if(PyTuple_Check(pyLi))
915 int size=PyTuple_Size(pyLi);
917 for(int i=0;i<size;i++)
919 PyObject *o=PyTuple_GetItem(pyLi,i);
921 fillArrayWithPyListDbl3(o,tmp1,ret);
929 throw INTERP_KERNEL::Exception(MSG);
933 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
936 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
938 std::vector<double> ret;
939 int size1=-1,size2=-1;
940 if(PyList_Check(pyLi))
942 size1=PyList_Size(pyLi);
943 for(int i=0;i<size1;i++)
945 PyObject *o=PyList_GetItem(pyLi,i);
946 fillArrayWithPyListDbl3(o,size2,ret);
951 else if(PyTuple_Check(pyLi))
953 size1=PyTuple_Size(pyLi);
954 for(int i=0;i<size1;i++)
956 PyObject *o=PyTuple_GetItem(pyLi,i);
957 fillArrayWithPyListDbl3(o,size2,ret);
963 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
965 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
969 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
971 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
974 if(PyList_Check(pyLi))
976 int size=PyList_Size(pyLi);
978 for(int i=0;i<size;i++)
980 PyObject *obj=PyList_GetItem(pyLi,i);
981 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
982 if(!SWIG_IsOK(status))
983 throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
984 T arg=reinterpret_cast< T >(argp);
988 else if(PyTuple_Check(pyLi))
990 int size=PyTuple_Size(pyLi);
992 for(int i=0;i<size;i++)
994 PyObject *obj=PyTuple_GetItem(pyLi,i);
995 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
996 if(!SWIG_IsOK(status))
998 std::ostringstream oss; oss << "tuple must contain only " << typeStr;
999 throw INTERP_KERNEL::Exception(oss.str().c_str());
1001 T arg=reinterpret_cast< T >(argp);
1005 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1008 T arg=reinterpret_cast< T >(argp);
1012 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1016 * if python int -> cpp int sw=1
1017 * if python list[int] -> cpp vector<int> sw=2
1018 * if python tuple[int] -> cpp vector<int> sw=2
1019 * if python DataArrayInt -> cpp DataArrayInt sw=3
1020 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1022 * switch between (int,vector<int>,DataArrayInt)
1024 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1027 if(PyInt_Check(value))
1029 iTyypp=(int)PyInt_AS_LONG(value);
1033 if(PyTuple_Check(value))
1035 int size=PyTuple_Size(value);
1036 stdvecTyypp.resize(size);
1037 for(int i=0;i<size;i++)
1039 PyObject *o=PyTuple_GetItem(value,i);
1041 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1044 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1045 throw INTERP_KERNEL::Exception(oss.str().c_str());
1051 if(PyList_Check(value))
1053 int size=PyList_Size(value);
1054 stdvecTyypp.resize(size);
1055 for(int i=0;i<size;i++)
1057 PyObject *o=PyList_GetItem(value,i);
1059 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1062 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1063 throw INTERP_KERNEL::Exception(oss.str().c_str());
1070 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1071 if(SWIG_IsOK(status))
1073 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1077 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1078 if(SWIG_IsOK(status))
1080 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1084 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1088 * if python double -> cpp double sw=1
1089 * if python int -> cpp double sw=1
1090 * if python list[double] -> cpp vector<double> sw=2
1091 * if python list[int] -> cpp vector<double> sw=2
1092 * if python tuple[double] -> cpp vector<double> sw=2
1093 * if python tuple[int] -> cpp vector<double> sw=2
1094 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1096 * switch between (int,vector<int>,DataArrayInt)
1098 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1101 if(PyFloat_Check(value))
1103 iTyypp=PyFloat_AS_DOUBLE(value);
1107 if(PyInt_Check(value))
1109 iTyypp=(double)PyInt_AS_LONG(value);
1113 if(PyTuple_Check(value))
1115 int size=PyTuple_Size(value);
1116 stdvecTyypp.resize(size);
1117 for(int i=0;i<size;i++)
1119 PyObject *o=PyTuple_GetItem(value,i);
1120 if(PyFloat_Check(o))
1121 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1122 else if(PyInt_Check(o))
1123 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1126 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1127 throw INTERP_KERNEL::Exception(oss.str().c_str());
1133 if(PyList_Check(value))
1135 int size=PyList_Size(value);
1136 stdvecTyypp.resize(size);
1137 for(int i=0;i<size;i++)
1139 PyObject *o=PyList_GetItem(value,i);
1140 if(PyFloat_Check(o))
1141 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1142 else if(PyInt_Check(o))
1143 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1146 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1147 throw INTERP_KERNEL::Exception(oss.str().c_str());
1154 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1155 if(!SWIG_IsOK(status))
1156 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1157 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1162 * if python double -> cpp double sw=1
1163 * if python int -> cpp double sw=1
1164 * if python list[double] -> cpp vector<double> sw=2
1165 * if python list[int] -> cpp vector<double> sw=2
1166 * if python tuple[double] -> cpp vector<double> sw=2
1167 * if python tuple[int] -> cpp vector<double> sw=2
1168 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1170 * switch between (int,vector<int>,DataArrayInt)
1172 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1175 if(PyFloat_Check(value))
1177 iTyypp=PyFloat_AS_DOUBLE(value);
1181 if(PyInt_Check(value))
1183 iTyypp=(double)PyInt_AS_LONG(value);
1187 if(PyTuple_Check(value))
1189 int size=PyTuple_Size(value);
1190 stdvecTyypp.resize(size);
1191 for(int i=0;i<size;i++)
1193 PyObject *o=PyTuple_GetItem(value,i);
1194 if(PyFloat_Check(o))
1195 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1196 else if(PyInt_Check(o))
1197 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1200 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1201 throw INTERP_KERNEL::Exception(oss.str().c_str());
1207 if(PyList_Check(value))
1209 int size=PyList_Size(value);
1210 stdvecTyypp.resize(size);
1211 for(int i=0;i<size;i++)
1213 PyObject *o=PyList_GetItem(value,i);
1214 if(PyFloat_Check(o))
1215 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1216 else if(PyInt_Check(o))
1217 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1220 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1221 throw INTERP_KERNEL::Exception(oss.str().c_str());
1228 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1229 if(!SWIG_IsOK(status))
1230 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1231 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1236 * if python int -> cpp int sw=1
1237 * if python list[int] -> cpp vector<int> sw=2
1238 * if python tuple[int] -> cpp vector<int> sw=2
1239 * if python slicp -> cpp pair sw=3 (begin,end,step)
1240 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1242 * switch between (int,vector<int>,DataArrayInt)
1244 static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, ParaMEDMEM::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1246 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1248 if(PyInt_Check(value))
1250 iTyypp=(int)PyInt_AS_LONG(value);
1254 if(PyTuple_Check(value))
1256 int size=PyTuple_Size(value);
1257 stdvecTyypp.resize(size);
1258 for(int i=0;i<size;i++)
1260 PyObject *o=PyTuple_GetItem(value,i);
1262 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1265 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1266 throw INTERP_KERNEL::Exception(oss.str().c_str());
1272 if(PyList_Check(value))
1274 int size=PyList_Size(value);
1275 stdvecTyypp.resize(size);
1276 for(int i=0;i<size;i++)
1278 PyObject *o=PyList_GetItem(value,i);
1280 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1283 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1284 throw INTERP_KERNEL::Exception(oss.str().c_str());
1290 if(PySlice_Check(value))
1292 Py_ssize_t strt=2,stp=2,step=2;
1293 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1294 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1295 if(nbelem!=0 || strt!=0 || stp!=0)
1297 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1298 throw INTERP_KERNEL::Exception(oss.str().c_str());
1302 p.second.second=step;
1307 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1308 if(SWIG_IsOK(status))
1310 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1313 std::ostringstream oss; oss << msg << " Instance in null !";
1314 throw INTERP_KERNEL::Exception(oss.str().c_str());
1319 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1320 if(SWIG_IsOK(status))
1322 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1325 std::ostringstream oss; oss << msg << " Instance in null !";
1326 throw INTERP_KERNEL::Exception(oss.str().c_str());
1328 stdvecTyypp.resize(tmp->getNumberOfCompo());
1329 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1333 throw INTERP_KERNEL::Exception(msg);
1337 * if python int -> cpp int sw=1
1338 * if python tuple[int] -> cpp vector<int> sw=2
1339 * if python list[int] -> cpp vector<int> sw=2
1340 * if python slice -> cpp pair sw=3
1341 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1343 static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, ParaMEDMEM::DataArrayIntTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1346 if(PyInt_Check(value))
1348 iTyypp=(int)PyInt_AS_LONG(value);
1352 if(PyTuple_Check(value))
1354 int size=PyTuple_Size(value);
1355 stdvecTyypp.resize(size);
1356 for(int i=0;i<size;i++)
1358 PyObject *o=PyTuple_GetItem(value,i);
1360 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1363 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1364 throw INTERP_KERNEL::Exception(oss.str().c_str());
1370 if(PyList_Check(value))
1372 int size=PyList_Size(value);
1373 stdvecTyypp.resize(size);
1374 for(int i=0;i<size;i++)
1376 PyObject *o=PyList_GetItem(value,i);
1378 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1381 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1382 throw INTERP_KERNEL::Exception(oss.str().c_str());
1388 if(PySlice_Check(value))
1390 Py_ssize_t strt=2,stp=2,step=2;
1391 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1392 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1393 if(nbelem!=0 || strt!=0 || stp!=0)
1395 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1396 throw INTERP_KERNEL::Exception(oss.str().c_str());
1400 p.second.second=step;
1405 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1406 if(!SWIG_IsOK(status))
1407 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1408 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1413 * if python string with size one -> cpp char sw=1
1414 * if python string with size different from one -> cpp string sw=2
1415 * if python tuple[string] or list[string] -> vector<string> sw=3
1416 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1417 * switch between (int,string,vector<string>,DataArrayChar)
1419 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1421 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1423 if(PyString_Check(value))
1425 const char *pt=PyString_AsString(value);
1426 Py_ssize_t sz=PyString_Size(value);
1440 if(PyTuple_Check(value))
1442 int size=PyTuple_Size(value);
1443 vsType.resize(size);
1444 for(int i=0;i<size;i++)
1446 PyObject *o=PyTuple_GetItem(value,i);
1447 if(PyString_Check(o))
1448 vsType[i]=PyString_AsString(o);
1451 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1452 throw INTERP_KERNEL::Exception(oss.str().c_str());
1458 if(PyList_Check(value))
1460 int size=PyList_Size(value);
1461 vsType.resize(size);
1462 for(int i=0;i<size;i++)
1464 PyObject *o=PyList_GetItem(value,i);
1465 if(PyString_Check(o))
1466 vsType[i]=PyString_AsString(o);
1469 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1470 throw INTERP_KERNEL::Exception(oss.str().c_str());
1477 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1478 if(SWIG_IsOK(status))
1480 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1483 std::ostringstream oss; oss << msg << " Instance in null !";
1484 throw INTERP_KERNEL::Exception(oss.str().c_str());
1489 throw INTERP_KERNEL::Exception(msg);
1493 * if value int -> cpp it sw=1
1494 * if value list[int] -> vt sw=2
1495 * if value tuple[int] -> vt sw=2
1496 * if value slice -> pt sw=3
1497 * if value DataArrayInt -> dt sw=4
1498 * if value tuple [int,int] -> cpp it,ip sw=5
1499 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1500 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1501 * if value tuple [slice,int] -> cpp pt,ip sw=7
1502 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1503 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1504 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1505 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1506 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1507 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1508 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1509 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1510 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1511 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1512 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1513 * if value tuple [int,slice] -> cpp it,pc sw=13
1514 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1515 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1516 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1517 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1519 * switch between (int,vector<int>,DataArrayInt)
1521 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1522 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1523 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1525 if(!PyTuple_Check(value))
1527 convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1532 int sz=PyTuple_Size(value);
1534 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1535 PyObject *ob0=PyTuple_GetItem(value,0);
1537 convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1538 PyObject *ob1=PyTuple_GetItem(value,1);
1539 convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1545 * if value int -> cpp val sw=1
1546 * if value double -> cpp val sw=1
1547 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1548 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1549 * if value list[int,double] -> cpp std::vector<double> sw=4
1550 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1552 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1555 if(PyFloat_Check(value))
1557 val=PyFloat_AS_DOUBLE(value);
1561 if(PyInt_Check(value))
1563 val=(double)PyInt_AS_LONG(value);
1567 if(PyTuple_Check(value))
1569 int size=PyTuple_Size(value);
1571 for(int i=0;i<size;i++)
1573 PyObject *o=PyTuple_GetItem(value,i);
1574 if(PyFloat_Check(o))
1575 f[i]=PyFloat_AS_DOUBLE(o);
1576 else if(PyInt_Check(o))
1577 f[i]=(double)PyInt_AS_LONG(o);
1580 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1581 throw INTERP_KERNEL::Exception(oss.str().c_str());
1587 if(PyList_Check(value))
1589 int size=PyList_Size(value);
1591 for(int i=0;i<size;i++)
1593 PyObject *o=PyList_GetItem(value,i);
1594 if(PyFloat_Check(o))
1595 f[i]=PyFloat_AS_DOUBLE(o);
1596 else if(PyInt_Check(o))
1597 f[i]=(double)PyInt_AS_LONG(o);
1600 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1601 throw INTERP_KERNEL::Exception(oss.str().c_str());
1608 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1609 if(SWIG_IsOK(status))
1611 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1615 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1616 if(SWIG_IsOK(status))
1618 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1622 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1626 * if value int -> cpp val sw=1
1627 * if value double -> cpp val sw=1
1628 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1629 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1630 * if value list[int,double] -> cpp std::vector<double> sw=4
1631 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1633 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1634 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1637 if(PyFloat_Check(value))
1639 val=PyFloat_AS_DOUBLE(value);
1641 if(nbTuplesExpected*nbCompExpected!=1)
1643 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1644 throw INTERP_KERNEL::Exception(oss.str().c_str());
1648 if(PyInt_Check(value))
1650 val=(double)PyInt_AS_LONG(value);
1652 if(nbTuplesExpected*nbCompExpected!=1)
1654 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1655 throw INTERP_KERNEL::Exception(oss.str().c_str());
1659 if(PyTuple_Check(value) || PyList_Check(value))
1663 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1664 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1669 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1672 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1673 if(SWIG_IsOK(status))
1675 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1679 if(d->getNumberOfTuples()==nbTuplesExpected)
1681 if(d->getNumberOfComponents()==nbCompExpected)
1683 return d->getConstPointer();
1687 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1688 throw INTERP_KERNEL::Exception(oss.str().c_str());
1693 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1694 throw INTERP_KERNEL::Exception(oss.str().c_str());
1701 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1702 throw INTERP_KERNEL::Exception(oss.str().c_str());
1708 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1709 if(SWIG_IsOK(status))
1711 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1713 if(e->getNumberOfCompo()==nbCompExpected)
1715 if(nbTuplesExpected==1)
1716 return e->getConstPointer();
1719 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1720 throw INTERP_KERNEL::Exception(oss.str().c_str());
1725 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1726 throw INTERP_KERNEL::Exception(oss.str().c_str());
1729 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1733 * if value int -> cpp val sw=1
1734 * if value double -> cpp val sw=1
1735 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1736 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1737 * if value list[int,double] -> cpp std::vector<double> sw=4
1738 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1740 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1741 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1744 if(PyFloat_Check(value))
1746 val=PyFloat_AS_DOUBLE(value);
1748 if(nbCompExpected!=1)
1750 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1751 throw INTERP_KERNEL::Exception(oss.str().c_str());
1756 if(PyInt_Check(value))
1758 val=(double)PyInt_AS_LONG(value);
1760 if(nbCompExpected!=1)
1762 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1763 throw INTERP_KERNEL::Exception(oss.str().c_str());
1768 if(PyTuple_Check(value))
1770 int size=PyTuple_Size(value);
1772 for(int i=0;i<size;i++)
1774 PyObject *o=PyTuple_GetItem(value,i);
1775 if(PyFloat_Check(o))
1776 f[i]=PyFloat_AS_DOUBLE(o);
1777 else if(PyInt_Check(o))
1778 f[i]=(double)PyInt_AS_LONG(o);
1781 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1782 throw INTERP_KERNEL::Exception(oss.str().c_str());
1786 if(size%nbCompExpected!=0)
1788 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1789 throw INTERP_KERNEL::Exception(oss.str().c_str());
1791 nbTuples=size/nbCompExpected;
1794 if(PyList_Check(value))
1796 int size=PyList_Size(value);
1798 for(int i=0;i<size;i++)
1800 PyObject *o=PyList_GetItem(value,i);
1801 if(PyFloat_Check(o))
1802 f[i]=PyFloat_AS_DOUBLE(o);
1803 else if(PyInt_Check(o))
1804 f[i]=(double)PyInt_AS_LONG(o);
1807 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1808 throw INTERP_KERNEL::Exception(oss.str().c_str());
1812 if(size%nbCompExpected!=0)
1814 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1815 throw INTERP_KERNEL::Exception(oss.str().c_str());
1817 nbTuples=size/nbCompExpected;
1821 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1822 if(SWIG_IsOK(status))
1824 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1828 if(d->getNumberOfComponents()==nbCompExpected)
1830 nbTuples=d->getNumberOfTuples();
1831 return d->getConstPointer();
1835 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1836 throw INTERP_KERNEL::Exception(oss.str().c_str());
1843 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1844 throw INTERP_KERNEL::Exception(oss.str().c_str());
1847 { nbTuples=0; return 0; }
1850 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1851 if(SWIG_IsOK(status))
1853 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1857 if(e->getNumberOfCompo()==nbCompExpected)
1860 return e->getConstPointer();
1864 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1865 throw INTERP_KERNEL::Exception(oss.str().c_str());
1872 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1873 throw INTERP_KERNEL::Exception(oss.str().c_str());
1876 { nbTuples=0; return 0; }
1879 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1883 * if value int -> cpp val sw=1
1884 * if value double -> cpp val sw=1
1885 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1886 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1887 * if value list[int,double] -> cpp std::vector<double> sw=4
1888 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1890 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
1891 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1893 ParaMEDMEM::DataArrayDouble *d=0;
1894 ParaMEDMEM::DataArrayDoubleTuple *e=0;
1896 if(PyFloat_Check(value))
1898 val=PyFloat_AS_DOUBLE(value);
1903 if(PyInt_Check(value))
1905 val=(double)PyInt_AS_LONG(value);
1910 if(PyTuple_Check(value))
1912 int size=PyTuple_Size(value);
1914 for(int i=0;i<size;i++)
1916 PyObject *o=PyTuple_GetItem(value,i);
1917 if(PyFloat_Check(o))
1918 f[i]=PyFloat_AS_DOUBLE(o);
1919 else if(PyInt_Check(o))
1920 f[i]=(double)PyInt_AS_LONG(o);
1923 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1924 throw INTERP_KERNEL::Exception(oss.str().c_str());
1931 if(PyList_Check(value))
1933 int size=PyList_Size(value);
1935 for(int i=0;i<size;i++)
1937 PyObject *o=PyList_GetItem(value,i);
1938 if(PyFloat_Check(o))
1939 f[i]=PyFloat_AS_DOUBLE(o);
1940 else if(PyInt_Check(o))
1941 f[i]=(double)PyInt_AS_LONG(o);
1944 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1945 throw INTERP_KERNEL::Exception(oss.str().c_str());
1953 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1954 if(SWIG_IsOK(status))
1956 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1960 if(d->getNumberOfComponents()==1)
1962 nbTuples=d->getNumberOfTuples();
1963 return d->getConstPointer();
1967 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
1968 throw INTERP_KERNEL::Exception(oss.str().c_str());
1975 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1976 throw INTERP_KERNEL::Exception(oss.str().c_str());
1979 { nbTuples=0; return 0; }
1982 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1983 if(SWIG_IsOK(status))
1985 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1989 nbTuples=e->getNumberOfCompo();
1990 return e->getConstPointer();
1996 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1997 throw INTERP_KERNEL::Exception(oss.str().c_str());
2000 { nbTuples=0; return 0; }
2003 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2007 * if python int -> cpp int sw=1
2008 * if python list[int] -> cpp vector<int> sw=2
2009 * if python tuple[int] -> cpp vector<int> sw=2
2010 * if python DataArrayInt -> cpp DataArrayInt sw=3
2011 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2013 * switch between (int,vector<int>,DataArrayInt)
2015 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2018 if(PyInt_Check(value))
2020 iTyypp=(int)PyInt_AS_LONG(value);
2024 if(PyTuple_Check(value))
2026 int size=PyTuple_Size(value);
2027 stdvecTyypp.resize(size);
2028 for(int i=0;i<size;i++)
2030 PyObject *o=PyTuple_GetItem(value,i);
2032 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2035 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2036 throw INTERP_KERNEL::Exception(oss.str().c_str());
2040 return &stdvecTyypp[0];
2042 if(PyList_Check(value))
2044 int size=PyList_Size(value);
2045 stdvecTyypp.resize(size);
2046 for(int i=0;i<size;i++)
2048 PyObject *o=PyList_GetItem(value,i);
2050 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2053 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2054 throw INTERP_KERNEL::Exception(oss.str().c_str());
2058 return &stdvecTyypp[0];
2061 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2062 if(SWIG_IsOK(status))
2064 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2067 sw=3; sz=daIntTyypp->getNbOfElems();
2068 return daIntTyypp->begin();
2076 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2077 if(SWIG_IsOK(status))
2079 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2080 sw=4; sz=daIntTuple->getNumberOfCompo();
2081 return daIntTuple->getConstPointer();
2083 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2086 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2088 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.";
2089 const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !";
2092 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2094 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2096 return (*self)+(*other);
2098 throw INTERP_KERNEL::Exception(msg);
2102 ParaMEDMEM::DataArrayDouble *a;
2103 ParaMEDMEM::DataArrayDoubleTuple *aa;
2104 std::vector<double> bb;
2106 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2111 if(!self->getArray())
2112 throw INTERP_KERNEL::Exception(msg2);
2113 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2114 ret->applyLin(1.,val);
2115 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2116 ret2->setArray(ret);
2121 if(!self->getArray())
2122 throw INTERP_KERNEL::Exception(msg2);
2123 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),a);
2124 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2125 ret2->setArray(ret);
2130 if(!self->getArray())
2131 throw INTERP_KERNEL::Exception(msg2);
2132 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2133 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2134 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2135 ret2->setArray(ret);
2140 if(!self->getArray())
2141 throw INTERP_KERNEL::Exception(msg2);
2142 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2143 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2144 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2145 ret2->setArray(ret);
2149 { throw INTERP_KERNEL::Exception(msg); }
2153 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2155 return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj);
2158 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2160 const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__rsub__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
2161 const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !";
2164 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2166 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2168 return (*other)-(*self);
2170 throw INTERP_KERNEL::Exception(msg);
2174 ParaMEDMEM::DataArrayDouble *a;
2175 ParaMEDMEM::DataArrayDoubleTuple *aa;
2176 std::vector<double> bb;
2178 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2183 if(!self->getArray())
2184 throw INTERP_KERNEL::Exception(msg2);
2185 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2186 ret->applyLin(-1.,val);
2187 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2188 ret2->setArray(ret);
2193 if(!self->getArray())
2194 throw INTERP_KERNEL::Exception(msg2);
2195 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(a,self->getArray());
2196 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2197 ret2->setArray(ret);
2202 if(!self->getArray())
2203 throw INTERP_KERNEL::Exception(msg2);
2204 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2205 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2206 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2207 ret2->setArray(ret);
2212 if(!self->getArray())
2213 throw INTERP_KERNEL::Exception(msg2);
2214 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2215 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2216 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2217 ret2->setArray(ret);
2221 { throw INTERP_KERNEL::Exception(msg); }
2225 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2227 const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__mul__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
2228 const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !";
2231 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2233 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2235 return (*self)*(*other);
2237 throw INTERP_KERNEL::Exception(msg);
2241 ParaMEDMEM::DataArrayDouble *a;
2242 ParaMEDMEM::DataArrayDoubleTuple *aa;
2243 std::vector<double> bb;
2245 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2250 if(!self->getArray())
2251 throw INTERP_KERNEL::Exception(msg2);
2252 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2253 ret->applyLin(val,0.);
2254 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2255 ret2->setArray(ret);
2260 if(!self->getArray())
2261 throw INTERP_KERNEL::Exception(msg2);
2262 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),a);
2263 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2264 ret2->setArray(ret);
2269 if(!self->getArray())
2270 throw INTERP_KERNEL::Exception(msg2);
2271 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2272 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2273 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2274 ret2->setArray(ret);
2279 if(!self->getArray())
2280 throw INTERP_KERNEL::Exception(msg2);
2281 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2282 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2283 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2284 ret2->setArray(ret);
2288 { throw INTERP_KERNEL::Exception(msg); }
2292 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2294 return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj);
2297 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2299 const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__rdiv__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
2300 const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !";
2303 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2305 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2307 return (*other)/(*self);
2309 throw INTERP_KERNEL::Exception(msg);
2313 ParaMEDMEM::DataArrayDouble *a;
2314 ParaMEDMEM::DataArrayDoubleTuple *aa;
2315 std::vector<double> bb;
2317 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2322 if(!self->getArray())
2323 throw INTERP_KERNEL::Exception(msg2);
2324 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2326 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2327 ret2->setArray(ret);
2332 if(!self->getArray())
2333 throw INTERP_KERNEL::Exception(msg2);
2334 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(a,self->getArray());
2335 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2336 ret2->setArray(ret);
2341 if(!self->getArray())
2342 throw INTERP_KERNEL::Exception(msg2);
2343 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2344 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2345 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2346 ret2->setArray(ret);
2351 if(!self->getArray())
2352 throw INTERP_KERNEL::Exception(msg2);
2353 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2354 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2355 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2356 ret2->setArray(ret);
2360 { throw INTERP_KERNEL::Exception(msg); }