1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDCouplingTimeDiscretization.hxx"
21 #include "MEDCouplingMemArray.hxx"
22 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
30 using namespace ParaMEDMEM;
32 const double MEDCouplingTimeDiscretization::TIME_TOLERANCE_DFT=1.e-12;
34 const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setTime : no time info attached.";
36 const char MEDCouplingNoTimeLabel::REPR[]="No time label defined.";
38 const char MEDCouplingWithTimeStep::EXCEPTION_MSG[]="No data on this time.";
40 const char MEDCouplingWithTimeStep::REPR[]="One time label.";
42 const char MEDCouplingConstOnTimeInterval::EXCEPTION_MSG[]="No data on this time.";
44 const char MEDCouplingConstOnTimeInterval::REPR[]="Constant on a time interval.";
46 const char MEDCouplingTwoTimeSteps::EXCEPTION_MSG[]="No data on this time.";
48 const char MEDCouplingLinearTime::REPR[]="Linear time between 2 time steps.";
50 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDiscretization type)
54 case MEDCouplingNoTimeLabel::DISCRETIZATION:
55 return new MEDCouplingNoTimeLabel;
56 case MEDCouplingWithTimeStep::DISCRETIZATION:
57 return new MEDCouplingWithTimeStep;
58 case MEDCouplingConstOnTimeInterval::DISCRETIZATION:
59 return new MEDCouplingConstOnTimeInterval;
60 case MEDCouplingLinearTime::DISCRETIZATION:
61 return new MEDCouplingLinearTime;
63 throw INTERP_KERNEL::Exception("Time discretization not implemented yet");
67 void MEDCouplingTimeDiscretization::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception)
69 _time_tolerance=other._time_tolerance;
70 _time_unit=other._time_unit;
73 void MEDCouplingTimeDiscretization::copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other)
75 _time_unit=other._time_unit;
76 if(_array && other._array)
77 _array->copyStringInfoFrom(*other._array);
80 void MEDCouplingTimeDiscretization::checkCoherency() const throw(INTERP_KERNEL::Exception)
83 throw INTERP_KERNEL::Exception("Field invalid because no values set !");
84 if(_time_tolerance<0.)
85 throw INTERP_KERNEL::Exception("time tolerance is expected to be greater than 0. !");
88 void MEDCouplingTimeDiscretization::updateTime() const
91 updateTimeWith(*_array);
94 bool MEDCouplingTimeDiscretization::areCompatible(const MEDCouplingTimeDiscretization *other) const
96 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
98 if(_array==0 && other->_array==0)
100 if(_array==0 || other->_array==0)
102 if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
107 bool MEDCouplingTimeDiscretization::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const
109 std::ostringstream oss; oss.precision(15);
110 if(_time_unit!=other->_time_unit)
112 oss << "Field discretizations differ : this time unit = \"" << _time_unit << "\" and other time unit = \"" << other->_time_unit << "\" !";
116 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
118 oss << "Field discretizations differ : this time tolerance = \"" << _time_tolerance << "\" and other time tolerance = \"" << other->_time_tolerance << "\" !";
122 if(_array==0 && other->_array==0)
124 if(_array==0 || other->_array==0)
126 reason="Field discretizations differ : Only one timediscretization between the two this and other has a DataArrayDouble for values defined";
129 if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
131 if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
136 bool MEDCouplingTimeDiscretization::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
138 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
140 if(_array==0 && other->_array==0)
142 if(_array==0 || other->_array==0)
144 if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
149 bool MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
151 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
153 if(_array==0 && other->_array==0)
155 if(_array==0 || other->_array==0)
157 int nbC1=_array->getNumberOfComponents();
158 int nbC2=other->_array->getNumberOfComponents();
159 int nbMin=std::min(nbC1,nbC2);
160 if(nbC1!=nbC2 && nbMin!=1)
165 bool MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
167 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
169 if(_array==0 && other->_array==0)
171 if(_array==0 || other->_array==0)
173 int nbC1=_array->getNumberOfComponents();
174 int nbC2=other->_array->getNumberOfComponents();
175 if(nbC1!=nbC2 && nbC2!=1)
180 bool MEDCouplingTimeDiscretization::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
182 if(!areStrictlyCompatible(other,reason))
184 if(_array==other->_array)
186 return _array->isEqualIfNotWhy(*other->_array,prec,reason);
189 bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
192 return isEqualIfNotWhy(other,prec,reason);
195 bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
198 if(!areStrictlyCompatible(other,tmp))
200 if(_array==other->_array)
202 return _array->isEqualWithoutConsideringStr(*other->_array,prec);
205 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(TypeOfTimeDiscretization type, bool deepCpy) const
207 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(type);
208 ret->setTimeUnit(getTimeUnit());
209 const DataArrayDouble *arrSrc=getArray();
210 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr;
212 arr=arrSrc->performCpy(deepCpy);
213 ret->setArray(arr,0);
217 void MEDCouplingTimeDiscretization::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
221 tinyInfo.push_back(_array->getNumberOfTuples());
222 tinyInfo.push_back(_array->getNumberOfComponents());
226 tinyInfo.push_back(-1);
227 tinyInfo.push_back(-1);
231 void MEDCouplingTimeDiscretization::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
236 DataArrayDouble *arr=0;
237 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
239 arr=DataArrayDouble::New();
240 arr->alloc(tinyInfoI[0],tinyInfoI[1]);
246 void MEDCouplingTimeDiscretization::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
248 _time_tolerance=tinyInfoD[0];
249 int nbOfCompo=_array->getNumberOfComponents();
250 for(int i=0;i<nbOfCompo;i++)
251 _array->setInfoOnComponent(i,tinyInfoS[i].c_str());
254 void MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
256 tinyInfo.push_back(_time_tolerance);
259 void MEDCouplingTimeDiscretization::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
261 int nbOfCompo=_array->getNumberOfComponents();
262 for(int i=0;i<nbOfCompo;i++)
263 tinyInfo.push_back(_array->getInfoOnComponent(i));
266 MEDCouplingTimeDiscretization::MEDCouplingTimeDiscretization():_time_tolerance(TIME_TOLERANCE_DFT),_array(0)
270 MEDCouplingTimeDiscretization::MEDCouplingTimeDiscretization(const MEDCouplingTimeDiscretization& other, bool deepCpy):_time_unit(other._time_unit),_time_tolerance(other._time_tolerance)
273 _array=other._array->performCpy(deepCpy);
278 MEDCouplingTimeDiscretization::~MEDCouplingTimeDiscretization()
284 void MEDCouplingTimeDiscretization::setArray(DataArrayDouble *array, TimeLabel *owner)
294 owner->declareAsNew();
298 const DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray() const
300 throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
303 DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray()
305 throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
308 void MEDCouplingTimeDiscretization::setEndArray(DataArrayDouble *array, TimeLabel *owner)
310 throw INTERP_KERNEL::Exception("setEndArray not available for this type of time discretization !");
313 void MEDCouplingTimeDiscretization::setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner) throw(INTERP_KERNEL::Exception)
316 throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretization::setArrays : number of arrays must be one.");
317 setArray(arrays.back(),owner);
320 void MEDCouplingTimeDiscretization::getArrays(std::vector<DataArrayDouble *>& arrays) const
326 bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception)
329 double time1=getEndTime(iteration,order)-_time_tolerance;
330 double time2=other->getStartTime(iteration,order)+other->getTimeTolerance();
334 bool MEDCouplingTimeDiscretization::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception)
337 double time1=getEndTime(iteration,order)+_time_tolerance;
338 double time2=other->getStartTime(iteration,order)-other->getTimeTolerance();
342 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
344 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
345 ret->setTimeUnit(getTimeUnit());
346 std::vector<DataArrayDouble *> arrays;
348 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
349 for(int j=0;j<(int)arrays.size();j++)
352 arrays2[j]=arrays[j]->doublyContractedProduct();
356 std::vector<DataArrayDouble *> arrays3(arrays.size());
357 for(int j=0;j<(int)arrays.size();j++)
358 arrays3[j]=arrays2[j];
359 ret->setArrays(arrays3,0);
363 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() const throw(INTERP_KERNEL::Exception)
365 std::vector<DataArrayDouble *> arrays;
367 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
368 for(int j=0;j<(int)arrays.size();j++)
371 arrays2[j]=arrays[j]->determinant();
375 std::vector<DataArrayDouble *> arrays3(arrays.size());
376 for(int j=0;j<(int)arrays.size();j++)
377 arrays3[j]=arrays2[j];
378 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
379 ret->setTimeUnit(getTimeUnit());
380 ret->setArrays(arrays3,0);
384 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() const throw(INTERP_KERNEL::Exception)
386 std::vector<DataArrayDouble *> arrays;
388 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
389 for(int j=0;j<(int)arrays.size();j++)
392 arrays2[j]=arrays[j]->eigenValues();
396 std::vector<DataArrayDouble *> arrays3(arrays.size());
397 for(int j=0;j<(int)arrays.size();j++)
398 arrays3[j]=arrays2[j];
399 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
400 ret->setTimeUnit(getTimeUnit());
401 ret->setArrays(arrays3,0);
405 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() const throw(INTERP_KERNEL::Exception)
407 std::vector<DataArrayDouble *> arrays;
409 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
410 for(int j=0;j<(int)arrays.size();j++)
413 arrays2[j]=arrays[j]->eigenVectors();
417 std::vector<DataArrayDouble *> arrays3(arrays.size());
418 for(int j=0;j<(int)arrays.size();j++)
419 arrays3[j]=arrays2[j];
420 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
421 ret->setTimeUnit(getTimeUnit());
422 ret->setArrays(arrays3,0);
426 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const throw(INTERP_KERNEL::Exception)
428 std::vector<DataArrayDouble *> arrays;
430 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
431 for(int j=0;j<(int)arrays.size();j++)
434 arrays2[j]=arrays[j]->inverse();
438 std::vector<DataArrayDouble *> arrays3(arrays.size());
439 for(int j=0;j<(int)arrays.size();j++)
440 arrays3[j]=arrays2[j];
441 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
442 ret->setTimeUnit(getTimeUnit());
443 ret->setArrays(arrays3,0);
447 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const throw(INTERP_KERNEL::Exception)
449 std::vector<DataArrayDouble *> arrays;
451 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
452 for(int j=0;j<(int)arrays.size();j++)
455 arrays2[j]=arrays[j]->trace();
459 std::vector<DataArrayDouble *> arrays3(arrays.size());
460 for(int j=0;j<(int)arrays.size();j++)
461 arrays3[j]=arrays2[j];
462 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
463 ret->setTimeUnit(getTimeUnit());
464 ret->setArrays(arrays3,0);
468 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const throw(INTERP_KERNEL::Exception)
470 std::vector<DataArrayDouble *> arrays;
472 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
473 for(int j=0;j<(int)arrays.size();j++)
476 arrays2[j]=arrays[j]->deviator();
480 std::vector<DataArrayDouble *> arrays3(arrays.size());
481 for(int j=0;j<(int)arrays.size();j++)
482 arrays3[j]=arrays2[j];
483 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
484 ret->setTimeUnit(getTimeUnit());
485 ret->setArrays(arrays3,0);
489 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const throw(INTERP_KERNEL::Exception)
491 std::vector<DataArrayDouble *> arrays;
493 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
494 for(int j=0;j<(int)arrays.size();j++)
497 arrays2[j]=arrays[j]->magnitude();
501 std::vector<DataArrayDouble *> arrays3(arrays.size());
502 for(int j=0;j<(int)arrays.size();j++)
503 arrays3[j]=arrays2[j];
504 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
505 ret->setTimeUnit(getTimeUnit());
506 ret->setArrays(arrays3,0);
510 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() const throw(INTERP_KERNEL::Exception)
512 std::vector<DataArrayDouble *> arrays;
514 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
515 for(int j=0;j<(int)arrays.size();j++)
518 arrays2[j]=arrays[j]->maxPerTuple();
522 std::vector<DataArrayDouble *> arrays3(arrays.size());
523 for(int j=0;j<(int)arrays.size();j++)
524 arrays3[j]=arrays2[j];
525 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
526 ret->setTimeUnit(getTimeUnit());
527 ret->setArrays(arrays3,0);
531 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
533 std::vector<DataArrayDouble *> arrays;
535 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
536 for(int j=0;j<(int)arrays.size();j++)
539 arrays2[j]=arrays[j]->keepSelectedComponents(compoIds);
543 std::vector<DataArrayDouble *> arrays3(arrays.size());
544 for(int j=0;j<(int)arrays.size();j++)
545 arrays3[j]=arrays2[j];
546 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
547 ret->setTimeUnit(getTimeUnit());
548 ret->setArrays(arrays3,0);
552 void MEDCouplingTimeDiscretization::setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
554 std::vector<DataArrayDouble *> arrays1,arrays2;
556 other->getArrays(arrays2);
557 if(arrays1.size()!=arrays2.size())
558 throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : number of arrays mismatch !");
559 for(unsigned int i=0;i<arrays1.size();i++)
561 if(arrays1[i]!=0 && arrays2[i]!=0)
562 arrays1[i]->setSelectedComponents(arrays2[i],compoIds);
563 else if(arrays1[i]!=0 || arrays2[i]!=0)
564 throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : some time array in correspondance are not defined symetrically !");
568 void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double dftValue) throw(INTERP_KERNEL::Exception)
570 std::vector<DataArrayDouble *> arrays;
572 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
573 for(int j=0;j<(int)arrays.size();j++)
576 arrays2[j]=arrays[j]->changeNbOfComponents(newNbOfComp,dftValue);
580 std::vector<DataArrayDouble *> arrays3(arrays.size());
581 for(int j=0;j<(int)arrays.size();j++)
582 arrays3[j]=arrays2[j];
583 setArrays(arrays3,0);
586 void MEDCouplingTimeDiscretization::sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception)
588 std::vector<DataArrayDouble *> arrays;
590 for(int j=0;j<(int)arrays.size();j++)
593 arrays[j]->sortPerTuple(asc);
597 void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, int nbOfCompo, double value)
599 std::vector<DataArrayDouble *> arrays;
601 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
602 for(int j=0;j<(int)arrays.size();j++)
606 arrays[j]->incrRef();
607 arrays[j]->fillWithValue(value);
608 arrays2[j]=arrays[j];
612 DataArrayDouble *tmp=DataArrayDouble::New();
613 tmp->alloc(nbOfTuple,nbOfCompo);
614 tmp->fillWithValue(value);
618 std::vector<DataArrayDouble *> arrays3(arrays.size());
619 for(int j=0;j<(int)arrays.size();j++)
620 arrays3[j]=arrays2[j];
621 setArrays(arrays3,0);
624 void MEDCouplingTimeDiscretization::applyLin(double a, double b, int compoId)
626 std::vector<DataArrayDouble *> arrays;
628 for(int j=0;j<(int)arrays.size();j++)
631 arrays[j]->applyLin(a,b,compoId);
635 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate func)
637 std::vector<DataArrayDouble *> arrays;
639 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
640 for(int j=0;j<(int)arrays.size();j++)
643 arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
647 std::vector<DataArrayDouble *> arrays3(arrays.size());
648 for(int j=0;j<(int)arrays.size();j++)
649 arrays3[j]=arrays2[j];
650 setArrays(arrays3,0);
653 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const char *func)
655 std::vector<DataArrayDouble *> arrays;
657 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
658 for(int j=0;j<(int)arrays.size();j++)
661 arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
665 std::vector<DataArrayDouble *> arrays3(arrays.size());
666 for(int j=0;j<(int)arrays.size();j++)
667 arrays3[j]=arrays2[j];
668 setArrays(arrays3,0);
671 void MEDCouplingTimeDiscretization::applyFunc2(int nbOfComp, const char *func)
673 std::vector<DataArrayDouble *> arrays;
675 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
676 for(int j=0;j<(int)arrays.size();j++)
679 arrays2[j]=arrays[j]->applyFunc2(nbOfComp,func);
683 std::vector<DataArrayDouble *> arrays3(arrays.size());
684 for(int j=0;j<(int)arrays.size();j++)
685 arrays3[j]=arrays2[j];
686 setArrays(arrays3,0);
689 void MEDCouplingTimeDiscretization::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const char *func)
691 std::vector<DataArrayDouble *> arrays;
693 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
694 for(int j=0;j<(int)arrays.size();j++)
697 arrays2[j]=arrays[j]->applyFunc3(nbOfComp,varsOrder,func);
701 std::vector<DataArrayDouble *> arrays3(arrays.size());
702 for(int j=0;j<(int)arrays.size();j++)
703 arrays3[j]=arrays2[j];
704 setArrays(arrays3,0);
707 void MEDCouplingTimeDiscretization::applyFunc(const char *func)
709 std::vector<DataArrayDouble *> arrays;
711 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
712 for(int j=0;j<(int)arrays.size();j++)
715 arrays2[j]=arrays[j]->applyFunc(func);
719 std::vector<DataArrayDouble *> arrays3(arrays.size());
720 for(int j=0;j<(int)arrays.size();j++)
721 arrays3[j]=arrays2[j];
722 setArrays(arrays3,0);
725 void MEDCouplingTimeDiscretization::applyFuncFast32(const char *func)
727 std::vector<DataArrayDouble *> arrays;
729 for(int j=0;j<(int)arrays.size();j++)
732 arrays[j]->applyFuncFast32(func);
736 void MEDCouplingTimeDiscretization::applyFuncFast64(const char *func)
738 std::vector<DataArrayDouble *> arrays;
740 for(int j=0;j<(int)arrays.size();j++)
743 arrays[j]->applyFuncFast64(func);
747 void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, FunctionToEvaluate func) throw(INTERP_KERNEL::Exception)
749 std::vector<DataArrayDouble *> arrays;
751 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
752 for(int j=0;j<(int)arrays.size();j++)
753 arrays2[j]=loc->applyFunc(nbOfComp,func);
754 std::vector<DataArrayDouble *> arrays3(arrays.size());
755 for(int j=0;j<(int)arrays.size();j++)
756 arrays3[j]=arrays2[j];
757 setArrays(arrays3,0);
760 void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception)
762 std::vector<DataArrayDouble *> arrays;
764 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
765 for(int j=0;j<(int)arrays.size();j++)
766 arrays2[j]=loc->applyFunc(nbOfComp,func);
767 std::vector<DataArrayDouble *> arrays3(arrays.size());
768 for(int j=0;j<(int)arrays.size();j++)
769 arrays3[j]=arrays2[j];
770 setArrays(arrays3,0);
773 void MEDCouplingTimeDiscretization::fillFromAnalytic2(const DataArrayDouble *loc, int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception)
775 std::vector<DataArrayDouble *> arrays;
777 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
778 for(int j=0;j<(int)arrays.size();j++)
779 arrays2[j]=loc->applyFunc2(nbOfComp,func);
780 std::vector<DataArrayDouble *> arrays3(arrays.size());
781 for(int j=0;j<(int)arrays.size();j++)
782 arrays3[j]=arrays2[j];
783 setArrays(arrays3,0);
786 void MEDCouplingTimeDiscretization::fillFromAnalytic3(const DataArrayDouble *loc, int nbOfComp, const std::vector<std::string>& varsOrder, const char *func) throw(INTERP_KERNEL::Exception)
788 std::vector<DataArrayDouble *> arrays;
790 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
791 for(int j=0;j<(int)arrays.size();j++)
792 arrays2[j]=loc->applyFunc3(nbOfComp,varsOrder,func);
793 std::vector<DataArrayDouble *> arrays3(arrays.size());
794 for(int j=0;j<(int)arrays.size();j++)
795 arrays3[j]=arrays2[j];
796 setArrays(arrays3,0);
799 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel()
803 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretization& other, bool deepCpy):MEDCouplingTimeDiscretization(other,deepCpy)
807 std::string MEDCouplingNoTimeLabel::getStringRepr() const
809 std::ostringstream stream;
811 stream << "\nTime unit is : \"" << _time_unit << "\"";
815 bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretization *other) const
817 if(!MEDCouplingTimeDiscretization::areCompatible(other))
819 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
823 bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const
825 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
827 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
830 reason.insert(0,"time discretization of this is NO_TIME, other has a different time discretization.");
834 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
836 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
838 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
842 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
844 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
846 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
850 bool MEDCouplingNoTimeLabel::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
852 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
854 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
858 bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
860 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
863 reason="This has time discretization NO_TIME, other not.";
866 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
869 bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
871 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
874 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
877 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCouplingTimeDiscretization *other) const
879 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
881 throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !");
882 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
883 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
884 ret->setArray(arr,0);
888 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
890 std::vector<const DataArrayDouble *> a(other.size());
892 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
894 const MEDCouplingNoTimeLabel *itC=dynamic_cast<const MEDCouplingNoTimeLabel *>(*it);
896 throw INTERP_KERNEL::Exception("NoTimeLabel::aggregate on mismatched time discretization !");
897 a[i]=itC->getArray();
899 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
900 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
901 ret->setArray(arr,0);
905 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::meld(const MEDCouplingTimeDiscretization *other) const
907 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
909 throw INTERP_KERNEL::Exception("NoTimeLabel::meld on mismatched time discretization !");
910 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
911 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
912 ret->setTimeTolerance(getTimeTolerance());
913 ret->setArray(arr,0);
917 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::dot(const MEDCouplingTimeDiscretization *other) const
919 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
921 throw INTERP_KERNEL::Exception("NoTimeLabel::dot on mismatched time discretization !");
922 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
923 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
924 ret->setArray(arr,0);
928 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::crossProduct(const MEDCouplingTimeDiscretization *other) const
930 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
932 throw INTERP_KERNEL::Exception("NoTimeLabel::crossProduct on mismatched time discretization !");
933 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
934 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
935 ret->setArray(arr,0);
939 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::max(const MEDCouplingTimeDiscretization *other) const
941 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
943 throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
944 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
945 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
946 ret->setArray(arr,0);
950 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::min(const MEDCouplingTimeDiscretization *other) const
952 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
954 throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
955 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
956 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
957 ret->setArray(arr,0);
961 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::add(const MEDCouplingTimeDiscretization *other) const
963 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
965 throw INTERP_KERNEL::Exception("NoTimeLabel::add on mismatched time discretization !");
966 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
967 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
968 ret->setArray(arr,0);
972 void MEDCouplingNoTimeLabel::addEqual(const MEDCouplingTimeDiscretization *other)
974 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
976 throw INTERP_KERNEL::Exception("NoTimeLabel::addEqual on mismatched time discretization !");
978 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::addEqual : Data Array is NULL !");
979 getArray()->addEqual(other->getArray());
982 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::substract(const MEDCouplingTimeDiscretization *other) const
984 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
986 throw INTERP_KERNEL::Exception("NoTimeLabel::substract on mismatched time discretization !");
988 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substract : Data Array is NULL !");
989 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
990 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
991 ret->setArray(arr,0);
995 void MEDCouplingNoTimeLabel::substractEqual(const MEDCouplingTimeDiscretization *other)
997 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
999 throw INTERP_KERNEL::Exception("NoTimeLabel::substractEqual on mismatched time discretization !");
1001 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substractEqual : Data Array is NULL !");
1002 getArray()->substractEqual(other->getArray());
1005 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::multiply(const MEDCouplingTimeDiscretization *other) const
1007 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1009 throw INTERP_KERNEL::Exception("NoTimeLabel::multiply on mismatched time discretization !");
1010 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1011 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1012 ret->setArray(arr,0);
1016 void MEDCouplingNoTimeLabel::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1018 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1020 throw INTERP_KERNEL::Exception("NoTimeLabel::multiplyEqual on mismatched time discretization !");
1022 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::multiplyEqual : Data Array is NULL !");
1023 getArray()->multiplyEqual(other->getArray());
1026 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::divide(const MEDCouplingTimeDiscretization *other) const
1028 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1030 throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
1031 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1032 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1033 ret->setArray(arr,0);
1037 void MEDCouplingNoTimeLabel::divideEqual(const MEDCouplingTimeDiscretization *other)
1039 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1041 throw INTERP_KERNEL::Exception("NoTimeLabel::divideEqual on mismatched time discretization !");
1043 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::divideEqual : Data Array is NULL !");
1044 getArray()->divideEqual(other->getArray());
1047 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCpy(bool deepCpy) const
1049 return new MEDCouplingNoTimeLabel(*this,deepCpy);
1052 void MEDCouplingNoTimeLabel::checkTimePresence(double time) const throw(INTERP_KERNEL::Exception)
1054 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1057 std::vector< const DataArrayDouble *> MEDCouplingNoTimeLabel::getArraysForTime(double time) const throw(INTERP_KERNEL::Exception)
1059 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1062 void MEDCouplingNoTimeLabel::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1064 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1067 bool MEDCouplingNoTimeLabel::isBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception)
1069 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1072 bool MEDCouplingNoTimeLabel::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception)
1074 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1077 double MEDCouplingNoTimeLabel::getStartTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception)
1079 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1082 double MEDCouplingNoTimeLabel::getEndTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception)
1084 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1087 void MEDCouplingNoTimeLabel::setStartIteration(int it) throw(INTERP_KERNEL::Exception)
1089 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1092 void MEDCouplingNoTimeLabel::setEndIteration(int it) throw(INTERP_KERNEL::Exception)
1094 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1097 void MEDCouplingNoTimeLabel::setStartOrder(int order) throw(INTERP_KERNEL::Exception)
1099 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1102 void MEDCouplingNoTimeLabel::setEndOrder(int order) throw(INTERP_KERNEL::Exception)
1104 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1107 void MEDCouplingNoTimeLabel::setStartTimeValue(double time) throw(INTERP_KERNEL::Exception)
1109 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1112 void MEDCouplingNoTimeLabel::setEndTimeValue(double time) throw(INTERP_KERNEL::Exception)
1114 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1117 void MEDCouplingNoTimeLabel::setStartTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception)
1119 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1122 void MEDCouplingNoTimeLabel::setEndTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception)
1124 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1127 void MEDCouplingNoTimeLabel::getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception)
1129 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1132 void MEDCouplingNoTimeLabel::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception)
1134 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1138 * idem getTinySerializationIntInformation except that it is for multi field fetch
1140 void MEDCouplingNoTimeLabel::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1146 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1148 void MEDCouplingNoTimeLabel::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1151 tinyInfo[0]=_time_tolerance;
1155 * idem finishUnserialization except that it is for multi field fetch
1157 void MEDCouplingNoTimeLabel::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1159 _time_tolerance=tinyInfoD[0];
1162 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCpy):MEDCouplingTimeDiscretization(other,deepCpy),
1163 _time(other._time),_iteration(other._iteration),_order(other._order)
1167 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep():_time(0.),_iteration(-1),_order(-1)
1171 std::string MEDCouplingWithTimeStep::getStringRepr() const
1173 std::ostringstream stream;
1174 stream << REPR << " Time is defined by iteration=" << _iteration << " order=" << _order << " and time=" << _time << ".";
1175 stream << "\nTime unit is : \"" << _time_unit << "\"";
1176 return stream.str();
1179 void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1181 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1182 tinyInfo.push_back(_iteration);
1183 tinyInfo.push_back(_order);
1186 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1188 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1189 tinyInfo.push_back(_time);
1192 void MEDCouplingWithTimeStep::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1194 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1196 _iteration=tinyInfoI[2];
1197 _order=tinyInfoI[3];
1201 * idem getTinySerializationIntInformation except that it is for multi field fetch
1203 void MEDCouplingWithTimeStep::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1206 tinyInfo[0]=_iteration;
1211 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1213 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1216 tinyInfo[0]=_time_tolerance;
1221 * idem finishUnserialization except that it is for multi field fetch
1223 void MEDCouplingWithTimeStep::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1225 _iteration=tinyInfoI[0];
1226 _order=tinyInfoI[1];
1227 _time_tolerance=tinyInfoD[0];
1231 bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretization *other) const
1233 if(!MEDCouplingTimeDiscretization::areCompatible(other))
1235 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1239 bool MEDCouplingWithTimeStep::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const
1241 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1243 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1246 reason.insert(0,"time discretization of this is ONE_TIME, other has a different time discretization.");
1250 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
1252 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1254 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1258 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
1260 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1262 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1266 bool MEDCouplingWithTimeStep::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1268 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1270 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1274 bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
1276 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1277 std::ostringstream oss; oss.precision(15);
1280 reason="This has time discretization ONE_TIME, other not.";
1283 if(_iteration!=otherC->_iteration)
1285 oss << "iterations differ. this iteration=" << _iteration << " other iteration=" << otherC->_iteration;
1289 if(_order!=otherC->_order)
1291 oss << "orders differ. this order=" << _order << " other order=" << otherC->_order;
1295 if(std::fabs(_time-otherC->_time)>_time_tolerance)
1297 oss << "times differ. this time=" << _time << " other time=" << otherC->_time;
1301 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1304 bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
1306 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1309 if(_iteration!=otherC->_iteration)
1311 if(_order!=otherC->_order)
1313 if(std::fabs(_time-otherC->_time)>_time_tolerance)
1315 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1318 void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception)
1320 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1321 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(&other);
1323 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::copyTinyAttrFrom : mismatch of time discretization !");
1324 _time=otherC->_time;
1325 _iteration=otherC->_iteration;
1326 _order=otherC->_order;
1329 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCouplingTimeDiscretization *other) const
1331 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1333 throw INTERP_KERNEL::Exception("WithTimeStep::aggregation on mismatched time discretization !");
1334 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1335 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1336 ret->setArray(arr,0);
1340 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1342 std::vector<const DataArrayDouble *> a(other.size());
1344 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1346 const MEDCouplingWithTimeStep *itC=dynamic_cast<const MEDCouplingWithTimeStep *>(*it);
1348 throw INTERP_KERNEL::Exception("WithTimeStep::aggregate on mismatched time discretization !");
1349 a[i]=itC->getArray();
1351 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1352 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1353 ret->setArray(arr,0);
1357 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::meld(const MEDCouplingTimeDiscretization *other) const
1359 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1361 throw INTERP_KERNEL::Exception("WithTimeStep::meld on mismatched time discretization !");
1362 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1363 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1364 ret->setArray(arr,0);
1368 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::dot(const MEDCouplingTimeDiscretization *other) const
1370 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1372 throw INTERP_KERNEL::Exception("WithTimeStep::dot on mismatched time discretization !");
1373 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1374 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1375 ret->setArray(arr,0);
1379 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::crossProduct(const MEDCouplingTimeDiscretization *other) const
1381 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1383 throw INTERP_KERNEL::Exception("WithTimeStep::crossProduct on mismatched time discretization !");
1384 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1385 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1386 ret->setArray(arr,0);
1390 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::max(const MEDCouplingTimeDiscretization *other) const
1392 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1394 throw INTERP_KERNEL::Exception("WithTimeStep::max on mismatched time discretization !");
1395 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1396 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1397 ret->setArray(arr,0);
1401 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::min(const MEDCouplingTimeDiscretization *other) const
1403 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1405 throw INTERP_KERNEL::Exception("WithTimeStep::min on mismatched time discretization !");
1406 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1407 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1408 ret->setArray(arr,0);
1412 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::add(const MEDCouplingTimeDiscretization *other) const
1414 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1416 throw INTERP_KERNEL::Exception("WithTimeStep::add on mismatched time discretization !");
1417 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1418 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1419 ret->setArray(arr,0);
1421 double tmp3=getStartTime(tmp1,tmp2);
1422 ret->setStartTime(tmp3,tmp1,tmp2);
1426 void MEDCouplingWithTimeStep::addEqual(const MEDCouplingTimeDiscretization *other)
1428 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1430 throw INTERP_KERNEL::Exception("WithTimeStep::addEqual on mismatched time discretization !");
1432 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::addEqual : Data Array is NULL !");
1433 getArray()->addEqual(other->getArray());
1436 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::substract(const MEDCouplingTimeDiscretization *other) const
1438 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1440 throw INTERP_KERNEL::Exception("WithTimeStep::substract on mismatched time discretization !");
1441 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1442 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1443 ret->setArray(arr,0);
1445 double tmp3=getStartTime(tmp1,tmp2);
1446 ret->setStartTime(tmp3,tmp1,tmp2);
1450 void MEDCouplingWithTimeStep::substractEqual(const MEDCouplingTimeDiscretization *other)
1452 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1454 throw INTERP_KERNEL::Exception("WithTimeStep::substractEqual on mismatched time discretization !");
1456 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::substractEqual : Data Array is NULL !");
1457 getArray()->substractEqual(other->getArray());
1460 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::multiply(const MEDCouplingTimeDiscretization *other) const
1462 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1464 throw INTERP_KERNEL::Exception("WithTimeStep::multiply on mismatched time discretization !");
1465 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1466 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1467 ret->setArray(arr,0);
1469 double tmp3=getStartTime(tmp1,tmp2);
1470 ret->setStartTime(tmp3,tmp1,tmp2);
1474 void MEDCouplingWithTimeStep::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1476 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1478 throw INTERP_KERNEL::Exception("WithTimeStep::multiplyEqual on mismatched time discretization !");
1480 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::multiplyEqual : Data Array is NULL !");
1481 getArray()->multiplyEqual(other->getArray());
1484 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::divide(const MEDCouplingTimeDiscretization *other) const
1486 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1488 throw INTERP_KERNEL::Exception("WithTimeStep::divide on mismatched time discretization !");
1489 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1490 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1491 ret->setArray(arr,0);
1493 double tmp3=getStartTime(tmp1,tmp2);
1494 ret->setStartTime(tmp3,tmp1,tmp2);
1498 void MEDCouplingWithTimeStep::divideEqual(const MEDCouplingTimeDiscretization *other)
1500 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1502 throw INTERP_KERNEL::Exception("WithTimeStep::divideEqual on mismatched time discretization !");
1504 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::divideEqual : Data Array is NULL !");
1505 getArray()->divideEqual(other->getArray());
1508 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCpy(bool deepCpy) const
1510 return new MEDCouplingWithTimeStep(*this,deepCpy);
1513 void MEDCouplingWithTimeStep::checkNoTimePresence() const throw(INTERP_KERNEL::Exception)
1515 throw INTERP_KERNEL::Exception("No time specified on a field defined on one time");
1518 void MEDCouplingWithTimeStep::checkTimePresence(double time) const throw(INTERP_KERNEL::Exception)
1520 if(std::fabs(time-_time)>_time_tolerance)
1522 std::ostringstream stream;
1523 stream << "The field is defined on time " << _time << " with eps=" << _time_tolerance << " and asking time = " << time << " !";
1524 throw INTERP_KERNEL::Exception(stream.str().c_str());
1528 std::vector< const DataArrayDouble *> MEDCouplingWithTimeStep::getArraysForTime(double time) const throw(INTERP_KERNEL::Exception)
1530 if(std::fabs(time-_time)<=_time_tolerance)
1532 std::vector< const DataArrayDouble *> ret(1);
1537 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1540 void MEDCouplingWithTimeStep::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1542 std::copy(vals.begin(),vals.end(),res);
1545 void MEDCouplingWithTimeStep::getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception)
1547 if(std::fabs(time-_time)<=_time_tolerance)
1549 _array->getTuple(eltId,value);
1551 throw INTERP_KERNEL::Exception("No array existing.");
1553 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1556 void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception)
1558 if(_iteration==iteration && _order==order)
1560 _array->getTuple(eltId,value);
1562 throw INTERP_KERNEL::Exception("No array existing.");
1564 throw INTERP_KERNEL::Exception("No data on this discrete time.");
1567 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval():_start_time(0.),_end_time(0.),_start_iteration(-1),_end_iteration(-1),_start_order(-1),_end_order(-1)
1571 void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception)
1573 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1574 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(&other);
1576 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::copyTinyAttrFrom : mismatch of time discretization !");
1577 _start_time=otherC->_start_time;
1578 _end_time=otherC->_end_time;
1579 _start_iteration=otherC->_start_iteration;
1580 _end_iteration=otherC->_end_iteration;
1581 _start_order=otherC->_start_order;
1582 _end_order=otherC->_end_order;
1585 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1587 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1588 tinyInfo.push_back(_start_iteration);
1589 tinyInfo.push_back(_start_order);
1590 tinyInfo.push_back(_end_iteration);
1591 tinyInfo.push_back(_end_order);
1594 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1596 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1597 tinyInfo.push_back(_start_time);
1598 tinyInfo.push_back(_end_time);
1601 void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1603 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1604 _start_time=tinyInfoD[1];
1605 _end_time=tinyInfoD[2];
1606 _start_iteration=tinyInfoI[2];
1607 _start_order=tinyInfoI[3];
1608 _end_iteration=tinyInfoI[4];
1609 _end_order=tinyInfoI[5];
1613 * idem getTinySerializationIntInformation except that it is for multi field fetch
1615 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1618 tinyInfo[0]=_start_iteration;
1619 tinyInfo[1]=_start_order;
1620 tinyInfo[2]=_end_iteration;
1621 tinyInfo[3]=_end_order;
1625 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1627 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1630 tinyInfo[0]=_time_tolerance;
1631 tinyInfo[1]=_start_time;
1632 tinyInfo[2]=_end_time;
1636 * idem finishUnserialization except that it is for multi field fetch
1638 void MEDCouplingConstOnTimeInterval::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1640 _start_iteration=tinyInfoI[0];
1641 _start_order=tinyInfoI[1];
1642 _end_iteration=tinyInfoI[2];
1643 _end_order=tinyInfoI[3];
1644 _time_tolerance=tinyInfoD[0];
1645 _start_time=tinyInfoD[1];
1646 _end_time=tinyInfoD[2];
1649 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCpy):
1650 MEDCouplingTimeDiscretization(other,deepCpy),_start_time(other._start_time),_end_time(other._end_time),_start_iteration(other._start_iteration),
1651 _end_iteration(other._end_iteration),_start_order(other._start_order),_end_order(other._end_order)
1655 std::string MEDCouplingConstOnTimeInterval::getStringRepr() const
1657 std::ostringstream stream;
1658 stream << REPR << " Time interval is defined by :\niteration_start=" << _start_iteration << " order_start=" << _start_order << " and time_start=" << _start_time << "\n";
1659 stream << "iteration_end=" << _end_iteration << " order_end=" << _end_order << " and end_time=" << _end_time << "\n";
1660 stream << "\nTime unit is : \"" << _time_unit << "\"";
1661 return stream.str();
1664 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCpy(bool deepCpy) const
1666 return new MEDCouplingConstOnTimeInterval(*this,deepCpy);
1669 std::vector< const DataArrayDouble *> MEDCouplingConstOnTimeInterval::getArraysForTime(double time) const throw(INTERP_KERNEL::Exception)
1671 if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance)
1673 std::vector< const DataArrayDouble *> ret(1);
1678 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1681 void MEDCouplingConstOnTimeInterval::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1683 std::copy(vals.begin(),vals.end(),res);
1686 bool MEDCouplingConstOnTimeInterval::areCompatible(const MEDCouplingTimeDiscretization *other) const
1688 if(!MEDCouplingTimeDiscretization::areCompatible(other))
1690 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1694 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const
1696 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1698 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1701 reason.insert(0,"time discretization of this is CONST_ON_TIME_INTERVAL, other has a different time discretization.");
1705 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
1707 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1709 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1713 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
1715 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1717 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1721 bool MEDCouplingConstOnTimeInterval::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1723 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1725 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1729 bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
1731 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1732 std::ostringstream oss; oss.precision(15);
1735 reason="This has time discretization CONST_ON_TIME_INTERVAL, other not.";
1738 if(_start_iteration!=otherC->_start_iteration)
1740 oss << "start iterations differ. this start iteration=" << _start_iteration << " other start iteration=" << otherC->_start_iteration;
1744 if(_start_order!=otherC->_start_order)
1746 oss << "start orders differ. this start order=" << _start_order << " other start order=" << otherC->_start_order;
1750 if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
1752 oss << "start times differ. this start time=" << _start_time << " other start time=" << otherC->_start_time;
1756 if(_end_iteration!=otherC->_end_iteration)
1758 oss << "end iterations differ. this end iteration=" << _end_iteration << " other end iteration=" << otherC->_end_iteration;
1762 if(_end_order!=otherC->_end_order)
1764 oss << "end orders differ. this end order=" << _end_order << " other end order=" << otherC->_end_order;
1768 if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
1770 oss << "end times differ. this end time=" << _end_time << " other end time=" << otherC->_end_time;
1774 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1777 bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
1779 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1782 if(_start_iteration!=otherC->_start_iteration)
1784 if(_start_order!=otherC->_start_order)
1786 if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
1788 if(_end_iteration!=otherC->_end_iteration)
1790 if(_end_order!=otherC->_end_order)
1792 if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
1794 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1797 void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception)
1799 if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance)
1801 _array->getTuple(eltId,value);
1803 throw INTERP_KERNEL::Exception("No array existing.");
1805 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1808 void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception)
1810 if(iteration>=_start_iteration && iteration<=_end_iteration)
1812 _array->getTuple(eltId,value);
1814 throw INTERP_KERNEL::Exception("No array existing.");
1816 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1819 void MEDCouplingConstOnTimeInterval::checkNoTimePresence() const throw(INTERP_KERNEL::Exception)
1821 throw INTERP_KERNEL::Exception("No time specified on a field defined as constant on one time interval");
1824 void MEDCouplingConstOnTimeInterval::checkTimePresence(double time) const throw(INTERP_KERNEL::Exception)
1826 if(time<_start_time-_time_tolerance || time>_end_time+_time_tolerance)
1828 std::ostringstream stream;
1829 stream << "The field is defined between times " << _start_time << " and " << _end_time << " worderh tolerance ";
1830 stream << _time_tolerance << " and trying to access on time = " << time;
1831 throw INTERP_KERNEL::Exception(stream.str().c_str());
1835 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const MEDCouplingTimeDiscretization *other) const
1837 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1839 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregation on mismatched time discretization !");
1840 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1841 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1842 ret->setArray(arr,0);
1846 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1848 std::vector<const DataArrayDouble *> a(other.size());
1850 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1852 const MEDCouplingConstOnTimeInterval *itC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(*it);
1854 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregate on mismatched time discretization !");
1855 a[i]=itC->getArray();
1857 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1858 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1859 ret->setArray(arr,0);
1863 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::meld(const MEDCouplingTimeDiscretization *other) const
1865 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1867 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::meld on mismatched time discretization !");
1868 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1869 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1870 ret->setTimeTolerance(getTimeTolerance());
1871 ret->setArray(arr,0);
1875 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::dot(const MEDCouplingTimeDiscretization *other) const
1877 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1879 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::dot on mismatched time discretization !");
1880 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1881 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1882 ret->setArray(arr,0);
1886 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::crossProduct(const MEDCouplingTimeDiscretization *other) const
1888 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1890 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::crossProduct on mismatched time discretization !");
1891 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1892 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1893 ret->setArray(arr,0);
1897 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::max(const MEDCouplingTimeDiscretization *other) const
1899 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1901 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::max on mismatched time discretization !");
1902 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1903 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1904 ret->setArray(arr,0);
1908 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::min(const MEDCouplingTimeDiscretization *other) const
1910 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1912 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::min on mismatched time discretization !");
1913 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1914 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1915 ret->setArray(arr,0);
1919 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::add(const MEDCouplingTimeDiscretization *other) const
1921 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1923 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::add on mismatched time discretization !");
1924 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1925 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1926 ret->setArray(arr,0);
1928 double tmp3=getStartTime(tmp1,tmp2);
1929 ret->setStartTime(tmp3,tmp1,tmp2);
1930 tmp3=getEndTime(tmp1,tmp2);
1931 ret->setEndTime(tmp3,tmp1,tmp2);
1935 void MEDCouplingConstOnTimeInterval::addEqual(const MEDCouplingTimeDiscretization *other)
1937 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1939 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::addEqual on mismatched time discretization !");
1941 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractaddEqual : Data Array is NULL !");
1942 getArray()->addEqual(other->getArray());
1945 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::substract(const MEDCouplingTimeDiscretization *other) const
1947 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1949 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substract on mismatched time discretization !");
1950 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1951 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1952 ret->setArray(arr,0);
1954 double tmp3=getStartTime(tmp1,tmp2);
1955 ret->setStartTime(tmp3,tmp1,tmp2);
1956 tmp3=getEndTime(tmp1,tmp2);
1957 ret->setEndTime(tmp3,tmp1,tmp2);
1961 void MEDCouplingConstOnTimeInterval::substractEqual(const MEDCouplingTimeDiscretization *other)
1963 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1965 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substractEqual on mismatched time discretization !");
1967 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractEqual : Data Array is NULL !");
1968 getArray()->substractEqual(other->getArray());
1971 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::multiply(const MEDCouplingTimeDiscretization *other) const
1973 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1975 throw INTERP_KERNEL::Exception("multiply on mismatched time discretization !");
1976 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1977 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1978 ret->setArray(arr,0);
1980 double tmp3=getStartTime(tmp1,tmp2);
1981 ret->setStartTime(tmp3,tmp1,tmp2);
1982 tmp3=getEndTime(tmp1,tmp2);
1983 ret->setEndTime(tmp3,tmp1,tmp2);
1987 void MEDCouplingConstOnTimeInterval::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1989 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1991 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::multiplyEqual on mismatched time discretization !");
1993 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::multiplyEqual : Data Array is NULL !");
1994 getArray()->multiplyEqual(other->getArray());
1997 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::divide(const MEDCouplingTimeDiscretization *other) const
1999 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2001 throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
2002 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
2003 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2004 ret->setArray(arr,0);
2006 double tmp3=getStartTime(tmp1,tmp2);
2007 ret->setStartTime(tmp3,tmp1,tmp2);
2008 tmp3=getEndTime(tmp1,tmp2);
2009 ret->setEndTime(tmp3,tmp1,tmp2);
2013 void MEDCouplingConstOnTimeInterval::divideEqual(const MEDCouplingTimeDiscretization *other)
2015 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2017 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::divideEqual on mismatched time discretization !");
2019 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::divideEqual : Data Array is NULL !");
2020 getArray()->divideEqual(other->getArray());
2023 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& other, bool deepCpy):MEDCouplingTimeDiscretization(other,deepCpy),
2024 _start_time(other._start_time),_end_time(other._end_time),
2025 _start_iteration(other._start_iteration),_end_iteration(other._end_iteration),
2026 _start_order(other._start_order),_end_order(other._end_order)
2028 if(other._end_array)
2029 _end_array=other._end_array->performCpy(deepCpy);
2034 void MEDCouplingTwoTimeSteps::updateTime() const
2036 MEDCouplingTimeDiscretization::updateTime();
2038 updateTimeWith(*_end_array);
2041 void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception)
2043 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
2044 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2046 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::copyTinyAttrFrom : mismatch of time discretization !");
2047 _start_time=otherC->_start_time;
2048 _end_time=otherC->_end_time;
2049 _start_iteration=otherC->_start_iteration;
2050 _end_iteration=otherC->_end_iteration;
2051 _start_order=otherC->_start_order;
2052 _end_order=otherC->_end_order;
2055 void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other)
2057 MEDCouplingTimeDiscretization::copyTinyStringsFrom(other);
2058 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2060 throw INTERP_KERNEL::Exception("Trying to operate copyTinyStringsFrom on different field type (two times//one time) !");
2061 if(_end_array && otherC->_end_array)
2062 _end_array->copyStringInfoFrom(*otherC->_end_array);
2065 const DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray() const
2070 DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray()
2075 void MEDCouplingTwoTimeSteps::checkCoherency() const throw(INTERP_KERNEL::Exception)
2077 MEDCouplingTimeDiscretization::checkCoherency();
2079 throw INTERP_KERNEL::Exception("No end array specified !");
2080 if(_array->getNumberOfComponents()!=_end_array->getNumberOfComponents())
2081 throw INTERP_KERNEL::Exception("The number of components mismatch between the start and the end arrays !");
2082 if(_array->getNumberOfTuples()!=_end_array->getNumberOfTuples())
2083 throw INTERP_KERNEL::Exception("The number of tuples mismatch between the start and the end arrays !");
2086 bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
2088 std::ostringstream oss;
2089 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(other);
2092 reason="This has time discretization LINEAR_TIME, other not.";
2095 if(_start_iteration!=otherC->_start_iteration)
2097 oss << "start iterations differ. this start iteration=" << _start_iteration << " other start iteration=" << otherC->_start_iteration;
2101 if(_start_order!=otherC->_start_order)
2103 oss << "start orders differ. this start order=" << _start_order << " other start order=" << otherC->_start_order;
2107 if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
2109 oss << "start times differ. this start time=" << _start_time << " other start time=" << otherC->_start_time;
2113 if(_end_iteration!=otherC->_end_iteration)
2115 oss << "end iterations differ. this end iteration=" << _end_iteration << " other end iteration=" << otherC->_end_iteration;
2119 if(_end_order!=otherC->_end_order)
2121 oss << "end orders differ. this end order=" << _end_order << " other end order=" << otherC->_end_order;
2125 if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
2127 oss << "end times differ. this end time=" << _end_time << " other end time=" << otherC->_end_time;
2131 if(_end_array!=otherC->_end_array)
2132 if(!_end_array->isEqualIfNotWhy(*otherC->_end_array,prec,reason))
2134 reason.insert(0,"end arrays differ for linear time.");
2137 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
2140 bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
2142 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(other);
2145 if(_start_iteration!=otherC->_start_iteration)
2147 if(_end_iteration!=otherC->_end_iteration)
2149 if(_start_order!=otherC->_start_order)
2151 if(_end_order!=otherC->_end_order)
2153 if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
2155 if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
2157 if(_end_array!=otherC->_end_array)
2158 if(!_end_array->isEqualWithoutConsideringStr(*otherC->_end_array,prec))
2160 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
2163 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_start_time(0.),_end_time(0.),_start_iteration(-1),_end_iteration(-1),_start_order(-1),_end_order(-1),_end_array(0)
2167 MEDCouplingTwoTimeSteps::~MEDCouplingTwoTimeSteps()
2170 _end_array->decrRef();
2173 void MEDCouplingTwoTimeSteps::checkNoTimePresence() const throw(INTERP_KERNEL::Exception)
2175 throw INTERP_KERNEL::Exception("The field presents a time to be specified in every access !");
2178 void MEDCouplingTwoTimeSteps::checkTimePresence(double time) const throw(INTERP_KERNEL::Exception)
2180 if(time<_start_time-_time_tolerance || time>_end_time+_time_tolerance)
2182 std::ostringstream stream;
2183 stream << "The field is defined between times " << _start_time << " and " << _end_time << " worderh tolerance ";
2184 stream << _time_tolerance << " and trying to access on time = " << time;
2185 throw INTERP_KERNEL::Exception(stream.str().c_str());
2189 void MEDCouplingTwoTimeSteps::getArrays(std::vector<DataArrayDouble *>& arrays) const
2193 arrays[1]=_end_array;
2196 void MEDCouplingTwoTimeSteps::setEndArray(DataArrayDouble *array, TimeLabel *owner)
2198 if(array!=_end_array)
2201 _end_array->decrRef();
2204 _end_array->incrRef();
2206 owner->declareAsNew();
2210 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
2212 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
2213 tinyInfo.push_back(_start_iteration);
2214 tinyInfo.push_back(_start_order);
2215 tinyInfo.push_back(_end_iteration);
2216 tinyInfo.push_back(_end_order);
2219 tinyInfo.push_back(_end_array->getNumberOfTuples());
2220 tinyInfo.push_back(_end_array->getNumberOfComponents());
2224 tinyInfo.push_back(-1);
2225 tinyInfo.push_back(-1);
2229 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
2231 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
2232 tinyInfo.push_back(_start_time);
2233 tinyInfo.push_back(_end_time);
2236 void MEDCouplingTwoTimeSteps::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
2238 int nbOfCompo=_array->getNumberOfComponents();
2239 for(int i=0;i<nbOfCompo;i++)
2240 tinyInfo.push_back(_array->getInfoOnComponent(i));
2241 for(int i=0;i<nbOfCompo;i++)
2242 tinyInfo.push_back(_end_array->getInfoOnComponent(i));
2245 void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
2251 _end_array->decrRef();
2252 DataArrayDouble *arr=0;
2253 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2255 arr=DataArrayDouble::New();
2256 arr->alloc(tinyInfoI[0],tinyInfoI[1]);
2261 if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2263 arr=DataArrayDouble::New();
2264 arr->alloc(tinyInfoI[6],tinyInfoI[7]);
2270 void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
2272 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
2273 _start_time=tinyInfoD[1];
2274 _end_time=tinyInfoD[2];
2275 _start_iteration=tinyInfoI[2];
2276 _start_order=tinyInfoI[3];
2277 _end_iteration=tinyInfoI[4];
2278 _end_order=tinyInfoI[5];
2282 * idem getTinySerializationIntInformation except that it is for multi field fetch
2284 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
2287 tinyInfo[0]=_start_iteration;
2288 tinyInfo[1]=_start_order;
2289 tinyInfo[2]=_end_iteration;
2290 tinyInfo[3]=_end_order;
2294 * idem getTinySerializationDbleInformation except that it is for multi field fetch
2296 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
2299 tinyInfo[0]=_time_tolerance;
2300 tinyInfo[1]=_start_time;
2301 tinyInfo[2]=_end_time;
2305 * idem finishUnserialization except that it is for multi field fetch
2307 void MEDCouplingTwoTimeSteps::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
2309 _start_iteration=tinyInfoI[0];
2310 _start_order=tinyInfoI[1];
2311 _end_iteration=tinyInfoI[2];
2312 _end_order=tinyInfoI[3];
2313 _time_tolerance=tinyInfoD[0];
2314 _start_time=tinyInfoD[1];
2315 _end_time=tinyInfoD[2];
2318 std::vector< const DataArrayDouble *> MEDCouplingTwoTimeSteps::getArraysForTime(double time) const throw(INTERP_KERNEL::Exception)
2320 if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance)
2322 std::vector< const DataArrayDouble *> ret(2);
2328 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2331 void MEDCouplingTwoTimeSteps::setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner) throw(INTERP_KERNEL::Exception)
2333 if(arrays.size()!=2)
2334 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::setArrays : number of arrays must be two.");
2335 setArray(arrays.front(),owner);
2336 setEndArray(arrays.back(),owner);
2339 MEDCouplingLinearTime::MEDCouplingLinearTime(const MEDCouplingLinearTime& other, bool deepCpy):MEDCouplingTwoTimeSteps(other,deepCpy)
2343 MEDCouplingLinearTime::MEDCouplingLinearTime()
2347 std::string MEDCouplingLinearTime::getStringRepr() const
2349 std::ostringstream stream;
2350 stream << REPR << " Time interval is defined by :\niteration_start=" << _start_iteration << " order_start=" << _start_order << " and time_start=" << _start_time << "\n";
2351 stream << "iteration_end=" << _end_iteration << " order_end=" << _end_order << " and end_time=" << _end_time << "\n";
2352 stream << "Time unit is : \"" << _time_unit << "\"";
2353 return stream.str();
2356 void MEDCouplingLinearTime::checkCoherency() const throw(INTERP_KERNEL::Exception)
2358 MEDCouplingTwoTimeSteps::checkCoherency();
2359 if(std::fabs(_start_time-_end_time)<_time_tolerance)
2360 throw INTERP_KERNEL::Exception("Start time and end time are equals regarding time tolerance.");
2363 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::performCpy(bool deepCpy) const
2365 return new MEDCouplingLinearTime(*this,deepCpy);
2368 bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretization *other) const
2370 if(!MEDCouplingTimeDiscretization::areCompatible(other))
2372 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2375 if(_end_array==0 && otherC->_end_array==0)
2377 if(_end_array==0 || otherC->_end_array==0)
2379 if(_end_array->getNumberOfComponents()!=otherC->_end_array->getNumberOfComponents())
2384 bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const
2386 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
2388 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2391 reason.insert(0,"time discretization of this is LINEAR_TIME, other has a different time discretization.");
2395 bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
2397 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
2399 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2403 bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
2405 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
2407 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2410 if(_end_array==0 && otherC->_end_array==0)
2412 if(_end_array==0 || otherC->_end_array==0)
2414 int nbC1=_end_array->getNumberOfComponents();
2415 int nbC2=otherC->_end_array->getNumberOfComponents();
2416 if(nbC1!=nbC2 && nbC2!=1)
2421 bool MEDCouplingLinearTime::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
2423 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
2425 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2430 * vals is expected to be of size 2*_array->getNumberOfTuples()==_array->getNumberOfTuples()+_end_array->getNumberOfTuples()
2432 void MEDCouplingLinearTime::getValueForTime(double time, const std::vector<double>& vals, double *res) const
2434 double alpha=(_end_time-time)/(_end_time-_start_time);
2435 std::size_t nbComp=vals.size()/2;
2436 std::transform(vals.begin(),vals.begin()+nbComp,res,std::bind2nd(std::multiplies<double>(),alpha));
2437 std::vector<double> tmp(nbComp);
2438 std::transform(vals.begin()+nbComp,vals.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2439 std::transform(tmp.begin(),tmp.end(),res,res,std::plus<double>());
2442 void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception)
2444 double alpha=(_end_time-time)/(_end_time-_start_time);
2447 _array->getTuple(eltId,value);
2449 throw INTERP_KERNEL::Exception("No start array existing.");
2450 nbComp=_array->getNumberOfComponents();
2451 std::transform(value,value+nbComp,value,std::bind2nd(std::multiplies<double>(),alpha));
2452 std::vector<double> tmp(nbComp);
2454 _end_array->getTuple(eltId,&tmp[0]);
2456 throw INTERP_KERNEL::Exception("No end array existing.");
2457 std::transform(tmp.begin(),tmp.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2458 std::transform(tmp.begin(),tmp.end(),value,value,std::plus<double>());
2461 void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception)
2463 if(iteration==_start_iteration && order==_start_order)
2466 _array->getTuple(eltId,value);
2468 throw INTERP_KERNEL::Exception("iteration order match with start time but no start array existing.");
2470 if(iteration==_end_iteration && order==_end_order)
2473 _end_array->getTuple(eltId,value);
2475 throw INTERP_KERNEL::Exception("iteration order match with end time but no end array existing.");
2478 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2481 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const MEDCouplingTimeDiscretization *other) const
2483 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2485 throw INTERP_KERNEL::Exception("LinearTime::aggregation on mismatched time discretization !");
2486 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Aggregate(getArray(),other->getArray());
2487 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Aggregate(getEndArray(),other->getEndArray());
2488 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2489 ret->setArray(arr1,0);
2490 ret->setEndArray(arr2,0);
2494 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
2496 std::vector<const DataArrayDouble *> a(other.size());
2497 std::vector<const DataArrayDouble *> b(other.size());
2499 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
2501 const MEDCouplingLinearTime *itC=dynamic_cast<const MEDCouplingLinearTime *>(*it);
2503 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::aggregate on mismatched time discretization !");
2504 a[i]=itC->getArray();
2505 b[i]=itC->getEndArray();
2507 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
2508 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Aggregate(b);
2509 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2510 ret->setArray(arr,0);
2511 ret->setEndArray(arr2,0);
2515 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::meld(const MEDCouplingTimeDiscretization *other) const
2517 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2519 throw INTERP_KERNEL::Exception("LinearTime::meld on mismatched time discretization !");
2520 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Meld(getArray(),other->getArray());
2521 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Meld(getEndArray(),other->getEndArray());
2522 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2523 ret->setTimeTolerance(getTimeTolerance());
2524 ret->setArray(arr1,0);
2525 ret->setEndArray(arr2,0);
2529 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeDiscretization *other) const
2531 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2533 throw INTERP_KERNEL::Exception("LinearTime::dot on mismatched time discretization !");
2534 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Dot(getArray(),other->getArray());
2535 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Dot(getEndArray(),other->getEndArray());
2536 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2537 ret->setArray(arr1,0);
2538 ret->setEndArray(arr2,0);
2542 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::crossProduct(const MEDCouplingTimeDiscretization *other) const
2544 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2546 throw INTERP_KERNEL::Exception("LinearTime::crossProduct on mismatched time discretization !");
2547 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::CrossProduct(getArray(),other->getArray());
2548 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::CrossProduct(getEndArray(),other->getEndArray());
2549 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2550 ret->setArray(arr1,0);
2551 ret->setEndArray(arr2,0);
2555 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::max(const MEDCouplingTimeDiscretization *other) const
2557 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2559 throw INTERP_KERNEL::Exception("LinearTime::max on mismatched time discretization !");
2560 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2561 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Max(getArray(),other->getArray());
2562 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Max(getEndArray(),other->getEndArray());
2563 ret->setArray(arr1,0);
2564 ret->setEndArray(arr2,0);
2568 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::min(const MEDCouplingTimeDiscretization *other) const
2570 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2572 throw INTERP_KERNEL::Exception("LinearTime::min on mismatched time discretization !");
2573 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Min(getArray(),other->getArray());
2574 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Min(getEndArray(),other->getEndArray());
2575 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2576 ret->setArray(arr1,0);
2577 ret->setEndArray(arr2,0);
2581 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::add(const MEDCouplingTimeDiscretization *other) const
2583 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2585 throw INTERP_KERNEL::Exception("LinearTime::add on mismatched time discretization !");
2586 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Add(getArray(),other->getArray());
2587 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Add(getEndArray(),other->getEndArray());
2588 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2589 ret->setArray(arr1,0);
2590 ret->setEndArray(arr2,0);
2594 void MEDCouplingLinearTime::addEqual(const MEDCouplingTimeDiscretization *other)
2596 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2598 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2600 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array is NULL !");
2602 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array (end) is NULL !");
2603 getArray()->addEqual(other->getArray());
2604 getEndArray()->addEqual(other->getEndArray());
2607 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::substract(const MEDCouplingTimeDiscretization *other) const
2609 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2611 throw INTERP_KERNEL::Exception("LinearTime::substract on mismatched time discretization !");
2612 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Substract(getArray(),other->getArray());
2613 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Substract(getEndArray(),other->getEndArray());
2614 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2615 ret->setArray(arr1,0);
2616 ret->setEndArray(arr2,0);
2620 void MEDCouplingLinearTime::substractEqual(const MEDCouplingTimeDiscretization *other)
2622 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2624 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2626 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array is NULL !");
2628 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array (end) is NULL !");
2629 getArray()->substractEqual(other->getArray());
2630 getEndArray()->substractEqual(other->getEndArray());
2633 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::multiply(const MEDCouplingTimeDiscretization *other) const
2635 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2637 throw INTERP_KERNEL::Exception("LinearTime::multiply on mismatched time discretization !");
2638 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Multiply(getArray(),other->getArray());
2639 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Multiply(getEndArray(),other->getEndArray());
2640 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2641 ret->setArray(arr1,0);
2642 ret->setEndArray(arr2,0);
2646 void MEDCouplingLinearTime::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2648 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2650 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2652 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array is NULL !");
2654 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array (end) is NULL !");
2655 getArray()->multiplyEqual(other->getArray());
2656 getEndArray()->multiplyEqual(other->getEndArray());
2659 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::divide(const MEDCouplingTimeDiscretization *other) const
2661 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2663 throw INTERP_KERNEL::Exception("LinearTime::divide on mismatched time discretization !");
2664 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Divide(getArray(),other->getArray());
2665 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Divide(getEndArray(),other->getEndArray());
2666 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2667 ret->setArray(arr1,0);
2668 ret->setEndArray(arr2,0);
2672 void MEDCouplingLinearTime::divideEqual(const MEDCouplingTimeDiscretization *other)
2674 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2676 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2678 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array is NULL !");
2680 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array (end) is NULL !");
2681 getArray()->divideEqual(other->getArray());
2682 getEndArray()->divideEqual(other->getEndArray());