1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __MEDCOUPLINGTYPEMAPS_I__
22 #define __MEDCOUPLINGTYPEMAPS_I__
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"
38 auto PyDeleter = [](PyObject *ob) { Py_DECREF(ob) ; };
40 class AutoPyPtr : std::unique_ptr<PyObject,decltype(PyDeleter)>
43 AutoPyPtr(PyObject *ob):std::unique_ptr<PyObject,decltype(PyDeleter)>(ob,PyDeleter) { }
44 PyObject *retn() { return this->release(); }
45 operator PyObject *() const { return this->get(); }
48 AutoPyPtr convertMapStringInt(const std::map<std::string,mcIdType>& cpp)
50 AutoPyPtr ret(PyDict_New());
53 AutoPyPtr st(PyString_FromString(it.first.c_str()));
54 AutoPyPtr val(PyInt_FromLong(it.second));
55 PyDict_SetItem(ret,st,val);
60 AutoPyPtr convertMapStringVectString(const std::map<std::string,std::vector<std::string>>& cpp)
62 AutoPyPtr ret(PyDict_New());
65 AutoPyPtr st(PyString_FromString(it.first.c_str()));
66 AutoPyPtr vec(PyList_New(it.second.size()));
68 for(auto it2 : it.second)
70 AutoPyPtr st2(PyString_FromString(it2.c_str()));
71 PyList_SetItem(vec,itc++,st2.retn());
73 PyDict_SetItem(ret,st,vec.retn());
78 static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner)
86 if(dynamic_cast<MEDCoupling::MEDCouplingUMesh *>(mesh))
87 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,owner);
88 if(dynamic_cast<MEDCoupling::MEDCoupling1SGTUMesh *>(mesh))
89 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCoupling1SGTUMesh,owner);
90 if(dynamic_cast<MEDCoupling::MEDCoupling1DGTUMesh *>(mesh))
91 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCoupling1DGTUMesh,owner);
92 if(dynamic_cast<MEDCoupling::MEDCouplingMappedExtrudedMesh *>(mesh))
93 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingMappedExtrudedMesh,owner);
94 if(dynamic_cast<MEDCoupling::MEDCouplingCMesh *>(mesh))
95 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingCMesh,owner);
96 if(dynamic_cast<MEDCoupling::MEDCouplingCurveLinearMesh *>(mesh))
97 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingCurveLinearMesh,owner);
98 if(dynamic_cast<MEDCoupling::MEDCouplingIMesh *>(mesh))
99 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingIMesh,owner);
101 throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
105 static PyObject *convertFieldDiscretization(MEDCoupling::MEDCouplingFieldDiscretization *fd, int owner)
113 if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationP0 *>(fd))
114 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationP0,owner);
115 if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationP1 *>(fd))
116 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationP1,owner);
117 if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationGauss *>(fd))
118 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationGauss,owner);
119 if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationGaussNE *>(fd))
120 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationGaussNE,owner);
121 if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationKriging *>(fd))
122 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationKriging,owner);
124 throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
128 static PyObject *convertField(MEDCoupling::MEDCouplingField *f, int owner)
136 if(dynamic_cast<MEDCoupling::MEDCouplingFieldDouble *>(f))
137 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,owner);
138 if(dynamic_cast<MEDCoupling::MEDCouplingFieldInt *>(f))
139 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldInt,owner);
140 if(dynamic_cast<MEDCoupling::MEDCouplingFieldFloat *>(f))
141 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldFloat,owner);
143 throw INTERP_KERNEL::Exception("Not recognized type of field on downcast !");
147 static PyObject* convertMultiFields(MEDCoupling::MEDCouplingMultiFields *mfs, int owner)
155 if(dynamic_cast<MEDCoupling::MEDCouplingFieldOverTime *>(mfs))
156 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldOverTime,owner);
158 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_MEDCoupling__MEDCouplingMultiFields,owner);
162 static PyObject *convertCartesianAMRMesh(MEDCoupling::MEDCouplingCartesianAMRMeshGen *mesh, int owner)
169 if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRMeshSub *>(mesh))
171 return SWIG_NewPointerObj(reinterpret_cast<void*>(mesh),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRMeshSub,owner);
173 if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRMesh *>(mesh))
175 return SWIG_NewPointerObj(reinterpret_cast<void*>(mesh),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRMesh,owner);
177 throw INTERP_KERNEL::Exception("convertCartesianAMRMesh wrap : unrecognized type of cartesian AMR mesh !");
180 static PyObject *convertDataForGodFather(MEDCoupling::MEDCouplingDataForGodFather *data, int owner)
187 if(dynamic_cast<MEDCoupling::MEDCouplingAMRAttribute *>(data))
189 return SWIG_NewPointerObj(reinterpret_cast<void*>(data),SWIGTYPE_p_MEDCoupling__MEDCouplingAMRAttribute,owner);
191 throw INTERP_KERNEL::Exception("convertDataForGodFather wrap : unrecognized data type for AMR !");
194 static PyObject *convertCartesianAMRPatch(MEDCoupling::MEDCouplingCartesianAMRPatchGen *patch, int owner)
201 if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRPatchGF *>(patch))
203 return SWIG_NewPointerObj(reinterpret_cast<void*>(patch),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRPatchGF,owner);
205 if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRPatch *>(patch))
207 return SWIG_NewPointerObj(reinterpret_cast<void*>(patch),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRPatch,owner);
209 throw INTERP_KERNEL::Exception("convertCartesianAMRPatch wrap : unrecognized type of cartesian AMR patch !");
212 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___add__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
214 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.";
215 const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !";
218 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
220 MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
222 return (*self)+(*other);
224 throw INTERP_KERNEL::Exception(msg);
228 MEDCoupling::DataArrayDouble *a;
229 MEDCoupling::DataArrayDoubleTuple *aa;
230 std::vector<double> bb;
232 convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
237 if(!self->getArray())
238 throw INTERP_KERNEL::Exception(msg2);
239 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
240 ret->applyLin(1.,val);
241 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
247 if(!self->getArray())
248 throw INTERP_KERNEL::Exception(msg2);
249 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),a);
250 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
256 if(!self->getArray())
257 throw INTERP_KERNEL::Exception(msg2);
258 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
259 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),aaa);
260 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
266 if(!self->getArray())
267 throw INTERP_KERNEL::Exception(msg2);
268 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,(int)bb.size());
269 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),aaa);
270 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
275 { throw INTERP_KERNEL::Exception(msg); }
279 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___radd__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
281 return MEDCoupling_MEDCouplingFieldDouble___add__Impl(self,obj);
284 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rsub__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
286 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.";
287 const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !";
290 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
292 MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
294 return (*other)-(*self);
296 throw INTERP_KERNEL::Exception(msg);
300 MEDCoupling::DataArrayDouble *a;
301 MEDCoupling::DataArrayDoubleTuple *aa;
302 std::vector<double> bb;
304 convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
309 if(!self->getArray())
310 throw INTERP_KERNEL::Exception(msg2);
311 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
312 ret->applyLin(-1.,val);
313 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
319 if(!self->getArray())
320 throw INTERP_KERNEL::Exception(msg2);
321 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Substract(a,self->getArray());
322 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
328 if(!self->getArray())
329 throw INTERP_KERNEL::Exception(msg2);
330 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
331 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Substract(aaa,self->getArray());
332 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
338 if(!self->getArray())
339 throw INTERP_KERNEL::Exception(msg2);
340 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,(int)bb.size());
341 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Substract(aaa,self->getArray());
342 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
347 { throw INTERP_KERNEL::Exception(msg); }
351 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___mul__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
353 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.";
354 const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !";
357 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
359 MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
361 return (*self)*(*other);
363 throw INTERP_KERNEL::Exception(msg);
367 MEDCoupling::DataArrayDouble *a;
368 MEDCoupling::DataArrayDoubleTuple *aa;
369 std::vector<double> bb;
371 convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
376 if(!self->getArray())
377 throw INTERP_KERNEL::Exception(msg2);
378 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
379 ret->applyLin(val,0.);
380 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
386 if(!self->getArray())
387 throw INTERP_KERNEL::Exception(msg2);
388 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),a);
389 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
395 if(!self->getArray())
396 throw INTERP_KERNEL::Exception(msg2);
397 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
398 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),aaa);
399 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
405 if(!self->getArray())
406 throw INTERP_KERNEL::Exception(msg2);
407 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,(int)bb.size());
408 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),aaa);
409 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
414 { throw INTERP_KERNEL::Exception(msg); }
418 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rmul__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
420 return MEDCoupling_MEDCouplingFieldDouble___mul__Impl(self,obj);
423 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rdiv__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj)
425 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.";
426 const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !";
429 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
431 MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
433 return (*other)/(*self);
435 throw INTERP_KERNEL::Exception(msg);
439 MEDCoupling::DataArrayDouble *a;
440 MEDCoupling::DataArrayDoubleTuple *aa;
441 std::vector<double> bb;
443 convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
448 if(!self->getArray())
449 throw INTERP_KERNEL::Exception(msg2);
450 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
452 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
458 if(!self->getArray())
459 throw INTERP_KERNEL::Exception(msg2);
460 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(a,self->getArray());
461 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
467 if(!self->getArray())
468 throw INTERP_KERNEL::Exception(msg2);
469 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
470 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(aaa,self->getArray());
471 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
477 if(!self->getArray())
478 throw INTERP_KERNEL::Exception(msg2);
479 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,(int)bb.size());
480 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(aaa,self->getArray());
481 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
486 { throw INTERP_KERNEL::Exception(msg); }
491 typename MEDCoupling::Traits<T>::FieldType *fieldT_buildSubPart(const MEDCoupling::MEDCouplingFieldT<T> *self, PyObject *li)
495 std::vector<mcIdType> multiVal;
496 std::pair<mcIdType, std::pair<mcIdType,mcIdType> > slic;
497 MEDCoupling::DataArrayIdType *daIntTyypp=0;
498 const MEDCoupling::MEDCouplingMesh *mesh=self->getMesh();
500 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : field lies on a null mesh !");
501 mcIdType nbc=mesh->getNumberOfCells();
502 convertIntStarOrSliceLikePyObjToCpp(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
509 std::ostringstream oss;
510 oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !";
511 throw INTERP_KERNEL::Exception(oss.str().c_str());
514 return self->buildSubPart(&singleVal,&singleVal+1);
519 mcIdType tmp=nbc+singleVal;
520 return self->buildSubPart(&tmp,&tmp+1);
524 std::ostringstream oss;
525 oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !";
526 throw INTERP_KERNEL::Exception(oss.str().c_str());
532 return self->buildSubPart(&multiVal[0],&multiVal[0]+multiVal.size());
536 return self->buildSubPartRange(slic.first,slic.second.first,slic.second.second);
541 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : null instance has been given in input !");
542 daIntTyypp->checkAllocated();
543 return self->buildSubPart(daIntTyypp->begin(),daIntTyypp->end());
546 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayIdType instance !");
551 typename MEDCoupling::Traits<T>::FieldType *fieldT__getitem__(const MEDCoupling::MEDCouplingFieldT<T> *self, PyObject *li)
553 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";
554 if(PyTuple_Check(li))
556 Py_ssize_t sz=PyTuple_Size(li);
558 throw INTERP_KERNEL::Exception(msg);
559 PyObject *elt0=PyTuple_GetItem(li,0),*elt1=PyTuple_GetItem(li,1);
561 std::size_t singleVal;
562 std::vector<std::size_t> multiVal;
563 std::pair<mcIdType, std::pair<mcIdType,mcIdType> > slic;
564 MEDCoupling::DataArrayIdType *daIntTyypp=0;
565 if(!self->getArray())
566 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array set on field to deduce number of components !");
568 { convertIntStarOrSliceLikePyObjToCpp(elt1,ToIdType(self->getArray()->getNumberOfComponents()),sw,singleVal,multiVal,slic,daIntTyypp); }
569 catch(INTERP_KERNEL::Exception& e)
570 { std::ostringstream oss; oss << "MEDCouplingFieldDouble::__getitem__ : invalid type in 2nd parameter (compo) !" << e.what(); throw INTERP_KERNEL::Exception(oss.str().c_str()); }
571 typename MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::FieldType > ret0(fieldT_buildSubPart<T>(self,elt0));
572 typename MEDCoupling::Traits<T>::ArrayType *ret0Arr=ret0->getArray();
574 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array exists to apply restriction on component on it !");
579 std::vector<std::size_t> v2(1,singleVal);
580 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(v2));
581 ret0->setArray(aarr);
586 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(multiVal));
587 ret0->setArray(aarr);
592 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(slic.first,slic.second.first,slic.second.second,"MEDCouplingFieldDouble::__getitem__ : invalid range in 2nd parameter (components) !"));
593 std::vector<std::size_t> v2(nbOfComp);
594 for(mcIdType i=0;i<nbOfComp;i++)
595 v2[i]=slic.first+i*slic.second.second;
596 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aarr(ret0Arr->keepSelectedComponents(v2));
597 ret0->setArray(aarr);
601 throw INTERP_KERNEL::Exception(msg);
605 return fieldT_buildSubPart<T>(self,li);
608 template<class FIELDT>
609 PyObject *field_getTinySerializationInformation(const FIELDT *self)
611 std::vector<double> a0;
612 std::vector<mcIdType> a1;
613 std::vector<std::string> a2;
614 self->getTinySerializationDbleInformation(a0);
615 self->getTinySerializationIntInformation(a1);
616 self->getTinySerializationStrInformation(a2);
618 PyObject *ret(PyTuple_New(3));
619 PyTuple_SetItem(ret,0,convertDblArrToPyList2(a0));
620 PyTuple_SetItem(ret,1,convertIntArrToPyList2(a1));
621 std::size_t sz(a2.size());
622 PyObject *ret2(PyList_New(sz));
624 for(std::size_t i=0;i<sz;i++)
625 PyList_SetItem(ret2,i,PyString_FromString(a2[i].c_str()));
627 PyTuple_SetItem(ret,2,ret2);
632 PyObject *field_serialize(const typename MEDCoupling::Traits<T>::FieldType *self)
634 MEDCoupling::DataArrayIdType *ret0(0);
635 std::vector<typename MEDCoupling::Traits<T>::ArrayType *> ret1;
636 self->serialize(ret0,ret1);
639 std::size_t sz(ret1.size());
640 PyObject *ret(PyTuple_New(2));
641 PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTITraits<mcIdType>::TI, SWIG_POINTER_OWN | 0 ));
642 PyObject *ret1Py(PyList_New(sz));
643 for(std::size_t i=0;i<sz;i++)
647 PyList_SetItem(ret1Py,i,convertArray(ret1[i],SWIG_POINTER_OWN | 0));
649 PyTuple_SetItem(ret,1,ret1Py);
653 template<class FIELDT>
654 PyObject *field__getnewargs__(FIELDT *self)
656 self->checkConsistencyLight();
657 PyObject *ret(PyTuple_New(1));
658 PyObject *ret0(PyDict_New());
660 PyObject *a(PyInt_FromLong(0)),*b(PyInt_FromLong(self->getTypeOfField())),*c(PyInt_FromLong(self->getTimeDiscretization()));
661 PyObject *d(PyTuple_New(2)); PyTuple_SetItem(d,0,b); PyTuple_SetItem(d,1,c);
662 PyDict_SetItem(ret0,a,d);
663 Py_DECREF(a); Py_DECREF(d);
665 PyTuple_SetItem(ret,0,ret0);
669 template<class FIELDT>
670 PyObject *field__getstate__(const FIELDT *self, PyObject *(*tinyserial)(const FIELDT *), PyObject *(*bigserial)(const FIELDT *))
672 self->checkConsistencyLight();
673 PyObject *ret0(tinyserial(self));
674 PyObject *ret1(bigserial(self));
675 const MEDCoupling::MEDCouplingMesh *mesh(self->getMesh());
678 PyObject *ret(PyTuple_New(3));
679 PyTuple_SetItem(ret,0,ret0);
680 PyTuple_SetItem(ret,1,ret1);
681 PyTuple_SetItem(ret,2,convertMesh(const_cast<MEDCoupling::MEDCouplingMesh *>(mesh),SWIG_POINTER_OWN | 0 ));
686 void field__setstate__(typename MEDCoupling::Traits<T>::FieldType *self, PyObject *inp)
688 static const char MSG[]="MEDCouplingFieldDouble.__setstate__ : expected input is a tuple of size 3 !";
689 if(!PyTuple_Check(inp))
690 throw INTERP_KERNEL::Exception(MSG);
691 std::size_t sz(PyTuple_Size(inp));
693 throw INTERP_KERNEL::Exception(MSG);
695 PyObject *elt2(PyTuple_GetItem(inp,2));
697 int status(SWIG_ConvertPtr(elt2,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingMesh,0|0));
698 if(!SWIG_IsOK(status))
699 throw INTERP_KERNEL::Exception(MSG);
700 self->setMesh(reinterpret_cast< const MEDCoupling::MEDCouplingMesh * >(argp));
702 PyObject *elt0(PyTuple_GetItem(inp,0));
703 PyObject *elt1(PyTuple_GetItem(inp,1));
704 std::vector<double> a0;
705 std::vector<mcIdType> a1;
706 std::vector<std::string> a2;
707 MEDCoupling::DataArrayIdType *b0(0);
708 std::vector<typename MEDCoupling::Traits<T>::ArrayType *>b1;
710 if(!PyTuple_Check(elt0) && PyTuple_Size(elt0)!=3)
711 throw INTERP_KERNEL::Exception(MSG);
712 PyObject *a0py(PyTuple_GetItem(elt0,0)),*a1py(PyTuple_GetItem(elt0,1)),*a2py(PyTuple_GetItem(elt0,2));
714 fillArrayWithPyListDbl3(a0py,tmp,a0);
715 convertPyToNewIntArr3(a1py,a1);
716 fillStringVector(a2py,a2);
719 if(!PyTuple_Check(elt1) && PyTuple_Size(elt1)!=2)
720 throw INTERP_KERNEL::Exception(MSG);
721 PyObject *b0py(PyTuple_GetItem(elt1,0)),*b1py(PyTuple_GetItem(elt1,1));
723 int status(SWIG_ConvertPtr(b0py,&argp,SWIGTITraits<mcIdType>::TI,0|0));
724 if(!SWIG_IsOK(status))
725 throw INTERP_KERNEL::Exception(MSG);
726 b0=reinterpret_cast<MEDCoupling::DataArrayIdType *>(argp);
727 convertFromPyObjVectorOfObj<typename MEDCoupling::Traits<T>::ArrayType *>(b1py,SWIGTITraits<T>::TI,MEDCoupling::Traits<T>::ArrayTypeName,b1);
729 self->checkForUnserialization(a1,b0,b1);
730 // useless here to call resizeForUnserialization because arrays are well resized.
731 self->finishUnserialization(a1,a0,a2);
734 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)
736 MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> elts,eltsIndex;
737 int spaceDim=self->getSpaceDimension();
739 int res1=SWIG_ConvertPtr(p,&da,SWIGTYPE_p_MEDCoupling__DataArrayDouble, 0 | 0 );
740 if (!SWIG_IsOK(res1))
743 INTERP_KERNEL::AutoCPtr<double> tmp=convertPyToNewDblArr2(p,&size);
744 mcIdType nbOfPoints=size/spaceDim;
747 throw INTERP_KERNEL::Exception("MEDCouplingMesh::getCellsContainingPoints : Invalid list length ! Must be a multiple of self.getSpaceDimension() !");
749 func(tmp,nbOfPoints,eps,elts,eltsIndex);
753 MEDCoupling::DataArrayDouble *da2=reinterpret_cast< MEDCoupling::DataArrayDouble * >(da);
755 throw INTERP_KERNEL::Exception("MEDCouplingMesh::getCellsContainingPoints : Not null DataArrayDouble instance expected !");
756 da2->checkAllocated();
757 mcIdType size=da2->getNumberOfTuples();
758 mcIdType nbOfCompo=ToIdType(da2->getNumberOfComponents());
759 if(nbOfCompo!=spaceDim)
761 throw INTERP_KERNEL::Exception("MEDCouplingMesh::getCellsContainingPoints : Invalid DataArrayDouble nb of components ! Expected same as self.getSpaceDimension() !");
763 func(da2->getConstPointer(),size,eps,elts,eltsIndex);
765 PyObject *ret=PyTuple_New(2);
766 PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(elts.retn()),SWIGTITraits<mcIdType>::TI, SWIG_POINTER_OWN | 0 ));
767 PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(eltsIndex.retn()),SWIGTITraits<mcIdType>::TI, SWIG_POINTER_OWN | 0 ));