X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingTimeDiscretization.cxx;h=5237b17a462902b32e5a734193358975d037495d;hb=ac1df6b0ba8b337555fb39610c89f678d889580d;hp=dd334c4eb53ad2680b1f3621bc83fbfd535eeeb2;hpb=7f53ba0ad6eebec56c2936b923ac3ae728f41074;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index dd334c4eb..5237b17a4 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -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."; @@ -117,73 +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)); -} - bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const { int iteration,order; @@ -200,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); @@ -211,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; @@ -251,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; @@ -272,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; @@ -293,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; @@ -314,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; @@ -335,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; @@ -356,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; @@ -377,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; @@ -398,13 +333,11 @@ 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; @@ -419,13 +352,11 @@ 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; @@ -443,7 +374,7 @@ 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 correspondance are not defined symmetrically !"); } } @@ -456,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;japplyFunc(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),_tk(other._tk) -{ -} - -std::string MEDCouplingTimeDiscretizationInt::getStringRepr() const +MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple(other,deepCopy) { - 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 @@ -844,29 +753,63 @@ bool MEDCouplingTimeDiscretizationInt::isEqualWithoutConsideringStr(const MEDCou return _array->isEqualWithoutConsideringStr(*(other->getArray())); } -double MEDCouplingTimeDiscretizationInt::getEndTime(int& iteration, int& order) const +//////////////////////// + +MEDCouplingTimeDiscretizationFloat::MEDCouplingTimeDiscretizationFloat(const MEDCouplingTimeDiscretizationFloat& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple(other,deepCopy) { - throw INTERP_KERNEL::Exception("getEndTime : invalid for this type of time discr !"); } -void MEDCouplingTimeDiscretizationInt::setEndIteration(int it) +MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::performCopyOrIncrRef(bool deepCopy) const { - throw INTERP_KERNEL::Exception("setEndIteration : invalid for this type of time discr !"); + return new MEDCouplingTimeDiscretizationFloat(*this,deepCopy); } -void MEDCouplingTimeDiscretizationInt::setEndOrder(int order) +MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::New(TypeOfTimeDiscretization type) { - throw INTERP_KERNEL::Exception("setEndOrder : invalid for this type of time discr !"); + switch(type) + { + case MEDCouplingTimeDiscretizationFloat::DISCRETIZATION: + return new MEDCouplingTimeDiscretizationFloat; + default: + throw INTERP_KERNEL::Exception("Time discretization not implemented yet for intergers !"); + } } -void MEDCouplingTimeDiscretizationInt::setEndTimeValue(double time) +bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, float prec, std::string& reason) const { - throw INTERP_KERNEL::Exception("setEndTimeValue : invalid for this type of time discr !"); + if(!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); } -void MEDCouplingTimeDiscretizationInt::setEndTime(double time, int iteration, int order) +bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, float prec) const { - throw INTERP_KERNEL::Exception("setEndTime : invalid for this type of time discr !"); + if(prec!=0) + throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr : only precision 0 is supported !"); + const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast(other)); + if(!otherC) + throw INTERP_KERNEL::Exception("isEqualWithoutConsideringStr : other is not a MEDCouplingTimeDiscretizationFloat !"); + std::string tmp; + if(!areStrictlyCompatible(other,tmp)) + return false; + std::string reason; + if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) + return false; + if(_array==other->getArray()) + return true; + return _array->isEqualWithoutConsideringStr(*(other->getArray()),prec); } //////////////////////// @@ -883,7 +826,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(); } @@ -1272,7 +1215,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(); } @@ -1283,8 +1226,8 @@ 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 @@ -1760,7 +1703,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(); } @@ -1773,7 +1716,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 @@ -2145,8 +2088,8 @@ void MEDCouplingTwoTimeSteps::synchronizeTimeWith(const MEDCouplingMesh *mesh) double val=mesh->getTime(it,order); _start.setAllInfo(val,it,order); _end.setAllInfo(val,it,order); - std::string tUnit=mesh->getTimeUnit(); - _time_unit=tUnit; + std::string tUnit(mesh->getTimeUnit()); + setTimeUnit(tUnit); } std::size_t MEDCouplingTwoTimeSteps::getHeapMemorySizeWithoutChildren() const @@ -2454,7 +2397,7 @@ std::string MEDCouplingLinearTime::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 << "Time unit is : \"" << _time_unit << "\""; + stream << "Time unit is : \"" << getTimeUnit() << "\""; return stream.str(); }