From: Anthony Geay Date: Wed, 24 Aug 2016 11:37:15 +0000 (+0200) Subject: Simplification of API of MEDFileIntField1TS and MEDFileIntFieldMultiTS X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5d734ab6afae8982126268e1381a44abba99992f;p=tools%2Fmedcoupling.git Simplification of API of MEDFileIntField1TS and MEDFileIntFieldMultiTS --- diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index e7c824d0c..8afb7a54f 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -21,6 +21,7 @@ #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingFieldT.txx" +#include "MEDCouplingFieldInt.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingTimeDiscretization.hxx" #include "MEDCouplingFieldDiscretization.hxx" @@ -662,14 +663,19 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPartRange(int begin, int return ret.retn(); } -/*! - * Returns a type of \ref MEDCouplingTemporalDisc "time discretization" of \a this field. - * \return MEDCoupling::TypeOfTimeDiscretization - an enum item describing the time - * discretization type. - */ -TypeOfTimeDiscretization MEDCouplingFieldDouble::getTimeDiscretization() const +MEDCouplingFieldInt *MEDCouplingFieldDouble::convertToIntField() const { - return timeDiscr()->getEnum(); + MCAuto tmp(MEDCouplingFieldTemplate::New(*this)); + int t1,t2; + double t0(getTime(t1,t2)); + MCAuto ret(MEDCouplingFieldInt::New(*tmp,getTimeDiscretization())); + ret->setTime(t0,t1,t2); + if(getArray()) + { + MCAuto arr(getArray()->convertToIntArr()); + ret->setArray(arr); + } + return ret.retn(); } MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingFieldT(type,MEDCouplingTimeDiscretization::New(td)) diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 871a0d5fa..4012646c4 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -27,6 +27,7 @@ namespace MEDCoupling { + class MEDCouplingFieldInt; class MEDCouplingFieldTemplate; class MEDCouplingFieldDouble : public MEDCouplingFieldT @@ -52,7 +53,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *nodeToCellDiscretization() const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *cellToNodeDiscretization() const; - MEDCOUPLING_EXPORT TypeOfTimeDiscretization getTimeDiscretization() const; + MEDCOUPLING_EXPORT MEDCouplingFieldInt *convertToIntField() const; MEDCOUPLING_EXPORT double getIJK(int cellId, int nodeIdInCell, int compoId) const; MEDCOUPLING_EXPORT double accumulate(int compId) const; MEDCOUPLING_EXPORT void accumulate(double *res) const; diff --git a/src/MEDCoupling/MEDCouplingFieldInt.cxx b/src/MEDCoupling/MEDCouplingFieldInt.cxx index 1f8d91197..f6b6fa297 100644 --- a/src/MEDCoupling/MEDCouplingFieldInt.cxx +++ b/src/MEDCoupling/MEDCouplingFieldInt.cxx @@ -20,6 +20,7 @@ #include "MEDCouplingFieldInt.hxx" #include "MEDCouplingFieldT.txx" +#include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingMesh.hxx" @@ -65,3 +66,18 @@ MEDCouplingFieldInt *MEDCouplingFieldInt::clone(bool recDeepCpy) const { return new MEDCouplingFieldInt(*this,recDeepCpy); } + +MEDCouplingFieldDouble *MEDCouplingFieldInt::convertToDblField() const +{ + MCAuto tmp(MEDCouplingFieldTemplate::New(*this)); + int t1,t2; + double t0(getTime(t1,t2)); + MCAuto ret(MEDCouplingFieldDouble::New(*tmp,getTimeDiscretization())); + ret->setTime(t0,t1,t2); + if(getArray()) + { + MCAuto arr(getArray()->convertToDblArr()); + ret->setArray(arr); + } + return ret.retn(); +} diff --git a/src/MEDCoupling/MEDCouplingFieldInt.hxx b/src/MEDCoupling/MEDCouplingFieldInt.hxx index 379be04df..60ab3dead 100644 --- a/src/MEDCoupling/MEDCouplingFieldInt.hxx +++ b/src/MEDCoupling/MEDCouplingFieldInt.hxx @@ -29,6 +29,7 @@ namespace MEDCoupling { + class MEDCouplingFieldDouble; class MEDCouplingFieldTemplate; class MEDCouplingFieldInt : public MEDCouplingFieldT @@ -38,6 +39,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT static MEDCouplingFieldInt *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME); MEDCOUPLING_EXPORT MEDCouplingFieldInt *deepCopy() const; MEDCOUPLING_EXPORT MEDCouplingFieldInt *clone(bool recDeepCpy) const; + MEDCOUPLING_EXPORT MEDCouplingFieldDouble *convertToDblField() const; protected: MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td); MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy); diff --git a/src/MEDCoupling/MEDCouplingFieldT.hxx b/src/MEDCoupling/MEDCouplingFieldT.hxx index 71e6bda3e..66f7843e9 100644 --- a/src/MEDCoupling/MEDCouplingFieldT.hxx +++ b/src/MEDCoupling/MEDCouplingFieldT.hxx @@ -42,6 +42,7 @@ namespace MEDCoupling MEDCouplingFieldT(MEDCouplingFieldDiscretization *type, NatureOfField n, MEDCouplingTimeDiscretizationTemplate *timeDiscr); ~MEDCouplingFieldT(); public: + MEDCOUPLING_EXPORT TypeOfTimeDiscretization getTimeDiscretization() const; MEDCOUPLING_EXPORT virtual typename Traits::FieldType *clone(bool recDeepCpy) const = 0; MEDCOUPLING_EXPORT void checkConsistencyLight() const; MEDCOUPLING_EXPORT typename Traits::FieldType *cloneWithMesh(bool recDeepCpy) const; diff --git a/src/MEDCoupling/MEDCouplingFieldT.txx b/src/MEDCoupling/MEDCouplingFieldT.txx index 9b1d82f48..6df99f351 100644 --- a/src/MEDCoupling/MEDCouplingFieldT.txx +++ b/src/MEDCoupling/MEDCouplingFieldT.txx @@ -356,6 +356,17 @@ namespace MEDCoupling } } } + + /*! + * Returns a type of \ref MEDCouplingTemporalDisc "time discretization" of \a this field. + * \return MEDCoupling::TypeOfTimeDiscretization - an enum item describing the time + * discretization type. + */ + template + TypeOfTimeDiscretization MEDCouplingFieldT::getTimeDiscretization() const + { + return _time_discr->getEnum(); + } } #endif diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 27e421491..eebe898c7 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -184,6 +184,7 @@ using namespace INTERP_KERNEL; %newobject MEDCoupling::MEDCouplingFieldDouble::getEndArray; %newobject MEDCoupling::MEDCouplingFieldDouble::MergeFields; %newobject MEDCoupling::MEDCouplingFieldDouble::MeldFields; +%newobject MEDCoupling::MEDCouplingFieldDouble::convertToIntField; %newobject MEDCoupling::MEDCouplingFieldDouble::doublyContractedProduct; %newobject MEDCoupling::MEDCouplingFieldDouble::determinant; %newobject MEDCoupling::MEDCouplingFieldDouble::eigenValues; @@ -230,6 +231,7 @@ using namespace INTERP_KERNEL; %newobject MEDCoupling::MEDCouplingFieldDouble::cellToNodeDiscretization; %newobject MEDCoupling::MEDCouplingFieldDouble::getValueOnMulti; %newobject MEDCoupling::MEDCouplingFieldInt::New; +%newobject MEDCoupling::MEDCouplingFieldInt::convertToDblField; %newobject MEDCoupling::MEDCouplingFieldInt::getArray; %newobject MEDCoupling::MEDCouplingFieldInt::deepCopy; %newobject MEDCoupling::MEDCouplingFieldInt::clone; @@ -3776,6 +3778,8 @@ namespace MEDCoupling } }; + class MEDCouplingFieldInt; + class MEDCouplingFieldDouble : public MEDCoupling::MEDCouplingField { public: @@ -3789,6 +3793,7 @@ namespace MEDCoupling std::string simpleRepr() const throw(INTERP_KERNEL::Exception); std::string advancedRepr() const throw(INTERP_KERNEL::Exception); std::string writeVTK(const std::string& fileName, bool isBinary=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *convertToIntField() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *clone(bool recDeepCpy) const; MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const; MEDCouplingFieldDouble *deepCopy() const; @@ -5191,6 +5196,7 @@ namespace MEDCoupling MEDCouplingFieldInt *deepCopy() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldInt *clone(bool recDeepCpy) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldInt *cloneWithMesh(bool recDeepCpy) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *convertToDblField() const throw(INTERP_KERNEL::Exception); %extend { MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME) { diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 3162a357d..b770def51 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -6400,9 +6400,9 @@ void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAut { if(!f) throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !"); - if(!((DataArray*)arr)) + if(arr.isNull()) throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !"); - DataArrayDouble *arrOutC=dynamic_cast((DataArray*)arr); + DataArrayDouble *arrOutC(dynamic_cast((DataArray*)arr)); if(!arrOutC) throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !"); f->setArray(arrOutC); @@ -6410,9 +6410,9 @@ void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAut DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto& arr) { - if(!((DataArray*)arr)) + if(arr.isNull()) throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !"); - DataArrayDouble *arrOutC=dynamic_cast((DataArray*)arr); + DataArrayDouble *arrOutC(dynamic_cast((DataArray*)arr)); if(!arrOutC) throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !"); arrOutC->incrRef(); @@ -6986,25 +6986,21 @@ const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const return ret; } -MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const { if(getFileName().empty()) throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); - MCAuto arrOut2; - MCAuto ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull()); - DataArrayInt *arrOutC=dynamic_cast((DataArray *)arrOut2); - if(!arrOutC) - throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !"); - arrOut=arrOutC; - arrOut->incrRef(); // arrOut2 dies at the end of the func - return ret.retn(); + MCAuto arrOut; + MCAuto ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull())); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); } DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto& arr) { if(arr.isNull()) throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !"); - DataArrayInt *arrC=dynamic_cast((DataArray *)arr); + DataArrayInt *arrC(dynamic_cast((DataArray *)arr)); if(!arrC) throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !"); arrC->incrRef(); @@ -7057,12 +7053,11 @@ MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const } /*! - * Returns a new MEDCouplingFieldDouble of a given type lying on + * Returns a new MEDCouplingFieldInt of a given type lying on * the top level cells of the first mesh in MED file. If \a this field * has not been constructed via file reading, an exception is thrown. * For more info, see \ref AdvMEDLoaderAPIFieldRW * \param [in] type - a spatial discretization of interest. - * \param [out] arrOut - the DataArrayInt containing values of field. * \param [in] renumPol - specifies how to permute values of the result field according to * the optional numbers of cells and nodes, if any. The valid values are * - 0 - do not permute. @@ -7070,7 +7065,7 @@ MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const * - 2 - permute nodes. * - 3 - permute cells and nodes. * - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The * caller is to delete this field using decrRef() as it is no more needed. * \throw If \a this field has not been constructed via file reading. * \throw If the MED file is not readable. @@ -7079,22 +7074,21 @@ MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const * \throw If no field values lying on the top level support. * \sa getFieldAtLevel() */ -MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const { if(getFileName().empty()) throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !"); - MCAuto arr; - MCAuto ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + MCAuto arrOut; + MCAuto ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull())); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); } /*! - * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh. + * Returns a new MEDCouplingFieldInt of given type lying on a given mesh. * For more info, see \ref AdvMEDLoaderAPIFieldRW * \param [in] type - a spatial discretization of the new field. * \param [in] mesh - the supporting mesh. - * \param [out] arrOut - the DataArrayInt containing values of field. * \param [in] renumPol - specifies how to permute values of the result field according to * the optional numbers of cells and nodes, if any. The valid values are * - 0 - do not permute. @@ -7102,7 +7096,7 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, * - 2 - permute nodes. * - 3 - permute cells and nodes. * - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The * caller is to delete this field using decrRef() as it is no more needed. * \throw If no field of \a this is lying on \a mesh. * \throw If the mesh is empty. @@ -7110,20 +7104,19 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, * \sa getFieldAtLevel() * \sa getFieldOnMeshAtLevel() */ -MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const { - MCAuto arr; - MCAuto ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + MCAuto arrOut; + MCAuto ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull())); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); } /*! - * Returns a new MEDCouplingFieldDouble of a given type lying on a given support. + * Returns a new MEDCouplingFieldInt of a given type lying on a given support. * For more info, see \ref AdvMEDLoaderAPIFieldRW * \param [in] type - a spatial discretization of interest. * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities. - * \param [out] arrOut - the DataArrayInt containing values of field. * \param [in] mesh - the supporting mesh. * \param [in] renumPol - specifies how to permute values of the result field according to * the optional numbers of cells and nodes, if any. The valid values are @@ -7132,7 +7125,7 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField ty * - 2 - permute nodes. * - 3 - permute cells and nodes. * - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The * caller is to delete this field using decrRef() as it is no more needed. * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh. * \throw If no field of \a this is lying on \a mesh. @@ -7140,12 +7133,12 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField ty * \sa getFieldAtLevel() * \sa getFieldOnMeshAtLevel() */ -MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const { - MCAuto arr; - MCAuto ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + MCAuto arrOut; + MCAuto ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull())); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); } /*! @@ -7157,7 +7150,6 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField ty * \param [in] type - a spatial discretization of interest. * \param [in] mName - a name of the supporting mesh. * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities. - * \param [out] arrOut - the DataArrayInt containing values of field. * \param [in] renumPol - specifies how to permute values of the result field according to * the optional numbers of cells and nodes, if any. The valid values are * - 0 - do not permute. @@ -7165,7 +7157,7 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField ty * - 2 - permute nodes. * - 3 - permute cells and nodes. * - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The * caller is to delete this field using decrRef() as it is no more needed. * \throw If the MED file is not readable. * \throw If there is no mesh named \a mName in the MED file. @@ -7175,14 +7167,14 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField ty * \throw If no field values of the given \a type or given \a meshDimRelToMax are available. * \sa getFieldAtLevel() */ -MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const { if(getFileName().empty()) - throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); - MCAuto arr; - MCAuto ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); + MCAuto arrOut; + MCAuto ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); } /*! diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 9a3da283e..ff5391513 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -778,11 +778,11 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileAnyTypeField1TS *shallowCpy() const; // MEDLOADER_EXPORT MEDCouplingFieldInt *field(const MEDFileMesh *mesh) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol=0) const; MEDLOADER_EXPORT DataArrayInt *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const; // MEDLOADER_EXPORT void setFieldNoProfileSBT(const MEDCouplingFieldInt *field); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 3944fbb22..6d7867e47 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -187,6 +187,10 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileIntField1TS::New; %newobject MEDCoupling::MEDFileIntField1TS::field; +%newobject MEDCoupling::MEDFileIntField1TS::getFieldAtLevel; +%newobject MEDCoupling::MEDFileIntField1TS::getFieldAtTopLevel; +%newobject MEDCoupling::MEDFileIntField1TS::getFieldOnMeshAtLevel; +%newobject MEDCoupling::MEDFileIntField1TS::getFieldAtLevelOld; %newobject MEDCoupling::MEDFileIntField1TS::getUndergroundDataArray; %newobject MEDCoupling::MEDFileIntField1TS::convertToDouble; @@ -2136,6 +2140,11 @@ namespace MEDCoupling void setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); void setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); MEDCouplingFieldInt *field(const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); %extend { MEDFileIntField1TS() throw(INTERP_KERNEL::Exception) @@ -2163,56 +2172,6 @@ namespace MEDCoupling return self->simpleRepr(); } - PyObject *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldAtLevel(type,meshDimRelToMax,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldAtTopLevel(type,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldOnMeshAtLevel(type,meshDimRelToMax,mesh,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldOnMeshAtLevel(type,mesh,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldAtLevelOld(type,mname,meshDimRelToMax,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - PyObject *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception) { DataArrayInt *ret1=0; diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 0471aa4b0..3b3823e80 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -2578,8 +2578,7 @@ class MEDLoaderTest3(unittest.TestCase): def testInt32InMEDFileFieldStar1(self): fname="Pyfile63.med" f1=MEDLoaderDataForTest.buildVecFieldOnCells_1(); - arr=f1.getArray().convertToIntArr() - f1.setArray(None) + f1=f1.convertToIntField() m1=f1.getMesh() mm1=MEDFileUMesh.New() mm1.setCoords(m1.getCoords()) @@ -2587,19 +2586,17 @@ class MEDLoaderTest3(unittest.TestCase): mm1.setName(m1.getName()) mm1.write(fname,2) ff1=MEDFileIntField1TS() - ff1.setFieldNoProfileSBT(f1,arr) - a,b=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - self.assertEqual(b.getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]']) - self.assertTrue(b.isEqual(arr)) + ff1.setFieldNoProfileSBT(f1) + a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) + self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]']) self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ff1.write(fname,0) ff2=MEDFileAnyTypeField1TS.New(fname) self.assertEqual(ff2.getName(),"VectorFieldOnCells") self.assertEqual(ff2.getTime(),[0,1,2.0]) self.assertTrue(isinstance(ff2,MEDFileIntField1TS)) - a,b=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - self.assertEqual(b.getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]']) - self.assertTrue(b.isEqual(arr)) + a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) + self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]']) self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ff2.setTime(1,2,3.) c=ff2.getUndergroundDataArray() ; c*=2 @@ -2608,23 +2605,21 @@ class MEDLoaderTest3(unittest.TestCase): self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)]) self.assertEqual(len(ffs1),2) self.assertTrue(isinstance(ffs1,MEDFileIntFieldMultiTS)) - a,b=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - self.assertTrue(b.isEqual(arr)) + a=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1) self.assertTrue(a.isEqual(f1,1e-12,1e-12)) - a,b=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - self.assertTrue(b.isEqual(arr)) + a=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1) self.assertTrue(a.isEqual(f1,1e-12,1e-12)) it=ffs1.__iter__() ; it.next() ; ff2bis=it.next() - a,b=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - self.assertTrue(b.isEqual(2*arr)) - f1.setTime(3.,1,2) - self.assertTrue(a.isEqual(f1,1e-12,1e-12)) + a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) + self.assertTrue(a.getArray().isEqual(2*f1.getArray())) + f1.setTime(3.,1,2) ; f1.getArray()[:]*=2 + self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ; f1.getArray()[:]/=2 bc=DataArrayInt(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]']) for it in ffs1: - a,b=it.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - bc+=b + a=it.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) + bc+=a.getArray() pass - self.assertTrue(bc.isEqual(3*arr)) + self.assertTrue(bc.isEqual(3*f1.getArray())) nf1=MEDCouplingFieldDouble(ON_NODES) nf1.setTime(9.,10,-1) nf1.setMesh(f1.getMesh()) @@ -2670,8 +2665,8 @@ class MEDLoaderTest3(unittest.TestCase): self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS)) self.assertTrue(isinstance(ffs[3],MEDFileIntFieldMultiTS)) # - self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(arr)) - self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*arr)) + self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray())) + self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray())) self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2)) self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr)) self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12)) @@ -5120,8 +5115,8 @@ class MEDLoaderTest3(unittest.TestCase): self.assertEqual(pfltest.getName(),pflName) self.assertEqual(ftest.getName(),fieldName) self.assertTrue(ftest.isEqualWithoutConsideringStr(arr)) - ftest2,vals=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm) - self.assertTrue(vals.isEqualWithoutConsideringStr(arr)) + ftest2=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm) + self.assertTrue(ftest2.getArray().isEqualWithoutConsideringStr(arr)) self.assertEqual(ftest2.getTime(),f.getTime()) self.assertEqual(ftest2.getMesh().getNumberOfCells(),len(arr)) pass