From 2516e3ae71a095b1fdbffbddd253af62f8c9fc7c Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 22 Aug 2016 14:16:56 +0200 Subject: [PATCH] Refactoring for MEDCouplingFieldInt --- src/MEDCoupling/MEDCouplingFieldDouble.cxx | 2 +- src/MEDCoupling/MEDCouplingFieldInt.cxx | 77 ++- src/MEDCoupling/MEDCouplingFieldInt.hxx | 13 +- src/MEDCoupling/MEDCouplingFieldTemplate.cxx | 12 + src/MEDCoupling/MEDCouplingFieldTemplate.hxx | 3 + src/MEDCoupling/MEDCouplingMemArray.hxx | 4 +- .../MEDCouplingTimeDiscretization.cxx | 496 +++++++----------- .../MEDCouplingTimeDiscretization.hxx | 228 ++++---- .../MEDCouplingTimeDiscretization.txx | 191 +++++++ src/MEDCoupling_Swig/MEDCouplingCommon.i | 12 + 10 files changed, 606 insertions(+), 432 deletions(-) create mode 100644 src/MEDCoupling/MEDCouplingTimeDiscretization.txx diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index b3e56754c..dc3693c3e 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -900,7 +900,7 @@ MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& f } MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy):MEDCouplingField(other,deepCopy), - _time_discr(other._time_discr->performCopyOrIncrRef(deepCopy)) + _time_discr(dynamic_cast(other._time_discr->performCopyOrIncrRef(deepCopy))) { } diff --git a/src/MEDCoupling/MEDCouplingFieldInt.cxx b/src/MEDCoupling/MEDCouplingFieldInt.cxx index 06c4447b1..aab9a45f1 100644 --- a/src/MEDCoupling/MEDCouplingFieldInt.cxx +++ b/src/MEDCoupling/MEDCouplingFieldInt.cxx @@ -19,6 +19,8 @@ // Author : Yann Pora (EDF R&D) #include "MEDCouplingFieldInt.hxx" +#include "MEDCouplingFieldTemplate.hxx" +#include "MEDCouplingMesh.hxx" using namespace MEDCoupling; @@ -27,17 +29,53 @@ MEDCouplingFieldInt *MEDCouplingFieldInt::New(TypeOfField type, TypeOfTimeDiscre return new MEDCouplingFieldInt(type,td); } +MEDCouplingFieldInt *MEDCouplingFieldInt::New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td) +{ + return new MEDCouplingFieldInt(ft,td); +} + void MEDCouplingFieldInt::checkConsistencyLight() const { MEDCouplingField::checkConsistencyLight(); - if(_array.isNull()) - throw INTERP_KERNEL::Exception("MEDCouplingFieldInt::checkConsistencyLight : array is null !"); + _time_discr->checkConsistencyLight(); _type->checkCoherencyBetween(_mesh,getArray()); } std::string MEDCouplingFieldInt::simpleRepr() const { - return std::string(); + std::ostringstream ret; + ret << "FieldInt with name : \"" << getName() << "\"\n"; + ret << "Description of field is : \"" << getDescription() << "\"\n"; + if(_type) + { ret << "FieldInt space discretization is : " << _type->getStringRepr() << "\n"; } + else + { ret << "FieldInt has no spatial discretization !\n"; } + if(_time_discr) + { ret << "FieldInt time discretization is : " << _time_discr->getStringRepr() << "\n"; } + else + { ret << "FieldInt has no time discretization !\n"; } + ret << "FieldInt nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n"; + if(getArray()) + { + if(getArray()->isAllocated()) + { + int nbOfCompo=getArray()->getNumberOfComponents(); + ret << "FieldInt default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; + ret << "FieldInt default array has following info on components : "; + for(int i=0;igetInfoOnComponent(i) << "\" "; + ret << "\n"; + } + else + { + ret << "Array set but not allocated !\n"; + } + } + if(_mesh) + ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr(); + else + ret << "Mesh support information : No mesh set !\n"; + return ret.str(); } void MEDCouplingFieldInt::reprQuickOverview(std::ostream& stream) const @@ -66,42 +104,28 @@ double MEDCouplingFieldInt::getTime(int& iteration, int& order) const void MEDCouplingFieldInt::setArray(DataArrayInt *array) { - MCAuto array2(array); - if(array2.isNotNull()) - array2->incrRef(); - _array=array2; - //_time_discr->setArray(array,this); + _time_discr->setArray(array,this); } const DataArrayInt *MEDCouplingFieldInt::getArray() const { - return _array; + return _time_discr->getArray(); } DataArrayInt *MEDCouplingFieldInt::getArray() { - return _array; + return _time_discr->getArray(); } -MEDCouplingFieldInt::MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type),_time_discr(MEDCouplingTimeDiscretization::New(td)) +MEDCouplingFieldInt::MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type),_time_discr(MEDCouplingTimeDiscretizationInt::New(td)) { } -MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy):MEDCouplingField(other,deepCopy),_time_discr(other._time_discr->performCopyOrIncrRef(deepCopy)) +MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy):MEDCouplingField(other,deepCopy),_time_discr(dynamic_cast(other._time_discr->performCopyOrIncrRef(deepCopy))) { - if(other._array.isNull()) - return ; - if(deepCopy) - { - _array=other._array->deepCopy(); - } - else - { - _array=other._array; - } } -MEDCouplingFieldInt::MEDCouplingFieldInt(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type):MEDCouplingField(type,n),_time_discr(td) +MEDCouplingFieldInt::MEDCouplingFieldInt(NatureOfField n, MEDCouplingTimeDiscretizationInt *td, MEDCouplingFieldDiscretization *type):MEDCouplingField(type,n),_time_discr(td) { } @@ -109,3 +133,10 @@ MEDCouplingFieldInt::~MEDCouplingFieldInt() { delete _time_discr; } + +/*! + * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! ** + */ +MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingField(ft,false),_time_discr(MEDCouplingTimeDiscretizationInt::New(td)) +{ +} diff --git a/src/MEDCoupling/MEDCouplingFieldInt.hxx b/src/MEDCoupling/MEDCouplingFieldInt.hxx index 5986efb60..71dbda7bf 100644 --- a/src/MEDCoupling/MEDCouplingFieldInt.hxx +++ b/src/MEDCoupling/MEDCouplingFieldInt.hxx @@ -18,8 +18,8 @@ // // Author : Yann Pora (EDF R&D) -#ifndef __PARAMEDMEM_MEDCOUPLINGFIELDINT_HXX__ -#define __PARAMEDMEM_MEDCOUPLINGFIELDINT_HXX__ +#ifndef __MEDCOUPLINGFIELDINT_HXX__ +#define __MEDCOUPLINGFIELDINT_HXX__ #include "MEDCoupling.hxx" #include "MEDCouplingField.hxx" @@ -30,10 +30,13 @@ namespace MEDCoupling { + class MEDCouplingFieldTemplate; + class MEDCouplingFieldInt : public MEDCouplingField { public: MEDCOUPLING_EXPORT static MEDCouplingFieldInt *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME); + MEDCOUPLING_EXPORT static MEDCouplingFieldInt *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME); MEDCOUPLING_EXPORT void checkConsistencyLight() const; MEDCOUPLING_EXPORT std::string simpleRepr() const; MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; @@ -47,11 +50,11 @@ namespace MEDCoupling protected: MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td); MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy); - MEDCouplingFieldInt(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type); + MEDCouplingFieldInt(NatureOfField n, MEDCouplingTimeDiscretizationInt *td, MEDCouplingFieldDiscretization *type); + MEDCouplingFieldInt(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td); ~MEDCouplingFieldInt(); private: - MEDCouplingTimeDiscretization *_time_discr; - MCAuto _array;// agy : don't panic ! this is temporary ! templatization of time discr is planned ! + MEDCouplingTimeDiscretizationInt *_time_discr; }; } diff --git a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx index f1f0d8a14..4f2893ab5 100644 --- a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx +++ b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx @@ -20,6 +20,7 @@ #include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingMesh.hxx" +#include "MEDCouplingFieldInt.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldDiscretization.hxx" @@ -32,6 +33,11 @@ MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldDo return new MEDCouplingFieldTemplate(f); } +MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldInt& f) +{ + return new MEDCouplingFieldTemplate(f); +} + /*! * The user should \b not use this method. Only useful for CORBA serialization/unserialization. */ @@ -46,6 +52,12 @@ MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& checkConsistencyLight(); } +MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f):MEDCouplingField(f,false) +{ + forceTimeOfThis(f); + checkConsistencyLight(); +} + MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(TypeOfField type):MEDCouplingField(type) { } diff --git a/src/MEDCoupling/MEDCouplingFieldTemplate.hxx b/src/MEDCoupling/MEDCouplingFieldTemplate.hxx index cc4fddbc3..a00ba79ff 100644 --- a/src/MEDCoupling/MEDCouplingFieldTemplate.hxx +++ b/src/MEDCoupling/MEDCouplingFieldTemplate.hxx @@ -25,6 +25,7 @@ namespace MEDCoupling { + class MEDCouplingFieldInt; class MEDCouplingFieldDouble; /*! * \brief A field template can be seen as a field without the array of values. @@ -40,6 +41,7 @@ namespace MEDCoupling { public: MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(const MEDCouplingFieldDouble& f); + MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(const MEDCouplingFieldInt& f); MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *New(TypeOfField type); MEDCOUPLING_EXPORT std::string simpleRepr() const; MEDCOUPLING_EXPORT std::string advancedRepr() const; @@ -55,6 +57,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; private: MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f); + MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f); MEDCouplingFieldTemplate(TypeOfField type); }; } diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 6162b095e..5d7378760 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -18,8 +18,8 @@ // // Author : Anthony Geay (CEA/DEN) -#ifndef __PARAMEDMEM_MEDCOUPLINGMEMARRAY_HXX__ -#define __PARAMEDMEM_MEDCOUPLINGMEMARRAY_HXX__ +#ifndef __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__ +#define __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__ #include "MEDCoupling.hxx" #include "MEDCouplingTimeLabel.hxx" diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 5aaca490a..db9a43ade 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -18,20 +18,21 @@ // // Author : Anthony Geay (CEA/DEN) -#include "MEDCouplingTimeDiscretization.hxx" +#include "MEDCouplingTimeDiscretization.txx" #include "MCAuto.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingMesh.hxx" -#include -#include #include #include #include using namespace MEDCoupling; -const double MEDCouplingTimeDiscretization::TIME_TOLERANCE_DFT=1.e-12; +template class MEDCouplingTimeDiscretizationTemplate; +template class MEDCouplingTimeDiscretizationTemplate; + +const char MEDCouplingTimeDiscretizationInt::REPR[]="One time label."; const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setTime : no time info attached."; @@ -66,88 +67,6 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDisc } } -void MEDCouplingTimeDiscretization::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) -{ - _time_tolerance=other._time_tolerance; - _time_unit=other._time_unit; -} - -void MEDCouplingTimeDiscretization::copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other) -{ - _time_unit=other._time_unit; - if(_array && other._array) - _array->copyStringInfoFrom(*other._array); -} - -void MEDCouplingTimeDiscretization::checkConsistencyLight() const -{ - if(!_array) - throw INTERP_KERNEL::Exception("Field invalid because no values set !"); - if(_time_tolerance<0.) - throw INTERP_KERNEL::Exception("time tolerance is expected to be greater than 0. !"); -} - -void MEDCouplingTimeDiscretization::updateTime() const -{ - if(_array) - updateTimeWith(*_array); -} - -std::size_t MEDCouplingTimeDiscretization::getHeapMemorySizeWithoutChildren() const -{ - std::size_t ret(_time_unit.capacity()); - return ret; -} - -std::vector MEDCouplingTimeDiscretization::getDirectChildrenWithNull() const -{ - std::vector ret; - ret.push_back(_array); - return ret; -} - -bool MEDCouplingTimeDiscretization::areCompatible(const MEDCouplingTimeDiscretization *other) const -{ - if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) - return false; - if(_array==0 && other->_array==0) - return true; - if(_array==0 || other->_array==0) - return false; - if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents()) - return false; - return true; -} - -bool MEDCouplingTimeDiscretization::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const -{ - std::ostringstream oss; oss.precision(15); - if(_time_unit!=other->_time_unit) - { - oss << "Field discretizations differ : this time unit = \"" << _time_unit << "\" and other time unit = \"" << other->_time_unit << "\" !"; - reason=oss.str(); - return false; - } - if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) - { - oss << "Field discretizations differ : this time tolerance = \"" << _time_tolerance << "\" and other time tolerance = \"" << other->_time_tolerance << "\" !"; - reason=oss.str(); - return false; - } - if(_array==0 && other->_array==0) - return true; - if(_array==0 || other->_array==0) - { - reason="Field discretizations differ : Only one timediscretization between the two this and other has a DataArrayDouble for values defined"; - return false; - } - if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents()) - return false; - if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples()) - return false; - return true; -} - bool MEDCouplingTimeDiscretization::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const { if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) @@ -161,37 +80,6 @@ bool MEDCouplingTimeDiscretization::areCompatibleForMeld(const MEDCouplingTimeDi return true; } -bool MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const -{ - if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) - return false; - if(_array==0 && other->_array==0) - return true; - if(_array==0 || other->_array==0) - return false; - int nbC1=_array->getNumberOfComponents(); - int nbC2=other->_array->getNumberOfComponents(); - int nbMin=std::min(nbC1,nbC2); - if(nbC1!=nbC2 && nbMin!=1) - return false; - return true; -} - -bool MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const -{ - if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) - return false; - if(_array==0 && other->_array==0) - return true; - if(_array==0 || other->_array==0) - return false; - int nbC1=_array->getNumberOfComponents(); - int nbC2=other->_array->getNumberOfComponents(); - if(nbC1!=nbC2 && nbC2!=1) - return false; - return true; -} - bool MEDCouplingTimeDiscretization::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const { if(!areStrictlyCompatible(other,reason)) @@ -296,38 +184,6 @@ void MEDCouplingTimeDiscretization::getTinySerializationStrInformation(std::vect tinyInfo.push_back(_array->getInfoOnComponent(i)); } -MEDCouplingTimeDiscretization::MEDCouplingTimeDiscretization():_time_tolerance(TIME_TOLERANCE_DFT),_array(0) -{ -} - -MEDCouplingTimeDiscretization::MEDCouplingTimeDiscretization(const MEDCouplingTimeDiscretization& other, bool deepCopy):_time_unit(other._time_unit),_time_tolerance(other._time_tolerance) -{ - if(other._array) - _array=other._array->performCopyOrIncrRef(deepCopy); - else - _array=0; -} - -MEDCouplingTimeDiscretization::~MEDCouplingTimeDiscretization() -{ - if(_array) - _array->decrRef(); -} - -void MEDCouplingTimeDiscretization::setArray(DataArrayDouble *array, TimeLabel *owner) -{ - if(array!=_array) - { - if(_array) - _array->decrRef(); - _array=array; - if(_array) - _array->incrRef(); - if(owner) - owner->declareAsNew(); - } -} - const DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray() const { throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !"); @@ -889,6 +745,97 @@ void MEDCouplingTimeDiscretization::fillFromAnalyticNamedCompo(const DataArrayDo setArrays(arrays3,0); } +//////////////////////// + +bool MEDCouplingTimeKeeper::isEqualIfNotWhy(const MEDCouplingTimeKeeper& other, double prec, std::string& reason) const +{ + std::ostringstream oss; + if(_iteration!=other._iteration) + { + oss << "iterations differ. this iteration=" << _iteration << " other iteration=" << other._iteration; + reason=oss.str(); + return false; + } + if(_order!=other._order) + { + oss << "orders differ. this order=" << _order << " other order=" << other._order; + reason=oss.str(); + return false; + } + if(std::fabs(_time-other._time)>prec) + { + oss << "times differ. this time=" << _time << " other time=" << other._time; + reason=oss.str(); + return false; + } + return true; +} + +bool MEDCouplingTimeKeeper::isEqual(const MEDCouplingTimeKeeper& other, double prec) const +{ + if(_iteration!=other._iteration) + return false; + if(_order!=other._order) + return false; + if(std::fabs(_time-other._time)>prec) + return false; + return true; +} + +void MEDCouplingTimeKeeper::copyFrom(const MEDCouplingTimeKeeper& other) +{ + _time=other._time; + _iteration=other._iteration; + _order=other._order; +} + +void MEDCouplingTimeKeeper::checkTimePresence(double time, double eps) const +{ + if(std::fabs(time-_time)>eps) + { + std::ostringstream stream; + stream << "The field is defined on time " << _time << " with eps=" << eps << " and asking time = " << time << " !"; + throw INTERP_KERNEL::Exception(stream.str().c_str()); + } +} + +//////////////////////// + +MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt() +{ +} + +MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate(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); +} + +MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::New(TypeOfTimeDiscretization type) +{ + switch(type) + { + case MEDCouplingTimeDiscretizationInt::DISCRETIZATION: + return new MEDCouplingTimeDiscretizationInt; + default: + throw INTERP_KERNEL::Exception("Time discretization not implemented yet for intergers !"); + } +} + + +//////////////////////// + MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel() { } @@ -910,7 +857,7 @@ void MEDCouplingNoTimeLabel::synchronizeTimeWith(const MEDCouplingMesh *mesh) throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::synchronizeTimeWith : impossible to synchronize time with a MEDCouplingMesh because the time discretization is incompatible with it !"); } -bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areCompatible(other)) return false; @@ -918,7 +865,7 @@ bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretization * return otherC!=0; } -bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const +bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason)) return false; @@ -929,7 +876,7 @@ bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscreti return ret; } -bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other)) return false; @@ -937,7 +884,7 @@ bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDi return otherC!=0; } -bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) return false; @@ -1278,19 +1225,18 @@ void MEDCouplingNoTimeLabel::finishUnserialization2(const std::vector& tiny _time_tolerance=tinyInfoD[0]; } -MEDCouplingWithTimeStep::MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy), - _time(other._time),_iteration(other._iteration),_order(other._order) +MEDCouplingWithTimeStep::MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy),_tk(other._tk) { } -MEDCouplingWithTimeStep::MEDCouplingWithTimeStep():_time(0.),_iteration(-1),_order(-1) +MEDCouplingWithTimeStep::MEDCouplingWithTimeStep() { } std::string MEDCouplingWithTimeStep::getStringRepr() const { std::ostringstream stream; - stream << REPR << " Time is defined by iteration=" << _iteration << " order=" << _order << " and time=" << _time << "."; + 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(); } @@ -1301,7 +1247,7 @@ void MEDCouplingWithTimeStep::synchronizeTimeWith(const MEDCouplingMesh *mesh) throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !"); int it=-1,order=-1; double val=mesh->getTime(it,order); - _time=val; _iteration=it; _order=order; + _tk.setAllInfo(val,it,order); std::string tUnit=mesh->getTimeUnit(); _time_unit=tUnit; } @@ -1309,22 +1255,22 @@ void MEDCouplingWithTimeStep::synchronizeTimeWith(const MEDCouplingMesh *mesh) void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo); - tinyInfo.push_back(_iteration); - tinyInfo.push_back(_order); + tinyInfo.push_back(_tk.getIteration()); + tinyInfo.push_back(_tk.getOrder()); } void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo); - tinyInfo.push_back(_time); + tinyInfo.push_back(_tk.getTimeValue()); } void MEDCouplingWithTimeStep::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) { MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS); - _time=tinyInfoD[1]; - _iteration=tinyInfoI[2]; - _order=tinyInfoI[3]; + _tk.setTimeValue(tinyInfoD[1]); + _tk.setIteration(tinyInfoI[2]); + _tk.setOrder(tinyInfoI[3]); } /*! @@ -1333,8 +1279,8 @@ void MEDCouplingWithTimeStep::finishUnserialization(const std::vector& tiny void MEDCouplingWithTimeStep::getTinySerializationIntInformation2(std::vector& tinyInfo) const { tinyInfo.resize(2); - tinyInfo[0]=_iteration; - tinyInfo[1]=_order; + tinyInfo[0]=_tk.getIteration(); + tinyInfo[1]=_tk.getOrder(); } /*! @@ -1344,7 +1290,7 @@ void MEDCouplingWithTimeStep::getTinySerializationDbleInformation2(std::vector& tinyInfoI, const std::vector& tinyInfoD) { - _iteration=tinyInfoI[0]; - _order=tinyInfoI[1]; + _tk.setIteration(tinyInfoI[0]); + _tk.setOrder(tinyInfoI[1]); _time_tolerance=tinyInfoD[0]; - _time=tinyInfoD[1]; + _tk.setTimeValue(tinyInfoD[1]); } -bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areCompatible(other)) return false; @@ -1366,7 +1312,7 @@ bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretization return otherC!=0; } -bool MEDCouplingWithTimeStep::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const +bool MEDCouplingWithTimeStep::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason)) return false; @@ -1377,7 +1323,7 @@ bool MEDCouplingWithTimeStep::areStrictlyCompatible(const MEDCouplingTimeDiscret return ret; } -bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other)) return false; @@ -1385,7 +1331,7 @@ bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeD return otherC!=0; } -bool MEDCouplingWithTimeStep::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingWithTimeStep::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) return false; @@ -1410,24 +1356,8 @@ bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretizatio reason="This has time discretization ONE_TIME, other not."; return false; } - if(_iteration!=otherC->_iteration) - { - oss << "iterations differ. this iteration=" << _iteration << " other iteration=" << otherC->_iteration; - reason=oss.str(); - return false; - } - if(_order!=otherC->_order) - { - oss << "orders differ. this order=" << _order << " other order=" << otherC->_order; - reason=oss.str(); - return false; - } - if(std::fabs(_time-otherC->_time)>_time_tolerance) - { - oss << "times differ. this time=" << _time << " other time=" << otherC->_time; - reason=oss.str(); - return false; - } + if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) + return false; return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason); } @@ -1436,24 +1366,18 @@ bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTime const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) return false; - if(_iteration!=otherC->_iteration) - return false; - if(_order!=otherC->_order) - return false; - if(std::fabs(_time-otherC->_time)>_time_tolerance) - return false; + if(!_tk.isEqual(otherC->_tk,_time_tolerance)) + return false; return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); } -void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) +void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate& other) { MEDCouplingTimeDiscretization::copyTinyAttrFrom(other); const MEDCouplingWithTimeStep *otherC=dynamic_cast(&other); if(!otherC) throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::copyTinyAttrFrom : mismatch of time discretization !"); - _time=otherC->_time; - _iteration=otherC->_iteration; - _order=otherC->_order; + _tk.copyFrom(otherC->_tk); } MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCouplingTimeDiscretization *other) const @@ -1671,17 +1595,12 @@ void MEDCouplingWithTimeStep::checkNoTimePresence() const void MEDCouplingWithTimeStep::checkTimePresence(double time) const { - if(std::fabs(time-_time)>_time_tolerance) - { - std::ostringstream stream; - stream << "The field is defined on time " << _time << " with eps=" << _time_tolerance << " and asking time = " << time << " !"; - throw INTERP_KERNEL::Exception(stream.str().c_str()); - } + _tk.checkTimePresence(time,_time_tolerance); } std::vector< const DataArrayDouble *> MEDCouplingWithTimeStep::getArraysForTime(double time) const { - if(std::fabs(time-_time)<=_time_tolerance) + if(std::fabs(time-_tk.getTimeValue())<=_time_tolerance) { std::vector< const DataArrayDouble *> ret(1); ret[0]=_array; @@ -1698,7 +1617,7 @@ void MEDCouplingWithTimeStep::getValueForTime(double time, const std::vectorgetTuple(eltId,value); else @@ -1709,7 +1628,7 @@ void MEDCouplingWithTimeStep::getValueOnTime(int eltId, double time, double *val void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const { - if(_iteration==iteration && _order==order) + if(_tk.getIteration()==iteration && _tk.getOrder()==order) if(_array) _array->getTuple(eltId,value); else @@ -1718,49 +1637,45 @@ void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int iteration, int o throw INTERP_KERNEL::Exception("No data on this discrete time."); } -MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval():_start_time(0.),_end_time(0.),_start_iteration(-1),_end_iteration(-1),_start_order(-1),_end_order(-1) +MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval() { } -void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) +void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate& other) { MEDCouplingTimeDiscretization::copyTinyAttrFrom(other); const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(&other); if(!otherC) throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::copyTinyAttrFrom : mismatch of time discretization !"); - _start_time=otherC->_start_time; - _end_time=otherC->_end_time; - _start_iteration=otherC->_start_iteration; - _end_iteration=otherC->_end_iteration; - _start_order=otherC->_start_order; - _end_order=otherC->_end_order; + _start.copyFrom(otherC->_start); + _end.copyFrom(otherC->_end); } void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo); - tinyInfo.push_back(_start_iteration); - tinyInfo.push_back(_start_order); - tinyInfo.push_back(_end_iteration); - tinyInfo.push_back(_end_order); + tinyInfo.push_back(_start.getIteration()); + tinyInfo.push_back(_start.getOrder()); + tinyInfo.push_back(_end.getIteration()); + tinyInfo.push_back(_end.getOrder()); } void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo); - tinyInfo.push_back(_start_time); - tinyInfo.push_back(_end_time); + tinyInfo.push_back(_start.getTimeValue()); + tinyInfo.push_back(_end.getTimeValue()); } void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) { MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS); - _start_time=tinyInfoD[1]; - _end_time=tinyInfoD[2]; - _start_iteration=tinyInfoI[2]; - _start_order=tinyInfoI[3]; - _end_iteration=tinyInfoI[4]; - _end_order=tinyInfoI[5]; + _start.setTimeValue(tinyInfoD[1]); + _end.setTimeValue(tinyInfoD[2]); + _start.setIteration(tinyInfoI[2]); + _start.setOrder(tinyInfoI[3]); + _end.setIteration(tinyInfoI[4]); + _end.setOrder(tinyInfoI[5]); } /*! @@ -1769,10 +1684,10 @@ void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector& tinyInfo) const { tinyInfo.resize(4); - tinyInfo[0]=_start_iteration; - tinyInfo[1]=_start_order; - tinyInfo[2]=_end_iteration; - tinyInfo[3]=_end_order; + tinyInfo[0]=_start.getIteration(); + tinyInfo[1]=_start.getOrder(); + tinyInfo[2]=_end.getIteration(); + tinyInfo[3]=_end.getOrder(); } /*! @@ -1782,8 +1697,8 @@ void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation2(std::v { tinyInfo.resize(3); tinyInfo[0]=_time_tolerance; - tinyInfo[1]=_start_time; - tinyInfo[2]=_end_time; + tinyInfo[1]=_start.getTimeValue(); + tinyInfo[2]=_end.getTimeValue(); } /*! @@ -1791,26 +1706,25 @@ void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation2(std::v */ void MEDCouplingConstOnTimeInterval::finishUnserialization2(const std::vector& tinyInfoI, const std::vector& tinyInfoD) { - _start_iteration=tinyInfoI[0]; - _start_order=tinyInfoI[1]; - _end_iteration=tinyInfoI[2]; - _end_order=tinyInfoI[3]; + _start.setIteration(tinyInfoI[0]); + _start.setOrder(tinyInfoI[1]); + _end.setIteration(tinyInfoI[2]); + _end.setOrder(tinyInfoI[3]); _time_tolerance=tinyInfoD[0]; - _start_time=tinyInfoD[1]; - _end_time=tinyInfoD[2]; + _start.setTimeValue(tinyInfoD[1]); + _end.setTimeValue(tinyInfoD[2]); } MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCopy): - MEDCouplingTimeDiscretization(other,deepCopy),_start_time(other._start_time),_end_time(other._end_time),_start_iteration(other._start_iteration), - _end_iteration(other._end_iteration),_start_order(other._start_order),_end_order(other._end_order) + MEDCouplingTimeDiscretization(other,deepCopy),_start(other._start),_end(other._end) { } std::string MEDCouplingConstOnTimeInterval::getStringRepr() const { std::ostringstream stream; - stream << REPR << " Time interval is defined by :\niteration_start=" << _start_iteration << " order_start=" << _start_order << " and time_start=" << _start_time << "\n"; - stream << "iteration_end=" << _end_iteration << " order_end=" << _end_order << " and end_time=" << _end_time << "\n"; + stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n"; + stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n"; stream << "\nTime unit is : \"" << _time_unit << "\""; return stream.str(); } @@ -1821,9 +1735,9 @@ void MEDCouplingConstOnTimeInterval::synchronizeTimeWith(const MEDCouplingMesh * throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !"); int it=-1,order=-1; double val=mesh->getTime(it,order); - _start_time=val; _start_iteration=it; _start_order=order; - _end_time=val; _end_iteration=it; _end_order=order; - std::string tUnit=mesh->getTimeUnit(); + _start.setAllInfo(val,it,order); + _end.setAllInfo(val,it,order); + std::string tUnit(mesh->getTimeUnit()); _time_unit=tUnit; } @@ -1834,7 +1748,7 @@ MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCopyOrIncr std::vector< const DataArrayDouble *> MEDCouplingConstOnTimeInterval::getArraysForTime(double time) const { - if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance) + if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance) { std::vector< const DataArrayDouble *> ret(1); ret[0]=_array; @@ -1849,7 +1763,7 @@ void MEDCouplingConstOnTimeInterval::getValueForTime(double time, const std::vec std::copy(vals.begin(),vals.end(),res); } -bool MEDCouplingConstOnTimeInterval::areCompatible(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingConstOnTimeInterval::areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areCompatible(other)) return false; @@ -1857,7 +1771,7 @@ bool MEDCouplingConstOnTimeInterval::areCompatible(const MEDCouplingTimeDiscreti return otherC!=0; } -bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const +bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason)) return false; @@ -1868,7 +1782,7 @@ bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTime return ret; } -bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other)) return false; @@ -1876,7 +1790,7 @@ bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCoupli return otherC!=0; } -bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) return false; @@ -1901,42 +1815,10 @@ bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscre reason="This has time discretization CONST_ON_TIME_INTERVAL, other not."; return false; } - if(_start_iteration!=otherC->_start_iteration) - { - oss << "start iterations differ. this start iteration=" << _start_iteration << " other start iteration=" << otherC->_start_iteration; - reason=oss.str(); - return false; - } - if(_start_order!=otherC->_start_order) - { - oss << "start orders differ. this start order=" << _start_order << " other start order=" << otherC->_start_order; - reason=oss.str(); - return false; - } - if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance) - { - oss << "start times differ. this start time=" << _start_time << " other start time=" << otherC->_start_time; - reason=oss.str(); - return false; - } - if(_end_iteration!=otherC->_end_iteration) - { - oss << "end iterations differ. this end iteration=" << _end_iteration << " other end iteration=" << otherC->_end_iteration; - reason=oss.str(); - return false; - } - if(_end_order!=otherC->_end_order) - { - oss << "end orders differ. this end order=" << _end_order << " other end order=" << otherC->_end_order; - reason=oss.str(); - return false; - } - if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance) - { - oss << "end times differ. this end time=" << _end_time << " other end time=" << otherC->_end_time; - reason=oss.str(); - return false; - } + if(!_start.isEqualIfNotWhy(otherC->_start,_time_tolerance,reason)) + return false; + if(!_end.isEqualIfNotWhy(otherC->_end,_time_tolerance,reason)) + return false; return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason); } @@ -1945,24 +1827,16 @@ bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCoupl const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); if(!otherC) return false; - if(_start_iteration!=otherC->_start_iteration) - return false; - if(_start_order!=otherC->_start_order) - return false; - if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance) - return false; - if(_end_iteration!=otherC->_end_iteration) - return false; - if(_end_order!=otherC->_end_order) + if(!_start.isEqual(otherC->_start,_time_tolerance)) return false; - if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance) + if(!_end.isEqual(otherC->_end,_time_tolerance)) return false; return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); } void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, double *value) const { - if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance) + if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance) if(_array) _array->getTuple(eltId,value); else @@ -1973,7 +1847,7 @@ void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, doub void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const { - if(iteration>=_start_iteration && iteration<=_end_iteration) + if(iteration>=_start.getIteration() && iteration<=_end.getIteration()) if(_array) _array->getTuple(eltId,value); else @@ -1989,10 +1863,10 @@ void MEDCouplingConstOnTimeInterval::checkNoTimePresence() const void MEDCouplingConstOnTimeInterval::checkTimePresence(double time) const { - if(time<_start_time-_time_tolerance || time>_end_time+_time_tolerance) + if(time<_start.getTimeValue()-_time_tolerance || time>_end.getTimeValue()+_time_tolerance) { std::ostringstream stream; - stream << "The field is defined between times " << _start_time << " and " << _end_time << " worderh tolerance "; + stream << "The field is defined between times " << _start.getTimeValue() << " and " << _end.getTimeValue() << " worderh tolerance "; stream << _time_tolerance << " and trying to access on time = " << time; throw INTERP_KERNEL::Exception(stream.str().c_str()); } @@ -2254,7 +2128,7 @@ std::vector MEDCouplingTwoTimeSteps::getDirectChildrenW return ret; } -void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) +void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate& other) { MEDCouplingTimeDiscretization::copyTinyAttrFrom(other); const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(&other); @@ -2268,7 +2142,7 @@ void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretizati _end_order=otherC->_end_order; } -void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other) +void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate& other) { MEDCouplingTimeDiscretization::copyTinyStringsFrom(other); const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(&other); @@ -2607,7 +2481,7 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::performCopyOrIncrRef(bool return new MEDCouplingLinearTime(*this,deepCopy); } -bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areCompatible(other)) return false; @@ -2623,7 +2497,7 @@ bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretization *o return true; } -bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const +bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason)) return false; @@ -2634,7 +2508,7 @@ bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretiz return ret; } -bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other)) return false; @@ -2642,7 +2516,7 @@ bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDis return otherC!=0; } -bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const +bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) return false; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index 373981bf9..2b88a67c5 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -18,13 +18,14 @@ // // Author : Anthony Geay (CEA/DEN) -#ifndef __PARAMEDMEM_MEDCOUPLINGTIMEDISCRETIZATION_HXX__ -#define __PARAMEDMEM_MEDCOUPLINGTIMEDISCRETIZATION_HXX__ +#ifndef __MEDCOUPLINGTIMEDISCRETIZATION_HXX__ +#define __MEDCOUPLINGTIMEDISCRETIZATION_HXX__ #include "MEDCoupling.hxx" #include "MEDCouplingTimeLabel.hxx" #include "MEDCouplingRefCountObject.hxx" #include "InterpKernelException.hxx" +#include "MEDCouplingTraits.hxx" #include @@ -34,32 +35,88 @@ namespace MEDCoupling class DataArrayDouble; class TimeLabel; - class MEDCouplingTimeDiscretization : public TimeLabel, public BigMemoryObject + template + class MEDCouplingTimeDiscretizationTemplate : public TimeLabel, public BigMemoryObject { - protected: - MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization(); - MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization(const MEDCouplingTimeDiscretization& other, bool deepCopy); public: MEDCOUPLING_EXPORT void updateTime() const; - MEDCOUPLING_EXPORT virtual std::size_t getHeapMemorySizeWithoutChildren() const; - MEDCOUPLING_EXPORT virtual std::vector getDirectChildrenWithNull() const; - MEDCOUPLING_EXPORT static MEDCouplingTimeDiscretization *New(TypeOfTimeDiscretization type); + MEDCOUPLING_EXPORT virtual void setArray(typename Traits::ArrayType *array, TimeLabel *owner); + MEDCOUPLING_EXPORT typename Traits::ArrayType *getArray() { return _array; } + MEDCOUPLING_EXPORT const typename Traits::ArrayType *getArray() const { return _array; } MEDCOUPLING_EXPORT void setTimeUnit(const std::string& unit) { _time_unit=unit; } MEDCOUPLING_EXPORT std::string getTimeUnit() const { return _time_unit; } - MEDCOUPLING_EXPORT virtual void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other); - MEDCOUPLING_EXPORT virtual void copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other); + MEDCOUPLING_EXPORT void setTimeTolerance(double val) { _time_tolerance=val; } + MEDCOUPLING_EXPORT double getTimeTolerance() const { return _time_tolerance; } + MEDCOUPLING_EXPORT double getTime(int& iteration, int& order) const { return getStartTime(iteration,order); } + MEDCOUPLING_EXPORT void setTime(double time, int iteration, int order) { setStartTime(time,iteration,order); } + MEDCOUPLING_EXPORT void setIteration(int it) { setStartIteration(it); } + MEDCOUPLING_EXPORT void setOrder(int order) { setStartOrder(order); } + MEDCOUPLING_EXPORT void setTimeValue(double val) { setStartTimeValue(val); } + MEDCOUPLING_EXPORT virtual double getStartTime(int& iteration, int& order) const = 0; + MEDCOUPLING_EXPORT virtual void setStartIteration(int it) = 0; + MEDCOUPLING_EXPORT virtual void setStartOrder(int order) = 0; + MEDCOUPLING_EXPORT virtual void setStartTime(double time, int iteration, int order) = 0; + MEDCOUPLING_EXPORT virtual void setStartTimeValue(double time) = 0; + MEDCOUPLING_EXPORT virtual std::string getStringRepr() const = 0; + MEDCOUPLING_EXPORT virtual TypeOfTimeDiscretization getEnum() const = 0; + MEDCOUPLING_EXPORT virtual MEDCouplingTimeDiscretizationTemplate *performCopyOrIncrRef(bool deepCopy) const = 0; + // + MEDCOUPLING_EXPORT virtual void copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate& other); + MEDCOUPLING_EXPORT virtual void copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate& other); MEDCOUPLING_EXPORT virtual void checkConsistencyLight() const; - MEDCOUPLING_EXPORT virtual bool areCompatible(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT virtual bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const; - MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const; + MEDCOUPLING_EXPORT virtual std::size_t getHeapMemorySizeWithoutChildren() const; + MEDCOUPLING_EXPORT virtual std::vector getDirectChildrenWithNull() const; + // + MEDCOUPLING_EXPORT virtual bool areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const; + MEDCOUPLING_EXPORT virtual bool areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const; + MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const; + MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const; + protected: + MEDCOUPLING_EXPORT MEDCouplingTimeDiscretizationTemplate(); + MEDCOUPLING_EXPORT MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate& other, bool deepCopy); + MEDCOUPLING_EXPORT virtual ~MEDCouplingTimeDiscretizationTemplate(); + protected: + std::string _time_unit; + double _time_tolerance; + typename Traits::ArrayType *_array; + protected: + static const double TIME_TOLERANCE_DFT; + }; + + class MEDCouplingTimeKeeper + { + public: + MEDCOUPLING_EXPORT MEDCouplingTimeKeeper():_time(0.),_iteration(-1),_order(-1) { } + MEDCOUPLING_EXPORT double getAllInfo(int& iteration, int& order) const { iteration=_iteration; order=_order; return _time; } + MEDCOUPLING_EXPORT void setAllInfo(double time, int iteration, int order) { _time=time; _iteration=iteration; _order=order; } + MEDCOUPLING_EXPORT int getIteration() const { return _iteration; } + MEDCOUPLING_EXPORT void setIteration(int it) { _iteration=it; } + MEDCOUPLING_EXPORT int getOrder() const { return _order; } + MEDCOUPLING_EXPORT void setOrder(int order) { _order=order; } + MEDCOUPLING_EXPORT double getTimeValue() const { return _time; } + MEDCOUPLING_EXPORT void setTimeValue(double time) { _time=time; } + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeKeeper& other, double prec, std::string& reason) const; + MEDCOUPLING_EXPORT bool isEqual(const MEDCouplingTimeKeeper& other, double prec) const; + MEDCOUPLING_EXPORT void copyFrom(const MEDCouplingTimeKeeper& other); + MEDCOUPLING_EXPORT void checkTimePresence(double time, double eps) const; + private: + double _time; + int _iteration; + int _order; + }; + + class MEDCouplingTimeDiscretization : public MEDCouplingTimeDiscretizationTemplate + { + protected: + MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization() { } + MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization(const MEDCouplingTimeDiscretization& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate(other,deepCopy) { } + public: + MEDCOUPLING_EXPORT static MEDCouplingTimeDiscretization *New(TypeOfTimeDiscretization type); MEDCOUPLING_EXPORT virtual bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; MEDCOUPLING_EXPORT virtual bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; MEDCOUPLING_EXPORT virtual bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; MEDCOUPLING_EXPORT virtual MEDCouplingTimeDiscretization *buildNewTimeReprFromThis(TypeOfTimeDiscretization type, bool deepCopy) const; - MEDCOUPLING_EXPORT virtual std::string getStringRepr() const = 0; - MEDCOUPLING_EXPORT virtual TypeOfTimeDiscretization getEnum() const = 0; MEDCOUPLING_EXPORT virtual void synchronizeTimeWith(const MEDCouplingMesh *mesh) = 0; MEDCOUPLING_EXPORT virtual MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const = 0; MEDCOUPLING_EXPORT virtual MEDCouplingTimeDiscretization *aggregate(const std::vector& other) const = 0; @@ -87,16 +144,10 @@ namespace MEDCoupling MEDCOUPLING_EXPORT virtual void getTinySerializationIntInformation2(std::vector& tinyInfo) const = 0; MEDCOUPLING_EXPORT virtual void getTinySerializationDbleInformation2(std::vector& tinyInfo) const = 0; MEDCOUPLING_EXPORT virtual void finishUnserialization2(const std::vector& tinyInfoI, const std::vector& tinyInfoD) = 0; - MEDCOUPLING_EXPORT virtual MEDCouplingTimeDiscretization *performCopyOrIncrRef(bool deepCopy) const = 0; - MEDCOUPLING_EXPORT void setTimeTolerance(double val) { _time_tolerance=val; } - MEDCOUPLING_EXPORT double getTimeTolerance() const { return _time_tolerance; } MEDCOUPLING_EXPORT virtual void checkNoTimePresence() const = 0; MEDCOUPLING_EXPORT virtual void checkTimePresence(double time) const = 0; - MEDCOUPLING_EXPORT virtual void setArray(DataArrayDouble *array, TimeLabel *owner); MEDCOUPLING_EXPORT virtual void setEndArray(DataArrayDouble *array, TimeLabel *owner); MEDCOUPLING_EXPORT virtual void setArrays(const std::vector& arrays, TimeLabel *owner); - MEDCOUPLING_EXPORT DataArrayDouble *getArray() { return _array; } - MEDCOUPLING_EXPORT const DataArrayDouble *getArray() const { return _array; } MEDCOUPLING_EXPORT virtual const DataArrayDouble *getEndArray() const; MEDCOUPLING_EXPORT virtual DataArrayDouble *getEndArray(); MEDCOUPLING_EXPORT virtual std::vector< const DataArrayDouble *> getArraysForTime(double time) const = 0; @@ -104,20 +155,10 @@ namespace MEDCoupling MEDCOUPLING_EXPORT virtual void getArrays(std::vector& arrays) const; MEDCOUPLING_EXPORT virtual bool isBefore(const MEDCouplingTimeDiscretization *other) const; MEDCOUPLING_EXPORT virtual bool isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT double getTime(int& iteration, int& order) const { return getStartTime(iteration,order); } - MEDCOUPLING_EXPORT virtual double getStartTime(int& iteration, int& order) const = 0; MEDCOUPLING_EXPORT virtual double getEndTime(int& iteration, int& order) const = 0; - MEDCOUPLING_EXPORT void setTime(double time, int iteration, int order) { setStartTime(time,iteration,order); } - MEDCOUPLING_EXPORT void setIteration(int it) { setStartIteration(it); } - MEDCOUPLING_EXPORT void setOrder(int order) { setStartOrder(order); } - MEDCOUPLING_EXPORT void setTimeValue(double val) { setStartTimeValue(val); } - MEDCOUPLING_EXPORT virtual void setStartIteration(int it) = 0; MEDCOUPLING_EXPORT virtual void setEndIteration(int it) = 0; - MEDCOUPLING_EXPORT virtual void setStartOrder(int order) = 0; MEDCOUPLING_EXPORT virtual void setEndOrder(int order) = 0; - MEDCOUPLING_EXPORT virtual void setStartTimeValue(double time) = 0; MEDCOUPLING_EXPORT virtual void setEndTimeValue(double time) = 0; - MEDCOUPLING_EXPORT virtual void setStartTime(double time, int iteration, int order) = 0; MEDCOUPLING_EXPORT virtual void setEndTime(double time, int iteration, int order) = 0; MEDCOUPLING_EXPORT virtual void getValueOnTime(int eltId, double time, double *value) const = 0; MEDCOUPLING_EXPORT virtual void getValueOnDiscTime(int eltId, int iteration, int order, double *value) const = 0; @@ -151,16 +192,29 @@ namespace MEDCoupling MEDCOUPLING_EXPORT virtual void fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, const std::string& func); 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); - // - MEDCOUPLING_EXPORT virtual ~MEDCouplingTimeDiscretization(); - protected: - std::string _time_unit; - double _time_tolerance; - DataArrayDouble *_array; + }; + + class MEDCouplingTimeDiscretizationInt : public MEDCouplingTimeDiscretizationTemplate + { + public: + MEDCouplingTimeDiscretizationInt(); + MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy); + static MEDCouplingTimeDiscretizationInt *New(TypeOfTimeDiscretization type); + 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); } + void setStartTimeValue(double time) { _tk.setTimeValue(time); } + void setStartTime(double time, int iteration, int order) { _tk.setAllInfo(time,iteration,order); } + std::string getStringRepr() const; + TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } + MEDCouplingTimeDiscretizationInt *performCopyOrIncrRef(bool deepCopy) const; + private: + static const TypeOfTimeDiscretization DISCRETIZATION=ONE_TIME; + MEDCOUPLING_EXPORT static const char REPR[]; protected: - static const double TIME_TOLERANCE_DFT; + MEDCouplingTimeKeeper _tk; }; - + class MEDCouplingNoTimeLabel : public MEDCouplingTimeDiscretization { public: @@ -188,10 +242,10 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void powEqual(const MEDCouplingTimeDiscretization *other); MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; - MEDCOUPLING_EXPORT bool areCompatible(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const; + MEDCOUPLING_EXPORT bool areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization *performCopyOrIncrRef(bool deepCopy) const; MEDCOUPLING_EXPORT void checkNoTimePresence() const { } @@ -229,7 +283,7 @@ namespace MEDCoupling public: MEDCOUPLING_EXPORT MEDCouplingWithTimeStep(); MEDCOUPLING_EXPORT std::string getStringRepr() const; - MEDCOUPLING_EXPORT void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other); + MEDCOUPLING_EXPORT void copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate& other); MEDCOUPLING_EXPORT TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } MEDCOUPLING_EXPORT void synchronizeTimeWith(const MEDCouplingMesh *mesh); MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; @@ -251,10 +305,10 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void powEqual(const MEDCouplingTimeDiscretization *other); MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; - MEDCOUPLING_EXPORT bool areCompatible(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const; + MEDCOUPLING_EXPORT bool areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector& tinyInfo) const; MEDCOUPLING_EXPORT void getTinySerializationDbleInformation(std::vector& tinyInfo) const; @@ -265,16 +319,16 @@ namespace MEDCoupling MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization *performCopyOrIncrRef(bool deepCopy) const; MEDCOUPLING_EXPORT void checkNoTimePresence() const; MEDCOUPLING_EXPORT void checkTimePresence(double time) const; - MEDCOUPLING_EXPORT void setStartTime(double time, int iteration, int order) { _time=time; _iteration=iteration; _order=order; } - MEDCOUPLING_EXPORT void setEndTime(double time, int iteration, int order) { _time=time; _iteration=iteration; _order=order; } - MEDCOUPLING_EXPORT double getStartTime(int& iteration, int& order) const { iteration=_iteration; order=_order; return _time; } - MEDCOUPLING_EXPORT double getEndTime(int& iteration, int& order) const { iteration=_iteration; order=_order; return _time; } - MEDCOUPLING_EXPORT void setStartIteration(int it) { _iteration=it; } - MEDCOUPLING_EXPORT void setEndIteration(int it) { _iteration=it; } - MEDCOUPLING_EXPORT void setStartOrder(int order) { _order=order; } - MEDCOUPLING_EXPORT void setEndOrder(int order) { _order=order; } - MEDCOUPLING_EXPORT void setStartTimeValue(double time) { _time=time; } - MEDCOUPLING_EXPORT void setEndTimeValue(double time) { _time=time; } + MEDCOUPLING_EXPORT void setStartTime(double time, int iteration, int order) { _tk.setAllInfo(time,iteration,order); } + MEDCOUPLING_EXPORT void setEndTime(double time, int iteration, int order) { _tk.setAllInfo(time,iteration,order); } + MEDCOUPLING_EXPORT double getStartTime(int& iteration, int& order) const { return _tk.getAllInfo(iteration,order); } + MEDCOUPLING_EXPORT double getEndTime(int& iteration, int& order) const { return _tk.getAllInfo(iteration,order); } + MEDCOUPLING_EXPORT void setStartIteration(int it) { _tk.setIteration(it); } + MEDCOUPLING_EXPORT void setEndIteration(int it) { _tk.setIteration(it); } + MEDCOUPLING_EXPORT void setStartOrder(int order) { _tk.setOrder(order); } + MEDCOUPLING_EXPORT void setEndOrder(int order) { _tk.setOrder(order); } + MEDCOUPLING_EXPORT void setStartTimeValue(double time) { _tk.setTimeValue(time); } + MEDCOUPLING_EXPORT void setEndTimeValue(double time) { _tk.setTimeValue(time); } MEDCOUPLING_EXPORT std::vector< const DataArrayDouble *> getArraysForTime(double time) const; MEDCOUPLING_EXPORT void getValueForTime(double time, const std::vector& vals, double *res) const; MEDCOUPLING_EXPORT void getValueOnTime(int eltId, double time, double *value) const; @@ -285,9 +339,7 @@ namespace MEDCoupling private: static const char EXCEPTION_MSG[]; protected: - double _time; - int _iteration; - int _order; + MEDCouplingTimeKeeper _tk; }; class MEDCouplingConstOnTimeInterval : public MEDCouplingTimeDiscretization @@ -296,7 +348,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCopy); public: MEDCOUPLING_EXPORT MEDCouplingConstOnTimeInterval(); - MEDCOUPLING_EXPORT void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other); + MEDCOUPLING_EXPORT void copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate& other); MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector& tinyInfo) const; MEDCOUPLING_EXPORT void getTinySerializationDbleInformation(std::vector& tinyInfo) const; MEDCOUPLING_EXPORT void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); @@ -304,10 +356,10 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void getTinySerializationDbleInformation2(std::vector& tinyInfo) const; MEDCOUPLING_EXPORT void finishUnserialization2(const std::vector& tinyInfoI, const std::vector& tinyInfoD); MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization *performCopyOrIncrRef(bool deepCopy) const; - MEDCOUPLING_EXPORT bool areCompatible(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const; + MEDCOUPLING_EXPORT bool areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; @@ -335,16 +387,16 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void divideEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const; MEDCOUPLING_EXPORT void powEqual(const MEDCouplingTimeDiscretization *other); - MEDCOUPLING_EXPORT void setStartTime(double time, int iteration, int order) { _start_time=time; _start_iteration=iteration; _start_order=order; } - MEDCOUPLING_EXPORT void setEndTime(double time, int iteration, int order) { _end_time=time; _end_iteration=iteration; _end_order=order; } - MEDCOUPLING_EXPORT double getStartTime(int& iteration, int& order) const { iteration=_start_iteration; order=_start_order; return _start_time; } - MEDCOUPLING_EXPORT double getEndTime(int& iteration, int& order) const { iteration=_end_iteration; order=_end_order; return _end_time; } - MEDCOUPLING_EXPORT void setStartIteration(int it) { _start_iteration=it; } - MEDCOUPLING_EXPORT void setEndIteration(int it) { _end_iteration=it; } - MEDCOUPLING_EXPORT void setStartOrder(int order) { _start_order=order; } - MEDCOUPLING_EXPORT void setEndOrder(int order) { _end_order=order; } - MEDCOUPLING_EXPORT void setStartTimeValue(double time) { _start_time=time; } - MEDCOUPLING_EXPORT void setEndTimeValue(double time) { _end_time=time; } + MEDCOUPLING_EXPORT void setStartTime(double time, int iteration, int order) { _start.setAllInfo(time,iteration,order); } + MEDCOUPLING_EXPORT void setEndTime(double time, int iteration, int order) { _end.setAllInfo(time,iteration,order); } + MEDCOUPLING_EXPORT double getStartTime(int& iteration, int& order) const { return _start.getAllInfo(iteration,order); } + MEDCOUPLING_EXPORT double getEndTime(int& iteration, int& order) const { return _end.getAllInfo(iteration,order); } + MEDCOUPLING_EXPORT void setStartIteration(int it) { _start.setIteration(it); } + MEDCOUPLING_EXPORT void setEndIteration(int it) { _end.setIteration(it); } + MEDCOUPLING_EXPORT void setStartOrder(int order) { _start.setOrder(order); } + MEDCOUPLING_EXPORT void setEndOrder(int order) { _end.setOrder(order); } + MEDCOUPLING_EXPORT void setStartTimeValue(double time) { _start.setTimeValue(time); } + MEDCOUPLING_EXPORT void setEndTimeValue(double time) { _end.setTimeValue(time); } MEDCOUPLING_EXPORT void checkNoTimePresence() const; MEDCOUPLING_EXPORT void checkTimePresence(double time) const; public: @@ -353,12 +405,8 @@ namespace MEDCoupling private: static const char EXCEPTION_MSG[]; protected: - double _start_time; - double _end_time; - int _start_iteration; - int _end_iteration; - int _start_order; - int _end_order; + MEDCouplingTimeKeeper _start; + MEDCouplingTimeKeeper _end; }; class MEDCouplingTwoTimeSteps : public MEDCouplingTimeDiscretization @@ -372,8 +420,8 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void synchronizeTimeWith(const MEDCouplingMesh *mesh); MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; MEDCOUPLING_EXPORT std::vector getDirectChildrenWithNull() const; - MEDCOUPLING_EXPORT void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other); - MEDCOUPLING_EXPORT void copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other); + MEDCOUPLING_EXPORT void copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate& other); + MEDCOUPLING_EXPORT void copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate& other); MEDCOUPLING_EXPORT const DataArrayDouble *getEndArray() const; MEDCOUPLING_EXPORT DataArrayDouble *getEndArray(); MEDCOUPLING_EXPORT void checkConsistencyLight() const; @@ -426,10 +474,10 @@ namespace MEDCoupling MEDCOUPLING_EXPORT TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } MEDCOUPLING_EXPORT void checkConsistencyLight() const; MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization *performCopyOrIncrRef(bool deepCopy) const; - MEDCOUPLING_EXPORT bool areCompatible(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const; + MEDCOUPLING_EXPORT bool areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; MEDCOUPLING_EXPORT void getValueForTime(double time, const std::vector& vals, double *res) const; MEDCOUPLING_EXPORT void getValueOnTime(int eltId, double time, double *value) const; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.txx b/src/MEDCoupling/MEDCouplingTimeDiscretization.txx new file mode 100644 index 000000000..f03bedf7d --- /dev/null +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.txx @@ -0,0 +1,191 @@ +// Copyright (C) 2007-2016 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 __MEDCOUPLINGTIMEDISCRETIZATION_TXX__ +#define __MEDCOUPLINGTIMEDISCRETIZATION_TXX__ + +#include "MEDCouplingTimeDiscretization.hxx" + +#include +#include + +namespace MEDCoupling +{ + template + const double MEDCouplingTimeDiscretizationTemplate::TIME_TOLERANCE_DFT=1.e-12; + + template + void MEDCouplingTimeDiscretizationTemplate::updateTime() const + { + if(_array) + updateTimeWith(*_array); + } + + template + void MEDCouplingTimeDiscretizationTemplate::setArray(typename Traits::ArrayType *array, TimeLabel *owner) + { + if(array!=_array) + { + if(_array) + _array->decrRef(); + _array=array; + if(_array) + _array->incrRef(); + if(owner) + owner->declareAsNew(); + } + } + + template + void MEDCouplingTimeDiscretizationTemplate::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate& other) + { + _time_tolerance=other._time_tolerance; + _time_unit=other._time_unit; + } + + template + void MEDCouplingTimeDiscretizationTemplate::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate& other) + { + _time_unit=other._time_unit; + if(_array && other._array) + _array->copyStringInfoFrom(*other._array); + } + + template + std::size_t MEDCouplingTimeDiscretizationTemplate::getHeapMemorySizeWithoutChildren() const + { + return _time_unit.capacity(); + } + + template + void MEDCouplingTimeDiscretizationTemplate::checkConsistencyLight() const + { + if(!_array) + throw INTERP_KERNEL::Exception("Field invalid because no values set !"); + if(_time_tolerance<0.) + throw INTERP_KERNEL::Exception("time tolerance is expected to be greater than 0. !"); + } + + template + std::vector MEDCouplingTimeDiscretizationTemplate::getDirectChildrenWithNull() const + { + std::vector ret; + ret.push_back(_array); + return ret; + } + + template + bool MEDCouplingTimeDiscretizationTemplate::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const + { + std::ostringstream oss; oss.precision(15); + if(_time_unit!=other->_time_unit) + { + oss << "Field discretizations differ : this time unit = \"" << _time_unit << "\" and other time unit = \"" << other->_time_unit << "\" !"; + reason=oss.str(); + return false; + } + if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) + { + oss << "Field discretizations differ : this time tolerance = \"" << _time_tolerance << "\" and other time tolerance = \"" << other->_time_tolerance << "\" !"; + reason=oss.str(); + return false; + } + if(_array==0 && other->_array==0) + return true; + if(_array==0 || other->_array==0) + { + reason="Field discretizations differ : Only one timediscretization between the two this and other has a DataArrayDouble for values defined"; + return false; + } + if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents()) + return false; + if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples()) + return false; + return true; + } + + template + bool MEDCouplingTimeDiscretizationTemplate::areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const + { + if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) + return false; + if(_array==0 && other->_array==0) + return true; + if(_array==0 || other->_array==0) + return false; + if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents()) + return false; + return true; + } + + template + bool MEDCouplingTimeDiscretizationTemplate::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const + { + if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) + return false; + if(_array==0 && other->_array==0) + return true; + if(_array==0 || other->_array==0) + return false; + int nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents()); + int nbMin(std::min(nbC1,nbC2)); + if(nbC1!=nbC2 && nbMin!=1) + return false; + return true; + } + + template + bool MEDCouplingTimeDiscretizationTemplate::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const + { + if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16) + return false; + if(_array==0 && other->_array==0) + return true; + if(_array==0 || other->_array==0) + return false; + int nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents()); + if(nbC1!=nbC2 && nbC2!=1) + return false; + return true; + } + + template + MEDCouplingTimeDiscretizationTemplate::MEDCouplingTimeDiscretizationTemplate():_time_tolerance(TIME_TOLERANCE_DFT),_array(0) + { + } + + template + MEDCouplingTimeDiscretizationTemplate::MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate& other, bool deepCopy):_time_unit(other._time_unit),_time_tolerance(other._time_tolerance) + { + if(other._array) + _array=other._array->performCopyOrIncrRef(deepCopy); + else + _array=0; + } + + template + MEDCouplingTimeDiscretizationTemplate::~MEDCouplingTimeDiscretizationTemplate() + { + if(_array) + _array->decrRef(); + } +} + +#endif diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index bcd478112..61088db71 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -3738,6 +3738,7 @@ namespace MEDCoupling { public: static MEDCouplingFieldTemplate *New(const MEDCouplingFieldDouble& f) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldTemplate *New(const MEDCouplingFieldInt& f) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldTemplate *New(TypeOfField type); std::string simpleRepr() const throw(INTERP_KERNEL::Exception); std::string advancedRepr() const throw(INTERP_KERNEL::Exception); @@ -3747,6 +3748,11 @@ namespace MEDCoupling { return MEDCouplingFieldTemplate::New(f); } + + MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f) throw(INTERP_KERNEL::Exception) + { + return MEDCouplingFieldTemplate::New(f); + } MEDCouplingFieldTemplate(TypeOfField type) throw(INTERP_KERNEL::Exception) { @@ -5174,6 +5180,7 @@ namespace MEDCoupling { public: static MEDCouplingFieldInt *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME); + static MEDCouplingFieldInt *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME); 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); @@ -5184,6 +5191,11 @@ namespace MEDCoupling return MEDCouplingFieldInt::New(type,td); } + MEDCouplingFieldInt(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME) + { + return MEDCouplingFieldInt::New(ft,td); + } + std::string __str__() const throw(INTERP_KERNEL::Exception) { return self->simpleRepr(); -- 2.39.2