1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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.txx"
23 #include "MEDCouplingMemArray.hxx"
24 #include "MEDCouplingMesh.hxx"
30 using namespace MEDCoupling;
32 template class MEDCouplingTimeDiscretizationTemplate<double>;
33 template class MEDCouplingTimeDiscretizationTemplate<int>;
35 const char MEDCouplingTimeDiscretizationInt::REPR[]="One time label.";
37 const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setTime : no time info attached.";
39 const char MEDCouplingNoTimeLabel::REPR[]="No time label defined.";
41 const char MEDCouplingWithTimeStep::EXCEPTION_MSG[]="No data on this time.";
43 const char MEDCouplingWithTimeStep::REPR[]="One time label.";
45 const char MEDCouplingConstOnTimeInterval::EXCEPTION_MSG[]="No data on this time.";
47 const char MEDCouplingConstOnTimeInterval::REPR[]="Constant on a time interval.";
49 const char MEDCouplingTwoTimeSteps::EXCEPTION_MSG[]="No data on this time.";
51 const char MEDCouplingLinearTime::REPR[]="Linear time between 2 time steps.";
53 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDiscretization type)
57 case MEDCouplingNoTimeLabel::DISCRETIZATION:
58 return new MEDCouplingNoTimeLabel;
59 case MEDCouplingWithTimeStep::DISCRETIZATION:
60 return new MEDCouplingWithTimeStep;
61 case MEDCouplingConstOnTimeInterval::DISCRETIZATION:
62 return new MEDCouplingConstOnTimeInterval;
63 case MEDCouplingLinearTime::DISCRETIZATION:
64 return new MEDCouplingLinearTime;
66 throw INTERP_KERNEL::Exception("Time discretization not implemented yet");
70 bool MEDCouplingTimeDiscretization::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
72 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
74 if(_array==0 && other->_array==0)
76 if(_array==0 || other->_array==0)
78 if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
83 bool MEDCouplingTimeDiscretization::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
85 if(!areStrictlyCompatible(other,reason))
87 if(_array==other->getArray())
89 return _array->isEqualIfNotWhy(*other->getArray(),prec,reason);
92 bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
95 return isEqualIfNotWhy(other,prec,reason);
98 bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
101 if(!areStrictlyCompatible(other,tmp))
103 if(_array==other->getArray())
105 return _array->isEqualWithoutConsideringStr(*other->getArray(),prec);
108 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(TypeOfTimeDiscretization type, bool deepCopy) const
110 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(type);
111 ret->setTimeUnit(getTimeUnit());
112 const DataArrayDouble *arrSrc=getArray();
113 MCAuto<DataArrayDouble> arr;
115 arr=arrSrc->performCopyOrIncrRef(deepCopy);
116 ret->setArray(arr,0);
120 void MEDCouplingTimeDiscretization::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
124 tinyInfo.push_back(_array->getNumberOfTuples());
125 tinyInfo.push_back(_array->getNumberOfComponents());
129 tinyInfo.push_back(-1);
130 tinyInfo.push_back(-1);
134 void MEDCouplingTimeDiscretization::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
139 DataArrayDouble *arr=0;
140 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
142 arr=DataArrayDouble::New();
143 arr->alloc(tinyInfoI[0],tinyInfoI[1]);
149 void MEDCouplingTimeDiscretization::checkForUnserialization(const std::vector<int>& tinyInfoI, const std::vector<DataArrayDouble *>& arrays)
151 static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size one !";
153 throw INTERP_KERNEL::Exception(MSG);
157 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
160 throw INTERP_KERNEL::Exception(MSG);
161 arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
167 void MEDCouplingTimeDiscretization::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
169 _time_tolerance=tinyInfoD[0];
170 int nbOfCompo=_array->getNumberOfComponents();
171 for(int i=0;i<nbOfCompo;i++)
172 _array->setInfoOnComponent(i,tinyInfoS[i]);
175 void MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
177 tinyInfo.push_back(_time_tolerance);
180 void MEDCouplingTimeDiscretization::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
182 int nbOfCompo=_array->getNumberOfComponents();
183 for(int i=0;i<nbOfCompo;i++)
184 tinyInfo.push_back(_array->getInfoOnComponent(i));
187 bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const
190 double time1=getEndTime(iteration,order)-_time_tolerance;
191 double time2=other->getStartTime(iteration,order)+other->getTimeTolerance();
195 bool MEDCouplingTimeDiscretization::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const
198 double time1=getEndTime(iteration,order)+_time_tolerance;
199 double time2=other->getStartTime(iteration,order)-other->getTimeTolerance();
203 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedProduct() const
205 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
206 ret->setTimeUnit(getTimeUnit());
207 std::vector<DataArrayDouble *> arrays;
209 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
210 for(std::size_t j=0;j<arrays.size();j++)
213 arrays2[j]=arrays[j]->doublyContractedProduct();
217 std::vector<DataArrayDouble *> arrays3(arrays.size());
218 for(std::size_t j=0;j<arrays.size();j++)
219 arrays3[j]=arrays2[j];
220 ret->setArrays(arrays3,0);
224 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() const
226 std::vector<DataArrayDouble *> arrays;
228 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
229 for(std::size_t j=0;j<arrays.size();j++)
232 arrays2[j]=arrays[j]->determinant();
236 std::vector<DataArrayDouble *> arrays3(arrays.size());
237 for(std::size_t j=0;j<arrays.size();j++)
238 arrays3[j]=arrays2[j];
239 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
240 ret->setTimeUnit(getTimeUnit());
241 ret->setArrays(arrays3,0);
245 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() const
247 std::vector<DataArrayDouble *> arrays;
249 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
250 for(std::size_t j=0;j<arrays.size();j++)
253 arrays2[j]=arrays[j]->eigenValues();
257 std::vector<DataArrayDouble *> arrays3(arrays.size());
258 for(std::size_t j=0;j<arrays.size();j++)
259 arrays3[j]=arrays2[j];
260 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
261 ret->setTimeUnit(getTimeUnit());
262 ret->setArrays(arrays3,0);
266 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() const
268 std::vector<DataArrayDouble *> arrays;
270 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
271 for(std::size_t j=0;j<arrays.size();j++)
274 arrays2[j]=arrays[j]->eigenVectors();
278 std::vector<DataArrayDouble *> arrays3(arrays.size());
279 for(std::size_t j=0;j<arrays.size();j++)
280 arrays3[j]=arrays2[j];
281 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
282 ret->setTimeUnit(getTimeUnit());
283 ret->setArrays(arrays3,0);
287 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const
289 std::vector<DataArrayDouble *> arrays;
291 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
292 for(std::size_t j=0;j<arrays.size();j++)
295 arrays2[j]=arrays[j]->inverse();
299 std::vector<DataArrayDouble *> arrays3(arrays.size());
300 for(std::size_t j=0;j<arrays.size();j++)
301 arrays3[j]=arrays2[j];
302 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
303 ret->setTimeUnit(getTimeUnit());
304 ret->setArrays(arrays3,0);
308 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const
310 std::vector<DataArrayDouble *> arrays;
312 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
313 for(std::size_t j=0;j<arrays.size();j++)
316 arrays2[j]=arrays[j]->trace();
320 std::vector<DataArrayDouble *> arrays3(arrays.size());
321 for(std::size_t j=0;j<arrays.size();j++)
322 arrays3[j]=arrays2[j];
323 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
324 ret->setTimeUnit(getTimeUnit());
325 ret->setArrays(arrays3,0);
329 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const
331 std::vector<DataArrayDouble *> arrays;
333 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
334 for(std::size_t j=0;j<arrays.size();j++)
337 arrays2[j]=arrays[j]->deviator();
341 std::vector<DataArrayDouble *> arrays3(arrays.size());
342 for(std::size_t j=0;j<arrays.size();j++)
343 arrays3[j]=arrays2[j];
344 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
345 ret->setTimeUnit(getTimeUnit());
346 ret->setArrays(arrays3,0);
350 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const
352 std::vector<DataArrayDouble *> arrays;
354 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
355 for(std::size_t j=0;j<arrays.size();j++)
358 arrays2[j]=arrays[j]->magnitude();
362 std::vector<DataArrayDouble *> arrays3(arrays.size());
363 for(std::size_t j=0;j<arrays.size();j++)
364 arrays3[j]=arrays2[j];
365 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
366 ret->setTimeUnit(getTimeUnit());
367 ret->setArrays(arrays3,0);
371 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::negate() const
373 std::vector<DataArrayDouble *> arrays;
375 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
376 for(std::size_t j=0;j<arrays.size();j++)
379 arrays2[j]=arrays[j]->negate();
383 std::vector<DataArrayDouble *> arrays3(arrays.size());
384 for(std::size_t j=0;j<arrays.size();j++)
385 arrays3[j]=arrays2[j];
386 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
387 ret->setTimeUnit(getTimeUnit());
388 ret->setArrays(arrays3,0);
392 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() const
394 std::vector<DataArrayDouble *> arrays;
396 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
397 for(std::size_t j=0;j<arrays.size();j++)
400 arrays2[j]=arrays[j]->maxPerTuple();
404 std::vector<DataArrayDouble *> arrays3(arrays.size());
405 for(std::size_t j=0;j<arrays.size();j++)
406 arrays3[j]=arrays2[j];
407 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
408 ret->setTimeUnit(getTimeUnit());
409 ret->setArrays(arrays3,0);
413 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedComponents(const std::vector<int>& compoIds) const
415 std::vector<DataArrayDouble *> arrays;
417 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
418 for(std::size_t j=0;j<arrays.size();j++)
421 arrays2[j]=static_cast<DataArrayDouble *>(arrays[j]->keepSelectedComponents(compoIds));
425 std::vector<DataArrayDouble *> arrays3(arrays.size());
426 for(std::size_t j=0;j<arrays.size();j++)
427 arrays3[j]=arrays2[j];
428 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
429 ret->setTimeUnit(getTimeUnit());
430 ret->setArrays(arrays3,0);
434 void MEDCouplingTimeDiscretization::setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector<int>& compoIds)
436 std::vector<DataArrayDouble *> arrays1,arrays2;
438 other->getArrays(arrays2);
439 if(arrays1.size()!=arrays2.size())
440 throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : number of arrays mismatch !");
441 for(std::size_t i=0;i<arrays1.size();i++)
443 if(arrays1[i]!=0 && arrays2[i]!=0)
444 arrays1[i]->setSelectedComponents(arrays2[i],compoIds);
445 else if(arrays1[i]!=0 || arrays2[i]!=0)
446 throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : some time array in correspondance are not defined symetrically !");
450 void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double dftValue)
452 std::vector<DataArrayDouble *> arrays;
454 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
455 for(std::size_t j=0;j<arrays.size();j++)
458 arrays2[j]=arrays[j]->changeNbOfComponents(newNbOfComp,dftValue);
462 std::vector<DataArrayDouble *> arrays3(arrays.size());
463 for(std::size_t j=0;j<arrays.size();j++)
464 arrays3[j]=arrays2[j];
465 setArrays(arrays3,0);
468 void MEDCouplingTimeDiscretization::sortPerTuple(bool asc)
470 std::vector<DataArrayDouble *> arrays;
472 for(std::size_t j=0;j<arrays.size();j++)
475 arrays[j]->sortPerTuple(asc);
479 void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, int nbOfCompo, double value)
481 std::vector<DataArrayDouble *> arrays;
483 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
484 for(std::size_t j=0;j<arrays.size();j++)
488 arrays2[j]=arrays[j]->changeNbOfComponents(nbOfCompo,value);
489 arrays2[j]->fillWithValue(value);
493 arrays2[j]=DataArrayDouble::New();
494 arrays2[j]->alloc(nbOfTuple,nbOfCompo);
495 arrays2[j]->fillWithValue(value);
498 std::vector<DataArrayDouble *> arrays3(arrays.size());
499 for(std::size_t j=0;j<arrays.size();j++)
500 arrays3[j]=arrays2[j];
501 setArrays(arrays3,0);
504 void MEDCouplingTimeDiscretization::setOrCreateUniformValueOnAllComponents(int nbOfTuple, double value)
506 std::vector<DataArrayDouble *> arrays;
508 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
510 for(std::size_t j=0;j<arrays.size();j++)
514 arrays2[j]=arrays[j]; arrays2[j]->incrRef();
515 arrays2[j]->fillWithValue(value);
520 arrays2[j]=DataArrayDouble::New();
521 arrays2[j]->alloc(nbOfTuple,1);
522 arrays2[j]->fillWithValue(value);
527 std::vector<DataArrayDouble *> arrays3(arrays.size());
528 for(std::size_t j=0;j<arrays.size();j++)
529 arrays3[j]=arrays2[j];
530 setArrays(arrays3,0);
534 void MEDCouplingTimeDiscretization::applyLin(double a, double b, int compoId)
536 std::vector<DataArrayDouble *> arrays;
538 for(std::size_t j=0;j<arrays.size();j++)
541 arrays[j]->applyLin(a,b,compoId);
545 void MEDCouplingTimeDiscretization::applyLin(double a, double b)
547 std::vector<DataArrayDouble *> arrays;
549 for(std::size_t j=0;j<arrays.size();j++)
552 arrays[j]->applyLin(a,b);
556 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate func)
558 std::vector<DataArrayDouble *> arrays;
560 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
561 for(std::size_t j=0;j<arrays.size();j++)
564 arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
568 std::vector<DataArrayDouble *> arrays3(arrays.size());
569 for(std::size_t j=0;j<arrays.size();j++)
570 arrays3[j]=arrays2[j];
571 setArrays(arrays3,0);
574 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const std::string& func)
576 std::vector<DataArrayDouble *> arrays;
578 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
579 for(std::size_t j=0;j<arrays.size();j++)
582 arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
586 std::vector<DataArrayDouble *> arrays3(arrays.size());
587 for(std::size_t j=0;j<arrays.size();j++)
588 arrays3[j]=arrays2[j];
589 setArrays(arrays3,0);
592 void MEDCouplingTimeDiscretization::applyFuncCompo(int nbOfComp, const std::string& func)
594 std::vector<DataArrayDouble *> arrays;
596 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
597 for(std::size_t j=0;j<arrays.size();j++)
600 arrays2[j]=arrays[j]->applyFuncCompo(nbOfComp,func);
604 std::vector<DataArrayDouble *> arrays3(arrays.size());
605 for(std::size_t j=0;j<arrays.size();j++)
606 arrays3[j]=arrays2[j];
607 setArrays(arrays3,0);
610 void MEDCouplingTimeDiscretization::applyFuncNamedCompo(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
612 std::vector<DataArrayDouble *> arrays;
614 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
615 for(std::size_t j=0;j<arrays.size();j++)
618 arrays2[j]=arrays[j]->applyFuncNamedCompo(nbOfComp,varsOrder,func);
622 std::vector<DataArrayDouble *> arrays3(arrays.size());
623 for(std::size_t j=0;j<arrays.size();j++)
624 arrays3[j]=arrays2[j];
625 setArrays(arrays3,0);
628 void MEDCouplingTimeDiscretization::applyFunc(const std::string& func)
630 std::vector<DataArrayDouble *> arrays;
632 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
633 for(std::size_t j=0;j<arrays.size();j++)
636 arrays2[j]=arrays[j]->applyFunc(func);
640 std::vector<DataArrayDouble *> arrays3(arrays.size());
641 for(std::size_t j=0;j<arrays.size();j++)
642 arrays3[j]=arrays2[j];
643 setArrays(arrays3,0);
646 void MEDCouplingTimeDiscretization::applyFuncFast32(const std::string& func)
648 std::vector<DataArrayDouble *> arrays;
650 for(std::size_t j=0;j<arrays.size();j++)
653 arrays[j]->applyFuncFast32(func);
657 void MEDCouplingTimeDiscretization::applyFuncFast64(const std::string& func)
659 std::vector<DataArrayDouble *> arrays;
661 for(std::size_t j=0;j<arrays.size();j++)
664 arrays[j]->applyFuncFast64(func);
668 void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, FunctionToEvaluate func)
670 std::vector<DataArrayDouble *> arrays;
672 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
673 for(std::size_t j=0;j<arrays.size();j++)
674 arrays2[j]=loc->applyFunc(nbOfComp,func);
675 std::vector<DataArrayDouble *> arrays3(arrays.size());
676 for(std::size_t j=0;j<arrays.size();j++)
677 arrays3[j]=arrays2[j];
678 setArrays(arrays3,0);
681 void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, const std::string& func)
683 std::vector<DataArrayDouble *> arrays;
685 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
686 for(std::size_t j=0;j<arrays.size();j++)
687 arrays2[j]=loc->applyFunc(nbOfComp,func);
688 std::vector<DataArrayDouble *> arrays3(arrays.size());
689 for(std::size_t j=0;j<arrays.size();j++)
690 arrays3[j]=arrays2[j];
691 setArrays(arrays3,0);
694 void MEDCouplingTimeDiscretization::fillFromAnalyticCompo(const DataArrayDouble *loc, int nbOfComp, const std::string& func)
696 std::vector<DataArrayDouble *> arrays;
698 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
699 for(std::size_t j=0;j<arrays.size();j++)
700 arrays2[j]=loc->applyFuncCompo(nbOfComp,func);
701 std::vector<DataArrayDouble *> arrays3(arrays.size());
702 for(std::size_t j=0;j<arrays.size();j++)
703 arrays3[j]=arrays2[j];
704 setArrays(arrays3,0);
707 void MEDCouplingTimeDiscretization::fillFromAnalyticNamedCompo(const DataArrayDouble *loc, int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
709 std::vector<DataArrayDouble *> arrays;
711 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
712 for(std::size_t j=0;j<arrays.size();j++)
713 arrays2[j]=loc->applyFuncNamedCompo(nbOfComp,varsOrder,func);
714 std::vector<DataArrayDouble *> arrays3(arrays.size());
715 for(std::size_t j=0;j<arrays.size();j++)
716 arrays3[j]=arrays2[j];
717 setArrays(arrays3,0);
720 ////////////////////////
722 bool MEDCouplingTimeKeeper::isEqualIfNotWhy(const MEDCouplingTimeKeeper& other, double prec, std::string& reason) const
724 std::ostringstream oss;
725 if(_iteration!=other._iteration)
727 oss << "iterations differ. this iteration=" << _iteration << " other iteration=" << other._iteration;
731 if(_order!=other._order)
733 oss << "orders differ. this order=" << _order << " other order=" << other._order;
737 if(std::fabs(_time-other._time)>prec)
739 oss << "times differ. this time=" << _time << " other time=" << other._time;
746 bool MEDCouplingTimeKeeper::isEqual(const MEDCouplingTimeKeeper& other, double prec) const
748 if(_iteration!=other._iteration)
750 if(_order!=other._order)
752 if(std::fabs(_time-other._time)>prec)
757 void MEDCouplingTimeKeeper::copyFrom(const MEDCouplingTimeKeeper& other)
760 _iteration=other._iteration;
764 void MEDCouplingTimeKeeper::checkTimePresence(double time, double eps) const
766 if(std::fabs(time-_time)>eps)
768 std::ostringstream stream;
769 stream << "The field is defined on time " << _time << " with eps=" << eps << " and asking time = " << time << " !";
770 throw INTERP_KERNEL::Exception(stream.str().c_str());
774 ////////////////////////
776 MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt()
780 MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate<int>(other,deepCopy),_tk(other._tk)
784 std::string MEDCouplingTimeDiscretizationInt::getStringRepr() const
786 std::ostringstream stream;
787 stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
788 stream << "\nTime unit is : \"" << _time_unit << "\"";
792 MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::performCopyOrIncrRef(bool deepCopy) const
794 return new MEDCouplingTimeDiscretizationInt(*this,deepCopy);
797 MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::New(TypeOfTimeDiscretization type)
801 case MEDCouplingTimeDiscretizationInt::DISCRETIZATION:
802 return new MEDCouplingTimeDiscretizationInt;
804 throw INTERP_KERNEL::Exception("Time discretization not implemented yet for intergers !");
808 bool MEDCouplingTimeDiscretizationInt::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<int> *other, int prec, std::string& reason) const
811 throw INTERP_KERNEL::Exception("isEqualIfNotWhy : only precision equal to 0 supported for int !");
814 reason="Time discretization is NULL.";
817 const MEDCouplingTimeDiscretizationInt *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationInt *>(other));
819 throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationInt !");
820 if(!MEDCouplingTimeDiscretizationTemplate<int>::areStrictlyCompatible(other,reason))
822 if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
824 if(_array==other->getArray())
826 return _array->isEqualIfNotWhy(*other->getArray(),reason);
829 bool MEDCouplingTimeDiscretizationInt::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<int> *other, int prec) const
832 throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationInt::isEqualWithoutConsideringStr : only precision 0 is supported !");
833 const MEDCouplingTimeDiscretizationInt *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationInt *>(other));
835 throw INTERP_KERNEL::Exception("isEqualWithoutConsideringStr : other is not a MEDCouplingTimeDiscretizationInt !");
837 if(!areStrictlyCompatible(other,tmp))
840 if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
842 if(_array==other->getArray())
844 return _array->isEqualWithoutConsideringStr(*(other->getArray()));
847 double MEDCouplingTimeDiscretizationInt::getEndTime(int& iteration, int& order) const
849 throw INTERP_KERNEL::Exception("getEndTime : invalid for this type of time discr !");
852 void MEDCouplingTimeDiscretizationInt::setEndIteration(int it)
854 throw INTERP_KERNEL::Exception("setEndIteration : invalid for this type of time discr !");
857 void MEDCouplingTimeDiscretizationInt::setEndOrder(int order)
859 throw INTERP_KERNEL::Exception("setEndOrder : invalid for this type of time discr !");
862 void MEDCouplingTimeDiscretizationInt::setEndTimeValue(double time)
864 throw INTERP_KERNEL::Exception("setEndTimeValue : invalid for this type of time discr !");
867 void MEDCouplingTimeDiscretizationInt::setEndTime(double time, int iteration, int order)
869 throw INTERP_KERNEL::Exception("setEndTime : invalid for this type of time discr !");
872 ////////////////////////
874 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel()
878 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretization& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy)
882 std::string MEDCouplingNoTimeLabel::getStringRepr() const
884 std::ostringstream stream;
886 stream << "\nTime unit is : \"" << _time_unit << "\"";
890 void MEDCouplingNoTimeLabel::synchronizeTimeWith(const MEDCouplingMesh *mesh)
892 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::synchronizeTimeWith : impossible to synchronize time with a MEDCouplingMesh because the time discretization is incompatible with it !");
895 bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
897 if(!MEDCouplingTimeDiscretization::areCompatible(other))
899 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
903 bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
905 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
907 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
910 reason.insert(0,"time discretization of this is NO_TIME, other has a different time discretization.");
914 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
916 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
918 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
922 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
924 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
926 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
930 bool MEDCouplingNoTimeLabel::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
932 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
934 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
938 bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
940 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
943 reason="This has time discretization NO_TIME, other not.";
946 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
949 bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
951 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
954 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
957 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCouplingTimeDiscretization *other) const
959 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
961 throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !");
962 MCAuto<DataArrayDouble> arr(DataArrayDouble::Aggregate(getArray(),other->getArray()));
963 MEDCouplingNoTimeLabel *ret(new MEDCouplingNoTimeLabel);
964 ret->setArray(arr,0);
968 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
970 std::vector<const DataArrayDouble *> a(other.size());
972 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
974 const MEDCouplingNoTimeLabel *itC=dynamic_cast<const MEDCouplingNoTimeLabel *>(*it);
976 throw INTERP_KERNEL::Exception("NoTimeLabel::aggregate on mismatched time discretization !");
977 a[i]=itC->getArray();
979 MCAuto<DataArrayDouble> arr(DataArrayDouble::Aggregate(a));
980 MEDCouplingNoTimeLabel *ret(new MEDCouplingNoTimeLabel);
981 ret->setArray(arr,0);
985 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::meld(const MEDCouplingTimeDiscretization *other) const
987 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
989 throw INTERP_KERNEL::Exception("NoTimeLabel::meld on mismatched time discretization !");
990 MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
991 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
992 ret->setTimeTolerance(getTimeTolerance());
993 ret->setArray(arr,0);
997 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::dot(const MEDCouplingTimeDiscretization *other) const
999 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1001 throw INTERP_KERNEL::Exception("NoTimeLabel::dot on mismatched time discretization !");
1002 MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1003 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1004 ret->setArray(arr,0);
1008 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::crossProduct(const MEDCouplingTimeDiscretization *other) const
1010 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1012 throw INTERP_KERNEL::Exception("NoTimeLabel::crossProduct on mismatched time discretization !");
1013 MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1014 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1015 ret->setArray(arr,0);
1019 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::max(const MEDCouplingTimeDiscretization *other) const
1021 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1023 throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
1024 MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1025 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1026 ret->setArray(arr,0);
1030 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::min(const MEDCouplingTimeDiscretization *other) const
1032 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1034 throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
1035 MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1036 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1037 ret->setArray(arr,0);
1041 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::add(const MEDCouplingTimeDiscretization *other) const
1043 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1045 throw INTERP_KERNEL::Exception("NoTimeLabel::add on mismatched time discretization !");
1046 MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1047 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1048 ret->setArray(arr,0);
1052 void MEDCouplingNoTimeLabel::addEqual(const MEDCouplingTimeDiscretization *other)
1054 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1056 throw INTERP_KERNEL::Exception("NoTimeLabel::addEqual on mismatched time discretization !");
1058 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::addEqual : Data Array is NULL !");
1059 getArray()->addEqual(other->getArray());
1062 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::substract(const MEDCouplingTimeDiscretization *other) const
1064 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1066 throw INTERP_KERNEL::Exception("NoTimeLabel::substract on mismatched time discretization !");
1068 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substract : Data Array is NULL !");
1069 MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1070 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1071 ret->setArray(arr,0);
1075 void MEDCouplingNoTimeLabel::substractEqual(const MEDCouplingTimeDiscretization *other)
1077 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1079 throw INTERP_KERNEL::Exception("NoTimeLabel::substractEqual on mismatched time discretization !");
1081 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substractEqual : Data Array is NULL !");
1082 getArray()->substractEqual(other->getArray());
1085 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::multiply(const MEDCouplingTimeDiscretization *other) const
1087 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1089 throw INTERP_KERNEL::Exception("NoTimeLabel::multiply on mismatched time discretization !");
1090 MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1091 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1092 ret->setArray(arr,0);
1096 void MEDCouplingNoTimeLabel::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1098 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1100 throw INTERP_KERNEL::Exception("NoTimeLabel::multiplyEqual on mismatched time discretization !");
1102 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::multiplyEqual : Data Array is NULL !");
1103 getArray()->multiplyEqual(other->getArray());
1106 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::divide(const MEDCouplingTimeDiscretization *other) const
1108 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1110 throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
1111 MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1112 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1113 ret->setArray(arr,0);
1117 void MEDCouplingNoTimeLabel::divideEqual(const MEDCouplingTimeDiscretization *other)
1119 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1121 throw INTERP_KERNEL::Exception("NoTimeLabel::divideEqual on mismatched time discretization !");
1123 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::divideEqual : Data Array is NULL !");
1124 getArray()->divideEqual(other->getArray());
1127 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::pow(const MEDCouplingTimeDiscretization *other) const
1129 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1131 throw INTERP_KERNEL::Exception("pow on mismatched time discretization !");
1132 MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
1133 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1134 ret->setArray(arr,0);
1138 void MEDCouplingNoTimeLabel::powEqual(const MEDCouplingTimeDiscretization *other)
1140 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1142 throw INTERP_KERNEL::Exception("NoTimeLabel::powEqual on mismatched time discretization !");
1144 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::powEqual : Data Array is NULL !");
1145 getArray()->powEqual(other->getArray());
1148 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCopyOrIncrRef(bool deepCopy) const
1150 return new MEDCouplingNoTimeLabel(*this,deepCopy);
1153 void MEDCouplingNoTimeLabel::checkTimePresence(double time) const
1155 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1158 std::vector< const DataArrayDouble *> MEDCouplingNoTimeLabel::getArraysForTime(double time) const
1160 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1163 void MEDCouplingNoTimeLabel::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1165 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1168 bool MEDCouplingNoTimeLabel::isBefore(const MEDCouplingTimeDiscretization *other) const
1170 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1173 bool MEDCouplingNoTimeLabel::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const
1175 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1178 double MEDCouplingNoTimeLabel::getStartTime(int& iteration, int& order) const
1180 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1183 double MEDCouplingNoTimeLabel::getEndTime(int& iteration, int& order) const
1185 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1188 void MEDCouplingNoTimeLabel::setStartIteration(int it)
1190 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1193 void MEDCouplingNoTimeLabel::setEndIteration(int it)
1195 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1198 void MEDCouplingNoTimeLabel::setStartOrder(int order)
1200 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1203 void MEDCouplingNoTimeLabel::setEndOrder(int order)
1205 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1208 void MEDCouplingNoTimeLabel::setStartTimeValue(double time)
1210 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1213 void MEDCouplingNoTimeLabel::setEndTimeValue(double time)
1215 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1218 void MEDCouplingNoTimeLabel::setStartTime(double time, int iteration, int order)
1220 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1223 void MEDCouplingNoTimeLabel::setEndTime(double time, int iteration, int order)
1225 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1228 void MEDCouplingNoTimeLabel::getValueOnTime(int eltId, double time, double *value) const
1230 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1233 void MEDCouplingNoTimeLabel::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1235 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1239 * idem getTinySerializationIntInformation except that it is for multi field fetch
1241 void MEDCouplingNoTimeLabel::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1247 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1249 void MEDCouplingNoTimeLabel::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1252 tinyInfo[0]=_time_tolerance;
1256 * idem finishUnserialization except that it is for multi field fetch
1258 void MEDCouplingNoTimeLabel::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1260 _time_tolerance=tinyInfoD[0];
1263 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy),_tk(other._tk)
1267 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep()
1271 std::string MEDCouplingWithTimeStep::getStringRepr() const
1273 std::ostringstream stream;
1274 stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
1275 stream << "\nTime unit is : \"" << _time_unit << "\"";
1276 return stream.str();
1279 void MEDCouplingWithTimeStep::synchronizeTimeWith(const MEDCouplingMesh *mesh)
1282 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
1284 double val=mesh->getTime(it,order);
1285 _tk.setAllInfo(val,it,order);
1286 std::string tUnit=mesh->getTimeUnit();
1290 void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1292 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1293 tinyInfo.push_back(_tk.getIteration());
1294 tinyInfo.push_back(_tk.getOrder());
1297 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1299 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1300 tinyInfo.push_back(_tk.getTimeValue());
1303 void MEDCouplingWithTimeStep::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1305 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1306 _tk.setTimeValue(tinyInfoD[1]);
1307 _tk.setIteration(tinyInfoI[2]);
1308 _tk.setOrder(tinyInfoI[3]);
1312 * idem getTinySerializationIntInformation except that it is for multi field fetch
1314 void MEDCouplingWithTimeStep::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1317 tinyInfo[0]=_tk.getIteration();
1318 tinyInfo[1]=_tk.getOrder();
1322 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1324 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1327 tinyInfo[0]=_time_tolerance;
1328 tinyInfo[1]=_tk.getTimeValue();
1332 * idem finishUnserialization except that it is for multi field fetch
1334 void MEDCouplingWithTimeStep::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1336 _tk.setIteration(tinyInfoI[0]);
1337 _tk.setOrder(tinyInfoI[1]);
1338 _time_tolerance=tinyInfoD[0];
1339 _tk.setTimeValue(tinyInfoD[1]);
1342 bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1344 if(!MEDCouplingTimeDiscretization::areCompatible(other))
1346 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1350 bool MEDCouplingWithTimeStep::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
1352 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1354 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1357 reason.insert(0,"time discretization of this is ONE_TIME, other has a different time discretization.");
1361 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1363 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1365 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1369 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1371 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1373 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1377 bool MEDCouplingWithTimeStep::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1379 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1381 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1385 bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
1387 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1388 std::ostringstream oss; oss.precision(15);
1391 reason="This has time discretization ONE_TIME, other not.";
1394 if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
1396 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1399 bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
1401 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1404 if(!_tk.isEqual(otherC->_tk,_time_tolerance))
1406 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1409 void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
1411 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1412 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(&other);
1414 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::copyTinyAttrFrom : mismatch of time discretization !");
1415 _tk.copyFrom(otherC->_tk);
1418 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCouplingTimeDiscretization *other) const
1420 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1422 throw INTERP_KERNEL::Exception("WithTimeStep::aggregation on mismatched time discretization !");
1423 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1424 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1425 ret->setArray(arr,0);
1429 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1431 std::vector<const DataArrayDouble *> a(other.size());
1433 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1435 const MEDCouplingWithTimeStep *itC=dynamic_cast<const MEDCouplingWithTimeStep *>(*it);
1437 throw INTERP_KERNEL::Exception("WithTimeStep::aggregate on mismatched time discretization !");
1438 a[i]=itC->getArray();
1440 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1441 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1442 ret->setArray(arr,0);
1446 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::meld(const MEDCouplingTimeDiscretization *other) const
1448 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1450 throw INTERP_KERNEL::Exception("WithTimeStep::meld on mismatched time discretization !");
1451 MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1452 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1453 ret->setArray(arr,0);
1457 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::dot(const MEDCouplingTimeDiscretization *other) const
1459 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1461 throw INTERP_KERNEL::Exception("WithTimeStep::dot on mismatched time discretization !");
1462 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1463 MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1464 ret->setArray(arr,0);
1468 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::crossProduct(const MEDCouplingTimeDiscretization *other) const
1470 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1472 throw INTERP_KERNEL::Exception("WithTimeStep::crossProduct on mismatched time discretization !");
1473 MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1474 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1475 ret->setArray(arr,0);
1479 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::max(const MEDCouplingTimeDiscretization *other) const
1481 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1483 throw INTERP_KERNEL::Exception("WithTimeStep::max on mismatched time discretization !");
1484 MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1485 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1486 ret->setArray(arr,0);
1490 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::min(const MEDCouplingTimeDiscretization *other) const
1492 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1494 throw INTERP_KERNEL::Exception("WithTimeStep::min on mismatched time discretization !");
1495 MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1496 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1497 ret->setArray(arr,0);
1501 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::add(const MEDCouplingTimeDiscretization *other) const
1503 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1505 throw INTERP_KERNEL::Exception("WithTimeStep::add on mismatched time discretization !");
1506 MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1507 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1508 ret->setArray(arr,0);
1510 double tmp3=getStartTime(tmp1,tmp2);
1511 ret->setStartTime(tmp3,tmp1,tmp2);
1515 void MEDCouplingWithTimeStep::addEqual(const MEDCouplingTimeDiscretization *other)
1517 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1519 throw INTERP_KERNEL::Exception("WithTimeStep::addEqual on mismatched time discretization !");
1521 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::addEqual : Data Array is NULL !");
1522 getArray()->addEqual(other->getArray());
1525 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::substract(const MEDCouplingTimeDiscretization *other) const
1527 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1529 throw INTERP_KERNEL::Exception("WithTimeStep::substract on mismatched time discretization !");
1530 MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1531 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1532 ret->setArray(arr,0);
1534 double tmp3=getStartTime(tmp1,tmp2);
1535 ret->setStartTime(tmp3,tmp1,tmp2);
1539 void MEDCouplingWithTimeStep::substractEqual(const MEDCouplingTimeDiscretization *other)
1541 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1543 throw INTERP_KERNEL::Exception("WithTimeStep::substractEqual on mismatched time discretization !");
1545 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::substractEqual : Data Array is NULL !");
1546 getArray()->substractEqual(other->getArray());
1549 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::multiply(const MEDCouplingTimeDiscretization *other) const
1551 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1553 throw INTERP_KERNEL::Exception("WithTimeStep::multiply on mismatched time discretization !");
1554 MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1555 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1556 ret->setArray(arr,0);
1558 double tmp3=getStartTime(tmp1,tmp2);
1559 ret->setStartTime(tmp3,tmp1,tmp2);
1563 void MEDCouplingWithTimeStep::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1565 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1567 throw INTERP_KERNEL::Exception("WithTimeStep::multiplyEqual on mismatched time discretization !");
1569 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::multiplyEqual : Data Array is NULL !");
1570 getArray()->multiplyEqual(other->getArray());
1573 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::divide(const MEDCouplingTimeDiscretization *other) const
1575 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1577 throw INTERP_KERNEL::Exception("WithTimeStep::divide on mismatched time discretization !");
1578 MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1579 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1580 ret->setArray(arr,0);
1582 double tmp3=getStartTime(tmp1,tmp2);
1583 ret->setStartTime(tmp3,tmp1,tmp2);
1587 void MEDCouplingWithTimeStep::divideEqual(const MEDCouplingTimeDiscretization *other)
1589 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1591 throw INTERP_KERNEL::Exception("WithTimeStep::divideEqual on mismatched time discretization !");
1593 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::divideEqual : Data Array is NULL !");
1594 getArray()->divideEqual(other->getArray());
1597 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::pow(const MEDCouplingTimeDiscretization *other) const
1599 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1601 throw INTERP_KERNEL::Exception("WithTimeStep::pow on mismatched time discretization !");
1602 MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
1603 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1604 ret->setArray(arr,0);
1606 double tmp3=getStartTime(tmp1,tmp2);
1607 ret->setStartTime(tmp3,tmp1,tmp2);
1611 void MEDCouplingWithTimeStep::powEqual(const MEDCouplingTimeDiscretization *other)
1613 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1615 throw INTERP_KERNEL::Exception("WithTimeStep::powEqual on mismatched time discretization !");
1617 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::powEqual : Data Array is NULL !");
1618 getArray()->powEqual(other->getArray());
1621 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCopyOrIncrRef(bool deepCopy) const
1623 return new MEDCouplingWithTimeStep(*this,deepCopy);
1626 void MEDCouplingWithTimeStep::checkNoTimePresence() const
1628 throw INTERP_KERNEL::Exception("No time specified on a field defined on one time");
1631 void MEDCouplingWithTimeStep::checkTimePresence(double time) const
1633 _tk.checkTimePresence(time,_time_tolerance);
1636 std::vector< const DataArrayDouble *> MEDCouplingWithTimeStep::getArraysForTime(double time) const
1638 if(std::fabs(time-_tk.getTimeValue())<=_time_tolerance)
1640 std::vector< const DataArrayDouble *> ret(1);
1645 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1648 void MEDCouplingWithTimeStep::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1650 std::copy(vals.begin(),vals.end(),res);
1653 void MEDCouplingWithTimeStep::getValueOnTime(int eltId, double time, double *value) const
1655 if(std::fabs(time-_tk.getTimeValue())<=_time_tolerance)
1657 _array->getTuple(eltId,value);
1659 throw INTERP_KERNEL::Exception("No array existing.");
1661 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1664 void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1666 if(_tk.getIteration()==iteration && _tk.getOrder()==order)
1668 _array->getTuple(eltId,value);
1670 throw INTERP_KERNEL::Exception("No array existing.");
1672 throw INTERP_KERNEL::Exception("No data on this discrete time.");
1675 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval()
1679 void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
1681 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1682 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(&other);
1684 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::copyTinyAttrFrom : mismatch of time discretization !");
1685 _start.copyFrom(otherC->_start);
1686 _end.copyFrom(otherC->_end);
1689 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1691 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1692 tinyInfo.push_back(_start.getIteration());
1693 tinyInfo.push_back(_start.getOrder());
1694 tinyInfo.push_back(_end.getIteration());
1695 tinyInfo.push_back(_end.getOrder());
1698 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1700 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1701 tinyInfo.push_back(_start.getTimeValue());
1702 tinyInfo.push_back(_end.getTimeValue());
1705 void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1707 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1708 _start.setTimeValue(tinyInfoD[1]);
1709 _end.setTimeValue(tinyInfoD[2]);
1710 _start.setIteration(tinyInfoI[2]);
1711 _start.setOrder(tinyInfoI[3]);
1712 _end.setIteration(tinyInfoI[4]);
1713 _end.setOrder(tinyInfoI[5]);
1717 * idem getTinySerializationIntInformation except that it is for multi field fetch
1719 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1722 tinyInfo[0]=_start.getIteration();
1723 tinyInfo[1]=_start.getOrder();
1724 tinyInfo[2]=_end.getIteration();
1725 tinyInfo[3]=_end.getOrder();
1729 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1731 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1734 tinyInfo[0]=_time_tolerance;
1735 tinyInfo[1]=_start.getTimeValue();
1736 tinyInfo[2]=_end.getTimeValue();
1740 * idem finishUnserialization except that it is for multi field fetch
1742 void MEDCouplingConstOnTimeInterval::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1744 _start.setIteration(tinyInfoI[0]);
1745 _start.setOrder(tinyInfoI[1]);
1746 _end.setIteration(tinyInfoI[2]);
1747 _end.setOrder(tinyInfoI[3]);
1748 _time_tolerance=tinyInfoD[0];
1749 _start.setTimeValue(tinyInfoD[1]);
1750 _end.setTimeValue(tinyInfoD[2]);
1753 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCopy):
1754 MEDCouplingTimeDiscretization(other,deepCopy),_start(other._start),_end(other._end)
1758 std::string MEDCouplingConstOnTimeInterval::getStringRepr() const
1760 std::ostringstream stream;
1761 stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n";
1762 stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n";
1763 stream << "\nTime unit is : \"" << _time_unit << "\"";
1764 return stream.str();
1767 void MEDCouplingConstOnTimeInterval::synchronizeTimeWith(const MEDCouplingMesh *mesh)
1770 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
1772 double val=mesh->getTime(it,order);
1773 _start.setAllInfo(val,it,order);
1774 _end.setAllInfo(val,it,order);
1775 std::string tUnit(mesh->getTimeUnit());
1779 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCopyOrIncrRef(bool deepCopy) const
1781 return new MEDCouplingConstOnTimeInterval(*this,deepCopy);
1784 std::vector< const DataArrayDouble *> MEDCouplingConstOnTimeInterval::getArraysForTime(double time) const
1786 if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
1788 std::vector< const DataArrayDouble *> ret(1);
1793 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1796 void MEDCouplingConstOnTimeInterval::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1798 std::copy(vals.begin(),vals.end(),res);
1801 bool MEDCouplingConstOnTimeInterval::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1803 if(!MEDCouplingTimeDiscretization::areCompatible(other))
1805 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1809 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
1811 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1813 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1816 reason.insert(0,"time discretization of this is CONST_ON_TIME_INTERVAL, other has a different time discretization.");
1820 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1822 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1824 const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1828 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1830 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1832 const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1836 bool MEDCouplingConstOnTimeInterval::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1838 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1840 const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1844 bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
1846 const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1847 std::ostringstream oss; oss.precision(15);
1850 reason="This has time discretization CONST_ON_TIME_INTERVAL, other not.";
1853 if(!_start.isEqualIfNotWhy(otherC->_start,_time_tolerance,reason))
1855 if(!_end.isEqualIfNotWhy(otherC->_end,_time_tolerance,reason))
1857 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1860 bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
1862 const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1865 if(!_start.isEqual(otherC->_start,_time_tolerance))
1867 if(!_end.isEqual(otherC->_end,_time_tolerance))
1869 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1872 void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, double *value) const
1874 if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
1876 _array->getTuple(eltId,value);
1878 throw INTERP_KERNEL::Exception("No array existing.");
1880 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1883 void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1885 if(iteration>=_start.getIteration() && iteration<=_end.getIteration())
1887 _array->getTuple(eltId,value);
1889 throw INTERP_KERNEL::Exception("No array existing.");
1891 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1894 void MEDCouplingConstOnTimeInterval::checkNoTimePresence() const
1896 throw INTERP_KERNEL::Exception("No time specified on a field defined as constant on one time interval");
1899 void MEDCouplingConstOnTimeInterval::checkTimePresence(double time) const
1901 if(time<_start.getTimeValue()-_time_tolerance || time>_end.getTimeValue()+_time_tolerance)
1903 std::ostringstream stream;
1904 stream << "The field is defined between times " << _start.getTimeValue() << " and " << _end.getTimeValue() << " worderh tolerance ";
1905 stream << _time_tolerance << " and trying to access on time = " << time;
1906 throw INTERP_KERNEL::Exception(stream.str().c_str());
1910 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const MEDCouplingTimeDiscretization *other) const
1912 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1914 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregation on mismatched time discretization !");
1915 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1916 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1917 ret->setArray(arr,0);
1921 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1923 std::vector<const DataArrayDouble *> a(other.size());
1925 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1927 const MEDCouplingConstOnTimeInterval *itC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(*it);
1929 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregate on mismatched time discretization !");
1930 a[i]=itC->getArray();
1932 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1933 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1934 ret->setArray(arr,0);
1938 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::meld(const MEDCouplingTimeDiscretization *other) const
1940 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1942 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::meld on mismatched time discretization !");
1943 MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1944 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1945 ret->setTimeTolerance(getTimeTolerance());
1946 ret->setArray(arr,0);
1950 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::dot(const MEDCouplingTimeDiscretization *other) const
1952 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1954 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::dot on mismatched time discretization !");
1955 MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1956 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1957 ret->setArray(arr,0);
1961 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::crossProduct(const MEDCouplingTimeDiscretization *other) const
1963 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1965 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::crossProduct on mismatched time discretization !");
1966 MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1967 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1968 ret->setArray(arr,0);
1972 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::max(const MEDCouplingTimeDiscretization *other) const
1974 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1976 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::max on mismatched time discretization !");
1977 MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1978 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1979 ret->setArray(arr,0);
1983 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::min(const MEDCouplingTimeDiscretization *other) const
1985 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1987 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::min on mismatched time discretization !");
1988 MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1989 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1990 ret->setArray(arr,0);
1994 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::add(const MEDCouplingTimeDiscretization *other) const
1996 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1998 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::add on mismatched time discretization !");
1999 MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
2000 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2001 ret->setArray(arr,0);
2003 double tmp3=getStartTime(tmp1,tmp2);
2004 ret->setStartTime(tmp3,tmp1,tmp2);
2005 tmp3=getEndTime(tmp1,tmp2);
2006 ret->setEndTime(tmp3,tmp1,tmp2);
2010 void MEDCouplingConstOnTimeInterval::addEqual(const MEDCouplingTimeDiscretization *other)
2012 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2014 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::addEqual on mismatched time discretization !");
2016 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractaddEqual : Data Array is NULL !");
2017 getArray()->addEqual(other->getArray());
2020 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::substract(const MEDCouplingTimeDiscretization *other) const
2022 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2024 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substract on mismatched time discretization !");
2025 MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
2026 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2027 ret->setArray(arr,0);
2029 double tmp3=getStartTime(tmp1,tmp2);
2030 ret->setStartTime(tmp3,tmp1,tmp2);
2031 tmp3=getEndTime(tmp1,tmp2);
2032 ret->setEndTime(tmp3,tmp1,tmp2);
2036 void MEDCouplingConstOnTimeInterval::substractEqual(const MEDCouplingTimeDiscretization *other)
2038 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2040 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substractEqual on mismatched time discretization !");
2042 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractEqual : Data Array is NULL !");
2043 getArray()->substractEqual(other->getArray());
2046 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::multiply(const MEDCouplingTimeDiscretization *other) const
2048 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2050 throw INTERP_KERNEL::Exception("multiply on mismatched time discretization !");
2051 MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
2052 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2053 ret->setArray(arr,0);
2055 double tmp3=getStartTime(tmp1,tmp2);
2056 ret->setStartTime(tmp3,tmp1,tmp2);
2057 tmp3=getEndTime(tmp1,tmp2);
2058 ret->setEndTime(tmp3,tmp1,tmp2);
2062 void MEDCouplingConstOnTimeInterval::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2064 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2066 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::multiplyEqual on mismatched time discretization !");
2068 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::multiplyEqual : Data Array is NULL !");
2069 getArray()->multiplyEqual(other->getArray());
2072 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::divide(const MEDCouplingTimeDiscretization *other) const
2074 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2076 throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
2077 MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
2078 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2079 ret->setArray(arr,0);
2081 double tmp3=getStartTime(tmp1,tmp2);
2082 ret->setStartTime(tmp3,tmp1,tmp2);
2083 tmp3=getEndTime(tmp1,tmp2);
2084 ret->setEndTime(tmp3,tmp1,tmp2);
2088 void MEDCouplingConstOnTimeInterval::divideEqual(const MEDCouplingTimeDiscretization *other)
2090 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2092 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::divideEqual on mismatched time discretization !");
2094 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::divideEqual : Data Array is NULL !");
2095 getArray()->divideEqual(other->getArray());
2098 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::pow(const MEDCouplingTimeDiscretization *other) const
2100 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2102 throw INTERP_KERNEL::Exception("pow on mismatched time discretization !");
2103 MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
2104 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2105 ret->setArray(arr,0);
2107 double tmp3=getStartTime(tmp1,tmp2);
2108 ret->setStartTime(tmp3,tmp1,tmp2);
2109 tmp3=getEndTime(tmp1,tmp2);
2110 ret->setEndTime(tmp3,tmp1,tmp2);
2114 void MEDCouplingConstOnTimeInterval::powEqual(const MEDCouplingTimeDiscretization *other)
2116 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2118 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::powEqual on mismatched time discretization !");
2120 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::powEqual : Data Array is NULL !");
2121 getArray()->powEqual(other->getArray());
2124 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy),
2125 _start(other._start),_end(other._end)
2127 if(other._end_array)
2128 _end_array=other._end_array->performCopyOrIncrRef(deepCopy);
2133 void MEDCouplingTwoTimeSteps::updateTime() const
2135 MEDCouplingTimeDiscretization::updateTime();
2137 updateTimeWith(*_end_array);
2140 void MEDCouplingTwoTimeSteps::synchronizeTimeWith(const MEDCouplingMesh *mesh)
2143 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
2145 double val=mesh->getTime(it,order);
2146 _start.setAllInfo(val,it,order);
2147 _end.setAllInfo(val,it,order);
2148 std::string tUnit=mesh->getTimeUnit();
2152 std::size_t MEDCouplingTwoTimeSteps::getHeapMemorySizeWithoutChildren() const
2154 return MEDCouplingTimeDiscretization::getHeapMemorySizeWithoutChildren();
2157 std::vector<const BigMemoryObject *> MEDCouplingTwoTimeSteps::getDirectChildrenWithNull() const
2159 std::vector<const BigMemoryObject *> ret(MEDCouplingTimeDiscretization::getDirectChildrenWithNull());
2160 ret.push_back(_end_array);
2164 void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
2166 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
2167 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2169 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::copyTinyAttrFrom : mismatch of time discretization !");
2170 _start.copyFrom(otherC->_start);
2171 _end.copyFrom(otherC->_end);
2174 void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
2176 MEDCouplingTimeDiscretization::copyTinyStringsFrom(other);
2177 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2179 throw INTERP_KERNEL::Exception("Trying to operate copyTinyStringsFrom on different field type (two times//one time) !");
2180 if(_end_array && otherC->_end_array)
2181 _end_array->copyStringInfoFrom(*otherC->_end_array);
2184 const DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray() const
2189 DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray()
2194 void MEDCouplingTwoTimeSteps::checkConsistencyLight() const
2196 MEDCouplingTimeDiscretization::checkConsistencyLight();
2198 throw INTERP_KERNEL::Exception("No end array specified !");
2199 if(_array->getNumberOfComponents()!=_end_array->getNumberOfComponents())
2200 throw INTERP_KERNEL::Exception("The number of components mismatch between the start and the end arrays !");
2201 if(_array->getNumberOfTuples()!=_end_array->getNumberOfTuples())
2202 throw INTERP_KERNEL::Exception("The number of tuples mismatch between the start and the end arrays !");
2205 bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
2207 std::ostringstream oss;
2208 const MEDCouplingTwoTimeSteps *otherC(dynamic_cast<const MEDCouplingTwoTimeSteps *>(other));
2211 reason="This has time discretization LINEAR_TIME, other not.";
2214 if(!_start.isEqualIfNotWhy(otherC->_start,_time_tolerance,reason))
2216 if(!_end.isEqualIfNotWhy(otherC->_end,_time_tolerance,reason))
2218 if(_end_array!=otherC->_end_array)
2219 if(!_end_array->isEqualIfNotWhy(*otherC->_end_array,prec,reason))
2221 reason.insert(0,"end arrays differ for linear time.");
2224 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
2227 bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
2229 const MEDCouplingTwoTimeSteps *otherC(dynamic_cast<const MEDCouplingTwoTimeSteps *>(other));
2232 if(!_start.isEqual(otherC->_start,_time_tolerance))
2234 if(!_end.isEqual(otherC->_end,_time_tolerance))
2236 if(_end_array!=otherC->_end_array)
2237 if(!_end_array->isEqualWithoutConsideringStr(*otherC->_end_array,prec))
2239 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
2242 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_end_array(0)
2246 MEDCouplingTwoTimeSteps::~MEDCouplingTwoTimeSteps()
2249 _end_array->decrRef();
2252 void MEDCouplingTwoTimeSteps::checkNoTimePresence() const
2254 throw INTERP_KERNEL::Exception("The field presents a time to be specified in every access !");
2257 void MEDCouplingTwoTimeSteps::checkTimePresence(double time) const
2259 if(time<_start.getTimeValue()-_time_tolerance || time>_end.getTimeValue()+_time_tolerance)
2261 std::ostringstream stream;
2262 stream << "The field is defined between times " << _start.getTimeValue() << " and " << _end.getTimeValue() << " worderh tolerance ";
2263 stream << _time_tolerance << " and trying to access on time = " << time;
2264 throw INTERP_KERNEL::Exception(stream.str().c_str());
2268 void MEDCouplingTwoTimeSteps::getArrays(std::vector<DataArrayDouble *>& arrays) const
2272 arrays[1]=_end_array;
2275 void MEDCouplingTwoTimeSteps::setEndArray(DataArrayDouble *array, TimeLabel *owner)
2277 if(array!=_end_array)
2280 _end_array->decrRef();
2283 _end_array->incrRef();
2285 owner->declareAsNew();
2289 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
2291 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
2292 tinyInfo.push_back(_start.getIteration());
2293 tinyInfo.push_back(_start.getOrder());
2294 tinyInfo.push_back(_end.getIteration());
2295 tinyInfo.push_back(_end.getOrder());
2298 tinyInfo.push_back(_end_array->getNumberOfTuples());
2299 tinyInfo.push_back(_end_array->getNumberOfComponents());
2303 tinyInfo.push_back(-1);
2304 tinyInfo.push_back(-1);
2308 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
2310 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
2311 tinyInfo.push_back(_start.getTimeValue());
2312 tinyInfo.push_back(_end.getTimeValue());
2315 void MEDCouplingTwoTimeSteps::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
2317 int nbOfCompo=_array->getNumberOfComponents();
2318 for(int i=0;i<nbOfCompo;i++)
2319 tinyInfo.push_back(_array->getInfoOnComponent(i));
2320 for(int i=0;i<nbOfCompo;i++)
2321 tinyInfo.push_back(_end_array->getInfoOnComponent(i));
2324 void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
2330 _end_array->decrRef();
2331 DataArrayDouble *arr=0;
2332 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2334 arr=DataArrayDouble::New();
2335 arr->alloc(tinyInfoI[0],tinyInfoI[1]);
2340 if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2342 arr=DataArrayDouble::New();
2343 arr->alloc(tinyInfoI[6],tinyInfoI[7]);
2349 void MEDCouplingTwoTimeSteps::checkForUnserialization(const std::vector<int>& tinyInfoI, const std::vector<DataArrayDouble *>& arrays)
2351 static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size two !";
2352 if(arrays.size()!=2)
2353 throw INTERP_KERNEL::Exception(MSG);
2357 _end_array->decrRef();
2358 _array=0; _end_array=0;
2359 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2362 throw INTERP_KERNEL::Exception(MSG);
2363 arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
2364 _array=arrays[0]; _array->incrRef();
2366 if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2369 throw INTERP_KERNEL::Exception(MSG);
2370 arrays[1]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
2371 _end_array=arrays[1]; _end_array->incrRef();
2375 void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
2377 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
2378 _start.setTimeValue(tinyInfoD[1]);
2379 _end.setTimeValue(tinyInfoD[2]);
2380 _start.setIteration(tinyInfoI[2]);
2381 _start.setOrder(tinyInfoI[3]);
2382 _end.setIteration(tinyInfoI[4]);
2383 _end.setOrder(tinyInfoI[5]);
2387 * idem getTinySerializationIntInformation except that it is for multi field fetch
2389 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
2392 tinyInfo[0]=_start.getIteration();
2393 tinyInfo[1]=_start.getOrder();
2394 tinyInfo[2]=_end.getIteration();
2395 tinyInfo[3]=_end.getOrder();
2399 * idem getTinySerializationDbleInformation except that it is for multi field fetch
2401 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
2404 tinyInfo[0]=_time_tolerance;
2405 tinyInfo[1]=_start.getTimeValue();
2406 tinyInfo[2]=_end.getTimeValue();
2410 * idem finishUnserialization except that it is for multi field fetch
2412 void MEDCouplingTwoTimeSteps::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
2414 _start.setIteration(tinyInfoI[0]);
2415 _start.setOrder(tinyInfoI[1]);
2416 _end.setIteration(tinyInfoI[2]);
2417 _end.setOrder(tinyInfoI[3]);
2418 _time_tolerance=tinyInfoD[0];
2419 _start.setTimeValue(tinyInfoD[1]);
2420 _end.setTimeValue(tinyInfoD[2]);
2423 std::vector< const DataArrayDouble *> MEDCouplingTwoTimeSteps::getArraysForTime(double time) const
2425 if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
2427 std::vector< const DataArrayDouble *> ret(2);
2433 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2436 void MEDCouplingTwoTimeSteps::setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner)
2438 if(arrays.size()!=2)
2439 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::setArrays : number of arrays must be two.");
2440 setArray(arrays.front(),owner);
2441 setEndArray(arrays.back(),owner);
2444 MEDCouplingLinearTime::MEDCouplingLinearTime(const MEDCouplingLinearTime& other, bool deepCopy):MEDCouplingTwoTimeSteps(other,deepCopy)
2448 MEDCouplingLinearTime::MEDCouplingLinearTime()
2452 std::string MEDCouplingLinearTime::getStringRepr() const
2454 std::ostringstream stream;
2455 stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n";
2456 stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n";
2457 stream << "Time unit is : \"" << _time_unit << "\"";
2458 return stream.str();
2461 void MEDCouplingLinearTime::checkConsistencyLight() const
2463 MEDCouplingTwoTimeSteps::checkConsistencyLight();
2464 if(std::fabs(_start.getTimeValue()-_end.getTimeValue())<_time_tolerance)
2465 throw INTERP_KERNEL::Exception("Start time and end time are equals regarding time tolerance.");
2468 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::performCopyOrIncrRef(bool deepCopy) const
2470 return new MEDCouplingLinearTime(*this,deepCopy);
2473 bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2475 if(!MEDCouplingTimeDiscretization::areCompatible(other))
2477 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2480 if(_end_array==0 && otherC->_end_array==0)
2482 if(_end_array==0 || otherC->_end_array==0)
2484 if(_end_array->getNumberOfComponents()!=otherC->_end_array->getNumberOfComponents())
2489 bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
2491 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
2493 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2496 reason.insert(0,"time discretization of this is LINEAR_TIME, other has a different time discretization.");
2500 bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2502 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
2504 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2508 bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2510 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
2512 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2515 if(_end_array==0 && otherC->_end_array==0)
2517 if(_end_array==0 || otherC->_end_array==0)
2519 int nbC1=_end_array->getNumberOfComponents();
2520 int nbC2=otherC->_end_array->getNumberOfComponents();
2521 if(nbC1!=nbC2 && nbC2!=1)
2526 bool MEDCouplingLinearTime::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
2528 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
2530 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2535 * vals is expected to be of size 2*_array->getNumberOfTuples()==_array->getNumberOfTuples()+_end_array->getNumberOfTuples()
2537 void MEDCouplingLinearTime::getValueForTime(double time, const std::vector<double>& vals, double *res) const
2539 double alpha=(_end.getTimeValue()-time)/(_end.getTimeValue()-_start.getTimeValue());
2540 std::size_t nbComp=vals.size()/2;
2541 std::transform(vals.begin(),vals.begin()+nbComp,res,std::bind2nd(std::multiplies<double>(),alpha));
2542 std::vector<double> tmp(nbComp);
2543 std::transform(vals.begin()+nbComp,vals.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2544 std::transform(tmp.begin(),tmp.end(),res,res,std::plus<double>());
2547 void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value) const
2549 double alpha=(_end.getTimeValue()-time)/(_end.getTimeValue()-_start.getTimeValue());
2552 _array->getTuple(eltId,value);
2554 throw INTERP_KERNEL::Exception("No start array existing.");
2555 nbComp=_array->getNumberOfComponents();
2556 std::transform(value,value+nbComp,value,std::bind2nd(std::multiplies<double>(),alpha));
2557 std::vector<double> tmp(nbComp);
2559 _end_array->getTuple(eltId,&tmp[0]);
2561 throw INTERP_KERNEL::Exception("No end array existing.");
2562 std::transform(tmp.begin(),tmp.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2563 std::transform(tmp.begin(),tmp.end(),value,value,std::plus<double>());
2566 void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
2568 if(iteration==_start.getIteration() && order==_start.getOrder())
2571 _array->getTuple(eltId,value);
2573 throw INTERP_KERNEL::Exception("iteration order match with start time but no start array existing.");
2575 if(iteration==_end.getIteration() && order==_end.getOrder())
2578 _end_array->getTuple(eltId,value);
2580 throw INTERP_KERNEL::Exception("iteration order match with end time but no end array existing.");
2583 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2586 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const MEDCouplingTimeDiscretization *other) const
2588 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2590 throw INTERP_KERNEL::Exception("LinearTime::aggregation on mismatched time discretization !");
2591 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Aggregate(getArray(),other->getArray());
2592 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Aggregate(getEndArray(),other->getEndArray());
2593 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2594 ret->setArray(arr1,0);
2595 ret->setEndArray(arr2,0);
2599 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
2601 std::vector<const DataArrayDouble *> a(other.size());
2602 std::vector<const DataArrayDouble *> b(other.size());
2604 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
2606 const MEDCouplingLinearTime *itC=dynamic_cast<const MEDCouplingLinearTime *>(*it);
2608 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::aggregate on mismatched time discretization !");
2609 a[i]=itC->getArray();
2610 b[i]=itC->getEndArray();
2612 MCAuto<DataArrayDouble> arr(DataArrayDouble::Aggregate(a)),arr2(DataArrayDouble::Aggregate(b));
2613 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2614 ret->setArray(arr,0);
2615 ret->setEndArray(arr2,0);
2619 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::meld(const MEDCouplingTimeDiscretization *other) const
2621 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2623 throw INTERP_KERNEL::Exception("LinearTime::meld on mismatched time discretization !");
2624 MCAuto<DataArrayDouble> arr1(DataArrayDouble::Meld(getArray(),other->getArray())),arr2(DataArrayDouble::Meld(getEndArray(),other->getEndArray()));
2625 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2626 ret->setTimeTolerance(getTimeTolerance());
2627 ret->setArray(arr1,0);
2628 ret->setEndArray(arr2,0);
2632 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeDiscretization *other) const
2634 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2636 throw INTERP_KERNEL::Exception("LinearTime::dot on mismatched time discretization !");
2637 MCAuto<DataArrayDouble> arr1(DataArrayDouble::Dot(getArray(),other->getArray())),arr2(DataArrayDouble::Dot(getEndArray(),other->getEndArray()));
2638 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2639 ret->setArray(arr1,0);
2640 ret->setEndArray(arr2,0);
2644 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::crossProduct(const MEDCouplingTimeDiscretization *other) const
2646 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2648 throw INTERP_KERNEL::Exception("LinearTime::crossProduct on mismatched time discretization !");
2649 MCAuto<DataArrayDouble> arr1(DataArrayDouble::CrossProduct(getArray(),other->getArray())),arr2(DataArrayDouble::CrossProduct(getEndArray(),other->getEndArray()));
2650 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2651 ret->setArray(arr1,0);
2652 ret->setEndArray(arr2,0);
2656 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::max(const MEDCouplingTimeDiscretization *other) const
2658 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2660 throw INTERP_KERNEL::Exception("LinearTime::max on mismatched time discretization !");
2661 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2662 MCAuto<DataArrayDouble> arr1(DataArrayDouble::Max(getArray(),other->getArray())),arr2(DataArrayDouble::Max(getEndArray(),other->getEndArray()));
2663 ret->setArray(arr1,0);
2664 ret->setEndArray(arr2,0);
2668 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::min(const MEDCouplingTimeDiscretization *other) const
2670 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2672 throw INTERP_KERNEL::Exception("LinearTime::min on mismatched time discretization !");
2673 MCAuto<DataArrayDouble> arr1(DataArrayDouble::Min(getArray(),other->getArray())),arr2(DataArrayDouble::Min(getEndArray(),other->getEndArray()));
2674 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2675 ret->setArray(arr1,0);
2676 ret->setEndArray(arr2,0);
2680 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::add(const MEDCouplingTimeDiscretization *other) const
2682 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2684 throw INTERP_KERNEL::Exception("LinearTime::add on mismatched time discretization !");
2685 MCAuto<DataArrayDouble> arr1(DataArrayDouble::Add(getArray(),other->getArray())),arr2(DataArrayDouble::Add(getEndArray(),other->getEndArray()));
2686 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2687 ret->setArray(arr1,0);
2688 ret->setEndArray(arr2,0);
2692 void MEDCouplingLinearTime::addEqual(const MEDCouplingTimeDiscretization *other)
2694 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2696 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2698 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array is NULL !");
2700 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array (end) is NULL !");
2701 getArray()->addEqual(other->getArray());
2702 getEndArray()->addEqual(other->getEndArray());
2705 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::substract(const MEDCouplingTimeDiscretization *other) const
2707 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2709 throw INTERP_KERNEL::Exception("LinearTime::substract on mismatched time discretization !");
2710 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Substract(getArray(),other->getArray());
2711 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Substract(getEndArray(),other->getEndArray());
2712 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2713 ret->setArray(arr1,0);
2714 ret->setEndArray(arr2,0);
2718 void MEDCouplingLinearTime::substractEqual(const MEDCouplingTimeDiscretization *other)
2720 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2722 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2724 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array is NULL !");
2726 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array (end) is NULL !");
2727 getArray()->substractEqual(other->getArray());
2728 getEndArray()->substractEqual(other->getEndArray());
2731 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::multiply(const MEDCouplingTimeDiscretization *other) const
2733 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2735 throw INTERP_KERNEL::Exception("LinearTime::multiply on mismatched time discretization !");
2736 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Multiply(getArray(),other->getArray());
2737 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Multiply(getEndArray(),other->getEndArray());
2738 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2739 ret->setArray(arr1,0);
2740 ret->setEndArray(arr2,0);
2744 void MEDCouplingLinearTime::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2746 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2748 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2750 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array is NULL !");
2752 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array (end) is NULL !");
2753 getArray()->multiplyEqual(other->getArray());
2754 getEndArray()->multiplyEqual(other->getEndArray());
2757 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::divide(const MEDCouplingTimeDiscretization *other) const
2759 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2761 throw INTERP_KERNEL::Exception("LinearTime::divide on mismatched time discretization !");
2762 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Divide(getArray(),other->getArray());
2763 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Divide(getEndArray(),other->getEndArray());
2764 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2765 ret->setArray(arr1,0);
2766 ret->setEndArray(arr2,0);
2770 void MEDCouplingLinearTime::divideEqual(const MEDCouplingTimeDiscretization *other)
2772 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2774 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2776 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array is NULL !");
2778 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array (end) is NULL !");
2779 getArray()->divideEqual(other->getArray());
2780 getEndArray()->divideEqual(other->getEndArray());
2783 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::pow(const MEDCouplingTimeDiscretization *other) const
2785 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2787 throw INTERP_KERNEL::Exception("LinearTime::pow on mismatched time discretization !");
2788 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Pow(getArray(),other->getArray());
2789 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Pow(getEndArray(),other->getEndArray());
2790 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2791 ret->setArray(arr1,0);
2792 ret->setEndArray(arr2,0);
2796 void MEDCouplingLinearTime::powEqual(const MEDCouplingTimeDiscretization *other)
2798 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2800 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2802 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array is NULL !");
2804 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array (end) is NULL !");
2805 getArray()->powEqual(other->getArray());
2806 getEndArray()->powEqual(other->getEndArray());