From: Anthony Geay Date: Tue, 2 May 2017 06:59:57 +0000 (+0200) Subject: First impl of MEDCouplingFieldFloat X-Git-Tag: V8_4_0a1~68 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0b115acf5e7a5023a92fff2803d84d239060273a;p=tools%2Fmedcoupling.git First impl of MEDCouplingFieldFloat --- diff --git a/src/MEDCoupling/CMakeLists.txt b/src/MEDCoupling/CMakeLists.txt index 2c8a580ae..f777468dd 100644 --- a/src/MEDCoupling/CMakeLists.txt +++ b/src/MEDCoupling/CMakeLists.txt @@ -34,6 +34,7 @@ INCLUDE_DIRECTORIES( SET(medcoupling_SOURCES MEDCouplingField.cxx + MEDCouplingFieldFloat.cxx MEDCouplingFieldDouble.cxx MEDCouplingFieldInt.cxx MEDCouplingUMesh.cxx diff --git a/src/MEDCoupling/MEDCouplingFieldFloat.cxx b/src/MEDCoupling/MEDCouplingFieldFloat.cxx new file mode 100644 index 000000000..7214562b6 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingFieldFloat.cxx @@ -0,0 +1,83 @@ +// Copyright (C) 2007-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony GEAY (EDF R&D) + +#include "MEDCouplingFieldFloat.hxx" +#include "MEDCouplingFieldT.txx" +#include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingFieldTemplate.hxx" +#include "MEDCouplingMesh.hxx" + +using namespace MEDCoupling; + +template class MEDCoupling::MEDCouplingFieldT; + +MEDCouplingFieldFloat *MEDCouplingFieldFloat::New(TypeOfField type, TypeOfTimeDiscretization td) +{ + return new MEDCouplingFieldFloat(type,td); +} + +MEDCouplingFieldFloat *MEDCouplingFieldFloat::New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td) +{ + return new MEDCouplingFieldFloat(ft,td); +} + +MEDCouplingFieldFloat::MEDCouplingFieldFloat(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingFieldT(type,MEDCouplingTimeDiscretizationFloat::New(td)) +{ +} + +MEDCouplingFieldFloat::MEDCouplingFieldFloat(const MEDCouplingFieldFloat& other, bool deepCopy):MEDCouplingFieldT(other,deepCopy) +{ +} + +MEDCouplingFieldFloat::MEDCouplingFieldFloat(NatureOfField n, MEDCouplingTimeDiscretizationFloat *td, MEDCouplingFieldDiscretization *type):MEDCouplingFieldT(type,n,td) +{ +} + +/*! + * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! ** + */ +MEDCouplingFieldFloat::MEDCouplingFieldFloat(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingFieldT(ft,MEDCouplingTimeDiscretizationFloat::New(td),false) +{ +} + +MEDCouplingFieldFloat *MEDCouplingFieldFloat::deepCopy() const +{ + return cloneWithMesh(true); +} + +MEDCouplingFieldFloat *MEDCouplingFieldFloat::clone(bool recDeepCpy) const +{ + return new MEDCouplingFieldFloat(*this,recDeepCpy); +} + +MEDCouplingFieldDouble *MEDCouplingFieldFloat::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/MEDCouplingFieldFloat.hxx b/src/MEDCoupling/MEDCouplingFieldFloat.hxx new file mode 100644 index 000000000..83e746596 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingFieldFloat.hxx @@ -0,0 +1,52 @@ +// Copyright (C) 2007-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony GEAY (EDF R&D) + +#ifndef __MEDCOUPLINGFIELDFLOAT_HXX__ +#define __MEDCOUPLINGFIELDFLOAT_HXX__ + +#include "MEDCoupling.hxx" +#include "MEDCouplingFieldT.hxx" +#include "MEDCouplingMemArray.hxx" + +#include + +namespace MEDCoupling +{ + class MEDCouplingFieldDouble; + class MEDCouplingFieldTemplate; + + class MEDCouplingFieldFloat : public MEDCouplingFieldT + { + public: + MEDCOUPLING_EXPORT static MEDCouplingFieldFloat *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME); + MEDCOUPLING_EXPORT static MEDCouplingFieldFloat *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME); + MEDCOUPLING_EXPORT MEDCouplingFieldFloat *deepCopy() const; + MEDCOUPLING_EXPORT MEDCouplingFieldFloat *clone(bool recDeepCpy) const; + MEDCOUPLING_EXPORT MEDCouplingFieldDouble *convertToDblField() const; + protected: + MEDCouplingFieldFloat(TypeOfField type, TypeOfTimeDiscretization td); + MEDCouplingFieldFloat(const MEDCouplingFieldFloat& other, bool deepCopy); + MEDCouplingFieldFloat(NatureOfField n, MEDCouplingTimeDiscretizationFloat *td, MEDCouplingFieldDiscretization *type); + MEDCouplingFieldFloat(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td); + ~MEDCouplingFieldFloat() { } + }; +} + +#endif diff --git a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx index 4f2893ab5..948ef2f64 100644 --- a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx +++ b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx @@ -21,6 +21,7 @@ #include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingMesh.hxx" #include "MEDCouplingFieldInt.hxx" +#include "MEDCouplingFieldFloat.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldDiscretization.hxx" @@ -33,6 +34,11 @@ MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldDo return new MEDCouplingFieldTemplate(f); } +MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldFloat& f) +{ + return new MEDCouplingFieldTemplate(f); +} + MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldInt& f) { return new MEDCouplingFieldTemplate(f); @@ -52,6 +58,12 @@ MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& checkConsistencyLight(); } +MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f):MEDCouplingField(f,false) +{ + forceTimeOfThis(f); + checkConsistencyLight(); +} + MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f):MEDCouplingField(f,false) { forceTimeOfThis(f); diff --git a/src/MEDCoupling/MEDCouplingFieldTemplate.hxx b/src/MEDCoupling/MEDCouplingFieldTemplate.hxx index a00ba79ff..6b27fc218 100644 --- a/src/MEDCoupling/MEDCouplingFieldTemplate.hxx +++ b/src/MEDCoupling/MEDCouplingFieldTemplate.hxx @@ -26,6 +26,7 @@ namespace MEDCoupling { class MEDCouplingFieldInt; + class MEDCouplingFieldFloat; class MEDCouplingFieldDouble; /*! * \brief A field template can be seen as a field without the array of values. @@ -41,6 +42,7 @@ namespace MEDCoupling { public: MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(const MEDCouplingFieldDouble& f); + MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(const MEDCouplingFieldFloat& f); MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(const MEDCouplingFieldInt& f); MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(TypeOfField type); MEDCOUPLING_EXPORT std::string simpleRepr() const; @@ -57,6 +59,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; private: MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f); + MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f); MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f); MEDCouplingFieldTemplate(TypeOfField type); }; diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 5067c1373..2ad3aaf63 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -40,6 +40,8 @@ template class MEDCoupling::MemArray; template class MEDCoupling::MemArray; template class MEDCoupling::DataArrayTemplate; template class MEDCoupling::DataArrayTemplate; +template class MEDCoupling::DataArrayTemplateClassic; +template class MEDCoupling::DataArrayTemplateClassic; template class MEDCoupling::DataArrayTemplateFP; template @@ -812,13 +814,7 @@ DataArrayDouble *DataArrayDouble::deepCopy() const */ DataArrayDouble *DataArrayDouble::performCopyOrIncrRef(bool dCpy) const { - if(dCpy) - return deepCopy(); - else - { - incrRef(); - return const_cast(this); - } + return DataArrayTemplateClassic::PerformCopyOrIncrRef(dCpy,*this); } /*! @@ -1125,23 +1121,6 @@ bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, return _mem.isEqual(other._mem,prec,tmp); } -/*! - * Creates a new DataArrayInt and assigns all (textual and numerical) data of \a this - * array to the new one. - * \return DataArrayInt * - the new instance of DataArrayInt. - */ -DataArrayInt *DataArrayDouble::convertToIntArr() const -{ - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc(getNumberOfTuples(),getNumberOfComponents()); - int *dest=ret->getPointer(); - // to make Visual C++ happy : instead of std::size_t nbOfVals=getNbOfElems(); std::copy(src,src+nbOfVals,dest); - for(const double *src=begin();src!=end();src++,dest++) - *dest=(int)*src; - ret->copyStringInfoFrom(*this); - return ret; -} - /*! * Returns a new DataArrayDouble holding the same values as \a this array but differently * arranged in memory. If \a this array holds 2 components of 3 values: @@ -4731,13 +4710,7 @@ DataArrayInt *DataArrayInt::deepCopy() const */ DataArrayInt *DataArrayInt::performCopyOrIncrRef(bool dCpy) const { - if(dCpy) - return deepCopy(); - else - { - incrRef(); - return const_cast(this); - } + return DataArrayTemplateClassic::PerformCopyOrIncrRef(dCpy,*this); } /*! @@ -6030,24 +6003,6 @@ bool DataArrayInt::hasUniqueValues() const return true; } -/*! - * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this - * array to the new one. - * \return DataArrayDouble * - the new instance of DataArrayInt. - */ -DataArrayDouble *DataArrayInt::convertToDblArr() const -{ - checkAllocated(); - DataArrayDouble *ret=DataArrayDouble::New(); - ret->alloc(getNumberOfTuples(),getNumberOfComponents()); - std::size_t nbOfVals=getNbOfElems(); - const int *src=getConstPointer(); - double *dest=ret->getPointer(); - std::copy(src,src+nbOfVals,dest); - ret->copyStringInfoFrom(*this); - return ret; -} - /*! * Appends components of another array to components of \a this one, tuple by tuple. * So that the number of tuples of \a this array remains the same and the number of diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 8a57b8d14..1d6acba01 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -298,7 +298,21 @@ namespace MEDCoupling }; template - class DataArrayTemplateFP : public DataArrayTemplate + class DataArrayTemplateClassic : public DataArrayTemplate + { + public: + MEDCOUPLING_EXPORT MCAuto convertToDblArr() const; + MEDCOUPLING_EXPORT MCAuto convertToIntArr() const; + MEDCOUPLING_EXPORT MCAuto convertToFloatArr() const; + protected: + static typename Traits::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits::ArrayType& self); + private: + template + MCAuto< typename Traits::ArrayType > convertToOtherTypeOfArr() const; + }; + + template + class DataArrayTemplateFP : public DataArrayTemplateClassic { public: MEDCOUPLING_EXPORT bool isUniform(T val, T eps) const; @@ -326,14 +340,14 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const; MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const; - public: + public:// non abstract but essential MEDCOUPLING_EXPORT std::string reprNotTooLong() const; MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const; - public: MEDCOUPLING_EXPORT bool isEqual(const DataArrayFloat& other, float prec) const; MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const; + MEDCOUPLING_EXPORT DataArrayFloat *performCopyOrIncrRef(bool deepCopy) const; private: ~DataArrayFloat() { } DataArrayFloat() { } @@ -370,7 +384,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT bool isEqual(const DataArrayDouble& other, double prec) const; MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const; - MEDCOUPLING_EXPORT DataArrayInt *convertToIntArr() const; MEDCOUPLING_EXPORT DataArrayDouble *fromNoInterlace() const; MEDCOUPLING_EXPORT DataArrayDouble *toNoInterlace() const; MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP::mySelectByTupleId(new2OldBg,new2OldEnd); } @@ -527,7 +540,7 @@ namespace MEDCoupling class DataArrayIntIterator; - class DataArrayInt : public DataArrayTemplate + class DataArrayInt : public DataArrayTemplateClassic { public: MEDCOUPLING_EXPORT static DataArrayInt *New(); @@ -573,7 +586,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const; MEDCOUPLING_EXPORT DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const; MEDCOUPLING_EXPORT DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const; - MEDCOUPLING_EXPORT DataArrayDouble *convertToDblArr() const; MEDCOUPLING_EXPORT DataArrayInt *fromNoInterlace() const; MEDCOUPLING_EXPORT DataArrayInt *toNoInterlace() const; MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate::mySelectByTupleId(new2OldBg,new2OldEnd); } diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 9fdf9051a..425ceeaae 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -2252,6 +2252,76 @@ namespace MEDCoupling std::reverse(work,work+nbOfCompo); std::reverse(_info_on_compo.begin(),_info_on_compo.end()); } + + template + template + MCAuto< typename Traits::ArrayType > DataArrayTemplateClassic::convertToOtherTypeOfArr() const + { + this->checkAllocated(); + MCAuto::ArrayType> ret(Traits::ArrayType::New()); + ret->alloc(this->getNumberOfTuples(),this->getNumberOfComponents()); + std::size_t nbOfVals(this->getNbOfElems()); + const T *src(this->begin()); + U *dest(ret->getPointer()); + // to make Visual C++ happy : instead of std::size_t nbOfVals=getNbOfElems(); std::copy(src,src+nbOfVals,dest); + //for(const T *src=this->begin();src!=this->end();src++,dest++) + // *dest=(int)*src; + std::copy(src,src+nbOfVals,dest); + ret->copyStringInfoFrom(*this); + return ret; + } + + /*! + * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this + * array to the new one. + * \return DataArrayDouble * - the new instance of DataArrayInt. + */ + template + MCAuto DataArrayTemplateClassic::convertToDblArr() const + { + return convertToOtherTypeOfArr(); + } + + /*! + * Creates a new DataArrayInt and assigns all (textual and numerical) data of \a this + * array to the new one. + * \return DataArrayInt * - the new instance of DataArrayInt. + */ + template + MCAuto DataArrayTemplateClassic::convertToIntArr() const + { + return convertToOtherTypeOfArr(); + } + + /*! + * Creates a new DataArrayFloat and assigns all (textual and numerical) data of \a this + * array to the new one. + * \return DataArrayFloat * - the new instance of DataArrayInt. + */ + template + MCAuto DataArrayTemplateClassic::convertToFloatArr() const + { + return convertToOtherTypeOfArr(); + } + + /*! + * Returns either a \a deep or \a shallow copy of this array. For more info see + * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow. + * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one. + * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy + * == \a true) or \a this instance (if \a dCpy == \a false). + */ + template + typename Traits::ArrayType *DataArrayTemplateClassic::PerformCopyOrIncrRef(bool dCpy, const typename Traits::ArrayType& self) + { + if(dCpy) + return self.deepCopy(); + else + { + self.incrRef(); + return const_cast::ArrayType *>(&self); + } + } /*! * Checks if all values in \a this array are equal to \a val at precision \a eps. diff --git a/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx b/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx index a06401848..36f4de3bb 100644 --- a/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx +++ b/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx @@ -24,6 +24,7 @@ using namespace MEDCoupling; template class MEDCoupling::MemArray; template class MEDCoupling::DataArrayTemplate; +template class MEDCoupling::DataArrayTemplateClassic; template class MEDCoupling::DataArrayTemplateFP; DataArrayFloat *DataArrayFloat::New() @@ -167,3 +168,15 @@ bool DataArrayFloat::isEqualWithoutConsideringStr(const DataArrayFloat& other, f std::string tmp; return _mem.isEqual(other._mem,prec,tmp); } + +/*! + * Returns either a \a deep or \a shallow copy of this array. For more info see + * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow. + * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one. + * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy + * == \a true) or \a this instance (if \a dCpy == \a false). + */ +DataArrayFloat *DataArrayFloat::performCopyOrIncrRef(bool dCpy) const +{ + return DataArrayTemplateClassic::PerformCopyOrIncrRef(dCpy,*this); +} diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 14494736b..f9c6b6a78 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -842,7 +842,7 @@ MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::New(Type } } -bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, float prec, std::string& reason) const +bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, float prec, std::string& reason) const { if(prec!=0) throw INTERP_KERNEL::Exception("isEqualIfNotWhy : only precision equal to 0 supported for int !"); @@ -854,16 +854,16 @@ bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDi const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast(other)); if(!otherC) throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationFloat !"); - if(!MEDCouplingTimeDiscretizationTemplate::areStrictlyCompatible(other,reason)) + if(!MEDCouplingTimeDiscretizationTemplate::areStrictlyCompatible(other,reason)) return false; if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) return false; if(_array==other->getArray()) return true; - return _array->isEqualIfNotWhy(*other->getArray(),reason); + return _array->isEqualIfNotWhy(*other->getArray(),prec,reason); } -bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, float prec) const +bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, float prec) const { if(prec!=0) throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr : only precision 0 is supported !"); @@ -878,7 +878,7 @@ bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDC return false; if(_array==other->getArray()) return true; - return _array->isEqualWithoutConsideringStr(*(other->getArray())); + return _array->isEqualWithoutConsideringStr(*(other->getArray()),prec); } //////////////////////// diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index 9925c2cd1..fd7e34e43 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -243,10 +243,10 @@ namespace MEDCoupling public: MEDCouplingTimeDiscretizationFloat() { } MEDCouplingTimeDiscretizationFloat(const MEDCouplingTimeDiscretizationFloat& other, bool deepCopy); - static MEDCouplingTimeDiscretization *New(TypeOfTimeDiscretization type); + static MEDCouplingTimeDiscretizationFloat *New(TypeOfTimeDiscretization type); MEDCouplingTimeDiscretizationFloat *performCopyOrIncrRef(bool deepCopy) const; bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, float prec, std::string& reason) const; - bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, float prec) const; + bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, float prec) const; private: static const TypeOfTimeDiscretization DISCRETIZATION=ONE_TIME; }; diff --git a/src/MEDCoupling/MEDCouplingTraits.hxx b/src/MEDCoupling/MEDCouplingTraits.hxx index 262328e71..22f203a45 100644 --- a/src/MEDCoupling/MEDCouplingTraits.hxx +++ b/src/MEDCoupling/MEDCouplingTraits.hxx @@ -37,6 +37,7 @@ namespace MEDCoupling class DataArrayChar; class DataArrayByte; class MEDCouplingFieldDouble; + class MEDCouplingFieldFloat; class MEDCouplingFieldInt; template<> @@ -58,7 +59,7 @@ namespace MEDCoupling static const char NPYStr[]; typedef DataArrayFloat ArrayType; typedef DataArrayFloat ArrayTypeCh; - //typedef MEDCouplingFieldFloat FieldType; + typedef MEDCouplingFieldFloat FieldType; }; template<> diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx index 3589367a5..460215242 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx @@ -77,11 +77,9 @@ void MEDCouplingBasicsTest1::testArray2() arr->setInfoOnComponent(1,"hhhh"); arr->setInfoOnComponent(2,"jj"); arr->setInfoOnComponent(3,"kkkkkk"); - DataArrayInt *arr2=arr->convertToIntArr(); - DataArrayDouble *arr3=arr2->convertToDblArr(); - arr2->decrRef(); + MCAuto arr2(arr->convertToIntArr()); + MCAuto arr3(arr2->convertToDblArr()); CPPUNIT_ASSERT(arr->isEqual(*arr3,1e-14)); - arr3->decrRef(); arr->decrRef(); } diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx index a6e7075ca..42972290c 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx @@ -681,7 +681,7 @@ void MEDCouplingBasicsTest3::testKeepSetSelectedComponent1() const double expected1[30]={2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.}; for(int i=0;i<30;i++) CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],a2->getIJ(0,i),1e-14); - DataArrayInt *a3=a1->convertToIntArr(); + MCAuto a3(a1->convertToIntArr()); DataArrayInt *a4=static_cast(a3->keepSelectedComponents(arr2V)); CPPUNIT_ASSERT_EQUAL(6,(int)a4->getNumberOfComponents()); CPPUNIT_ASSERT_EQUAL(5,(int)a4->getNumberOfTuples()); @@ -713,7 +713,7 @@ void MEDCouplingBasicsTest3::testKeepSetSelectedComponent1() const double expected2[30]={2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.}; for(int i=0;i<30;i++) CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],a2->getIJ(0,i),1e-14); - DataArrayInt *a6=a5->convertToIntArr(); + MCAuto a6=a5->convertToIntArr(); a6->setInfoOnComponent(0,"eeee"); a6->setInfoOnComponent(1,"ffff"); a4->setSelectedComponents(a6,arr4V); @@ -740,10 +740,8 @@ void MEDCouplingBasicsTest3::testKeepSetSelectedComponent1() arr7V.resize(3); CPPUNIT_ASSERT_THROW(a2->setSelectedComponents(a1,arr7V),INTERP_KERNEL::Exception); // - a6->decrRef(); a5->decrRef(); a4->decrRef(); - a3->decrRef(); a2->decrRef(); a1->decrRef(); } @@ -1066,14 +1064,13 @@ void MEDCouplingBasicsTest3::testDAFromNoInterlace1() CPPUNIT_ASSERT_EQUAL(5,(int)da2->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components ! CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer())); - DataArrayDouble *da3=da->convertToDblArr(); + MCAuto da3=da->convertToDblArr(); DataArrayDouble *da4=da3->fromNoInterlace(); CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(3,(int)da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components ! for(int i=0;i<15;i++) CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14); da4->decrRef(); - da3->decrRef(); da2->decrRef(); da->decrRef(); } @@ -1089,14 +1086,13 @@ void MEDCouplingBasicsTest3::testDAToNoInterlace1() CPPUNIT_ASSERT_EQUAL(5,(int)da2->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(3,(int)da2->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components ! CPPUNIT_ASSERT(std::equal(expected1,expected1+15,da2->getConstPointer())); - DataArrayDouble *da3=da->convertToDblArr(); + MCAuto da3=da->convertToDblArr(); DataArrayDouble *da4=da3->toNoInterlace(); CPPUNIT_ASSERT_EQUAL(5,(int)da4->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(3,(int)da4->getNumberOfComponents());// it's not a bug. Avoid to have 1 million components ! for(int i=0;i<15;i++) CPPUNIT_ASSERT_DOUBLES_EQUAL((double)expected1[i],da4->getIJ(0,i),1e-14); da4->decrRef(); - da3->decrRef(); da2->decrRef(); da->decrRef(); } @@ -1112,13 +1108,12 @@ void MEDCouplingBasicsTest3::testDAIsUniform1() CPPUNIT_ASSERT(!da->isUniform(1)); da->setIJ(2,0,1); CPPUNIT_ASSERT(da->isUniform(1)); - DataArrayDouble *da2=da->convertToDblArr(); + MCAuto da2=da->convertToDblArr(); CPPUNIT_ASSERT(da2->isUniform(1.,1e-12)); da2->setIJ(1,0,1.+1.e-13); CPPUNIT_ASSERT(da2->isUniform(1.,1e-12)); da2->setIJ(1,0,1.+1.e-11); CPPUNIT_ASSERT(!da2->isUniform(1.,1e-12)); - da2->decrRef(); da->decrRef(); } @@ -1648,7 +1643,7 @@ void MEDCouplingBasicsTest3::testDAMeld1() // da1->fillWithValue(7.); da2->iota(0.); - DataArrayDouble *da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec"); + MCAuto da3=da2->applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec"); // da1->setInfoOnComponent(0,"c0da1"); da1->setInfoOnComponent(1,"c1da1"); @@ -1670,8 +1665,8 @@ void MEDCouplingBasicsTest3::testDAMeld1() for(int i=0;i<35;i++) CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da1->getIJ(0,i),1e-10); // - DataArrayInt *dai1=da1C->convertToIntArr(); - DataArrayInt *dai3=da3->convertToIntArr(); + MCAuto dai1=da1C->convertToIntArr(); + MCAuto dai3=da3->convertToIntArr(); dai1->meldWith(dai3); CPPUNIT_ASSERT_EQUAL(5,(int)dai1->getNumberOfComponents()); CPPUNIT_ASSERT_EQUAL(7,(int)dai1->getNumberOfTuples()); @@ -1694,7 +1689,6 @@ void MEDCouplingBasicsTest3::testDAMeld1() for(int i=0;i<35;i++) CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],da4->getIJ(0,i),1e-10); // test of static method DataArrayInt::meld - dai1->decrRef(); dai1=da1C->convertToIntArr(); DataArrayInt *dai4=DataArrayInt::Meld(dai1,dai3); CPPUNIT_ASSERT_EQUAL(5,(int)dai4->getNumberOfComponents()); @@ -1709,12 +1703,9 @@ void MEDCouplingBasicsTest3::testDAMeld1() // dai4->decrRef(); da4->decrRef(); - dai3->decrRef(); - dai1->decrRef(); da1C->decrRef(); da1->decrRef(); da2->decrRef(); - da3->decrRef(); } void MEDCouplingBasicsTest3::testFieldMeld1() @@ -2140,7 +2131,7 @@ void MEDCouplingBasicsTest3::testDARearrange1() for(int i=0;i<12;i++) CPPUNIT_ASSERT_EQUAL(i,da1->getIJ(0,i)); //double - DataArrayDouble *da2=da1->convertToDblArr(); + MCAuto da2=da1->convertToDblArr(); da1->decrRef(); const double *ptr2=da2->getConstPointer(); // @@ -2180,7 +2171,6 @@ void MEDCouplingBasicsTest3::testDARearrange1() CPPUNIT_ASSERT_EQUAL(4,(int)da2->getNumberOfTuples()); for(int i=0;i<12;i++) CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i,da2->getIJ(0,i),1e-14); - da2->decrRef(); } void MEDCouplingBasicsTest3::testGetDifferentValues1() @@ -2224,7 +2214,7 @@ void MEDCouplingBasicsTest3::testDAIBuildPermutationArr1() c=a->buildPermutationArr(*b); const int expect2[5]={1,3,4,2,3}; CPPUNIT_ASSERT(std::equal(expect2,expect2+5,c->getConstPointer())); - DataArrayDouble *d=b->convertToDblArr(); + MCAuto d=b->convertToDblArr(); b->sort(); const int expect3[5]={4,4,5,6,8}; CPPUNIT_ASSERT(std::equal(expect3,expect3+5,b->getConstPointer())); @@ -2234,10 +2224,9 @@ void MEDCouplingBasicsTest3::testDAIBuildPermutationArr1() for(int i=0;i<5;i++) CPPUNIT_ASSERT_DOUBLES_EQUAL(double(expect3[i]),d->getIJ(i,0),1e-14); // - d->decrRef(); + b->decrRef(); c->decrRef(); a->decrRef(); - b->decrRef(); } void MEDCouplingBasicsTest3::testAreCellsIncludedIn2() diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index 6ed02e3ed..fc199652f 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -998,7 +998,7 @@ void MEDCouplingBasicsTest4::testDACpyFrom1() d1->deepCopyFrom(*d); CPPUNIT_ASSERT(d->isEqual(*d1,1e-12)); // - DataArrayInt *d2=d->convertToIntArr(); + MCAuto d2=d->convertToIntArr(); DataArrayInt *d4=DataArrayInt::New(); CPPUNIT_ASSERT(!d2->isEqual(*d4)); d4->deepCopyFrom(*d2); @@ -1012,7 +1012,6 @@ void MEDCouplingBasicsTest4::testDACpyFrom1() // d->decrRef(); d1->decrRef(); - d2->decrRef(); d4->decrRef(); } diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx index 3213b5728..b18a7d3de 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx @@ -601,7 +601,7 @@ void MEDCouplingBasicsTest5::testDataArrayAbs1() const double expected1[12]={2.,3.,5.,6.,7.,8.,9.,10.,11.,12.,13.,15.}; d1->alloc(6,2); std::copy(val1,val1+12,d1->getPointer()); - DataArrayInt *d2=d1->convertToIntArr(); + MCAuto d2=d1->convertToIntArr(); // d1->abs(); for(int i=0;i<12;i++) @@ -612,7 +612,6 @@ void MEDCouplingBasicsTest5::testDataArrayAbs1() for(int i=0;i<12;i++) CPPUNIT_ASSERT_EQUAL(expected2[i],d2->getIJ(0,i)); // - d2->decrRef(); d1->decrRef(); } diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 1fd7a8d6e..0b6ca517b 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -54,6 +54,7 @@ %newobject MEDCoupling::DataArrayInt::__iter__; %newobject MEDCoupling::DataArrayInt::selectPartDef; %newobject MEDCoupling::DataArrayInt::convertToDblArr; +%newobject MEDCoupling::DataArrayInt::convertToFloatArr; %newobject MEDCoupling::DataArrayInt::performCopyOrIncrRef; %newobject MEDCoupling::DataArrayInt::subArray; %newobject MEDCoupling::DataArrayInt::changeNbOfComponents; @@ -150,6 +151,7 @@ %newobject MEDCoupling::DataArrayDouble::__iter__; %newobject MEDCoupling::DataArrayDouble::selectPartDef; %newobject MEDCoupling::DataArrayDouble::convertToIntArr; +%newobject MEDCoupling::DataArrayDouble::convertToFloatArr; %newobject MEDCoupling::DataArrayDouble::performCopyOrIncrRef; %newobject MEDCoupling::DataArrayDouble::Aggregate; %newobject MEDCoupling::DataArrayDouble::Meld; @@ -773,7 +775,6 @@ namespace MEDCoupling std::string reprNotTooLong() const throw(INTERP_KERNEL::Exception); bool isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception); bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception); - DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception); DataArrayDouble *fromNoInterlace() const throw(INTERP_KERNEL::Exception); DataArrayDouble *toNoInterlace() const throw(INTERP_KERNEL::Exception); DataArrayDouble *subArray(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); @@ -890,6 +891,18 @@ namespace MEDCoupling return ret.retn(); } + DataArrayFloat *convertToFloatArr() const throw(INTERP_KERNEL::Exception) + { + MCAuto ret(self->convertToFloatArr()); + return ret.retn(); + } + + DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception) + { + MCAuto ret(self->convertToIntArr()); + return ret.retn(); + } + void pushBackValsSilent(PyObject *li) throw(INTERP_KERNEL::Exception) { double val; @@ -2341,7 +2354,6 @@ namespace MEDCoupling DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const throw(INTERP_KERNEL::Exception); DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const throw(INTERP_KERNEL::Exception); DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception); - DataArrayDouble *convertToDblArr() const throw(INTERP_KERNEL::Exception); DataArrayInt *indicesOfSubPart(const DataArrayInt& partOfThis) const throw(INTERP_KERNEL::Exception); DataArrayInt *fromNoInterlace() const throw(INTERP_KERNEL::Exception); DataArrayInt *toNoInterlace() const throw(INTERP_KERNEL::Exception); @@ -2543,6 +2555,18 @@ namespace MEDCoupling { return MEDCoupling_DataArrayInt_New__SWIG_1(elt0,nbOfTuples,nbOfComp); } + + DataArrayDouble *convertToDblArr() const throw(INTERP_KERNEL::Exception) + { + MCAuto ret(self->convertToDblArr()); + return ret.retn(); + } + + DataArrayFloat *convertToFloatArr() const throw(INTERP_KERNEL::Exception) + { + MCAuto ret(self->convertToFloatArr()); + return ret.retn(); + } std::string __str__() const throw(INTERP_KERNEL::Exception) {