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 MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
85 if(!areStrictlyCompatible(other,reason))
87 if(_array==other->_array)
89 return _array->isEqualIfNotWhy(*other->_array,prec,reason);
92 bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
95 return isEqualIfNotWhy(other,prec,reason);
98 bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
101 if(!areStrictlyCompatible(other,tmp))
103 if(_array==other->_array)
105 return _array->isEqualWithoutConsideringStr(*other->_array,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 const DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray() const
189 throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
192 DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray()
194 throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
197 void MEDCouplingTimeDiscretization::setEndArray(DataArrayDouble *array, TimeLabel *owner)
199 throw INTERP_KERNEL::Exception("setEndArray not available for this type of time discretization !");
202 void MEDCouplingTimeDiscretization::setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner)
205 throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretization::setArrays : number of arrays must be one.");
206 setArray(arrays.back(),owner);
209 void MEDCouplingTimeDiscretization::getArrays(std::vector<DataArrayDouble *>& arrays) const
215 bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const
218 double time1=getEndTime(iteration,order)-_time_tolerance;
219 double time2=other->getStartTime(iteration,order)+other->getTimeTolerance();
223 bool MEDCouplingTimeDiscretization::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const
226 double time1=getEndTime(iteration,order)+_time_tolerance;
227 double time2=other->getStartTime(iteration,order)-other->getTimeTolerance();
231 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedProduct() const
233 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
234 ret->setTimeUnit(getTimeUnit());
235 std::vector<DataArrayDouble *> arrays;
237 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
238 for(std::size_t j=0;j<arrays.size();j++)
241 arrays2[j]=arrays[j]->doublyContractedProduct();
245 std::vector<DataArrayDouble *> arrays3(arrays.size());
246 for(std::size_t j=0;j<arrays.size();j++)
247 arrays3[j]=arrays2[j];
248 ret->setArrays(arrays3,0);
252 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() const
254 std::vector<DataArrayDouble *> arrays;
256 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
257 for(std::size_t j=0;j<arrays.size();j++)
260 arrays2[j]=arrays[j]->determinant();
264 std::vector<DataArrayDouble *> arrays3(arrays.size());
265 for(std::size_t j=0;j<arrays.size();j++)
266 arrays3[j]=arrays2[j];
267 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
268 ret->setTimeUnit(getTimeUnit());
269 ret->setArrays(arrays3,0);
273 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() const
275 std::vector<DataArrayDouble *> arrays;
277 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
278 for(std::size_t j=0;j<arrays.size();j++)
281 arrays2[j]=arrays[j]->eigenValues();
285 std::vector<DataArrayDouble *> arrays3(arrays.size());
286 for(std::size_t j=0;j<arrays.size();j++)
287 arrays3[j]=arrays2[j];
288 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
289 ret->setTimeUnit(getTimeUnit());
290 ret->setArrays(arrays3,0);
294 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() const
296 std::vector<DataArrayDouble *> arrays;
298 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
299 for(std::size_t j=0;j<arrays.size();j++)
302 arrays2[j]=arrays[j]->eigenVectors();
306 std::vector<DataArrayDouble *> arrays3(arrays.size());
307 for(std::size_t j=0;j<arrays.size();j++)
308 arrays3[j]=arrays2[j];
309 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
310 ret->setTimeUnit(getTimeUnit());
311 ret->setArrays(arrays3,0);
315 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const
317 std::vector<DataArrayDouble *> arrays;
319 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
320 for(std::size_t j=0;j<arrays.size();j++)
323 arrays2[j]=arrays[j]->inverse();
327 std::vector<DataArrayDouble *> arrays3(arrays.size());
328 for(std::size_t j=0;j<arrays.size();j++)
329 arrays3[j]=arrays2[j];
330 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
331 ret->setTimeUnit(getTimeUnit());
332 ret->setArrays(arrays3,0);
336 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const
338 std::vector<DataArrayDouble *> arrays;
340 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
341 for(std::size_t j=0;j<arrays.size();j++)
344 arrays2[j]=arrays[j]->trace();
348 std::vector<DataArrayDouble *> arrays3(arrays.size());
349 for(std::size_t j=0;j<arrays.size();j++)
350 arrays3[j]=arrays2[j];
351 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
352 ret->setTimeUnit(getTimeUnit());
353 ret->setArrays(arrays3,0);
357 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const
359 std::vector<DataArrayDouble *> arrays;
361 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
362 for(std::size_t j=0;j<arrays.size();j++)
365 arrays2[j]=arrays[j]->deviator();
369 std::vector<DataArrayDouble *> arrays3(arrays.size());
370 for(std::size_t j=0;j<arrays.size();j++)
371 arrays3[j]=arrays2[j];
372 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
373 ret->setTimeUnit(getTimeUnit());
374 ret->setArrays(arrays3,0);
378 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const
380 std::vector<DataArrayDouble *> arrays;
382 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
383 for(std::size_t j=0;j<arrays.size();j++)
386 arrays2[j]=arrays[j]->magnitude();
390 std::vector<DataArrayDouble *> arrays3(arrays.size());
391 for(std::size_t j=0;j<arrays.size();j++)
392 arrays3[j]=arrays2[j];
393 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
394 ret->setTimeUnit(getTimeUnit());
395 ret->setArrays(arrays3,0);
399 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::negate() const
401 std::vector<DataArrayDouble *> arrays;
403 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
404 for(std::size_t j=0;j<arrays.size();j++)
407 arrays2[j]=arrays[j]->negate();
411 std::vector<DataArrayDouble *> arrays3(arrays.size());
412 for(std::size_t j=0;j<arrays.size();j++)
413 arrays3[j]=arrays2[j];
414 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
415 ret->setTimeUnit(getTimeUnit());
416 ret->setArrays(arrays3,0);
420 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() const
422 std::vector<DataArrayDouble *> arrays;
424 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
425 for(std::size_t j=0;j<arrays.size();j++)
428 arrays2[j]=arrays[j]->maxPerTuple();
432 std::vector<DataArrayDouble *> arrays3(arrays.size());
433 for(std::size_t j=0;j<arrays.size();j++)
434 arrays3[j]=arrays2[j];
435 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
436 ret->setTimeUnit(getTimeUnit());
437 ret->setArrays(arrays3,0);
441 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedComponents(const std::vector<int>& compoIds) const
443 std::vector<DataArrayDouble *> arrays;
445 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
446 for(std::size_t j=0;j<arrays.size();j++)
449 arrays2[j]=static_cast<DataArrayDouble *>(arrays[j]->keepSelectedComponents(compoIds));
453 std::vector<DataArrayDouble *> arrays3(arrays.size());
454 for(std::size_t j=0;j<arrays.size();j++)
455 arrays3[j]=arrays2[j];
456 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
457 ret->setTimeUnit(getTimeUnit());
458 ret->setArrays(arrays3,0);
462 void MEDCouplingTimeDiscretization::setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector<int>& compoIds)
464 std::vector<DataArrayDouble *> arrays1,arrays2;
466 other->getArrays(arrays2);
467 if(arrays1.size()!=arrays2.size())
468 throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : number of arrays mismatch !");
469 for(std::size_t i=0;i<arrays1.size();i++)
471 if(arrays1[i]!=0 && arrays2[i]!=0)
472 arrays1[i]->setSelectedComponents(arrays2[i],compoIds);
473 else if(arrays1[i]!=0 || arrays2[i]!=0)
474 throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : some time array in correspondance are not defined symetrically !");
478 void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double dftValue)
480 std::vector<DataArrayDouble *> arrays;
482 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
483 for(std::size_t j=0;j<arrays.size();j++)
486 arrays2[j]=arrays[j]->changeNbOfComponents(newNbOfComp,dftValue);
490 std::vector<DataArrayDouble *> arrays3(arrays.size());
491 for(std::size_t j=0;j<arrays.size();j++)
492 arrays3[j]=arrays2[j];
493 setArrays(arrays3,0);
496 void MEDCouplingTimeDiscretization::sortPerTuple(bool asc)
498 std::vector<DataArrayDouble *> arrays;
500 for(std::size_t j=0;j<arrays.size();j++)
503 arrays[j]->sortPerTuple(asc);
507 void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, int nbOfCompo, double value)
509 std::vector<DataArrayDouble *> arrays;
511 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
512 for(std::size_t j=0;j<arrays.size();j++)
516 arrays2[j]=arrays[j]->changeNbOfComponents(nbOfCompo,value);
517 arrays2[j]->fillWithValue(value);
521 arrays2[j]=DataArrayDouble::New();
522 arrays2[j]->alloc(nbOfTuple,nbOfCompo);
523 arrays2[j]->fillWithValue(value);
526 std::vector<DataArrayDouble *> arrays3(arrays.size());
527 for(std::size_t j=0;j<arrays.size();j++)
528 arrays3[j]=arrays2[j];
529 setArrays(arrays3,0);
532 void MEDCouplingTimeDiscretization::setOrCreateUniformValueOnAllComponents(int nbOfTuple, double value)
534 std::vector<DataArrayDouble *> arrays;
536 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
538 for(std::size_t j=0;j<arrays.size();j++)
542 arrays2[j]=arrays[j]; arrays2[j]->incrRef();
543 arrays2[j]->fillWithValue(value);
548 arrays2[j]=DataArrayDouble::New();
549 arrays2[j]->alloc(nbOfTuple,1);
550 arrays2[j]->fillWithValue(value);
555 std::vector<DataArrayDouble *> arrays3(arrays.size());
556 for(std::size_t j=0;j<arrays.size();j++)
557 arrays3[j]=arrays2[j];
558 setArrays(arrays3,0);
562 void MEDCouplingTimeDiscretization::applyLin(double a, double b, int compoId)
564 std::vector<DataArrayDouble *> arrays;
566 for(std::size_t j=0;j<arrays.size();j++)
569 arrays[j]->applyLin(a,b,compoId);
573 void MEDCouplingTimeDiscretization::applyLin(double a, double b)
575 std::vector<DataArrayDouble *> arrays;
577 for(std::size_t j=0;j<arrays.size();j++)
580 arrays[j]->applyLin(a,b);
584 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate func)
586 std::vector<DataArrayDouble *> arrays;
588 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
589 for(std::size_t j=0;j<arrays.size();j++)
592 arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
596 std::vector<DataArrayDouble *> arrays3(arrays.size());
597 for(std::size_t j=0;j<arrays.size();j++)
598 arrays3[j]=arrays2[j];
599 setArrays(arrays3,0);
602 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const std::string& func)
604 std::vector<DataArrayDouble *> arrays;
606 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
607 for(std::size_t j=0;j<arrays.size();j++)
610 arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
614 std::vector<DataArrayDouble *> arrays3(arrays.size());
615 for(std::size_t j=0;j<arrays.size();j++)
616 arrays3[j]=arrays2[j];
617 setArrays(arrays3,0);
620 void MEDCouplingTimeDiscretization::applyFuncCompo(int nbOfComp, const std::string& func)
622 std::vector<DataArrayDouble *> arrays;
624 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
625 for(std::size_t j=0;j<arrays.size();j++)
628 arrays2[j]=arrays[j]->applyFuncCompo(nbOfComp,func);
632 std::vector<DataArrayDouble *> arrays3(arrays.size());
633 for(std::size_t j=0;j<arrays.size();j++)
634 arrays3[j]=arrays2[j];
635 setArrays(arrays3,0);
638 void MEDCouplingTimeDiscretization::applyFuncNamedCompo(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
640 std::vector<DataArrayDouble *> arrays;
642 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
643 for(std::size_t j=0;j<arrays.size();j++)
646 arrays2[j]=arrays[j]->applyFuncNamedCompo(nbOfComp,varsOrder,func);
650 std::vector<DataArrayDouble *> arrays3(arrays.size());
651 for(std::size_t j=0;j<arrays.size();j++)
652 arrays3[j]=arrays2[j];
653 setArrays(arrays3,0);
656 void MEDCouplingTimeDiscretization::applyFunc(const std::string& func)
658 std::vector<DataArrayDouble *> arrays;
660 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
661 for(std::size_t j=0;j<arrays.size();j++)
664 arrays2[j]=arrays[j]->applyFunc(func);
668 std::vector<DataArrayDouble *> arrays3(arrays.size());
669 for(std::size_t j=0;j<arrays.size();j++)
670 arrays3[j]=arrays2[j];
671 setArrays(arrays3,0);
674 void MEDCouplingTimeDiscretization::applyFuncFast32(const std::string& func)
676 std::vector<DataArrayDouble *> arrays;
678 for(std::size_t j=0;j<arrays.size();j++)
681 arrays[j]->applyFuncFast32(func);
685 void MEDCouplingTimeDiscretization::applyFuncFast64(const std::string& func)
687 std::vector<DataArrayDouble *> arrays;
689 for(std::size_t j=0;j<arrays.size();j++)
692 arrays[j]->applyFuncFast64(func);
696 void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, FunctionToEvaluate func)
698 std::vector<DataArrayDouble *> arrays;
700 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
701 for(std::size_t j=0;j<arrays.size();j++)
702 arrays2[j]=loc->applyFunc(nbOfComp,func);
703 std::vector<DataArrayDouble *> arrays3(arrays.size());
704 for(std::size_t j=0;j<arrays.size();j++)
705 arrays3[j]=arrays2[j];
706 setArrays(arrays3,0);
709 void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, const std::string& func)
711 std::vector<DataArrayDouble *> arrays;
713 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
714 for(std::size_t j=0;j<arrays.size();j++)
715 arrays2[j]=loc->applyFunc(nbOfComp,func);
716 std::vector<DataArrayDouble *> arrays3(arrays.size());
717 for(std::size_t j=0;j<arrays.size();j++)
718 arrays3[j]=arrays2[j];
719 setArrays(arrays3,0);
722 void MEDCouplingTimeDiscretization::fillFromAnalyticCompo(const DataArrayDouble *loc, int nbOfComp, const std::string& func)
724 std::vector<DataArrayDouble *> arrays;
726 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
727 for(std::size_t j=0;j<arrays.size();j++)
728 arrays2[j]=loc->applyFuncCompo(nbOfComp,func);
729 std::vector<DataArrayDouble *> arrays3(arrays.size());
730 for(std::size_t j=0;j<arrays.size();j++)
731 arrays3[j]=arrays2[j];
732 setArrays(arrays3,0);
735 void MEDCouplingTimeDiscretization::fillFromAnalyticNamedCompo(const DataArrayDouble *loc, int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
737 std::vector<DataArrayDouble *> arrays;
739 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
740 for(std::size_t j=0;j<arrays.size();j++)
741 arrays2[j]=loc->applyFuncNamedCompo(nbOfComp,varsOrder,func);
742 std::vector<DataArrayDouble *> arrays3(arrays.size());
743 for(std::size_t j=0;j<arrays.size();j++)
744 arrays3[j]=arrays2[j];
745 setArrays(arrays3,0);
748 ////////////////////////
750 bool MEDCouplingTimeKeeper::isEqualIfNotWhy(const MEDCouplingTimeKeeper& other, double prec, std::string& reason) const
752 std::ostringstream oss;
753 if(_iteration!=other._iteration)
755 oss << "iterations differ. this iteration=" << _iteration << " other iteration=" << other._iteration;
759 if(_order!=other._order)
761 oss << "orders differ. this order=" << _order << " other order=" << other._order;
765 if(std::fabs(_time-other._time)>prec)
767 oss << "times differ. this time=" << _time << " other time=" << other._time;
774 bool MEDCouplingTimeKeeper::isEqual(const MEDCouplingTimeKeeper& other, double prec) const
776 if(_iteration!=other._iteration)
778 if(_order!=other._order)
780 if(std::fabs(_time-other._time)>prec)
785 void MEDCouplingTimeKeeper::copyFrom(const MEDCouplingTimeKeeper& other)
788 _iteration=other._iteration;
792 void MEDCouplingTimeKeeper::checkTimePresence(double time, double eps) const
794 if(std::fabs(time-_time)>eps)
796 std::ostringstream stream;
797 stream << "The field is defined on time " << _time << " with eps=" << eps << " and asking time = " << time << " !";
798 throw INTERP_KERNEL::Exception(stream.str().c_str());
802 ////////////////////////
804 MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt()
808 MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate<int>(other,deepCopy)
812 std::string MEDCouplingTimeDiscretizationInt::getStringRepr() const
814 std::ostringstream stream;
815 stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
816 stream << "\nTime unit is : \"" << _time_unit << "\"";
820 MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::performCopyOrIncrRef(bool deepCopy) const
822 return new MEDCouplingTimeDiscretizationInt(*this,deepCopy);
825 MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::New(TypeOfTimeDiscretization type)
829 case MEDCouplingTimeDiscretizationInt::DISCRETIZATION:
830 return new MEDCouplingTimeDiscretizationInt;
832 throw INTERP_KERNEL::Exception("Time discretization not implemented yet for intergers !");
837 ////////////////////////
839 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel()
843 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretization& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy)
847 std::string MEDCouplingNoTimeLabel::getStringRepr() const
849 std::ostringstream stream;
851 stream << "\nTime unit is : \"" << _time_unit << "\"";
855 void MEDCouplingNoTimeLabel::synchronizeTimeWith(const MEDCouplingMesh *mesh)
857 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::synchronizeTimeWith : impossible to synchronize time with a MEDCouplingMesh because the time discretization is incompatible with it !");
860 bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
862 if(!MEDCouplingTimeDiscretization::areCompatible(other))
864 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
868 bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
870 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
872 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
875 reason.insert(0,"time discretization of this is NO_TIME, other has a different time discretization.");
879 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
881 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
883 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
887 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
889 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
891 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
895 bool MEDCouplingNoTimeLabel::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
897 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
899 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
903 bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
905 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
908 reason="This has time discretization NO_TIME, other not.";
911 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
914 bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
916 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
919 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
922 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCouplingTimeDiscretization *other) const
924 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
926 throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !");
927 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
928 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
929 ret->setArray(arr,0);
933 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
935 std::vector<const DataArrayDouble *> a(other.size());
937 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
939 const MEDCouplingNoTimeLabel *itC=dynamic_cast<const MEDCouplingNoTimeLabel *>(*it);
941 throw INTERP_KERNEL::Exception("NoTimeLabel::aggregate on mismatched time discretization !");
942 a[i]=itC->getArray();
944 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
945 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
946 ret->setArray(arr,0);
950 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::meld(const MEDCouplingTimeDiscretization *other) const
952 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
954 throw INTERP_KERNEL::Exception("NoTimeLabel::meld on mismatched time discretization !");
955 MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
956 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
957 ret->setTimeTolerance(getTimeTolerance());
958 ret->setArray(arr,0);
962 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::dot(const MEDCouplingTimeDiscretization *other) const
964 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
966 throw INTERP_KERNEL::Exception("NoTimeLabel::dot on mismatched time discretization !");
967 MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
968 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
969 ret->setArray(arr,0);
973 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::crossProduct(const MEDCouplingTimeDiscretization *other) const
975 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
977 throw INTERP_KERNEL::Exception("NoTimeLabel::crossProduct on mismatched time discretization !");
978 MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
979 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
980 ret->setArray(arr,0);
984 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::max(const MEDCouplingTimeDiscretization *other) const
986 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
988 throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
989 MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
990 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
991 ret->setArray(arr,0);
995 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::min(const MEDCouplingTimeDiscretization *other) const
997 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
999 throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
1000 MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1001 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1002 ret->setArray(arr,0);
1006 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::add(const MEDCouplingTimeDiscretization *other) const
1008 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1010 throw INTERP_KERNEL::Exception("NoTimeLabel::add on mismatched time discretization !");
1011 MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1012 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1013 ret->setArray(arr,0);
1017 void MEDCouplingNoTimeLabel::addEqual(const MEDCouplingTimeDiscretization *other)
1019 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1021 throw INTERP_KERNEL::Exception("NoTimeLabel::addEqual on mismatched time discretization !");
1023 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::addEqual : Data Array is NULL !");
1024 getArray()->addEqual(other->getArray());
1027 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::substract(const MEDCouplingTimeDiscretization *other) const
1029 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1031 throw INTERP_KERNEL::Exception("NoTimeLabel::substract on mismatched time discretization !");
1033 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substract : Data Array is NULL !");
1034 MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1035 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1036 ret->setArray(arr,0);
1040 void MEDCouplingNoTimeLabel::substractEqual(const MEDCouplingTimeDiscretization *other)
1042 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1044 throw INTERP_KERNEL::Exception("NoTimeLabel::substractEqual on mismatched time discretization !");
1046 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substractEqual : Data Array is NULL !");
1047 getArray()->substractEqual(other->getArray());
1050 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::multiply(const MEDCouplingTimeDiscretization *other) const
1052 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1054 throw INTERP_KERNEL::Exception("NoTimeLabel::multiply on mismatched time discretization !");
1055 MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1056 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1057 ret->setArray(arr,0);
1061 void MEDCouplingNoTimeLabel::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1063 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1065 throw INTERP_KERNEL::Exception("NoTimeLabel::multiplyEqual on mismatched time discretization !");
1067 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::multiplyEqual : Data Array is NULL !");
1068 getArray()->multiplyEqual(other->getArray());
1071 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::divide(const MEDCouplingTimeDiscretization *other) const
1073 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1075 throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
1076 MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1077 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1078 ret->setArray(arr,0);
1082 void MEDCouplingNoTimeLabel::divideEqual(const MEDCouplingTimeDiscretization *other)
1084 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1086 throw INTERP_KERNEL::Exception("NoTimeLabel::divideEqual on mismatched time discretization !");
1088 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::divideEqual : Data Array is NULL !");
1089 getArray()->divideEqual(other->getArray());
1092 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::pow(const MEDCouplingTimeDiscretization *other) const
1094 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1096 throw INTERP_KERNEL::Exception("pow on mismatched time discretization !");
1097 MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
1098 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1099 ret->setArray(arr,0);
1103 void MEDCouplingNoTimeLabel::powEqual(const MEDCouplingTimeDiscretization *other)
1105 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1107 throw INTERP_KERNEL::Exception("NoTimeLabel::powEqual on mismatched time discretization !");
1109 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::powEqual : Data Array is NULL !");
1110 getArray()->powEqual(other->getArray());
1113 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCopyOrIncrRef(bool deepCopy) const
1115 return new MEDCouplingNoTimeLabel(*this,deepCopy);
1118 void MEDCouplingNoTimeLabel::checkTimePresence(double time) const
1120 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1123 std::vector< const DataArrayDouble *> MEDCouplingNoTimeLabel::getArraysForTime(double time) const
1125 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1128 void MEDCouplingNoTimeLabel::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1130 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1133 bool MEDCouplingNoTimeLabel::isBefore(const MEDCouplingTimeDiscretization *other) const
1135 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1138 bool MEDCouplingNoTimeLabel::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const
1140 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1143 double MEDCouplingNoTimeLabel::getStartTime(int& iteration, int& order) const
1145 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1148 double MEDCouplingNoTimeLabel::getEndTime(int& iteration, int& order) const
1150 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1153 void MEDCouplingNoTimeLabel::setStartIteration(int it)
1155 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1158 void MEDCouplingNoTimeLabel::setEndIteration(int it)
1160 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1163 void MEDCouplingNoTimeLabel::setStartOrder(int order)
1165 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1168 void MEDCouplingNoTimeLabel::setEndOrder(int order)
1170 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1173 void MEDCouplingNoTimeLabel::setStartTimeValue(double time)
1175 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1178 void MEDCouplingNoTimeLabel::setEndTimeValue(double time)
1180 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1183 void MEDCouplingNoTimeLabel::setStartTime(double time, int iteration, int order)
1185 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1188 void MEDCouplingNoTimeLabel::setEndTime(double time, int iteration, int order)
1190 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1193 void MEDCouplingNoTimeLabel::getValueOnTime(int eltId, double time, double *value) const
1195 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1198 void MEDCouplingNoTimeLabel::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1200 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1204 * idem getTinySerializationIntInformation except that it is for multi field fetch
1206 void MEDCouplingNoTimeLabel::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1212 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1214 void MEDCouplingNoTimeLabel::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1217 tinyInfo[0]=_time_tolerance;
1221 * idem finishUnserialization except that it is for multi field fetch
1223 void MEDCouplingNoTimeLabel::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1225 _time_tolerance=tinyInfoD[0];
1228 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy),_tk(other._tk)
1232 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep()
1236 std::string MEDCouplingWithTimeStep::getStringRepr() const
1238 std::ostringstream stream;
1239 stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
1240 stream << "\nTime unit is : \"" << _time_unit << "\"";
1241 return stream.str();
1244 void MEDCouplingWithTimeStep::synchronizeTimeWith(const MEDCouplingMesh *mesh)
1247 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
1249 double val=mesh->getTime(it,order);
1250 _tk.setAllInfo(val,it,order);
1251 std::string tUnit=mesh->getTimeUnit();
1255 void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1257 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1258 tinyInfo.push_back(_tk.getIteration());
1259 tinyInfo.push_back(_tk.getOrder());
1262 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1264 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1265 tinyInfo.push_back(_tk.getTimeValue());
1268 void MEDCouplingWithTimeStep::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1270 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1271 _tk.setTimeValue(tinyInfoD[1]);
1272 _tk.setIteration(tinyInfoI[2]);
1273 _tk.setOrder(tinyInfoI[3]);
1277 * idem getTinySerializationIntInformation except that it is for multi field fetch
1279 void MEDCouplingWithTimeStep::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1282 tinyInfo[0]=_tk.getIteration();
1283 tinyInfo[1]=_tk.getOrder();
1287 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1289 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1292 tinyInfo[0]=_time_tolerance;
1293 tinyInfo[1]=_tk.getTimeValue();
1297 * idem finishUnserialization except that it is for multi field fetch
1299 void MEDCouplingWithTimeStep::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1301 _tk.setIteration(tinyInfoI[0]);
1302 _tk.setOrder(tinyInfoI[1]);
1303 _time_tolerance=tinyInfoD[0];
1304 _tk.setTimeValue(tinyInfoD[1]);
1307 bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1309 if(!MEDCouplingTimeDiscretization::areCompatible(other))
1311 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1315 bool MEDCouplingWithTimeStep::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
1317 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1319 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1322 reason.insert(0,"time discretization of this is ONE_TIME, other has a different time discretization.");
1326 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1328 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1330 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1334 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1336 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1338 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1342 bool MEDCouplingWithTimeStep::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1344 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1346 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1350 bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
1352 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1353 std::ostringstream oss; oss.precision(15);
1356 reason="This has time discretization ONE_TIME, other not.";
1359 if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
1361 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1364 bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
1366 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1369 if(!_tk.isEqual(otherC->_tk,_time_tolerance))
1371 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1374 void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
1376 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1377 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(&other);
1379 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::copyTinyAttrFrom : mismatch of time discretization !");
1380 _tk.copyFrom(otherC->_tk);
1383 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCouplingTimeDiscretization *other) const
1385 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1387 throw INTERP_KERNEL::Exception("WithTimeStep::aggregation on mismatched time discretization !");
1388 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1389 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1390 ret->setArray(arr,0);
1394 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1396 std::vector<const DataArrayDouble *> a(other.size());
1398 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1400 const MEDCouplingWithTimeStep *itC=dynamic_cast<const MEDCouplingWithTimeStep *>(*it);
1402 throw INTERP_KERNEL::Exception("WithTimeStep::aggregate on mismatched time discretization !");
1403 a[i]=itC->getArray();
1405 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1406 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1407 ret->setArray(arr,0);
1411 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::meld(const MEDCouplingTimeDiscretization *other) const
1413 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1415 throw INTERP_KERNEL::Exception("WithTimeStep::meld on mismatched time discretization !");
1416 MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1417 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1418 ret->setArray(arr,0);
1422 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::dot(const MEDCouplingTimeDiscretization *other) const
1424 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1426 throw INTERP_KERNEL::Exception("WithTimeStep::dot on mismatched time discretization !");
1427 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1428 MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1429 ret->setArray(arr,0);
1433 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::crossProduct(const MEDCouplingTimeDiscretization *other) const
1435 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1437 throw INTERP_KERNEL::Exception("WithTimeStep::crossProduct on mismatched time discretization !");
1438 MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1439 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1440 ret->setArray(arr,0);
1444 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::max(const MEDCouplingTimeDiscretization *other) const
1446 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1448 throw INTERP_KERNEL::Exception("WithTimeStep::max on mismatched time discretization !");
1449 MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1450 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1451 ret->setArray(arr,0);
1455 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::min(const MEDCouplingTimeDiscretization *other) const
1457 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1459 throw INTERP_KERNEL::Exception("WithTimeStep::min on mismatched time discretization !");
1460 MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1461 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1462 ret->setArray(arr,0);
1466 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::add(const MEDCouplingTimeDiscretization *other) const
1468 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1470 throw INTERP_KERNEL::Exception("WithTimeStep::add on mismatched time discretization !");
1471 MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1472 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1473 ret->setArray(arr,0);
1475 double tmp3=getStartTime(tmp1,tmp2);
1476 ret->setStartTime(tmp3,tmp1,tmp2);
1480 void MEDCouplingWithTimeStep::addEqual(const MEDCouplingTimeDiscretization *other)
1482 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1484 throw INTERP_KERNEL::Exception("WithTimeStep::addEqual on mismatched time discretization !");
1486 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::addEqual : Data Array is NULL !");
1487 getArray()->addEqual(other->getArray());
1490 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::substract(const MEDCouplingTimeDiscretization *other) const
1492 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1494 throw INTERP_KERNEL::Exception("WithTimeStep::substract on mismatched time discretization !");
1495 MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1496 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1497 ret->setArray(arr,0);
1499 double tmp3=getStartTime(tmp1,tmp2);
1500 ret->setStartTime(tmp3,tmp1,tmp2);
1504 void MEDCouplingWithTimeStep::substractEqual(const MEDCouplingTimeDiscretization *other)
1506 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1508 throw INTERP_KERNEL::Exception("WithTimeStep::substractEqual on mismatched time discretization !");
1510 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::substractEqual : Data Array is NULL !");
1511 getArray()->substractEqual(other->getArray());
1514 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::multiply(const MEDCouplingTimeDiscretization *other) const
1516 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1518 throw INTERP_KERNEL::Exception("WithTimeStep::multiply on mismatched time discretization !");
1519 MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1520 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1521 ret->setArray(arr,0);
1523 double tmp3=getStartTime(tmp1,tmp2);
1524 ret->setStartTime(tmp3,tmp1,tmp2);
1528 void MEDCouplingWithTimeStep::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1530 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1532 throw INTERP_KERNEL::Exception("WithTimeStep::multiplyEqual on mismatched time discretization !");
1534 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::multiplyEqual : Data Array is NULL !");
1535 getArray()->multiplyEqual(other->getArray());
1538 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::divide(const MEDCouplingTimeDiscretization *other) const
1540 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1542 throw INTERP_KERNEL::Exception("WithTimeStep::divide on mismatched time discretization !");
1543 MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1544 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1545 ret->setArray(arr,0);
1547 double tmp3=getStartTime(tmp1,tmp2);
1548 ret->setStartTime(tmp3,tmp1,tmp2);
1552 void MEDCouplingWithTimeStep::divideEqual(const MEDCouplingTimeDiscretization *other)
1554 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1556 throw INTERP_KERNEL::Exception("WithTimeStep::divideEqual on mismatched time discretization !");
1558 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::divideEqual : Data Array is NULL !");
1559 getArray()->divideEqual(other->getArray());
1562 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::pow(const MEDCouplingTimeDiscretization *other) const
1564 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1566 throw INTERP_KERNEL::Exception("WithTimeStep::pow on mismatched time discretization !");
1567 MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
1568 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1569 ret->setArray(arr,0);
1571 double tmp3=getStartTime(tmp1,tmp2);
1572 ret->setStartTime(tmp3,tmp1,tmp2);
1576 void MEDCouplingWithTimeStep::powEqual(const MEDCouplingTimeDiscretization *other)
1578 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1580 throw INTERP_KERNEL::Exception("WithTimeStep::powEqual on mismatched time discretization !");
1582 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::powEqual : Data Array is NULL !");
1583 getArray()->powEqual(other->getArray());
1586 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCopyOrIncrRef(bool deepCopy) const
1588 return new MEDCouplingWithTimeStep(*this,deepCopy);
1591 void MEDCouplingWithTimeStep::checkNoTimePresence() const
1593 throw INTERP_KERNEL::Exception("No time specified on a field defined on one time");
1596 void MEDCouplingWithTimeStep::checkTimePresence(double time) const
1598 _tk.checkTimePresence(time,_time_tolerance);
1601 std::vector< const DataArrayDouble *> MEDCouplingWithTimeStep::getArraysForTime(double time) const
1603 if(std::fabs(time-_tk.getTimeValue())<=_time_tolerance)
1605 std::vector< const DataArrayDouble *> ret(1);
1610 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1613 void MEDCouplingWithTimeStep::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1615 std::copy(vals.begin(),vals.end(),res);
1618 void MEDCouplingWithTimeStep::getValueOnTime(int eltId, double time, double *value) const
1620 if(std::fabs(time-_tk.getTimeValue())<=_time_tolerance)
1622 _array->getTuple(eltId,value);
1624 throw INTERP_KERNEL::Exception("No array existing.");
1626 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1629 void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1631 if(_tk.getIteration()==iteration && _tk.getOrder()==order)
1633 _array->getTuple(eltId,value);
1635 throw INTERP_KERNEL::Exception("No array existing.");
1637 throw INTERP_KERNEL::Exception("No data on this discrete time.");
1640 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval()
1644 void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
1646 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1647 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(&other);
1649 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::copyTinyAttrFrom : mismatch of time discretization !");
1650 _start.copyFrom(otherC->_start);
1651 _end.copyFrom(otherC->_end);
1654 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1656 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1657 tinyInfo.push_back(_start.getIteration());
1658 tinyInfo.push_back(_start.getOrder());
1659 tinyInfo.push_back(_end.getIteration());
1660 tinyInfo.push_back(_end.getOrder());
1663 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1665 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1666 tinyInfo.push_back(_start.getTimeValue());
1667 tinyInfo.push_back(_end.getTimeValue());
1670 void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1672 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1673 _start.setTimeValue(tinyInfoD[1]);
1674 _end.setTimeValue(tinyInfoD[2]);
1675 _start.setIteration(tinyInfoI[2]);
1676 _start.setOrder(tinyInfoI[3]);
1677 _end.setIteration(tinyInfoI[4]);
1678 _end.setOrder(tinyInfoI[5]);
1682 * idem getTinySerializationIntInformation except that it is for multi field fetch
1684 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1687 tinyInfo[0]=_start.getIteration();
1688 tinyInfo[1]=_start.getOrder();
1689 tinyInfo[2]=_end.getIteration();
1690 tinyInfo[3]=_end.getOrder();
1694 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1696 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1699 tinyInfo[0]=_time_tolerance;
1700 tinyInfo[1]=_start.getTimeValue();
1701 tinyInfo[2]=_end.getTimeValue();
1705 * idem finishUnserialization except that it is for multi field fetch
1707 void MEDCouplingConstOnTimeInterval::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1709 _start.setIteration(tinyInfoI[0]);
1710 _start.setOrder(tinyInfoI[1]);
1711 _end.setIteration(tinyInfoI[2]);
1712 _end.setOrder(tinyInfoI[3]);
1713 _time_tolerance=tinyInfoD[0];
1714 _start.setTimeValue(tinyInfoD[1]);
1715 _end.setTimeValue(tinyInfoD[2]);
1718 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCopy):
1719 MEDCouplingTimeDiscretization(other,deepCopy),_start(other._start),_end(other._end)
1723 std::string MEDCouplingConstOnTimeInterval::getStringRepr() const
1725 std::ostringstream stream;
1726 stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n";
1727 stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n";
1728 stream << "\nTime unit is : \"" << _time_unit << "\"";
1729 return stream.str();
1732 void MEDCouplingConstOnTimeInterval::synchronizeTimeWith(const MEDCouplingMesh *mesh)
1735 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
1737 double val=mesh->getTime(it,order);
1738 _start.setAllInfo(val,it,order);
1739 _end.setAllInfo(val,it,order);
1740 std::string tUnit(mesh->getTimeUnit());
1744 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCopyOrIncrRef(bool deepCopy) const
1746 return new MEDCouplingConstOnTimeInterval(*this,deepCopy);
1749 std::vector< const DataArrayDouble *> MEDCouplingConstOnTimeInterval::getArraysForTime(double time) const
1751 if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
1753 std::vector< const DataArrayDouble *> ret(1);
1758 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1761 void MEDCouplingConstOnTimeInterval::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1763 std::copy(vals.begin(),vals.end(),res);
1766 bool MEDCouplingConstOnTimeInterval::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1768 if(!MEDCouplingTimeDiscretization::areCompatible(other))
1770 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1774 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
1776 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1778 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1781 reason.insert(0,"time discretization of this is CONST_ON_TIME_INTERVAL, other has a different time discretization.");
1785 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1787 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1789 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1793 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1795 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1797 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1801 bool MEDCouplingConstOnTimeInterval::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1803 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1805 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1809 bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
1811 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1812 std::ostringstream oss; oss.precision(15);
1815 reason="This has time discretization CONST_ON_TIME_INTERVAL, other not.";
1818 if(!_start.isEqualIfNotWhy(otherC->_start,_time_tolerance,reason))
1820 if(!_end.isEqualIfNotWhy(otherC->_end,_time_tolerance,reason))
1822 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1825 bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
1827 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1830 if(!_start.isEqual(otherC->_start,_time_tolerance))
1832 if(!_end.isEqual(otherC->_end,_time_tolerance))
1834 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1837 void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, double *value) const
1839 if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
1841 _array->getTuple(eltId,value);
1843 throw INTERP_KERNEL::Exception("No array existing.");
1845 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1848 void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1850 if(iteration>=_start.getIteration() && iteration<=_end.getIteration())
1852 _array->getTuple(eltId,value);
1854 throw INTERP_KERNEL::Exception("No array existing.");
1856 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1859 void MEDCouplingConstOnTimeInterval::checkNoTimePresence() const
1861 throw INTERP_KERNEL::Exception("No time specified on a field defined as constant on one time interval");
1864 void MEDCouplingConstOnTimeInterval::checkTimePresence(double time) const
1866 if(time<_start.getTimeValue()-_time_tolerance || time>_end.getTimeValue()+_time_tolerance)
1868 std::ostringstream stream;
1869 stream << "The field is defined between times " << _start.getTimeValue() << " and " << _end.getTimeValue() << " worderh tolerance ";
1870 stream << _time_tolerance << " and trying to access on time = " << time;
1871 throw INTERP_KERNEL::Exception(stream.str().c_str());
1875 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const MEDCouplingTimeDiscretization *other) const
1877 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1879 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregation on mismatched time discretization !");
1880 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1881 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1882 ret->setArray(arr,0);
1886 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1888 std::vector<const DataArrayDouble *> a(other.size());
1890 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1892 const MEDCouplingConstOnTimeInterval *itC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(*it);
1894 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregate on mismatched time discretization !");
1895 a[i]=itC->getArray();
1897 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1898 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1899 ret->setArray(arr,0);
1903 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::meld(const MEDCouplingTimeDiscretization *other) const
1905 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1907 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::meld on mismatched time discretization !");
1908 MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1909 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1910 ret->setTimeTolerance(getTimeTolerance());
1911 ret->setArray(arr,0);
1915 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::dot(const MEDCouplingTimeDiscretization *other) const
1917 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1919 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::dot on mismatched time discretization !");
1920 MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1921 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1922 ret->setArray(arr,0);
1926 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::crossProduct(const MEDCouplingTimeDiscretization *other) const
1928 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1930 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::crossProduct on mismatched time discretization !");
1931 MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1932 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1933 ret->setArray(arr,0);
1937 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::max(const MEDCouplingTimeDiscretization *other) const
1939 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1941 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::max on mismatched time discretization !");
1942 MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1943 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1944 ret->setArray(arr,0);
1948 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::min(const MEDCouplingTimeDiscretization *other) const
1950 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1952 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::min on mismatched time discretization !");
1953 MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1954 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1955 ret->setArray(arr,0);
1959 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::add(const MEDCouplingTimeDiscretization *other) const
1961 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1963 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::add on mismatched time discretization !");
1964 MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1965 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1966 ret->setArray(arr,0);
1968 double tmp3=getStartTime(tmp1,tmp2);
1969 ret->setStartTime(tmp3,tmp1,tmp2);
1970 tmp3=getEndTime(tmp1,tmp2);
1971 ret->setEndTime(tmp3,tmp1,tmp2);
1975 void MEDCouplingConstOnTimeInterval::addEqual(const MEDCouplingTimeDiscretization *other)
1977 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1979 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::addEqual on mismatched time discretization !");
1981 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractaddEqual : Data Array is NULL !");
1982 getArray()->addEqual(other->getArray());
1985 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::substract(const MEDCouplingTimeDiscretization *other) const
1987 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1989 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substract on mismatched time discretization !");
1990 MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1991 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1992 ret->setArray(arr,0);
1994 double tmp3=getStartTime(tmp1,tmp2);
1995 ret->setStartTime(tmp3,tmp1,tmp2);
1996 tmp3=getEndTime(tmp1,tmp2);
1997 ret->setEndTime(tmp3,tmp1,tmp2);
2001 void MEDCouplingConstOnTimeInterval::substractEqual(const MEDCouplingTimeDiscretization *other)
2003 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2005 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substractEqual on mismatched time discretization !");
2007 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractEqual : Data Array is NULL !");
2008 getArray()->substractEqual(other->getArray());
2011 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::multiply(const MEDCouplingTimeDiscretization *other) const
2013 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2015 throw INTERP_KERNEL::Exception("multiply on mismatched time discretization !");
2016 MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
2017 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2018 ret->setArray(arr,0);
2020 double tmp3=getStartTime(tmp1,tmp2);
2021 ret->setStartTime(tmp3,tmp1,tmp2);
2022 tmp3=getEndTime(tmp1,tmp2);
2023 ret->setEndTime(tmp3,tmp1,tmp2);
2027 void MEDCouplingConstOnTimeInterval::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2029 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2031 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::multiplyEqual on mismatched time discretization !");
2033 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::multiplyEqual : Data Array is NULL !");
2034 getArray()->multiplyEqual(other->getArray());
2037 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::divide(const MEDCouplingTimeDiscretization *other) const
2039 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2041 throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
2042 MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
2043 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2044 ret->setArray(arr,0);
2046 double tmp3=getStartTime(tmp1,tmp2);
2047 ret->setStartTime(tmp3,tmp1,tmp2);
2048 tmp3=getEndTime(tmp1,tmp2);
2049 ret->setEndTime(tmp3,tmp1,tmp2);
2053 void MEDCouplingConstOnTimeInterval::divideEqual(const MEDCouplingTimeDiscretization *other)
2055 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2057 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::divideEqual on mismatched time discretization !");
2059 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::divideEqual : Data Array is NULL !");
2060 getArray()->divideEqual(other->getArray());
2063 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::pow(const MEDCouplingTimeDiscretization *other) const
2065 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2067 throw INTERP_KERNEL::Exception("pow on mismatched time discretization !");
2068 MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
2069 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2070 ret->setArray(arr,0);
2072 double tmp3=getStartTime(tmp1,tmp2);
2073 ret->setStartTime(tmp3,tmp1,tmp2);
2074 tmp3=getEndTime(tmp1,tmp2);
2075 ret->setEndTime(tmp3,tmp1,tmp2);
2079 void MEDCouplingConstOnTimeInterval::powEqual(const MEDCouplingTimeDiscretization *other)
2081 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2083 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::powEqual on mismatched time discretization !");
2085 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::powEqual : Data Array is NULL !");
2086 getArray()->powEqual(other->getArray());
2089 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy),
2090 _start_time(other._start_time),_end_time(other._end_time),
2091 _start_iteration(other._start_iteration),_end_iteration(other._end_iteration),
2092 _start_order(other._start_order),_end_order(other._end_order)
2094 if(other._end_array)
2095 _end_array=other._end_array->performCopyOrIncrRef(deepCopy);
2100 void MEDCouplingTwoTimeSteps::updateTime() const
2102 MEDCouplingTimeDiscretization::updateTime();
2104 updateTimeWith(*_end_array);
2107 void MEDCouplingTwoTimeSteps::synchronizeTimeWith(const MEDCouplingMesh *mesh)
2110 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
2112 double val=mesh->getTime(it,order);
2113 _start_time=val; _start_iteration=it; _start_order=order;
2114 _end_time=val; _end_iteration=it; _end_order=order;
2115 std::string tUnit=mesh->getTimeUnit();
2119 std::size_t MEDCouplingTwoTimeSteps::getHeapMemorySizeWithoutChildren() const
2121 return MEDCouplingTimeDiscretization::getHeapMemorySizeWithoutChildren();
2124 std::vector<const BigMemoryObject *> MEDCouplingTwoTimeSteps::getDirectChildrenWithNull() const
2126 std::vector<const BigMemoryObject *> ret(MEDCouplingTimeDiscretization::getDirectChildrenWithNull());
2127 ret.push_back(_end_array);
2131 void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
2133 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
2134 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2136 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::copyTinyAttrFrom : mismatch of time discretization !");
2137 _start_time=otherC->_start_time;
2138 _end_time=otherC->_end_time;
2139 _start_iteration=otherC->_start_iteration;
2140 _end_iteration=otherC->_end_iteration;
2141 _start_order=otherC->_start_order;
2142 _end_order=otherC->_end_order;
2145 void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
2147 MEDCouplingTimeDiscretization::copyTinyStringsFrom(other);
2148 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2150 throw INTERP_KERNEL::Exception("Trying to operate copyTinyStringsFrom on different field type (two times//one time) !");
2151 if(_end_array && otherC->_end_array)
2152 _end_array->copyStringInfoFrom(*otherC->_end_array);
2155 const DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray() const
2160 DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray()
2165 void MEDCouplingTwoTimeSteps::checkConsistencyLight() const
2167 MEDCouplingTimeDiscretization::checkConsistencyLight();
2169 throw INTERP_KERNEL::Exception("No end array specified !");
2170 if(_array->getNumberOfComponents()!=_end_array->getNumberOfComponents())
2171 throw INTERP_KERNEL::Exception("The number of components mismatch between the start and the end arrays !");
2172 if(_array->getNumberOfTuples()!=_end_array->getNumberOfTuples())
2173 throw INTERP_KERNEL::Exception("The number of tuples mismatch between the start and the end arrays !");
2176 bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
2178 std::ostringstream oss;
2179 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(other);
2182 reason="This has time discretization LINEAR_TIME, other not.";
2185 if(_start_iteration!=otherC->_start_iteration)
2187 oss << "start iterations differ. this start iteration=" << _start_iteration << " other start iteration=" << otherC->_start_iteration;
2191 if(_start_order!=otherC->_start_order)
2193 oss << "start orders differ. this start order=" << _start_order << " other start order=" << otherC->_start_order;
2197 if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
2199 oss << "start times differ. this start time=" << _start_time << " other start time=" << otherC->_start_time;
2203 if(_end_iteration!=otherC->_end_iteration)
2205 oss << "end iterations differ. this end iteration=" << _end_iteration << " other end iteration=" << otherC->_end_iteration;
2209 if(_end_order!=otherC->_end_order)
2211 oss << "end orders differ. this end order=" << _end_order << " other end order=" << otherC->_end_order;
2215 if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
2217 oss << "end times differ. this end time=" << _end_time << " other end time=" << otherC->_end_time;
2221 if(_end_array!=otherC->_end_array)
2222 if(!_end_array->isEqualIfNotWhy(*otherC->_end_array,prec,reason))
2224 reason.insert(0,"end arrays differ for linear time.");
2227 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
2230 bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
2232 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(other);
2235 if(_start_iteration!=otherC->_start_iteration)
2237 if(_end_iteration!=otherC->_end_iteration)
2239 if(_start_order!=otherC->_start_order)
2241 if(_end_order!=otherC->_end_order)
2243 if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
2245 if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
2247 if(_end_array!=otherC->_end_array)
2248 if(!_end_array->isEqualWithoutConsideringStr(*otherC->_end_array,prec))
2250 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
2253 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_start_time(0.),_end_time(0.),_start_iteration(-1),_end_iteration(-1),_start_order(-1),_end_order(-1),_end_array(0)
2257 MEDCouplingTwoTimeSteps::~MEDCouplingTwoTimeSteps()
2260 _end_array->decrRef();
2263 void MEDCouplingTwoTimeSteps::checkNoTimePresence() const
2265 throw INTERP_KERNEL::Exception("The field presents a time to be specified in every access !");
2268 void MEDCouplingTwoTimeSteps::checkTimePresence(double time) const
2270 if(time<_start_time-_time_tolerance || time>_end_time+_time_tolerance)
2272 std::ostringstream stream;
2273 stream << "The field is defined between times " << _start_time << " and " << _end_time << " worderh tolerance ";
2274 stream << _time_tolerance << " and trying to access on time = " << time;
2275 throw INTERP_KERNEL::Exception(stream.str().c_str());
2279 void MEDCouplingTwoTimeSteps::getArrays(std::vector<DataArrayDouble *>& arrays) const
2283 arrays[1]=_end_array;
2286 void MEDCouplingTwoTimeSteps::setEndArray(DataArrayDouble *array, TimeLabel *owner)
2288 if(array!=_end_array)
2291 _end_array->decrRef();
2294 _end_array->incrRef();
2296 owner->declareAsNew();
2300 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
2302 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
2303 tinyInfo.push_back(_start_iteration);
2304 tinyInfo.push_back(_start_order);
2305 tinyInfo.push_back(_end_iteration);
2306 tinyInfo.push_back(_end_order);
2309 tinyInfo.push_back(_end_array->getNumberOfTuples());
2310 tinyInfo.push_back(_end_array->getNumberOfComponents());
2314 tinyInfo.push_back(-1);
2315 tinyInfo.push_back(-1);
2319 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
2321 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
2322 tinyInfo.push_back(_start_time);
2323 tinyInfo.push_back(_end_time);
2326 void MEDCouplingTwoTimeSteps::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
2328 int nbOfCompo=_array->getNumberOfComponents();
2329 for(int i=0;i<nbOfCompo;i++)
2330 tinyInfo.push_back(_array->getInfoOnComponent(i));
2331 for(int i=0;i<nbOfCompo;i++)
2332 tinyInfo.push_back(_end_array->getInfoOnComponent(i));
2335 void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
2341 _end_array->decrRef();
2342 DataArrayDouble *arr=0;
2343 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2345 arr=DataArrayDouble::New();
2346 arr->alloc(tinyInfoI[0],tinyInfoI[1]);
2351 if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2353 arr=DataArrayDouble::New();
2354 arr->alloc(tinyInfoI[6],tinyInfoI[7]);
2360 void MEDCouplingTwoTimeSteps::checkForUnserialization(const std::vector<int>& tinyInfoI, const std::vector<DataArrayDouble *>& arrays)
2362 static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size two !";
2363 if(arrays.size()!=2)
2364 throw INTERP_KERNEL::Exception(MSG);
2368 _end_array->decrRef();
2369 _array=0; _end_array=0;
2370 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2373 throw INTERP_KERNEL::Exception(MSG);
2374 arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
2375 _array=arrays[0]; _array->incrRef();
2377 if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2380 throw INTERP_KERNEL::Exception(MSG);
2381 arrays[1]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
2382 _end_array=arrays[1]; _end_array->incrRef();
2386 void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
2388 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
2389 _start_time=tinyInfoD[1];
2390 _end_time=tinyInfoD[2];
2391 _start_iteration=tinyInfoI[2];
2392 _start_order=tinyInfoI[3];
2393 _end_iteration=tinyInfoI[4];
2394 _end_order=tinyInfoI[5];
2398 * idem getTinySerializationIntInformation except that it is for multi field fetch
2400 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
2403 tinyInfo[0]=_start_iteration;
2404 tinyInfo[1]=_start_order;
2405 tinyInfo[2]=_end_iteration;
2406 tinyInfo[3]=_end_order;
2410 * idem getTinySerializationDbleInformation except that it is for multi field fetch
2412 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
2415 tinyInfo[0]=_time_tolerance;
2416 tinyInfo[1]=_start_time;
2417 tinyInfo[2]=_end_time;
2421 * idem finishUnserialization except that it is for multi field fetch
2423 void MEDCouplingTwoTimeSteps::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
2425 _start_iteration=tinyInfoI[0];
2426 _start_order=tinyInfoI[1];
2427 _end_iteration=tinyInfoI[2];
2428 _end_order=tinyInfoI[3];
2429 _time_tolerance=tinyInfoD[0];
2430 _start_time=tinyInfoD[1];
2431 _end_time=tinyInfoD[2];
2434 std::vector< const DataArrayDouble *> MEDCouplingTwoTimeSteps::getArraysForTime(double time) const
2436 if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance)
2438 std::vector< const DataArrayDouble *> ret(2);
2444 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2447 void MEDCouplingTwoTimeSteps::setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner)
2449 if(arrays.size()!=2)
2450 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::setArrays : number of arrays must be two.");
2451 setArray(arrays.front(),owner);
2452 setEndArray(arrays.back(),owner);
2455 MEDCouplingLinearTime::MEDCouplingLinearTime(const MEDCouplingLinearTime& other, bool deepCopy):MEDCouplingTwoTimeSteps(other,deepCopy)
2459 MEDCouplingLinearTime::MEDCouplingLinearTime()
2463 std::string MEDCouplingLinearTime::getStringRepr() const
2465 std::ostringstream stream;
2466 stream << REPR << " Time interval is defined by :\niteration_start=" << _start_iteration << " order_start=" << _start_order << " and time_start=" << _start_time << "\n";
2467 stream << "iteration_end=" << _end_iteration << " order_end=" << _end_order << " and end_time=" << _end_time << "\n";
2468 stream << "Time unit is : \"" << _time_unit << "\"";
2469 return stream.str();
2472 void MEDCouplingLinearTime::checkConsistencyLight() const
2474 MEDCouplingTwoTimeSteps::checkConsistencyLight();
2475 if(std::fabs(_start_time-_end_time)<_time_tolerance)
2476 throw INTERP_KERNEL::Exception("Start time and end time are equals regarding time tolerance.");
2479 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::performCopyOrIncrRef(bool deepCopy) const
2481 return new MEDCouplingLinearTime(*this,deepCopy);
2484 bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2486 if(!MEDCouplingTimeDiscretization::areCompatible(other))
2488 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2491 if(_end_array==0 && otherC->_end_array==0)
2493 if(_end_array==0 || otherC->_end_array==0)
2495 if(_end_array->getNumberOfComponents()!=otherC->_end_array->getNumberOfComponents())
2500 bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
2502 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
2504 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2507 reason.insert(0,"time discretization of this is LINEAR_TIME, other has a different time discretization.");
2511 bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2513 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
2515 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2519 bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2521 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
2523 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2526 if(_end_array==0 && otherC->_end_array==0)
2528 if(_end_array==0 || otherC->_end_array==0)
2530 int nbC1=_end_array->getNumberOfComponents();
2531 int nbC2=otherC->_end_array->getNumberOfComponents();
2532 if(nbC1!=nbC2 && nbC2!=1)
2537 bool MEDCouplingLinearTime::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
2539 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
2541 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2546 * vals is expected to be of size 2*_array->getNumberOfTuples()==_array->getNumberOfTuples()+_end_array->getNumberOfTuples()
2548 void MEDCouplingLinearTime::getValueForTime(double time, const std::vector<double>& vals, double *res) const
2550 double alpha=(_end_time-time)/(_end_time-_start_time);
2551 std::size_t nbComp=vals.size()/2;
2552 std::transform(vals.begin(),vals.begin()+nbComp,res,std::bind2nd(std::multiplies<double>(),alpha));
2553 std::vector<double> tmp(nbComp);
2554 std::transform(vals.begin()+nbComp,vals.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2555 std::transform(tmp.begin(),tmp.end(),res,res,std::plus<double>());
2558 void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value) const
2560 double alpha=(_end_time-time)/(_end_time-_start_time);
2563 _array->getTuple(eltId,value);
2565 throw INTERP_KERNEL::Exception("No start array existing.");
2566 nbComp=_array->getNumberOfComponents();
2567 std::transform(value,value+nbComp,value,std::bind2nd(std::multiplies<double>(),alpha));
2568 std::vector<double> tmp(nbComp);
2570 _end_array->getTuple(eltId,&tmp[0]);
2572 throw INTERP_KERNEL::Exception("No end array existing.");
2573 std::transform(tmp.begin(),tmp.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2574 std::transform(tmp.begin(),tmp.end(),value,value,std::plus<double>());
2577 void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
2579 if(iteration==_start_iteration && order==_start_order)
2582 _array->getTuple(eltId,value);
2584 throw INTERP_KERNEL::Exception("iteration order match with start time but no start array existing.");
2586 if(iteration==_end_iteration && order==_end_order)
2589 _end_array->getTuple(eltId,value);
2591 throw INTERP_KERNEL::Exception("iteration order match with end time but no end array existing.");
2594 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2597 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const MEDCouplingTimeDiscretization *other) const
2599 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2601 throw INTERP_KERNEL::Exception("LinearTime::aggregation on mismatched time discretization !");
2602 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Aggregate(getArray(),other->getArray());
2603 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Aggregate(getEndArray(),other->getEndArray());
2604 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2605 ret->setArray(arr1,0);
2606 ret->setEndArray(arr2,0);
2610 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
2612 std::vector<const DataArrayDouble *> a(other.size());
2613 std::vector<const DataArrayDouble *> b(other.size());
2615 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
2617 const MEDCouplingLinearTime *itC=dynamic_cast<const MEDCouplingLinearTime *>(*it);
2619 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::aggregate on mismatched time discretization !");
2620 a[i]=itC->getArray();
2621 b[i]=itC->getEndArray();
2623 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
2624 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Aggregate(b);
2625 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2626 ret->setArray(arr,0);
2627 ret->setEndArray(arr2,0);
2631 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::meld(const MEDCouplingTimeDiscretization *other) const
2633 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2635 throw INTERP_KERNEL::Exception("LinearTime::meld on mismatched time discretization !");
2636 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Meld(getArray(),other->getArray());
2637 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Meld(getEndArray(),other->getEndArray());
2638 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2639 ret->setTimeTolerance(getTimeTolerance());
2640 ret->setArray(arr1,0);
2641 ret->setEndArray(arr2,0);
2645 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeDiscretization *other) const
2647 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2649 throw INTERP_KERNEL::Exception("LinearTime::dot on mismatched time discretization !");
2650 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Dot(getArray(),other->getArray());
2651 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Dot(getEndArray(),other->getEndArray());
2652 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2653 ret->setArray(arr1,0);
2654 ret->setEndArray(arr2,0);
2658 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::crossProduct(const MEDCouplingTimeDiscretization *other) const
2660 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2662 throw INTERP_KERNEL::Exception("LinearTime::crossProduct on mismatched time discretization !");
2663 MCAuto<DataArrayDouble> arr1=DataArrayDouble::CrossProduct(getArray(),other->getArray());
2664 MCAuto<DataArrayDouble> arr2=DataArrayDouble::CrossProduct(getEndArray(),other->getEndArray());
2665 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2666 ret->setArray(arr1,0);
2667 ret->setEndArray(arr2,0);
2671 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::max(const MEDCouplingTimeDiscretization *other) const
2673 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2675 throw INTERP_KERNEL::Exception("LinearTime::max on mismatched time discretization !");
2676 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2677 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Max(getArray(),other->getArray());
2678 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Max(getEndArray(),other->getEndArray());
2679 ret->setArray(arr1,0);
2680 ret->setEndArray(arr2,0);
2684 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::min(const MEDCouplingTimeDiscretization *other) const
2686 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2688 throw INTERP_KERNEL::Exception("LinearTime::min on mismatched time discretization !");
2689 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Min(getArray(),other->getArray());
2690 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Min(getEndArray(),other->getEndArray());
2691 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2692 ret->setArray(arr1,0);
2693 ret->setEndArray(arr2,0);
2697 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::add(const MEDCouplingTimeDiscretization *other) const
2699 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2701 throw INTERP_KERNEL::Exception("LinearTime::add on mismatched time discretization !");
2702 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Add(getArray(),other->getArray());
2703 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Add(getEndArray(),other->getEndArray());
2704 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2705 ret->setArray(arr1,0);
2706 ret->setEndArray(arr2,0);
2710 void MEDCouplingLinearTime::addEqual(const MEDCouplingTimeDiscretization *other)
2712 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2714 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2716 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array is NULL !");
2718 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array (end) is NULL !");
2719 getArray()->addEqual(other->getArray());
2720 getEndArray()->addEqual(other->getEndArray());
2723 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::substract(const MEDCouplingTimeDiscretization *other) const
2725 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2727 throw INTERP_KERNEL::Exception("LinearTime::substract on mismatched time discretization !");
2728 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Substract(getArray(),other->getArray());
2729 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Substract(getEndArray(),other->getEndArray());
2730 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2731 ret->setArray(arr1,0);
2732 ret->setEndArray(arr2,0);
2736 void MEDCouplingLinearTime::substractEqual(const MEDCouplingTimeDiscretization *other)
2738 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2740 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2742 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array is NULL !");
2744 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array (end) is NULL !");
2745 getArray()->substractEqual(other->getArray());
2746 getEndArray()->substractEqual(other->getEndArray());
2749 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::multiply(const MEDCouplingTimeDiscretization *other) const
2751 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2753 throw INTERP_KERNEL::Exception("LinearTime::multiply on mismatched time discretization !");
2754 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Multiply(getArray(),other->getArray());
2755 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Multiply(getEndArray(),other->getEndArray());
2756 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2757 ret->setArray(arr1,0);
2758 ret->setEndArray(arr2,0);
2762 void MEDCouplingLinearTime::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2764 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2766 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2768 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array is NULL !");
2770 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array (end) is NULL !");
2771 getArray()->multiplyEqual(other->getArray());
2772 getEndArray()->multiplyEqual(other->getEndArray());
2775 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::divide(const MEDCouplingTimeDiscretization *other) const
2777 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2779 throw INTERP_KERNEL::Exception("LinearTime::divide on mismatched time discretization !");
2780 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Divide(getArray(),other->getArray());
2781 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Divide(getEndArray(),other->getEndArray());
2782 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2783 ret->setArray(arr1,0);
2784 ret->setEndArray(arr2,0);
2788 void MEDCouplingLinearTime::divideEqual(const MEDCouplingTimeDiscretization *other)
2790 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2792 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2794 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array is NULL !");
2796 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array (end) is NULL !");
2797 getArray()->divideEqual(other->getArray());
2798 getEndArray()->divideEqual(other->getEndArray());
2801 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::pow(const MEDCouplingTimeDiscretization *other) const
2803 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2805 throw INTERP_KERNEL::Exception("LinearTime::pow on mismatched time discretization !");
2806 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Pow(getArray(),other->getArray());
2807 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Pow(getEndArray(),other->getEndArray());
2808 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2809 ret->setArray(arr1,0);
2810 ret->setEndArray(arr2,0);
2814 void MEDCouplingLinearTime::powEqual(const MEDCouplingTimeDiscretization *other)
2816 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2818 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2820 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array is NULL !");
2822 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array (end) is NULL !");
2823 getArray()->powEqual(other->getArray());
2824 getEndArray()->powEqual(other->getEndArray());