X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingTimeDiscretization.cxx;h=873193aba4edba2031c1e08a4854d4cb9d772288;hb=af8a6b836ed960509fcb2d719d7396c187dfbf2b;hp=db9a43adef8cafdaa65f9ec89051a9f7523121a0;hpb=2516e3ae71a095b1fdbffbddd253af62f8c9fc7c;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index db9a43ade..873193aba 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// Copyright (C) 2007-2020 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 @@ -29,10 +29,11 @@ using namespace MEDCoupling; -template class MEDCouplingTimeDiscretizationTemplate; -template class MEDCouplingTimeDiscretizationTemplate; - -const char MEDCouplingTimeDiscretizationInt::REPR[]="One time label."; +template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate; +template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate; +template class MEDCoupling::MEDCouplingTimeDiscretizationSimple; +template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate; +template class MEDCoupling::MEDCouplingTimeDiscretizationSimple; const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setTime : no time info attached."; @@ -80,13 +81,13 @@ bool MEDCouplingTimeDiscretization::areCompatibleForMeld(const MEDCouplingTimeDi return true; } -bool MEDCouplingTimeDiscretization::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const +bool MEDCouplingTimeDiscretization::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const { if(!areStrictlyCompatible(other,reason)) return false; - if(_array==other->_array) + if(_array==other->getArray()) return true; - return _array->isEqualIfNotWhy(*other->_array,prec,reason); + return _array->isEqualIfNotWhy(*other->getArray(),prec,reason); } bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const @@ -95,14 +96,14 @@ bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization return isEqualIfNotWhy(other,prec,reason); } -bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const { std::string tmp; if(!areStrictlyCompatible(other,tmp)) return false; - if(_array==other->_array) + if(_array==other->getArray()) return true; - return _array->isEqualWithoutConsideringStr(*other->_array,prec); + return _array->isEqualWithoutConsideringStr(*other->getArray(),prec); } MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(TypeOfTimeDiscretization type, bool deepCopy) const @@ -117,101 +118,6 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFr return ret; } -void MEDCouplingTimeDiscretization::getTinySerializationIntInformation(std::vector& tinyInfo) const -{ - if(_array) - { - tinyInfo.push_back(_array->getNumberOfTuples()); - tinyInfo.push_back(_array->getNumberOfComponents()); - } - else - { - tinyInfo.push_back(-1); - tinyInfo.push_back(-1); - } -} - -void MEDCouplingTimeDiscretization::resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays) -{ - arrays.resize(1); - if(_array!=0) - _array->decrRef(); - DataArrayDouble *arr=0; - if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1) - { - arr=DataArrayDouble::New(); - arr->alloc(tinyInfoI[0],tinyInfoI[1]); - } - _array=arr; - arrays[0]=arr; -} - -void MEDCouplingTimeDiscretization::checkForUnserialization(const std::vector& tinyInfoI, const std::vector& arrays) -{ - static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size one !"; - if(arrays.size()!=1) - throw INTERP_KERNEL::Exception(MSG); - if(_array!=0) - _array->decrRef(); - _array=0; - if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1) - { - if(!arrays[0]) - throw INTERP_KERNEL::Exception(MSG); - arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG); - _array=arrays[0]; - _array->incrRef(); - } -} - -void MEDCouplingTimeDiscretization::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) -{ - _time_tolerance=tinyInfoD[0]; - int nbOfCompo=_array->getNumberOfComponents(); - for(int i=0;isetInfoOnComponent(i,tinyInfoS[i]); -} - -void MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(std::vector& tinyInfo) const -{ - tinyInfo.push_back(_time_tolerance); -} - -void MEDCouplingTimeDiscretization::getTinySerializationStrInformation(std::vector& tinyInfo) const -{ - int nbOfCompo=_array->getNumberOfComponents(); - for(int i=0;igetInfoOnComponent(i)); -} - -const DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray() const -{ - throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !"); -} - -DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray() -{ - throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !"); -} - -void MEDCouplingTimeDiscretization::setEndArray(DataArrayDouble *array, TimeLabel *owner) -{ - throw INTERP_KERNEL::Exception("setEndArray not available for this type of time discretization !"); -} - -void MEDCouplingTimeDiscretization::setArrays(const std::vector& arrays, TimeLabel *owner) -{ - if(arrays.size()!=1) - throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretization::setArrays : number of arrays must be one."); - setArray(arrays.back(),owner); -} - -void MEDCouplingTimeDiscretization::getArrays(std::vector& arrays) const -{ - arrays.resize(1); - arrays[0]=_array; -} - bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const { int iteration,order; @@ -228,9 +134,28 @@ bool MEDCouplingTimeDiscretization::isStrictlyBefore(const MEDCouplingTimeDiscre return time1setTimeUnit(getTimeUnit()); + std::vector arrays; + getArrays(arrays); + std::vector< MCAuto > arrays2(arrays.size()); + for(std::size_t j=0;jfromCartToCylGiven(coords,center,vect); + } + std::vector arrays3(arrays.size()); + for(std::size_t j=0;jsetArrays(arrays3,0); + return ret; +} + MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedProduct() const { - MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); + MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum())); ret->setTimeUnit(getTimeUnit()); std::vector arrays; getArrays(arrays); @@ -239,8 +164,6 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedPr { if(arrays[j]) arrays2[j]=arrays[j]->doublyContractedProduct(); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;jdeterminant(); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); ret->setArrays(arrays3,0); return ret; @@ -279,13 +200,11 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() cons { if(arrays[j]) arrays2[j]=arrays[j]->eigenValues(); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); ret->setArrays(arrays3,0); return ret; @@ -300,13 +219,11 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() con { if(arrays[j]) arrays2[j]=arrays[j]->eigenVectors(); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); ret->setArrays(arrays3,0); return ret; @@ -321,13 +238,11 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const { if(arrays[j]) arrays2[j]=arrays[j]->inverse(); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); ret->setArrays(arrays3,0); return ret; @@ -342,13 +257,11 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const { if(arrays[j]) arrays2[j]=arrays[j]->trace(); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); ret->setArrays(arrays3,0); return ret; @@ -363,13 +276,11 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const { if(arrays[j]) arrays2[j]=arrays[j]->deviator(); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); ret->setArrays(arrays3,0); return ret; @@ -384,13 +295,11 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const { if(arrays[j]) arrays2[j]=arrays[j]->magnitude(); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); ret->setArrays(arrays3,0); return ret; @@ -405,13 +314,11 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::negate() const { if(arrays[j]) arrays2[j]=arrays[j]->negate(); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); ret->setArrays(arrays3,0); return ret; @@ -426,19 +333,17 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() cons { if(arrays[j]) arrays2[j]=arrays[j]->maxPerTuple(); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); ret->setArrays(arrays3,0); return ret; } -MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedComponents(const std::vector& compoIds) const +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedComponents(const std::vector& compoIds) const { std::vector arrays; getArrays(arrays); @@ -447,19 +352,17 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedCompon { if(arrays[j]) arrays2[j]=static_cast(arrays[j]->keepSelectedComponents(compoIds)); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); ret->setArrays(arrays3,0); return ret; } -void MEDCouplingTimeDiscretization::setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector& compoIds) +void MEDCouplingTimeDiscretization::setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector& compoIds) { std::vector arrays1,arrays2; getArrays(arrays1); @@ -471,11 +374,11 @@ void MEDCouplingTimeDiscretization::setSelectedComponents(const MEDCouplingTimeD if(arrays1[i]!=0 && arrays2[i]!=0) arrays1[i]->setSelectedComponents(arrays2[i],compoIds); else if(arrays1[i]!=0 || arrays2[i]!=0) - throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : some time array in correspondance are not defined symetrically !"); + throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : some time array in correspondence are not defined symmetrically !"); } } -void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double dftValue) +void MEDCouplingTimeDiscretization::changeNbOfComponents(std::size_t newNbOfComp, double dftValue) { std::vector arrays; getArrays(arrays); @@ -484,8 +387,6 @@ void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double { if(arrays[j]) arrays2[j]=arrays[j]->changeNbOfComponents(newNbOfComp,dftValue); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;j arrays; getArrays(arrays); @@ -529,7 +430,7 @@ void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, int nbOfCompo setArrays(arrays3,0); } -void MEDCouplingTimeDiscretization::setOrCreateUniformValueOnAllComponents(int nbOfTuple, double value) +void MEDCouplingTimeDiscretization::setOrCreateUniformValueOnAllComponents(mcIdType nbOfTuple, double value) { std::vector arrays; getArrays(arrays); @@ -590,8 +491,6 @@ void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate f { if(arrays[j]) arrays2[j]=arrays[j]->applyFunc(nbOfComp,func); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;japplyFuncCompo(nbOfComp,func); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;japplyFuncNamedCompo(nbOfComp,varsOrder,func); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;japplyFunc(func); - else - arrays2[j]=0; } std::vector arrays3(arrays.size()); for(std::size_t j=0;j(other,deepCopy) { } -MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate(other,deepCopy) +MEDCouplingTimeDiscretizationInt32 *MEDCouplingTimeDiscretizationInt32::performCopyOrIncrRef(bool deepCopy) const { + return new MEDCouplingTimeDiscretizationInt32(*this,deepCopy); } -std::string MEDCouplingTimeDiscretizationInt::getStringRepr() const +MEDCouplingTimeDiscretizationInt32 *MEDCouplingTimeDiscretizationInt32::New(TypeOfTimeDiscretization type) { - 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(); + switch(type) + { + case MEDCouplingTimeDiscretizationInt32::DISCRETIZATION: + return new MEDCouplingTimeDiscretizationInt32; + default: + throw INTERP_KERNEL::Exception("Time discretization not implemented yet for integers !"); + } +} + +bool MEDCouplingTimeDiscretizationInt32::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, Int32 prec, std::string& reason) const +{ + if(prec!=0) + throw INTERP_KERNEL::Exception("isEqualIfNotWhy : only precision equal to 0 supported for int !"); + if(!other) + { + reason="Time discretization is NULL."; + return false; + } + const MEDCouplingTimeDiscretizationInt32 *otherC(dynamic_cast(other)); + if(!otherC) + throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationInt32 !"); + if(!MEDCouplingTimeDiscretizationTemplate::areStrictlyCompatible(other,reason)) + return false; + if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) + return false; + if(_array==other->getArray()) + return true; + return _array->isEqualIfNotWhy(*other->getArray(),reason); +} + +bool MEDCouplingTimeDiscretizationInt32::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, Int32 prec) const +{ + if(prec!=0) + throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationInt32::isEqualWithoutConsideringStr : only precision 0 is supported !"); + const MEDCouplingTimeDiscretizationInt32 *otherC(dynamic_cast(other)); + if(!otherC) + throw INTERP_KERNEL::Exception("isEqualWithoutConsideringStr : other is not a MEDCouplingTimeDiscretizationInt !"); + std::string tmp; + if(!areStrictlyCompatible(other,tmp)) + return false; + std::string reason; + if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) + return false; + if(_array==other->getArray()) + return true; + return _array->isEqualWithoutConsideringStr(*(other->getArray())); } -MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::performCopyOrIncrRef(bool deepCopy) const +//////////////////////// + +MEDCouplingTimeDiscretizationInt64::MEDCouplingTimeDiscretizationInt64(const MEDCouplingTimeDiscretizationInt64& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple(other,deepCopy) { - return new MEDCouplingTimeDiscretizationInt(*this,deepCopy); } -MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::New(TypeOfTimeDiscretization type) +MEDCouplingTimeDiscretizationInt64 *MEDCouplingTimeDiscretizationInt64::performCopyOrIncrRef(bool deepCopy) const +{ + return new MEDCouplingTimeDiscretizationInt64(*this,deepCopy); +} + +MEDCouplingTimeDiscretizationInt64 *MEDCouplingTimeDiscretizationInt64::New(TypeOfTimeDiscretization type) +{ + switch(type) + { + case MEDCouplingTimeDiscretizationInt64::DISCRETIZATION: + return new MEDCouplingTimeDiscretizationInt64; + default: + throw INTERP_KERNEL::Exception("Time discretization not implemented yet for integers !"); + } +} + +bool MEDCouplingTimeDiscretizationInt64::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, Int64 prec, std::string& reason) const +{ + if(prec!=0) + throw INTERP_KERNEL::Exception("isEqualIfNotWhy : only precision equal to 0 supported for int !"); + if(!other) + { + reason="Time discretization is NULL."; + return false; + } + const MEDCouplingTimeDiscretizationInt64 *otherC(dynamic_cast(other)); + if(!otherC) + throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationInt64 !"); + if(!MEDCouplingTimeDiscretizationTemplate::areStrictlyCompatible(other,reason)) + return false; + if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) + return false; + if(_array==other->getArray()) + return true; + return _array->isEqualIfNotWhy(*other->getArray(),reason); +} + +bool MEDCouplingTimeDiscretizationInt64::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, Int64 prec) const +{ + if(prec!=0) + throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationInt64::isEqualWithoutConsideringStr : only precision 0 is supported !"); + const MEDCouplingTimeDiscretizationInt64 *otherC(dynamic_cast(other)); + if(!otherC) + throw INTERP_KERNEL::Exception("isEqualWithoutConsideringStr : other is not a MEDCouplingTimeDiscretizationInt !"); + std::string tmp; + if(!areStrictlyCompatible(other,tmp)) + return false; + std::string reason; + if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) + return false; + if(_array==other->getArray()) + return true; + return _array->isEqualWithoutConsideringStr(*(other->getArray())); +} + +//////////////////////// + +MEDCouplingTimeDiscretizationFloat::MEDCouplingTimeDiscretizationFloat(const MEDCouplingTimeDiscretizationFloat& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple(other,deepCopy) +{ +} + +MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::performCopyOrIncrRef(bool deepCopy) const +{ + return new MEDCouplingTimeDiscretizationFloat(*this,deepCopy); +} + +MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::New(TypeOfTimeDiscretization type) { switch(type) { - case MEDCouplingTimeDiscretizationInt::DISCRETIZATION: - return new MEDCouplingTimeDiscretizationInt; + case MEDCouplingTimeDiscretizationFloat::DISCRETIZATION: + return new MEDCouplingTimeDiscretizationFloat; default: - throw INTERP_KERNEL::Exception("Time discretization not implemented yet for intergers !"); + throw INTERP_KERNEL::Exception("Time discretization not implemented yet for integers !"); } } +bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, float prec, std::string& reason) const +{ + if(!other) + { + reason="Time discretization is NULL."; + return false; + } + const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast(other)); + if(!otherC) + throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationFloat !"); + if(!MEDCouplingTimeDiscretizationTemplate::areStrictlyCompatible(other,reason)) + return false; + if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) + return false; + if(_array==other->getArray()) + return true; + return _array->isEqualIfNotWhy(*other->getArray(),prec,reason); +} + +bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, float prec) const +{ + if(prec!=0) + throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr : only precision 0 is supported !"); + const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast(other)); + if(!otherC) + throw INTERP_KERNEL::Exception("isEqualWithoutConsideringStr : other is not a MEDCouplingTimeDiscretizationFloat !"); + std::string tmp; + if(!areStrictlyCompatible(other,tmp)) + return false; + std::string reason; + if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) + return false; + if(_array==other->getArray()) + return true; + return _array->isEqualWithoutConsideringStr(*(other->getArray()),prec); +} //////////////////////// @@ -848,7 +887,7 @@ std::string MEDCouplingNoTimeLabel::getStringRepr() const { std::ostringstream stream; stream << REPR; - stream << "\nTime unit is : \"" << _time_unit << "\""; + stream << "\nTime unit is : \"" << getTimeUnit() << "\""; return stream.str(); } @@ -861,7 +900,7 @@ bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretizationTe { if(!MEDCouplingTimeDiscretization::areCompatible(other)) return false; - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); return otherC!=0; } @@ -869,7 +908,7 @@ bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscreti { if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason)) return false; - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); bool ret=otherC!=0; if(!ret) reason.insert(0,"time discretization of this is NO_TIME, other has a different time discretization."); @@ -880,7 +919,7 @@ bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDi { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other)) return false; - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); return otherC!=0; } @@ -888,7 +927,7 @@ bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDi { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) return false; - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); return otherC!=0; } @@ -896,13 +935,13 @@ bool MEDCouplingNoTimeLabel::areCompatibleForMeld(const MEDCouplingTimeDiscretiz { if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other)) return false; - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); return otherC!=0; } -bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const +bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const { - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); if(!otherC) { reason="This has time discretization NO_TIME, other not."; @@ -911,9 +950,9 @@ bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretization return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason); } -bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const { - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); if(!otherC) return false; return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); @@ -921,11 +960,11 @@ bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeD MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCouplingTimeDiscretization *other) const { - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); if(!otherC) throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !"); - MCAuto arr=DataArrayDouble::Aggregate(getArray(),other->getArray()); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + MCAuto arr(DataArrayDouble::Aggregate(getArray(),other->getArray())); + MEDCouplingNoTimeLabel *ret(new MEDCouplingNoTimeLabel); ret->setArray(arr,0); return ret; } @@ -941,8 +980,8 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const std::vect throw INTERP_KERNEL::Exception("NoTimeLabel::aggregate on mismatched time discretization !"); a[i]=itC->getArray(); } - MCAuto arr=DataArrayDouble::Aggregate(a); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + MCAuto arr(DataArrayDouble::Aggregate(a)); + MEDCouplingNoTimeLabel *ret(new MEDCouplingNoTimeLabel); ret->setArray(arr,0); return ret; } @@ -1190,12 +1229,12 @@ void MEDCouplingNoTimeLabel::setEndTime(double time, int iteration, int order) throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } -void MEDCouplingNoTimeLabel::getValueOnTime(int eltId, double time, double *value) const +void MEDCouplingNoTimeLabel::getValueOnTime(mcIdType eltId, double time, double *value) const { throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } -void MEDCouplingNoTimeLabel::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const +void MEDCouplingNoTimeLabel::getValueOnDiscTime(mcIdType eltId, int iteration, int order, double *value) const { throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } @@ -1203,7 +1242,7 @@ void MEDCouplingNoTimeLabel::getValueOnDiscTime(int eltId, int iteration, int or /*! * idem getTinySerializationIntInformation except that it is for multi field fetch */ -void MEDCouplingNoTimeLabel::getTinySerializationIntInformation2(std::vector& tinyInfo) const +void MEDCouplingNoTimeLabel::getTinySerializationIntInformation2(std::vector& tinyInfo) const { tinyInfo.clear(); } @@ -1220,7 +1259,7 @@ void MEDCouplingNoTimeLabel::getTinySerializationDbleInformation2(std::vector& tinyInfoI, const std::vector& tinyInfoD) +void MEDCouplingNoTimeLabel::finishUnserialization2(const std::vector& tinyInfoI, const std::vector& tinyInfoD) { _time_tolerance=tinyInfoD[0]; } @@ -1237,7 +1276,7 @@ std::string MEDCouplingWithTimeStep::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 << "\""; + stream << "\nTime unit is : \"" << getTimeUnit() << "\""; return stream.str(); } @@ -1248,11 +1287,11 @@ void MEDCouplingWithTimeStep::synchronizeTimeWith(const MEDCouplingMesh *mesh) int it=-1,order=-1; double val=mesh->getTime(it,order); _tk.setAllInfo(val,it,order); - std::string tUnit=mesh->getTimeUnit(); - _time_unit=tUnit; + std::string tUnit(mesh->getTimeUnit()); + setTimeUnit(tUnit); } -void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector& tinyInfo) const +void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo); tinyInfo.push_back(_tk.getIteration()); @@ -1265,18 +1304,18 @@ void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) +void MEDCouplingWithTimeStep::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) { MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS); _tk.setTimeValue(tinyInfoD[1]); - _tk.setIteration(tinyInfoI[2]); - _tk.setOrder(tinyInfoI[3]); + _tk.setIteration(FromIdType(tinyInfoI[2])); + _tk.setOrder(FromIdType(tinyInfoI[3])); } /*! * idem getTinySerializationIntInformation except that it is for multi field fetch */ -void MEDCouplingWithTimeStep::getTinySerializationIntInformation2(std::vector& tinyInfo) const +void MEDCouplingWithTimeStep::getTinySerializationIntInformation2(std::vector& tinyInfo) const { tinyInfo.resize(2); tinyInfo[0]=_tk.getIteration(); @@ -1296,10 +1335,10 @@ void MEDCouplingWithTimeStep::getTinySerializationDbleInformation2(std::vector& tinyInfoI, const std::vector& tinyInfoD) +void MEDCouplingWithTimeStep::finishUnserialization2(const std::vector& tinyInfoI, const std::vector& tinyInfoD) { - _tk.setIteration(tinyInfoI[0]); - _tk.setOrder(tinyInfoI[1]); + _tk.setIteration(FromIdType(tinyInfoI[0])); + _tk.setOrder(FromIdType(tinyInfoI[1])); _time_tolerance=tinyInfoD[0]; _tk.setTimeValue(tinyInfoD[1]); } @@ -1347,7 +1386,7 @@ bool MEDCouplingWithTimeStep::areCompatibleForMeld(const MEDCouplingTimeDiscreti return otherC!=0; } -bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const +bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const { const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); std::ostringstream oss; oss.precision(15); @@ -1361,7 +1400,7 @@ bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretizatio return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason); } -bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const { const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) @@ -1615,7 +1654,7 @@ void MEDCouplingWithTimeStep::getValueForTime(double time, const std::vector_end); } -void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector& tinyInfo) const +void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo); tinyInfo.push_back(_start.getIteration()); @@ -1667,21 +1706,21 @@ void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation(std::ve tinyInfo.push_back(_end.getTimeValue()); } -void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) +void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) { MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS); _start.setTimeValue(tinyInfoD[1]); _end.setTimeValue(tinyInfoD[2]); - _start.setIteration(tinyInfoI[2]); - _start.setOrder(tinyInfoI[3]); - _end.setIteration(tinyInfoI[4]); - _end.setOrder(tinyInfoI[5]); + _start.setIteration(FromIdType(tinyInfoI[2])); + _start.setOrder(FromIdType(tinyInfoI[3])); + _end.setIteration(FromIdType(tinyInfoI[4])); + _end.setOrder(FromIdType(tinyInfoI[5])); } /*! * idem getTinySerializationIntInformation except that it is for multi field fetch */ -void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation2(std::vector& tinyInfo) const +void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation2(std::vector& tinyInfo) const { tinyInfo.resize(4); tinyInfo[0]=_start.getIteration(); @@ -1704,12 +1743,12 @@ void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation2(std::v /*! * idem finishUnserialization except that it is for multi field fetch */ -void MEDCouplingConstOnTimeInterval::finishUnserialization2(const std::vector& tinyInfoI, const std::vector& tinyInfoD) +void MEDCouplingConstOnTimeInterval::finishUnserialization2(const std::vector& tinyInfoI, const std::vector& tinyInfoD) { - _start.setIteration(tinyInfoI[0]); - _start.setOrder(tinyInfoI[1]); - _end.setIteration(tinyInfoI[2]); - _end.setOrder(tinyInfoI[3]); + _start.setIteration(FromIdType(tinyInfoI[0])); + _start.setOrder(FromIdType(tinyInfoI[1])); + _end.setIteration(FromIdType(tinyInfoI[2])); + _end.setOrder(FromIdType(tinyInfoI[3])); _time_tolerance=tinyInfoD[0]; _start.setTimeValue(tinyInfoD[1]); _end.setTimeValue(tinyInfoD[2]); @@ -1725,7 +1764,7 @@ std::string MEDCouplingConstOnTimeInterval::getStringRepr() const std::ostringstream stream; 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 << "\""; + stream << "\nTime unit is : \"" << getTimeUnit() << "\""; return stream.str(); } @@ -1738,7 +1777,7 @@ void MEDCouplingConstOnTimeInterval::synchronizeTimeWith(const MEDCouplingMesh * _start.setAllInfo(val,it,order); _end.setAllInfo(val,it,order); std::string tUnit(mesh->getTimeUnit()); - _time_unit=tUnit; + setTimeUnit(tUnit); } MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCopyOrIncrRef(bool deepCopy) const @@ -1786,7 +1825,7 @@ bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCoupli { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other)) return false; - const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast(other)); return otherC!=0; } @@ -1794,7 +1833,7 @@ bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCoupli { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) return false; - const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast(other)); return otherC!=0; } @@ -1802,13 +1841,13 @@ bool MEDCouplingConstOnTimeInterval::areCompatibleForMeld(const MEDCouplingTimeD { if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other)) return false; - const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast(other)); return otherC!=0; } -bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const +bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const { - const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast(other)); std::ostringstream oss; oss.precision(15); if(!otherC) { @@ -1822,9 +1861,9 @@ bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscre return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason); } -bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const { - const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast(other)); if(!otherC) return false; if(!_start.isEqual(otherC->_start,_time_tolerance)) @@ -1834,7 +1873,7 @@ bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCoupl return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); } -void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, double *value) const +void MEDCouplingConstOnTimeInterval::getValueOnTime(mcIdType eltId, double time, double *value) const { if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance) if(_array) @@ -1845,7 +1884,7 @@ void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, doub throw INTERP_KERNEL::Exception(EXCEPTION_MSG); } -void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const +void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(mcIdType eltId, int iteration, int order, double *value) const { if(iteration>=_start.getIteration() && iteration<=_end.getIteration()) if(_array) @@ -2087,9 +2126,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,10 +2147,10 @@ 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; - std::string tUnit=mesh->getTimeUnit(); - _time_unit=tUnit; + _start.setAllInfo(val,it,order); + _end.setAllInfo(val,it,order); + std::string tUnit(mesh->getTimeUnit()); + setTimeUnit(tUnit); } std::size_t MEDCouplingTwoTimeSteps::getHeapMemorySizeWithoutChildren() const @@ -2134,12 +2171,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) @@ -2173,51 +2206,19 @@ void MEDCouplingTwoTimeSteps::checkConsistencyLight() const throw INTERP_KERNEL::Exception("The number of tuples mismatch between the start and the end arrays !"); } -bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const +bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const { std::ostringstream oss; - const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(other); + const MEDCouplingTwoTimeSteps *otherC(dynamic_cast(other)); if(!otherC) { 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)) { @@ -2227,22 +2228,14 @@ bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretizatio return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason); } -bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const { - const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(other); + 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 +2243,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 +2260,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()); } @@ -2297,17 +2290,17 @@ void MEDCouplingTwoTimeSteps::setEndArray(DataArrayDouble *array, TimeLabel *own } } -void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(std::vector& tinyInfo) const +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()); - tinyInfo.push_back(_end_array->getNumberOfComponents()); + tinyInfo.push_back(ToIdType(_end_array->getNumberOfComponents())); } else { @@ -2319,20 +2312,20 @@ 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 { - int nbOfCompo=_array->getNumberOfComponents(); - for(int i=0;igetNumberOfComponents(); + for(std::size_t i=0;igetInfoOnComponent(i)); - for(int i=0;igetInfoOnComponent(i)); } -void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays) +void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays) { arrays.resize(2); if(_array!=0) @@ -2357,7 +2350,7 @@ void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector& t arrays[1]=arr; } -void MEDCouplingTwoTimeSteps::checkForUnserialization(const std::vector& tinyInfoI, const std::vector& arrays) +void MEDCouplingTwoTimeSteps::checkForUnserialization(const std::vector& tinyInfoI, const std::vector& arrays) { static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size two !"; if(arrays.size()!=2) @@ -2383,27 +2376,27 @@ void MEDCouplingTwoTimeSteps::checkForUnserialization(const std::vector& ti } } -void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) +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(FromIdType(tinyInfoI[2])); + _start.setOrder(FromIdType(tinyInfoI[3])); + _end.setIteration(FromIdType(tinyInfoI[4])); + _end.setOrder(FromIdType(tinyInfoI[5])); } /*! * idem getTinySerializationIntInformation except that it is for multi field fetch */ -void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation2(std::vector& tinyInfo) const +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,27 +2406,27 @@ void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation2(std::vector& tinyInfoI, const std::vector& tinyInfoD) +void MEDCouplingTwoTimeSteps::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(FromIdType(tinyInfoI[0])); + _start.setOrder(FromIdType(tinyInfoI[1])); + _end.setIteration(FromIdType(tinyInfoI[2])); + _end.setOrder(FromIdType(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,16 +2456,16 @@ 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 << "Time unit is : \"" << _time_unit << "\""; + 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 : \"" << getTimeUnit() << "\""; return stream.str(); } 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."); } @@ -2527,8 +2520,8 @@ bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDis return true; if(_end_array==0 || otherC->_end_array==0) return false; - int nbC1=_end_array->getNumberOfComponents(); - int nbC2=otherC->_end_array->getNumberOfComponents(); + std::size_t nbC1=_end_array->getNumberOfComponents(); + std::size_t nbC2=otherC->_end_array->getNumberOfComponents(); if(nbC1!=nbC2 && nbC2!=1) return false; return true; @@ -2547,7 +2540,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); @@ -2555,15 +2548,14 @@ void MEDCouplingLinearTime::getValueForTime(double time, const std::vector()); } -void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value) const +void MEDCouplingLinearTime::getValueOnTime(mcIdType eltId, double time, double *value) const { - double alpha=(_end_time-time)/(_end_time-_start_time); - int nbComp; + double alpha=(_end.getTimeValue()-time)/(_end.getTimeValue()-_start.getTimeValue()); if(_array) _array->getTuple(eltId,value); else throw INTERP_KERNEL::Exception("No start array existing."); - nbComp=_array->getNumberOfComponents(); + std::size_t nbComp=_array->getNumberOfComponents(); std::transform(value,value+nbComp,value,std::bind2nd(std::multiplies(),alpha)); std::vector tmp(nbComp); if(_end_array) @@ -2574,16 +2566,16 @@ void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value std::transform(tmp.begin(),tmp.end(),value,value,std::plus()); } -void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const +void MEDCouplingLinearTime::getValueOnDiscTime(mcIdType 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 +2612,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 +2624,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 +2637,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 +2649,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 +2662,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 +2673,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 +2685,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;