From: Anthony Geay Date: Thu, 4 May 2017 14:01:58 +0000 (+0200) Subject: MEDCouplingFieldInt and MEDCouplingFieldFloat are pickelized X-Git-Tag: V8_4_0a1~59 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fagy%2Ffloat32_4;p=tools%2Fmedcoupling.git MEDCouplingFieldInt and MEDCouplingFieldFloat are pickelized --- diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index ef7ead170..504451a71 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -1626,126 +1626,6 @@ double MEDCouplingFieldDouble::getIJK(int cellId, int nodeIdInCell, int compoId) */ //void MEDCouplingFieldDouble::setArrays(const std::vector& arrs) -void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector& tinyInfo) const -{ - tinyInfo.clear(); - timeDiscr()->getTinySerializationStrInformation(tinyInfo); - tinyInfo.push_back(_name); - tinyInfo.push_back(_desc); - tinyInfo.push_back(getTimeUnit()); -} - -/*! - * This method retrieves some critical values to resize and prepare remote instance. - * The first two elements returned in tinyInfo correspond to the parameters to give in constructor. - * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny. - */ -void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector& tinyInfo) const -{ - if(_type.isNull()) - throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !"); - tinyInfo.clear(); - tinyInfo.push_back((int)_type->getEnum()); - tinyInfo.push_back((int)timeDiscr()->getEnum()); - tinyInfo.push_back((int)_nature); - timeDiscr()->getTinySerializationIntInformation(tinyInfo); - std::vector tinyInfo2; - _type->getTinySerializationIntInformation(tinyInfo2); - tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); - tinyInfo.push_back((int)tinyInfo2.size()); -} - -/*! - * This method retrieves some critical values to resize and prepare remote instance. - * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny. - */ -void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector& tinyInfo) const -{ - if(_type.isNull()) - throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !"); - tinyInfo.clear(); - timeDiscr()->getTinySerializationDbleInformation(tinyInfo); - std::vector tinyInfo2; - _type->getTinySerializationDbleInformation(tinyInfo2); - tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); - tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it -} - -/*! - * This method has to be called to the new instance filled by CORBA, MPI, File... - * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied. - * @param dataInt out parameter. If not null the pointer is already owned by \a this after the call of this method. In this case no decrRef must be applied. - * @param arrays out parameter is a vector resized to the right size. The pointers in the vector is already owned by \a this after the call of this method. - * No decrRef must be applied to every instances in returned vector. - * \sa checkForUnserialization - */ -void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector& tinyInfoI, DataArrayInt *&dataInt, std::vector& arrays) -{ - if(_type.isNull()) - throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); - dataInt=0; - std::vector tinyInfoITmp(tinyInfoI); - int sz=tinyInfoITmp.back(); - tinyInfoITmp.pop_back(); - std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); - std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); - timeDiscr()->resizeForUnserialization(tinyInfoI2,arrays); - std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); - _type->resizeForUnserialization(tinyInfoITmp3,dataInt); -} - -/*! - * This method is extremely close to resizeForUnserialization except that here the arrays in \a dataInt and in \a arrays are attached in \a this - * after having checked that size is correct. This method is used in python pickeling context to avoid copy of data. - * \sa resizeForUnserialization - */ -void MEDCouplingFieldDouble::checkForUnserialization(const std::vector& tinyInfoI, const DataArrayInt *dataInt, const std::vector& arrays) -{ - if(_type.isNull()) - throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); - std::vector tinyInfoITmp(tinyInfoI); - int sz=tinyInfoITmp.back(); - tinyInfoITmp.pop_back(); - std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); - std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); - timeDiscr()->checkForUnserialization(tinyInfoI2,arrays); - std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); - _type->checkForUnserialization(tinyInfoITmp3,dataInt); -} - -void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) -{ - if(_type.isNull()) - throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !"); - std::vector tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end()); - // - std::vector tmp(tinyInfoD); - int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it - tmp.pop_back(); - std::vector tmp1(tmp.begin(),tmp.end()-sz); - std::vector tmp2(tmp.end()-sz,tmp.end()); - // - timeDiscr()->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS); - _nature=(NatureOfField)tinyInfoI[2]; - _type->finishUnserialization(tmp2); - int nbOfElemS=(int)tinyInfoS.size(); - _name=tinyInfoS[nbOfElemS-3]; - _desc=tinyInfoS[nbOfElemS-2]; - setTimeUnit(tinyInfoS[nbOfElemS-1]); -} - -/*! - * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller. - * The values returned must be consulted only in readonly mode. - */ -void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector& arrays) const -{ - if(_type.isNull()) - throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !"); - timeDiscr()->getArrays(arrays); - _type->getSerializationIntArray(dataInt); -} - /*! * Tries to set an \a other mesh as the support of \a this field. An attempt fails, if * a current and the \a other meshes are different with use of specified equality diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index a68e907f4..5fadccd19 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -96,14 +96,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; MEDCOUPLING_EXPORT std::vector getDirectChildrenWithNull() const; // - MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector& tinyInfo) const; - MEDCOUPLING_EXPORT void getTinySerializationDbleInformation(std::vector& tinyInfo) const; - MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector& tinyInfo) const; - MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector& tinyInfoI, DataArrayInt *&dataInt, std::vector& arrays); - MEDCOUPLING_EXPORT void checkForUnserialization(const std::vector& tinyInfoI, const DataArrayInt *dataInt, const std::vector& arrays); - MEDCOUPLING_EXPORT void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); - MEDCOUPLING_EXPORT void serialize(DataArrayInt *&dataInt, std::vector& arrays) const; - // MEDCOUPLING_EXPORT void changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps=1e-15); MEDCOUPLING_EXPORT void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps=1e-15); MEDCOUPLING_EXPORT bool mergeNodes(double eps, double epsOnVals=1e-15); diff --git a/src/MEDCoupling/MEDCouplingFieldT.hxx b/src/MEDCoupling/MEDCouplingFieldT.hxx index dbeaf2c0e..b9fba16bc 100644 --- a/src/MEDCoupling/MEDCouplingFieldT.hxx +++ b/src/MEDCoupling/MEDCouplingFieldT.hxx @@ -87,6 +87,14 @@ namespace MEDCoupling MEDCOUPLING_EXPORT bool areCompatibleForDiv(const MEDCouplingField *other) const; MEDCOUPLING_EXPORT void copyTinyAttrFrom(const MEDCouplingFieldT *other); MEDCOUPLING_EXPORT void copyAllTinyAttrFrom(const MEDCouplingFieldT *other); + // + MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector& tinyInfo) const; + MEDCOUPLING_EXPORT void getTinySerializationDbleInformation(std::vector& tinyInfo) const; + MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector& tinyInfo) const; + MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector& tinyInfoI, DataArrayInt *&dataInt, std::vector::ArrayType *>& arrays); + MEDCOUPLING_EXPORT void checkForUnserialization(const std::vector& tinyInfoI, const DataArrayInt *dataInt, const std::vector::ArrayType *>& arrays); + MEDCOUPLING_EXPORT void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); + MEDCOUPLING_EXPORT void serialize(DataArrayInt *&dataInt, std::vector::ArrayType *>& arrays) const; protected: const MEDCouplingTimeDiscretizationTemplate *timeDiscrSafe() const; MEDCouplingTimeDiscretizationTemplate *timeDiscrSafe(); diff --git a/src/MEDCoupling/MEDCouplingFieldT.txx b/src/MEDCoupling/MEDCouplingFieldT.txx index 7f6819c18..61e2aa1bf 100644 --- a/src/MEDCoupling/MEDCouplingFieldT.txx +++ b/src/MEDCoupling/MEDCouplingFieldT.txx @@ -530,6 +530,133 @@ namespace MEDCoupling throw INTERP_KERNEL::Exception("const FieldT : Null type of time discr !"); return ret; } + + template + void MEDCouplingFieldT::getTinySerializationStrInformation(std::vector& tinyInfo) const + { + tinyInfo.clear(); + timeDiscrSafe()->getTinySerializationStrInformation(tinyInfo); + tinyInfo.push_back(_name); + tinyInfo.push_back(_desc); + tinyInfo.push_back(getTimeUnit()); + } + + /*! + * This method retrieves some critical values to resize and prepare remote instance. + * The first two elements returned in tinyInfo correspond to the parameters to give in constructor. + * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny. + */ + template + void MEDCouplingFieldT::getTinySerializationIntInformation(std::vector& tinyInfo) const + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !"); + tinyInfo.clear(); + tinyInfo.push_back((int)_type->getEnum()); + tinyInfo.push_back((int)timeDiscrSafe()->getEnum()); + tinyInfo.push_back((int)_nature); + timeDiscrSafe()->getTinySerializationIntInformation(tinyInfo); + std::vector tinyInfo2; + _type->getTinySerializationIntInformation(tinyInfo2); + tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); + tinyInfo.push_back((int)tinyInfo2.size()); + } + + /*! + * This method retrieves some critical values to resize and prepare remote instance. + * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny. + */ + template + void MEDCouplingFieldT::getTinySerializationDbleInformation(std::vector& tinyInfo) const + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !"); + tinyInfo.clear(); + timeDiscrSafe()->getTinySerializationDbleInformation(tinyInfo); + std::vector tinyInfo2; + _type->getTinySerializationDbleInformation(tinyInfo2); + tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); + tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it + } + + /*! + * This method has to be called to the new instance filled by CORBA, MPI, File... + * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied. + * @param dataInt out parameter. If not null the pointer is already owned by \a this after the call of this method. In this case no decrRef must be applied. + * @param arrays out parameter is a vector resized to the right size. The pointers in the vector is already owned by \a this after the call of this method. + * No decrRef must be applied to every instances in returned vector. + * \sa checkForUnserialization + */ + template + void MEDCouplingFieldT::resizeForUnserialization(const std::vector& tinyInfoI, DataArrayInt *&dataInt, std::vector::ArrayType *>& arrays) + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); + dataInt=0; + std::vector tinyInfoITmp(tinyInfoI); + int sz=tinyInfoITmp.back(); + tinyInfoITmp.pop_back(); + std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); + std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); + timeDiscrSafe()->resizeForUnserialization(tinyInfoI2,arrays); + std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); + _type->resizeForUnserialization(tinyInfoITmp3,dataInt); + } + + /*! + * This method is extremely close to resizeForUnserialization except that here the arrays in \a dataInt and in \a arrays are attached in \a this + * after having checked that size is correct. This method is used in python pickeling context to avoid copy of data. + * \sa resizeForUnserialization + */ + template + void MEDCouplingFieldT::checkForUnserialization(const std::vector& tinyInfoI, const DataArrayInt *dataInt, const std::vector::ArrayType *>& arrays) + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); + std::vector tinyInfoITmp(tinyInfoI); + int sz=tinyInfoITmp.back(); + tinyInfoITmp.pop_back(); + std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); + std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); + timeDiscrSafe()->checkForUnserialization(tinyInfoI2,arrays); + std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); + _type->checkForUnserialization(tinyInfoITmp3,dataInt); + } + + template + void MEDCouplingFieldT::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !"); + std::vector tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end()); + // + std::vector tmp(tinyInfoD); + int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it + tmp.pop_back(); + std::vector tmp1(tmp.begin(),tmp.end()-sz); + std::vector tmp2(tmp.end()-sz,tmp.end()); + // + timeDiscrSafe()->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS); + _nature=(NatureOfField)tinyInfoI[2]; + _type->finishUnserialization(tmp2); + int nbOfElemS=(int)tinyInfoS.size(); + _name=tinyInfoS[nbOfElemS-3]; + _desc=tinyInfoS[nbOfElemS-2]; + setTimeUnit(tinyInfoS[nbOfElemS-1]); + } + + /*! + * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller. + * The values returned must be consulted only in readonly mode. + */ + template + void MEDCouplingFieldT::serialize(DataArrayInt *&dataInt, std::vector::ArrayType *>& arrays) const + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !"); + timeDiscrSafe()->getArrays(arrays); + _type->getSerializationIntArray(dataInt); + } } #endif diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index d156115b4..968656cfb 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -3384,85 +3384,6 @@ DataArrayDouble *DataArrayDouble::Aggregate(const std::vectorgetNumberOfTuples() != \a a2->getNumberOfTuples() - */ -DataArrayDouble *DataArrayDouble::Meld(const DataArrayDouble *a1, const DataArrayDouble *a2) -{ - std::vector arr(2); - arr[0]=a1; arr[1]=a2; - return Meld(arr); -} - -/*! - * Returns a new DataArrayDouble by aggregating all given arrays, so that (1) the number - * of components in the result array is a sum of the number of components of given arrays - * and (2) the number of tuples in the result array is same as that of each of given - * arrays. In other words the i-th tuple of result array includes all components of - * i-th tuples of all given arrays. - * Number of tuples in the given arrays must be the same. - * \param [in] arr - a sequence of arrays to include in the result array. - * \return DataArrayDouble * - the new instance of DataArrayDouble. - * The caller is to delete this result array using decrRef() as it is no more - * needed. - * \throw If all arrays within \a arr are NULL. - * \throw If any given array is not allocated. - * \throw If getNumberOfTuples() of arrays within \a arr is different. - */ -DataArrayDouble *DataArrayDouble::Meld(const std::vector& arr) -{ - std::vector a; - for(std::vector::const_iterator it4=arr.begin();it4!=arr.end();it4++) - if(*it4) - a.push_back(*it4); - if(a.empty()) - throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : input list must contain at least one NON EMPTY DataArrayDouble !"); - std::vector::const_iterator it; - for(it=a.begin();it!=a.end();it++) - (*it)->checkAllocated(); - it=a.begin(); - int nbOfTuples=(*it)->getNumberOfTuples(); - std::vector nbc(a.size()); - std::vector pts(a.size()); - nbc[0]=(*it)->getNumberOfComponents(); - pts[0]=(*it++)->getConstPointer(); - for(int i=1;it!=a.end();it++,i++) - { - if(nbOfTuples!=(*it)->getNumberOfTuples()) - throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : mismatch of number of tuples !"); - nbc[i]=(*it)->getNumberOfComponents(); - pts[i]=(*it)->getConstPointer(); - } - int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0); - DataArrayDouble *ret=DataArrayDouble::New(); - ret->alloc(nbOfTuples,totalNbOfComp); - double *retPtr=ret->getPointer(); - for(int i=0;isetInfoOnComponent(k,a[i]->getInfoOnComponent(j)); - return ret; -} - /*! * Returns a new DataArrayDouble containing a dot product of two given arrays, so that * the i-th tuple of the result array is a sum of products of j-th components of i-th @@ -6238,85 +6159,6 @@ void DataArrayInt::applyRPow(int val) declareAsNew(); } -/*! - * Returns a new DataArrayInt by aggregating two given arrays, so that (1) the number - * of components in the result array is a sum of the number of components of given arrays - * and (2) the number of tuples in the result array is same as that of each of given - * arrays. In other words the i-th tuple of result array includes all components of - * i-th tuples of all given arrays. - * Number of tuples in the given arrays must be the same. - * \param [in] a1 - an array to include in the result array. - * \param [in] a2 - another array to include in the result array. - * \return DataArrayInt * - the new instance of DataArrayInt. - * The caller is to delete this result array using decrRef() as it is no more - * needed. - * \throw If both \a a1 and \a a2 are NULL. - * \throw If any given array is not allocated. - * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() - */ -DataArrayInt *DataArrayInt::Meld(const DataArrayInt *a1, const DataArrayInt *a2) -{ - std::vector arr(2); - arr[0]=a1; arr[1]=a2; - return Meld(arr); -} - -/*! - * Returns a new DataArrayInt by aggregating all given arrays, so that (1) the number - * of components in the result array is a sum of the number of components of given arrays - * and (2) the number of tuples in the result array is same as that of each of given - * arrays. In other words the i-th tuple of result array includes all components of - * i-th tuples of all given arrays. - * Number of tuples in the given arrays must be the same. - * \param [in] arr - a sequence of arrays to include in the result array. - * \return DataArrayInt * - the new instance of DataArrayInt. - * The caller is to delete this result array using decrRef() as it is no more - * needed. - * \throw If all arrays within \a arr are NULL. - * \throw If any given array is not allocated. - * \throw If getNumberOfTuples() of arrays within \a arr is different. - */ -DataArrayInt *DataArrayInt::Meld(const std::vector& arr) -{ - std::vector a; - for(std::vector::const_iterator it4=arr.begin();it4!=arr.end();it4++) - if(*it4) - a.push_back(*it4); - if(a.empty()) - throw INTERP_KERNEL::Exception("DataArrayInt::Meld : array must be NON empty !"); - std::vector::const_iterator it; - for(it=a.begin();it!=a.end();it++) - (*it)->checkAllocated(); - it=a.begin(); - int nbOfTuples=(*it)->getNumberOfTuples(); - std::vector nbc(a.size()); - std::vector pts(a.size()); - nbc[0]=(*it)->getNumberOfComponents(); - pts[0]=(*it++)->getConstPointer(); - for(int i=1;it!=a.end();it++,i++) - { - if(nbOfTuples!=(*it)->getNumberOfTuples()) - throw INTERP_KERNEL::Exception("DataArrayInt::meld : mismatch of number of tuples !"); - nbc[i]=(*it)->getNumberOfComponents(); - pts[i]=(*it)->getConstPointer(); - } - int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc(nbOfTuples,totalNbOfComp); - int *retPtr=ret->getPointer(); - for(int i=0;isetInfoOnComponent(k,a[i]->getInfoOnComponent(j)); - return ret; -} - /*! * Returns a new DataArrayInt which is a minimal partition of elements of \a groups. * The i-th item of the result array is an ID of a set of elements belonging to a diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 6f67b7d0c..77ba020ec 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -315,6 +315,8 @@ namespace MEDCoupling MEDCOUPLING_EXPORT static typename Traits::ArrayType *Divide(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2); MEDCOUPLING_EXPORT static typename Traits::ArrayType *Add(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2); MEDCOUPLING_EXPORT static typename Traits::ArrayType *Multiply(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2); + MEDCOUPLING_EXPORT static typename Traits::ArrayType *Meld(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2); + MEDCOUPLING_EXPORT static typename Traits::ArrayType *Meld(const std::vector::ArrayType *>& arr); MEDCOUPLING_EXPORT MCAuto findIdsGreaterOrEqualTo(T val) const; MEDCOUPLING_EXPORT MCAuto findIdsGreaterThan(T val) const; MEDCOUPLING_EXPORT MCAuto findIdsLowerOrEqualTo(T val) const; @@ -488,8 +490,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayInt *findIdsNotInRange(double vmin, double vmax) const; MEDCOUPLING_EXPORT static DataArrayDouble *Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2); MEDCOUPLING_EXPORT static DataArrayDouble *Aggregate(const std::vector& arr); - MEDCOUPLING_EXPORT static DataArrayDouble *Meld(const DataArrayDouble *a1, const DataArrayDouble *a2); - MEDCOUPLING_EXPORT static DataArrayDouble *Meld(const std::vector& arr); MEDCOUPLING_EXPORT static DataArrayDouble *Dot(const DataArrayDouble *a1, const DataArrayDouble *a2); MEDCOUPLING_EXPORT static DataArrayDouble *CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2); MEDCOUPLING_EXPORT static DataArrayDouble *Max(const DataArrayDouble *a1, const DataArrayDouble *a2); @@ -620,8 +620,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT static DataArrayInt *Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2); MEDCOUPLING_EXPORT static DataArrayInt *Aggregate(const std::vector& arr); MEDCOUPLING_EXPORT static DataArrayInt *AggregateIndexes(const std::vector& arrs); - MEDCOUPLING_EXPORT static DataArrayInt *Meld(const DataArrayInt *a1, const DataArrayInt *a2); - MEDCOUPLING_EXPORT static DataArrayInt *Meld(const std::vector& arr); MEDCOUPLING_EXPORT static DataArrayInt *MakePartition(const std::vector& groups, int newNb, std::vector< std::vector >& fidsOfGroups); MEDCOUPLING_EXPORT static DataArrayInt *BuildUnion(const std::vector& arr); MEDCOUPLING_EXPORT static DataArrayInt *BuildIntersection(const std::vector& arr); diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 2a1c356b0..7643ad169 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -2929,6 +2929,87 @@ struct NotInRange LowerThan lt(val); return findIdsAdv(lt); } + + /*! + * Returns a new DataArrayDouble by aggregating two given arrays, so that (1) the number + * of components in the result array is a sum of the number of components of given arrays + * and (2) the number of tuples in the result array is same as that of each of given + * arrays. In other words the i-th tuple of result array includes all components of + * i-th tuples of all given arrays. + * Number of tuples in the given arrays must be the same. + * \param [in] a1 - an array to include in the result array. + * \param [in] a2 - another array to include in the result array. + * \return DataArrayDouble * - the new instance of DataArrayDouble. + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If both \a a1 and \a a2 are NULL. + * \throw If any given array is not allocated. + * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() + */ + template + typename Traits::ArrayType *DataArrayTemplateClassic::Meld(const typename Traits::ArrayType *a1, const typename Traits::ArrayType *a2) + { + std::vector::ArrayType *> arr(2); + arr[0]=a1; arr[1]=a2; + return Meld(arr); + } + + /*! + * Returns a new DataArrayDouble by aggregating all given arrays, so that (1) the number + * of components in the result array is a sum of the number of components of given arrays + * and (2) the number of tuples in the result array is same as that of each of given + * arrays. In other words the i-th tuple of result array includes all components of + * i-th tuples of all given arrays. + * Number of tuples in the given arrays must be the same. + * \param [in] arr - a sequence of arrays to include in the result array. + * \return DataArrayDouble * - the new instance of DataArrayDouble. + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If all arrays within \a arr are NULL. + * \throw If any given array is not allocated. + * \throw If getNumberOfTuples() of arrays within \a arr is different. + */ + template + typename Traits::ArrayType *DataArrayTemplateClassic::Meld(const std::vector::ArrayType *>& arr) + { + std::vector::ArrayType *> a; + for(typename std::vector::ArrayType *>::const_iterator it4=arr.begin();it4!=arr.end();it4++) + if(*it4) + a.push_back(*it4); + if(a.empty()) + throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : input list must contain at least one NON EMPTY DataArrayDouble !"); + typename std::vector::ArrayType *>::const_iterator it; + for(it=a.begin();it!=a.end();it++) + (*it)->checkAllocated(); + it=a.begin(); + int nbOfTuples((*it)->getNumberOfTuples()); + std::vector nbc(a.size()); + std::vector pts(a.size()); + nbc[0]=(*it)->getNumberOfComponents(); + pts[0]=(*it++)->getConstPointer(); + for(int i=1;it!=a.end();it++,i++) + { + if(nbOfTuples!=(*it)->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : mismatch of number of tuples !"); + nbc[i]=(*it)->getNumberOfComponents(); + pts[i]=(*it)->getConstPointer(); + } + int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0); + typename Traits::ArrayType *ret(Traits::ArrayType::New()); + ret->alloc(nbOfTuples,totalNbOfComp); + T *retPtr(ret->getPointer()); + for(int i=0;isetInfoOnComponent(k,a[i]->getInfoOnComponent(j)); + return ret; + } /*! * Checks if all values in \a this array are equal to \a val at precision \a eps. diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index f9c6b6a78..40f7921bd 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -118,73 +118,6 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFr return ret; } -void MEDCouplingTimeDiscretization::getTinySerializationIntInformation(std::vector& tinyInfo) const -{ - if(_array) - { - tinyInfo.push_back(_array->getNumberOfTuples()); - tinyInfo.push_back(_array->getNumberOfComponents()); - } - else - { - tinyInfo.push_back(-1); - tinyInfo.push_back(-1); - } -} - -void MEDCouplingTimeDiscretization::resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays) -{ - arrays.resize(1); - if(_array!=0) - _array->decrRef(); - DataArrayDouble *arr=0; - if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1) - { - arr=DataArrayDouble::New(); - arr->alloc(tinyInfoI[0],tinyInfoI[1]); - } - _array=arr; - arrays[0]=arr; -} - -void MEDCouplingTimeDiscretization::checkForUnserialization(const std::vector& tinyInfoI, const std::vector& arrays) -{ - static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size one !"; - if(arrays.size()!=1) - throw INTERP_KERNEL::Exception(MSG); - if(_array!=0) - _array->decrRef(); - _array=0; - if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1) - { - if(!arrays[0]) - throw INTERP_KERNEL::Exception(MSG); - arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG); - _array=arrays[0]; - _array->incrRef(); - } -} - -void MEDCouplingTimeDiscretization::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) -{ - _time_tolerance=tinyInfoD[0]; - int nbOfCompo=_array->getNumberOfComponents(); - for(int i=0;isetInfoOnComponent(i,tinyInfoS[i]); -} - -void MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(std::vector& tinyInfo) const -{ - tinyInfo.push_back(_time_tolerance); -} - -void MEDCouplingTimeDiscretization::getTinySerializationStrInformation(std::vector& tinyInfo) const -{ - int nbOfCompo=_array->getNumberOfComponents(); - for(int i=0;igetInfoOnComponent(i)); -} - bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const { int iteration,order; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index fd7e34e43..0edcddba3 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -87,6 +87,12 @@ namespace MEDCoupling MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT virtual ~MEDCouplingTimeDiscretizationTemplate(); + MEDCOUPLING_EXPORT virtual void getTinySerializationIntInformation(std::vector& tinyInfo) const; + MEDCOUPLING_EXPORT virtual void getTinySerializationDbleInformation(std::vector& tinyInfo) const; + MEDCOUPLING_EXPORT virtual void getTinySerializationStrInformation(std::vector& tinyInfo) const; + MEDCOUPLING_EXPORT virtual void resizeForUnserialization(const std::vector& tinyInfoI, std::vector::ArrayType *>& arrays); + MEDCOUPLING_EXPORT virtual void checkForUnserialization(const std::vector& tinyInfoI, const std::vector::ArrayType *>& arrays); + MEDCOUPLING_EXPORT virtual void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); protected: MEDCOUPLING_EXPORT MEDCouplingTimeDiscretizationTemplate(); MEDCOUPLING_EXPORT MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate& other, bool deepCopy); @@ -150,12 +156,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT virtual void divideEqual(const MEDCouplingTimeDiscretization *other) = 0; MEDCOUPLING_EXPORT virtual MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const = 0; MEDCOUPLING_EXPORT virtual void powEqual(const MEDCouplingTimeDiscretization *other) = 0; - MEDCOUPLING_EXPORT virtual void getTinySerializationIntInformation(std::vector& tinyInfo) const; - MEDCOUPLING_EXPORT virtual void getTinySerializationDbleInformation(std::vector& tinyInfo) const; - MEDCOUPLING_EXPORT virtual void getTinySerializationStrInformation(std::vector& tinyInfo) const; - MEDCOUPLING_EXPORT virtual void resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays); - MEDCOUPLING_EXPORT virtual void checkForUnserialization(const std::vector& tinyInfoI, const std::vector& arrays); - MEDCOUPLING_EXPORT virtual void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); MEDCOUPLING_EXPORT virtual void getTinySerializationIntInformation2(std::vector& tinyInfo) const = 0; MEDCOUPLING_EXPORT virtual void getTinySerializationDbleInformation2(std::vector& tinyInfo) const = 0; MEDCOUPLING_EXPORT virtual void finishUnserialization2(const std::vector& tinyInfoI, const std::vector& tinyInfoD) = 0; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.txx b/src/MEDCoupling/MEDCouplingTimeDiscretization.txx index c60dfc79a..a53e36db2 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.txx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.txx @@ -22,6 +22,7 @@ #define __MEDCOUPLINGTIMEDISCRETIZATION_TXX__ #include "MEDCouplingTimeDiscretization.hxx" +#include "MEDCouplingMemArray.txx" #include #include @@ -223,6 +224,81 @@ namespace MEDCoupling arrays[0]=_array; } + template + void MEDCouplingTimeDiscretizationTemplate::getTinySerializationIntInformation(std::vector& tinyInfo) const + { + if(_array) + { + tinyInfo.push_back(_array->getNumberOfTuples()); + tinyInfo.push_back(_array->getNumberOfComponents()); + } + else + { + tinyInfo.push_back(-1); + tinyInfo.push_back(-1); + } + } + + template + void MEDCouplingTimeDiscretizationTemplate::getTinySerializationDbleInformation(std::vector& tinyInfo) const + { + tinyInfo.push_back(_time_tolerance); + } + + template + void MEDCouplingTimeDiscretizationTemplate::getTinySerializationStrInformation(std::vector& tinyInfo) const + { + int nbOfCompo(_array->getNumberOfComponents()); + for(int i=0;igetInfoOnComponent(i)); + } + + template + void MEDCouplingTimeDiscretizationTemplate::resizeForUnserialization(const std::vector& tinyInfoI, std::vector::ArrayType *>& arrays) + { + arrays.resize(1); + if(_array!=0) + _array->decrRef(); + typename Traits::ArrayType *arr=0; + if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1) + { + arr=Traits::ArrayType::New(); + arr->alloc(tinyInfoI[0],tinyInfoI[1]); + } + _array=arr; + arrays[0]=arr; + } + + template + void MEDCouplingTimeDiscretizationTemplate::checkForUnserialization(const std::vector& tinyInfoI, const std::vector::ArrayType *>& arrays) + { + static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size one !"; + if(arrays.size()!=1) + throw INTERP_KERNEL::Exception(MSG); + if(_array!=0) + _array->decrRef(); + _array=0; + if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1) + { + if(!arrays[0]) + throw INTERP_KERNEL::Exception(MSG); + arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG); + _array=arrays[0]; + _array->incrRef(); + } + } + + template + void MEDCouplingTimeDiscretizationTemplate::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) + { + _time_tolerance=tinyInfoD[0]; + int nbOfCompo=_array->getNumberOfComponents(); + for(int i=0;isetInfoOnComponent(i,tinyInfoS[i]); + } + + ///////////////////////// + template std::string MEDCouplingTimeDiscretizationSimple::getStringRepr() const { diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 1342d2aac..41eab4b45 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -56,6 +56,12 @@ def MEDCouplingFieldDoubleIdiv(self,*args): def MEDCouplingFieldDoubleIpow(self,*args): import _MEDCoupling return _MEDCoupling.MEDCouplingFieldDouble____ipow___(self, self, *args) +def MEDCouplingFieldIntnew(cls,*args): + import _MEDCoupling + return _MEDCoupling.MEDCouplingFieldInt____new___(cls,args) +def MEDCouplingFieldFloatnew(cls,*args): + import _MEDCoupling + return _MEDCoupling.MEDCouplingFieldFloat____new___(cls,args) def MEDCouplingDataArrayIntnew(cls,*args): import _MEDCoupling return _MEDCoupling.DataArrayInt____new___(cls,args) diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index a19239b5d..f66c2106c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -4997,45 +4997,12 @@ namespace MEDCoupling PyObject *getTinySerializationInformation() const throw(INTERP_KERNEL::Exception) { - 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(self); } PyObject *serialize() const throw(INTERP_KERNEL::Exception) { - DataArrayInt *ret0(0); - std::vector 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,SWIG_NewPointerObj(SWIG_as_voidptr(ret1[i]),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 )); - } - PyTuple_SetItem(ret,1,ret1Py); - return ret; + return field_serialize(self); } static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception) @@ -5045,80 +5012,17 @@ namespace MEDCoupling PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception) {// put an empty dict in input to say to __new__ to call __init__... - 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; + return field__getnewargs__(self); } PyObject *__getstate__() const throw(INTERP_KERNEL::Exception) { - self->checkConsistencyLight(); - PyObject *ret0(MEDCoupling_MEDCouplingFieldDouble_getTinySerializationInformation(self)); - PyObject *ret1(MEDCoupling_MEDCouplingFieldDouble_serialize(self)); - const 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; + return field__getstate__(self,MEDCoupling_MEDCouplingFieldDouble_getTinySerializationInformation,MEDCoupling_MEDCouplingFieldDouble_serialize); } void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception) { - 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 MEDCouplingUMesh * >(argp)); - // - PyObject *elt0(PyTuple_GetItem(inp,0)); - PyObject *elt1(PyTuple_GetItem(inp,1)); - std::vector a0; - std::vector a1; - std::vector a2; - DataArrayInt *b0(0); - std::vectorb1; - { - 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(b1py,SWIGTYPE_p_MEDCoupling__DataArrayDouble,"DataArrayDouble",b1); - } - self->checkForUnserialization(a1,b0,b1); - // useless here to call resizeForUnserialization because arrays are well resized. - self->finishUnserialization(a1,a0,a2); + field__setstate__(self,inp); } } }; @@ -5345,6 +5249,36 @@ namespace MEDCoupling PyList_SetItem(res,2,SWIG_From_int(tmp2)); return res; } + + PyObject *getTinySerializationInformation() const throw(INTERP_KERNEL::Exception) + { + return field_getTinySerializationInformation(self); + } + + PyObject *serialize() const throw(INTERP_KERNEL::Exception) + { + return field_serialize(self); + } + + static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception) + { + return NewMethWrapCallInitOnlyIfDictWithSingleEltInInputGeneral(cls,args,"MEDCouplingFieldInt"); + } + + PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception) + {// put an empty dict in input to say to __new__ to call __init__... + return field__getnewargs__(self); + } + + PyObject *__getstate__() const throw(INTERP_KERNEL::Exception) + { + return field__getstate__(self,MEDCoupling_MEDCouplingFieldInt_getTinySerializationInformation,MEDCoupling_MEDCouplingFieldInt_serialize); + } + + void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception) + { + field__setstate__(self,inp); + } } }; @@ -5404,7 +5338,7 @@ namespace MEDCoupling } PyObject *getTime() throw(INTERP_KERNEL::Exception) - { + { int tmp1,tmp2; double tmp0=self->getTime(tmp1,tmp2); PyObject *res = PyList_New(3); @@ -5412,7 +5346,37 @@ namespace MEDCoupling PyList_SetItem(res,1,SWIG_From_int(tmp1)); PyList_SetItem(res,2,SWIG_From_int(tmp2)); return res; - } + } + + PyObject *getTinySerializationInformation() const throw(INTERP_KERNEL::Exception) + { + return field_getTinySerializationInformation(self); + } + + PyObject *serialize() const throw(INTERP_KERNEL::Exception) + { + return field_serialize(self); + } + + static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception) + { + return NewMethWrapCallInitOnlyIfDictWithSingleEltInInputGeneral(cls,args,"MEDCouplingFieldFloat"); + } + + PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception) + {// put an empty dict in input to say to __new__ to call __init__... + return field__getnewargs__(self); + } + + PyObject *__getstate__() const throw(INTERP_KERNEL::Exception) + { + return field__getstate__(self,MEDCoupling_MEDCouplingFieldFloat_getTinySerializationInformation,MEDCoupling_MEDCouplingFieldFloat_serialize); + } + + void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception) + { + field__setstate__(self,inp); + } } }; diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i index 564c3a5e4..b410892c4 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i @@ -26,6 +26,25 @@ #include +static PyObject *convertArray(MEDCoupling::DataArray *array, int owner) +{ + PyObject *ret(NULL); + if(!array) + { + Py_XINCREF(Py_None); + return Py_None; + } + if(dynamic_cast(array)) + ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner); + if(dynamic_cast(array)) + ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayInt,owner); + if(dynamic_cast(array)) + ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner); + if(!ret) + throw INTERP_KERNEL::Exception("Not recognized type of array on downcast !"); + return ret; +} + /*! * This method is an extention of PySlice_GetIndices but less * open than PySlice_GetIndicesEx that accepts too many situations. diff --git a/src/MEDCoupling_Swig/MEDCouplingFinalize.i b/src/MEDCoupling_Swig/MEDCouplingFinalize.i index a297355d2..6d84db1f6 100644 --- a/src/MEDCoupling_Swig/MEDCouplingFinalize.i +++ b/src/MEDCoupling_Swig/MEDCouplingFinalize.i @@ -49,6 +49,10 @@ MEDCouplingFieldDouble.__imul__=MEDCouplingFieldDoubleImul MEDCouplingFieldDouble.__idiv__=MEDCouplingFieldDoubleIdiv MEDCouplingFieldDouble.__ipow__=MEDCouplingFieldDoubleIpow +MEDCouplingFieldInt.__new__=classmethod(MEDCouplingFieldIntnew) + +MEDCouplingFieldFloat.__new__=classmethod(MEDCouplingFieldFloatnew) + DataArrayDoubleTuple.__iadd__=MEDCouplingDataArrayDoubleTupleIadd DataArrayDoubleTuple.__isub__=MEDCouplingDataArrayDoubleTupleIsub DataArrayDoubleTuple.__imul__=MEDCouplingDataArrayDoubleTupleImul diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index f7b62cdd5..946415833 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -67,6 +67,7 @@ %newobject MEDCoupling::DataArrayFloat::New; %newobject MEDCoupling::DataArrayFloat::iterator; %newobject MEDCoupling::DataArrayFloat::__iter__; +%newobject MEDCoupling::DataArrayFloat::Meld; %newobject MEDCoupling::DataArrayInt::New; %newobject MEDCoupling::DataArrayInt::__iter__; %newobject MEDCoupling::DataArrayInt::performCopyOrIncrRef; @@ -681,6 +682,7 @@ namespace MEDCoupling void iota(float init=0.) throw(INTERP_KERNEL::Exception); DataArrayFloatIterator *iterator() throw(INTERP_KERNEL::Exception); MCAuto convertToDblArr() const throw(INTERP_KERNEL::Exception); + static DataArrayFloat *Meld(const DataArrayFloat *a1, const DataArrayFloat *a2) throw(INTERP_KERNEL::Exception); %extend { DataArrayFloat() throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling_Swig/MEDCouplingPickleTest.py b/src/MEDCoupling_Swig/MEDCouplingPickleTest.py index bbb2a64cb..9e1f9e0e9 100644 --- a/src/MEDCoupling_Swig/MEDCouplingPickleTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingPickleTest.py @@ -317,6 +317,51 @@ class MEDCouplingPickleTest(unittest.TestCase): self.assertTrue(x2.isEqual(x,1e-7)) pass + @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy") + def test16(self): + """ Test of MEDCouplingFieldInt lying on MEDCouplingCMesh pickeling. """ + arrX=DataArrayDouble(10) ; arrX.iota() ; arrX.setInfoOnComponents(["aa"]) + arrY=DataArrayDouble(5) ; arrY.iota() ; arrY.setInfoOnComponents(["bbb"]) + m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) + f=m.getMeasureField(True) + f=f.convertToIntField() + self.assertTrue(isinstance(f,MEDCouplingFieldInt)) + f.setName("aname") + a=f.getArray() + b=a[:] ; b.iota(7000) + f.setArray(DataArrayInt.Meld(a,b)) + f.getArray().setInfoOnComponents(["u1","vv2"]) + f.checkConsistencyLight(); + # + st=cPickle.dumps(f,cPickle.HIGHEST_PROTOCOL) + f2=cPickle.loads(st) + self.assertTrue(f2.isEqual(f,1e-16,0)) + self.assertTrue(f2.getMesh().isEqual(f.getMesh(),1e-16)) + pass + + @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy") + def test17(self): + """ Test of MEDCouplingFieldInt lying on MEDCouplingCMesh pickeling. """ + arrX=DataArrayDouble(10) ; arrX.iota() ; arrX.setInfoOnComponents(["aa"]) + arrY=DataArrayDouble(5) ; arrY.iota() ; arrY.setInfoOnComponents(["bbb"]) + m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) + f2=m.getMeasureField(True) + f=MEDCouplingFieldFloat(ON_CELLS) + f.setMesh(m) ; f.setArray(f2.getArray().convertToFloatArr()) + self.assertTrue(isinstance(f,MEDCouplingFieldFloat)) + f.setName("aname") + a=f.getArray() + b=a[:] ; b.iota(7000.) + f.setArray(DataArrayFloat.Meld(a,b)) + f.getArray().setInfoOnComponents(["u1","vv2"]) + f.checkConsistencyLight(); + # + st=cPickle.dumps(f,cPickle.HIGHEST_PROTOCOL) + f2=cPickle.loads(st) + self.assertTrue(f2.isEqual(f,1e-16,0)) + self.assertTrue(f2.getMesh().isEqual(f.getMesh(),1e-16)) + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapper.i b/src/MEDCoupling_Swig/MEDCouplingRemapper.i index 7bbd61cd7..aad7b1997 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapper.i +++ b/src/MEDCoupling_Swig/MEDCouplingRemapper.i @@ -139,6 +139,12 @@ def MEDCouplingFieldDoubleIdiv(self,*args): def MEDCouplingFieldDoubleIpow(self,*args): import _MEDCouplingRemapper return _MEDCouplingRemapper.MEDCouplingFieldDouble____ipow___(self, self, *args) +def MEDCouplingFieldIntnew(cls,*args): + import _MEDCouplingRemapper + return _MEDCouplingRemapper.MEDCouplingFieldInt____new___(cls,args) +def MEDCouplingFieldFloatnew(cls,*args): + import _MEDCouplingRemapper + return _MEDCouplingRemapper.MEDCouplingFieldFloat____new___(cls,args) def MEDCouplingDataArrayBytenew(cls,*args): import _MEDCouplingRemapper return _MEDCouplingRemapper.DataArrayByte____new___(cls,args) diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index 0bd84c00e..72450ab35 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -33,7 +33,7 @@ #include "MEDCouplingPartDefinition.hxx" #include "MEDCouplingCartesianAMRMesh.hxx" -static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner) { PyObject *ret=0; if(!mesh) @@ -60,7 +60,7 @@ static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner) thro return ret; } -static PyObject *convertFieldDiscretization(MEDCoupling::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertFieldDiscretization(MEDCoupling::MEDCouplingFieldDiscretization *fd, int owner) { PyObject *ret=0; if(!fd) @@ -83,7 +83,7 @@ static PyObject *convertFieldDiscretization(MEDCoupling::MEDCouplingFieldDiscret return ret; } -static PyObject* convertMultiFields(MEDCoupling::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception) +static PyObject* convertMultiFields(MEDCoupling::MEDCouplingMultiFields *mfs, int owner) { PyObject *ret=0; if(!mfs) @@ -98,7 +98,7 @@ static PyObject* convertMultiFields(MEDCoupling::MEDCouplingMultiFields *mfs, in return ret; } -static PyObject *convertCartesianAMRMesh(MEDCoupling::MEDCouplingCartesianAMRMeshGen *mesh, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertCartesianAMRMesh(MEDCoupling::MEDCouplingCartesianAMRMeshGen *mesh, int owner) { if(!mesh) { @@ -116,7 +116,7 @@ static PyObject *convertCartesianAMRMesh(MEDCoupling::MEDCouplingCartesianAMRMes throw INTERP_KERNEL::Exception("convertCartesianAMRMesh wrap : unrecognized type of cartesian AMR mesh !"); } -static PyObject *convertDataForGodFather(MEDCoupling::MEDCouplingDataForGodFather *data, int owner) throw(INTERP_KERNEL::Exception) +static PyObject *convertDataForGodFather(MEDCoupling::MEDCouplingDataForGodFather *data, int owner) { if(!data) { @@ -544,5 +544,130 @@ typename MEDCoupling::Traits::FieldType *fieldT__getitem__(const MEDCoupling: 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 diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 250022c4e..65365882a 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -57,6 +57,12 @@ def MEDCouplingFieldDoubleIdiv(self,*args): def MEDCouplingFieldDoubleIpow(self,*args): import _MEDLoader return _MEDLoader.MEDCouplingFieldDouble____ipow___(self, self, *args) +def MEDCouplingFieldIntnew(cls,*args): + import _MEDLoader + return _MEDLoader.MEDCouplingFieldInt____new___(cls,args) +def MEDCouplingFieldFloatnew(cls,*args): + import _MEDLoader + return _MEDLoader.MEDCouplingFieldFloat____new___(cls,args) def MEDCouplingDataArrayBytenew(cls,*args): import _MEDLoader return _MEDLoader.DataArrayByte____new___(cls,args)