From: Anthony Geay Date: Fri, 28 Jul 2017 14:44:21 +0000 (+0200) Subject: First iter X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1e16972a3c968eb57a6dec810877f49007eb2fc3;p=tools%2Fmedcoupling.git First iter --- diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 4afc32168..94c0a12fa 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -34,7 +34,7 @@ void MEDCouplingField::checkConsistencyLight() const throw INTERP_KERNEL::Exception("MEDCouplingField::checkConsistencyLight : no spatial discretization !"); } -bool MEDCouplingField::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const +bool MEDCouplingField::isEqualIfNotWhyProtected(const MEDCouplingField *other, double meshPrec, std::string& reason) const { if(!other) throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualIfNotWhy : other instance is NULL !"); @@ -57,7 +57,7 @@ bool MEDCouplingField::isEqualIfNotWhy(const MEDCouplingField *other, double mes reason=oss.str(); return false; } - if(!_type->isEqualIfNotWhy(other->_type,valsPrec,reason)) + if(!_type->isEqualIfNotWhy(other->_type,meshPrec,reason)) { reason.insert(0,"Spatial discretizations differ :"); return false; @@ -77,37 +77,22 @@ bool MEDCouplingField::isEqualIfNotWhy(const MEDCouplingField *other, double mes return ret; } -/*! - * Checks if \a this and another MEDCouplingField are fully equal. - * \param [in] other - the field to compare with \a this one. - * \param [in] meshPrec - precision used to compare node coordinates of the underlying mesh. - * \param [in] valsPrec - precision used to compare field values. - * \return bool - \c true if the two fields are equal, \c false else. - * \throw If \a other is NULL. - */ -bool MEDCouplingField::isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const -{ - std::string tmp; - return isEqualIfNotWhy(other,meshPrec,valsPrec,tmp); -} - /*! * Checks if \a this and another MEDCouplingField are equal. The textual * information like names etc. is not considered. * \param [in] other - the field to compare with \a this one. * \param [in] meshPrec - precision used to compare node coordinates of the underlying mesh. - * \param [in] valsPrec - precision used to compare field values. * \return bool - \c true if the two fields are equal, \c false else. * \throw If \a other is NULL. * \throw If the spatial discretization of \a this field is NULL. */ -bool MEDCouplingField::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const +bool MEDCouplingField::isEqualWithoutConsideringStrProtected(const MEDCouplingField *other, double meshPrec) const { if(!other) throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : input field is NULL !"); if(!_type) throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : spatial discretization of this is NULL !"); - if(!_type->isEqualWithoutConsideringStr(other->_type,valsPrec)) + if(!_type->isEqualWithoutConsideringStr(other->_type,meshPrec)) return false; if(_nature!=other->_nature) return false; diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index dc71d95f9..d29efca74 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -48,9 +48,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT virtual bool areCompatibleForMerge(const MEDCouplingField *other) const; MEDCOUPLING_EXPORT virtual bool areStrictlyCompatible(const MEDCouplingField *other) const; MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const; - MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const; - MEDCOUPLING_EXPORT virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; - MEDCOUPLING_EXPORT virtual bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const; MEDCOUPLING_EXPORT virtual void copyTinyStringsFrom(const MEDCouplingField *other); MEDCOUPLING_EXPORT void setMesh(const MEDCoupling::MEDCouplingMesh *mesh); MEDCOUPLING_EXPORT const MEDCoupling::MEDCouplingMesh *getMesh() const { return _mesh; } @@ -96,6 +93,8 @@ namespace MEDCoupling MEDCOUPLING_EXPORT MEDCouplingField(const MEDCouplingField& other, bool deepCopy=true); MEDCOUPLING_EXPORT MEDCouplingField(MEDCouplingFieldDiscretization *type, NatureOfField nature=NoNature); MEDCOUPLING_EXPORT virtual ~MEDCouplingField(); + MEDCOUPLING_EXPORT bool isEqualIfNotWhyProtected(const MEDCouplingField *other, double meshPrec, std::string& reason) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStrProtected(const MEDCouplingField *other, double meshPrec) const; protected: std::string _name; std::string _desc; diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index c4a301a16..20ded05dd 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -22,6 +22,7 @@ #include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingFieldT.txx" #include "MEDCouplingFieldInt.hxx" +#include "MEDCouplingFieldFloat.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingTimeDiscretization.hxx" #include "MEDCouplingFieldDiscretization.hxx" @@ -522,21 +523,32 @@ DataArrayInt *MEDCouplingFieldDouble::findIdsInRange(double vmin, double vmax) c return getArray()->findIdsInRange(vmin,vmax); } -MEDCouplingFieldInt *MEDCouplingFieldDouble::convertToIntField() const +template +typename Traits::FieldType *ConvertToUField(const MEDCouplingFieldDouble *self) { - MCAuto tmp(MEDCouplingFieldTemplate::New(*this)); + MCAuto tmp(MEDCouplingFieldTemplate::New(*self)); int t1,t2; - double t0(getTime(t1,t2)); - MCAuto ret(MEDCouplingFieldInt::New(*tmp,getTimeDiscretization())); + double t0(self->getTime(t1,t2)); + MCAuto::FieldType > ret(Traits::FieldType::New(*tmp,self->getTimeDiscretization())); ret->setTime(t0,t1,t2); - if(getArray()) + if(self->getArray()) { - MCAuto arr(getArray()->convertToIntArr()); + MCAuto::ArrayType> arr(self->getArray()->convertToOtherTypeOfArr()); ret->setArray(arr); } return ret.retn(); } +MEDCouplingFieldInt *MEDCouplingFieldDouble::convertToIntField() const +{ + return ConvertToUField(this); +} + +MEDCouplingFieldFloat *MEDCouplingFieldDouble::convertToFloatField() const +{ + return ConvertToUField(this); +} + MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingFieldT(type,MEDCouplingTimeDiscretization::New(td)) { } diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index f12f4ed52..7ae4248dd 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -52,6 +52,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT MEDCouplingFieldDouble *nodeToCellDiscretization() const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *cellToNodeDiscretization() const; MEDCOUPLING_EXPORT MEDCouplingFieldInt *convertToIntField() const; + MEDCOUPLING_EXPORT MEDCouplingFieldFloat *convertToFloatField() 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/MEDCouplingFieldT.hxx b/src/MEDCoupling/MEDCouplingFieldT.hxx index 6abd6f8fb..3e832ef56 100644 --- a/src/MEDCoupling/MEDCouplingFieldT.hxx +++ b/src/MEDCoupling/MEDCouplingFieldT.hxx @@ -75,8 +75,9 @@ namespace MEDCoupling MEDCOUPLING_EXPORT double getStartTime(int& iteration, int& order) const { return _time_discr->getStartTime(iteration,order); } MEDCOUPLING_EXPORT double getEndTime(int& iteration, int& order) const { return _time_discr->getEndTime(iteration,order); } MEDCOUPLING_EXPORT T getIJ(int tupleId, int compoId) const { return getArray()->getIJ(tupleId,compoId); } - MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const; - MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const; + MEDCOUPLING_EXPORT virtual bool isEqual(const MEDCouplingFieldT *other, double meshPrec, T valsPrec) const; + MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const MEDCouplingFieldT *other, double meshPrec, T valsPrec, std::string& reason) const; + MEDCOUPLING_EXPORT virtual bool isEqualWithoutConsideringStr(const MEDCouplingFieldT *other, double meshPrec, T valsPrec) const; MEDCOUPLING_EXPORT void copyTinyStringsFrom(const MEDCouplingField *other); MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingField *other) const; MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const; diff --git a/src/MEDCoupling/MEDCouplingFieldT.txx b/src/MEDCoupling/MEDCouplingFieldT.txx index 61e2aa1bf..d274bdce6 100644 --- a/src/MEDCoupling/MEDCouplingFieldT.txx +++ b/src/MEDCoupling/MEDCouplingFieldT.txx @@ -117,21 +117,22 @@ namespace MEDCoupling } return ret.retn(); } + + template + bool MEDCouplingFieldT::isEqual(const MEDCouplingFieldT *other, double meshPrec, T valsPrec) const + { + std::string tmp; + return isEqualIfNotWhy(other,meshPrec,valsPrec,tmp); + } template - bool MEDCouplingFieldT::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const + bool MEDCouplingFieldT::isEqualIfNotWhy(const MEDCouplingFieldT *other, double meshPrec, T valsPrec, std::string& reason) const { if(!other) throw INTERP_KERNEL::Exception("MEDCouplingFieldT::isEqualIfNotWhy : other instance is NULL !"); - const MEDCouplingFieldT *otherC(dynamic_cast *>(other)); - if(!otherC) - { - reason="field given in input is not castable in MEDCouplingFieldT !"; - return false; - } - if(!MEDCouplingField::isEqualIfNotWhy(other,meshPrec,valsPrec,reason)) + if(!isEqualIfNotWhyProtected(other,meshPrec,reason)) return false; - if(!_time_discr->isEqualIfNotWhy(otherC->_time_discr,T(valsPrec),reason)) + if(!_time_discr->isEqualIfNotWhy(other->_time_discr,T(valsPrec),reason)) { reason.insert(0,"In FieldT time discretizations differ :"); return false; @@ -150,14 +151,13 @@ namespace MEDCoupling * \throw If the spatial discretization of \a this field is NULL. */ template - bool MEDCouplingFieldT::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const + bool MEDCouplingFieldT::isEqualWithoutConsideringStr(const MEDCouplingFieldT *other, double meshPrec, T valsPrec) const { - const MEDCouplingFieldT *otherC(dynamic_cast *>(other)); - if(!otherC) + if(!other) return false; - if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec)) + if(!isEqualWithoutConsideringStrProtected(other,meshPrec)) return false; - if(!_time_discr->isEqualWithoutConsideringStr(otherC->_time_discr,T(valsPrec))) + if(!_time_discr->isEqualWithoutConsideringStr(other->_time_discr,valsPrec)) return false; return true; } diff --git a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx index 2e432b88a..a9871a43d 100644 --- a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx +++ b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx @@ -59,6 +59,22 @@ MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCou return new MEDCouplingFieldTemplate(f,false); } +bool MEDCouplingFieldTemplate::isEqualIfNotWhy(const MEDCouplingFieldTemplate *other, double meshPrec, std::string& reason) const +{ + return isEqualIfNotWhyProtected(other,meshPrec,reason); +} + +bool MEDCouplingFieldTemplate::isEqual(const MEDCouplingFieldTemplate *other, double meshPrec) const +{ + std::string tmp; + return isEqualIfNotWhyProtected(other,meshPrec,tmp); +} + +bool MEDCouplingFieldTemplate::isEqualWithoutConsideringStr(const MEDCouplingFieldTemplate *other, double meshPrec) const +{ + return isEqualWithoutConsideringStrProtected(other,meshPrec); +} + /*! * The user should \b not use this method. Only useful for CORBA serialization/unserialization. */ diff --git a/src/MEDCoupling/MEDCouplingFieldTemplate.hxx b/src/MEDCoupling/MEDCouplingFieldTemplate.hxx index a12842f51..43a19c887 100644 --- a/src/MEDCoupling/MEDCouplingFieldTemplate.hxx +++ b/src/MEDCoupling/MEDCouplingFieldTemplate.hxx @@ -48,6 +48,9 @@ namespace MEDCoupling MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *NewWithoutCheck(const MEDCouplingFieldDouble& f); MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *NewWithoutCheck(const MEDCouplingFieldFloat& f); MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *NewWithoutCheck(const MEDCouplingFieldInt& f); + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingFieldTemplate *other, double meshPrec, std::string& reason) const; + MEDCOUPLING_EXPORT bool isEqual(const MEDCouplingFieldTemplate *other, double meshPrec) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingFieldTemplate *other, double meshPrec) const; MEDCOUPLING_EXPORT std::string simpleRepr() const; MEDCOUPLING_EXPORT std::string advancedRepr() const; MEDCOUPLING_EXPORT void checkConsistencyLight() const; diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index b4ed5643c..bf8a15ff4 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -349,13 +349,13 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT std::string reprNotTooLong() const; + template + MCAuto< typename Traits::ArrayType > convertToOtherTypeOfArr() const; protected: static typename Traits::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits::ArrayType& self); template MCAuto findIdsAdv(const OP& op) const; private: - template - MCAuto< typename Traits::ArrayType > convertToOtherTypeOfArr() const; template void somethingEqual(const typename Traits::ArrayType *other); }; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 246f9a6bf..782018995 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -777,8 +777,6 @@ MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::New(Type 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 !"); if(!other) { reason="Time discretization is NULL."; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py index 778604242..6035e19fb 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py @@ -3902,32 +3902,32 @@ class MEDCouplingBasicsTest5(unittest.TestCase): arr2=DataArrayInt([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr2.setInfoOnComponents(["aa","bbb"]) f2.setArray(arr2) ; f2.setName("f1") ; f2.setTime(2.,3,4) # - self.assertTrue(f1.isEqual(f2,1e-12,0.)) + self.assertTrue(f1.isEqual(f2,1e-12,0)) f1.getArray()[:]*=2 - self.assertTrue(not f1.isEqual(f2,1e-12,0.)) - self.assertTrue(not f1.isEqualWithoutConsideringStr(f2,1e-12,0.)) + self.assertTrue(not f1.isEqual(f2,1e-12,0)) + self.assertTrue(not f1.isEqualWithoutConsideringStr(f2,1e-12,0)) f1.getArray()[:]/=2 - self.assertTrue(f1.isEqual(f2,1e-12,0.)) + self.assertTrue(f1.isEqual(f2,1e-12,0)) # f1.setName("F1") - self.assertTrue(not f1.isEqual(f2,1e-12,0.)) + self.assertTrue(not f1.isEqual(f2,1e-12,0)) f1.setName("f1") - self.assertTrue(f1.isEqual(f2,1e-12,0.)) + self.assertTrue(f1.isEqual(f2,1e-12,0)) # f1.getArray().setInfoOnComponents(["aa","bbbb"]) - self.assertTrue(not f1.isEqual(f2,1e-12,0.)) - self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,0.)) + self.assertTrue(not f1.isEqual(f2,1e-12,0)) + self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,0)) f1.getArray().setInfoOnComponents(["aa","bbb"]) - self.assertTrue(f1.isEqual(f2,1e-12,0.)) + self.assertTrue(f1.isEqual(f2,1e-12,0)) # f3=f2.deepCopy() - self.assertTrue(f1.isEqual(f3,1e-12,0.)) + self.assertTrue(f1.isEqual(f3,1e-12,0)) # for fd,expected in ((ON_NODES,False),(ON_CELLS,True)): f4=MEDCouplingFieldInt(fd) ; f4.setMesh(m2) ; f4.setTime(2.,3,4) arr4=DataArrayInt([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr4.setInfoOnComponents(["aa","bbb"]) f4.setArray(arr4) ; f4.setName("f1") - self.assertEqual(f1.isEqual(f4,1e-12,0.),expected) + self.assertEqual(f1.isEqual(f4,1e-12,0),expected) pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index d97b69bbb..ddf21af6d 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -188,6 +188,7 @@ using namespace INTERP_KERNEL; %newobject MEDCoupling::MEDCouplingFieldDouble::MergeFields; %newobject MEDCoupling::MEDCouplingFieldDouble::MeldFields; %newobject MEDCoupling::MEDCouplingFieldDouble::convertToIntField; +%newobject MEDCoupling::MEDCouplingFieldDouble::convertToFloatField; %newobject MEDCoupling::MEDCouplingFieldDouble::doublyContractedProduct; %newobject MEDCoupling::MEDCouplingFieldDouble::determinant; %newobject MEDCoupling::MEDCouplingFieldDouble::eigenValues; @@ -3810,8 +3811,6 @@ namespace MEDCoupling public: virtual void checkConsistencyLight() const throw(INTERP_KERNEL::Exception); virtual bool areCompatibleForMerge(const MEDCouplingField *other) const throw(INTERP_KERNEL::Exception); - virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception); - virtual bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception); virtual void copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception); void setMesh(const MEDCoupling::MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); void setName(const char *name) throw(INTERP_KERNEL::Exception); @@ -3857,18 +3856,6 @@ namespace MEDCoupling return convertIntArrToPyList3(ret); } - PyObject *isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception) - { - std::string ret1; - bool ret0=self->isEqualIfNotWhy(other,meshPrec,valsPrec,ret1); - PyObject *ret=PyTuple_New(2); - PyObject *ret0Py=ret0?Py_True:Py_False; - Py_XINCREF(ret0Py); - PyTuple_SetItem(ret,0,ret0Py); - PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); - return ret; - } - PyObject *buildSubMeshData(PyObject *li) const throw(INTERP_KERNEL::Exception) { DataArrayInt *ret1=0; @@ -3971,6 +3958,8 @@ namespace MEDCoupling static MEDCouplingFieldTemplate *New(TypeOfField type); std::string simpleRepr() const throw(INTERP_KERNEL::Exception); std::string advancedRepr() const throw(INTERP_KERNEL::Exception); + bool isEqual(const MEDCouplingFieldTemplate *other, double meshPrec) const throw(INTERP_KERNEL::Exception); + bool isEqualWithoutConsideringStr(const MEDCouplingFieldTemplate *other, double meshPrec) const throw(INTERP_KERNEL::Exception); %extend { MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f) throw(INTERP_KERNEL::Exception) @@ -4004,16 +3993,31 @@ namespace MEDCoupling self->reprQuickOverview(oss); return oss.str(); } + + PyObject *isEqualIfNotWhy(const MEDCouplingFieldTemplate *other, double meshPrec) const throw(INTERP_KERNEL::Exception) + { + std::string ret1; + bool ret0=self->isEqualIfNotWhy(other,meshPrec,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); + return ret; + } } }; class MEDCouplingFieldInt; + class MEDCouplingFieldFloat; class MEDCouplingFieldDouble : public MEDCoupling::MEDCouplingField { public: static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME); static MEDCouplingFieldDouble *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME); + bool isEqual(const MEDCouplingFieldDouble *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception); + bool isEqualWithoutConsideringStr(const MEDCouplingFieldDouble *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception); void setTimeUnit(const std::string& unit); std::string getTimeUnit() const; void synchronizeTimeWithSupport() throw(INTERP_KERNEL::Exception); @@ -4023,6 +4027,7 @@ namespace MEDCoupling 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); + MEDCouplingFieldFloat *convertToFloatField() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *clone(bool recDeepCpy) const; MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const; MEDCouplingFieldDouble *deepCopy() const; @@ -4130,6 +4135,18 @@ namespace MEDCoupling self->reprQuickOverview(oss); return oss.str(); } + + PyObject *isEqualIfNotWhy(const MEDCouplingFieldDouble *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception) + { + std::string ret1; + bool ret0=self->isEqualIfNotWhy(other,meshPrec,valsPrec,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); + return ret; + } MEDCouplingFieldDouble *voronoize(double eps) const throw(INTERP_KERNEL::Exception) { @@ -5212,6 +5229,8 @@ namespace MEDCoupling public: static MEDCouplingFieldInt *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME); static MEDCouplingFieldInt *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME); + bool isEqual(const MEDCouplingFieldInt *other, double meshPrec, int valsPrec) const throw(INTERP_KERNEL::Exception); + bool isEqualWithoutConsideringStr(const MEDCouplingFieldInt *other, double meshPrec, int valsPrec) const throw(INTERP_KERNEL::Exception); void setTimeUnit(const std::string& unit) throw(INTERP_KERNEL::Exception); std::string getTimeUnit() const throw(INTERP_KERNEL::Exception); void setTime(double val, int iteration, int order) throw(INTERP_KERNEL::Exception); @@ -5232,6 +5251,18 @@ namespace MEDCoupling return MEDCouplingFieldInt::New(ft,td); } + PyObject *isEqualIfNotWhy(const MEDCouplingFieldInt *other, double meshPrec, int valsPrec) const throw(INTERP_KERNEL::Exception) + { + std::string ret1; + bool ret0=self->isEqualIfNotWhy(other,meshPrec,valsPrec,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); + return ret; + } + std::string __str__() const throw(INTERP_KERNEL::Exception) { return self->simpleRepr(); @@ -5310,6 +5341,8 @@ namespace MEDCoupling public: static MEDCouplingFieldFloat *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME); static MEDCouplingFieldFloat *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME); + bool isEqual(const MEDCouplingFieldFloat *other, double meshPrec, float valsPrec) const throw(INTERP_KERNEL::Exception); + bool isEqualWithoutConsideringStr(const MEDCouplingFieldFloat *other, double meshPrec, float valsPrec) const throw(INTERP_KERNEL::Exception); void setTimeUnit(const std::string& unit) throw(INTERP_KERNEL::Exception); std::string getTimeUnit() const throw(INTERP_KERNEL::Exception); void setTime(double val, int iteration, int order) throw(INTERP_KERNEL::Exception); @@ -5330,6 +5363,18 @@ namespace MEDCoupling return MEDCouplingFieldFloat::New(ft,td); } + PyObject *isEqualIfNotWhy(const MEDCouplingFieldFloat *other, double meshPrec, float valsPrec) const throw(INTERP_KERNEL::Exception) + { + std::string ret1; + bool ret0=self->isEqualIfNotWhy(other,meshPrec,valsPrec,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); + return ret; + } + std::string __str__() const throw(INTERP_KERNEL::Exception) { return self->simpleRepr(); diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i index a46926f32..66cb1d33c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i @@ -1718,6 +1718,19 @@ static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& convertFPStarLikePyObjToCpp_2(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple); } +/*! + * if value int -> cpp val sw=1 + * if value double -> cpp val sw=1 + * if value DataArrayDouble -> cpp DataArrayDouble sw=2 + * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3 + * if value list[int,double] -> cpp std::vector sw=4 + * if value tuple[int,double] -> cpp std::vector sw=4 + */ +static void convertFloatStarLikePyObjToCpp_2(PyObject *value, int& sw, float& val, MEDCoupling::DataArrayFloat *&d, MEDCoupling::DataArrayFloatTuple *&e, std::vector& f) +{ + convertFPStarLikePyObjToCpp_2(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayFloat,SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple); +} + /*! * if python int -> cpp int sw=1 * if python list[int] -> cpp vector sw=2 @@ -3366,4 +3379,37 @@ PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCouplin return DataArrayT_isub__internal(trueSelf,obj,self,SWIGTITraits::TI,SWIGTITraits::TI_TUPLE); } +template +typename MEDCoupling::Traits::ArrayType *DataArrayFPT_rmul(typename MEDCoupling::Traits::ArrayType *self, PyObject *obj) +{ + const char msg[]="Unexpected situation in __rmul__ !"; + T val; + typename MEDCoupling::Traits::ArrayType *a; + typename MEDCoupling::Traits::ArrayTuple *aa; + std::vector bb; + int sw; + convertFPStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb,SWIGTITraits::TI,SWIGTITraits::TI_TUPLE); + switch(sw) + { + case 1: + { + typename MEDCoupling::MCAuto::ArrayType> ret(self->deepCopy()); + ret->applyLin(val,0.); + return ret.retn(); + } + case 3: + { + typename MEDCoupling::MCAuto::ArrayType> aaa(aa->buildDA(1,self->getNumberOfComponents())); + return MEDCoupling::Traits::ArrayType::Multiply(self,aaa); + } + case 4: + { + typename MEDCoupling::MCAuto::ArrayType> aaa(MEDCoupling::Traits::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size()); + return MEDCoupling::Traits::ArrayType::Multiply(self,aaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } +} + #endif diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index ab06253fe..17a682bdb 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -73,6 +73,7 @@ %newobject MEDCoupling::DataArrayFloat::iterator; %newobject MEDCoupling::DataArrayFloat::__iter__; %newobject MEDCoupling::DataArrayFloat::Meld; +%newobject MEDCoupling::DataArrayFloat::__rmul__; %newobject MEDCoupling::DataArrayInt::New; %newobject MEDCoupling::DataArrayInt::__iter__; %newobject MEDCoupling::DataArrayInt::performCopyOrIncrRef; @@ -745,6 +746,18 @@ namespace MEDCoupling int nbOfComp(self->getNumberOfComponents()),nbOfTuples(self->getNumberOfTuples()); return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); } + + PyObject *isEqualIfNotWhy(const DataArrayFloat& other, float prec) const throw(INTERP_KERNEL::Exception) + { + std::string ret1; + bool ret0=self->isEqualIfNotWhy(other,prec,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); + return ret; + } PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) { @@ -771,6 +784,11 @@ namespace MEDCoupling return DataArrayT_imul(trueSelf,obj,self); } + DataArrayFloat *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayFPT_rmul(self,obj); + } + PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { return DataArrayT_idiv(trueSelf,obj,self); @@ -1689,34 +1707,7 @@ namespace MEDCoupling DataArrayDouble *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in __rmul__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MCAuto ret=self->deepCopy(); - ret->applyLin(val,0.); - return ret.retn(); - } - case 3: - { - MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Multiply(self,aaa); - } - case 4: - { - MCAuto aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Multiply(self,aaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } + return DataArrayFPT_rmul(self,obj); } PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index cb09988db..3f3d6f45a 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -723,7 +723,14 @@ void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileF goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast(startFeeding)); return ; } - throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !"); + DataArrayFloat *arrF(dynamic_cast(arr)); + if(arrF) + { + float *startFeeding(arrF->getPointer()+_start*nbOfCompo); + goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast(startFeeding)); + return ; + } + throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 FLOAT32 or INT32 !"); } /*! @@ -897,15 +904,18 @@ void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldN throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !"); if(!arr->isAllocated()) throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !"); - const DataArrayDouble *arrD=dynamic_cast(arr); - const DataArrayInt *arrI=dynamic_cast(arr); + const DataArrayDouble *arrD(dynamic_cast(arr)); + const DataArrayInt *arrI(dynamic_cast(arr)); + const DataArrayFloat *arrF(dynamic_cast(arr)); const unsigned char *locToWrite=0; if(arrD) locToWrite=reinterpret_cast(arrD->getConstPointer()+_start*arr->getNumberOfComponents()); else if(arrI) locToWrite=reinterpret_cast(arrI->getConstPointer()+_start*arr->getNumberOfComponents()); + else if(arrF) + locToWrite=reinterpret_cast(arrF->getConstPointer()+_start*arr->getNumberOfComponents()); else - throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !"); + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 FLOAT32 and INT32 !"); MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti, MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval, locToWrite)); @@ -5973,7 +5983,7 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_i ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector()); break; } - case MED_NODE://6432 + case MED_FLOAT32: { ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector()); break; @@ -6033,7 +6043,7 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_i ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector()); break; } - case MED_NODE://6432 + case MED_FLOAT32: { ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector()); break; @@ -6093,7 +6103,13 @@ MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDF ret->_content=c; c->incrRef(); return ret.retn(); } - throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !"); + if(dynamic_cast(c)) + { + MCAuto ret(MEDFileFloatField1TS::New()); + ret->_content=c; c->incrRef(); + return ret.retn(); + } + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !"); } MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid) @@ -6179,7 +6195,7 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_i ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector()); break; } - case MED_NODE://6432 + case MED_FLOAT32: { ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector()); break; @@ -7346,7 +7362,7 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysR _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos); break; } - case MED_NODE://6432 + case MED_FLOAT32: { _time_steps[i]=MEDFileFloatField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos); break; @@ -7996,7 +8012,7 @@ MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFr ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities); break; } - case MED_NODE://6432 + case MED_FLOAT32: { ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities); break; @@ -8032,7 +8048,7 @@ MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFr ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0); break; } - case MED_NODE://6432 + case MED_FLOAT32: { ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0); break; @@ -8064,7 +8080,13 @@ MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromCont ret->_content=c; c->incrRef(); return ret.retn(); } - throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !"); + if(dynamic_cast(c)) + { + MCAuto ret(MEDFileFloatFieldMultiTS::New()); + ret->_content=c; c->incrRef(); + return ret.retn(); + } + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !"); } MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid) @@ -9187,7 +9209,7 @@ try:MEDFileFieldGlobsReal(fid) _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities); break; } - case MED_NODE://6432 + case MED_FLOAT32: { _fields[i]=MEDFileFloatFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities); break; @@ -9523,13 +9545,16 @@ MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const MCAuto ret; const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast(fmts)); const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast(fmts)); + const MEDFileFloatFieldMultiTSWithoutSDA *fmtsC3(dynamic_cast(fmts)); if(fmtsC) ret=MEDFileFieldMultiTS::New(*fmtsC,false); else if(fmtsC2) ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false); + else if(fmtsC3) + ret=MEDFileFloatFieldMultiTS::New(*fmtsC3,false); else { - std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !"; + std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor float (FLOAT32) nor integer (INT32) !"; throw INTERP_KERNEL::Exception(oss.str()); } ret->shallowCpyGlobs(*this); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index c39bfdafd..2749a349a 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -981,7 +981,7 @@ namespace MEDCoupling { friend class MEDFileTemplateField1TS; private: - med_field_type getMEDFileFieldType() const { return MED_INT32; }//6432 + med_field_type getMEDFileFieldType() const { return MED_FLOAT32; } MEDLOADER_EXPORT MEDFileFloatField1TS *shallowCpy() const { return new MEDFileFloatField1TS(*this); } private: ~MEDFileFloatField1TS() { } @@ -1150,7 +1150,7 @@ namespace MEDCoupling protected: MEDFileFloatFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileNDTemplateFieldMultiTSWithoutSDA(fieldName,meshName) { } MEDFileFloatFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities) { } - med_field_type getMEDFileFieldType() const { return MED_INT32; }//6432 + med_field_type getMEDFileFieldType() const { return MED_FLOAT32; } public: MEDLOADER_EXPORT MEDFileFloatFieldMultiTSWithoutSDA() { } }; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 11050bf8c..5093d0473 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -2332,12 +2332,7 @@ namespace MEDCoupling PyObject *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception) { - DataArrayInt *ret1=0; - DataArrayDouble *ret0=self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; + return MEDFileField1TS_getFieldWithProfile(self,type,meshDimRelToMax,mesh); } PyObject *getFieldSplitedByType2(const std::string& mname=std::string()) const throw(INTERP_KERNEL::Exception) @@ -2469,12 +2464,7 @@ namespace MEDCoupling PyObject *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception) { - DataArrayInt *ret1=0; - DataArrayInt *ret0=self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; + return MEDFileField1TS_getFieldWithProfile(self,type,meshDimRelToMax,mesh); } DataArrayInt *getUndergroundDataArray() const throw(INTERP_KERNEL::Exception) @@ -2545,12 +2535,7 @@ namespace MEDCoupling PyObject *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception) { - DataArrayInt *ret1=0; - DataArrayFloat *ret0=self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayFloat, SWIG_POINTER_OWN | 0 )); - return ret; + return MEDFileField1TS_getFieldWithProfile(self,type,meshDimRelToMax,mesh); } DataArrayFloat *getUndergroundDataArray() const throw(INTERP_KERNEL::Exception) diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 8536b2a1d..a368af721 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -5989,6 +5989,118 @@ class MEDLoaderTest3(unittest.TestCase): self.assertTrue(ff1.field(mm).isEqual(f3,1e-12,1e-12)) pass + def testFloat32InMEDFileFieldStar1(self): + """Like testInt32InMEDFileFieldStar1 but with float32 :)""" + fname="Pyfile114.med" + f1=MEDLoaderDataForTest.buildVecFieldOnCells_1(); + f1=f1.convertToFloatField() + m1=f1.getMesh() + mm1=MEDFileUMesh.New() + mm1.setCoords(m1.getCoords()) + mm1.setMeshAtLevel(0,m1) + mm1.setName(m1.getName()) + mm1.write(fname,2) + ff1=MEDFileFloatField1TS() + 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,MEDFileFloatField1TS)) + a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,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 + ff2.write(fname,0) # 2 time steps in + ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells") + self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)]) + self.assertEqual(len(ffs1),2) + self.assertTrue(isinstance(ffs1,MEDFileFloatFieldMultiTS)) + a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1) + self.assertTrue(a.isEqual(f1,1e-12,1e-12)) + a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1) + self.assertTrue(a.isEqual(f1,1e-12,1e-12)) + it=ffs1.__iter__() ; it.next() ; ff2bis=it.next() + a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) + self.assertTrue(a.getArray().isEqual(2*f1.getArray(),1e-7)) + f1.setTime(3.,1,2) ; f1.getArray()[:]*=2 + self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ; f1.getArray()[:]/=2 + bc=DataArrayFloat(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]']) + for it in ffs1: + a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1) + bc+=a.getArray() + pass + self.assertTrue(bc.isEqual(3*f1.getArray(),1e-7)) + nf1=MEDCouplingFieldFloat(ON_NODES) + nf1.setTime(9.,10,-1) + nf1.setMesh(f1.getMesh()) + narr=DataArrayFloat(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0] + nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr) + nff1=MEDFileFloatField1TS.New() + nff1.setFieldNoProfileSBT(nf1) + self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]')) + self.assertEqual(nff1.getTime(),[10,-1,9.0]) + nff1.write(fname,0) + # + nf2=MEDCouplingFieldFloat(ON_NODES) + nf2.setTime(19.,20,-11) + nf2.setMesh(f1.getMesh()) + narr2=DataArrayFloat(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0] + nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2) + nff2=MEDFileFloatField1TS.New() + npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl") + nff2.setFieldProfile(nf2,mm1,0,npfl) + nff2.getFieldWithProfile(ON_NODES,0,mm1) + a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName()) + self.assertTrue(b.isEqual(npfl)) + self.assertTrue(a.isEqual(narr2,1e-7)) + nff2.write(fname,0) + nff2bis=MEDFileFloatField1TS(fname,"VectorFieldOnNodesPfl") + a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName()) + self.assertTrue(b.isEqual(npfl)) + self.assertTrue(a.isEqual(narr2,1e-7)) + # + nf3=MEDCouplingFieldDouble(ON_NODES) + nf3.setName("VectorFieldOnNodesDouble") + nf3.setTime(29.,30,-21) + nf3.setMesh(f1.getMesh()) + nf3.setArray(f1.getMesh().getCoords()) + nff3=MEDFileField1TS.New() + nff3.setFieldNoProfileSBT(nf3) + nff3.write(fname,0) + fs=MEDFileFields(fname) + self.assertEqual(len(fs),4) + ffs=[it for it in fs] + self.assertTrue(isinstance(ffs[0],MEDFileFloatFieldMultiTS)) + self.assertTrue(isinstance(ffs[1],MEDFileFloatFieldMultiTS)) + self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS)) + self.assertTrue(isinstance(ffs[3],MEDFileFloatFieldMultiTS)) + # + self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray(),1e-7)) + self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray(),1e-7)) + self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2,1e-7)) + self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr,1e-7)) + self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12)) + # + nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble") + self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12)) + self.assertRaises(InterpKernelException,MEDFileFloatFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance + self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance + MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21) + self.assertRaises(InterpKernelException,MEDFileFloatField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance + MEDFileFloatField1TS.New(fname,"VectorFieldOnNodes",10,-1) + self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance + # + self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1')) + self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')])) + self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh')) + self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')])) + pass + pass if __name__ == "__main__": diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index f4991ea08..379036af6 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -16,7 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Anthony Geay (CEA/DEN) +// Author : Anthony Geay (EDF R&D) #include @@ -402,3 +402,14 @@ void convertToMapIntDataArrayInt(PyObject *pyMap, std::map +PyObject *MEDFileField1TS_getFieldWithProfile(const typename MLFieldTraits::F1TSType *self, TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) +{ + DataArrayInt *ret1(NULL); + typename MEDCoupling::Traits::ArrayType *ret0(self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1)); + PyObject *ret(PyTuple_New(2)); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; +} +