From af300a5c4856d1d99f568c821513c826b1167726 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 22 Aug 2016 15:33:40 +0200 Subject: [PATCH] End refacto --- .../MEDCouplingTimeDiscretization.cxx | 171 ++++++------------ .../MEDCouplingTimeDiscretization.hxx | 28 ++- 2 files changed, 71 insertions(+), 128 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index db9a43ade..2262cd871 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -2087,9 +2087,7 @@ void MEDCouplingConstOnTimeInterval::powEqual(const MEDCouplingTimeDiscretizatio } MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& 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) + _start(other._start),_end(other._end) { if(other._end_array) _end_array=other._end_array->performCopyOrIncrRef(deepCopy); @@ -2110,8 +2108,8 @@ void MEDCouplingTwoTimeSteps::synchronizeTimeWith(const MEDCouplingMesh *mesh) throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::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; + _start.setAllInfo(val,it,order); + _end.setAllInfo(val,it,order); std::string tUnit=mesh->getTimeUnit(); _time_unit=tUnit; } @@ -2134,12 +2132,8 @@ void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretizati const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(&other); if(!otherC) throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::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 MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate& other) @@ -2182,42 +2176,10 @@ bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretizatio reason="This has time discretization LINEAR_TIME, 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; if(_end_array!=otherC->_end_array) if(!_end_array->isEqualIfNotWhy(*otherC->_end_array,prec,reason)) { @@ -2232,17 +2194,9 @@ bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTime const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(other); if(!otherC) return false; - if(_start_iteration!=otherC->_start_iteration) - return false; - if(_end_iteration!=otherC->_end_iteration) - return false; - if(_start_order!=otherC->_start_order) - return false; - if(_end_order!=otherC->_end_order) - return false; - if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance) + 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; if(_end_array!=otherC->_end_array) if(!_end_array->isEqualWithoutConsideringStr(*otherC->_end_array,prec)) @@ -2250,7 +2204,7 @@ bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTime return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); } -MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_start_time(0.),_end_time(0.),_start_iteration(-1),_end_iteration(-1),_start_order(-1),_end_order(-1),_end_array(0) +MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_end_array(0) { } @@ -2267,10 +2221,10 @@ void MEDCouplingTwoTimeSteps::checkNoTimePresence() const void MEDCouplingTwoTimeSteps::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()); } @@ -2300,10 +2254,10 @@ void MEDCouplingTwoTimeSteps::setEndArray(DataArrayDouble *array, TimeLabel *own void MEDCouplingTwoTimeSteps::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()); if(_end_array) { tinyInfo.push_back(_end_array->getNumberOfTuples()); @@ -2319,8 +2273,8 @@ void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(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 MEDCouplingTwoTimeSteps::getTinySerializationStrInformation(std::vector& tinyInfo) const @@ -2386,12 +2340,12 @@ void MEDCouplingTwoTimeSteps::checkForUnserialization(const std::vector& ti void MEDCouplingTwoTimeSteps::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]); } /*! @@ -2400,10 +2354,10 @@ void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector& tiny void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation2(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(); } /*! @@ -2413,8 +2367,8 @@ void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation2(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]); } std::vector< const DataArrayDouble *> MEDCouplingTwoTimeSteps::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(2); ret[0]=_array; @@ -2463,8 +2417,8 @@ MEDCouplingLinearTime::MEDCouplingLinearTime() std::string MEDCouplingLinearTime::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 << "Time unit is : \"" << _time_unit << "\""; return stream.str(); } @@ -2472,7 +2426,7 @@ std::string MEDCouplingLinearTime::getStringRepr() const void MEDCouplingLinearTime::checkConsistencyLight() const { MEDCouplingTwoTimeSteps::checkConsistencyLight(); - if(std::fabs(_start_time-_end_time)<_time_tolerance) + if(std::fabs(_start.getTimeValue()-_end.getTimeValue())<_time_tolerance) throw INTERP_KERNEL::Exception("Start time and end time are equals regarding time tolerance."); } @@ -2547,7 +2501,7 @@ bool MEDCouplingLinearTime::areCompatibleForMeld(const MEDCouplingTimeDiscretiza */ void MEDCouplingLinearTime::getValueForTime(double time, const std::vector& vals, double *res) const { - double alpha=(_end_time-time)/(_end_time-_start_time); + double alpha=(_end.getTimeValue()-time)/(_end.getTimeValue()-_start.getTimeValue()); std::size_t nbComp=vals.size()/2; std::transform(vals.begin(),vals.begin()+nbComp,res,std::bind2nd(std::multiplies(),alpha)); std::vector tmp(nbComp); @@ -2557,7 +2511,7 @@ void MEDCouplingLinearTime::getValueForTime(double time, const std::vectorgetTuple(eltId,value); @@ -2576,14 +2530,14 @@ void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const { - if(iteration==_start_iteration && order==_start_order) + if(iteration==_start.getIteration() && order==_start.getOrder()) { if(_array) _array->getTuple(eltId,value); else throw INTERP_KERNEL::Exception("iteration order match with start time but no start array existing."); } - if(iteration==_end_iteration && order==_end_order) + if(iteration==_end.getIteration() && order==_end.getOrder()) { if(_end_array) _end_array->getTuple(eltId,value); @@ -2620,9 +2574,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const std::vecto a[i]=itC->getArray(); b[i]=itC->getEndArray(); } - MCAuto arr=DataArrayDouble::Aggregate(a); - MCAuto arr2=DataArrayDouble::Aggregate(b); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr(DataArrayDouble::Aggregate(a)),arr2(DataArrayDouble::Aggregate(b)); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setArray(arr,0); ret->setEndArray(arr2,0); return ret; @@ -2633,9 +2586,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::meld(const MEDCouplingTime const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::meld on mismatched time discretization !"); - MCAuto arr1=DataArrayDouble::Meld(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::Meld(getEndArray(),other->getEndArray()); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr1(DataArrayDouble::Meld(getArray(),other->getArray())),arr2(DataArrayDouble::Meld(getEndArray(),other->getEndArray())); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setTimeTolerance(getTimeTolerance()); ret->setArray(arr1,0); ret->setEndArray(arr2,0); @@ -2647,9 +2599,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeD const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::dot on mismatched time discretization !"); - MCAuto arr1=DataArrayDouble::Dot(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::Dot(getEndArray(),other->getEndArray()); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr1(DataArrayDouble::Dot(getArray(),other->getArray())),arr2(DataArrayDouble::Dot(getEndArray(),other->getEndArray())); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setArray(arr1,0); ret->setEndArray(arr2,0); return ret; @@ -2660,9 +2611,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::crossProduct(const MEDCoup const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::crossProduct on mismatched time discretization !"); - MCAuto arr1=DataArrayDouble::CrossProduct(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::CrossProduct(getEndArray(),other->getEndArray()); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr1(DataArrayDouble::CrossProduct(getArray(),other->getArray())),arr2(DataArrayDouble::CrossProduct(getEndArray(),other->getEndArray())); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setArray(arr1,0); ret->setEndArray(arr2,0); return ret; @@ -2674,8 +2624,7 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::max(const MEDCouplingTimeD if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::max on mismatched time discretization !"); MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; - MCAuto arr1=DataArrayDouble::Max(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::Max(getEndArray(),other->getEndArray()); + MCAuto arr1(DataArrayDouble::Max(getArray(),other->getArray())),arr2(DataArrayDouble::Max(getEndArray(),other->getEndArray())); ret->setArray(arr1,0); ret->setEndArray(arr2,0); return ret; @@ -2686,9 +2635,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::min(const MEDCouplingTimeD const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::min on mismatched time discretization !"); - MCAuto arr1=DataArrayDouble::Min(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::Min(getEndArray(),other->getEndArray()); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr1(DataArrayDouble::Min(getArray(),other->getArray())),arr2(DataArrayDouble::Min(getEndArray(),other->getEndArray())); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setArray(arr1,0); ret->setEndArray(arr2,0); return ret; @@ -2699,9 +2647,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::add(const MEDCouplingTimeD const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::add on mismatched time discretization !"); - MCAuto arr1=DataArrayDouble::Add(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::Add(getEndArray(),other->getEndArray()); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr1(DataArrayDouble::Add(getArray(),other->getArray())),arr2(DataArrayDouble::Add(getEndArray(),other->getEndArray())); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setArray(arr1,0); ret->setEndArray(arr2,0); return ret; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index 2b88a67c5..f50af41c7 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -431,16 +431,16 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void checkTimePresence(double time) const; MEDCOUPLING_EXPORT void getArrays(std::vector& arrays) const; MEDCOUPLING_EXPORT void setEndArray(DataArrayDouble *array, TimeLabel *owner); - 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 getTinySerializationIntInformation(std::vector& tinyInfo) const; MEDCOUPLING_EXPORT void getTinySerializationDbleInformation(std::vector& tinyInfo) const; MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector& tinyInfo) const; @@ -455,12 +455,8 @@ namespace MEDCoupling protected: 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; DataArrayDouble *_end_array; }; -- 2.39.2