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 MEDCoupling::MEDCouplingTimeDiscretizationTemplate<double>;
33 template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate<float>;
34 template class MEDCoupling::MEDCouplingTimeDiscretizationSimple<float>;
35 template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate<int>;
36 template class MEDCoupling::MEDCouplingTimeDiscretizationSimple<int>;
38 const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setTime : no time info attached.";
40 const char MEDCouplingNoTimeLabel::REPR[]="No time label defined.";
42 const char MEDCouplingWithTimeStep::EXCEPTION_MSG[]="No data on this time.";
44 const char MEDCouplingWithTimeStep::REPR[]="One time label.";
46 const char MEDCouplingConstOnTimeInterval::EXCEPTION_MSG[]="No data on this time.";
48 const char MEDCouplingConstOnTimeInterval::REPR[]="Constant on a time interval.";
50 const char MEDCouplingTwoTimeSteps::EXCEPTION_MSG[]="No data on this time.";
52 const char MEDCouplingLinearTime::REPR[]="Linear time between 2 time steps.";
54 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDiscretization type)
58 case MEDCouplingNoTimeLabel::DISCRETIZATION:
59 return new MEDCouplingNoTimeLabel;
60 case MEDCouplingWithTimeStep::DISCRETIZATION:
61 return new MEDCouplingWithTimeStep;
62 case MEDCouplingConstOnTimeInterval::DISCRETIZATION:
63 return new MEDCouplingConstOnTimeInterval;
64 case MEDCouplingLinearTime::DISCRETIZATION:
65 return new MEDCouplingLinearTime;
67 throw INTERP_KERNEL::Exception("Time discretization not implemented yet");
71 bool MEDCouplingTimeDiscretization::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
73 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
75 if(_array==0 && other->_array==0)
77 if(_array==0 || other->_array==0)
79 if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
84 bool MEDCouplingTimeDiscretization::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
86 if(!areStrictlyCompatible(other,reason))
88 if(_array==other->getArray())
90 return _array->isEqualIfNotWhy(*other->getArray(),prec,reason);
93 bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
96 return isEqualIfNotWhy(other,prec,reason);
99 bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
102 if(!areStrictlyCompatible(other,tmp))
104 if(_array==other->getArray())
106 return _array->isEqualWithoutConsideringStr(*other->getArray(),prec);
109 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(TypeOfTimeDiscretization type, bool deepCopy) const
111 MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(type);
112 ret->setTimeUnit(getTimeUnit());
113 const DataArrayDouble *arrSrc=getArray();
114 MCAuto<DataArrayDouble> arr;
116 arr=arrSrc->performCopyOrIncrRef(deepCopy);
117 ret->setArray(arr,0);
121 bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const
124 double time1=getEndTime(iteration,order)-_time_tolerance;
125 double time2=other->getStartTime(iteration,order)+other->getTimeTolerance();
129 bool MEDCouplingTimeDiscretization::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const
132 double time1=getEndTime(iteration,order)+_time_tolerance;
133 double time2=other->getStartTime(iteration,order)-other->getTimeTolerance();
137 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::computeVectorFieldCyl(const DataArrayDouble *coords, const double center[3], const double vect[3]) const
139 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
140 ret->setTimeUnit(getTimeUnit());
141 std::vector<DataArrayDouble *> arrays;
143 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
144 for(std::size_t j=0;j<arrays.size();j++)
147 arrays2[j]=arrays[j]->fromCartToCylGiven(coords,center,vect);
149 std::vector<DataArrayDouble *> arrays3(arrays.size());
150 for(std::size_t j=0;j<arrays.size();j++)
151 arrays3[j]=arrays2[j];
152 ret->setArrays(arrays3,0);
156 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedProduct() const
158 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
159 ret->setTimeUnit(getTimeUnit());
160 std::vector<DataArrayDouble *> arrays;
162 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
163 for(std::size_t j=0;j<arrays.size();j++)
166 arrays2[j]=arrays[j]->doublyContractedProduct();
168 std::vector<DataArrayDouble *> arrays3(arrays.size());
169 for(std::size_t j=0;j<arrays.size();j++)
170 arrays3[j]=arrays2[j];
171 ret->setArrays(arrays3,0);
175 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() const
177 std::vector<DataArrayDouble *> arrays;
179 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
180 for(std::size_t j=0;j<arrays.size();j++)
183 arrays2[j]=arrays[j]->determinant();
185 std::vector<DataArrayDouble *> arrays3(arrays.size());
186 for(std::size_t j=0;j<arrays.size();j++)
187 arrays3[j]=arrays2[j];
188 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
189 ret->setTimeUnit(getTimeUnit());
190 ret->setArrays(arrays3,0);
194 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() const
196 std::vector<DataArrayDouble *> arrays;
198 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
199 for(std::size_t j=0;j<arrays.size();j++)
202 arrays2[j]=arrays[j]->eigenValues();
204 std::vector<DataArrayDouble *> arrays3(arrays.size());
205 for(std::size_t j=0;j<arrays.size();j++)
206 arrays3[j]=arrays2[j];
207 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
208 ret->setTimeUnit(getTimeUnit());
209 ret->setArrays(arrays3,0);
213 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() const
215 std::vector<DataArrayDouble *> arrays;
217 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
218 for(std::size_t j=0;j<arrays.size();j++)
221 arrays2[j]=arrays[j]->eigenVectors();
223 std::vector<DataArrayDouble *> arrays3(arrays.size());
224 for(std::size_t j=0;j<arrays.size();j++)
225 arrays3[j]=arrays2[j];
226 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
227 ret->setTimeUnit(getTimeUnit());
228 ret->setArrays(arrays3,0);
232 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const
234 std::vector<DataArrayDouble *> arrays;
236 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
237 for(std::size_t j=0;j<arrays.size();j++)
240 arrays2[j]=arrays[j]->inverse();
242 std::vector<DataArrayDouble *> arrays3(arrays.size());
243 for(std::size_t j=0;j<arrays.size();j++)
244 arrays3[j]=arrays2[j];
245 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
246 ret->setTimeUnit(getTimeUnit());
247 ret->setArrays(arrays3,0);
251 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const
253 std::vector<DataArrayDouble *> arrays;
255 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
256 for(std::size_t j=0;j<arrays.size();j++)
259 arrays2[j]=arrays[j]->trace();
261 std::vector<DataArrayDouble *> arrays3(arrays.size());
262 for(std::size_t j=0;j<arrays.size();j++)
263 arrays3[j]=arrays2[j];
264 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
265 ret->setTimeUnit(getTimeUnit());
266 ret->setArrays(arrays3,0);
270 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const
272 std::vector<DataArrayDouble *> arrays;
274 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
275 for(std::size_t j=0;j<arrays.size();j++)
278 arrays2[j]=arrays[j]->deviator();
280 std::vector<DataArrayDouble *> arrays3(arrays.size());
281 for(std::size_t j=0;j<arrays.size();j++)
282 arrays3[j]=arrays2[j];
283 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
284 ret->setTimeUnit(getTimeUnit());
285 ret->setArrays(arrays3,0);
289 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const
291 std::vector<DataArrayDouble *> arrays;
293 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
294 for(std::size_t j=0;j<arrays.size();j++)
297 arrays2[j]=arrays[j]->magnitude();
299 std::vector<DataArrayDouble *> arrays3(arrays.size());
300 for(std::size_t j=0;j<arrays.size();j++)
301 arrays3[j]=arrays2[j];
302 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
303 ret->setTimeUnit(getTimeUnit());
304 ret->setArrays(arrays3,0);
308 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::negate() const
310 std::vector<DataArrayDouble *> arrays;
312 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
313 for(std::size_t j=0;j<arrays.size();j++)
316 arrays2[j]=arrays[j]->negate();
318 std::vector<DataArrayDouble *> arrays3(arrays.size());
319 for(std::size_t j=0;j<arrays.size();j++)
320 arrays3[j]=arrays2[j];
321 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
322 ret->setTimeUnit(getTimeUnit());
323 ret->setArrays(arrays3,0);
327 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() const
329 std::vector<DataArrayDouble *> arrays;
331 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
332 for(std::size_t j=0;j<arrays.size();j++)
335 arrays2[j]=arrays[j]->maxPerTuple();
337 std::vector<DataArrayDouble *> arrays3(arrays.size());
338 for(std::size_t j=0;j<arrays.size();j++)
339 arrays3[j]=arrays2[j];
340 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
341 ret->setTimeUnit(getTimeUnit());
342 ret->setArrays(arrays3,0);
346 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedComponents(const std::vector<int>& compoIds) const
348 std::vector<DataArrayDouble *> arrays;
350 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
351 for(std::size_t j=0;j<arrays.size();j++)
354 arrays2[j]=static_cast<DataArrayDouble *>(arrays[j]->keepSelectedComponents(compoIds));
356 std::vector<DataArrayDouble *> arrays3(arrays.size());
357 for(std::size_t j=0;j<arrays.size();j++)
358 arrays3[j]=arrays2[j];
359 MEDCouplingTimeDiscretization *ret(MEDCouplingTimeDiscretization::New(getEnum()));
360 ret->setTimeUnit(getTimeUnit());
361 ret->setArrays(arrays3,0);
365 void MEDCouplingTimeDiscretization::setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector<int>& compoIds)
367 std::vector<DataArrayDouble *> arrays1,arrays2;
369 other->getArrays(arrays2);
370 if(arrays1.size()!=arrays2.size())
371 throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : number of arrays mismatch !");
372 for(std::size_t i=0;i<arrays1.size();i++)
374 if(arrays1[i]!=0 && arrays2[i]!=0)
375 arrays1[i]->setSelectedComponents(arrays2[i],compoIds);
376 else if(arrays1[i]!=0 || arrays2[i]!=0)
377 throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : some time array in correspondance are not defined symmetrically !");
381 void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double dftValue)
383 std::vector<DataArrayDouble *> arrays;
385 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
386 for(std::size_t j=0;j<arrays.size();j++)
389 arrays2[j]=arrays[j]->changeNbOfComponents(newNbOfComp,dftValue);
391 std::vector<DataArrayDouble *> arrays3(arrays.size());
392 for(std::size_t j=0;j<arrays.size();j++)
393 arrays3[j]=arrays2[j];
394 setArrays(arrays3,0);
397 void MEDCouplingTimeDiscretization::sortPerTuple(bool asc)
399 std::vector<DataArrayDouble *> arrays;
401 for(std::size_t j=0;j<arrays.size();j++)
404 arrays[j]->sortPerTuple(asc);
408 void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, int nbOfCompo, double value)
410 std::vector<DataArrayDouble *> arrays;
412 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
413 for(std::size_t j=0;j<arrays.size();j++)
417 arrays2[j]=arrays[j]->changeNbOfComponents(nbOfCompo,value);
418 arrays2[j]->fillWithValue(value);
422 arrays2[j]=DataArrayDouble::New();
423 arrays2[j]->alloc(nbOfTuple,nbOfCompo);
424 arrays2[j]->fillWithValue(value);
427 std::vector<DataArrayDouble *> arrays3(arrays.size());
428 for(std::size_t j=0;j<arrays.size();j++)
429 arrays3[j]=arrays2[j];
430 setArrays(arrays3,0);
433 void MEDCouplingTimeDiscretization::setOrCreateUniformValueOnAllComponents(int nbOfTuple, double value)
435 std::vector<DataArrayDouble *> arrays;
437 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
439 for(std::size_t j=0;j<arrays.size();j++)
443 arrays2[j]=arrays[j]; arrays2[j]->incrRef();
444 arrays2[j]->fillWithValue(value);
449 arrays2[j]=DataArrayDouble::New();
450 arrays2[j]->alloc(nbOfTuple,1);
451 arrays2[j]->fillWithValue(value);
456 std::vector<DataArrayDouble *> arrays3(arrays.size());
457 for(std::size_t j=0;j<arrays.size();j++)
458 arrays3[j]=arrays2[j];
459 setArrays(arrays3,0);
463 void MEDCouplingTimeDiscretization::applyLin(double a, double b, int compoId)
465 std::vector<DataArrayDouble *> arrays;
467 for(std::size_t j=0;j<arrays.size();j++)
470 arrays[j]->applyLin(a,b,compoId);
474 void MEDCouplingTimeDiscretization::applyLin(double a, double b)
476 std::vector<DataArrayDouble *> arrays;
478 for(std::size_t j=0;j<arrays.size();j++)
481 arrays[j]->applyLin(a,b);
485 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate func)
487 std::vector<DataArrayDouble *> arrays;
489 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
490 for(std::size_t j=0;j<arrays.size();j++)
493 arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
495 std::vector<DataArrayDouble *> arrays3(arrays.size());
496 for(std::size_t j=0;j<arrays.size();j++)
497 arrays3[j]=arrays2[j];
498 setArrays(arrays3,0);
501 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const std::string& func)
503 std::vector<DataArrayDouble *> arrays;
505 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
506 for(std::size_t j=0;j<arrays.size();j++)
509 arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
513 std::vector<DataArrayDouble *> arrays3(arrays.size());
514 for(std::size_t j=0;j<arrays.size();j++)
515 arrays3[j]=arrays2[j];
516 setArrays(arrays3,0);
519 void MEDCouplingTimeDiscretization::applyFuncCompo(int nbOfComp, const std::string& func)
521 std::vector<DataArrayDouble *> arrays;
523 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
524 for(std::size_t j=0;j<arrays.size();j++)
527 arrays2[j]=arrays[j]->applyFuncCompo(nbOfComp,func);
529 std::vector<DataArrayDouble *> arrays3(arrays.size());
530 for(std::size_t j=0;j<arrays.size();j++)
531 arrays3[j]=arrays2[j];
532 setArrays(arrays3,0);
535 void MEDCouplingTimeDiscretization::applyFuncNamedCompo(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
537 std::vector<DataArrayDouble *> arrays;
539 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
540 for(std::size_t j=0;j<arrays.size();j++)
543 arrays2[j]=arrays[j]->applyFuncNamedCompo(nbOfComp,varsOrder,func);
545 std::vector<DataArrayDouble *> arrays3(arrays.size());
546 for(std::size_t j=0;j<arrays.size();j++)
547 arrays3[j]=arrays2[j];
548 setArrays(arrays3,0);
551 void MEDCouplingTimeDiscretization::applyFunc(const std::string& func)
553 std::vector<DataArrayDouble *> arrays;
555 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
556 for(std::size_t j=0;j<arrays.size();j++)
559 arrays2[j]=arrays[j]->applyFunc(func);
561 std::vector<DataArrayDouble *> arrays3(arrays.size());
562 for(std::size_t j=0;j<arrays.size();j++)
563 arrays3[j]=arrays2[j];
564 setArrays(arrays3,0);
567 void MEDCouplingTimeDiscretization::applyFuncFast32(const std::string& func)
569 std::vector<DataArrayDouble *> arrays;
571 for(std::size_t j=0;j<arrays.size();j++)
574 arrays[j]->applyFuncFast32(func);
578 void MEDCouplingTimeDiscretization::applyFuncFast64(const std::string& func)
580 std::vector<DataArrayDouble *> arrays;
582 for(std::size_t j=0;j<arrays.size();j++)
585 arrays[j]->applyFuncFast64(func);
589 void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, FunctionToEvaluate func)
591 std::vector<DataArrayDouble *> arrays;
593 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
594 for(std::size_t j=0;j<arrays.size();j++)
595 arrays2[j]=loc->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::fillFromAnalytic(const DataArrayDouble *loc, 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++)
608 arrays2[j]=loc->applyFunc(nbOfComp,func);
609 std::vector<DataArrayDouble *> arrays3(arrays.size());
610 for(std::size_t j=0;j<arrays.size();j++)
611 arrays3[j]=arrays2[j];
612 setArrays(arrays3,0);
615 void MEDCouplingTimeDiscretization::fillFromAnalyticCompo(const DataArrayDouble *loc, int nbOfComp, const std::string& func)
617 std::vector<DataArrayDouble *> arrays;
619 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
620 for(std::size_t j=0;j<arrays.size();j++)
621 arrays2[j]=loc->applyFuncCompo(nbOfComp,func);
622 std::vector<DataArrayDouble *> arrays3(arrays.size());
623 for(std::size_t j=0;j<arrays.size();j++)
624 arrays3[j]=arrays2[j];
625 setArrays(arrays3,0);
628 void MEDCouplingTimeDiscretization::fillFromAnalyticNamedCompo(const DataArrayDouble *loc, int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
630 std::vector<DataArrayDouble *> arrays;
632 std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
633 for(std::size_t j=0;j<arrays.size();j++)
634 arrays2[j]=loc->applyFuncNamedCompo(nbOfComp,varsOrder,func);
635 std::vector<DataArrayDouble *> arrays3(arrays.size());
636 for(std::size_t j=0;j<arrays.size();j++)
637 arrays3[j]=arrays2[j];
638 setArrays(arrays3,0);
641 ////////////////////////
643 bool MEDCouplingTimeKeeper::isEqualIfNotWhy(const MEDCouplingTimeKeeper& other, double prec, std::string& reason) const
645 std::ostringstream oss;
646 if(_iteration!=other._iteration)
648 oss << "iterations differ. this iteration=" << _iteration << " other iteration=" << other._iteration;
652 if(_order!=other._order)
654 oss << "orders differ. this order=" << _order << " other order=" << other._order;
658 if(std::fabs(_time-other._time)>prec)
660 oss << "times differ. this time=" << _time << " other time=" << other._time;
667 bool MEDCouplingTimeKeeper::isEqual(const MEDCouplingTimeKeeper& other, double prec) const
669 if(_iteration!=other._iteration)
671 if(_order!=other._order)
673 if(std::fabs(_time-other._time)>prec)
678 void MEDCouplingTimeKeeper::copyFrom(const MEDCouplingTimeKeeper& other)
681 _iteration=other._iteration;
685 void MEDCouplingTimeKeeper::checkTimePresence(double time, double eps) const
687 if(std::fabs(time-_time)>eps)
689 std::ostringstream stream;
690 stream << "The field is defined on time " << _time << " with eps=" << eps << " and asking time = " << time << " !";
691 throw INTERP_KERNEL::Exception(stream.str().c_str());
695 ////////////////////////
697 MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple<int>(other,deepCopy)
701 MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::performCopyOrIncrRef(bool deepCopy) const
703 return new MEDCouplingTimeDiscretizationInt(*this,deepCopy);
706 MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::New(TypeOfTimeDiscretization type)
710 case MEDCouplingTimeDiscretizationInt::DISCRETIZATION:
711 return new MEDCouplingTimeDiscretizationInt;
713 throw INTERP_KERNEL::Exception("Time discretization not implemented yet for integers !");
717 bool MEDCouplingTimeDiscretizationInt::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<int> *other, int prec, std::string& reason) const
720 throw INTERP_KERNEL::Exception("isEqualIfNotWhy : only precision equal to 0 supported for int !");
723 reason="Time discretization is NULL.";
726 const MEDCouplingTimeDiscretizationInt *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationInt *>(other));
728 throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationInt !");
729 if(!MEDCouplingTimeDiscretizationTemplate<int>::areStrictlyCompatible(other,reason))
731 if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
733 if(_array==other->getArray())
735 return _array->isEqualIfNotWhy(*other->getArray(),reason);
738 bool MEDCouplingTimeDiscretizationInt::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<int> *other, int prec) const
741 throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationInt::isEqualWithoutConsideringStr : only precision 0 is supported !");
742 const MEDCouplingTimeDiscretizationInt *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationInt *>(other));
744 throw INTERP_KERNEL::Exception("isEqualWithoutConsideringStr : other is not a MEDCouplingTimeDiscretizationInt !");
746 if(!areStrictlyCompatible(other,tmp))
749 if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
751 if(_array==other->getArray())
753 return _array->isEqualWithoutConsideringStr(*(other->getArray()));
756 ////////////////////////
758 MEDCouplingTimeDiscretizationFloat::MEDCouplingTimeDiscretizationFloat(const MEDCouplingTimeDiscretizationFloat& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple<float>(other,deepCopy)
762 MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::performCopyOrIncrRef(bool deepCopy) const
764 return new MEDCouplingTimeDiscretizationFloat(*this,deepCopy);
767 MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::New(TypeOfTimeDiscretization type)
771 case MEDCouplingTimeDiscretizationFloat::DISCRETIZATION:
772 return new MEDCouplingTimeDiscretizationFloat;
774 throw INTERP_KERNEL::Exception("Time discretization not implemented yet for integers !");
778 bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec, std::string& reason) const
782 reason="Time discretization is NULL.";
785 const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationFloat *>(other));
787 throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationFloat !");
788 if(!MEDCouplingTimeDiscretizationTemplate<float>::areStrictlyCompatible(other,reason))
790 if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
792 if(_array==other->getArray())
794 return _array->isEqualIfNotWhy(*other->getArray(),prec,reason);
797 bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec) const
800 throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr : only precision 0 is supported !");
801 const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationFloat *>(other));
803 throw INTERP_KERNEL::Exception("isEqualWithoutConsideringStr : other is not a MEDCouplingTimeDiscretizationFloat !");
805 if(!areStrictlyCompatible(other,tmp))
808 if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
810 if(_array==other->getArray())
812 return _array->isEqualWithoutConsideringStr(*(other->getArray()),prec);
815 ////////////////////////
817 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel()
821 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretization& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy)
825 std::string MEDCouplingNoTimeLabel::getStringRepr() const
827 std::ostringstream stream;
829 stream << "\nTime unit is : \"" << getTimeUnit() << "\"";
833 void MEDCouplingNoTimeLabel::synchronizeTimeWith(const MEDCouplingMesh *mesh)
835 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::synchronizeTimeWith : impossible to synchronize time with a MEDCouplingMesh because the time discretization is incompatible with it !");
838 bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
840 if(!MEDCouplingTimeDiscretization::areCompatible(other))
842 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
846 bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
848 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
850 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
853 reason.insert(0,"time discretization of this is NO_TIME, other has a different time discretization.");
857 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
859 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
861 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
865 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
867 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
869 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
873 bool MEDCouplingNoTimeLabel::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
875 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
877 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
881 bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
883 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
886 reason="This has time discretization NO_TIME, other not.";
889 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
892 bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
894 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
897 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
900 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCouplingTimeDiscretization *other) const
902 const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
904 throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !");
905 MCAuto<DataArrayDouble> arr(DataArrayDouble::Aggregate(getArray(),other->getArray()));
906 MEDCouplingNoTimeLabel *ret(new MEDCouplingNoTimeLabel);
907 ret->setArray(arr,0);
911 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
913 std::vector<const DataArrayDouble *> a(other.size());
915 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
917 const MEDCouplingNoTimeLabel *itC=dynamic_cast<const MEDCouplingNoTimeLabel *>(*it);
919 throw INTERP_KERNEL::Exception("NoTimeLabel::aggregate on mismatched time discretization !");
920 a[i]=itC->getArray();
922 MCAuto<DataArrayDouble> arr(DataArrayDouble::Aggregate(a));
923 MEDCouplingNoTimeLabel *ret(new MEDCouplingNoTimeLabel);
924 ret->setArray(arr,0);
928 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::meld(const MEDCouplingTimeDiscretization *other) const
930 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
932 throw INTERP_KERNEL::Exception("NoTimeLabel::meld on mismatched time discretization !");
933 MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
934 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
935 ret->setTimeTolerance(getTimeTolerance());
936 ret->setArray(arr,0);
940 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::dot(const MEDCouplingTimeDiscretization *other) const
942 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
944 throw INTERP_KERNEL::Exception("NoTimeLabel::dot on mismatched time discretization !");
945 MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
946 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
947 ret->setArray(arr,0);
951 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::crossProduct(const MEDCouplingTimeDiscretization *other) const
953 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
955 throw INTERP_KERNEL::Exception("NoTimeLabel::crossProduct on mismatched time discretization !");
956 MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
957 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
958 ret->setArray(arr,0);
962 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::max(const MEDCouplingTimeDiscretization *other) const
964 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
966 throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
967 MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
968 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
969 ret->setArray(arr,0);
973 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::min(const MEDCouplingTimeDiscretization *other) const
975 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
977 throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
978 MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
979 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
980 ret->setArray(arr,0);
984 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::add(const MEDCouplingTimeDiscretization *other) const
986 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
988 throw INTERP_KERNEL::Exception("NoTimeLabel::add on mismatched time discretization !");
989 MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
990 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
991 ret->setArray(arr,0);
995 void MEDCouplingNoTimeLabel::addEqual(const MEDCouplingTimeDiscretization *other)
997 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
999 throw INTERP_KERNEL::Exception("NoTimeLabel::addEqual on mismatched time discretization !");
1001 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::addEqual : Data Array is NULL !");
1002 getArray()->addEqual(other->getArray());
1005 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::substract(const MEDCouplingTimeDiscretization *other) const
1007 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1009 throw INTERP_KERNEL::Exception("NoTimeLabel::substract on mismatched time discretization !");
1011 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substract : Data Array is NULL !");
1012 MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1013 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1014 ret->setArray(arr,0);
1018 void MEDCouplingNoTimeLabel::substractEqual(const MEDCouplingTimeDiscretization *other)
1020 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1022 throw INTERP_KERNEL::Exception("NoTimeLabel::substractEqual on mismatched time discretization !");
1024 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substractEqual : Data Array is NULL !");
1025 getArray()->substractEqual(other->getArray());
1028 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::multiply(const MEDCouplingTimeDiscretization *other) const
1030 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1032 throw INTERP_KERNEL::Exception("NoTimeLabel::multiply on mismatched time discretization !");
1033 MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1034 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1035 ret->setArray(arr,0);
1039 void MEDCouplingNoTimeLabel::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1041 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1043 throw INTERP_KERNEL::Exception("NoTimeLabel::multiplyEqual on mismatched time discretization !");
1045 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::multiplyEqual : Data Array is NULL !");
1046 getArray()->multiplyEqual(other->getArray());
1049 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::divide(const MEDCouplingTimeDiscretization *other) const
1051 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1053 throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
1054 MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1055 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1056 ret->setArray(arr,0);
1060 void MEDCouplingNoTimeLabel::divideEqual(const MEDCouplingTimeDiscretization *other)
1062 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1064 throw INTERP_KERNEL::Exception("NoTimeLabel::divideEqual on mismatched time discretization !");
1066 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::divideEqual : Data Array is NULL !");
1067 getArray()->divideEqual(other->getArray());
1070 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::pow(const MEDCouplingTimeDiscretization *other) const
1072 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1074 throw INTERP_KERNEL::Exception("pow on mismatched time discretization !");
1075 MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
1076 MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1077 ret->setArray(arr,0);
1081 void MEDCouplingNoTimeLabel::powEqual(const MEDCouplingTimeDiscretization *other)
1083 const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1085 throw INTERP_KERNEL::Exception("NoTimeLabel::powEqual on mismatched time discretization !");
1087 throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::powEqual : Data Array is NULL !");
1088 getArray()->powEqual(other->getArray());
1091 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCopyOrIncrRef(bool deepCopy) const
1093 return new MEDCouplingNoTimeLabel(*this,deepCopy);
1096 void MEDCouplingNoTimeLabel::checkTimePresence(double time) const
1098 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1101 std::vector< const DataArrayDouble *> MEDCouplingNoTimeLabel::getArraysForTime(double time) const
1103 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1106 void MEDCouplingNoTimeLabel::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1108 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1111 bool MEDCouplingNoTimeLabel::isBefore(const MEDCouplingTimeDiscretization *other) const
1113 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1116 bool MEDCouplingNoTimeLabel::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const
1118 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1121 double MEDCouplingNoTimeLabel::getStartTime(int& iteration, int& order) const
1123 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1126 double MEDCouplingNoTimeLabel::getEndTime(int& iteration, int& order) const
1128 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1131 void MEDCouplingNoTimeLabel::setStartIteration(int it)
1133 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1136 void MEDCouplingNoTimeLabel::setEndIteration(int it)
1138 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1141 void MEDCouplingNoTimeLabel::setStartOrder(int order)
1143 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1146 void MEDCouplingNoTimeLabel::setEndOrder(int order)
1148 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1151 void MEDCouplingNoTimeLabel::setStartTimeValue(double time)
1153 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1156 void MEDCouplingNoTimeLabel::setEndTimeValue(double time)
1158 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1161 void MEDCouplingNoTimeLabel::setStartTime(double time, int iteration, int order)
1163 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1166 void MEDCouplingNoTimeLabel::setEndTime(double time, int iteration, int order)
1168 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1171 void MEDCouplingNoTimeLabel::getValueOnTime(int eltId, double time, double *value) const
1173 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1176 void MEDCouplingNoTimeLabel::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1178 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1182 * idem getTinySerializationIntInformation except that it is for multi field fetch
1184 void MEDCouplingNoTimeLabel::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1190 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1192 void MEDCouplingNoTimeLabel::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1195 tinyInfo[0]=_time_tolerance;
1199 * idem finishUnserialization except that it is for multi field fetch
1201 void MEDCouplingNoTimeLabel::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1203 _time_tolerance=tinyInfoD[0];
1206 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy),_tk(other._tk)
1210 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep()
1214 std::string MEDCouplingWithTimeStep::getStringRepr() const
1216 std::ostringstream stream;
1217 stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
1218 stream << "\nTime unit is : \"" << getTimeUnit() << "\"";
1219 return stream.str();
1222 void MEDCouplingWithTimeStep::synchronizeTimeWith(const MEDCouplingMesh *mesh)
1225 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
1227 double val=mesh->getTime(it,order);
1228 _tk.setAllInfo(val,it,order);
1229 std::string tUnit(mesh->getTimeUnit());
1233 void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1235 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1236 tinyInfo.push_back(_tk.getIteration());
1237 tinyInfo.push_back(_tk.getOrder());
1240 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1242 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1243 tinyInfo.push_back(_tk.getTimeValue());
1246 void MEDCouplingWithTimeStep::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1248 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1249 _tk.setTimeValue(tinyInfoD[1]);
1250 _tk.setIteration(tinyInfoI[2]);
1251 _tk.setOrder(tinyInfoI[3]);
1255 * idem getTinySerializationIntInformation except that it is for multi field fetch
1257 void MEDCouplingWithTimeStep::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1260 tinyInfo[0]=_tk.getIteration();
1261 tinyInfo[1]=_tk.getOrder();
1265 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1267 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1270 tinyInfo[0]=_time_tolerance;
1271 tinyInfo[1]=_tk.getTimeValue();
1275 * idem finishUnserialization except that it is for multi field fetch
1277 void MEDCouplingWithTimeStep::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1279 _tk.setIteration(tinyInfoI[0]);
1280 _tk.setOrder(tinyInfoI[1]);
1281 _time_tolerance=tinyInfoD[0];
1282 _tk.setTimeValue(tinyInfoD[1]);
1285 bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1287 if(!MEDCouplingTimeDiscretization::areCompatible(other))
1289 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1293 bool MEDCouplingWithTimeStep::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
1295 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1297 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1300 reason.insert(0,"time discretization of this is ONE_TIME, other has a different time discretization.");
1304 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1306 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1308 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1312 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1314 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1316 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1320 bool MEDCouplingWithTimeStep::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1322 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1324 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1328 bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
1330 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1331 std::ostringstream oss; oss.precision(15);
1334 reason="This has time discretization ONE_TIME, other not.";
1337 if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
1339 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1342 bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
1344 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1347 if(!_tk.isEqual(otherC->_tk,_time_tolerance))
1349 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1352 void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
1354 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1355 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(&other);
1357 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::copyTinyAttrFrom : mismatch of time discretization !");
1358 _tk.copyFrom(otherC->_tk);
1361 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCouplingTimeDiscretization *other) const
1363 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1365 throw INTERP_KERNEL::Exception("WithTimeStep::aggregation on mismatched time discretization !");
1366 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1367 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1368 ret->setArray(arr,0);
1372 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1374 std::vector<const DataArrayDouble *> a(other.size());
1376 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1378 const MEDCouplingWithTimeStep *itC=dynamic_cast<const MEDCouplingWithTimeStep *>(*it);
1380 throw INTERP_KERNEL::Exception("WithTimeStep::aggregate on mismatched time discretization !");
1381 a[i]=itC->getArray();
1383 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1384 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1385 ret->setArray(arr,0);
1389 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::meld(const MEDCouplingTimeDiscretization *other) const
1391 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1393 throw INTERP_KERNEL::Exception("WithTimeStep::meld on mismatched time discretization !");
1394 MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1395 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1396 ret->setArray(arr,0);
1400 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::dot(const MEDCouplingTimeDiscretization *other) const
1402 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1404 throw INTERP_KERNEL::Exception("WithTimeStep::dot on mismatched time discretization !");
1405 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1406 MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1407 ret->setArray(arr,0);
1411 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::crossProduct(const MEDCouplingTimeDiscretization *other) const
1413 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1415 throw INTERP_KERNEL::Exception("WithTimeStep::crossProduct on mismatched time discretization !");
1416 MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1417 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1418 ret->setArray(arr,0);
1422 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::max(const MEDCouplingTimeDiscretization *other) const
1424 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1426 throw INTERP_KERNEL::Exception("WithTimeStep::max on mismatched time discretization !");
1427 MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1428 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1429 ret->setArray(arr,0);
1433 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::min(const MEDCouplingTimeDiscretization *other) const
1435 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1437 throw INTERP_KERNEL::Exception("WithTimeStep::min on mismatched time discretization !");
1438 MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1439 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1440 ret->setArray(arr,0);
1444 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::add(const MEDCouplingTimeDiscretization *other) const
1446 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1448 throw INTERP_KERNEL::Exception("WithTimeStep::add on mismatched time discretization !");
1449 MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1450 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1451 ret->setArray(arr,0);
1453 double tmp3=getStartTime(tmp1,tmp2);
1454 ret->setStartTime(tmp3,tmp1,tmp2);
1458 void MEDCouplingWithTimeStep::addEqual(const MEDCouplingTimeDiscretization *other)
1460 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1462 throw INTERP_KERNEL::Exception("WithTimeStep::addEqual on mismatched time discretization !");
1464 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::addEqual : Data Array is NULL !");
1465 getArray()->addEqual(other->getArray());
1468 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::substract(const MEDCouplingTimeDiscretization *other) const
1470 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1472 throw INTERP_KERNEL::Exception("WithTimeStep::substract on mismatched time discretization !");
1473 MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1474 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1475 ret->setArray(arr,0);
1477 double tmp3=getStartTime(tmp1,tmp2);
1478 ret->setStartTime(tmp3,tmp1,tmp2);
1482 void MEDCouplingWithTimeStep::substractEqual(const MEDCouplingTimeDiscretization *other)
1484 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1486 throw INTERP_KERNEL::Exception("WithTimeStep::substractEqual on mismatched time discretization !");
1488 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::substractEqual : Data Array is NULL !");
1489 getArray()->substractEqual(other->getArray());
1492 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::multiply(const MEDCouplingTimeDiscretization *other) const
1494 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1496 throw INTERP_KERNEL::Exception("WithTimeStep::multiply on mismatched time discretization !");
1497 MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1498 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1499 ret->setArray(arr,0);
1501 double tmp3=getStartTime(tmp1,tmp2);
1502 ret->setStartTime(tmp3,tmp1,tmp2);
1506 void MEDCouplingWithTimeStep::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1508 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1510 throw INTERP_KERNEL::Exception("WithTimeStep::multiplyEqual on mismatched time discretization !");
1512 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::multiplyEqual : Data Array is NULL !");
1513 getArray()->multiplyEqual(other->getArray());
1516 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::divide(const MEDCouplingTimeDiscretization *other) const
1518 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1520 throw INTERP_KERNEL::Exception("WithTimeStep::divide on mismatched time discretization !");
1521 MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1522 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1523 ret->setArray(arr,0);
1525 double tmp3=getStartTime(tmp1,tmp2);
1526 ret->setStartTime(tmp3,tmp1,tmp2);
1530 void MEDCouplingWithTimeStep::divideEqual(const MEDCouplingTimeDiscretization *other)
1532 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1534 throw INTERP_KERNEL::Exception("WithTimeStep::divideEqual on mismatched time discretization !");
1536 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::divideEqual : Data Array is NULL !");
1537 getArray()->divideEqual(other->getArray());
1540 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::pow(const MEDCouplingTimeDiscretization *other) const
1542 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1544 throw INTERP_KERNEL::Exception("WithTimeStep::pow on mismatched time discretization !");
1545 MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
1546 MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1547 ret->setArray(arr,0);
1549 double tmp3=getStartTime(tmp1,tmp2);
1550 ret->setStartTime(tmp3,tmp1,tmp2);
1554 void MEDCouplingWithTimeStep::powEqual(const MEDCouplingTimeDiscretization *other)
1556 const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1558 throw INTERP_KERNEL::Exception("WithTimeStep::powEqual on mismatched time discretization !");
1560 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::powEqual : Data Array is NULL !");
1561 getArray()->powEqual(other->getArray());
1564 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCopyOrIncrRef(bool deepCopy) const
1566 return new MEDCouplingWithTimeStep(*this,deepCopy);
1569 void MEDCouplingWithTimeStep::checkNoTimePresence() const
1571 throw INTERP_KERNEL::Exception("No time specified on a field defined on one time");
1574 void MEDCouplingWithTimeStep::checkTimePresence(double time) const
1576 _tk.checkTimePresence(time,_time_tolerance);
1579 std::vector< const DataArrayDouble *> MEDCouplingWithTimeStep::getArraysForTime(double time) const
1581 if(std::fabs(time-_tk.getTimeValue())<=_time_tolerance)
1583 std::vector< const DataArrayDouble *> ret(1);
1588 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1591 void MEDCouplingWithTimeStep::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1593 std::copy(vals.begin(),vals.end(),res);
1596 void MEDCouplingWithTimeStep::getValueOnTime(int eltId, double time, double *value) const
1598 if(std::fabs(time-_tk.getTimeValue())<=_time_tolerance)
1600 _array->getTuple(eltId,value);
1602 throw INTERP_KERNEL::Exception("No array existing.");
1604 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1607 void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1609 if(_tk.getIteration()==iteration && _tk.getOrder()==order)
1611 _array->getTuple(eltId,value);
1613 throw INTERP_KERNEL::Exception("No array existing.");
1615 throw INTERP_KERNEL::Exception("No data on this discrete time.");
1618 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval()
1622 void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
1624 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1625 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(&other);
1627 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::copyTinyAttrFrom : mismatch of time discretization !");
1628 _start.copyFrom(otherC->_start);
1629 _end.copyFrom(otherC->_end);
1632 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1634 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1635 tinyInfo.push_back(_start.getIteration());
1636 tinyInfo.push_back(_start.getOrder());
1637 tinyInfo.push_back(_end.getIteration());
1638 tinyInfo.push_back(_end.getOrder());
1641 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1643 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1644 tinyInfo.push_back(_start.getTimeValue());
1645 tinyInfo.push_back(_end.getTimeValue());
1648 void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1650 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1651 _start.setTimeValue(tinyInfoD[1]);
1652 _end.setTimeValue(tinyInfoD[2]);
1653 _start.setIteration(tinyInfoI[2]);
1654 _start.setOrder(tinyInfoI[3]);
1655 _end.setIteration(tinyInfoI[4]);
1656 _end.setOrder(tinyInfoI[5]);
1660 * idem getTinySerializationIntInformation except that it is for multi field fetch
1662 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1665 tinyInfo[0]=_start.getIteration();
1666 tinyInfo[1]=_start.getOrder();
1667 tinyInfo[2]=_end.getIteration();
1668 tinyInfo[3]=_end.getOrder();
1672 * idem getTinySerializationDbleInformation except that it is for multi field fetch
1674 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1677 tinyInfo[0]=_time_tolerance;
1678 tinyInfo[1]=_start.getTimeValue();
1679 tinyInfo[2]=_end.getTimeValue();
1683 * idem finishUnserialization except that it is for multi field fetch
1685 void MEDCouplingConstOnTimeInterval::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1687 _start.setIteration(tinyInfoI[0]);
1688 _start.setOrder(tinyInfoI[1]);
1689 _end.setIteration(tinyInfoI[2]);
1690 _end.setOrder(tinyInfoI[3]);
1691 _time_tolerance=tinyInfoD[0];
1692 _start.setTimeValue(tinyInfoD[1]);
1693 _end.setTimeValue(tinyInfoD[2]);
1696 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCopy):
1697 MEDCouplingTimeDiscretization(other,deepCopy),_start(other._start),_end(other._end)
1701 std::string MEDCouplingConstOnTimeInterval::getStringRepr() const
1703 std::ostringstream stream;
1704 stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n";
1705 stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n";
1706 stream << "\nTime unit is : \"" << getTimeUnit() << "\"";
1707 return stream.str();
1710 void MEDCouplingConstOnTimeInterval::synchronizeTimeWith(const MEDCouplingMesh *mesh)
1713 throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
1715 double val=mesh->getTime(it,order);
1716 _start.setAllInfo(val,it,order);
1717 _end.setAllInfo(val,it,order);
1718 std::string tUnit(mesh->getTimeUnit());
1722 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCopyOrIncrRef(bool deepCopy) const
1724 return new MEDCouplingConstOnTimeInterval(*this,deepCopy);
1727 std::vector< const DataArrayDouble *> MEDCouplingConstOnTimeInterval::getArraysForTime(double time) const
1729 if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
1731 std::vector< const DataArrayDouble *> ret(1);
1736 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1739 void MEDCouplingConstOnTimeInterval::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1741 std::copy(vals.begin(),vals.end(),res);
1744 bool MEDCouplingConstOnTimeInterval::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1746 if(!MEDCouplingTimeDiscretization::areCompatible(other))
1748 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1752 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
1754 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1756 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1759 reason.insert(0,"time discretization of this is CONST_ON_TIME_INTERVAL, other has a different time discretization.");
1763 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1765 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1767 const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1771 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1773 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1775 const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1779 bool MEDCouplingConstOnTimeInterval::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1781 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1783 const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1787 bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
1789 const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1790 std::ostringstream oss; oss.precision(15);
1793 reason="This has time discretization CONST_ON_TIME_INTERVAL, other not.";
1796 if(!_start.isEqualIfNotWhy(otherC->_start,_time_tolerance,reason))
1798 if(!_end.isEqualIfNotWhy(otherC->_end,_time_tolerance,reason))
1800 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1803 bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
1805 const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1808 if(!_start.isEqual(otherC->_start,_time_tolerance))
1810 if(!_end.isEqual(otherC->_end,_time_tolerance))
1812 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1815 void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, double *value) const
1817 if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
1819 _array->getTuple(eltId,value);
1821 throw INTERP_KERNEL::Exception("No array existing.");
1823 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1826 void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1828 if(iteration>=_start.getIteration() && iteration<=_end.getIteration())
1830 _array->getTuple(eltId,value);
1832 throw INTERP_KERNEL::Exception("No array existing.");
1834 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1837 void MEDCouplingConstOnTimeInterval::checkNoTimePresence() const
1839 throw INTERP_KERNEL::Exception("No time specified on a field defined as constant on one time interval");
1842 void MEDCouplingConstOnTimeInterval::checkTimePresence(double time) const
1844 if(time<_start.getTimeValue()-_time_tolerance || time>_end.getTimeValue()+_time_tolerance)
1846 std::ostringstream stream;
1847 stream << "The field is defined between times " << _start.getTimeValue() << " and " << _end.getTimeValue() << " worderh tolerance ";
1848 stream << _time_tolerance << " and trying to access on time = " << time;
1849 throw INTERP_KERNEL::Exception(stream.str().c_str());
1853 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const MEDCouplingTimeDiscretization *other) const
1855 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1857 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregation on mismatched time discretization !");
1858 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1859 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1860 ret->setArray(arr,0);
1864 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1866 std::vector<const DataArrayDouble *> a(other.size());
1868 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1870 const MEDCouplingConstOnTimeInterval *itC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(*it);
1872 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregate on mismatched time discretization !");
1873 a[i]=itC->getArray();
1875 MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1876 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1877 ret->setArray(arr,0);
1881 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::meld(const MEDCouplingTimeDiscretization *other) const
1883 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1885 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::meld on mismatched time discretization !");
1886 MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1887 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1888 ret->setTimeTolerance(getTimeTolerance());
1889 ret->setArray(arr,0);
1893 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::dot(const MEDCouplingTimeDiscretization *other) const
1895 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1897 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::dot on mismatched time discretization !");
1898 MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1899 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1900 ret->setArray(arr,0);
1904 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::crossProduct(const MEDCouplingTimeDiscretization *other) const
1906 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1908 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::crossProduct on mismatched time discretization !");
1909 MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1910 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1911 ret->setArray(arr,0);
1915 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::max(const MEDCouplingTimeDiscretization *other) const
1917 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1919 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::max on mismatched time discretization !");
1920 MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1921 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1922 ret->setArray(arr,0);
1926 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::min(const MEDCouplingTimeDiscretization *other) const
1928 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1930 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::min on mismatched time discretization !");
1931 MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1932 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1933 ret->setArray(arr,0);
1937 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::add(const MEDCouplingTimeDiscretization *other) const
1939 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1941 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::add on mismatched time discretization !");
1942 MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1943 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1944 ret->setArray(arr,0);
1946 double tmp3=getStartTime(tmp1,tmp2);
1947 ret->setStartTime(tmp3,tmp1,tmp2);
1948 tmp3=getEndTime(tmp1,tmp2);
1949 ret->setEndTime(tmp3,tmp1,tmp2);
1953 void MEDCouplingConstOnTimeInterval::addEqual(const MEDCouplingTimeDiscretization *other)
1955 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1957 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::addEqual on mismatched time discretization !");
1959 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractaddEqual : Data Array is NULL !");
1960 getArray()->addEqual(other->getArray());
1963 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::substract(const MEDCouplingTimeDiscretization *other) const
1965 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1967 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substract on mismatched time discretization !");
1968 MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1969 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1970 ret->setArray(arr,0);
1972 double tmp3=getStartTime(tmp1,tmp2);
1973 ret->setStartTime(tmp3,tmp1,tmp2);
1974 tmp3=getEndTime(tmp1,tmp2);
1975 ret->setEndTime(tmp3,tmp1,tmp2);
1979 void MEDCouplingConstOnTimeInterval::substractEqual(const MEDCouplingTimeDiscretization *other)
1981 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1983 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substractEqual on mismatched time discretization !");
1985 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractEqual : Data Array is NULL !");
1986 getArray()->substractEqual(other->getArray());
1989 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::multiply(const MEDCouplingTimeDiscretization *other) const
1991 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1993 throw INTERP_KERNEL::Exception("multiply on mismatched time discretization !");
1994 MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1995 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1996 ret->setArray(arr,0);
1998 double tmp3=getStartTime(tmp1,tmp2);
1999 ret->setStartTime(tmp3,tmp1,tmp2);
2000 tmp3=getEndTime(tmp1,tmp2);
2001 ret->setEndTime(tmp3,tmp1,tmp2);
2005 void MEDCouplingConstOnTimeInterval::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2007 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2009 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::multiplyEqual on mismatched time discretization !");
2011 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::multiplyEqual : Data Array is NULL !");
2012 getArray()->multiplyEqual(other->getArray());
2015 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::divide(const MEDCouplingTimeDiscretization *other) const
2017 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2019 throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
2020 MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
2021 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2022 ret->setArray(arr,0);
2024 double tmp3=getStartTime(tmp1,tmp2);
2025 ret->setStartTime(tmp3,tmp1,tmp2);
2026 tmp3=getEndTime(tmp1,tmp2);
2027 ret->setEndTime(tmp3,tmp1,tmp2);
2031 void MEDCouplingConstOnTimeInterval::divideEqual(const MEDCouplingTimeDiscretization *other)
2033 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2035 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::divideEqual on mismatched time discretization !");
2037 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::divideEqual : Data Array is NULL !");
2038 getArray()->divideEqual(other->getArray());
2041 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::pow(const MEDCouplingTimeDiscretization *other) const
2043 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2045 throw INTERP_KERNEL::Exception("pow on mismatched time discretization !");
2046 MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
2047 MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2048 ret->setArray(arr,0);
2050 double tmp3=getStartTime(tmp1,tmp2);
2051 ret->setStartTime(tmp3,tmp1,tmp2);
2052 tmp3=getEndTime(tmp1,tmp2);
2053 ret->setEndTime(tmp3,tmp1,tmp2);
2057 void MEDCouplingConstOnTimeInterval::powEqual(const MEDCouplingTimeDiscretization *other)
2059 const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2061 throw INTERP_KERNEL::Exception("ConstOnTimeInterval::powEqual on mismatched time discretization !");
2063 throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::powEqual : Data Array is NULL !");
2064 getArray()->powEqual(other->getArray());
2067 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy),
2068 _start(other._start),_end(other._end)
2070 if(other._end_array)
2071 _end_array=other._end_array->performCopyOrIncrRef(deepCopy);
2076 void MEDCouplingTwoTimeSteps::updateTime() const
2078 MEDCouplingTimeDiscretization::updateTime();
2080 updateTimeWith(*_end_array);
2083 void MEDCouplingTwoTimeSteps::synchronizeTimeWith(const MEDCouplingMesh *mesh)
2086 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
2088 double val=mesh->getTime(it,order);
2089 _start.setAllInfo(val,it,order);
2090 _end.setAllInfo(val,it,order);
2091 std::string tUnit(mesh->getTimeUnit());
2095 std::size_t MEDCouplingTwoTimeSteps::getHeapMemorySizeWithoutChildren() const
2097 return MEDCouplingTimeDiscretization::getHeapMemorySizeWithoutChildren();
2100 std::vector<const BigMemoryObject *> MEDCouplingTwoTimeSteps::getDirectChildrenWithNull() const
2102 std::vector<const BigMemoryObject *> ret(MEDCouplingTimeDiscretization::getDirectChildrenWithNull());
2103 ret.push_back(_end_array);
2107 void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
2109 MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
2110 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2112 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::copyTinyAttrFrom : mismatch of time discretization !");
2113 _start.copyFrom(otherC->_start);
2114 _end.copyFrom(otherC->_end);
2117 void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
2119 MEDCouplingTimeDiscretization::copyTinyStringsFrom(other);
2120 const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2122 throw INTERP_KERNEL::Exception("Trying to operate copyTinyStringsFrom on different field type (two times//one time) !");
2123 if(_end_array && otherC->_end_array)
2124 _end_array->copyStringInfoFrom(*otherC->_end_array);
2127 const DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray() const
2132 DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray()
2137 void MEDCouplingTwoTimeSteps::checkConsistencyLight() const
2139 MEDCouplingTimeDiscretization::checkConsistencyLight();
2141 throw INTERP_KERNEL::Exception("No end array specified !");
2142 if(_array->getNumberOfComponents()!=_end_array->getNumberOfComponents())
2143 throw INTERP_KERNEL::Exception("The number of components mismatch between the start and the end arrays !");
2144 if(_array->getNumberOfTuples()!=_end_array->getNumberOfTuples())
2145 throw INTERP_KERNEL::Exception("The number of tuples mismatch between the start and the end arrays !");
2148 bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
2150 std::ostringstream oss;
2151 const MEDCouplingTwoTimeSteps *otherC(dynamic_cast<const MEDCouplingTwoTimeSteps *>(other));
2154 reason="This has time discretization LINEAR_TIME, other not.";
2157 if(!_start.isEqualIfNotWhy(otherC->_start,_time_tolerance,reason))
2159 if(!_end.isEqualIfNotWhy(otherC->_end,_time_tolerance,reason))
2161 if(_end_array!=otherC->_end_array)
2162 if(!_end_array->isEqualIfNotWhy(*otherC->_end_array,prec,reason))
2164 reason.insert(0,"end arrays differ for linear time.");
2167 return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
2170 bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
2172 const MEDCouplingTwoTimeSteps *otherC(dynamic_cast<const MEDCouplingTwoTimeSteps *>(other));
2175 if(!_start.isEqual(otherC->_start,_time_tolerance))
2177 if(!_end.isEqual(otherC->_end,_time_tolerance))
2179 if(_end_array!=otherC->_end_array)
2180 if(!_end_array->isEqualWithoutConsideringStr(*otherC->_end_array,prec))
2182 return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
2185 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_end_array(0)
2189 MEDCouplingTwoTimeSteps::~MEDCouplingTwoTimeSteps()
2192 _end_array->decrRef();
2195 void MEDCouplingTwoTimeSteps::checkNoTimePresence() const
2197 throw INTERP_KERNEL::Exception("The field presents a time to be specified in every access !");
2200 void MEDCouplingTwoTimeSteps::checkTimePresence(double time) const
2202 if(time<_start.getTimeValue()-_time_tolerance || time>_end.getTimeValue()+_time_tolerance)
2204 std::ostringstream stream;
2205 stream << "The field is defined between times " << _start.getTimeValue() << " and " << _end.getTimeValue() << " worderh tolerance ";
2206 stream << _time_tolerance << " and trying to access on time = " << time;
2207 throw INTERP_KERNEL::Exception(stream.str().c_str());
2211 void MEDCouplingTwoTimeSteps::getArrays(std::vector<DataArrayDouble *>& arrays) const
2215 arrays[1]=_end_array;
2218 void MEDCouplingTwoTimeSteps::setEndArray(DataArrayDouble *array, TimeLabel *owner)
2220 if(array!=_end_array)
2223 _end_array->decrRef();
2226 _end_array->incrRef();
2228 owner->declareAsNew();
2232 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
2234 MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
2235 tinyInfo.push_back(_start.getIteration());
2236 tinyInfo.push_back(_start.getOrder());
2237 tinyInfo.push_back(_end.getIteration());
2238 tinyInfo.push_back(_end.getOrder());
2241 tinyInfo.push_back(_end_array->getNumberOfTuples());
2242 tinyInfo.push_back(_end_array->getNumberOfComponents());
2246 tinyInfo.push_back(-1);
2247 tinyInfo.push_back(-1);
2251 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
2253 MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
2254 tinyInfo.push_back(_start.getTimeValue());
2255 tinyInfo.push_back(_end.getTimeValue());
2258 void MEDCouplingTwoTimeSteps::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
2260 int nbOfCompo=_array->getNumberOfComponents();
2261 for(int i=0;i<nbOfCompo;i++)
2262 tinyInfo.push_back(_array->getInfoOnComponent(i));
2263 for(int i=0;i<nbOfCompo;i++)
2264 tinyInfo.push_back(_end_array->getInfoOnComponent(i));
2267 void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
2273 _end_array->decrRef();
2274 DataArrayDouble *arr=0;
2275 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2277 arr=DataArrayDouble::New();
2278 arr->alloc(tinyInfoI[0],tinyInfoI[1]);
2283 if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2285 arr=DataArrayDouble::New();
2286 arr->alloc(tinyInfoI[6],tinyInfoI[7]);
2292 void MEDCouplingTwoTimeSteps::checkForUnserialization(const std::vector<int>& tinyInfoI, const std::vector<DataArrayDouble *>& arrays)
2294 static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size two !";
2295 if(arrays.size()!=2)
2296 throw INTERP_KERNEL::Exception(MSG);
2300 _end_array->decrRef();
2301 _array=0; _end_array=0;
2302 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2305 throw INTERP_KERNEL::Exception(MSG);
2306 arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
2307 _array=arrays[0]; _array->incrRef();
2309 if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2312 throw INTERP_KERNEL::Exception(MSG);
2313 arrays[1]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
2314 _end_array=arrays[1]; _end_array->incrRef();
2318 void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
2320 MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
2321 _start.setTimeValue(tinyInfoD[1]);
2322 _end.setTimeValue(tinyInfoD[2]);
2323 _start.setIteration(tinyInfoI[2]);
2324 _start.setOrder(tinyInfoI[3]);
2325 _end.setIteration(tinyInfoI[4]);
2326 _end.setOrder(tinyInfoI[5]);
2330 * idem getTinySerializationIntInformation except that it is for multi field fetch
2332 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
2335 tinyInfo[0]=_start.getIteration();
2336 tinyInfo[1]=_start.getOrder();
2337 tinyInfo[2]=_end.getIteration();
2338 tinyInfo[3]=_end.getOrder();
2342 * idem getTinySerializationDbleInformation except that it is for multi field fetch
2344 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
2347 tinyInfo[0]=_time_tolerance;
2348 tinyInfo[1]=_start.getTimeValue();
2349 tinyInfo[2]=_end.getTimeValue();
2353 * idem finishUnserialization except that it is for multi field fetch
2355 void MEDCouplingTwoTimeSteps::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
2357 _start.setIteration(tinyInfoI[0]);
2358 _start.setOrder(tinyInfoI[1]);
2359 _end.setIteration(tinyInfoI[2]);
2360 _end.setOrder(tinyInfoI[3]);
2361 _time_tolerance=tinyInfoD[0];
2362 _start.setTimeValue(tinyInfoD[1]);
2363 _end.setTimeValue(tinyInfoD[2]);
2366 std::vector< const DataArrayDouble *> MEDCouplingTwoTimeSteps::getArraysForTime(double time) const
2368 if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
2370 std::vector< const DataArrayDouble *> ret(2);
2376 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2379 void MEDCouplingTwoTimeSteps::setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner)
2381 if(arrays.size()!=2)
2382 throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::setArrays : number of arrays must be two.");
2383 setArray(arrays.front(),owner);
2384 setEndArray(arrays.back(),owner);
2387 MEDCouplingLinearTime::MEDCouplingLinearTime(const MEDCouplingLinearTime& other, bool deepCopy):MEDCouplingTwoTimeSteps(other,deepCopy)
2391 MEDCouplingLinearTime::MEDCouplingLinearTime()
2395 std::string MEDCouplingLinearTime::getStringRepr() const
2397 std::ostringstream stream;
2398 stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n";
2399 stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n";
2400 stream << "Time unit is : \"" << getTimeUnit() << "\"";
2401 return stream.str();
2404 void MEDCouplingLinearTime::checkConsistencyLight() const
2406 MEDCouplingTwoTimeSteps::checkConsistencyLight();
2407 if(std::fabs(_start.getTimeValue()-_end.getTimeValue())<_time_tolerance)
2408 throw INTERP_KERNEL::Exception("Start time and end time are equals regarding time tolerance.");
2411 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::performCopyOrIncrRef(bool deepCopy) const
2413 return new MEDCouplingLinearTime(*this,deepCopy);
2416 bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2418 if(!MEDCouplingTimeDiscretization::areCompatible(other))
2420 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2423 if(_end_array==0 && otherC->_end_array==0)
2425 if(_end_array==0 || otherC->_end_array==0)
2427 if(_end_array->getNumberOfComponents()!=otherC->_end_array->getNumberOfComponents())
2432 bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
2434 if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
2436 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2439 reason.insert(0,"time discretization of this is LINEAR_TIME, other has a different time discretization.");
2443 bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2445 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
2447 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2451 bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2453 if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
2455 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2458 if(_end_array==0 && otherC->_end_array==0)
2460 if(_end_array==0 || otherC->_end_array==0)
2462 int nbC1=_end_array->getNumberOfComponents();
2463 int nbC2=otherC->_end_array->getNumberOfComponents();
2464 if(nbC1!=nbC2 && nbC2!=1)
2469 bool MEDCouplingLinearTime::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
2471 if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
2473 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2478 * vals is expected to be of size 2*_array->getNumberOfTuples()==_array->getNumberOfTuples()+_end_array->getNumberOfTuples()
2480 void MEDCouplingLinearTime::getValueForTime(double time, const std::vector<double>& vals, double *res) const
2482 double alpha=(_end.getTimeValue()-time)/(_end.getTimeValue()-_start.getTimeValue());
2483 std::size_t nbComp=vals.size()/2;
2484 std::transform(vals.begin(),vals.begin()+nbComp,res,std::bind2nd(std::multiplies<double>(),alpha));
2485 std::vector<double> tmp(nbComp);
2486 std::transform(vals.begin()+nbComp,vals.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2487 std::transform(tmp.begin(),tmp.end(),res,res,std::plus<double>());
2490 void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value) const
2492 double alpha=(_end.getTimeValue()-time)/(_end.getTimeValue()-_start.getTimeValue());
2495 _array->getTuple(eltId,value);
2497 throw INTERP_KERNEL::Exception("No start array existing.");
2498 nbComp=_array->getNumberOfComponents();
2499 std::transform(value,value+nbComp,value,std::bind2nd(std::multiplies<double>(),alpha));
2500 std::vector<double> tmp(nbComp);
2502 _end_array->getTuple(eltId,&tmp[0]);
2504 throw INTERP_KERNEL::Exception("No end array existing.");
2505 std::transform(tmp.begin(),tmp.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2506 std::transform(tmp.begin(),tmp.end(),value,value,std::plus<double>());
2509 void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
2511 if(iteration==_start.getIteration() && order==_start.getOrder())
2514 _array->getTuple(eltId,value);
2516 throw INTERP_KERNEL::Exception("iteration order match with start time but no start array existing.");
2518 if(iteration==_end.getIteration() && order==_end.getOrder())
2521 _end_array->getTuple(eltId,value);
2523 throw INTERP_KERNEL::Exception("iteration order match with end time but no end array existing.");
2526 throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2529 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const MEDCouplingTimeDiscretization *other) const
2531 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2533 throw INTERP_KERNEL::Exception("LinearTime::aggregation on mismatched time discretization !");
2534 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Aggregate(getArray(),other->getArray());
2535 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Aggregate(getEndArray(),other->getEndArray());
2536 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2537 ret->setArray(arr1,0);
2538 ret->setEndArray(arr2,0);
2542 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
2544 std::vector<const DataArrayDouble *> a(other.size());
2545 std::vector<const DataArrayDouble *> b(other.size());
2547 for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
2549 const MEDCouplingLinearTime *itC=dynamic_cast<const MEDCouplingLinearTime *>(*it);
2551 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::aggregate on mismatched time discretization !");
2552 a[i]=itC->getArray();
2553 b[i]=itC->getEndArray();
2555 MCAuto<DataArrayDouble> arr(DataArrayDouble::Aggregate(a)),arr2(DataArrayDouble::Aggregate(b));
2556 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2557 ret->setArray(arr,0);
2558 ret->setEndArray(arr2,0);
2562 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::meld(const MEDCouplingTimeDiscretization *other) const
2564 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2566 throw INTERP_KERNEL::Exception("LinearTime::meld on mismatched time discretization !");
2567 MCAuto<DataArrayDouble> arr1(DataArrayDouble::Meld(getArray(),other->getArray())),arr2(DataArrayDouble::Meld(getEndArray(),other->getEndArray()));
2568 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2569 ret->setTimeTolerance(getTimeTolerance());
2570 ret->setArray(arr1,0);
2571 ret->setEndArray(arr2,0);
2575 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeDiscretization *other) const
2577 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2579 throw INTERP_KERNEL::Exception("LinearTime::dot on mismatched time discretization !");
2580 MCAuto<DataArrayDouble> arr1(DataArrayDouble::Dot(getArray(),other->getArray())),arr2(DataArrayDouble::Dot(getEndArray(),other->getEndArray()));
2581 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2582 ret->setArray(arr1,0);
2583 ret->setEndArray(arr2,0);
2587 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::crossProduct(const MEDCouplingTimeDiscretization *other) const
2589 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2591 throw INTERP_KERNEL::Exception("LinearTime::crossProduct on mismatched time discretization !");
2592 MCAuto<DataArrayDouble> arr1(DataArrayDouble::CrossProduct(getArray(),other->getArray())),arr2(DataArrayDouble::CrossProduct(getEndArray(),other->getEndArray()));
2593 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2594 ret->setArray(arr1,0);
2595 ret->setEndArray(arr2,0);
2599 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::max(const MEDCouplingTimeDiscretization *other) const
2601 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2603 throw INTERP_KERNEL::Exception("LinearTime::max on mismatched time discretization !");
2604 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2605 MCAuto<DataArrayDouble> arr1(DataArrayDouble::Max(getArray(),other->getArray())),arr2(DataArrayDouble::Max(getEndArray(),other->getEndArray()));
2606 ret->setArray(arr1,0);
2607 ret->setEndArray(arr2,0);
2611 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::min(const MEDCouplingTimeDiscretization *other) const
2613 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2615 throw INTERP_KERNEL::Exception("LinearTime::min on mismatched time discretization !");
2616 MCAuto<DataArrayDouble> arr1(DataArrayDouble::Min(getArray(),other->getArray())),arr2(DataArrayDouble::Min(getEndArray(),other->getEndArray()));
2617 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2618 ret->setArray(arr1,0);
2619 ret->setEndArray(arr2,0);
2623 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::add(const MEDCouplingTimeDiscretization *other) const
2625 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2627 throw INTERP_KERNEL::Exception("LinearTime::add on mismatched time discretization !");
2628 MCAuto<DataArrayDouble> arr1(DataArrayDouble::Add(getArray(),other->getArray())),arr2(DataArrayDouble::Add(getEndArray(),other->getEndArray()));
2629 MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2630 ret->setArray(arr1,0);
2631 ret->setEndArray(arr2,0);
2635 void MEDCouplingLinearTime::addEqual(const MEDCouplingTimeDiscretization *other)
2637 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2639 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2641 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array is NULL !");
2643 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array (end) is NULL !");
2644 getArray()->addEqual(other->getArray());
2645 getEndArray()->addEqual(other->getEndArray());
2648 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::substract(const MEDCouplingTimeDiscretization *other) const
2650 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2652 throw INTERP_KERNEL::Exception("LinearTime::substract on mismatched time discretization !");
2653 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Substract(getArray(),other->getArray());
2654 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Substract(getEndArray(),other->getEndArray());
2655 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2656 ret->setArray(arr1,0);
2657 ret->setEndArray(arr2,0);
2661 void MEDCouplingLinearTime::substractEqual(const MEDCouplingTimeDiscretization *other)
2663 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2665 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2667 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array is NULL !");
2669 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array (end) is NULL !");
2670 getArray()->substractEqual(other->getArray());
2671 getEndArray()->substractEqual(other->getEndArray());
2674 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::multiply(const MEDCouplingTimeDiscretization *other) const
2676 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2678 throw INTERP_KERNEL::Exception("LinearTime::multiply on mismatched time discretization !");
2679 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Multiply(getArray(),other->getArray());
2680 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Multiply(getEndArray(),other->getEndArray());
2681 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2682 ret->setArray(arr1,0);
2683 ret->setEndArray(arr2,0);
2687 void MEDCouplingLinearTime::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2689 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2691 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2693 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array is NULL !");
2695 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array (end) is NULL !");
2696 getArray()->multiplyEqual(other->getArray());
2697 getEndArray()->multiplyEqual(other->getEndArray());
2700 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::divide(const MEDCouplingTimeDiscretization *other) const
2702 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2704 throw INTERP_KERNEL::Exception("LinearTime::divide on mismatched time discretization !");
2705 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Divide(getArray(),other->getArray());
2706 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Divide(getEndArray(),other->getEndArray());
2707 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2708 ret->setArray(arr1,0);
2709 ret->setEndArray(arr2,0);
2713 void MEDCouplingLinearTime::divideEqual(const MEDCouplingTimeDiscretization *other)
2715 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2717 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2719 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array is NULL !");
2721 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array (end) is NULL !");
2722 getArray()->divideEqual(other->getArray());
2723 getEndArray()->divideEqual(other->getEndArray());
2726 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::pow(const MEDCouplingTimeDiscretization *other) const
2728 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2730 throw INTERP_KERNEL::Exception("LinearTime::pow on mismatched time discretization !");
2731 MCAuto<DataArrayDouble> arr1=DataArrayDouble::Pow(getArray(),other->getArray());
2732 MCAuto<DataArrayDouble> arr2=DataArrayDouble::Pow(getEndArray(),other->getEndArray());
2733 MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2734 ret->setArray(arr1,0);
2735 ret->setEndArray(arr2,0);
2739 void MEDCouplingLinearTime::powEqual(const MEDCouplingTimeDiscretization *other)
2741 const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2743 throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2745 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array is NULL !");
2747 throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array (end) is NULL !");
2748 getArray()->powEqual(other->getArray());
2749 getEndArray()->powEqual(other->getEndArray());