From: Anthony Geay Date: Fri, 28 Apr 2017 14:53:07 +0000 (+0200) Subject: On the road X-Git-Tag: V8_4_0a1~69 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f609387141a50019ab2c53143f09ca2b750a83f0;p=tools%2Fmedcoupling.git On the road --- diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 988048d99..14494736b 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -30,9 +30,10 @@ using namespace MEDCoupling; template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate; +template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate; +template class MEDCoupling::MEDCouplingTimeDiscretizationSimple; template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate; - -const char MEDCouplingTimeDiscretizationInt::REPR[]="One time label."; +template class MEDCoupling::MEDCouplingTimeDiscretizationSimple; const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setTime : no time info attached."; @@ -760,22 +761,10 @@ void MEDCouplingTimeKeeper::checkTimePresence(double time, double eps) const //////////////////////// -MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt() -{ -} - -MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate(other,deepCopy),_tk(other._tk) +MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple(other,deepCopy) { } -std::string MEDCouplingTimeDiscretizationInt::getStringRepr() const -{ - std::ostringstream stream; - stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << "."; - stream << "\nTime unit is : \"" << _time_unit << "\""; - return stream.str(); -} - MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::performCopyOrIncrRef(bool deepCopy) const { return new MEDCouplingTimeDiscretizationInt(*this,deepCopy); @@ -831,29 +820,65 @@ bool MEDCouplingTimeDiscretizationInt::isEqualWithoutConsideringStr(const MEDCou return _array->isEqualWithoutConsideringStr(*(other->getArray())); } -double MEDCouplingTimeDiscretizationInt::getEndTime(int& iteration, int& order) const +//////////////////////// + +MEDCouplingTimeDiscretizationFloat::MEDCouplingTimeDiscretizationFloat(const MEDCouplingTimeDiscretizationFloat& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple(other,deepCopy) { - throw INTERP_KERNEL::Exception("getEndTime : invalid for this type of time discr !"); } -void MEDCouplingTimeDiscretizationInt::setEndIteration(int it) +MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::performCopyOrIncrRef(bool deepCopy) const { - throw INTERP_KERNEL::Exception("setEndIteration : invalid for this type of time discr !"); + return new MEDCouplingTimeDiscretizationFloat(*this,deepCopy); } -void MEDCouplingTimeDiscretizationInt::setEndOrder(int order) +MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::New(TypeOfTimeDiscretization type) { - throw INTERP_KERNEL::Exception("setEndOrder : invalid for this type of time discr !"); + switch(type) + { + case MEDCouplingTimeDiscretizationFloat::DISCRETIZATION: + return new MEDCouplingTimeDiscretizationFloat; + default: + throw INTERP_KERNEL::Exception("Time discretization not implemented yet for intergers !"); + } } -void MEDCouplingTimeDiscretizationInt::setEndTimeValue(double time) +bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, float prec, std::string& reason) const { - throw INTERP_KERNEL::Exception("setEndTimeValue : invalid for this type of time discr !"); + if(prec!=0) + throw INTERP_KERNEL::Exception("isEqualIfNotWhy : only precision equal to 0 supported for int !"); + if(!other) + { + reason="Time discretization is NULL."; + return false; + } + const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast(other)); + if(!otherC) + throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationFloat !"); + 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); } -void MEDCouplingTimeDiscretizationInt::setEndTime(double time, int iteration, int order) +bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, float prec) const { - throw INTERP_KERNEL::Exception("setEndTime : invalid for this type of time discr !"); + if(prec!=0) + throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr : only precision 0 is supported !"); + const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast(other)); + if(!otherC) + throw INTERP_KERNEL::Exception("isEqualWithoutConsideringStr : other is not a MEDCouplingTimeDiscretizationFloat !"); + std::string tmp; + if(!areStrictlyCompatible(other,tmp)) + return false; + std::string reason; + if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) + return false; + if(_array==other->getArray()) + return true; + return _array->isEqualWithoutConsideringStr(*(other->getArray())); } //////////////////////// diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index c75304ab8..9925c2cd1 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -199,13 +199,12 @@ namespace MEDCoupling MEDCOUPLING_EXPORT virtual void fillFromAnalyticCompo(const DataArrayDouble *loc, int nbOfComp, const std::string& func); MEDCOUPLING_EXPORT virtual void fillFromAnalyticNamedCompo(const DataArrayDouble *loc, int nbOfComp, const std::vector& varsOrder, const std::string& func); }; - - class MEDCouplingTimeDiscretizationInt : public MEDCouplingTimeDiscretizationTemplate + + template + class MEDCouplingTimeDiscretizationSimple : public MEDCouplingTimeDiscretizationTemplate { public: - MEDCouplingTimeDiscretizationInt(); - MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy); - static MEDCouplingTimeDiscretizationInt *New(TypeOfTimeDiscretization type); + std::string getStringRepr() const; double getStartTime(int& iteration, int& order) const { return _tk.getAllInfo(iteration,order); } void setStartIteration(int it) { _tk.setIteration(it); } void setStartOrder(int order) { _tk.setOrder(order); } @@ -216,16 +215,40 @@ namespace MEDCoupling void setEndOrder(int order); void setEndTimeValue(double time); void setEndTime(double time, int iteration, int order); - std::string getStringRepr() const; TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } + protected: + MEDCouplingTimeDiscretizationSimple(const MEDCouplingTimeDiscretizationSimple& other, bool deepCopy); + MEDCouplingTimeDiscretizationSimple() { } + protected: + MEDCouplingTimeKeeper _tk; + private: + MEDCOUPLING_EXPORT static const char REPR[]; + protected: + static const TypeOfTimeDiscretization DISCRETIZATION=ONE_TIME; + }; + + class MEDCouplingTimeDiscretizationInt : public MEDCouplingTimeDiscretizationSimple + { + public: + MEDCouplingTimeDiscretizationInt() { } + MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy); + static MEDCouplingTimeDiscretizationInt *New(TypeOfTimeDiscretization type); MEDCouplingTimeDiscretizationInt *performCopyOrIncrRef(bool deepCopy) const; bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, int prec, std::string& reason) const; bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, int prec) const; + }; + + class MEDCouplingTimeDiscretizationFloat : public MEDCouplingTimeDiscretizationSimple + { + public: + MEDCouplingTimeDiscretizationFloat() { } + MEDCouplingTimeDiscretizationFloat(const MEDCouplingTimeDiscretizationFloat& other, bool deepCopy); + static MEDCouplingTimeDiscretization *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; private: static const TypeOfTimeDiscretization DISCRETIZATION=ONE_TIME; - MEDCOUPLING_EXPORT static const char REPR[]; - protected: - MEDCouplingTimeKeeper _tk; }; class MEDCouplingNoTimeLabel : public MEDCouplingTimeDiscretization diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.txx b/src/MEDCoupling/MEDCouplingTimeDiscretization.txx index 4d96c7cc8..c60dfc79a 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.txx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.txx @@ -28,6 +28,9 @@ namespace MEDCoupling { + template + const char MEDCouplingTimeDiscretizationSimple::REPR[]="One time label."; + template const double MEDCouplingTimeDiscretizationTemplate::TIME_TOLERANCE_DFT=1.e-12; @@ -219,6 +222,50 @@ namespace MEDCoupling arrays.resize(1); arrays[0]=_array; } + + template + std::string MEDCouplingTimeDiscretizationSimple::getStringRepr() const + { + std::ostringstream stream; + stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << "."; + stream << "\nTime unit is : \"" << this->_time_unit << "\""; + return stream.str(); + } + + template + double MEDCouplingTimeDiscretizationSimple::getEndTime(int& iteration, int& order) const + { + throw INTERP_KERNEL::Exception("getEndTime : invalid for this type of time discr !"); + } + + template + void MEDCouplingTimeDiscretizationSimple::setEndIteration(int it) + { + throw INTERP_KERNEL::Exception("setEndIteration : invalid for this type of time discr !"); + } + + template + void MEDCouplingTimeDiscretizationSimple::setEndOrder(int order) + { + throw INTERP_KERNEL::Exception("setEndOrder : invalid for this type of time discr !"); + } + + template + void MEDCouplingTimeDiscretizationSimple::setEndTimeValue(double time) + { + throw INTERP_KERNEL::Exception("setEndTimeValue : invalid for this type of time discr !"); + } + + template + void MEDCouplingTimeDiscretizationSimple::setEndTime(double time, int iteration, int order) + { + throw INTERP_KERNEL::Exception("setEndTime : invalid for this type of time discr !"); + } + + template + MEDCouplingTimeDiscretizationSimple::MEDCouplingTimeDiscretizationSimple(const MEDCouplingTimeDiscretizationSimple& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate(other,deepCopy),_tk(other._tk) + { + } } #endif