X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling_Swig%2FMEDCouplingTypemaps.i;h=b7a4ade9de7535214b00065a0439b35723c78e16;hb=5b299d506fcc63ff652df59a13f5b082fd45dabf;hp=f0382c2cda99b332ce87ee14b0a34554a92da26d;hpb=1f722cfc504a6acb89bc49272c70694603d2fe04;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index f0382c2cd..b7a4ade9d 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// Copyright (C) 2007-2016 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 @@ -18,9 +18,22 @@ // // Author : Anthony Geay (CEA/DEN) +#ifndef __MEDCOUPLINGTYPEMAPS_I__ +#define __MEDCOUPLINGTYPEMAPS_I__ + #include "MEDCouplingDataArrayTypemaps.i" +#include "MEDCouplingUMesh.hxx" +#include "MEDCouplingCMesh.hxx" +#include "MEDCouplingIMesh.hxx" +#include "MEDCouplingCurveLinearMesh.hxx" +#include "MEDCouplingMappedExtrudedMesh.hxx" +#include "MEDCoupling1GTUMesh.hxx" +#include "MEDCouplingFieldDiscretization.hxx" +#include "MEDCouplingMultiFields.hxx" +#include "MEDCouplingPartDefinition.hxx" +#include "MEDCouplingCartesianAMRMesh.hxx" -static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner) { PyObject *ret=0; if(!mesh) @@ -28,26 +41,26 @@ static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw 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(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCoupling1SGTUMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCoupling1DGTUMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingMappedExtrudedMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingCMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__MEDCouplingCurveLinearMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_MEDCoupling__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) +static PyObject *convertFieldDiscretization(MEDCoupling::MEDCouplingFieldDiscretization *fd, int owner) { PyObject *ret=0; if(!fd) @@ -55,22 +68,41 @@ static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscreti 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(dynamic_cast(fd)) + ret=SWIG_NewPointerObj(reinterpret_cast(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationP0,owner); + if(dynamic_cast(fd)) + ret=SWIG_NewPointerObj(reinterpret_cast(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationP1,owner); + if(dynamic_cast(fd)) + ret=SWIG_NewPointerObj(reinterpret_cast(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationGauss,owner); + if(dynamic_cast(fd)) + ret=SWIG_NewPointerObj(reinterpret_cast(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationGaussNE,owner); + if(dynamic_cast(fd)) + ret=SWIG_NewPointerObj(reinterpret_cast(fd),SWIGTYPE_p_MEDCoupling__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) +static PyObject *convertField(MEDCoupling::MEDCouplingField *f, int owner) +{ + PyObject *ret(NULL); + if(!f) + { + Py_XINCREF(Py_None); + return Py_None; + } + if(dynamic_cast(f)) + ret=SWIG_NewPointerObj(reinterpret_cast(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,owner); + if(dynamic_cast(f)) + ret=SWIG_NewPointerObj(reinterpret_cast(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldInt,owner); + if(dynamic_cast(f)) + ret=SWIG_NewPointerObj(reinterpret_cast(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldFloat,owner); + if(!ret) + throw INTERP_KERNEL::Exception("Not recognized type of field on downcast !"); + return ret; +} + +static PyObject* convertMultiFields(MEDCoupling::MEDCouplingMultiFields *mfs, int owner) { PyObject *ret=0; if(!mfs) @@ -78,22 +110,72 @@ static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int Py_XINCREF(Py_None); return Py_None; } - if(dynamic_cast(mfs)) - ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner); + if(dynamic_cast(mfs)) + ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldOverTime,owner); else - ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner); + ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_MEDCoupling__MEDCouplingMultiFields,owner); return ret; } -static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +static PyObject *convertCartesianAMRMesh(MEDCoupling::MEDCouplingCartesianAMRMeshGen *mesh, int owner) +{ + if(!mesh) + { + Py_XINCREF(Py_None); + return Py_None; + } + if(dynamic_cast(mesh)) + { + return SWIG_NewPointerObj(reinterpret_cast(mesh),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRMeshSub,owner); + } + if(dynamic_cast(mesh)) + { + return SWIG_NewPointerObj(reinterpret_cast(mesh),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRMesh,owner); + } + throw INTERP_KERNEL::Exception("convertCartesianAMRMesh wrap : unrecognized type of cartesian AMR mesh !"); +} + +static PyObject *convertDataForGodFather(MEDCoupling::MEDCouplingDataForGodFather *data, int owner) +{ + if(!data) + { + Py_XINCREF(Py_None); + return Py_None; + } + if(dynamic_cast(data)) + { + return SWIG_NewPointerObj(reinterpret_cast(data),SWIGTYPE_p_MEDCoupling__MEDCouplingAMRAttribute,owner); + } + throw INTERP_KERNEL::Exception("convertDataForGodFather wrap : unrecognized data type for AMR !"); +} + +static PyObject *convertCartesianAMRPatch(MEDCoupling::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_MEDCoupling__MEDCouplingCartesianAMRPatchGF,owner); + } + if(dynamic_cast(patch)) + { + return SWIG_NewPointerObj(reinterpret_cast(patch),SWIGTYPE_p_MEDCoupling__MEDCouplingCartesianAMRPatch,owner); + } + throw INTERP_KERNEL::Exception("convertCartesianAMRPatch wrap : unrecognized type of cartesian AMR patch !"); +} + +static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___add__Impl(MEDCoupling::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))) + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0))) { - ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp); if(other) return (*self)+(*other); else @@ -101,20 +183,20 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___a } // double val; - ParaMEDMEM::DataArrayDouble *a; - ParaMEDMEM::DataArrayDoubleTuple *aa; + MEDCoupling::DataArrayDouble *a; + MEDCoupling::DataArrayDoubleTuple *aa; std::vector bb; int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + MEDCoupling::MCAuto ret=self->getArray()->deepCopy(); ret->applyLin(1.,val); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -122,8 +204,8 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___a { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),a); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),a); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -131,9 +213,9 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___a { 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); + MEDCoupling::MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),aaa); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -141,9 +223,9 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___a { 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); + MEDCoupling::MCAuto aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size()); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Add(self->getArray(),aaa); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -152,20 +234,20 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___a } } -static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___radd__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) { - return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj); + return MEDCoupling_MEDCouplingFieldDouble___add__Impl(self,obj); } -static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rsub__Impl(MEDCoupling::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))) + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0))) { - ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp); if(other) return (*other)-(*self); else @@ -173,20 +255,20 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___r } // double val; - ParaMEDMEM::DataArrayDouble *a; - ParaMEDMEM::DataArrayDoubleTuple *aa; + MEDCoupling::DataArrayDouble *a; + MEDCoupling::DataArrayDoubleTuple *aa; std::vector bb; int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + MEDCoupling::MCAuto ret=self->getArray()->deepCopy(); ret->applyLin(-1.,val); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -194,8 +276,8 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___r { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Substract(a,self->getArray()); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Substract(a,self->getArray()); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -203,9 +285,9 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___r { 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); + MEDCoupling::MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Substract(aaa,self->getArray()); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -213,9 +295,9 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___r { 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); + MEDCoupling::MCAuto aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size()); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Substract(aaa,self->getArray()); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -224,15 +306,15 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___r } } -static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +static MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___mul__Impl(MEDCoupling::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))) + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0))) { - ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp); if(other) return (*self)*(*other); else @@ -240,20 +322,20 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___m } // double val; - ParaMEDMEM::DataArrayDouble *a; - ParaMEDMEM::DataArrayDoubleTuple *aa; + MEDCoupling::DataArrayDouble *a; + MEDCoupling::DataArrayDoubleTuple *aa; std::vector bb; int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + MEDCoupling::MCAuto ret=self->getArray()->deepCopy(); ret->applyLin(val,0.); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -261,8 +343,8 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___m { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),a); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),a); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -270,9 +352,9 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___m { 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); + MEDCoupling::MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),aaa); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -280,9 +362,9 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___m { 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); + MEDCoupling::MCAuto aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size()); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Multiply(self->getArray(),aaa); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -291,20 +373,20 @@ static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___m } } -ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rmul__Impl(MEDCoupling::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) { - return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj); + return MEDCoupling_MEDCouplingFieldDouble___mul__Impl(self,obj); } -ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +MEDCoupling::MEDCouplingFieldDouble *MEDCoupling_MEDCouplingFieldDouble___rdiv__Impl(MEDCoupling::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))) + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,0|0))) { - ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + MEDCoupling::MEDCouplingFieldDouble *other=reinterpret_cast< MEDCoupling::MEDCouplingFieldDouble * >(argp); if(other) return (*other)/(*self); else @@ -312,20 +394,20 @@ ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Im } // double val; - ParaMEDMEM::DataArrayDouble *a; - ParaMEDMEM::DataArrayDoubleTuple *aa; + MEDCoupling::DataArrayDouble *a; + MEDCoupling::DataArrayDoubleTuple *aa; std::vector bb; int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + MEDCoupling::MCAuto ret=self->getArray()->deepCopy(); ret->applyInv(val); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -333,8 +415,8 @@ ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Im { if(!self->getArray()) throw INTERP_KERNEL::Exception(msg2); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Divide(a,self->getArray()); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Divide(a,self->getArray()); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -342,9 +424,9 @@ ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Im { 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); + MEDCoupling::MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Divide(aaa,self->getArray()); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -352,9 +434,9 @@ ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Im { 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); + MEDCoupling::MCAuto aaa=MEDCoupling::DataArrayDouble::New(); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size()); + MEDCoupling::MCAuto ret=MEDCoupling::DataArrayDouble::Divide(aaa,self->getArray()); + MEDCoupling::MCAuto ret2=self->clone(false); ret2->setArray(ret); return ret2.retn(); } @@ -362,3 +444,249 @@ ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Im { throw INTERP_KERNEL::Exception(msg); } } } + +template +typename MEDCoupling::Traits::FieldType *fieldT_buildSubPart(const MEDCoupling::MEDCouplingFieldT *self, PyObject *li) +{ + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + MEDCoupling::DataArrayInt *daIntTyypp=0; + const MEDCoupling::MEDCouplingMesh *mesh=self->getMesh(); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : field lies on a null mesh !"); + int nbc=mesh->getNumberOfCells(); + convertIntStarOrSliceLikePyObjToCpp(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + { + if(singleVal>=nbc) + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(singleVal>=0) + return self->buildSubPart(&singleVal,&singleVal+1); + else + { + if(nbc+singleVal>0) + { + int tmp=nbc+singleVal; + return self->buildSubPart(&tmp,&tmp+1); + } + else + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } + case 2: + { + return self->buildSubPart(&multiVal[0],&multiVal[0]+multiVal.size()); + } + case 3: + { + return self->buildSubPartRange(slic.first,slic.second.first,slic.second.second); + } + case 4: + { + if(!daIntTyypp) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : null instance has been given in input !"); + daIntTyypp->checkAllocated(); + return self->buildSubPart(daIntTyypp->begin(),daIntTyypp->end()); + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayInt instance !"); + } +} + +template +typename MEDCoupling::Traits::FieldType *fieldT__getitem__(const MEDCoupling::MEDCouplingFieldT *self, PyObject *li) +{ + const char msg[]="MEDCouplingFieldDouble::__getitem__ : invalid call Available API are : \n-myField[dataArrayInt]\n-myField[slice]\n-myField[pythonListOfCellIds]\n-myField[integer]\n-myField[dataArrayInt,1]\n-myField[slice,1]\n-myField[pythonListOfCellIds,1]\n-myField[integer,1]\n"; + if(PyTuple_Check(li)) + { + Py_ssize_t sz=PyTuple_Size(li); + if(sz!=2) + throw INTERP_KERNEL::Exception(msg); + PyObject *elt0=PyTuple_GetItem(li,0),*elt1=PyTuple_GetItem(li,1); + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + MEDCoupling::DataArrayInt *daIntTyypp=0; + if(!self->getArray()) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array set on field to deduce number of components !"); + try + { convertIntStarOrSliceLikePyObjToCpp(elt1,self->getArray()->getNumberOfComponents(),sw,singleVal,multiVal,slic,daIntTyypp); } + catch(INTERP_KERNEL::Exception& e) + { std::ostringstream oss; oss << "MEDCouplingFieldDouble::__getitem__ : invalid type in 2nd parameter (compo) !" << e.what(); throw INTERP_KERNEL::Exception(oss.str().c_str()); } + typename MEDCoupling::MCAuto< typename MEDCoupling::Traits::FieldType > ret0(fieldT_buildSubPart(self,elt0)); + typename MEDCoupling::Traits::ArrayType *ret0Arr=ret0->getArray(); + if(!ret0Arr) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array exists to apply restriction on component on it !"); + switch(sw) + { + case 1: + { + std::vector v2(1,singleVal); + MEDCoupling::MCAuto< typename MEDCoupling::Traits::ArrayType > aarr(ret0Arr->keepSelectedComponents(v2)); + ret0->setArray(aarr); + return ret0.retn(); + } + case 2: + { + MEDCoupling::MCAuto< typename MEDCoupling::Traits::ArrayType > aarr(ret0Arr->keepSelectedComponents(multiVal)); + ret0->setArray(aarr); + return ret0.retn(); + } + case 3: + { + int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(slic.first,slic.second.first,slic.second.second,"MEDCouplingFieldDouble::__getitem__ : invalid range in 2nd parameter (components) !")); + std::vector v2(nbOfComp); + for(int i=0;i::ArrayType > aarr(ret0Arr->keepSelectedComponents(v2)); + ret0->setArray(aarr); + return ret0.retn(); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + else + return fieldT_buildSubPart(self,li); +} + +template +PyObject *field_getTinySerializationInformation(const FIELDT *self) +{ + std::vector a0; + std::vector a1; + std::vector a2; + self->getTinySerializationDbleInformation(a0); + self->getTinySerializationIntInformation(a1); + self->getTinySerializationStrInformation(a2); + // + PyObject *ret(PyTuple_New(3)); + PyTuple_SetItem(ret,0,convertDblArrToPyList2(a0)); + PyTuple_SetItem(ret,1,convertIntArrToPyList2(a1)); + int sz(a2.size()); + PyObject *ret2(PyList_New(sz)); + { + for(int i=0;i +PyObject *field_serialize(const typename MEDCoupling::Traits::FieldType *self) +{ + MEDCoupling::DataArrayInt *ret0(0); + std::vector::ArrayType *> ret1; + self->serialize(ret0,ret1); + if(ret0) + ret0->incrRef(); + std::size_t sz(ret1.size()); + PyObject *ret(PyTuple_New(2)); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyObject *ret1Py(PyList_New(sz)); + for(std::size_t i=0;iincrRef(); + PyList_SetItem(ret1Py,i,convertArray(ret1[i],SWIG_POINTER_OWN | 0)); + } + PyTuple_SetItem(ret,1,ret1Py); + return ret; +} + +template +PyObject *field__getnewargs__(FIELDT *self) +{ + self->checkConsistencyLight(); + PyObject *ret(PyTuple_New(1)); + PyObject *ret0(PyDict_New()); + { + PyObject *a(PyInt_FromLong(0)),*b(PyInt_FromLong(self->getTypeOfField())),*c(PyInt_FromLong(self->getTimeDiscretization())); + PyObject *d(PyTuple_New(2)); PyTuple_SetItem(d,0,b); PyTuple_SetItem(d,1,c); + PyDict_SetItem(ret0,a,d); + Py_DECREF(a); Py_DECREF(d); + } + PyTuple_SetItem(ret,0,ret0); + return ret; +} + +template +PyObject *field__getstate__(const FIELDT *self, PyObject *(*tinyserial)(const FIELDT *), PyObject *(*bigserial)(const FIELDT *)) +{ + self->checkConsistencyLight(); + PyObject *ret0(tinyserial(self)); + PyObject *ret1(bigserial(self)); + const MEDCoupling::MEDCouplingMesh *mesh(self->getMesh()); + if(mesh) + mesh->incrRef(); + PyObject *ret(PyTuple_New(3)); + PyTuple_SetItem(ret,0,ret0); + PyTuple_SetItem(ret,1,ret1); + PyTuple_SetItem(ret,2,convertMesh(const_cast(mesh),SWIG_POINTER_OWN | 0 )); + return ret; +} + +template +void field__setstate__(typename MEDCoupling::Traits::FieldType *self, PyObject *inp) +{ + static const char MSG[]="MEDCouplingFieldDouble.__setstate__ : expected input is a tuple of size 3 !"; + if(!PyTuple_Check(inp)) + throw INTERP_KERNEL::Exception(MSG); + int sz(PyTuple_Size(inp)); + if(sz!=3) + throw INTERP_KERNEL::Exception(MSG); + // mesh + PyObject *elt2(PyTuple_GetItem(inp,2)); + void *argp=0; + int status(SWIG_ConvertPtr(elt2,&argp,SWIGTYPE_p_MEDCoupling__MEDCouplingMesh,0|0)); + if(!SWIG_IsOK(status)) + throw INTERP_KERNEL::Exception(MSG); + self->setMesh(reinterpret_cast< const MEDCoupling::MEDCouplingMesh * >(argp)); + // + PyObject *elt0(PyTuple_GetItem(inp,0)); + PyObject *elt1(PyTuple_GetItem(inp,1)); + std::vector a0; + std::vector a1; + std::vector a2; + MEDCoupling::DataArrayInt *b0(0); + std::vector::ArrayType *>b1; + { + if(!PyTuple_Check(elt0) && PyTuple_Size(elt0)!=3) + throw INTERP_KERNEL::Exception(MSG); + PyObject *a0py(PyTuple_GetItem(elt0,0)),*a1py(PyTuple_GetItem(elt0,1)),*a2py(PyTuple_GetItem(elt0,2)); + int tmp(-1); + fillArrayWithPyListDbl3(a0py,tmp,a0); + convertPyToNewIntArr3(a1py,a1); + fillStringVector(a2py,a2); + } + { + if(!PyTuple_Check(elt1) && PyTuple_Size(elt1)!=2) + throw INTERP_KERNEL::Exception(MSG); + PyObject *b0py(PyTuple_GetItem(elt1,0)),*b1py(PyTuple_GetItem(elt1,1)); + void *argp(0); + int status(SWIG_ConvertPtr(b0py,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0)); + if(!SWIG_IsOK(status)) + throw INTERP_KERNEL::Exception(MSG); + b0=reinterpret_cast(argp); + convertFromPyObjVectorOfObj::ArrayType *>(b1py,SWIGTITraits::TI,MEDCoupling::Traits::ArrayTypeName,b1); + } + self->checkForUnserialization(a1,b0,b1); + // useless here to call resizeForUnserialization because arrays are well resized. + self->finishUnserialization(a1,a0,a2); +} + +#endif