Salome HOME
Temporarily deactivating failing tests on mapping for intersection
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingTypemaps.i
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
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, or (at your option) any later version.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #ifndef __MEDCOUPLINGTYPEMAPS_I__
22 #define __MEDCOUPLINGTYPEMAPS_I__
23
24 #include "MEDCouplingDataArrayTypemaps.i"
25 #include "MEDCouplingUMesh.hxx"
26 #include "MEDCouplingCMesh.hxx"
27 #include "MEDCouplingIMesh.hxx"
28 #include "MEDCouplingCurveLinearMesh.hxx"
29 #include "MEDCouplingMappedExtrudedMesh.hxx"
30 #include "MEDCoupling1GTUMesh.hxx"
31 #include "MEDCouplingFieldDiscretization.hxx"
32 #include "MEDCouplingMultiFields.hxx"
33 #include "MEDCouplingPartDefinition.hxx"
34 #include "MEDCouplingCartesianAMRMesh.hxx"
35
36 static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner)
37 {
38   PyObject *ret=0;
39   if(!mesh)
40     {
41       Py_XINCREF(Py_None);
42       return Py_None;
43     }
44   if(dynamic_cast<MEDCoupling::MEDCouplingUMesh *>(mesh))
45     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,owner);
46   if(dynamic_cast<MEDCoupling::MEDCoupling1SGTUMesh *>(mesh))
47     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCoupling1SGTUMesh,owner);
48   if(dynamic_cast<MEDCoupling::MEDCoupling1DGTUMesh *>(mesh))
49     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCoupling1DGTUMesh,owner);
50   if(dynamic_cast<MEDCoupling::MEDCouplingMappedExtrudedMesh *>(mesh))
51     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingMappedExtrudedMesh,owner);
52   if(dynamic_cast<MEDCoupling::MEDCouplingCMesh *>(mesh))
53     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingCMesh,owner);
54   if(dynamic_cast<MEDCoupling::MEDCouplingCurveLinearMesh *>(mesh))
55     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingCurveLinearMesh,owner);
56   if(dynamic_cast<MEDCoupling::MEDCouplingIMesh *>(mesh))
57     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingIMesh,owner);
58   if(!ret)
59     throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
60   return ret;
61 }
62
63 static PyObject *convertFieldDiscretization(MEDCoupling::MEDCouplingFieldDiscretization *fd, int owner)
64 {
65   PyObject *ret=0;
66   if(!fd)
67     {
68       Py_XINCREF(Py_None);
69       return Py_None;
70     }
71   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationP0 *>(fd))
72     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationP0,owner);
73   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationP1 *>(fd))
74     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationP1,owner);
75   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationGauss *>(fd))
76     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationGauss,owner);
77   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationGaussNE *>(fd))
78     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationGaussNE,owner);
79   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationKriging *>(fd))
80     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationKriging,owner);
81   if(!ret)
82     throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
83   return ret;
84 }
85
86 static PyObject* convertMultiFields(MEDCoupling::MEDCouplingMultiFields *mfs, int owner)
87 {
88   PyObject *ret=0;
89   if(!mfs)
90     {
91       Py_XINCREF(Py_None);
92       return Py_None;
93     }
94   if(dynamic_cast<MEDCoupling::MEDCouplingFieldOverTime *>(mfs))
95     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldOverTime,owner);
96   else
97     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_MEDCoupling__MEDCouplingMultiFields,owner);
98   return ret;
99 }
100
101 static PyObject *convertCartesianAMRMesh(MEDCoupling::MEDCouplingCartesianAMRMeshGen *mesh, int owner)
102 {
103   if(!mesh)
104     {
105       Py_XINCREF(Py_None);
106       return Py_None;
107     }
108   if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRMeshSub *>(mesh))
109     {
110       return SWIG_NewPointerObj(reinterpret_cast<void*>(mesh),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRMeshSub,owner);
111     }
112   if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRMesh *>(mesh))
113     {
114       return SWIG_NewPointerObj(reinterpret_cast<void*>(mesh),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRMesh,owner);
115     }
116   throw INTERP_KERNEL::Exception("convertCartesianAMRMesh wrap : unrecognized type of cartesian AMR mesh !");
117 }
118
119 static PyObject *convertDataForGodFather(MEDCoupling::MEDCouplingDataForGodFather *data, int owner)
120 {
121   if(!data)
122     {
123       Py_XINCREF(Py_None);
124       return Py_None;
125     }
126   if(dynamic_cast<MEDCoupling::MEDCouplingAMRAttribute *>(data))
127     {
128       return SWIG_NewPointerObj(reinterpret_cast<void*>(data),SWIGTYPE_p_MEDCoupling__MEDCouplingAMRAttribute,owner);
129     }
130   throw INTERP_KERNEL::Exception("convertDataForGodFather wrap : unrecognized data type for AMR !");
131 }
132
133 static PyObject *convertCartesianAMRPatch(MEDCoupling::MEDCouplingCartesianAMRPatchGen *patch, int owner) throw(INTERP_KERNEL::Exception)
134 {
135   if(!patch)
136     {
137       Py_XINCREF(Py_None);
138       return Py_None;
139     }
140   if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRPatchGF *>(patch))
141     {
142       return SWIG_NewPointerObj(reinterpret_cast<void*>(patch),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRPatchGF,owner);
143     }
144   if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRPatch *>(patch))
145     {
146       return SWIG_NewPointerObj(reinterpret_cast<void*>(patch),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRPatch,owner);
147     }
148   throw INTERP_KERNEL::Exception("convertCartesianAMRPatch wrap : unrecognized type of cartesian AMR patch !");
149 }
150
151 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___add__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
152 {
153   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.";
154   const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !";
155   void *argp;
156   //
157   if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
158     {
159       MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
160       if(other)
161         return (*self)+(*other);
162       else
163         throw INTERP_KERNEL::Exception(msg);
164     }
165   //
166   double val;
167   MEDCoupling::DataArrayDouble *a;
168   MEDCoupling::DataArrayDoubleTuple *aa;
169   std::vector<double> bb;
170   int sw;
171   convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
172   switch(sw)
173     {
174     case 1:
175       {
176         if(!self->getArray())
177           throw INTERP_KERNEL::Exception(msg2);
178         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
179         ret->applyLin(1.,val);
180         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
181         ret2->setArray(ret);
182         return ret2.retn();
183       }
184     case 2:
185       {
186         if(!self->getArray())
187           throw INTERP_KERNEL::Exception(msg2);
188         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),a);
189         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
190         ret2->setArray(ret);
191         return ret2.retn();
192       }
193     case 3:
194       {
195         if(!self->getArray())
196           throw INTERP_KERNEL::Exception(msg2);
197         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
198         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),aaa);
199         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
200         ret2->setArray(ret);
201         return ret2.retn();
202       }
203     case 4:
204       {
205         if(!self->getArray())
206           throw INTERP_KERNEL::Exception(msg2);
207         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
208         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),aaa);
209         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
210         ret2->setArray(ret);
211         return ret2.retn();
212       }
213     default:
214       { throw INTERP_KERNEL::Exception(msg); }
215     }
216 }
217
218 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___radd__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
219 {
220   return MEDCoupling_MEDCouplingFieldDouble___add__Impl(self,obj);
221 }
222
223 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rsub__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
224 {
225   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.";
226   const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !";
227   void *argp;
228   //
229   if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
230     {
231       MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
232       if(other)
233         return (*other)-(*self);
234       else
235         throw INTERP_KERNEL::Exception(msg);
236     }
237   //
238   double val;
239   MEDCoupling::DataArrayDouble *a;
240   MEDCoupling::DataArrayDoubleTuple *aa;
241   std::vector<double> bb;
242   int sw;
243   convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
244   switch(sw)
245     {
246     case 1:
247       {
248         if(!self->getArray())
249           throw INTERP_KERNEL::Exception(msg2);
250         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
251         ret->applyLin(-1.,val);
252         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
253         ret2->setArray(ret);
254         return ret2.retn();
255       }
256     case 2:
257       {
258         if(!self->getArray())
259           throw INTERP_KERNEL::Exception(msg2);
260         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Substract(a,self->getArray());
261         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
262         ret2->setArray(ret);
263         return ret2.retn();
264       }
265     case 3:
266       {
267         if(!self->getArray())
268           throw INTERP_KERNEL::Exception(msg2);
269         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
270         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Substract(aaa,self->getArray());
271         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
272         ret2->setArray(ret);
273         return ret2.retn();
274       }
275     case 4:
276       {
277         if(!self->getArray())
278           throw INTERP_KERNEL::Exception(msg2);
279         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
280         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Substract(aaa,self->getArray());
281         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
282         ret2->setArray(ret);
283         return ret2.retn();
284       }
285     default:
286       { throw INTERP_KERNEL::Exception(msg); }
287     }
288 }
289
290 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___mul__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
291 {
292   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.";
293   const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !";
294   void *argp;
295   //
296   if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
297     {
298       MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
299       if(other)
300         return (*self)*(*other);
301       else
302         throw INTERP_KERNEL::Exception(msg);
303     }
304   //
305   double val;
306   MEDCoupling::DataArrayDouble *a;
307   MEDCoupling::DataArrayDoubleTuple *aa;
308   std::vector<double> bb;
309   int sw;
310   convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
311   switch(sw)
312     {
313     case 1:
314       {
315         if(!self->getArray())
316           throw INTERP_KERNEL::Exception(msg2);
317         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
318         ret->applyLin(val,0.);
319         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
320         ret2->setArray(ret);
321         return ret2.retn();
322       }
323     case 2:
324       {
325         if(!self->getArray())
326           throw INTERP_KERNEL::Exception(msg2);
327         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),a);
328         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
329         ret2->setArray(ret);
330         return ret2.retn();
331       }
332     case 3:
333       {
334         if(!self->getArray())
335           throw INTERP_KERNEL::Exception(msg2);
336         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
337         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),aaa);
338         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
339         ret2->setArray(ret);
340         return ret2.retn();
341       }
342     case 4:
343       {
344         if(!self->getArray())
345           throw INTERP_KERNEL::Exception(msg2);
346         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
347         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),aaa);
348         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
349         ret2->setArray(ret);
350         return ret2.retn();
351       }
352     default:
353       { throw INTERP_KERNEL::Exception(msg); }
354     }
355 }
356
357 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rmul__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
358 {
359   return MEDCoupling_MEDCouplingFieldDouble___mul__Impl(self,obj);
360 }
361
362 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rdiv__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
363 {
364   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.";
365   const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !";
366   void *argp;
367   //
368   if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
369     {
370       MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
371       if(other)
372         return (*other)/(*self);
373       else
374         throw INTERP_KERNEL::Exception(msg);
375     }
376   //
377   double val;
378   MEDCoupling::DataArrayDouble *a;
379   MEDCoupling::DataArrayDoubleTuple *aa;
380   std::vector<double> bb;
381   int sw;
382   convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
383   switch(sw)
384     {
385     case 1:
386       {
387         if(!self->getArray())
388           throw INTERP_KERNEL::Exception(msg2);
389         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
390         ret->applyInv(val);
391         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
392         ret2->setArray(ret);
393         return ret2.retn();
394       }
395     case 2:
396       {
397         if(!self->getArray())
398           throw INTERP_KERNEL::Exception(msg2);
399         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(a,self->getArray());
400         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
401         ret2->setArray(ret);
402         return ret2.retn();
403       }
404     case 3:
405       {
406         if(!self->getArray())
407           throw INTERP_KERNEL::Exception(msg2);
408         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
409         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(aaa,self->getArray());
410         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
411         ret2->setArray(ret);
412         return ret2.retn();
413       }
414     case 4:
415       {
416         if(!self->getArray())
417           throw INTERP_KERNEL::Exception(msg2);
418         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
419         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(aaa,self->getArray());
420         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
421         ret2->setArray(ret);
422         return ret2.retn();
423       }
424     default:
425       { throw INTERP_KERNEL::Exception(msg); }
426     }
427 }
428
429 template<class T>
430 typename MEDCoupling::Traits<T>::FieldType *fieldT_buildSubPart(const MEDCoupling::MEDCouplingFieldT<T> *self, PyObject *li)
431 {
432   int sw;
433   int singleVal;
434   std::vector<int> multiVal;
435   std::pair<int, std::pair<int,int> > slic;
436   MEDCoupling::DataArrayInt *daIntTyypp=0;
437   const MEDCoupling::MEDCouplingMesh *mesh=self->getMesh();
438   if(!mesh)
439     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : field lies on a null mesh !");
440   int nbc=mesh->getNumberOfCells();
441   convertIntStarOrSliceLikePyObjToCpp(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
442   switch(sw)
443     {
444     case 1:
445       {
446         if(singleVal>=nbc)
447           {
448             std::ostringstream oss;
449             oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !";
450             throw INTERP_KERNEL::Exception(oss.str().c_str());
451           }
452         if(singleVal>=0)
453           return self->buildSubPart(&singleVal,&singleVal+1);
454         else
455           {
456             if(nbc+singleVal>0)
457               {
458                 int tmp=nbc+singleVal;
459                 return self->buildSubPart(&tmp,&tmp+1);
460               }
461             else
462               {
463                 std::ostringstream oss;
464                 oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !";
465                 throw INTERP_KERNEL::Exception(oss.str().c_str());
466               }
467           }
468       }
469     case 2:
470       {
471         return self->buildSubPart(&multiVal[0],&multiVal[0]+multiVal.size());
472       }
473     case 3:
474       {
475         return self->buildSubPartRange(slic.first,slic.second.first,slic.second.second);
476       }
477     case 4:
478       {
479         if(!daIntTyypp)
480           throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : null instance has been given in input !");
481         daIntTyypp->checkAllocated();
482         return self->buildSubPart(daIntTyypp->begin(),daIntTyypp->end());
483       }
484     default:
485       throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayInt instance !");
486     }
487 }
488
489 template<class T>
490 typename MEDCoupling::Traits<T>::FieldType *fieldT__getitem__(const MEDCoupling::MEDCouplingFieldT<T> *self, PyObject *li)
491 {
492   const char msg[]="MEDCouplingFieldDouble::__getitem__ : invalid call  Available API are : \n-myField[dataArrayInt]\n-myField[slice]\n-myField[pythonListOfCellIds]\n-myField[integer]\n-myField[dataArrayInt,1]\n-myField[slice,1]\n-myField[pythonListOfCellIds,1]\n-myField[integer,1]\n";
493   if(PyTuple_Check(li))
494     {
495       Py_ssize_t sz=PyTuple_Size(li);
496       if(sz!=2)
497         throw INTERP_KERNEL::Exception(msg);
498       PyObject *elt0=PyTuple_GetItem(li,0),*elt1=PyTuple_GetItem(li,1);
499       int sw;
500       int singleVal;
501       std::vector<int> multiVal;
502       std::pair<int, std::pair<int,int> > slic;
503       MEDCoupling::DataArrayInt *daIntTyypp=0;
504       if(!self->getArray())
505         throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array set on field to deduce number of components !");
506       try
507         { convertIntStarOrSliceLikePyObjToCpp(elt1,self->getArray()->getNumberOfComponents(),sw,singleVal,multiVal,slic,daIntTyypp); }
508       catch(INTERP_KERNEL::Exception& e)
509         { std::ostringstream oss; oss << "MEDCouplingFieldDouble::__getitem__ : invalid type in 2nd parameter (compo) !" << e.what(); throw INTERP_KERNEL::Exception(oss.str().c_str()); }
510       typename MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::FieldType > ret0(fieldT_buildSubPart<T>(self,elt0));
511       typename MEDCoupling::Traits<T>::ArrayType *ret0Arr=ret0->getArray();
512       if(!ret0Arr)
513         throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array exists to apply restriction on component on it !");
514       switch(sw)
515         {
516         case 1:
517           {
518             std::vector<int> v2(1,singleVal);
519             MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(v2));
520             ret0->setArray(aarr);
521             return ret0.retn();
522           }
523         case 2:
524           {
525             MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(multiVal));
526             ret0->setArray(aarr);
527             return ret0.retn();
528           }
529         case 3:
530           {
531             int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(slic.first,slic.second.first,slic.second.second,"MEDCouplingFieldDouble::__getitem__ : invalid range in 2nd parameter (components) !"));
532             std::vector<int> v2(nbOfComp);
533             for(int i=0;i<nbOfComp;i++)
534               v2[i]=slic.first+i*slic.second.second;
535             MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(v2));
536             ret0->setArray(aarr);
537             return ret0.retn();
538           }
539         default:
540           throw INTERP_KERNEL::Exception(msg);
541         }
542     }
543   else
544     return fieldT_buildSubPart<T>(self,li);
545 }
546
547 template<class FIELDT>
548 PyObject *field_getTinySerializationInformation(const FIELDT *self)
549 {
550   std::vector<double> a0;
551   std::vector<int> a1;
552   std::vector<std::string> a2;
553   self->getTinySerializationDbleInformation(a0);
554   self->getTinySerializationIntInformation(a1);
555   self->getTinySerializationStrInformation(a2);
556   //
557   PyObject *ret(PyTuple_New(3));
558   PyTuple_SetItem(ret,0,convertDblArrToPyList2(a0));
559   PyTuple_SetItem(ret,1,convertIntArrToPyList2(a1));
560   int sz(a2.size());
561   PyObject *ret2(PyList_New(sz));
562   {
563     for(int i=0;i<sz;i++)
564       PyList_SetItem(ret2,i,PyString_FromString(a2[i].c_str()));
565   }
566   PyTuple_SetItem(ret,2,ret2);
567   return ret;
568 }
569
570 template<class T>
571 PyObject *field_serialize(const typename MEDCoupling::Traits<T>::FieldType *self)
572 {
573   MEDCoupling::DataArrayInt *ret0(0);
574   std::vector<typename MEDCoupling::Traits<T>::ArrayType *> ret1;
575   self->serialize(ret0,ret1);
576   if(ret0)
577     ret0->incrRef();
578   std::size_t sz(ret1.size());
579   PyObject *ret(PyTuple_New(2));
580   PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
581   PyObject *ret1Py(PyList_New(sz));
582   for(std::size_t i=0;i<sz;i++)
583     {
584       if(ret1[i])
585         ret1[i]->incrRef();
586       PyList_SetItem(ret1Py,i,convertArray(ret1[i],SWIG_POINTER_OWN | 0));
587     }
588   PyTuple_SetItem(ret,1,ret1Py);
589   return ret;
590 }
591
592 template<class FIELDT>
593 PyObject *field__getnewargs__(FIELDT *self)
594 {
595   self->checkConsistencyLight();
596   PyObject *ret(PyTuple_New(1));
597   PyObject *ret0(PyDict_New());
598   {
599     PyObject *a(PyInt_FromLong(0)),*b(PyInt_FromLong(self->getTypeOfField())),*c(PyInt_FromLong(self->getTimeDiscretization()));
600     PyObject *d(PyTuple_New(2)); PyTuple_SetItem(d,0,b); PyTuple_SetItem(d,1,c);
601     PyDict_SetItem(ret0,a,d);
602     Py_DECREF(a); Py_DECREF(d);
603   }
604   PyTuple_SetItem(ret,0,ret0);
605   return ret;
606 }
607
608 template<class FIELDT>
609 PyObject *field__getstate__(const FIELDT *self, PyObject *(*tinyserial)(const FIELDT *), PyObject *(*bigserial)(const FIELDT *))
610 {
611   self->checkConsistencyLight();
612   PyObject *ret0(tinyserial(self));
613   PyObject *ret1(bigserial(self));
614   const MEDCoupling::MEDCouplingMesh *mesh(self->getMesh());
615   if(mesh)
616     mesh->incrRef();
617   PyObject *ret(PyTuple_New(3));
618   PyTuple_SetItem(ret,0,ret0);
619   PyTuple_SetItem(ret,1,ret1);
620   PyTuple_SetItem(ret,2,convertMesh(const_cast<MEDCoupling::MEDCouplingMesh *>(mesh),SWIG_POINTER_OWN | 0 ));
621   return ret;
622 }
623
624 template<class T>
625 void field__setstate__(typename MEDCoupling::Traits<T>::FieldType *self, PyObject *inp)
626 {
627   static const char MSG[]="MEDCouplingFieldDouble.__setstate__ : expected input is a tuple of size 3 !";
628   if(!PyTuple_Check(inp))
629     throw INTERP_KERNEL::Exception(MSG);
630   int sz(PyTuple_Size(inp));
631   if(sz!=3)
632     throw INTERP_KERNEL::Exception(MSG);
633   // mesh
634   PyObject *elt2(PyTuple_GetItem(inp,2));
635   void *argp=0;
636   int status(SWIG_ConvertPtr(elt2,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingMesh,0|0));
637   if(!SWIG_IsOK(status))
638     throw INTERP_KERNEL::Exception(MSG);
639   self->setMesh(reinterpret_cast< const MEDCoupling::MEDCouplingMesh * >(argp));
640   //
641   PyObject *elt0(PyTuple_GetItem(inp,0));
642   PyObject *elt1(PyTuple_GetItem(inp,1));
643   std::vector<double> a0;
644   std::vector<int> a1;
645   std::vector<std::string> a2;
646   MEDCoupling::DataArrayInt *b0(0);
647   std::vector<typename MEDCoupling::Traits<T>::ArrayType *>b1;
648   {
649     if(!PyTuple_Check(elt0) && PyTuple_Size(elt0)!=3)
650       throw INTERP_KERNEL::Exception(MSG);
651     PyObject *a0py(PyTuple_GetItem(elt0,0)),*a1py(PyTuple_GetItem(elt0,1)),*a2py(PyTuple_GetItem(elt0,2));
652     int tmp(-1);
653     fillArrayWithPyListDbl3(a0py,tmp,a0);
654     convertPyToNewIntArr3(a1py,a1);
655     fillStringVector(a2py,a2);
656   }
657   {
658     if(!PyTuple_Check(elt1) && PyTuple_Size(elt1)!=2)
659       throw INTERP_KERNEL::Exception(MSG);
660     PyObject *b0py(PyTuple_GetItem(elt1,0)),*b1py(PyTuple_GetItem(elt1,1));
661     void *argp(0);
662     int status(SWIG_ConvertPtr(b0py,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0));
663     if(!SWIG_IsOK(status))
664       throw INTERP_KERNEL::Exception(MSG);
665     b0=reinterpret_cast<MEDCoupling::DataArrayInt *>(argp);
666     convertFromPyObjVectorOfObj<typename MEDCoupling::Traits<T>::ArrayType *>(b1py,SWIGTITraits<T>::TI,MEDCoupling::Traits<T>::ArrayTypeName,b1);
667   }
668   self->checkForUnserialization(a1,b0,b1);
669   // useless here to call resizeForUnserialization because arrays are well resized.
670   self->finishUnserialization(a1,a0,a2);
671 }
672
673 #endif