Salome HOME
Fix computation height of isocel triangle with base equal zero : NaN
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingTypemaps.i
1 // Copyright (C) 2007-2023  CEA, EDF
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 (EDF R&D)
20
21 #pragma once
22
23 #include "MEDCouplingDataArrayTypemaps.i"
24 #include "MEDCouplingUMesh.hxx"
25 #include "MEDCouplingCMesh.hxx"
26 #include "MEDCouplingIMesh.hxx"
27 #include "MEDCouplingCurveLinearMesh.hxx"
28 #include "MEDCouplingMappedExtrudedMesh.hxx"
29 #include "MEDCoupling1GTUMesh.hxx"
30 #include "MEDCouplingFieldDiscretization.hxx"
31 #include "MEDCouplingFieldDiscretizationOnNodesFE.hxx"
32 #include "MEDCouplingMultiFields.hxx"
33 #include "MEDCouplingPartDefinition.hxx"
34 #include "MEDCouplingCartesianAMRMesh.hxx"
35
36 #include <memory>
37
38 auto PyDeleter = [](PyObject *ob) { Py_DECREF(ob) ; };
39
40 namespace {   // Only in this TU, so in an anonymous namespace
41   class AutoPyPtr : std::unique_ptr<PyObject,decltype(PyDeleter)>
42   {
43     public:
44       AutoPyPtr(PyObject *ob):std::unique_ptr<PyObject,decltype(PyDeleter)>(ob,PyDeleter) { }
45       PyObject *retn() { return this->release(); }
46       operator PyObject *() const { return this->get(); }
47   };
48 }
49
50 AutoPyPtr convertMapStringInt(const std::map<std::string,mcIdType>& cpp)
51 {
52   AutoPyPtr ret(PyDict_New());
53   for(auto it : cpp)
54   {
55     AutoPyPtr st(PyString_FromString(it.first.c_str()));
56     AutoPyPtr val(PyInt_FromLong(it.second));
57     PyDict_SetItem(ret,st,val);
58   }
59   return ret;
60 }
61
62 AutoPyPtr convertMapStringVectString(const std::map<std::string,std::vector<std::string>>& cpp)
63 {
64   AutoPyPtr ret(PyDict_New());
65   for(auto it : cpp)
66   {
67     AutoPyPtr st(PyString_FromString(it.first.c_str()));
68     AutoPyPtr vec(PyList_New(it.second.size()));
69     std::size_t itc(0);
70     for(auto it2 : it.second)
71     {
72       AutoPyPtr st2(PyString_FromString(it2.c_str()));
73       PyList_SetItem(vec,itc++,st2.retn());
74     }
75     PyDict_SetItem(ret,st,vec.retn());
76   }
77   return ret;
78 }
79
80 static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner)
81 {
82   PyObject *ret=0;
83   if(!mesh)
84     {
85       Py_XINCREF(Py_None);
86       return Py_None;
87     }
88   if(dynamic_cast<MEDCoupling::MEDCouplingUMesh *>(mesh))
89     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,owner);
90   if(dynamic_cast<MEDCoupling::MEDCoupling1SGTUMesh *>(mesh))
91     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCoupling1SGTUMesh,owner);
92   if(dynamic_cast<MEDCoupling::MEDCoupling1DGTUMesh *>(mesh))
93     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCoupling1DGTUMesh,owner);
94   if(dynamic_cast<MEDCoupling::MEDCouplingMappedExtrudedMesh *>(mesh))
95     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingMappedExtrudedMesh,owner);
96   if(dynamic_cast<MEDCoupling::MEDCouplingCMesh *>(mesh))
97     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingCMesh,owner);
98   if(dynamic_cast<MEDCoupling::MEDCouplingCurveLinearMesh *>(mesh))
99     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingCurveLinearMesh,owner);
100   if(dynamic_cast<MEDCoupling::MEDCouplingIMesh *>(mesh))
101     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingIMesh,owner);
102   if(!ret)
103     throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
104   return ret;
105 }
106
107 static PyObject *convertFieldDiscretization(MEDCoupling::MEDCouplingFieldDiscretization *fd, int owner)
108 {
109   PyObject *ret=0;
110   if(!fd)
111     {
112       Py_XINCREF(Py_None);
113       return Py_None;
114     }
115   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationP0 *>(fd))
116     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationP0,owner);
117   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationP1 *>(fd))
118     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationP1,owner);
119   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationGauss *>(fd))
120     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationGauss,owner);
121   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationGaussNE *>(fd))
122     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationGaussNE,owner);
123   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationKriging *>(fd))
124     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationKriging,owner);
125   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationOnNodesFE *>(fd))
126     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationOnNodesFE,owner);
127   if(!ret)
128     throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
129   return ret;
130 }
131
132 static PyObject *convertField(MEDCoupling::MEDCouplingField *f, int owner)
133 {
134   PyObject *ret(NULL);
135   if(!f)
136     {
137       Py_XINCREF(Py_None);
138       return Py_None;
139     }
140   if(dynamic_cast<MEDCoupling::MEDCouplingFieldDouble *>(f))
141     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,owner);
142   if(dynamic_cast<MEDCoupling::MEDCouplingFieldInt32 *>(f))
143     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldInt32,owner);
144   if(dynamic_cast<MEDCoupling::MEDCouplingFieldInt64 *>(f))
145     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldInt64,owner);
146   if(dynamic_cast<MEDCoupling::MEDCouplingFieldFloat *>(f))
147     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldFloat,owner);
148   if(!ret)
149     throw INTERP_KERNEL::Exception("Not recognized type of field on downcast !");
150   return ret;
151 }
152
153 static PyObject* convertMultiFields(MEDCoupling::MEDCouplingMultiFields *mfs, int owner)
154 {
155   PyObject *ret=0;
156   if(!mfs)
157     {
158       Py_XINCREF(Py_None);
159       return Py_None;
160     }
161   if(dynamic_cast<MEDCoupling::MEDCouplingFieldOverTime *>(mfs))
162     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldOverTime,owner);
163   else
164     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_MEDCoupling__MEDCouplingMultiFields,owner);
165   return ret;
166 }
167
168 static PyObject *convertCartesianAMRMesh(MEDCoupling::MEDCouplingCartesianAMRMeshGen *mesh, int owner)
169 {
170   if(!mesh)
171     {
172       Py_XINCREF(Py_None);
173       return Py_None;
174     }
175   if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRMeshSub *>(mesh))
176     {
177       return SWIG_NewPointerObj(reinterpret_cast<void*>(mesh),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRMeshSub,owner);
178     }
179   if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRMesh *>(mesh))
180     {
181       return SWIG_NewPointerObj(reinterpret_cast<void*>(mesh),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRMesh,owner);
182     }
183   throw INTERP_KERNEL::Exception("convertCartesianAMRMesh wrap : unrecognized type of cartesian AMR mesh !");
184 }
185
186 static PyObject *convertDataForGodFather(MEDCoupling::MEDCouplingDataForGodFather *data, int owner)
187 {
188   if(!data)
189     {
190       Py_XINCREF(Py_None);
191       return Py_None;
192     }
193   if(dynamic_cast<MEDCoupling::MEDCouplingAMRAttribute *>(data))
194     {
195       return SWIG_NewPointerObj(reinterpret_cast<void*>(data),SWIGTYPE_p_MEDCoupling__MEDCouplingAMRAttribute,owner);
196     }
197   throw INTERP_KERNEL::Exception("convertDataForGodFather wrap : unrecognized data type for AMR !");
198 }
199
200 static PyObject *convertCartesianAMRPatch(MEDCoupling::MEDCouplingCartesianAMRPatchGen *patch, int owner)
201 {
202   if(!patch)
203     {
204       Py_XINCREF(Py_None);
205       return Py_None;
206     }
207   if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRPatchGF *>(patch))
208     {
209       return SWIG_NewPointerObj(reinterpret_cast<void*>(patch),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRPatchGF,owner);
210     }
211   if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRPatch *>(patch))
212     {
213       return SWIG_NewPointerObj(reinterpret_cast<void*>(patch),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRPatch,owner);
214     }
215   throw INTERP_KERNEL::Exception("convertCartesianAMRPatch wrap : unrecognized type of cartesian AMR patch !");
216 }
217
218 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___add__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
219 {
220   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.";
221   const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !";
222   void *argp;
223   //
224   if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
225     {
226       MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
227       if(other)
228         return (*self)+(*other);
229       else
230         throw INTERP_KERNEL::Exception(msg);
231     }
232   //
233   double val;
234   MEDCoupling::DataArrayDouble *a;
235   MEDCoupling::DataArrayDoubleTuple *aa;
236   std::vector<double> bb;
237   mcIdType sw;
238   convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
239   switch(sw)
240     {
241     case 1:
242       {
243         if(!self->getArray())
244           throw INTERP_KERNEL::Exception(msg2);
245         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
246         ret->applyLin(1.,val);
247         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
248         ret2->setArray(ret);
249         return ret2.retn();
250       }
251     case 2:
252       {
253         if(!self->getArray())
254           throw INTERP_KERNEL::Exception(msg2);
255         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),a);
256         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
257         ret2->setArray(ret);
258         return ret2.retn();
259       }
260     case 3:
261       {
262         if(!self->getArray())
263           throw INTERP_KERNEL::Exception(msg2);
264         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
265         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),aaa);
266         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
267         ret2->setArray(ret);
268         return ret2.retn();
269       }
270     case 4:
271       {
272         if(!self->getArray())
273           throw INTERP_KERNEL::Exception(msg2);
274         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,(int)bb.size());
275         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),aaa);
276         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
277         ret2->setArray(ret);
278         return ret2.retn();
279       }
280     default:
281       { throw INTERP_KERNEL::Exception(msg); }
282     }
283 }
284
285 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___radd__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
286 {
287   return MEDCoupling_MEDCouplingFieldDouble___add__Impl(self,obj);
288 }
289
290 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rsub__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
291 {
292   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.";
293   const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : 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 (*other)-(*self);
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   mcIdType 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(-1.,val);
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::Substract(a,self->getArray());
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::Substract(aaa,self->getArray());
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::DeallocType::CPP_DEALLOC,1,(int)bb.size());
347         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Substract(aaa,self->getArray());
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 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___mul__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
358 {
359   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.";
360   const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !";
361   void *argp;
362   //
363   if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
364     {
365       MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
366       if(other)
367         return (*self)*(*other);
368       else
369         throw INTERP_KERNEL::Exception(msg);
370     }
371   //
372   double val;
373   MEDCoupling::DataArrayDouble *a;
374   MEDCoupling::DataArrayDoubleTuple *aa;
375   std::vector<double> bb;
376   mcIdType sw;
377   convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
378   switch(sw)
379     {
380     case 1:
381       {
382         if(!self->getArray())
383           throw INTERP_KERNEL::Exception(msg2);
384         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
385         ret->applyLin(val,0.);
386         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
387         ret2->setArray(ret);
388         return ret2.retn();
389       }
390     case 2:
391       {
392         if(!self->getArray())
393           throw INTERP_KERNEL::Exception(msg2);
394         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),a);
395         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
396         ret2->setArray(ret);
397         return ret2.retn();
398       }
399     case 3:
400       {
401         if(!self->getArray())
402           throw INTERP_KERNEL::Exception(msg2);
403         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
404         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),aaa);
405         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
406         ret2->setArray(ret);
407         return ret2.retn();
408       }
409     case 4:
410       {
411         if(!self->getArray())
412           throw INTERP_KERNEL::Exception(msg2);
413         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,(int)bb.size());
414         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),aaa);
415         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
416         ret2->setArray(ret);
417         return ret2.retn();
418       }
419     default:
420       { throw INTERP_KERNEL::Exception(msg); }
421     }
422 }
423
424 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rmul__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
425 {
426   return MEDCoupling_MEDCouplingFieldDouble___mul__Impl(self,obj);
427 }
428
429 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rdiv__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
430 {
431   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.";
432   const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !";
433   void *argp;
434   //
435   if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
436     {
437       MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
438       if(other)
439         return (*other)/(*self);
440       else
441         throw INTERP_KERNEL::Exception(msg);
442     }
443   //
444   double val;
445   MEDCoupling::DataArrayDouble *a;
446   MEDCoupling::DataArrayDoubleTuple *aa;
447   std::vector<double> bb;
448   mcIdType sw;
449   convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
450   switch(sw)
451     {
452     case 1:
453       {
454         if(!self->getArray())
455           throw INTERP_KERNEL::Exception(msg2);
456         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
457         ret->applyInv(val);
458         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
459         ret2->setArray(ret);
460         return ret2.retn();
461       }
462     case 2:
463       {
464         if(!self->getArray())
465           throw INTERP_KERNEL::Exception(msg2);
466         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(a,self->getArray());
467         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
468         ret2->setArray(ret);
469         return ret2.retn();
470       }
471     case 3:
472       {
473         if(!self->getArray())
474           throw INTERP_KERNEL::Exception(msg2);
475         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
476         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(aaa,self->getArray());
477         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
478         ret2->setArray(ret);
479         return ret2.retn();
480       }
481     case 4:
482       {
483         if(!self->getArray())
484           throw INTERP_KERNEL::Exception(msg2);
485         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,(int)bb.size());
486         MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(aaa,self->getArray());
487         MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
488         ret2->setArray(ret);
489         return ret2.retn();
490       }
491     default:
492       { throw INTERP_KERNEL::Exception(msg); }
493     }
494 }
495
496 template<class T>
497 typename MEDCoupling::Traits<T>::FieldType *fieldT_buildSubPart(const MEDCoupling::MEDCouplingFieldT<T> *self, PyObject *li)
498 {
499   mcIdType sw;
500   mcIdType singleVal;
501   std::vector<mcIdType> multiVal;
502   std::pair<mcIdType, std::pair<mcIdType,mcIdType> > slic;
503   MEDCoupling::DataArrayIdType *daIntTyypp=0;
504   const MEDCoupling::MEDCouplingMesh *mesh=self->getMesh();
505   if(!mesh)
506     throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : field lies on a null mesh !");
507   mcIdType nbc=mesh->getNumberOfCells();
508   convertIntStarOrSliceLikePyObjToCpp(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
509   switch(sw)
510     {
511     case 1:
512       {
513         if(singleVal>=nbc)
514           {
515             std::ostringstream oss;
516             oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !";
517             throw INTERP_KERNEL::Exception(oss.str().c_str());
518           }
519         if(singleVal>=0)
520           return self->buildSubPart(&singleVal,&singleVal+1);
521         else
522           {
523             if(nbc+singleVal>0)
524               {
525                 mcIdType tmp=nbc+singleVal;
526                 return self->buildSubPart(&tmp,&tmp+1);
527               }
528             else
529               {
530                 std::ostringstream oss;
531                 oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !";
532                 throw INTERP_KERNEL::Exception(oss.str().c_str());
533               }
534           }
535       }
536     case 2:
537       {
538         return self->buildSubPart(&multiVal[0],&multiVal[0]+multiVal.size());
539       }
540     case 3:
541       {
542         return self->buildSubPartRange(slic.first,slic.second.first,slic.second.second);
543       }
544     case 4:
545       {
546         if(!daIntTyypp)
547           throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : null instance has been given in input !");
548         daIntTyypp->checkAllocated();
549         return self->buildSubPart(daIntTyypp->begin(),daIntTyypp->end());
550       }
551     default:
552       throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayIdType instance !");
553     }
554 }
555
556 template<class T>
557 typename MEDCoupling::Traits<T>::FieldType *fieldT__getitem__(const MEDCoupling::MEDCouplingFieldT<T> *self, PyObject *li)
558 {
559   const char msg[]="MEDCouplingFieldDouble::__getitem__ : invalid call  Available API are : \n-myField[DataArrayIdType]\n-myField[slice]\n-myField[pythonListOfCellIds]\n-myField[integer]\n-myField[DataArrayIdType,1]\n-myField[slice,1]\n-myField[pythonListOfCellIds,1]\n-myField[integer,1]\n";
560   if(PyTuple_Check(li))
561     {
562       Py_ssize_t sz=PyTuple_Size(li);
563       if(sz!=2)
564         throw INTERP_KERNEL::Exception(msg);
565       PyObject *elt0=PyTuple_GetItem(li,0),*elt1=PyTuple_GetItem(li,1);
566       mcIdType sw;
567       std::size_t singleVal;
568       std::vector<std::size_t> multiVal;
569       std::pair<mcIdType, std::pair<mcIdType,mcIdType> > slic;
570       MEDCoupling::DataArrayIdType *daIntTyypp=0;
571       if(!self->getArray())
572         throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array set on field to deduce number of components !");
573       try
574       { convertIntStarOrSliceLikePyObjToCpp(elt1,ToIdType(self->getArray()->getNumberOfComponents()),sw,singleVal,multiVal,slic,daIntTyypp); }
575       catch(INTERP_KERNEL::Exception& e)
576         { std::ostringstream oss; oss << "MEDCouplingFieldDouble::__getitem__ : invalid type in 2nd parameter (compo) !" << e.what(); throw INTERP_KERNEL::Exception(oss.str().c_str()); }
577       typename MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::FieldType > ret0(fieldT_buildSubPart<T>(self,elt0));
578       typename MEDCoupling::Traits<T>::ArrayType *ret0Arr=ret0->getArray();
579       if(!ret0Arr)
580         throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array exists to apply restriction on component on it !");
581       switch(sw)
582         {
583         case 1:
584           {
585             std::vector<std::size_t> v2(1,singleVal);
586             MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(v2));
587             ret0->setArray(aarr);
588             return ret0.retn();
589           }
590         case 2:
591           {
592             MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(multiVal));
593             ret0->setArray(aarr);
594             return ret0.retn();
595           }
596         case 3:
597           {
598             mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(slic.first,slic.second.first,slic.second.second,"MEDCouplingFieldDouble::__getitem__ : invalid range in 2nd parameter (components) !"));
599             std::vector<std::size_t> v2(nbOfComp);
600             for(mcIdType i=0;i<nbOfComp;i++)
601               v2[i]=slic.first+i*slic.second.second;
602             MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(v2));
603             ret0->setArray(aarr);
604             return ret0.retn();
605           }
606         default:
607           throw INTERP_KERNEL::Exception(msg);
608         }
609     }
610   else
611     return fieldT_buildSubPart<T>(self,li);
612 }
613
614 template<class FIELDT>
615 PyObject *field_getTinySerializationInformation(const FIELDT *self)
616 {
617   std::vector<double> a0;
618   std::vector<mcIdType> a1;
619   std::vector<std::string> a2;
620   self->getTinySerializationDbleInformation(a0);
621   self->getTinySerializationIntInformation(a1);
622   self->getTinySerializationStrInformation(a2);
623   //
624   PyObject *ret(PyTuple_New(3));
625   PyTuple_SetItem(ret,0,convertDblArrToPyList2(a0));
626   PyTuple_SetItem(ret,1,convertIntArrToPyList2(a1));
627   std::size_t sz(a2.size());
628   PyObject *ret2(PyList_New(sz));
629   {
630     for(std::size_t i=0;i<sz;i++)
631       PyList_SetItem(ret2,i,PyString_FromString(a2[i].c_str()));
632   }
633   PyTuple_SetItem(ret,2,ret2);
634   return ret;
635 }
636
637 template<class T>
638 PyObject *field_serialize(const typename MEDCoupling::Traits<T>::FieldType *self)
639 {
640   MEDCoupling::DataArrayIdType *ret0(0);
641   std::vector<typename MEDCoupling::Traits<T>::ArrayType *> ret1;
642   self->serialize(ret0,ret1);
643   if(ret0)
644     ret0->incrRef();
645   std::size_t sz(ret1.size());
646   PyObject *ret(PyTuple_New(2));
647   PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTITraits<mcIdType>::TI, SWIG_POINTER_OWN | 0 ));
648   PyObject *ret1Py(PyList_New(sz));
649   for(std::size_t i=0;i<sz;i++)
650     {
651       if(ret1[i])
652         ret1[i]->incrRef();
653       PyList_SetItem(ret1Py,i,convertArray(ret1[i],SWIG_POINTER_OWN | 0));
654     }
655   PyTuple_SetItem(ret,1,ret1Py);
656   return ret;
657 }
658
659 template<class FIELDT>
660 PyObject *field__getnewargs__(FIELDT *self)
661 {
662   self->checkConsistencyLight();
663   PyObject *ret(PyTuple_New(1));
664   PyObject *ret0(PyDict_New());
665   {
666     PyObject *a(PyInt_FromLong(0)),*b(PyInt_FromLong(self->getTypeOfField())),*c(PyInt_FromLong(self->getTimeDiscretization()));
667     PyObject *d(PyTuple_New(2)); PyTuple_SetItem(d,0,b); PyTuple_SetItem(d,1,c);
668     PyDict_SetItem(ret0,a,d);
669     Py_DECREF(a); Py_DECREF(d);
670   }
671   PyTuple_SetItem(ret,0,ret0);
672   return ret;
673 }
674
675 template<class FIELDT>
676 PyObject *field__getstate__(const FIELDT *self, PyObject *(*tinyserial)(const FIELDT *), PyObject *(*bigserial)(const FIELDT *))
677 {
678   self->checkConsistencyLight();
679   PyObject *ret0(tinyserial(self));
680   PyObject *ret1(bigserial(self));
681   const MEDCoupling::MEDCouplingMesh *mesh(self->getMesh());
682   if(mesh)
683     mesh->incrRef();
684   PyObject *ret(PyTuple_New(3));
685   PyTuple_SetItem(ret,0,ret0);
686   PyTuple_SetItem(ret,1,ret1);
687   PyTuple_SetItem(ret,2,convertMesh(const_cast<MEDCoupling::MEDCouplingMesh *>(mesh),SWIG_POINTER_OWN | 0 ));
688   return ret;
689 }
690
691 template<class T>
692 void field__setstate__(typename MEDCoupling::Traits<T>::FieldType *self, PyObject *inp)
693 {
694   static const char MSG[]="MEDCouplingFieldDouble.__setstate__ : expected input is a tuple of size 3 !";
695   if(!PyTuple_Check(inp))
696     throw INTERP_KERNEL::Exception(MSG);
697   std::size_t sz(PyTuple_Size(inp));
698   if(sz!=3)
699     throw INTERP_KERNEL::Exception(MSG);
700   // mesh
701   PyObject *elt2(PyTuple_GetItem(inp,2));
702   void *argp=0;
703   int status(SWIG_ConvertPtr(elt2,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingMesh,0|0));
704   if(!SWIG_IsOK(status))
705     throw INTERP_KERNEL::Exception(MSG);
706   self->setMesh(reinterpret_cast< const MEDCoupling::MEDCouplingMesh * >(argp));
707   //
708   PyObject *elt0(PyTuple_GetItem(inp,0));
709   PyObject *elt1(PyTuple_GetItem(inp,1));
710   std::vector<double> a0;
711   std::vector<mcIdType> a1;
712   std::vector<std::string> a2;
713   MEDCoupling::DataArrayIdType *b0(0);
714   std::vector<typename MEDCoupling::Traits<T>::ArrayType *>b1;
715   {
716     if(!PyTuple_Check(elt0) && PyTuple_Size(elt0)!=3)
717       throw INTERP_KERNEL::Exception(MSG);
718     PyObject *a0py(PyTuple_GetItem(elt0,0)),*a1py(PyTuple_GetItem(elt0,1)),*a2py(PyTuple_GetItem(elt0,2));
719     mcIdType tmp(-1);
720     fillArrayWithPyListDbl3(a0py,tmp,a0);
721     convertPyToNewIntArr3(a1py,a1);
722     fillStringVector(a2py,a2);
723   }
724   {
725     if(!PyTuple_Check(elt1) && PyTuple_Size(elt1)!=2)
726       throw INTERP_KERNEL::Exception(MSG);
727     PyObject *b0py(PyTuple_GetItem(elt1,0)),*b1py(PyTuple_GetItem(elt1,1));
728     void *argp(0);
729     int status(SWIG_ConvertPtr(b0py,&argp,SWIGTITraits<mcIdType>::TI,0|0));
730     if(!SWIG_IsOK(status))
731       throw INTERP_KERNEL::Exception(MSG);
732     b0=reinterpret_cast<MEDCoupling::DataArrayIdType *>(argp);
733     convertFromPyObjVectorOfObj<typename MEDCoupling::Traits<T>::ArrayType *>(b1py,SWIGTITraits<T>::TI,MEDCoupling::Traits<T>::ArrayTypeName,b1);
734   }
735   self->checkForUnserialization(a1,b0,b1);
736   // useless here to call resizeForUnserialization because arrays are well resized.
737   self->finishUnserialization(a1,a0,a2);
738 }
739
740 PyObject *Mesh_getCellsContainingPointsLike(PyObject *p, double eps, const MEDCoupling::MEDCouplingMesh *self, std::function<void(const double *,mcIdType,double,MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType>&,MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType>&)> func)
741 {
742   MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elts,eltsIndex;
743   int spaceDim=self->getSpaceDimension();
744   void *da=0;
745   int res1=SWIG_ConvertPtr(p,&da,SWIGTYPE_p_MEDCoupling__DataArrayDouble, 0 |  0 );
746   if (!SWIG_IsOK(res1))
747     {
748       mcIdType size;
749       INTERP_KERNEL::AutoCPtr<double> tmp=convertPyToNewDblArr2(p,&size);
750       mcIdType nbOfPoints=size/spaceDim;
751       if(size%spaceDim!=0)
752         {
753           throw INTERP_KERNEL::Exception("MEDCouplingMesh::getCellsContainingPoints : Invalid list length ! Must be a multiple of self.getSpaceDimension() !");
754         }
755       func(tmp,nbOfPoints,eps,elts,eltsIndex);
756     }
757   else
758     {
759       MEDCoupling::DataArrayDouble *da2=reinterpret_cast< MEDCoupling::DataArrayDouble * >(da);
760       if(!da2)
761         throw INTERP_KERNEL::Exception("MEDCouplingMesh::getCellsContainingPoints : Not null DataArrayDouble instance expected !");
762       da2->checkAllocated();
763       mcIdType size=da2->getNumberOfTuples();
764       mcIdType nbOfCompo=ToIdType(da2->getNumberOfComponents());
765       if(nbOfCompo!=spaceDim)
766         {
767           throw INTERP_KERNEL::Exception("MEDCouplingMesh::getCellsContainingPoints : Invalid DataArrayDouble nb of components ! Expected same as self.getSpaceDimension() !");
768         }
769       func(da2->getConstPointer(),size,eps,elts,eltsIndex);
770     }
771   PyObject *ret=PyTuple_New(2);
772   PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(elts.retn()),SWIGTITraits<mcIdType>::TI, SWIG_POINTER_OWN | 0 ));
773   PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(eltsIndex.retn()),SWIGTITraits<mcIdType>::TI, SWIG_POINTER_OWN | 0 ));
774   return ret;
775 }