1 // Copyright (C) 2007-2016 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 #include "MEDCouplingDataArrayTypemaps.i"
23 static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception)
31 if(dynamic_cast<MEDCoupling::MEDCouplingUMesh *>(mesh))
32 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,owner);
33 if(dynamic_cast<MEDCoupling::MEDCoupling1SGTUMesh *>(mesh))
34 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCoupling1SGTUMesh,owner);
35 if(dynamic_cast<MEDCoupling::MEDCoupling1DGTUMesh *>(mesh))
36 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCoupling1DGTUMesh,owner);
37 if(dynamic_cast<MEDCoupling::MEDCouplingMappedExtrudedMesh *>(mesh))
38 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingMappedExtrudedMesh,owner);
39 if(dynamic_cast<MEDCoupling::MEDCouplingCMesh *>(mesh))
40 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingCMesh,owner);
41 if(dynamic_cast<MEDCoupling::MEDCouplingCurveLinearMesh *>(mesh))
42 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingCurveLinearMesh,owner);
43 if(dynamic_cast<MEDCoupling::MEDCouplingIMesh *>(mesh))
44 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingIMesh,owner);
46 throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
50 static PyObject *convertFieldDiscretization(MEDCoupling::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
58 if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationP0 *>(fd))
59 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationP0,owner);
60 if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationP1 *>(fd))
61 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationP1,owner);
62 if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationGauss *>(fd))
63 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationGauss,owner);
64 if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationGaussNE *>(fd))
65 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationGaussNE,owner);
66 if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationKriging *>(fd))
67 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationKriging,owner);
69 throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
73 static PyObject* convertMultiFields(MEDCoupling::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
81 if(dynamic_cast<MEDCoupling::MEDCouplingFieldOverTime *>(mfs))
82 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldOverTime,owner);
84 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_MEDCoupling__MEDCouplingMultiFields,owner);
88 static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner) throw(INTERP_KERNEL::Exception)
96 if(dynamic_cast<MEDCoupling::DataArrayPartDefinition *>(pd))
97 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__DataArrayPartDefinition,owner);
99 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__SlicePartDefinition,owner);
103 static PyObject *convertCartesianAMRMesh(MEDCoupling::MEDCouplingCartesianAMRMeshGen *mesh, int owner) throw(INTERP_KERNEL::Exception)
110 if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRMeshSub *>(mesh))
112 return SWIG_NewPointerObj(reinterpret_cast<void*>(mesh),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRMeshSub,owner);
114 if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRMesh *>(mesh))
116 return SWIG_NewPointerObj(reinterpret_cast<void*>(mesh),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRMesh,owner);
118 throw INTERP_KERNEL::Exception("convertCartesianAMRMesh wrap : unrecognized type of cartesian AMR mesh !");
121 static PyObject *convertDataForGodFather(MEDCoupling::MEDCouplingDataForGodFather *data, int owner) throw(INTERP_KERNEL::Exception)
128 if(dynamic_cast<MEDCoupling::MEDCouplingAMRAttribute *>(data))
130 return SWIG_NewPointerObj(reinterpret_cast<void*>(data),SWIGTYPE_p_MEDCoupling__MEDCouplingAMRAttribute,owner);
132 throw INTERP_KERNEL::Exception("convertDataForGodFather wrap : unrecognized data type for AMR !");
135 static PyObject *convertCartesianAMRPatch(MEDCoupling::MEDCouplingCartesianAMRPatchGen *patch, int owner) throw(INTERP_KERNEL::Exception)
142 if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRPatchGF *>(patch))
144 return SWIG_NewPointerObj(reinterpret_cast<void*>(patch),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRPatchGF,owner);
146 if(dynamic_cast<MEDCoupling::MEDCouplingCartesianAMRPatch *>(patch))
148 return SWIG_NewPointerObj(reinterpret_cast<void*>(patch),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRPatch,owner);
150 throw INTERP_KERNEL::Exception("convertCartesianAMRPatch wrap : unrecognized type of cartesian AMR patch !");
153 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___add__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
155 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.";
156 const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !";
159 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
161 MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
163 return (*self)+(*other);
165 throw INTERP_KERNEL::Exception(msg);
169 MEDCoupling::DataArrayDouble *a;
170 MEDCoupling::DataArrayDoubleTuple *aa;
171 std::vector<double> bb;
173 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
178 if(!self->getArray())
179 throw INTERP_KERNEL::Exception(msg2);
180 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
181 ret->applyLin(1.,val);
182 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
188 if(!self->getArray())
189 throw INTERP_KERNEL::Exception(msg2);
190 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),a);
191 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
197 if(!self->getArray())
198 throw INTERP_KERNEL::Exception(msg2);
199 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
200 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),aaa);
201 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
207 if(!self->getArray())
208 throw INTERP_KERNEL::Exception(msg2);
209 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
210 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),aaa);
211 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
216 { throw INTERP_KERNEL::Exception(msg); }
220 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___radd__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
222 return MEDCoupling_MEDCouplingFieldDouble___add__Impl(self,obj);
225 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rsub__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
227 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.";
228 const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !";
231 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
233 MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
235 return (*other)-(*self);
237 throw INTERP_KERNEL::Exception(msg);
241 MEDCoupling::DataArrayDouble *a;
242 MEDCoupling::DataArrayDoubleTuple *aa;
243 std::vector<double> bb;
245 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
250 if(!self->getArray())
251 throw INTERP_KERNEL::Exception(msg2);
252 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
253 ret->applyLin(-1.,val);
254 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
260 if(!self->getArray())
261 throw INTERP_KERNEL::Exception(msg2);
262 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Substract(a,self->getArray());
263 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
269 if(!self->getArray())
270 throw INTERP_KERNEL::Exception(msg2);
271 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
272 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Substract(aaa,self->getArray());
273 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
279 if(!self->getArray())
280 throw INTERP_KERNEL::Exception(msg2);
281 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
282 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Substract(aaa,self->getArray());
283 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
288 { throw INTERP_KERNEL::Exception(msg); }
292 static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___mul__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
294 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.";
295 const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !";
298 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
300 MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
302 return (*self)*(*other);
304 throw INTERP_KERNEL::Exception(msg);
308 MEDCoupling::DataArrayDouble *a;
309 MEDCoupling::DataArrayDoubleTuple *aa;
310 std::vector<double> bb;
312 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
317 if(!self->getArray())
318 throw INTERP_KERNEL::Exception(msg2);
319 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
320 ret->applyLin(val,0.);
321 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
327 if(!self->getArray())
328 throw INTERP_KERNEL::Exception(msg2);
329 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),a);
330 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
336 if(!self->getArray())
337 throw INTERP_KERNEL::Exception(msg2);
338 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
339 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),aaa);
340 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
346 if(!self->getArray())
347 throw INTERP_KERNEL::Exception(msg2);
348 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
349 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),aaa);
350 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
355 { throw INTERP_KERNEL::Exception(msg); }
359 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rmul__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
361 return MEDCoupling_MEDCouplingFieldDouble___mul__Impl(self,obj);
364 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rdiv__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
366 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.";
367 const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !";
370 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0)))
372 MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp);
374 return (*other)/(*self);
376 throw INTERP_KERNEL::Exception(msg);
380 MEDCoupling::DataArrayDouble *a;
381 MEDCoupling::DataArrayDoubleTuple *aa;
382 std::vector<double> bb;
384 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
389 if(!self->getArray())
390 throw INTERP_KERNEL::Exception(msg2);
391 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=self->getArray()->deepCopy();
393 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
399 if(!self->getArray())
400 throw INTERP_KERNEL::Exception(msg2);
401 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(a,self->getArray());
402 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
408 if(!self->getArray())
409 throw INTERP_KERNEL::Exception(msg2);
410 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
411 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(aaa,self->getArray());
412 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
418 if(!self->getArray())
419 throw INTERP_KERNEL::Exception(msg2);
420 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
421 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> ret=MEDCoupling::DataArrayDouble::Divide(aaa,self->getArray());
422 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret2=self->clone(false);
427 { throw INTERP_KERNEL::Exception(msg); }
431 static PyObject *NewMethWrapCallInitOnlyIfEmptyDictInInput(PyObject *cls, PyObject *args, const char *clsName)
433 if(!PyTuple_Check(args))
435 std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
436 throw INTERP_KERNEL::Exception(oss.str().c_str());
438 PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
439 PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
440 PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
442 PyObject *tmp0(PyTuple_New(1));
443 PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
444 PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
447 if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==0 )
448 {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
449 PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
450 PyObject *tmp3(PyTuple_New(0));
451 PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));