From 548f49a521b2ea0aaeb6bc4c7de05e93f7a09884 Mon Sep 17 00:00:00 2001 From: ageay Date: Tue, 9 Apr 2013 12:41:57 +0000 Subject: [PATCH] Extend operator __pow__ of MEDCouplingFieldDouble --- src/MEDCoupling/MEDCouplingFieldDouble.cxx | 36 +++++++ src/MEDCoupling/MEDCouplingFieldDouble.hxx | 3 + .../MEDCouplingTimeDiscretization.cxx | 97 +++++++++++++++++++ .../MEDCouplingTimeDiscretization.hxx | 10 ++ 4 files changed, 146 insertions(+) diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 45908d984..afa52106d 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -1936,6 +1936,42 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCoupli return *this; } +/*! + * Directly called by MEDCouplingFieldDouble::operator^. + * + * \sa MEDCouplingFieldDouble::operator^ + */ +MEDCouplingFieldDouble *MEDCouplingFieldDouble::PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) +{ + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::PowFields : input field is NULL !"); + if(!f1->areCompatibleForMul(f2)) + throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply PowFields on them !"); + MEDCouplingTimeDiscretization *td=f1->_time_discr->pow(f2->_time_discr); + td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + ret->setMesh(f1->getMesh()); + return ret; +} + +/*! + * Directly call MEDCouplingFieldDouble::PowFields static method. + * + * \sa MEDCouplingFieldDouble::PowFields + */ +MEDCouplingFieldDouble *MEDCouplingFieldDouble::operator^(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) +{ + return PowFields(this,&other); +} + +const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) +{ + if(!areCompatibleForDiv(&other)) + throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !"); + _time_discr->powEqual(other._time_discr); + return *this; +} + /*! * This method writes the field series 'fs' in the VTK file 'fileName'. * If 'fs' is empty no file is written. If fields lies on more than one mesh an exception will be thrown and no file will be written too. diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 577f54e4b..8d245f56d 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -183,6 +183,9 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return DivideFields(this,&other); } const MEDCouplingFieldDouble &operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator^(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + const MEDCouplingFieldDouble &operator^=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); static void WriteVTK(const char *fileName, const std::vector& fs) throw(INTERP_KERNEL::Exception); public: const MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() const { return _time_discr; } diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 7836e91c4..7ae3e992e 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -1059,6 +1059,27 @@ void MEDCouplingNoTimeLabel::divideEqual(const MEDCouplingTimeDiscretization *ot getArray()->divideEqual(other->getArray()); } +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::pow(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("pow on mismatched time discretization !"); + MEDCouplingAutoRefCountObjectPtr arr=DataArrayDouble::Pow(getArray(),other->getArray()); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + ret->setArray(arr,0); + return ret; +} + +void MEDCouplingNoTimeLabel::powEqual(const MEDCouplingTimeDiscretization *other) +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("NoTimeLabel::powEqual on mismatched time discretization !"); + if(!getArray()) + throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::powEqual : Data Array is NULL !"); + getArray()->powEqual(other->getArray()); +} + MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCpy(bool deepCpy) const { return new MEDCouplingNoTimeLabel(*this,deepCpy); @@ -1531,6 +1552,30 @@ void MEDCouplingWithTimeStep::divideEqual(const MEDCouplingTimeDiscretization *o getArray()->divideEqual(other->getArray()); } +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::pow(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("WithTimeStep::pow on mismatched time discretization !"); + MEDCouplingAutoRefCountObjectPtr arr=DataArrayDouble::Pow(getArray(),other->getArray()); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + ret->setArray(arr,0); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + return ret; +} + +void MEDCouplingWithTimeStep::powEqual(const MEDCouplingTimeDiscretization *other) +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("WithTimeStep::powEqual on mismatched time discretization !"); + if(!getArray()) + throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::powEqual : Data Array is NULL !"); + getArray()->powEqual(other->getArray()); +} + MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCpy(bool deepCpy) const { return new MEDCouplingWithTimeStep(*this,deepCpy); @@ -2058,6 +2103,32 @@ void MEDCouplingConstOnTimeInterval::divideEqual(const MEDCouplingTimeDiscretiza getArray()->divideEqual(other->getArray()); } +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::pow(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("pow on mismatched time discretization !"); + MEDCouplingAutoRefCountObjectPtr arr=DataArrayDouble::Pow(getArray(),other->getArray()); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + ret->setArray(arr,0); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + tmp3=getEndTime(tmp1,tmp2); + ret->setEndTime(tmp3,tmp1,tmp2); + return ret; +} + +void MEDCouplingConstOnTimeInterval::powEqual(const MEDCouplingTimeDiscretization *other) +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("ConstOnTimeInterval::powEqual on mismatched time discretization !"); + if(!getArray()) + throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::powEqual : Data Array is NULL !"); + getArray()->powEqual(other->getArray()); +} + MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& other, bool deepCpy):MEDCouplingTimeDiscretization(other,deepCpy), _start_time(other._start_time),_end_time(other._end_time), _start_iteration(other._start_iteration),_end_iteration(other._end_iteration), @@ -2739,3 +2810,29 @@ void MEDCouplingLinearTime::divideEqual(const MEDCouplingTimeDiscretization *oth getArray()->divideEqual(other->getArray()); getEndArray()->divideEqual(other->getEndArray()); } + +MEDCouplingTimeDiscretization *MEDCouplingLinearTime::pow(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingLinearTime *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("LinearTime::pow on mismatched time discretization !"); + MEDCouplingAutoRefCountObjectPtr arr1=DataArrayDouble::Pow(getArray(),other->getArray()); + MEDCouplingAutoRefCountObjectPtr arr2=DataArrayDouble::Pow(getEndArray(),other->getEndArray()); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + ret->setArray(arr1,0); + ret->setEndArray(arr2,0); + return ret; +} + +void MEDCouplingLinearTime::powEqual(const MEDCouplingTimeDiscretization *other) +{ + const MEDCouplingLinearTime *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !"); + if(!getArray()) + throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array is NULL !"); + if(!getEndArray()) + throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array (end) is NULL !"); + getArray()->powEqual(other->getArray()); + getEndArray()->powEqual(other->getEndArray()); +} diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index d5a51be86..97d134e40 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -75,6 +75,8 @@ namespace ParaMEDMEM virtual void multiplyEqual(const MEDCouplingTimeDiscretization *other) = 0; virtual MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const = 0; virtual void divideEqual(const MEDCouplingTimeDiscretization *other) = 0; + virtual MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const = 0; + virtual void powEqual(const MEDCouplingTimeDiscretization *other) = 0; virtual void getTinySerializationIntInformation(std::vector& tinyInfo) const; virtual void getTinySerializationDbleInformation(std::vector& tinyInfo) const; virtual void getTinySerializationStrInformation(std::vector& tinyInfo) const; @@ -177,6 +179,8 @@ namespace ParaMEDMEM void multiplyEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; void divideEqual(const MEDCouplingTimeDiscretization *other); + MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const; + void powEqual(const MEDCouplingTimeDiscretization *other); bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; bool areCompatible(const MEDCouplingTimeDiscretization *other) const; @@ -238,6 +242,8 @@ namespace ParaMEDMEM void multiplyEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; void divideEqual(const MEDCouplingTimeDiscretization *other); + MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const; + void powEqual(const MEDCouplingTimeDiscretization *other); bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; bool areCompatible(const MEDCouplingTimeDiscretization *other) const; @@ -322,6 +328,8 @@ namespace ParaMEDMEM void multiplyEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; void divideEqual(const MEDCouplingTimeDiscretization *other); + MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const; + void powEqual(const MEDCouplingTimeDiscretization *other); void setStartTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { _start_time=time; _start_iteration=iteration; _start_order=order; } void setEndTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { _end_time=time; _end_iteration=iteration; _end_order=order; } double getStartTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) { iteration=_start_iteration; order=_start_order; return _start_time; } @@ -434,6 +442,8 @@ namespace ParaMEDMEM void multiplyEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; void divideEqual(const MEDCouplingTimeDiscretization *other); + MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const; + void powEqual(const MEDCouplingTimeDiscretization *other); public: static const TypeOfTimeDiscretization DISCRETIZATION=LINEAR_TIME; static const char REPR[]; -- 2.39.2