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