// Copyright (C) 2007-2015 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // Author : Anthony Geay (CEA/DEN) #include "MEDCouplingDataArrayTypemaps.i" static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; if(!mesh) { Py_XINCREF(Py_None); return Py_None; } if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCoupling1SGTUMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCoupling1DGTUMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingIMesh,owner); if(!ret) throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !"); return ret; } static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; if(!fd) { Py_XINCREF(Py_None); return Py_None; } if(dynamic_cast(fd)) ret=SWIG_NewPointerObj(reinterpret_cast(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner); if(dynamic_cast(fd)) ret=SWIG_NewPointerObj(reinterpret_cast(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner); if(dynamic_cast(fd)) ret=SWIG_NewPointerObj(reinterpret_cast(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner); if(dynamic_cast(fd)) ret=SWIG_NewPointerObj(reinterpret_cast(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner); if(dynamic_cast(fd)) ret=SWIG_NewPointerObj(reinterpret_cast(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner); if(!ret) throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !"); return ret; } static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; if(!mfs) { Py_XINCREF(Py_None); return Py_None; } if(dynamic_cast(mfs)) ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner); else ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner); return ret; } static PyObject *convertPartDefinition(ParaMEDMEM::PartDefinition *pd, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; if(!pd) { Py_XINCREF(Py_None); return Py_None; } if(dynamic_cast(pd)) ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_ParaMEDMEM__DataArrayPartDefinition,owner); else ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_ParaMEDMEM__SlicePartDefinition,owner); return ret; } static PyObject *convertCartesianAMRMesh(ParaMEDMEM::MEDCouplingCartesianAMRMeshGen *mesh, int owner) throw(INTERP_KERNEL::Exception) { if(!mesh) { Py_XINCREF(Py_None); return Py_None; } if(dynamic_cast(mesh)) { return SWIG_NewPointerObj(reinterpret_cast(mesh),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCartesianAMRMeshSub,owner); } if(dynamic_cast(mesh)) { return SWIG_NewPointerObj(reinterpret_cast(mesh),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCartesianAMRMesh,owner); } throw INTERP_KERNEL::Exception("convertCartesianAMRMesh wrap : unrecognized type of cartesian AMR mesh !"); } static PyObject *convertDataForGodFather(ParaMEDMEM::MEDCouplingDataForGodFather *data, int owner) throw(INTERP_KERNEL::Exception) { if(!data) { Py_XINCREF(Py_None); return Py_None; } if(dynamic_cast(data)) { return SWIG_NewPointerObj(reinterpret_cast(data),SWIGTYPE_p_ParaMEDMEM__MEDCouplingAMRAttribute,owner); } throw INTERP_KERNEL::Exception("convertDataForGodFather wrap : unrecognized data type for AMR !"); } static PyObject *convertCartesianAMRPatch(ParaMEDMEM::MEDCouplingCartesianAMRPatchGen *patch, int owner) throw(INTERP_KERNEL::Exception) { if(!patch) { Py_XINCREF(Py_None); return Py_None; } if(dynamic_cast(patch)) { return SWIG_NewPointerObj(reinterpret_cast(patch),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCartesianAMRPatchGF,owner); } if(dynamic_cast(patch)) { return SWIG_NewPointerObj(reinterpret_cast(patch),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCartesianAMRPatch,owner); } throw INTERP_KERNEL::Exception("convertCartesianAMRPatch wrap : unrecognized type of cartesian AMR patch !"); } static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) { 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."; const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !"; void *argp; // if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) { ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); if(other) return (*self)+(*other); else throw INTERP_KERNEL::Exception(msg); } // double val; ParaMEDMEM::DataArrayDouble *a; ParaMEDMEM::DataArrayDoubleTuple *aa; std::vector bb; int sw; convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) { case 1: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); ret->applyLin(1.,val); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 2: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),a); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 3: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 4: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } default: { throw INTERP_KERNEL::Exception(msg); } } } static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) { return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj); } static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) { 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."; const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !"; void *argp; // if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) { ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); if(other) return (*other)-(*self); else throw INTERP_KERNEL::Exception(msg); } // double val; ParaMEDMEM::DataArrayDouble *a; ParaMEDMEM::DataArrayDoubleTuple *aa; std::vector bb; int sw; convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) { case 1: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); ret->applyLin(-1.,val); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 2: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Substract(a,self->getArray()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 3: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 4: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } default: { throw INTERP_KERNEL::Exception(msg); } } } static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) { 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."; const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !"; void *argp; // if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) { ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); if(other) return (*self)*(*other); else throw INTERP_KERNEL::Exception(msg); } // double val; ParaMEDMEM::DataArrayDouble *a; ParaMEDMEM::DataArrayDoubleTuple *aa; std::vector bb; int sw; convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) { case 1: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); ret->applyLin(val,0.); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 2: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),a); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 3: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 4: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } default: { throw INTERP_KERNEL::Exception(msg); } } } ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) { return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj); } ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) { 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."; const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !"; void *argp; // if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) { ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); if(other) return (*other)/(*self); else throw INTERP_KERNEL::Exception(msg); } // double val; ParaMEDMEM::DataArrayDouble *a; ParaMEDMEM::DataArrayDoubleTuple *aa; std::vector bb; int sw; convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) { case 1: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); ret->applyInv(val); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 2: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Divide(a,self->getArray()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 3: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } case 4: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray()); ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } default: { throw INTERP_KERNEL::Exception(msg); } } } static PyObject *NewMethWrapCallInitOnlyIfEmptyDictInInput(PyObject *cls, PyObject *args, const char *clsName) { if(!PyTuple_Check(args)) { std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } PyObject *builtinsd(PyEval_GetBuiltins());//borrowed PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__")); // PyObject *tmp0(PyTuple_New(1)); PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls); PyObject *instance(PyObject_CallObject(selfMeth,tmp0)); Py_DECREF(tmp0); Py_DECREF(selfMeth); if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==0 ) {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ ! PyObject *initMeth(PyObject_GetAttrString(instance,"__init__")); PyObject *tmp3(PyTuple_New(0)); PyObject *tmp2(PyObject_CallObject(initMeth,tmp3)); Py_XDECREF(tmp2); Py_DECREF(tmp3); Py_DECREF(initMeth); } return instance; }