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
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingTimeDiscretization.hxx"
22 #include "MEDCouplingMemArray.hxx"
23 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
31 using namespace ParaMEDMEM;
33 const double MEDCouplingTimeDiscretization::TIME_TOLERANCE_DFT=1.e-12;
35 const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setTime : no time info attached.";
37 const char MEDCouplingNoTimeLabel::REPR[]="No time label defined.";
39 const char MEDCouplingWithTimeStep::EXCEPTION_MSG[]="No data on this time.";
41 const char MEDCouplingWithTimeStep::REPR[]="One time label.";
43 const char MEDCouplingConstOnTimeInterval::EXCEPTION_MSG[]="No data on this time.";
45 const char MEDCouplingConstOnTimeInterval::REPR[]="Constant on a time interval.";
47 const char MEDCouplingTwoTimeSteps::EXCEPTION_MSG[]="No data on this time.";
49 const char MEDCouplingLinearTime::REPR[]="Linear time between 2 time steps.";
51 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDiscretization type)
55 case MEDCouplingNoTimeLabel::DISCRETIZATION:
56 return new MEDCouplingNoTimeLabel;
57 case MEDCouplingWithTimeStep::DISCRETIZATION:
58 return new MEDCouplingWithTimeStep;
59 case MEDCouplingConstOnTimeInterval::DISCRETIZATION:
60 return new MEDCouplingConstOnTimeInterval;
61 case MEDCouplingLinearTime::DISCRETIZATION:
62 return new MEDCouplingLinearTime;
64 throw INTERP_KERNEL::Exception("Time discretization not implemented yet");
68 void MEDCouplingTimeDiscretization::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception)
70 _time_tolerance=other._time_tolerance;
71 _time_unit=other._time_unit;
74 void MEDCouplingTimeDiscretization::copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other)
76 _time_unit=other._time_unit;
77 if(_array && other._array)
78 _array->copyStringInfoFrom(*other._array);
81 void MEDCouplingTimeDiscretization::checkCoherency() const throw(INTERP_KERNEL::Exception)
84 throw INTERP_KERNEL::Exception("Field invalid because no values set !");
85 if(_time_tolerance<0.)
86 throw INTERP_KERNEL::Exception("time tolerance is expected to be greater than 0. !");
89 void MEDCouplingTimeDiscretization::updateTime() const
92 updateTimeWith(*_array);
95 bool MEDCouplingTimeDiscretization::areCompatible(const MEDCouplingTimeDiscretization *other) const
97 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
99 if(_array==0 && other->_array==0)
101 if(_array==0 || other->_array==0)
103 if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
108 bool MEDCouplingTimeDiscretization::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const
110 std::ostringstream oss; oss.precision(15);
111 if(_time_unit!=other->_time_unit)
113 oss << "Field discretizations differ : this time unit = \"" << _time_unit << "\" and other time unit = \"" << other->_time_unit << "\" !";
117 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
119 oss << "Field discretizations differ : this time tolerance = \"" << _time_tolerance << "\" and other time tolerance = \"" << other->_time_tolerance << "\" !";
123 if(_array==0 && other->_array==0)
125 if(_array==0 || other->_array==0)
127 reason="Field discretizations differ : Only one timediscretization between the two this and other has a DataArrayDouble for values defined";
130 if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
132 if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
137 bool MEDCouplingTimeDiscretization::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
139 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
141 if(_array==0 && other->_array==0)
143 if(_array==0 || other->_array==0)
145 if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
150 bool MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
152 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
154 if(_array==0 && other->_array==0)
156 if(_array==0 || other->_array==0)
158 int nbC1=_array->getNumberOfComponents();
159 int nbC2=other->_array->getNumberOfComponents();
160 int nbMin=std::min(nbC1,nbC2);
161 if(nbC1!=nbC2 && nbMin!=1)
166 bool MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
168 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
170 if(_array==0 && other->_array==0)
172 if(_array==0 || other->_array==0)
174 int nbC1=_array->getNumberOfComponents();
175 int nbC2=other->_array->getNumberOfComponents();
176 if(nbC1!=nbC2 && nbC2!=1)
181 bool MEDCouplingTimeDiscretization::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
183 if(!areStrictlyCompatible(other,reason))
185 if(_array==other->_array)
187 return _array->isEqualIfNotWhy(*other->_array,prec,reason);
190 bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
193 return isEqualIfNotWhy(other,prec,reason);
196 bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
199 if(!areStrictlyCompatible(other,tmp))
201 if(_array==other->_array)
203 return _array->isEqualWithoutConsideringStr(*other->_array,prec);
206 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(TypeOfTimeDiscretization type, bool deepCpy) const
208 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(type);
209 ret->setTimeUnit(getTimeUnit());
210 const DataArrayDouble *arrSrc=getArray();
211 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr;
213 arr=arrSrc->performCpy(deepCpy);
214 ret->setArray(arr,0);
218 void MEDCouplingTimeDiscretization::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
222 tinyInfo.push_back(_array->getNumberOfTuples());
223 tinyInfo.push_back(_array->getNumberOfComponents());
227 tinyInfo.push_back(-1);
228 tinyInfo.push_back(-1);
232 void MEDCouplingTimeDiscretization::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
237 DataArrayDouble *arr=0;
238 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
240 arr=DataArrayDouble::New();
241 arr->alloc(tinyInfoI[0],tinyInfoI[1]);
247 void MEDCouplingTimeDiscretization::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
249 _time_tolerance=tinyInfoD[0];
250 int nbOfCompo=_array->getNumberOfComponents();
251 for(int i=0;i<nbOfCompo;i++)
252 _array->setInfoOnComponent(i,tinyInfoS[i].c_str());
255 void MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
257 tinyInfo.push_back(_time_tolerance);
260 void MEDCouplingTimeDiscretization::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
262 int nbOfCompo=_array->getNumberOfComponents();
263 for(int i=0;i<nbOfCompo;i++)
264 tinyInfo.push_back(_array->getInfoOnComponent(i));
267 MEDCouplingTimeDiscretization::MEDCouplingTimeDiscretization():_time_tolerance(TIME_TOLERANCE_DFT),_array(0)
271 MEDCouplingTimeDiscretization::MEDCouplingTimeDiscretization(const MEDCouplingTimeDiscretization& other, bool deepCpy):_time_unit(other._time_unit),_time_tolerance(other._time_tolerance)
274 _array=other._array->performCpy(deepCpy);
279 MEDCouplingTimeDiscretization::~MEDCouplingTimeDiscretization()
285 void MEDCouplingTimeDiscretization::setArray(DataArrayDouble *array, TimeLabel *owner)
295 owner->declareAsNew();
299 const DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray() const
301 throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
304 DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray()
306 throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
309 void MEDCouplingTimeDiscretization::setEndArray(DataArrayDouble *array, TimeLabel *owner)
311 throw INTERP_KERNEL::Exception("setEndArray not available for this type of time discretization !");
314 void MEDCouplingTimeDiscretization::setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner) throw(INTERP_KERNEL::Exception)
317 throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretization::setArrays : number of arrays must be one.");
318 setArray(arrays.back(),owner);
321 void MEDCouplingTimeDiscretization::getArrays(std::vector<DataArrayDouble *>& arrays) const
327 bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception)
330 double time1=getEndTime(iteration,order)-_time_tolerance;
331 double time2=other->getStartTime(iteration,order)+other->getTimeTolerance();
335 bool MEDCouplingTimeDiscretization::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception)
338 double time1=getEndTime(iteration,order)+_time_tolerance;
339 double time2=other->getStartTime(iteration,order)-other->getTimeTolerance();
343 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
345 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
346 ret->setTimeUnit(getTimeUnit());
347 std::vector<DataArrayDouble *> arrays;
349 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
350 for(int j=0;j<(int)arrays.size();j++)
353 arrays2[j]=arrays[j]->doublyContractedProduct();
357 std::vector<DataArrayDouble *> arrays3(arrays.size());
358 for(int j=0;j<(int)arrays.size();j++)
359 arrays3[j]=arrays2[j];
360 ret->setArrays(arrays3,0);
364 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() const throw(INTERP_KERNEL::Exception)
366 std::vector<DataArrayDouble *> arrays;
368 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
369 for(int j=0;j<(int)arrays.size();j++)
372 arrays2[j]=arrays[j]->determinant();
376 std::vector<DataArrayDouble *> arrays3(arrays.size());
377 for(int j=0;j<(int)arrays.size();j++)
378 arrays3[j]=arrays2[j];
379 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
380 ret->setTimeUnit(getTimeUnit());
381 ret->setArrays(arrays3,0);
385 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() const throw(INTERP_KERNEL::Exception)
387 std::vector<DataArrayDouble *> arrays;
389 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
390 for(int j=0;j<(int)arrays.size();j++)
393 arrays2[j]=arrays[j]->eigenValues();
397 std::vector<DataArrayDouble *> arrays3(arrays.size());
398 for(int j=0;j<(int)arrays.size();j++)
399 arrays3[j]=arrays2[j];
400 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
401 ret->setTimeUnit(getTimeUnit());
402 ret->setArrays(arrays3,0);
406 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() const throw(INTERP_KERNEL::Exception)
408 std::vector<DataArrayDouble *> arrays;
410 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
411 for(int j=0;j<(int)arrays.size();j++)
414 arrays2[j]=arrays[j]->eigenVectors();
418 std::vector<DataArrayDouble *> arrays3(arrays.size());
419 for(int j=0;j<(int)arrays.size();j++)
420 arrays3[j]=arrays2[j];
421 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
422 ret->setTimeUnit(getTimeUnit());
423 ret->setArrays(arrays3,0);
427 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const throw(INTERP_KERNEL::Exception)
429 std::vector<DataArrayDouble *> arrays;
431 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
432 for(int j=0;j<(int)arrays.size();j++)
435 arrays2[j]=arrays[j]->inverse();
439 std::vector<DataArrayDouble *> arrays3(arrays.size());
440 for(int j=0;j<(int)arrays.size();j++)
441 arrays3[j]=arrays2[j];
442 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
443 ret->setTimeUnit(getTimeUnit());
444 ret->setArrays(arrays3,0);
448 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const throw(INTERP_KERNEL::Exception)
450 std::vector<DataArrayDouble *> arrays;
452 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
453 for(int j=0;j<(int)arrays.size();j++)
456 arrays2[j]=arrays[j]->trace();
460 std::vector<DataArrayDouble *> arrays3(arrays.size());
461 for(int j=0;j<(int)arrays.size();j++)
462 arrays3[j]=arrays2[j];
463 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
464 ret->setTimeUnit(getTimeUnit());
465 ret->setArrays(arrays3,0);
469 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const throw(INTERP_KERNEL::Exception)
471 std::vector<DataArrayDouble *> arrays;
473 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
474 for(int j=0;j<(int)arrays.size();j++)
477 arrays2[j]=arrays[j]->deviator();
481 std::vector<DataArrayDouble *> arrays3(arrays.size());
482 for(int j=0;j<(int)arrays.size();j++)
483 arrays3[j]=arrays2[j];
484 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
485 ret->setTimeUnit(getTimeUnit());
486 ret->setArrays(arrays3,0);
490 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const throw(INTERP_KERNEL::Exception)
492 std::vector<DataArrayDouble *> arrays;
494 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
495 for(int j=0;j<(int)arrays.size();j++)
498 arrays2[j]=arrays[j]->magnitude();
502 std::vector<DataArrayDouble *> arrays3(arrays.size());
503 for(int j=0;j<(int)arrays.size();j++)
504 arrays3[j]=arrays2[j];
505 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
506 ret->setTimeUnit(getTimeUnit());
507 ret->setArrays(arrays3,0);
511 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() const throw(INTERP_KERNEL::Exception)
513 std::vector<DataArrayDouble *> arrays;
515 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
516 for(int j=0;j<(int)arrays.size();j++)
519 arrays2[j]=arrays[j]->maxPerTuple();
523 std::vector<DataArrayDouble *> arrays3(arrays.size());
524 for(int j=0;j<(int)arrays.size();j++)
525 arrays3[j]=arrays2[j];
526 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
527 ret->setTimeUnit(getTimeUnit());
528 ret->setArrays(arrays3,0);
532 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
534 std::vector<DataArrayDouble *> arrays;
536 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
537 for(int j=0;j<(int)arrays.size();j++)
540 arrays2[j]=arrays[j]->keepSelectedComponents(compoIds);
544 std::vector<DataArrayDouble *> arrays3(arrays.size());
545 for(int j=0;j<(int)arrays.size();j++)
546 arrays3[j]=arrays2[j];
547 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
548 ret->setTimeUnit(getTimeUnit());
549 ret->setArrays(arrays3,0);
553 void MEDCouplingTimeDiscretization::setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
555 std::vector<DataArrayDouble *> arrays1,arrays2;
557 other->getArrays(arrays2);
558 if(arrays1.size()!=arrays2.size())
559 throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : number of arrays mismatch !");
560 for(unsigned int i=0;i<arrays1.size();i++)
562 if(arrays1[i]!=0 && arrays2[i]!=0)
563 arrays1[i]->setSelectedComponents(arrays2[i],compoIds);
564 else if(arrays1[i]!=0 || arrays2[i]!=0)
565 throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : some time array in correspondance are not defined symetrically !");
569 void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double dftValue) throw(INTERP_KERNEL::Exception)
571 std::vector<DataArrayDouble *> arrays;
573 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
574 for(int j=0;j<(int)arrays.size();j++)
577 arrays2[j]=arrays[j]->changeNbOfComponents(newNbOfComp,dftValue);
581 std::vector<DataArrayDouble *> arrays3(arrays.size());
582 for(int j=0;j<(int)arrays.size();j++)
583 arrays3[j]=arrays2[j];
584 setArrays(arrays3,0);
587 void MEDCouplingTimeDiscretization::sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception)
589 std::vector<DataArrayDouble *> arrays;
591 for(int j=0;j<(int)arrays.size();j++)
594 arrays[j]->sortPerTuple(asc);
598 void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, int nbOfCompo, double value)
600 std::vector<DataArrayDouble *> arrays;
602 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
603 for(int j=0;j<(int)arrays.size();j++)
607 arrays[j]->incrRef();
608 arrays[j]->fillWithValue(value);
609 arrays2[j]=arrays[j];
613 DataArrayDouble *tmp=DataArrayDouble::New();
614 tmp->alloc(nbOfTuple,nbOfCompo);
615 tmp->fillWithValue(value);
619 std::vector<DataArrayDouble *> arrays3(arrays.size());
620 for(int j=0;j<(int)arrays.size();j++)
621 arrays3[j]=arrays2[j];
622 setArrays(arrays3,0);
625 void MEDCouplingTimeDiscretization::applyLin(double a, double b, int compoId)
627 std::vector<DataArrayDouble *> arrays;
629 for(int j=0;j<(int)arrays.size();j++)
632 arrays[j]->applyLin(a,b,compoId);
636 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate func)
638 std::vector<DataArrayDouble *> arrays;
640 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
641 for(int j=0;j<(int)arrays.size();j++)
644 arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
648 std::vector<DataArrayDouble *> arrays3(arrays.size());
649 for(int j=0;j<(int)arrays.size();j++)
650 arrays3[j]=arrays2[j];
651 setArrays(arrays3,0);
654 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const char *func)
656 std::vector<DataArrayDouble *> arrays;
658 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
659 for(int j=0;j<(int)arrays.size();j++)
662 arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
666 std::vector<DataArrayDouble *> arrays3(arrays.size());
667 for(int j=0;j<(int)arrays.size();j++)
668 arrays3[j]=arrays2[j];
669 setArrays(arrays3,0);
672 void MEDCouplingTimeDiscretization::applyFunc2(int nbOfComp, const char *func)
674 std::vector<DataArrayDouble *> arrays;
676 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
677 for(int j=0;j<(int)arrays.size();j++)
680 arrays2[j]=arrays[j]->applyFunc2(nbOfComp,func);
684 std::vector<DataArrayDouble *> arrays3(arrays.size());
685 for(int j=0;j<(int)arrays.size();j++)
686 arrays3[j]=arrays2[j];
687 setArrays(arrays3,0);
690 void MEDCouplingTimeDiscretization::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const char *func)
692 std::vector<DataArrayDouble *> arrays;
694 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
695 for(int j=0;j<(int)arrays.size();j++)
698 arrays2[j]=arrays[j]->applyFunc3(nbOfComp,varsOrder,func);
702 std::vector<DataArrayDouble *> arrays3(arrays.size());
703 for(int j=0;j<(int)arrays.size();j++)
704 arrays3[j]=arrays2[j];
705 setArrays(arrays3,0);
708 void MEDCouplingTimeDiscretization::applyFunc(const char *func)
710 std::vector<DataArrayDouble *> arrays;
712 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
713 for(int j=0;j<(int)arrays.size();j++)
716 arrays2[j]=arrays[j]->applyFunc(func);
720 std::vector<DataArrayDouble *> arrays3(arrays.size());
721 for(int j=0;j<(int)arrays.size();j++)
722 arrays3[j]=arrays2[j];
723 setArrays(arrays3,0);
726 void MEDCouplingTimeDiscretization::applyFuncFast32(const char *func)
728 std::vector<DataArrayDouble *> arrays;
730 for(int j=0;j<(int)arrays.size();j++)
733 arrays[j]->applyFuncFast32(func);
737 void MEDCouplingTimeDiscretization::applyFuncFast64(const char *func)
739 std::vector<DataArrayDouble *> arrays;
741 for(int j=0;j<(int)arrays.size();j++)
744 arrays[j]->applyFuncFast64(func);
748 void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, FunctionToEvaluate func) throw(INTERP_KERNEL::Exception)
750 std::vector<DataArrayDouble *> arrays;
752 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
753 for(int j=0;j<(int)arrays.size();j++)
754 arrays2[j]=loc->applyFunc(nbOfComp,func);
755 std::vector<DataArrayDouble *> arrays3(arrays.size());
756 for(int j=0;j<(int)arrays.size();j++)
757 arrays3[j]=arrays2[j];
758 setArrays(arrays3,0);
761 void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception)
763 std::vector<DataArrayDouble *> arrays;
765 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
766 for(int j=0;j<(int)arrays.size();j++)
767 arrays2[j]=loc->applyFunc(nbOfComp,func);
768 std::vector<DataArrayDouble *> arrays3(arrays.size());
769 for(int j=0;j<(int)arrays.size();j++)
770 arrays3[j]=arrays2[j];
771 setArrays(arrays3,0);
774 void MEDCouplingTimeDiscretization::fillFromAnalytic2(const DataArrayDouble *loc, int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception)
776 std::vector<DataArrayDouble *> arrays;
778 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
779 for(int j=0;j<(int)arrays.size();j++)
780 arrays2[j]=loc->applyFunc2(nbOfComp,func);
781 std::vector<DataArrayDouble *> arrays3(arrays.size());
782 for(int j=0;j<(int)arrays.size();j++)
783 arrays3[j]=arrays2[j];
784 setArrays(arrays3,0);
787 void MEDCouplingTimeDiscretization::fillFromAnalytic3(const DataArrayDouble *loc, int nbOfComp, const std::vector<std::string>& varsOrder, const char *func) throw(INTERP_KERNEL::Exception)
789 std::vector<DataArrayDouble *> arrays;
791 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrays2(arrays.size());
792 for(int j=0;j<(int)arrays.size();j++)
793 arrays2[j]=loc->applyFunc3(nbOfComp,varsOrder,func);
794 std::vector<DataArrayDouble *> arrays3(arrays.size());
795 for(int j=0;j<(int)arrays.size();j++)
796 arrays3[j]=arrays2[j];
797 setArrays(arrays3,0);
800 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel()
804 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretization& other, bool deepCpy):MEDCouplingTimeDiscretization(other,deepCpy)
808 std::string MEDCouplingNoTimeLabel::getStringRepr() const
810 std::ostringstream stream;
812 stream << "\nTime unit is : \"" << _time_unit << "\"";
816 bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretization *other) const
818 if(!MEDCouplingTimeDiscretization::areCompatible(other))
820 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
824 bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const
826 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
828 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
831 reason.insert(0,"time discretization of this is NO_TIME, other has a different time discretization.");
835 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
837 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
839 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
843 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
845 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
847 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
851 bool MEDCouplingNoTimeLabel::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
853 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
855 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
859 bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
861 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
864 reason="This has time discretization NO_TIME, other not.";
867 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
870 bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
872 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
875 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
878 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCouplingTimeDiscretization *other) const
880 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
882 throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !");
883 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
884 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
885 ret->setArray(arr,0);
889 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
891 std::vector<const DataArrayDouble *> a(other.size());
893 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
895 const MEDCouplingNoTimeLabel *itC=dynamic_cast<const MEDCouplingNoTimeLabel *>(*it);
897 throw INTERP_KERNEL::Exception("NoTimeLabel::aggregate on mismatched time discretization !");
898 a[i]=itC->getArray();
900 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
901 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
902 ret->setArray(arr,0);
906 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::meld(const MEDCouplingTimeDiscretization *other) const
908 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
910 throw INTERP_KERNEL::Exception("NoTimeLabel::meld on mismatched time discretization !");
911 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
912 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
913 ret->setTimeTolerance(getTimeTolerance());
914 ret->setArray(arr,0);
918 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::dot(const MEDCouplingTimeDiscretization *other) const
920 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
922 throw INTERP_KERNEL::Exception("NoTimeLabel::dot on mismatched time discretization !");
923 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
924 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
925 ret->setArray(arr,0);
929 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::crossProduct(const MEDCouplingTimeDiscretization *other) const
931 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
933 throw INTERP_KERNEL::Exception("NoTimeLabel::crossProduct on mismatched time discretization !");
934 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
935 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
936 ret->setArray(arr,0);
940 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::max(const MEDCouplingTimeDiscretization *other) const
942 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
944 throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
945 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
946 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
947 ret->setArray(arr,0);
951 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::min(const MEDCouplingTimeDiscretization *other) const
953 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
955 throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
956 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
957 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
958 ret->setArray(arr,0);
962 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::add(const MEDCouplingTimeDiscretization *other) const
964 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
966 throw INTERP_KERNEL::Exception("NoTimeLabel::add on mismatched time discretization !");
967 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
968 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
969 ret->setArray(arr,0);
973 void MEDCouplingNoTimeLabel::addEqual(const MEDCouplingTimeDiscretization *other)
975 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
977 throw INTERP_KERNEL::Exception("NoTimeLabel::addEqual on mismatched time discretization !");
979 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::addEqual : Data Array is NULL !");
980 getArray()->addEqual(other->getArray());
983 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::substract(const MEDCouplingTimeDiscretization *other) const
985 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
987 throw INTERP_KERNEL::Exception("NoTimeLabel::substract on mismatched time discretization !");
989 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substract : Data Array is NULL !");
990 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
991 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
992 ret->setArray(arr,0);
996 void MEDCouplingNoTimeLabel::substractEqual(const MEDCouplingTimeDiscretization *other)
998 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1000 throw INTERP_KERNEL::Exception("NoTimeLabel::substractEqual on mismatched time discretization !");
1002 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substractEqual : Data Array is NULL !");
1003 getArray()->substractEqual(other->getArray());
1006 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::multiply(const MEDCouplingTimeDiscretization *other) const
1008 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1010 throw INTERP_KERNEL::Exception("NoTimeLabel::multiply on mismatched time discretization !");
1011 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1012 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1013 ret->setArray(arr,0);
1017 void MEDCouplingNoTimeLabel::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1019 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1021 throw INTERP_KERNEL::Exception("NoTimeLabel::multiplyEqual on mismatched time discretization !");
1023 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::multiplyEqual : Data Array is NULL !");
1024 getArray()->multiplyEqual(other->getArray());
1027 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::divide(const MEDCouplingTimeDiscretization *other) const
1029 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1031 throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
1032 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1033 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1034 ret->setArray(arr,0);
1038 void MEDCouplingNoTimeLabel::divideEqual(const MEDCouplingTimeDiscretization *other)
1040 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1042 throw INTERP_KERNEL::Exception("NoTimeLabel::divideEqual on mismatched time discretization !");
1044 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::divideEqual : Data Array is NULL !");
1045 getArray()->divideEqual(other->getArray());
1048 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCpy(bool deepCpy) const
1050 return new MEDCouplingNoTimeLabel(*this,deepCpy);
1053 void MEDCouplingNoTimeLabel::checkTimePresence(double time) const throw(INTERP_KERNEL::Exception)
1055 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1058 std::vector< const DataArrayDouble *> MEDCouplingNoTimeLabel::getArraysForTime(double time) const throw(INTERP_KERNEL::Exception)
1060 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1063 void MEDCouplingNoTimeLabel::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1065 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1068 bool MEDCouplingNoTimeLabel::isBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception)
1070 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1073 bool MEDCouplingNoTimeLabel::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const throw(INTERP_KERNEL::Exception)
1075 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1078 double MEDCouplingNoTimeLabel::getStartTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception)
1080 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1083 double MEDCouplingNoTimeLabel::getEndTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception)
1085 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1088 void MEDCouplingNoTimeLabel::setStartIteration(int it) throw(INTERP_KERNEL::Exception)
1090 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1093 void MEDCouplingNoTimeLabel::setEndIteration(int it) throw(INTERP_KERNEL::Exception)
1095 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1098 void MEDCouplingNoTimeLabel::setStartOrder(int order) throw(INTERP_KERNEL::Exception)
1100 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1103 void MEDCouplingNoTimeLabel::setEndOrder(int order) throw(INTERP_KERNEL::Exception)
1105 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1108 void MEDCouplingNoTimeLabel::setStartTimeValue(double time) throw(INTERP_KERNEL::Exception)
1110 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1113 void MEDCouplingNoTimeLabel::setEndTimeValue(double time) throw(INTERP_KERNEL::Exception)
1115 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1118 void MEDCouplingNoTimeLabel::setStartTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception)
1120 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1123 void MEDCouplingNoTimeLabel::setEndTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception)
1125 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1128 void MEDCouplingNoTimeLabel::getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception)
1130 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1133 void MEDCouplingNoTimeLabel::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception)
1135 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1139 * idem getTinySerializationIntInformation except that it is for multi field fetch
1141 void MEDCouplingNoTimeLabel::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1147 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1149 void MEDCouplingNoTimeLabel::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1152 tinyInfo[0]=_time_tolerance;
1156 * idem finishUnserialization except that it is for multi field fetch
1158 void MEDCouplingNoTimeLabel::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1160 _time_tolerance=tinyInfoD[0];
1163 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCpy):MEDCouplingTimeDiscretization(other,deepCpy),
1164 _time(other._time),_iteration(other._iteration),_order(other._order)
1168 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep():_time(0.),_iteration(-1),_order(-1)
1172 std::string MEDCouplingWithTimeStep::getStringRepr() const
1174 std::ostringstream stream;
1175 stream << REPR << " Time is defined by iteration=" << _iteration << " order=" << _order << " and time=" << _time << ".";
1176 stream << "\nTime unit is : \"" << _time_unit << "\"";
1177 return stream.str();
1180 void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1182 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1183 tinyInfo.push_back(_iteration);
1184 tinyInfo.push_back(_order);
1187 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1189 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1190 tinyInfo.push_back(_time);
1193 void MEDCouplingWithTimeStep::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1195 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1197 _iteration=tinyInfoI[2];
1198 _order=tinyInfoI[3];
1202 * idem getTinySerializationIntInformation except that it is for multi field fetch
1204 void MEDCouplingWithTimeStep::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1207 tinyInfo[0]=_iteration;
1212 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1214 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1217 tinyInfo[0]=_time_tolerance;
1222 * idem finishUnserialization except that it is for multi field fetch
1224 void MEDCouplingWithTimeStep::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1226 _iteration=tinyInfoI[0];
1227 _order=tinyInfoI[1];
1228 _time_tolerance=tinyInfoD[0];
1232 bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretization *other) const
1234 if(!MEDCouplingTimeDiscretization::areCompatible(other))
1236 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1240 bool MEDCouplingWithTimeStep::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const
1242 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1244 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1247 reason.insert(0,"time discretization of this is ONE_TIME, other has a different time discretization.");
1251 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
1253 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1255 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1259 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
1261 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1263 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1267 bool MEDCouplingWithTimeStep::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1269 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1271 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1275 bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
1277 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1278 std::ostringstream oss; oss.precision(15);
1281 reason="This has time discretization ONE_TIME, other not.";
1284 if(_iteration!=otherC->_iteration)
1286 oss << "iterations differ. this iteration=" << _iteration << " other iteration=" << otherC->_iteration;
1290 if(_order!=otherC->_order)
1292 oss << "orders differ. this order=" << _order << " other order=" << otherC->_order;
1296 if(std::fabs(_time-otherC->_time)>_time_tolerance)
1298 oss << "times differ. this time=" << _time << " other time=" << otherC->_time;
1302 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1305 bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
1307 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1310 if(_iteration!=otherC->_iteration)
1312 if(_order!=otherC->_order)
1314 if(std::fabs(_time-otherC->_time)>_time_tolerance)
1316 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1319 void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception)
1321 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1322 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(&other);
1324 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::copyTinyAttrFrom : mismatch of time discretization !");
1325 _time=otherC->_time;
1326 _iteration=otherC->_iteration;
1327 _order=otherC->_order;
1330 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCouplingTimeDiscretization *other) const
1332 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1334 throw INTERP_KERNEL::Exception("WithTimeStep::aggregation on mismatched time discretization !");
1335 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1336 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1337 ret->setArray(arr,0);
1341 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1343 std::vector<const DataArrayDouble *> a(other.size());
1345 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1347 const MEDCouplingWithTimeStep *itC=dynamic_cast<const MEDCouplingWithTimeStep *>(*it);
1349 throw INTERP_KERNEL::Exception("WithTimeStep::aggregate on mismatched time discretization !");
1350 a[i]=itC->getArray();
1352 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1353 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1354 ret->setArray(arr,0);
1358 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::meld(const MEDCouplingTimeDiscretization *other) const
1360 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1362 throw INTERP_KERNEL::Exception("WithTimeStep::meld on mismatched time discretization !");
1363 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1364 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1365 ret->setArray(arr,0);
1369 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::dot(const MEDCouplingTimeDiscretization *other) const
1371 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1373 throw INTERP_KERNEL::Exception("WithTimeStep::dot on mismatched time discretization !");
1374 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1375 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1376 ret->setArray(arr,0);
1380 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::crossProduct(const MEDCouplingTimeDiscretization *other) const
1382 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1384 throw INTERP_KERNEL::Exception("WithTimeStep::crossProduct on mismatched time discretization !");
1385 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1386 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1387 ret->setArray(arr,0);
1391 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::max(const MEDCouplingTimeDiscretization *other) const
1393 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1395 throw INTERP_KERNEL::Exception("WithTimeStep::max on mismatched time discretization !");
1396 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1397 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1398 ret->setArray(arr,0);
1402 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::min(const MEDCouplingTimeDiscretization *other) const
1404 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1406 throw INTERP_KERNEL::Exception("WithTimeStep::min on mismatched time discretization !");
1407 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1408 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1409 ret->setArray(arr,0);
1413 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::add(const MEDCouplingTimeDiscretization *other) const
1415 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1417 throw INTERP_KERNEL::Exception("WithTimeStep::add on mismatched time discretization !");
1418 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1419 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1420 ret->setArray(arr,0);
1422 double tmp3=getStartTime(tmp1,tmp2);
1423 ret->setStartTime(tmp3,tmp1,tmp2);
1427 void MEDCouplingWithTimeStep::addEqual(const MEDCouplingTimeDiscretization *other)
1429 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1431 throw INTERP_KERNEL::Exception("WithTimeStep::addEqual on mismatched time discretization !");
1433 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::addEqual : Data Array is NULL !");
1434 getArray()->addEqual(other->getArray());
1437 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::substract(const MEDCouplingTimeDiscretization *other) const
1439 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1441 throw INTERP_KERNEL::Exception("WithTimeStep::substract on mismatched time discretization !");
1442 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1443 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1444 ret->setArray(arr,0);
1446 double tmp3=getStartTime(tmp1,tmp2);
1447 ret->setStartTime(tmp3,tmp1,tmp2);
1451 void MEDCouplingWithTimeStep::substractEqual(const MEDCouplingTimeDiscretization *other)
1453 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1455 throw INTERP_KERNEL::Exception("WithTimeStep::substractEqual on mismatched time discretization !");
1457 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::substractEqual : Data Array is NULL !");
1458 getArray()->substractEqual(other->getArray());
1461 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::multiply(const MEDCouplingTimeDiscretization *other) const
1463 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1465 throw INTERP_KERNEL::Exception("WithTimeStep::multiply on mismatched time discretization !");
1466 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1467 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1468 ret->setArray(arr,0);
1470 double tmp3=getStartTime(tmp1,tmp2);
1471 ret->setStartTime(tmp3,tmp1,tmp2);
1475 void MEDCouplingWithTimeStep::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1477 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1479 throw INTERP_KERNEL::Exception("WithTimeStep::multiplyEqual on mismatched time discretization !");
1481 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::multiplyEqual : Data Array is NULL !");
1482 getArray()->multiplyEqual(other->getArray());
1485 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::divide(const MEDCouplingTimeDiscretization *other) const
1487 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1489 throw INTERP_KERNEL::Exception("WithTimeStep::divide on mismatched time discretization !");
1490 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1491 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1492 ret->setArray(arr,0);
1494 double tmp3=getStartTime(tmp1,tmp2);
1495 ret->setStartTime(tmp3,tmp1,tmp2);
1499 void MEDCouplingWithTimeStep::divideEqual(const MEDCouplingTimeDiscretization *other)
1501 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1503 throw INTERP_KERNEL::Exception("WithTimeStep::divideEqual on mismatched time discretization !");
1505 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::divideEqual : Data Array is NULL !");
1506 getArray()->divideEqual(other->getArray());
1509 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCpy(bool deepCpy) const
1511 return new MEDCouplingWithTimeStep(*this,deepCpy);
1514 void MEDCouplingWithTimeStep::checkNoTimePresence() const throw(INTERP_KERNEL::Exception)
1516 throw INTERP_KERNEL::Exception("No time specified on a field defined on one time");
1519 void MEDCouplingWithTimeStep::checkTimePresence(double time) const throw(INTERP_KERNEL::Exception)
1521 if(std::fabs(time-_time)>_time_tolerance)
1523 std::ostringstream stream;
1524 stream << "The field is defined on time " << _time << " with eps=" << _time_tolerance << " and asking time = " << time << " !";
1525 throw INTERP_KERNEL::Exception(stream.str().c_str());
1529 std::vector< const DataArrayDouble *> MEDCouplingWithTimeStep::getArraysForTime(double time) const throw(INTERP_KERNEL::Exception)
1531 if(std::fabs(time-_time)<=_time_tolerance)
1533 std::vector< const DataArrayDouble *> ret(1);
1538 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1541 void MEDCouplingWithTimeStep::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1543 std::copy(vals.begin(),vals.end(),res);
1546 void MEDCouplingWithTimeStep::getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception)
1548 if(std::fabs(time-_time)<=_time_tolerance)
1550 _array->getTuple(eltId,value);
1552 throw INTERP_KERNEL::Exception("No array existing.");
1554 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1557 void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception)
1559 if(_iteration==iteration && _order==order)
1561 _array->getTuple(eltId,value);
1563 throw INTERP_KERNEL::Exception("No array existing.");
1565 throw INTERP_KERNEL::Exception("No data on this discrete time.");
1568 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval():_start_time(0.),_end_time(0.),_start_iteration(-1),_end_iteration(-1),_start_order(-1),_end_order(-1)
1572 void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception)
1574 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1575 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(&other);
1577 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::copyTinyAttrFrom : mismatch of time discretization !");
1578 _start_time=otherC->_start_time;
1579 _end_time=otherC->_end_time;
1580 _start_iteration=otherC->_start_iteration;
1581 _end_iteration=otherC->_end_iteration;
1582 _start_order=otherC->_start_order;
1583 _end_order=otherC->_end_order;
1586 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1588 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1589 tinyInfo.push_back(_start_iteration);
1590 tinyInfo.push_back(_start_order);
1591 tinyInfo.push_back(_end_iteration);
1592 tinyInfo.push_back(_end_order);
1595 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1597 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1598 tinyInfo.push_back(_start_time);
1599 tinyInfo.push_back(_end_time);
1602 void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1604 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1605 _start_time=tinyInfoD[1];
1606 _end_time=tinyInfoD[2];
1607 _start_iteration=tinyInfoI[2];
1608 _start_order=tinyInfoI[3];
1609 _end_iteration=tinyInfoI[4];
1610 _end_order=tinyInfoI[5];
1614 * idem getTinySerializationIntInformation except that it is for multi field fetch
1616 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1619 tinyInfo[0]=_start_iteration;
1620 tinyInfo[1]=_start_order;
1621 tinyInfo[2]=_end_iteration;
1622 tinyInfo[3]=_end_order;
1626 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1628 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1631 tinyInfo[0]=_time_tolerance;
1632 tinyInfo[1]=_start_time;
1633 tinyInfo[2]=_end_time;
1637 * idem finishUnserialization except that it is for multi field fetch
1639 void MEDCouplingConstOnTimeInterval::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1641 _start_iteration=tinyInfoI[0];
1642 _start_order=tinyInfoI[1];
1643 _end_iteration=tinyInfoI[2];
1644 _end_order=tinyInfoI[3];
1645 _time_tolerance=tinyInfoD[0];
1646 _start_time=tinyInfoD[1];
1647 _end_time=tinyInfoD[2];
1650 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCpy):
1651 MEDCouplingTimeDiscretization(other,deepCpy),_start_time(other._start_time),_end_time(other._end_time),_start_iteration(other._start_iteration),
1652 _end_iteration(other._end_iteration),_start_order(other._start_order),_end_order(other._end_order)
1656 std::string MEDCouplingConstOnTimeInterval::getStringRepr() const
1658 std::ostringstream stream;
1659 stream << REPR << " Time interval is defined by :\niteration_start=" << _start_iteration << " order_start=" << _start_order << " and time_start=" << _start_time << "\n";
1660 stream << "iteration_end=" << _end_iteration << " order_end=" << _end_order << " and end_time=" << _end_time << "\n";
1661 stream << "\nTime unit is : \"" << _time_unit << "\"";
1662 return stream.str();
1665 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCpy(bool deepCpy) const
1667 return new MEDCouplingConstOnTimeInterval(*this,deepCpy);
1670 std::vector< const DataArrayDouble *> MEDCouplingConstOnTimeInterval::getArraysForTime(double time) const throw(INTERP_KERNEL::Exception)
1672 if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance)
1674 std::vector< const DataArrayDouble *> ret(1);
1679 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1682 void MEDCouplingConstOnTimeInterval::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1684 std::copy(vals.begin(),vals.end(),res);
1687 bool MEDCouplingConstOnTimeInterval::areCompatible(const MEDCouplingTimeDiscretization *other) const
1689 if(!MEDCouplingTimeDiscretization::areCompatible(other))
1691 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1695 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const
1697 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1699 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1702 reason.insert(0,"time discretization of this is CONST_ON_TIME_INTERVAL, other has a different time discretization.");
1706 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
1708 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1710 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1714 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
1716 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1718 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1722 bool MEDCouplingConstOnTimeInterval::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1724 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1726 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1730 bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
1732 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1733 std::ostringstream oss; oss.precision(15);
1736 reason="This has time discretization CONST_ON_TIME_INTERVAL, other not.";
1739 if(_start_iteration!=otherC->_start_iteration)
1741 oss << "start iterations differ. this start iteration=" << _start_iteration << " other start iteration=" << otherC->_start_iteration;
1745 if(_start_order!=otherC->_start_order)
1747 oss << "start orders differ. this start order=" << _start_order << " other start order=" << otherC->_start_order;
1751 if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
1753 oss << "start times differ. this start time=" << _start_time << " other start time=" << otherC->_start_time;
1757 if(_end_iteration!=otherC->_end_iteration)
1759 oss << "end iterations differ. this end iteration=" << _end_iteration << " other end iteration=" << otherC->_end_iteration;
1763 if(_end_order!=otherC->_end_order)
1765 oss << "end orders differ. this end order=" << _end_order << " other end order=" << otherC->_end_order;
1769 if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
1771 oss << "end times differ. this end time=" << _end_time << " other end time=" << otherC->_end_time;
1775 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1778 bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
1780 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1783 if(_start_iteration!=otherC->_start_iteration)
1785 if(_start_order!=otherC->_start_order)
1787 if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
1789 if(_end_iteration!=otherC->_end_iteration)
1791 if(_end_order!=otherC->_end_order)
1793 if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
1795 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1798 void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception)
1800 if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance)
1802 _array->getTuple(eltId,value);
1804 throw INTERP_KERNEL::Exception("No array existing.");
1806 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1809 void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception)
1811 if(iteration>=_start_iteration && iteration<=_end_iteration)
1813 _array->getTuple(eltId,value);
1815 throw INTERP_KERNEL::Exception("No array existing.");
1817 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1820 void MEDCouplingConstOnTimeInterval::checkNoTimePresence() const throw(INTERP_KERNEL::Exception)
1822 throw INTERP_KERNEL::Exception("No time specified on a field defined as constant on one time interval");
1825 void MEDCouplingConstOnTimeInterval::checkTimePresence(double time) const throw(INTERP_KERNEL::Exception)
1827 if(time<_start_time-_time_tolerance || time>_end_time+_time_tolerance)
1829 std::ostringstream stream;
1830 stream << "The field is defined between times " << _start_time << " and " << _end_time << " worderh tolerance ";
1831 stream << _time_tolerance << " and trying to access on time = " << time;
1832 throw INTERP_KERNEL::Exception(stream.str().c_str());
1836 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const MEDCouplingTimeDiscretization *other) const
1838 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1840 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregation on mismatched time discretization !");
1841 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1842 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1843 ret->setArray(arr,0);
1847 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1849 std::vector<const DataArrayDouble *> a(other.size());
1851 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1853 const MEDCouplingConstOnTimeInterval *itC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(*it);
1855 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregate on mismatched time discretization !");
1856 a[i]=itC->getArray();
1858 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1859 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1860 ret->setArray(arr,0);
1864 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::meld(const MEDCouplingTimeDiscretization *other) const
1866 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1868 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::meld on mismatched time discretization !");
1869 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1870 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1871 ret->setTimeTolerance(getTimeTolerance());
1872 ret->setArray(arr,0);
1876 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::dot(const MEDCouplingTimeDiscretization *other) const
1878 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1880 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::dot on mismatched time discretization !");
1881 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1882 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1883 ret->setArray(arr,0);
1887 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::crossProduct(const MEDCouplingTimeDiscretization *other) const
1889 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1891 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::crossProduct on mismatched time discretization !");
1892 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1893 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1894 ret->setArray(arr,0);
1898 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::max(const MEDCouplingTimeDiscretization *other) const
1900 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1902 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::max on mismatched time discretization !");
1903 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1904 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1905 ret->setArray(arr,0);
1909 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::min(const MEDCouplingTimeDiscretization *other) const
1911 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1913 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::min on mismatched time discretization !");
1914 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1915 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1916 ret->setArray(arr,0);
1920 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::add(const MEDCouplingTimeDiscretization *other) const
1922 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1924 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::add on mismatched time discretization !");
1925 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1926 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1927 ret->setArray(arr,0);
1929 double tmp3=getStartTime(tmp1,tmp2);
1930 ret->setStartTime(tmp3,tmp1,tmp2);
1931 tmp3=getEndTime(tmp1,tmp2);
1932 ret->setEndTime(tmp3,tmp1,tmp2);
1936 void MEDCouplingConstOnTimeInterval::addEqual(const MEDCouplingTimeDiscretization *other)
1938 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1940 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::addEqual on mismatched time discretization !");
1942 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractaddEqual : Data Array is NULL !");
1943 getArray()->addEqual(other->getArray());
1946 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::substract(const MEDCouplingTimeDiscretization *other) const
1948 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1950 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substract on mismatched time discretization !");
1951 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1952 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1953 ret->setArray(arr,0);
1955 double tmp3=getStartTime(tmp1,tmp2);
1956 ret->setStartTime(tmp3,tmp1,tmp2);
1957 tmp3=getEndTime(tmp1,tmp2);
1958 ret->setEndTime(tmp3,tmp1,tmp2);
1962 void MEDCouplingConstOnTimeInterval::substractEqual(const MEDCouplingTimeDiscretization *other)
1964 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1966 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substractEqual on mismatched time discretization !");
1968 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractEqual : Data Array is NULL !");
1969 getArray()->substractEqual(other->getArray());
1972 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::multiply(const MEDCouplingTimeDiscretization *other) const
1974 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1976 throw INTERP_KERNEL::Exception("multiply on mismatched time discretization !");
1977 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1978 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1979 ret->setArray(arr,0);
1981 double tmp3=getStartTime(tmp1,tmp2);
1982 ret->setStartTime(tmp3,tmp1,tmp2);
1983 tmp3=getEndTime(tmp1,tmp2);
1984 ret->setEndTime(tmp3,tmp1,tmp2);
1988 void MEDCouplingConstOnTimeInterval::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1990 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1992 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::multiplyEqual on mismatched time discretization !");
1994 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::multiplyEqual : Data Array is NULL !");
1995 getArray()->multiplyEqual(other->getArray());
1998 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::divide(const MEDCouplingTimeDiscretization *other) const
2000 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2002 throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
2003 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
2004 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2005 ret->setArray(arr,0);
2007 double tmp3=getStartTime(tmp1,tmp2);
2008 ret->setStartTime(tmp3,tmp1,tmp2);
2009 tmp3=getEndTime(tmp1,tmp2);
2010 ret->setEndTime(tmp3,tmp1,tmp2);
2014 void MEDCouplingConstOnTimeInterval::divideEqual(const MEDCouplingTimeDiscretization *other)
2016 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2018 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::divideEqual on mismatched time discretization !");
2020 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::divideEqual : Data Array is NULL !");
2021 getArray()->divideEqual(other->getArray());
2024 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& other, bool deepCpy):MEDCouplingTimeDiscretization(other,deepCpy),
2025 _start_time(other._start_time),_end_time(other._end_time),
2026 _start_iteration(other._start_iteration),_end_iteration(other._end_iteration),
2027 _start_order(other._start_order),_end_order(other._end_order)
2029 if(other._end_array)
2030 _end_array=other._end_array->performCpy(deepCpy);
2035 void MEDCouplingTwoTimeSteps::updateTime() const
2037 MEDCouplingTimeDiscretization::updateTime();
2039 updateTimeWith(*_end_array);
2042 void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception)
2044 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
2045 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2047 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::copyTinyAttrFrom : mismatch of time discretization !");
2048 _start_time=otherC->_start_time;
2049 _end_time=otherC->_end_time;
2050 _start_iteration=otherC->_start_iteration;
2051 _end_iteration=otherC->_end_iteration;
2052 _start_order=otherC->_start_order;
2053 _end_order=otherC->_end_order;
2056 void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other)
2058 MEDCouplingTimeDiscretization::copyTinyStringsFrom(other);
2059 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2061 throw INTERP_KERNEL::Exception("Trying to operate copyTinyStringsFrom on different field type (two times//one time) !");
2062 if(_end_array && otherC->_end_array)
2063 _end_array->copyStringInfoFrom(*otherC->_end_array);
2066 const DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray() const
2071 DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray()
2076 void MEDCouplingTwoTimeSteps::checkCoherency() const throw(INTERP_KERNEL::Exception)
2078 MEDCouplingTimeDiscretization::checkCoherency();
2080 throw INTERP_KERNEL::Exception("No end array specified !");
2081 if(_array->getNumberOfComponents()!=_end_array->getNumberOfComponents())
2082 throw INTERP_KERNEL::Exception("The number of components mismatch between the start and the end arrays !");
2083 if(_array->getNumberOfTuples()!=_end_array->getNumberOfTuples())
2084 throw INTERP_KERNEL::Exception("The number of tuples mismatch between the start and the end arrays !");
2087 bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
2089 std::ostringstream oss;
2090 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(other);
2093 reason="This has time discretization LINEAR_TIME, other not.";
2096 if(_start_iteration!=otherC->_start_iteration)
2098 oss << "start iterations differ. this start iteration=" << _start_iteration << " other start iteration=" << otherC->_start_iteration;
2102 if(_start_order!=otherC->_start_order)
2104 oss << "start orders differ. this start order=" << _start_order << " other start order=" << otherC->_start_order;
2108 if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
2110 oss << "start times differ. this start time=" << _start_time << " other start time=" << otherC->_start_time;
2114 if(_end_iteration!=otherC->_end_iteration)
2116 oss << "end iterations differ. this end iteration=" << _end_iteration << " other end iteration=" << otherC->_end_iteration;
2120 if(_end_order!=otherC->_end_order)
2122 oss << "end orders differ. this end order=" << _end_order << " other end order=" << otherC->_end_order;
2126 if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
2128 oss << "end times differ. this end time=" << _end_time << " other end time=" << otherC->_end_time;
2132 if(_end_array!=otherC->_end_array)
2133 if(!_end_array->isEqualIfNotWhy(*otherC->_end_array,prec,reason))
2135 reason.insert(0,"end arrays differ for linear time.");
2138 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
2141 bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
2143 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(other);
2146 if(_start_iteration!=otherC->_start_iteration)
2148 if(_end_iteration!=otherC->_end_iteration)
2150 if(_start_order!=otherC->_start_order)
2152 if(_end_order!=otherC->_end_order)
2154 if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
2156 if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
2158 if(_end_array!=otherC->_end_array)
2159 if(!_end_array->isEqualWithoutConsideringStr(*otherC->_end_array,prec))
2161 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
2164 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_start_time(0.),_end_time(0.),_start_iteration(-1),_end_iteration(-1),_start_order(-1),_end_order(-1),_end_array(0)
2168 MEDCouplingTwoTimeSteps::~MEDCouplingTwoTimeSteps()
2171 _end_array->decrRef();
2174 void MEDCouplingTwoTimeSteps::checkNoTimePresence() const throw(INTERP_KERNEL::Exception)
2176 throw INTERP_KERNEL::Exception("The field presents a time to be specified in every access !");
2179 void MEDCouplingTwoTimeSteps::checkTimePresence(double time) const throw(INTERP_KERNEL::Exception)
2181 if(time<_start_time-_time_tolerance || time>_end_time+_time_tolerance)
2183 std::ostringstream stream;
2184 stream << "The field is defined between times " << _start_time << " and " << _end_time << " worderh tolerance ";
2185 stream << _time_tolerance << " and trying to access on time = " << time;
2186 throw INTERP_KERNEL::Exception(stream.str().c_str());
2190 void MEDCouplingTwoTimeSteps::getArrays(std::vector<DataArrayDouble *>& arrays) const
2194 arrays[1]=_end_array;
2197 void MEDCouplingTwoTimeSteps::setEndArray(DataArrayDouble *array, TimeLabel *owner)
2199 if(array!=_end_array)
2202 _end_array->decrRef();
2205 _end_array->incrRef();
2207 owner->declareAsNew();
2211 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
2213 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
2214 tinyInfo.push_back(_start_iteration);
2215 tinyInfo.push_back(_start_order);
2216 tinyInfo.push_back(_end_iteration);
2217 tinyInfo.push_back(_end_order);
2220 tinyInfo.push_back(_end_array->getNumberOfTuples());
2221 tinyInfo.push_back(_end_array->getNumberOfComponents());
2225 tinyInfo.push_back(-1);
2226 tinyInfo.push_back(-1);
2230 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
2232 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
2233 tinyInfo.push_back(_start_time);
2234 tinyInfo.push_back(_end_time);
2237 void MEDCouplingTwoTimeSteps::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
2239 int nbOfCompo=_array->getNumberOfComponents();
2240 for(int i=0;i<nbOfCompo;i++)
2241 tinyInfo.push_back(_array->getInfoOnComponent(i));
2242 for(int i=0;i<nbOfCompo;i++)
2243 tinyInfo.push_back(_end_array->getInfoOnComponent(i));
2246 void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
2252 _end_array->decrRef();
2253 DataArrayDouble *arr=0;
2254 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2256 arr=DataArrayDouble::New();
2257 arr->alloc(tinyInfoI[0],tinyInfoI[1]);
2262 if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2264 arr=DataArrayDouble::New();
2265 arr->alloc(tinyInfoI[6],tinyInfoI[7]);
2271 void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
2273 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
2274 _start_time=tinyInfoD[1];
2275 _end_time=tinyInfoD[2];
2276 _start_iteration=tinyInfoI[2];
2277 _start_order=tinyInfoI[3];
2278 _end_iteration=tinyInfoI[4];
2279 _end_order=tinyInfoI[5];
2283 * idem getTinySerializationIntInformation except that it is for multi field fetch
2285 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
2288 tinyInfo[0]=_start_iteration;
2289 tinyInfo[1]=_start_order;
2290 tinyInfo[2]=_end_iteration;
2291 tinyInfo[3]=_end_order;
2295 * idem getTinySerializationDbleInformation except that it is for multi field fetch
2297 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
2300 tinyInfo[0]=_time_tolerance;
2301 tinyInfo[1]=_start_time;
2302 tinyInfo[2]=_end_time;
2306 * idem finishUnserialization except that it is for multi field fetch
2308 void MEDCouplingTwoTimeSteps::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
2310 _start_iteration=tinyInfoI[0];
2311 _start_order=tinyInfoI[1];
2312 _end_iteration=tinyInfoI[2];
2313 _end_order=tinyInfoI[3];
2314 _time_tolerance=tinyInfoD[0];
2315 _start_time=tinyInfoD[1];
2316 _end_time=tinyInfoD[2];
2319 std::vector< const DataArrayDouble *> MEDCouplingTwoTimeSteps::getArraysForTime(double time) const throw(INTERP_KERNEL::Exception)
2321 if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance)
2323 std::vector< const DataArrayDouble *> ret(2);
2329 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2332 void MEDCouplingTwoTimeSteps::setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner) throw(INTERP_KERNEL::Exception)
2334 if(arrays.size()!=2)
2335 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::setArrays : number of arrays must be two.");
2336 setArray(arrays.front(),owner);
2337 setEndArray(arrays.back(),owner);
2340 MEDCouplingLinearTime::MEDCouplingLinearTime(const MEDCouplingLinearTime& other, bool deepCpy):MEDCouplingTwoTimeSteps(other,deepCpy)
2344 MEDCouplingLinearTime::MEDCouplingLinearTime()
2348 std::string MEDCouplingLinearTime::getStringRepr() const
2350 std::ostringstream stream;
2351 stream << REPR << " Time interval is defined by :\niteration_start=" << _start_iteration << " order_start=" << _start_order << " and time_start=" << _start_time << "\n";
2352 stream << "iteration_end=" << _end_iteration << " order_end=" << _end_order << " and end_time=" << _end_time << "\n";
2353 stream << "Time unit is : \"" << _time_unit << "\"";
2354 return stream.str();
2357 void MEDCouplingLinearTime::checkCoherency() const throw(INTERP_KERNEL::Exception)
2359 MEDCouplingTwoTimeSteps::checkCoherency();
2360 if(std::fabs(_start_time-_end_time)<_time_tolerance)
2361 throw INTERP_KERNEL::Exception("Start time and end time are equals regarding time tolerance.");
2364 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::performCpy(bool deepCpy) const
2366 return new MEDCouplingLinearTime(*this,deepCpy);
2369 bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretization *other) const
2371 if(!MEDCouplingTimeDiscretization::areCompatible(other))
2373 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2376 if(_end_array==0 && otherC->_end_array==0)
2378 if(_end_array==0 || otherC->_end_array==0)
2380 if(_end_array->getNumberOfComponents()!=otherC->_end_array->getNumberOfComponents())
2385 bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other, std::string& reason) const
2387 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
2389 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2392 reason.insert(0,"time discretization of this is LINEAR_TIME, other has a different time discretization.");
2396 bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
2398 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
2400 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2404 bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
2406 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
2408 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2411 if(_end_array==0 && otherC->_end_array==0)
2413 if(_end_array==0 || otherC->_end_array==0)
2415 int nbC1=_end_array->getNumberOfComponents();
2416 int nbC2=otherC->_end_array->getNumberOfComponents();
2417 if(nbC1!=nbC2 && nbC2!=1)
2422 bool MEDCouplingLinearTime::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
2424 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
2426 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2431 * vals is expected to be of size 2*_array->getNumberOfTuples()==_array->getNumberOfTuples()+_end_array->getNumberOfTuples()
2433 void MEDCouplingLinearTime::getValueForTime(double time, const std::vector<double>& vals, double *res) const
2435 double alpha=(_end_time-time)/(_end_time-_start_time);
2436 std::size_t nbComp=vals.size()/2;
2437 std::transform(vals.begin(),vals.begin()+nbComp,res,std::bind2nd(std::multiplies<double>(),alpha));
2438 std::vector<double> tmp(nbComp);
2439 std::transform(vals.begin()+nbComp,vals.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2440 std::transform(tmp.begin(),tmp.end(),res,res,std::plus<double>());
2443 void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception)
2445 double alpha=(_end_time-time)/(_end_time-_start_time);
2448 _array->getTuple(eltId,value);
2450 throw INTERP_KERNEL::Exception("No start array existing.");
2451 nbComp=_array->getNumberOfComponents();
2452 std::transform(value,value+nbComp,value,std::bind2nd(std::multiplies<double>(),alpha));
2453 std::vector<double> tmp(nbComp);
2455 _end_array->getTuple(eltId,&tmp[0]);
2457 throw INTERP_KERNEL::Exception("No end array existing.");
2458 std::transform(tmp.begin(),tmp.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2459 std::transform(tmp.begin(),tmp.end(),value,value,std::plus<double>());
2462 void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const throw(INTERP_KERNEL::Exception)
2464 if(iteration==_start_iteration && order==_start_order)
2467 _array->getTuple(eltId,value);
2469 throw INTERP_KERNEL::Exception("iteration order match with start time but no start array existing.");
2471 if(iteration==_end_iteration && order==_end_order)
2474 _end_array->getTuple(eltId,value);
2476 throw INTERP_KERNEL::Exception("iteration order match with end time but no end array existing.");
2479 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2482 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const MEDCouplingTimeDiscretization *other) const
2484 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2486 throw INTERP_KERNEL::Exception("LinearTime::aggregation on mismatched time discretization !");
2487 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Aggregate(getArray(),other->getArray());
2488 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Aggregate(getEndArray(),other->getEndArray());
2489 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2490 ret->setArray(arr1,0);
2491 ret->setEndArray(arr2,0);
2495 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
2497 std::vector<const DataArrayDouble *> a(other.size());
2498 std::vector<const DataArrayDouble *> b(other.size());
2500 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
2502 const MEDCouplingLinearTime *itC=dynamic_cast<const MEDCouplingLinearTime *>(*it);
2504 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::aggregate on mismatched time discretization !");
2505 a[i]=itC->getArray();
2506 b[i]=itC->getEndArray();
2508 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
2509 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Aggregate(b);
2510 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2511 ret->setArray(arr,0);
2512 ret->setEndArray(arr2,0);
2516 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::meld(const MEDCouplingTimeDiscretization *other) const
2518 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2520 throw INTERP_KERNEL::Exception("LinearTime::meld on mismatched time discretization !");
2521 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Meld(getArray(),other->getArray());
2522 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Meld(getEndArray(),other->getEndArray());
2523 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2524 ret->setTimeTolerance(getTimeTolerance());
2525 ret->setArray(arr1,0);
2526 ret->setEndArray(arr2,0);
2530 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeDiscretization *other) const
2532 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2534 throw INTERP_KERNEL::Exception("LinearTime::dot on mismatched time discretization !");
2535 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Dot(getArray(),other->getArray());
2536 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Dot(getEndArray(),other->getEndArray());
2537 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2538 ret->setArray(arr1,0);
2539 ret->setEndArray(arr2,0);
2543 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::crossProduct(const MEDCouplingTimeDiscretization *other) const
2545 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2547 throw INTERP_KERNEL::Exception("LinearTime::crossProduct on mismatched time discretization !");
2548 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::CrossProduct(getArray(),other->getArray());
2549 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::CrossProduct(getEndArray(),other->getEndArray());
2550 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2551 ret->setArray(arr1,0);
2552 ret->setEndArray(arr2,0);
2556 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::max(const MEDCouplingTimeDiscretization *other) const
2558 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2560 throw INTERP_KERNEL::Exception("LinearTime::max on mismatched time discretization !");
2561 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2562 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Max(getArray(),other->getArray());
2563 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Max(getEndArray(),other->getEndArray());
2564 ret->setArray(arr1,0);
2565 ret->setEndArray(arr2,0);
2569 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::min(const MEDCouplingTimeDiscretization *other) const
2571 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2573 throw INTERP_KERNEL::Exception("LinearTime::min on mismatched time discretization !");
2574 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Min(getArray(),other->getArray());
2575 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Min(getEndArray(),other->getEndArray());
2576 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2577 ret->setArray(arr1,0);
2578 ret->setEndArray(arr2,0);
2582 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::add(const MEDCouplingTimeDiscretization *other) const
2584 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2586 throw INTERP_KERNEL::Exception("LinearTime::add on mismatched time discretization !");
2587 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Add(getArray(),other->getArray());
2588 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Add(getEndArray(),other->getEndArray());
2589 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2590 ret->setArray(arr1,0);
2591 ret->setEndArray(arr2,0);
2595 void MEDCouplingLinearTime::addEqual(const MEDCouplingTimeDiscretization *other)
2597 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2599 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2601 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array is NULL !");
2603 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array (end) is NULL !");
2604 getArray()->addEqual(other->getArray());
2605 getEndArray()->addEqual(other->getEndArray());
2608 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::substract(const MEDCouplingTimeDiscretization *other) const
2610 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2612 throw INTERP_KERNEL::Exception("LinearTime::substract on mismatched time discretization !");
2613 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Substract(getArray(),other->getArray());
2614 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Substract(getEndArray(),other->getEndArray());
2615 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2616 ret->setArray(arr1,0);
2617 ret->setEndArray(arr2,0);
2621 void MEDCouplingLinearTime::substractEqual(const MEDCouplingTimeDiscretization *other)
2623 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2625 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2627 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array is NULL !");
2629 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array (end) is NULL !");
2630 getArray()->substractEqual(other->getArray());
2631 getEndArray()->substractEqual(other->getEndArray());
2634 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::multiply(const MEDCouplingTimeDiscretization *other) const
2636 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2638 throw INTERP_KERNEL::Exception("LinearTime::multiply on mismatched time discretization !");
2639 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Multiply(getArray(),other->getArray());
2640 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Multiply(getEndArray(),other->getEndArray());
2641 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2642 ret->setArray(arr1,0);
2643 ret->setEndArray(arr2,0);
2647 void MEDCouplingLinearTime::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2649 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2651 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2653 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array is NULL !");
2655 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array (end) is NULL !");
2656 getArray()->multiplyEqual(other->getArray());
2657 getEndArray()->multiplyEqual(other->getEndArray());
2660 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::divide(const MEDCouplingTimeDiscretization *other) const
2662 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2664 throw INTERP_KERNEL::Exception("LinearTime::divide on mismatched time discretization !");
2665 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr1=DataArrayDouble::Divide(getArray(),other->getArray());
2666 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=DataArrayDouble::Divide(getEndArray(),other->getEndArray());
2667 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2668 ret->setArray(arr1,0);
2669 ret->setEndArray(arr2,0);
2673 void MEDCouplingLinearTime::divideEqual(const MEDCouplingTimeDiscretization *other)
2675 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2677 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2679 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array is NULL !");
2681 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array (end) is NULL !");
2682 getArray()->divideEqual(other->getArray());
2683 getEndArray()->divideEqual(other->getEndArray());