Salome HOME
db9a43adef8cafdaa65f9ec89051a9f7523121a0
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingTimeDiscretization.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingTimeDiscretization.txx"
22 #include "MCAuto.hxx"
23 #include "MEDCouplingMemArray.hxx"
24 #include "MEDCouplingMesh.hxx"
25
26 #include <iterator>
27 #include <algorithm>
28 #include <functional>
29
30 using namespace MEDCoupling;
31
32 template class MEDCouplingTimeDiscretizationTemplate<double>;
33 template class MEDCouplingTimeDiscretizationTemplate<int>;
34
35 const char MEDCouplingTimeDiscretizationInt::REPR[]="One time label.";
36
37 const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setTime : no time info attached.";
38
39 const char MEDCouplingNoTimeLabel::REPR[]="No time label defined.";
40
41 const char MEDCouplingWithTimeStep::EXCEPTION_MSG[]="No data on this time.";
42
43 const char MEDCouplingWithTimeStep::REPR[]="One time label.";
44
45 const char MEDCouplingConstOnTimeInterval::EXCEPTION_MSG[]="No data on this time.";
46
47 const char MEDCouplingConstOnTimeInterval::REPR[]="Constant on a time interval.";
48
49 const char MEDCouplingTwoTimeSteps::EXCEPTION_MSG[]="No data on this time.";
50
51 const char MEDCouplingLinearTime::REPR[]="Linear time between 2 time steps.";
52
53 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDiscretization type)
54 {
55   switch(type)
56   {
57     case MEDCouplingNoTimeLabel::DISCRETIZATION:
58       return new MEDCouplingNoTimeLabel;
59     case MEDCouplingWithTimeStep::DISCRETIZATION:
60       return new MEDCouplingWithTimeStep;
61     case MEDCouplingConstOnTimeInterval::DISCRETIZATION:
62       return new MEDCouplingConstOnTimeInterval;
63     case MEDCouplingLinearTime::DISCRETIZATION:
64       return new MEDCouplingLinearTime;
65     default:
66       throw INTERP_KERNEL::Exception("Time discretization not implemented yet");
67   }
68 }
69
70 bool MEDCouplingTimeDiscretization::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
71 {
72   if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
73     return false;
74   if(_array==0 && other->_array==0)
75     return true;
76   if(_array==0 || other->_array==0)
77     return false;
78   if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
79     return false;
80   return true;
81 }
82
83 bool MEDCouplingTimeDiscretization::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
84 {
85   if(!areStrictlyCompatible(other,reason))
86     return false;
87   if(_array==other->_array)
88     return true;
89   return _array->isEqualIfNotWhy(*other->_array,prec,reason);
90 }
91
92 bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
93 {
94   std::string reason;
95   return isEqualIfNotWhy(other,prec,reason);
96 }
97
98 bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
99 {
100   std::string tmp;
101   if(!areStrictlyCompatible(other,tmp))
102     return false;
103   if(_array==other->_array)
104     return true;
105   return _array->isEqualWithoutConsideringStr(*other->_array,prec);
106 }
107
108 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(TypeOfTimeDiscretization type, bool deepCopy) const
109 {
110   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(type);
111   ret->setTimeUnit(getTimeUnit());
112   const DataArrayDouble *arrSrc=getArray();
113   MCAuto<DataArrayDouble> arr;
114   if(arrSrc)
115     arr=arrSrc->performCopyOrIncrRef(deepCopy);
116   ret->setArray(arr,0);
117   return ret;
118 }
119
120 void MEDCouplingTimeDiscretization::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
121 {
122   if(_array)
123     {
124       tinyInfo.push_back(_array->getNumberOfTuples());
125       tinyInfo.push_back(_array->getNumberOfComponents());
126     }
127   else
128     {
129       tinyInfo.push_back(-1);
130       tinyInfo.push_back(-1);
131     }
132 }
133
134 void MEDCouplingTimeDiscretization::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
135 {
136   arrays.resize(1);
137   if(_array!=0)
138     _array->decrRef();
139   DataArrayDouble *arr=0;
140   if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
141     {
142       arr=DataArrayDouble::New();
143       arr->alloc(tinyInfoI[0],tinyInfoI[1]);
144     }
145   _array=arr;
146   arrays[0]=arr;
147 }
148
149 void MEDCouplingTimeDiscretization::checkForUnserialization(const std::vector<int>& tinyInfoI, const std::vector<DataArrayDouble *>& arrays)
150 {
151   static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size one !";
152   if(arrays.size()!=1)
153     throw INTERP_KERNEL::Exception(MSG);
154   if(_array!=0)
155     _array->decrRef();
156   _array=0;
157   if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
158     {
159       if(!arrays[0])
160         throw INTERP_KERNEL::Exception(MSG);
161       arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
162       _array=arrays[0];
163       _array->incrRef();
164     }
165 }
166
167 void MEDCouplingTimeDiscretization::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
168 {
169   _time_tolerance=tinyInfoD[0];
170   int nbOfCompo=_array->getNumberOfComponents();
171   for(int i=0;i<nbOfCompo;i++)
172     _array->setInfoOnComponent(i,tinyInfoS[i]);
173 }
174
175 void MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
176 {
177   tinyInfo.push_back(_time_tolerance);
178 }
179
180 void MEDCouplingTimeDiscretization::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
181 {
182   int nbOfCompo=_array->getNumberOfComponents();
183   for(int i=0;i<nbOfCompo;i++)
184     tinyInfo.push_back(_array->getInfoOnComponent(i));
185 }
186
187 const DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray() const
188 {
189   throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
190 }
191
192 DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray()
193 {
194   throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
195 }
196
197 void MEDCouplingTimeDiscretization::setEndArray(DataArrayDouble *array, TimeLabel *owner)
198 {
199   throw INTERP_KERNEL::Exception("setEndArray not available for this type of time discretization !");
200 }
201
202 void MEDCouplingTimeDiscretization::setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner)
203 {
204   if(arrays.size()!=1)
205     throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretization::setArrays : number of arrays must be one.");
206   setArray(arrays.back(),owner);
207 }
208
209 void MEDCouplingTimeDiscretization::getArrays(std::vector<DataArrayDouble *>& arrays) const
210 {
211   arrays.resize(1);
212   arrays[0]=_array;
213 }
214
215 bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const
216 {
217   int iteration,order;
218   double time1=getEndTime(iteration,order)-_time_tolerance;
219   double time2=other->getStartTime(iteration,order)+other->getTimeTolerance();
220   return time1<=time2;
221 }
222
223 bool MEDCouplingTimeDiscretization::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const
224 {
225   int iteration,order;
226   double time1=getEndTime(iteration,order)+_time_tolerance;
227   double time2=other->getStartTime(iteration,order)-other->getTimeTolerance();
228   return time1<time2;
229 }
230
231 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedProduct() const
232 {
233   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
234   ret->setTimeUnit(getTimeUnit());
235   std::vector<DataArrayDouble *> arrays;
236   getArrays(arrays);
237   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
238   for(std::size_t j=0;j<arrays.size();j++)
239     {
240       if(arrays[j])
241         arrays2[j]=arrays[j]->doublyContractedProduct();
242       else
243         arrays2[j]=0;
244     }
245   std::vector<DataArrayDouble *> arrays3(arrays.size());
246   for(std::size_t j=0;j<arrays.size();j++)
247     arrays3[j]=arrays2[j];
248   ret->setArrays(arrays3,0);
249   return ret;
250 }
251
252 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() const
253 {
254   std::vector<DataArrayDouble *> arrays;
255   getArrays(arrays);
256   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
257   for(std::size_t j=0;j<arrays.size();j++)
258     {
259       if(arrays[j])
260         arrays2[j]=arrays[j]->determinant();
261       else
262         arrays2[j]=0;
263     }
264   std::vector<DataArrayDouble *> arrays3(arrays.size());
265   for(std::size_t j=0;j<arrays.size();j++)
266     arrays3[j]=arrays2[j];
267   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
268   ret->setTimeUnit(getTimeUnit());
269   ret->setArrays(arrays3,0);
270   return ret;
271 }
272
273 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() const
274 {
275   std::vector<DataArrayDouble *> arrays;
276   getArrays(arrays);
277   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
278   for(std::size_t j=0;j<arrays.size();j++)
279     {
280       if(arrays[j])
281         arrays2[j]=arrays[j]->eigenValues();
282       else
283         arrays2[j]=0;
284     }
285   std::vector<DataArrayDouble *> arrays3(arrays.size());
286   for(std::size_t j=0;j<arrays.size();j++)
287     arrays3[j]=arrays2[j];
288   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
289   ret->setTimeUnit(getTimeUnit());
290   ret->setArrays(arrays3,0);
291   return ret;
292 }
293
294 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() const
295 {
296   std::vector<DataArrayDouble *> arrays;
297   getArrays(arrays);
298   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
299   for(std::size_t j=0;j<arrays.size();j++)
300     {
301       if(arrays[j])
302         arrays2[j]=arrays[j]->eigenVectors();
303       else
304         arrays2[j]=0;
305     }
306   std::vector<DataArrayDouble *> arrays3(arrays.size());
307   for(std::size_t j=0;j<arrays.size();j++)
308     arrays3[j]=arrays2[j];
309   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
310   ret->setTimeUnit(getTimeUnit());
311   ret->setArrays(arrays3,0);
312   return ret;
313 }
314
315 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const
316 {
317   std::vector<DataArrayDouble *> arrays;
318   getArrays(arrays);
319   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
320   for(std::size_t j=0;j<arrays.size();j++)
321     {
322       if(arrays[j])
323         arrays2[j]=arrays[j]->inverse();
324       else
325         arrays2[j]=0;
326     }
327   std::vector<DataArrayDouble *> arrays3(arrays.size());
328   for(std::size_t j=0;j<arrays.size();j++)
329     arrays3[j]=arrays2[j];
330   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
331   ret->setTimeUnit(getTimeUnit());
332   ret->setArrays(arrays3,0);
333   return ret;
334 }
335
336 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const
337 {
338   std::vector<DataArrayDouble *> arrays;
339   getArrays(arrays);
340   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
341   for(std::size_t j=0;j<arrays.size();j++)
342     {
343       if(arrays[j])
344         arrays2[j]=arrays[j]->trace();
345       else
346         arrays2[j]=0;
347     }
348   std::vector<DataArrayDouble *> arrays3(arrays.size());
349   for(std::size_t j=0;j<arrays.size();j++)
350     arrays3[j]=arrays2[j];
351   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
352   ret->setTimeUnit(getTimeUnit());
353   ret->setArrays(arrays3,0);
354   return ret;
355 }
356
357 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const
358 {
359   std::vector<DataArrayDouble *> arrays;
360   getArrays(arrays);
361   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
362   for(std::size_t j=0;j<arrays.size();j++)
363     {
364       if(arrays[j])
365         arrays2[j]=arrays[j]->deviator();
366       else
367         arrays2[j]=0;
368     }
369   std::vector<DataArrayDouble *> arrays3(arrays.size());
370   for(std::size_t j=0;j<arrays.size();j++)
371     arrays3[j]=arrays2[j];
372   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
373   ret->setTimeUnit(getTimeUnit());
374   ret->setArrays(arrays3,0);
375   return ret;
376 }
377
378 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const
379 {
380   std::vector<DataArrayDouble *> arrays;
381   getArrays(arrays);
382   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
383   for(std::size_t j=0;j<arrays.size();j++)
384     {
385       if(arrays[j])
386         arrays2[j]=arrays[j]->magnitude();
387       else
388         arrays2[j]=0;
389     }
390   std::vector<DataArrayDouble *> arrays3(arrays.size());
391   for(std::size_t j=0;j<arrays.size();j++)
392     arrays3[j]=arrays2[j];
393   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
394   ret->setTimeUnit(getTimeUnit());
395   ret->setArrays(arrays3,0);
396   return ret;
397 }
398
399 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::negate() const
400 {
401   std::vector<DataArrayDouble *> arrays;
402   getArrays(arrays);
403   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
404   for(std::size_t j=0;j<arrays.size();j++)
405     {
406       if(arrays[j])
407         arrays2[j]=arrays[j]->negate();
408       else
409         arrays2[j]=0;
410     }
411   std::vector<DataArrayDouble *> arrays3(arrays.size());
412   for(std::size_t j=0;j<arrays.size();j++)
413     arrays3[j]=arrays2[j];
414   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
415   ret->setTimeUnit(getTimeUnit());
416   ret->setArrays(arrays3,0);
417   return ret;
418 }
419
420 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() const
421 {
422   std::vector<DataArrayDouble *> arrays;
423   getArrays(arrays);
424   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
425   for(std::size_t j=0;j<arrays.size();j++)
426     {
427       if(arrays[j])
428         arrays2[j]=arrays[j]->maxPerTuple();
429       else
430         arrays2[j]=0;
431     }
432   std::vector<DataArrayDouble *> arrays3(arrays.size());
433   for(std::size_t j=0;j<arrays.size();j++)
434     arrays3[j]=arrays2[j];
435   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
436   ret->setTimeUnit(getTimeUnit());
437   ret->setArrays(arrays3,0);
438   return ret;
439 }
440
441 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedComponents(const std::vector<int>& compoIds) const
442 {
443   std::vector<DataArrayDouble *> arrays;
444   getArrays(arrays);
445   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
446   for(std::size_t j=0;j<arrays.size();j++)
447     {
448       if(arrays[j])
449         arrays2[j]=static_cast<DataArrayDouble *>(arrays[j]->keepSelectedComponents(compoIds));
450       else
451         arrays2[j]=0;
452     }
453   std::vector<DataArrayDouble *> arrays3(arrays.size());
454   for(std::size_t j=0;j<arrays.size();j++)
455     arrays3[j]=arrays2[j];
456   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum());
457   ret->setTimeUnit(getTimeUnit());
458   ret->setArrays(arrays3,0);
459   return ret;
460 }
461
462 void MEDCouplingTimeDiscretization::setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector<int>& compoIds)
463 {
464   std::vector<DataArrayDouble *> arrays1,arrays2;
465   getArrays(arrays1);
466   other->getArrays(arrays2);
467   if(arrays1.size()!=arrays2.size())
468     throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : number of arrays mismatch !");
469   for(std::size_t i=0;i<arrays1.size();i++)
470     {
471       if(arrays1[i]!=0 && arrays2[i]!=0)
472         arrays1[i]->setSelectedComponents(arrays2[i],compoIds);
473       else if(arrays1[i]!=0 || arrays2[i]!=0)
474         throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : some time array in correspondance are not defined symetrically !");
475     }
476 }
477
478 void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double dftValue)
479 {
480   std::vector<DataArrayDouble *> arrays;
481   getArrays(arrays);
482   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
483   for(std::size_t j=0;j<arrays.size();j++)
484     {
485       if(arrays[j])
486         arrays2[j]=arrays[j]->changeNbOfComponents(newNbOfComp,dftValue);
487       else
488         arrays2[j]=0;
489     }
490   std::vector<DataArrayDouble *> arrays3(arrays.size());
491   for(std::size_t j=0;j<arrays.size();j++)
492     arrays3[j]=arrays2[j];
493   setArrays(arrays3,0);
494 }
495
496 void MEDCouplingTimeDiscretization::sortPerTuple(bool asc)
497 {
498   std::vector<DataArrayDouble *> arrays;
499   getArrays(arrays);
500   for(std::size_t j=0;j<arrays.size();j++)
501     {
502       if(arrays[j])
503         arrays[j]->sortPerTuple(asc);
504     }
505 }
506
507 void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, int nbOfCompo, double value)
508 {
509   std::vector<DataArrayDouble *> arrays;
510   getArrays(arrays);
511   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
512   for(std::size_t j=0;j<arrays.size();j++)
513     {
514       if(arrays[j])
515         {
516           arrays2[j]=arrays[j]->changeNbOfComponents(nbOfCompo,value);
517           arrays2[j]->fillWithValue(value);
518         }
519       else
520         {
521           arrays2[j]=DataArrayDouble::New();
522           arrays2[j]->alloc(nbOfTuple,nbOfCompo);
523           arrays2[j]->fillWithValue(value);
524         }
525     }
526   std::vector<DataArrayDouble *> arrays3(arrays.size());
527   for(std::size_t j=0;j<arrays.size();j++)
528     arrays3[j]=arrays2[j];
529   setArrays(arrays3,0);
530 }
531
532 void MEDCouplingTimeDiscretization::setOrCreateUniformValueOnAllComponents(int nbOfTuple, double value)
533 {
534   std::vector<DataArrayDouble *> arrays;
535   getArrays(arrays);
536   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
537   bool newArr=false;
538   for(std::size_t j=0;j<arrays.size();j++)
539     {
540       if(arrays[j])
541         {
542           arrays2[j]=arrays[j]; arrays2[j]->incrRef();
543           arrays2[j]->fillWithValue(value);
544         }
545       else
546         {
547           newArr=true;
548           arrays2[j]=DataArrayDouble::New();
549           arrays2[j]->alloc(nbOfTuple,1);
550           arrays2[j]->fillWithValue(value);
551         }
552     }
553   if(newArr)
554     {
555       std::vector<DataArrayDouble *> arrays3(arrays.size());
556       for(std::size_t j=0;j<arrays.size();j++)
557         arrays3[j]=arrays2[j];
558       setArrays(arrays3,0);
559     }
560 }
561
562 void MEDCouplingTimeDiscretization::applyLin(double a, double b, int compoId)
563 {
564   std::vector<DataArrayDouble *> arrays;
565   getArrays(arrays);
566   for(std::size_t j=0;j<arrays.size();j++)
567     {
568       if(arrays[j])
569         arrays[j]->applyLin(a,b,compoId);
570     }
571 }
572
573 void MEDCouplingTimeDiscretization::applyLin(double a, double b)
574 {
575   std::vector<DataArrayDouble *> arrays;
576   getArrays(arrays);
577   for(std::size_t j=0;j<arrays.size();j++)
578     {
579       if(arrays[j])
580         arrays[j]->applyLin(a,b);
581     }
582 }
583
584 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate func)
585 {
586   std::vector<DataArrayDouble *> arrays;
587   getArrays(arrays);
588   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
589   for(std::size_t j=0;j<arrays.size();j++)
590     {
591       if(arrays[j])
592         arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
593       else
594         arrays2[j]=0;
595     }
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);
600 }
601
602 void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const std::string& func)
603 {
604   std::vector<DataArrayDouble *> arrays;
605   getArrays(arrays);
606   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
607   for(std::size_t j=0;j<arrays.size();j++)
608     {
609       if(arrays[j])
610         arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
611       else
612         arrays2[j]=0;
613     }
614   std::vector<DataArrayDouble *> arrays3(arrays.size());
615   for(std::size_t j=0;j<arrays.size();j++)
616     arrays3[j]=arrays2[j];
617   setArrays(arrays3,0);
618 }
619
620 void MEDCouplingTimeDiscretization::applyFuncCompo(int nbOfComp, const std::string& func)
621 {
622   std::vector<DataArrayDouble *> arrays;
623   getArrays(arrays);
624   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
625   for(std::size_t j=0;j<arrays.size();j++)
626     {
627       if(arrays[j])
628         arrays2[j]=arrays[j]->applyFuncCompo(nbOfComp,func);
629       else
630         arrays2[j]=0;
631     }
632   std::vector<DataArrayDouble *> arrays3(arrays.size());
633   for(std::size_t j=0;j<arrays.size();j++)
634     arrays3[j]=arrays2[j];
635   setArrays(arrays3,0);
636 }
637
638 void MEDCouplingTimeDiscretization::applyFuncNamedCompo(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
639 {
640   std::vector<DataArrayDouble *> arrays;
641   getArrays(arrays);
642   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
643   for(std::size_t j=0;j<arrays.size();j++)
644     {
645       if(arrays[j])
646         arrays2[j]=arrays[j]->applyFuncNamedCompo(nbOfComp,varsOrder,func);
647       else
648         arrays2[j]=0;
649     }
650   std::vector<DataArrayDouble *> arrays3(arrays.size());
651   for(std::size_t j=0;j<arrays.size();j++)
652     arrays3[j]=arrays2[j];
653   setArrays(arrays3,0);
654 }
655
656 void MEDCouplingTimeDiscretization::applyFunc(const std::string& func)
657 {
658   std::vector<DataArrayDouble *> arrays;
659   getArrays(arrays);
660   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
661   for(std::size_t j=0;j<arrays.size();j++)
662     {
663       if(arrays[j])
664         arrays2[j]=arrays[j]->applyFunc(func);
665       else
666         arrays2[j]=0;
667     }
668   std::vector<DataArrayDouble *> arrays3(arrays.size());
669   for(std::size_t j=0;j<arrays.size();j++)
670     arrays3[j]=arrays2[j];
671   setArrays(arrays3,0);
672 }
673
674 void MEDCouplingTimeDiscretization::applyFuncFast32(const std::string& func)
675 {
676   std::vector<DataArrayDouble *> arrays;
677   getArrays(arrays);
678   for(std::size_t j=0;j<arrays.size();j++)
679     {
680       if(arrays[j])
681         arrays[j]->applyFuncFast32(func);
682     }
683 }
684
685 void MEDCouplingTimeDiscretization::applyFuncFast64(const std::string& func)
686 {
687   std::vector<DataArrayDouble *> arrays;
688   getArrays(arrays);
689   for(std::size_t j=0;j<arrays.size();j++)
690     {
691       if(arrays[j])
692         arrays[j]->applyFuncFast64(func);
693     }
694 }
695
696 void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, FunctionToEvaluate func)
697 {
698   std::vector<DataArrayDouble *> arrays;
699   getArrays(arrays);
700   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
701   for(std::size_t j=0;j<arrays.size();j++)
702     arrays2[j]=loc->applyFunc(nbOfComp,func);
703   std::vector<DataArrayDouble *> arrays3(arrays.size());
704   for(std::size_t j=0;j<arrays.size();j++)
705     arrays3[j]=arrays2[j];
706   setArrays(arrays3,0);
707 }
708
709 void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, int nbOfComp, const std::string& func)
710 {
711   std::vector<DataArrayDouble *> arrays;
712   getArrays(arrays);
713   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
714   for(std::size_t j=0;j<arrays.size();j++)
715     arrays2[j]=loc->applyFunc(nbOfComp,func);
716   std::vector<DataArrayDouble *> arrays3(arrays.size());
717   for(std::size_t j=0;j<arrays.size();j++)
718     arrays3[j]=arrays2[j];
719   setArrays(arrays3,0);
720 }
721
722 void MEDCouplingTimeDiscretization::fillFromAnalyticCompo(const DataArrayDouble *loc, int nbOfComp, const std::string& func)
723 {
724   std::vector<DataArrayDouble *> arrays;
725   getArrays(arrays);
726   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
727   for(std::size_t j=0;j<arrays.size();j++)
728     arrays2[j]=loc->applyFuncCompo(nbOfComp,func);
729   std::vector<DataArrayDouble *> arrays3(arrays.size());
730   for(std::size_t j=0;j<arrays.size();j++)
731     arrays3[j]=arrays2[j];
732   setArrays(arrays3,0);
733 }
734
735 void MEDCouplingTimeDiscretization::fillFromAnalyticNamedCompo(const DataArrayDouble *loc, int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
736 {
737   std::vector<DataArrayDouble *> arrays;
738   getArrays(arrays);
739   std::vector< MCAuto<DataArrayDouble> > arrays2(arrays.size());
740   for(std::size_t j=0;j<arrays.size();j++)
741     arrays2[j]=loc->applyFuncNamedCompo(nbOfComp,varsOrder,func);
742   std::vector<DataArrayDouble *> arrays3(arrays.size());
743   for(std::size_t j=0;j<arrays.size();j++)
744     arrays3[j]=arrays2[j];
745   setArrays(arrays3,0);
746 }
747
748 ////////////////////////
749
750 bool MEDCouplingTimeKeeper::isEqualIfNotWhy(const MEDCouplingTimeKeeper& other, double prec, std::string& reason) const
751 {
752   std::ostringstream oss;
753   if(_iteration!=other._iteration)
754     {
755       oss << "iterations differ. this iteration=" << _iteration << " other iteration=" << other._iteration;
756       reason=oss.str();
757       return false;
758     }
759   if(_order!=other._order)
760     {
761       oss << "orders differ. this order=" << _order << " other order=" << other._order;
762       reason=oss.str();
763       return false;
764     }
765   if(std::fabs(_time-other._time)>prec)
766     {
767       oss << "times differ. this time=" << _time << " other time=" << other._time;
768       reason=oss.str();
769       return false;
770     }
771   return true;
772 }
773
774 bool MEDCouplingTimeKeeper::isEqual(const MEDCouplingTimeKeeper& other, double prec) const
775 {
776   if(_iteration!=other._iteration)
777     return false;
778   if(_order!=other._order)
779     return false;
780   if(std::fabs(_time-other._time)>prec)
781     return false;
782   return true;
783 }
784
785 void MEDCouplingTimeKeeper::copyFrom(const MEDCouplingTimeKeeper& other)
786 {
787   _time=other._time;
788   _iteration=other._iteration;
789   _order=other._order;
790 }
791
792 void MEDCouplingTimeKeeper::checkTimePresence(double time, double eps) const
793 {
794   if(std::fabs(time-_time)>eps)
795     {
796       std::ostringstream stream;
797       stream << "The field is defined on time " << _time << " with eps=" << eps << " and asking time = " << time << " !";
798       throw INTERP_KERNEL::Exception(stream.str().c_str());
799     }
800 }
801
802 ////////////////////////
803
804 MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt()
805 {
806 }
807
808 MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate<int>(other,deepCopy)
809 {
810 }
811
812 std::string MEDCouplingTimeDiscretizationInt::getStringRepr() const
813 {
814   std::ostringstream stream;
815   stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
816   stream << "\nTime unit is : \"" << _time_unit << "\"";
817   return stream.str();
818 }
819
820 MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::performCopyOrIncrRef(bool deepCopy) const
821 {
822   return new MEDCouplingTimeDiscretizationInt(*this,deepCopy);
823 }
824
825 MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::New(TypeOfTimeDiscretization type)
826 {
827   switch(type)
828   {
829     case MEDCouplingTimeDiscretizationInt::DISCRETIZATION:
830       return new MEDCouplingTimeDiscretizationInt;
831     default:
832       throw INTERP_KERNEL::Exception("Time discretization not implemented yet for intergers !");
833   }
834 }
835
836
837 ////////////////////////
838
839 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel()
840 {
841 }
842
843 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretization& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy)
844 {
845 }
846
847 std::string MEDCouplingNoTimeLabel::getStringRepr() const
848 {
849   std::ostringstream stream;
850   stream << REPR;
851   stream << "\nTime unit is : \"" << _time_unit << "\"";
852   return stream.str();
853 }
854
855 void MEDCouplingNoTimeLabel::synchronizeTimeWith(const MEDCouplingMesh *mesh)
856 {
857   throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::synchronizeTimeWith : impossible to synchronize time with a MEDCouplingMesh because the time discretization is incompatible with it !");
858 }
859
860 bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
861 {
862   if(!MEDCouplingTimeDiscretization::areCompatible(other))
863     return false;
864   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
865   return otherC!=0;
866 }
867
868 bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
869 {
870   if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
871     return false;
872   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
873   bool ret=otherC!=0;
874   if(!ret)
875     reason.insert(0,"time discretization of this is NO_TIME, other has a different time discretization.");
876   return ret;
877 }
878
879 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
880 {
881   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
882     return false;
883   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
884   return otherC!=0;
885 }
886
887 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
888 {
889   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
890     return false;
891   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
892   return otherC!=0;
893 }
894
895 bool MEDCouplingNoTimeLabel::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
896 {
897   if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
898     return false;
899   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
900   return otherC!=0;
901 }
902
903 bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
904 {
905   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
906   if(!otherC)
907     {
908       reason="This has time discretization NO_TIME, other not.";
909       return false;
910     }
911   return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
912 }
913
914 bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
915 {
916   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
917   if(!otherC)
918     return false;
919   return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
920 }
921
922 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCouplingTimeDiscretization *other) const
923 {
924   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
925   if(!otherC)
926     throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !");
927   MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
928   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
929   ret->setArray(arr,0);
930   return ret;
931 }
932
933 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
934 {
935   std::vector<const DataArrayDouble *> a(other.size());
936   int i=0;
937   for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
938     {
939       const MEDCouplingNoTimeLabel *itC=dynamic_cast<const MEDCouplingNoTimeLabel *>(*it);
940       if(!itC)
941         throw INTERP_KERNEL::Exception("NoTimeLabel::aggregate on mismatched time discretization !");
942       a[i]=itC->getArray();
943     }
944   MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
945   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
946   ret->setArray(arr,0);
947   return ret;
948 }
949
950 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::meld(const MEDCouplingTimeDiscretization *other) const
951 {
952   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
953   if(!otherC)
954     throw INTERP_KERNEL::Exception("NoTimeLabel::meld on mismatched time discretization !");
955   MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
956   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
957   ret->setTimeTolerance(getTimeTolerance());
958   ret->setArray(arr,0);
959   return ret;
960 }
961
962 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::dot(const MEDCouplingTimeDiscretization *other) const
963 {
964   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
965   if(!otherC)
966     throw INTERP_KERNEL::Exception("NoTimeLabel::dot on mismatched time discretization !");
967   MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
968   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
969   ret->setArray(arr,0);
970   return ret;
971 }
972
973 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::crossProduct(const MEDCouplingTimeDiscretization *other) const
974 {
975   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
976   if(!otherC)
977     throw INTERP_KERNEL::Exception("NoTimeLabel::crossProduct on mismatched time discretization !");
978   MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
979   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
980   ret->setArray(arr,0);
981   return ret;
982 }
983
984 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::max(const MEDCouplingTimeDiscretization *other) const
985 {
986   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
987   if(!otherC)
988     throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
989   MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
990   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
991   ret->setArray(arr,0);
992   return ret;
993 }
994
995 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::min(const MEDCouplingTimeDiscretization *other) const
996 {
997   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
998   if(!otherC)
999     throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
1000   MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1001   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1002   ret->setArray(arr,0);
1003   return ret;
1004 }
1005
1006 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::add(const MEDCouplingTimeDiscretization *other) const
1007 {
1008   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1009   if(!otherC)
1010     throw INTERP_KERNEL::Exception("NoTimeLabel::add on mismatched time discretization !");
1011   MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1012   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1013   ret->setArray(arr,0);
1014   return ret;
1015 }
1016
1017 void MEDCouplingNoTimeLabel::addEqual(const MEDCouplingTimeDiscretization *other)
1018 {
1019   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1020   if(!otherC)
1021     throw INTERP_KERNEL::Exception("NoTimeLabel::addEqual on mismatched time discretization !");
1022   if(!getArray())
1023     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::addEqual : Data Array is NULL !");
1024   getArray()->addEqual(other->getArray());
1025 }
1026
1027 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::substract(const MEDCouplingTimeDiscretization *other) const
1028 {
1029   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1030   if(!otherC)
1031     throw INTERP_KERNEL::Exception("NoTimeLabel::substract on mismatched time discretization !");
1032   if(!getArray())
1033     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substract : Data Array is NULL !");
1034   MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1035   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1036   ret->setArray(arr,0);
1037   return ret;
1038 }
1039
1040 void MEDCouplingNoTimeLabel::substractEqual(const MEDCouplingTimeDiscretization *other)
1041 {
1042   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1043   if(!otherC)
1044     throw INTERP_KERNEL::Exception("NoTimeLabel::substractEqual on mismatched time discretization !");
1045   if(!getArray())
1046     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substractEqual : Data Array is NULL !");
1047   getArray()->substractEqual(other->getArray());
1048 }
1049
1050 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::multiply(const MEDCouplingTimeDiscretization *other) const
1051 {
1052   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1053   if(!otherC)
1054     throw INTERP_KERNEL::Exception("NoTimeLabel::multiply on mismatched time discretization !");
1055   MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1056   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1057   ret->setArray(arr,0);
1058   return ret;
1059 }
1060
1061 void MEDCouplingNoTimeLabel::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1062 {
1063   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1064   if(!otherC)
1065     throw INTERP_KERNEL::Exception("NoTimeLabel::multiplyEqual on mismatched time discretization !");
1066   if(!getArray())
1067     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::multiplyEqual : Data Array is NULL !");
1068   getArray()->multiplyEqual(other->getArray());
1069 }
1070
1071 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::divide(const MEDCouplingTimeDiscretization *other) const
1072 {
1073   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1074   if(!otherC)
1075     throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
1076   MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1077   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1078   ret->setArray(arr,0);
1079   return ret;
1080 }
1081
1082 void MEDCouplingNoTimeLabel::divideEqual(const MEDCouplingTimeDiscretization *other)
1083 {
1084   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1085   if(!otherC)
1086     throw INTERP_KERNEL::Exception("NoTimeLabel::divideEqual on mismatched time discretization !");
1087   if(!getArray())
1088     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::divideEqual : Data Array is NULL !");
1089   getArray()->divideEqual(other->getArray());
1090 }
1091
1092 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::pow(const MEDCouplingTimeDiscretization *other) const
1093 {
1094   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1095   if(!otherC)
1096     throw INTERP_KERNEL::Exception("pow on mismatched time discretization !");
1097   MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
1098   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1099   ret->setArray(arr,0);
1100   return ret;
1101 }
1102
1103 void MEDCouplingNoTimeLabel::powEqual(const MEDCouplingTimeDiscretization *other)
1104 {
1105   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1106   if(!otherC)
1107     throw INTERP_KERNEL::Exception("NoTimeLabel::powEqual on mismatched time discretization !");
1108   if(!getArray())
1109     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::powEqual : Data Array is NULL !");
1110   getArray()->powEqual(other->getArray());
1111 }
1112
1113 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCopyOrIncrRef(bool deepCopy) const
1114 {
1115   return new MEDCouplingNoTimeLabel(*this,deepCopy);
1116 }
1117
1118 void MEDCouplingNoTimeLabel::checkTimePresence(double time) const
1119 {
1120   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1121 }
1122
1123 std::vector< const DataArrayDouble *> MEDCouplingNoTimeLabel::getArraysForTime(double time) const
1124 {
1125   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1126 }
1127
1128 void MEDCouplingNoTimeLabel::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1129 {
1130   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1131 }
1132
1133 bool MEDCouplingNoTimeLabel::isBefore(const MEDCouplingTimeDiscretization *other) const
1134 {
1135   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1136 }
1137
1138 bool MEDCouplingNoTimeLabel::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const
1139 {
1140   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1141 }
1142
1143 double MEDCouplingNoTimeLabel::getStartTime(int& iteration, int& order) const
1144 {
1145   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1146 }
1147
1148 double MEDCouplingNoTimeLabel::getEndTime(int& iteration, int& order) const
1149 {
1150   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1151 }
1152
1153 void MEDCouplingNoTimeLabel::setStartIteration(int it)
1154 {
1155   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1156 }
1157
1158 void MEDCouplingNoTimeLabel::setEndIteration(int it)
1159 {
1160   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1161 }
1162
1163 void MEDCouplingNoTimeLabel::setStartOrder(int order)
1164 {
1165   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1166 }
1167
1168 void MEDCouplingNoTimeLabel::setEndOrder(int order)
1169 {
1170   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1171 }
1172
1173 void MEDCouplingNoTimeLabel::setStartTimeValue(double time)
1174 {
1175   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1176 }
1177
1178 void MEDCouplingNoTimeLabel::setEndTimeValue(double time)
1179 {
1180   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1181 }
1182
1183 void MEDCouplingNoTimeLabel::setStartTime(double time, int iteration, int order)
1184 {
1185   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1186 }
1187
1188 void MEDCouplingNoTimeLabel::setEndTime(double time, int iteration, int order)
1189 {
1190   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1191 }
1192
1193 void MEDCouplingNoTimeLabel::getValueOnTime(int eltId, double time, double *value) const
1194 {
1195   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1196 }
1197
1198 void MEDCouplingNoTimeLabel::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1199 {
1200   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1201 }
1202
1203 /*!
1204  * idem getTinySerializationIntInformation except that it is for multi field fetch
1205  */
1206 void MEDCouplingNoTimeLabel::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1207 {
1208   tinyInfo.clear();
1209 }
1210
1211 /*!
1212  * idem getTinySerializationDbleInformation except that it is for multi field fetch
1213  */
1214 void MEDCouplingNoTimeLabel::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1215 {
1216   tinyInfo.resize(1);
1217   tinyInfo[0]=_time_tolerance;
1218 }
1219
1220 /*!
1221  * idem finishUnserialization except that it is for multi field fetch
1222  */
1223 void MEDCouplingNoTimeLabel::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1224 {
1225   _time_tolerance=tinyInfoD[0];
1226 }
1227
1228 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy),_tk(other._tk)
1229 {
1230 }
1231
1232 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep()
1233 {
1234 }
1235
1236 std::string MEDCouplingWithTimeStep::getStringRepr() const
1237 {
1238   std::ostringstream stream;
1239   stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
1240   stream << "\nTime unit is : \"" << _time_unit << "\"";
1241   return stream.str();
1242 }
1243
1244 void MEDCouplingWithTimeStep::synchronizeTimeWith(const MEDCouplingMesh *mesh)
1245 {
1246   if(!mesh)
1247     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
1248   int it=-1,order=-1;
1249   double val=mesh->getTime(it,order);
1250   _tk.setAllInfo(val,it,order);
1251   std::string tUnit=mesh->getTimeUnit();
1252   _time_unit=tUnit;
1253 }
1254
1255 void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1256 {
1257   MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1258   tinyInfo.push_back(_tk.getIteration());
1259   tinyInfo.push_back(_tk.getOrder());
1260 }
1261
1262 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1263 {
1264   MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1265   tinyInfo.push_back(_tk.getTimeValue());
1266 }
1267
1268 void MEDCouplingWithTimeStep::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1269 {
1270   MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1271   _tk.setTimeValue(tinyInfoD[1]);
1272   _tk.setIteration(tinyInfoI[2]);
1273   _tk.setOrder(tinyInfoI[3]);
1274 }
1275
1276 /*!
1277  * idem getTinySerializationIntInformation except that it is for multi field fetch
1278  */
1279 void MEDCouplingWithTimeStep::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1280 {
1281   tinyInfo.resize(2);
1282   tinyInfo[0]=_tk.getIteration();
1283   tinyInfo[1]=_tk.getOrder();
1284 }
1285
1286 /*!
1287  * idem getTinySerializationDbleInformation except that it is for multi field fetch
1288  */
1289 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1290 {
1291   tinyInfo.resize(2);
1292   tinyInfo[0]=_time_tolerance;
1293   tinyInfo[1]=_tk.getTimeValue();
1294 }
1295
1296 /*!
1297  * idem finishUnserialization except that it is for multi field fetch
1298  */
1299 void MEDCouplingWithTimeStep::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1300 {
1301   _tk.setIteration(tinyInfoI[0]);
1302   _tk.setOrder(tinyInfoI[1]);
1303   _time_tolerance=tinyInfoD[0];
1304   _tk.setTimeValue(tinyInfoD[1]);
1305 }
1306
1307 bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1308 {
1309   if(!MEDCouplingTimeDiscretization::areCompatible(other))
1310     return false;
1311   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1312   return otherC!=0;
1313 }
1314
1315 bool MEDCouplingWithTimeStep::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
1316 {
1317   if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1318     return false;
1319   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1320   bool ret=otherC!=0;
1321   if(!ret)
1322     reason.insert(0,"time discretization of this is ONE_TIME, other has a different time discretization.");
1323   return ret;
1324 }
1325
1326 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1327 {
1328   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1329     return false;
1330   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1331   return otherC!=0;
1332 }
1333
1334 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1335 {
1336   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1337     return false;
1338   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1339   return otherC!=0;
1340 }
1341
1342 bool MEDCouplingWithTimeStep::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1343 {
1344   if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1345     return false;
1346   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1347   return otherC!=0;
1348 }
1349
1350 bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
1351 {
1352   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1353   std::ostringstream oss; oss.precision(15);
1354   if(!otherC)
1355     {
1356       reason="This has time discretization ONE_TIME, other not.";
1357       return false;
1358     }
1359   if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
1360     return false;
1361   return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1362 }
1363
1364 bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
1365 {
1366   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1367   if(!otherC)
1368     return false;
1369   if(!_tk.isEqual(otherC->_tk,_time_tolerance))
1370      return false;
1371   return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1372 }
1373
1374 void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
1375 {
1376   MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1377   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(&other);
1378   if(!otherC)
1379     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::copyTinyAttrFrom : mismatch of time discretization !");
1380   _tk.copyFrom(otherC->_tk);
1381 }
1382
1383 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCouplingTimeDiscretization *other) const
1384 {
1385   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1386   if(!otherC)
1387     throw INTERP_KERNEL::Exception("WithTimeStep::aggregation on mismatched time discretization !");
1388   MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1389   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1390   ret->setArray(arr,0);
1391   return ret;
1392 }
1393
1394 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1395 {
1396   std::vector<const DataArrayDouble *> a(other.size());
1397   int i=0;
1398   for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1399     {
1400       const MEDCouplingWithTimeStep *itC=dynamic_cast<const MEDCouplingWithTimeStep *>(*it);
1401       if(!itC)
1402         throw INTERP_KERNEL::Exception("WithTimeStep::aggregate on mismatched time discretization !");
1403       a[i]=itC->getArray();
1404     }
1405   MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1406   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1407   ret->setArray(arr,0);
1408   return ret;
1409 }
1410
1411 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::meld(const MEDCouplingTimeDiscretization *other) const
1412 {
1413   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1414   if(!otherC)
1415     throw INTERP_KERNEL::Exception("WithTimeStep::meld on mismatched time discretization !");
1416   MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1417   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1418   ret->setArray(arr,0);
1419   return ret;
1420 }
1421
1422 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::dot(const MEDCouplingTimeDiscretization *other) const
1423 {
1424   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1425   if(!otherC)
1426     throw INTERP_KERNEL::Exception("WithTimeStep::dot on mismatched time discretization !");
1427   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1428   MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1429   ret->setArray(arr,0);
1430   return ret;
1431 }
1432
1433 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::crossProduct(const MEDCouplingTimeDiscretization *other) const
1434 {
1435   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1436   if(!otherC)
1437     throw INTERP_KERNEL::Exception("WithTimeStep::crossProduct on mismatched time discretization !");
1438   MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1439   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1440   ret->setArray(arr,0);
1441   return ret;
1442 }
1443
1444 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::max(const MEDCouplingTimeDiscretization *other) const
1445 {
1446   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1447   if(!otherC)
1448     throw INTERP_KERNEL::Exception("WithTimeStep::max on mismatched time discretization !");
1449   MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1450   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1451   ret->setArray(arr,0);
1452   return ret;
1453 }
1454
1455 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::min(const MEDCouplingTimeDiscretization *other) const
1456 {
1457   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1458   if(!otherC)
1459     throw INTERP_KERNEL::Exception("WithTimeStep::min on mismatched time discretization !");
1460   MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1461   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1462   ret->setArray(arr,0);
1463   return ret;
1464 }
1465
1466 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::add(const MEDCouplingTimeDiscretization *other) const
1467 {
1468   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1469   if(!otherC)
1470     throw INTERP_KERNEL::Exception("WithTimeStep::add on mismatched time discretization !");
1471   MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1472   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1473   ret->setArray(arr,0);
1474   int tmp1,tmp2;
1475   double tmp3=getStartTime(tmp1,tmp2);
1476   ret->setStartTime(tmp3,tmp1,tmp2);
1477   return ret;
1478 }
1479
1480 void MEDCouplingWithTimeStep::addEqual(const MEDCouplingTimeDiscretization *other)
1481 {
1482   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1483   if(!otherC)
1484     throw INTERP_KERNEL::Exception("WithTimeStep::addEqual on mismatched time discretization !");
1485   if(!getArray())
1486     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::addEqual : Data Array is NULL !");
1487   getArray()->addEqual(other->getArray());
1488 }
1489
1490 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::substract(const MEDCouplingTimeDiscretization *other) const
1491 {
1492   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1493   if(!otherC)
1494     throw INTERP_KERNEL::Exception("WithTimeStep::substract on mismatched time discretization !");
1495   MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1496   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1497   ret->setArray(arr,0);
1498   int tmp1,tmp2;
1499   double tmp3=getStartTime(tmp1,tmp2);
1500   ret->setStartTime(tmp3,tmp1,tmp2);
1501   return ret;
1502 }
1503
1504 void MEDCouplingWithTimeStep::substractEqual(const MEDCouplingTimeDiscretization *other)
1505 {
1506   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1507   if(!otherC)
1508     throw INTERP_KERNEL::Exception("WithTimeStep::substractEqual on mismatched time discretization !");
1509   if(!getArray())
1510     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::substractEqual : Data Array is NULL !");
1511   getArray()->substractEqual(other->getArray());
1512 }
1513
1514 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::multiply(const MEDCouplingTimeDiscretization *other) const
1515 {
1516   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1517   if(!otherC)
1518     throw INTERP_KERNEL::Exception("WithTimeStep::multiply on mismatched time discretization !");
1519   MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1520   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1521   ret->setArray(arr,0);
1522   int tmp1,tmp2;
1523   double tmp3=getStartTime(tmp1,tmp2);
1524   ret->setStartTime(tmp3,tmp1,tmp2);
1525   return ret;
1526 }
1527
1528 void MEDCouplingWithTimeStep::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1529 {
1530   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1531   if(!otherC)
1532     throw INTERP_KERNEL::Exception("WithTimeStep::multiplyEqual on mismatched time discretization !");
1533   if(!getArray())
1534     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::multiplyEqual : Data Array is NULL !");
1535   getArray()->multiplyEqual(other->getArray());
1536 }
1537
1538 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::divide(const MEDCouplingTimeDiscretization *other) const
1539 {
1540   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1541   if(!otherC)
1542     throw INTERP_KERNEL::Exception("WithTimeStep::divide on mismatched time discretization !");
1543   MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1544   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1545   ret->setArray(arr,0);
1546   int tmp1,tmp2;
1547   double tmp3=getStartTime(tmp1,tmp2);
1548   ret->setStartTime(tmp3,tmp1,tmp2);
1549   return ret;
1550 }
1551
1552 void MEDCouplingWithTimeStep::divideEqual(const MEDCouplingTimeDiscretization *other)
1553 {
1554   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1555   if(!otherC)
1556     throw INTERP_KERNEL::Exception("WithTimeStep::divideEqual on mismatched time discretization !");
1557   if(!getArray())
1558     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::divideEqual : Data Array is NULL !");
1559   getArray()->divideEqual(other->getArray());
1560 }
1561
1562 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::pow(const MEDCouplingTimeDiscretization *other) const
1563 {
1564   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1565   if(!otherC)
1566     throw INTERP_KERNEL::Exception("WithTimeStep::pow on mismatched time discretization !");
1567   MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
1568   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1569   ret->setArray(arr,0);
1570   int tmp1,tmp2;
1571   double tmp3=getStartTime(tmp1,tmp2);
1572   ret->setStartTime(tmp3,tmp1,tmp2);
1573   return ret;
1574 }
1575
1576 void MEDCouplingWithTimeStep::powEqual(const MEDCouplingTimeDiscretization *other)
1577 {
1578   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1579   if(!otherC)
1580     throw INTERP_KERNEL::Exception("WithTimeStep::powEqual on mismatched time discretization !");
1581   if(!getArray())
1582     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::powEqual : Data Array is NULL !");
1583   getArray()->powEqual(other->getArray());
1584 }
1585
1586 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCopyOrIncrRef(bool deepCopy) const
1587 {
1588   return new MEDCouplingWithTimeStep(*this,deepCopy);
1589 }
1590
1591 void MEDCouplingWithTimeStep::checkNoTimePresence() const
1592 {
1593   throw INTERP_KERNEL::Exception("No time specified on a field defined on one time");
1594 }
1595
1596 void MEDCouplingWithTimeStep::checkTimePresence(double time) const
1597 {
1598   _tk.checkTimePresence(time,_time_tolerance);
1599 }
1600
1601 std::vector< const DataArrayDouble *> MEDCouplingWithTimeStep::getArraysForTime(double time) const
1602 {
1603   if(std::fabs(time-_tk.getTimeValue())<=_time_tolerance)
1604     {
1605       std::vector< const DataArrayDouble *> ret(1);
1606       ret[0]=_array;
1607       return ret;
1608     }
1609   else
1610     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1611 }
1612
1613 void MEDCouplingWithTimeStep::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1614 {
1615   std::copy(vals.begin(),vals.end(),res);
1616 }
1617
1618 void MEDCouplingWithTimeStep::getValueOnTime(int eltId, double time, double *value) const
1619 {
1620   if(std::fabs(time-_tk.getTimeValue())<=_time_tolerance)
1621     if(_array)
1622       _array->getTuple(eltId,value);
1623     else
1624       throw INTERP_KERNEL::Exception("No array existing.");
1625   else
1626     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1627 }
1628
1629 void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1630 {
1631   if(_tk.getIteration()==iteration && _tk.getOrder()==order)
1632     if(_array)
1633       _array->getTuple(eltId,value);
1634     else
1635       throw INTERP_KERNEL::Exception("No array existing.");
1636   else
1637     throw INTERP_KERNEL::Exception("No data on this discrete time.");
1638 }
1639
1640 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval()
1641 {
1642 }
1643
1644 void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
1645 {
1646   MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1647   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(&other);
1648   if(!otherC)
1649     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::copyTinyAttrFrom : mismatch of time discretization !");
1650   _start.copyFrom(otherC->_start);
1651   _end.copyFrom(otherC->_end);
1652 }
1653
1654 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1655 {
1656   MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1657   tinyInfo.push_back(_start.getIteration());
1658   tinyInfo.push_back(_start.getOrder());
1659   tinyInfo.push_back(_end.getIteration());
1660   tinyInfo.push_back(_end.getOrder());
1661 }
1662
1663 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1664 {
1665   MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1666   tinyInfo.push_back(_start.getTimeValue());
1667   tinyInfo.push_back(_end.getTimeValue());
1668 }
1669
1670 void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1671 {
1672   MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1673   _start.setTimeValue(tinyInfoD[1]);
1674   _end.setTimeValue(tinyInfoD[2]);
1675   _start.setIteration(tinyInfoI[2]);
1676   _start.setOrder(tinyInfoI[3]);
1677   _end.setIteration(tinyInfoI[4]);
1678   _end.setOrder(tinyInfoI[5]);
1679 }
1680
1681 /*!
1682  * idem getTinySerializationIntInformation except that it is for multi field fetch
1683  */
1684 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1685 {
1686   tinyInfo.resize(4);
1687   tinyInfo[0]=_start.getIteration();
1688   tinyInfo[1]=_start.getOrder();
1689   tinyInfo[2]=_end.getIteration();
1690   tinyInfo[3]=_end.getOrder();
1691 }
1692
1693 /*!
1694  * idem getTinySerializationDbleInformation except that it is for multi field fetch
1695  */
1696 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1697 {
1698   tinyInfo.resize(3);
1699   tinyInfo[0]=_time_tolerance;
1700   tinyInfo[1]=_start.getTimeValue();
1701   tinyInfo[2]=_end.getTimeValue();
1702 }
1703
1704 /*!
1705  * idem finishUnserialization except that it is for multi field fetch
1706  */
1707 void MEDCouplingConstOnTimeInterval::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1708 {
1709   _start.setIteration(tinyInfoI[0]);
1710   _start.setOrder(tinyInfoI[1]);
1711   _end.setIteration(tinyInfoI[2]);
1712   _end.setOrder(tinyInfoI[3]);
1713   _time_tolerance=tinyInfoD[0];
1714   _start.setTimeValue(tinyInfoD[1]);
1715   _end.setTimeValue(tinyInfoD[2]);
1716 }
1717
1718 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCopy):
1719   MEDCouplingTimeDiscretization(other,deepCopy),_start(other._start),_end(other._end)
1720 {
1721 }
1722
1723 std::string MEDCouplingConstOnTimeInterval::getStringRepr() const
1724 {
1725   std::ostringstream stream;
1726   stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n";
1727   stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n";
1728   stream << "\nTime unit is : \"" << _time_unit << "\"";
1729   return stream.str();
1730 }
1731
1732 void MEDCouplingConstOnTimeInterval::synchronizeTimeWith(const MEDCouplingMesh *mesh)
1733 {
1734   if(!mesh)
1735     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
1736   int it=-1,order=-1;
1737   double val=mesh->getTime(it,order);
1738   _start.setAllInfo(val,it,order);
1739   _end.setAllInfo(val,it,order);
1740   std::string tUnit(mesh->getTimeUnit());
1741   _time_unit=tUnit;
1742 }
1743
1744 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCopyOrIncrRef(bool deepCopy) const
1745 {
1746   return new MEDCouplingConstOnTimeInterval(*this,deepCopy);
1747 }
1748
1749 std::vector< const DataArrayDouble *> MEDCouplingConstOnTimeInterval::getArraysForTime(double time) const
1750 {
1751   if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
1752     {
1753       std::vector< const DataArrayDouble *> ret(1);
1754       ret[0]=_array;
1755       return ret;
1756     }
1757   else
1758     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1759 }
1760
1761 void MEDCouplingConstOnTimeInterval::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1762 {
1763   std::copy(vals.begin(),vals.end(),res);
1764 }
1765
1766 bool MEDCouplingConstOnTimeInterval::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1767 {
1768   if(!MEDCouplingTimeDiscretization::areCompatible(other))
1769     return false;
1770   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1771   return otherC!=0;
1772 }
1773
1774 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
1775 {
1776   if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1777     return false;
1778   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1779   bool ret=otherC!=0;
1780   if(!ret)
1781     reason.insert(0,"time discretization of this is CONST_ON_TIME_INTERVAL, other has a different time discretization.");
1782   return ret;
1783 }
1784
1785 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1786 {
1787   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1788     return false;
1789   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1790   return otherC!=0;
1791 }
1792
1793 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1794 {
1795   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1796     return false;
1797   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1798   return otherC!=0;
1799 }
1800
1801 bool MEDCouplingConstOnTimeInterval::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1802 {
1803   if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1804     return false;
1805   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1806   return otherC!=0;
1807 }
1808
1809 bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
1810 {
1811   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1812   std::ostringstream oss; oss.precision(15);
1813   if(!otherC)
1814     {
1815       reason="This has time discretization CONST_ON_TIME_INTERVAL, other not.";
1816       return false;
1817     }
1818   if(!_start.isEqualIfNotWhy(otherC->_start,_time_tolerance,reason))
1819     return false;
1820   if(!_end.isEqualIfNotWhy(otherC->_end,_time_tolerance,reason))
1821     return false;
1822   return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1823 }
1824
1825 bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
1826 {
1827   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1828   if(!otherC)
1829     return false;
1830   if(!_start.isEqual(otherC->_start,_time_tolerance))
1831     return false;
1832   if(!_end.isEqual(otherC->_end,_time_tolerance))
1833     return false;
1834   return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1835 }
1836
1837 void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, double *value) const
1838 {
1839   if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
1840     if(_array)
1841       _array->getTuple(eltId,value);
1842     else
1843       throw INTERP_KERNEL::Exception("No array existing.");
1844   else
1845     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1846 }
1847
1848 void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1849 {
1850   if(iteration>=_start.getIteration() && iteration<=_end.getIteration())
1851     if(_array)
1852       _array->getTuple(eltId,value);
1853     else
1854       throw INTERP_KERNEL::Exception("No array existing.");
1855   else
1856     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1857 }
1858
1859 void MEDCouplingConstOnTimeInterval::checkNoTimePresence() const
1860 {
1861   throw INTERP_KERNEL::Exception("No time specified on a field defined as constant on one time interval");
1862 }
1863
1864 void MEDCouplingConstOnTimeInterval::checkTimePresence(double time) const
1865 {
1866   if(time<_start.getTimeValue()-_time_tolerance || time>_end.getTimeValue()+_time_tolerance)
1867     {
1868       std::ostringstream stream;
1869       stream << "The field is defined between times " << _start.getTimeValue() << " and " << _end.getTimeValue() << " worderh tolerance ";
1870       stream << _time_tolerance << " and trying to access on time = " << time;
1871       throw INTERP_KERNEL::Exception(stream.str().c_str());
1872     }
1873 }
1874
1875 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const MEDCouplingTimeDiscretization *other) const
1876 {
1877   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1878   if(!otherC)
1879     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregation on mismatched time discretization !");
1880   MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1881   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1882   ret->setArray(arr,0);
1883   return ret;
1884 }
1885
1886 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1887 {
1888   std::vector<const DataArrayDouble *> a(other.size());
1889   int i=0;
1890   for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1891     {
1892       const MEDCouplingConstOnTimeInterval *itC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(*it);
1893       if(!itC)
1894         throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregate on mismatched time discretization !");
1895       a[i]=itC->getArray();
1896     }
1897   MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1898   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1899   ret->setArray(arr,0);
1900   return ret;
1901 }
1902
1903 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::meld(const MEDCouplingTimeDiscretization *other) const
1904 {
1905   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1906   if(!otherC)
1907     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::meld on mismatched time discretization !");
1908   MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1909   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1910   ret->setTimeTolerance(getTimeTolerance());
1911   ret->setArray(arr,0);
1912   return ret;
1913 }
1914
1915 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::dot(const MEDCouplingTimeDiscretization *other) const
1916 {
1917   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1918   if(!otherC)
1919     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::dot on mismatched time discretization !");
1920   MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1921   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1922   ret->setArray(arr,0);
1923   return ret;
1924 }
1925
1926 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::crossProduct(const MEDCouplingTimeDiscretization *other) const
1927 {
1928   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1929   if(!otherC)
1930     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::crossProduct on mismatched time discretization !");
1931   MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1932   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1933   ret->setArray(arr,0);
1934   return ret;
1935 }
1936
1937 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::max(const MEDCouplingTimeDiscretization *other) const
1938 {
1939   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1940   if(!otherC)
1941     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::max on mismatched time discretization !");
1942   MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1943   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1944   ret->setArray(arr,0);
1945   return ret;
1946 }
1947
1948 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::min(const MEDCouplingTimeDiscretization *other) const
1949 {
1950   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1951   if(!otherC)
1952     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::min on mismatched time discretization !");
1953   MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1954   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1955   ret->setArray(arr,0);
1956   return ret;
1957 }
1958
1959 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::add(const MEDCouplingTimeDiscretization *other) const
1960 {
1961   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1962   if(!otherC)
1963     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::add on mismatched time discretization !");
1964   MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1965   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1966   ret->setArray(arr,0);
1967   int tmp1,tmp2;
1968   double tmp3=getStartTime(tmp1,tmp2);
1969   ret->setStartTime(tmp3,tmp1,tmp2);
1970   tmp3=getEndTime(tmp1,tmp2);
1971   ret->setEndTime(tmp3,tmp1,tmp2);
1972   return ret;
1973 }
1974
1975 void MEDCouplingConstOnTimeInterval::addEqual(const MEDCouplingTimeDiscretization *other)
1976 {
1977   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1978   if(!otherC)
1979     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::addEqual on mismatched time discretization !");
1980   if(!getArray())
1981     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractaddEqual : Data Array is NULL !");
1982   getArray()->addEqual(other->getArray());
1983 }
1984
1985 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::substract(const MEDCouplingTimeDiscretization *other) const
1986 {
1987   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1988   if(!otherC)
1989     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substract on mismatched time discretization !");
1990   MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1991   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1992   ret->setArray(arr,0);
1993   int tmp1,tmp2;
1994   double tmp3=getStartTime(tmp1,tmp2);
1995   ret->setStartTime(tmp3,tmp1,tmp2);
1996   tmp3=getEndTime(tmp1,tmp2);
1997   ret->setEndTime(tmp3,tmp1,tmp2);
1998   return ret;
1999 }
2000
2001 void MEDCouplingConstOnTimeInterval::substractEqual(const MEDCouplingTimeDiscretization *other)
2002 {
2003   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2004   if(!otherC)
2005     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substractEqual on mismatched time discretization !");
2006   if(!getArray())
2007     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractEqual : Data Array is NULL !");
2008   getArray()->substractEqual(other->getArray());
2009 }
2010
2011 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::multiply(const MEDCouplingTimeDiscretization *other) const
2012 {
2013   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2014   if(!otherC)
2015     throw INTERP_KERNEL::Exception("multiply on mismatched time discretization !");
2016   MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
2017   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2018   ret->setArray(arr,0);
2019   int tmp1,tmp2;
2020   double tmp3=getStartTime(tmp1,tmp2);
2021   ret->setStartTime(tmp3,tmp1,tmp2);
2022   tmp3=getEndTime(tmp1,tmp2);
2023   ret->setEndTime(tmp3,tmp1,tmp2);
2024   return ret;
2025 }
2026
2027 void MEDCouplingConstOnTimeInterval::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2028 {
2029   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2030   if(!otherC)
2031     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::multiplyEqual on mismatched time discretization !");
2032   if(!getArray())
2033     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::multiplyEqual : Data Array is NULL !");
2034   getArray()->multiplyEqual(other->getArray());
2035 }
2036
2037 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::divide(const MEDCouplingTimeDiscretization *other) const
2038 {
2039   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2040   if(!otherC)
2041     throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
2042   MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
2043   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2044   ret->setArray(arr,0);
2045   int tmp1,tmp2;
2046   double tmp3=getStartTime(tmp1,tmp2);
2047   ret->setStartTime(tmp3,tmp1,tmp2);
2048   tmp3=getEndTime(tmp1,tmp2);
2049   ret->setEndTime(tmp3,tmp1,tmp2);
2050   return ret;
2051 }
2052
2053 void MEDCouplingConstOnTimeInterval::divideEqual(const MEDCouplingTimeDiscretization *other)
2054 {
2055   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2056   if(!otherC)
2057     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::divideEqual on mismatched time discretization !");
2058   if(!getArray())
2059     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::divideEqual : Data Array is NULL !");
2060   getArray()->divideEqual(other->getArray());
2061 }
2062
2063 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::pow(const MEDCouplingTimeDiscretization *other) const
2064 {
2065   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2066   if(!otherC)
2067     throw INTERP_KERNEL::Exception("pow on mismatched time discretization !");
2068   MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
2069   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2070   ret->setArray(arr,0);
2071   int tmp1,tmp2;
2072   double tmp3=getStartTime(tmp1,tmp2);
2073   ret->setStartTime(tmp3,tmp1,tmp2);
2074   tmp3=getEndTime(tmp1,tmp2);
2075   ret->setEndTime(tmp3,tmp1,tmp2);
2076   return ret;
2077 }
2078
2079 void MEDCouplingConstOnTimeInterval::powEqual(const MEDCouplingTimeDiscretization *other)
2080 {
2081   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2082   if(!otherC)
2083     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::powEqual on mismatched time discretization !");
2084   if(!getArray())
2085     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::powEqual : Data Array is NULL !");
2086   getArray()->powEqual(other->getArray());
2087 }
2088
2089 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy),
2090     _start_time(other._start_time),_end_time(other._end_time),
2091     _start_iteration(other._start_iteration),_end_iteration(other._end_iteration),
2092     _start_order(other._start_order),_end_order(other._end_order)
2093 {
2094   if(other._end_array)
2095     _end_array=other._end_array->performCopyOrIncrRef(deepCopy);
2096   else
2097     _end_array=0;
2098 }
2099
2100 void MEDCouplingTwoTimeSteps::updateTime() const
2101 {
2102   MEDCouplingTimeDiscretization::updateTime();
2103   if(_end_array)
2104     updateTimeWith(*_end_array);
2105 }
2106
2107 void MEDCouplingTwoTimeSteps::synchronizeTimeWith(const MEDCouplingMesh *mesh)
2108 {
2109   if(!mesh)
2110     throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
2111   int it=-1,order=-1;
2112   double val=mesh->getTime(it,order);
2113   _start_time=val; _start_iteration=it; _start_order=order;
2114   _end_time=val; _end_iteration=it; _end_order=order;
2115   std::string tUnit=mesh->getTimeUnit();
2116   _time_unit=tUnit;
2117 }
2118
2119 std::size_t MEDCouplingTwoTimeSteps::getHeapMemorySizeWithoutChildren() const
2120 {
2121   return MEDCouplingTimeDiscretization::getHeapMemorySizeWithoutChildren();
2122 }
2123
2124 std::vector<const BigMemoryObject *> MEDCouplingTwoTimeSteps::getDirectChildrenWithNull() const
2125 {
2126   std::vector<const BigMemoryObject *> ret(MEDCouplingTimeDiscretization::getDirectChildrenWithNull());
2127   ret.push_back(_end_array);
2128   return ret;
2129 }
2130
2131 void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
2132 {
2133   MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
2134   const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2135   if(!otherC)
2136     throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::copyTinyAttrFrom : mismatch of time discretization !");
2137   _start_time=otherC->_start_time;
2138   _end_time=otherC->_end_time;
2139   _start_iteration=otherC->_start_iteration;
2140   _end_iteration=otherC->_end_iteration;
2141   _start_order=otherC->_start_order;
2142   _end_order=otherC->_end_order;
2143 }
2144
2145 void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
2146 {
2147   MEDCouplingTimeDiscretization::copyTinyStringsFrom(other);
2148   const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2149   if(!otherC)
2150     throw INTERP_KERNEL::Exception("Trying to operate copyTinyStringsFrom on different field type (two times//one time) !");
2151   if(_end_array && otherC->_end_array)
2152     _end_array->copyStringInfoFrom(*otherC->_end_array);
2153 }
2154
2155 const DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray() const
2156 {
2157   return _end_array;
2158 }
2159
2160 DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray()
2161 {
2162   return _end_array;
2163 }
2164
2165 void MEDCouplingTwoTimeSteps::checkConsistencyLight() const
2166 {
2167   MEDCouplingTimeDiscretization::checkConsistencyLight();
2168   if(!_end_array)
2169     throw INTERP_KERNEL::Exception("No end array specified !");
2170   if(_array->getNumberOfComponents()!=_end_array->getNumberOfComponents())
2171     throw INTERP_KERNEL::Exception("The number of components mismatch between the start and the end arrays !");
2172   if(_array->getNumberOfTuples()!=_end_array->getNumberOfTuples())
2173     throw INTERP_KERNEL::Exception("The number of tuples mismatch between the start and the end arrays !");
2174 }
2175
2176 bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const
2177 {
2178   std::ostringstream oss;
2179   const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(other);
2180   if(!otherC)
2181     {
2182       reason="This has time discretization LINEAR_TIME, other not.";
2183       return false;
2184     }
2185   if(_start_iteration!=otherC->_start_iteration)
2186     {
2187       oss << "start iterations differ. this start iteration=" << _start_iteration << " other start iteration=" << otherC->_start_iteration;
2188       reason=oss.str();
2189       return false;
2190     }
2191   if(_start_order!=otherC->_start_order)
2192     {
2193       oss << "start orders differ. this start order=" << _start_order << " other start order=" << otherC->_start_order;
2194       reason=oss.str();
2195       return false;
2196     }
2197   if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
2198     {
2199       oss << "start times differ. this start time=" << _start_time << " other start time=" << otherC->_start_time;
2200       reason=oss.str();
2201       return false;
2202     }
2203   if(_end_iteration!=otherC->_end_iteration)
2204     {
2205       oss << "end iterations differ. this end iteration=" << _end_iteration << " other end iteration=" << otherC->_end_iteration;
2206       reason=oss.str();
2207       return false;
2208     }
2209   if(_end_order!=otherC->_end_order)
2210     {
2211       oss << "end orders differ. this end order=" << _end_order << " other end order=" << otherC->_end_order;
2212       reason=oss.str();
2213       return false;
2214     }
2215   if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
2216     {
2217       oss << "end times differ. this end time=" << _end_time << " other end time=" << otherC->_end_time;
2218       reason=oss.str();
2219       return false;
2220     }
2221   if(_end_array!=otherC->_end_array)
2222     if(!_end_array->isEqualIfNotWhy(*otherC->_end_array,prec,reason))
2223       {
2224         reason.insert(0,"end arrays differ for linear time.");
2225         return false;
2226       }
2227   return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
2228 }
2229
2230 bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const
2231 {
2232   const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(other);
2233   if(!otherC)
2234     return false;
2235   if(_start_iteration!=otherC->_start_iteration)
2236     return false;
2237   if(_end_iteration!=otherC->_end_iteration)
2238     return false;
2239   if(_start_order!=otherC->_start_order)
2240     return false;
2241   if(_end_order!=otherC->_end_order)
2242     return false;
2243   if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance)
2244     return false;
2245   if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance)
2246     return false;
2247   if(_end_array!=otherC->_end_array)
2248     if(!_end_array->isEqualWithoutConsideringStr(*otherC->_end_array,prec))
2249       return false;
2250   return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
2251 }
2252
2253 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_start_time(0.),_end_time(0.),_start_iteration(-1),_end_iteration(-1),_start_order(-1),_end_order(-1),_end_array(0)
2254 {
2255 }
2256
2257 MEDCouplingTwoTimeSteps::~MEDCouplingTwoTimeSteps()
2258 {
2259   if(_end_array)
2260     _end_array->decrRef();
2261 }
2262
2263 void MEDCouplingTwoTimeSteps::checkNoTimePresence() const
2264 {
2265   throw INTERP_KERNEL::Exception("The field presents a time to be specified in every access !");
2266 }
2267
2268 void MEDCouplingTwoTimeSteps::checkTimePresence(double time) const
2269 {
2270   if(time<_start_time-_time_tolerance || time>_end_time+_time_tolerance)
2271     {
2272       std::ostringstream stream;
2273       stream << "The field is defined between times " << _start_time << " and " << _end_time << " worderh tolerance ";
2274       stream << _time_tolerance << " and trying to access on time = " << time;
2275       throw INTERP_KERNEL::Exception(stream.str().c_str());
2276     }
2277 }
2278
2279 void MEDCouplingTwoTimeSteps::getArrays(std::vector<DataArrayDouble *>& arrays) const
2280 {
2281   arrays.resize(2);
2282   arrays[0]=_array;
2283   arrays[1]=_end_array;
2284 }
2285
2286 void MEDCouplingTwoTimeSteps::setEndArray(DataArrayDouble *array, TimeLabel *owner)
2287 {
2288   if(array!=_end_array)
2289     {
2290       if(_end_array)
2291         _end_array->decrRef();
2292       _end_array=array;
2293       if(_end_array)
2294         _end_array->incrRef();
2295       if(owner)
2296         owner->declareAsNew();
2297     }
2298 }
2299
2300 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
2301 {
2302   MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
2303   tinyInfo.push_back(_start_iteration);
2304   tinyInfo.push_back(_start_order);
2305   tinyInfo.push_back(_end_iteration);
2306   tinyInfo.push_back(_end_order);
2307   if(_end_array)
2308     {
2309       tinyInfo.push_back(_end_array->getNumberOfTuples());
2310       tinyInfo.push_back(_end_array->getNumberOfComponents());
2311     }
2312   else
2313     {
2314       tinyInfo.push_back(-1);
2315       tinyInfo.push_back(-1);
2316     }
2317 }
2318
2319 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
2320 {
2321   MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
2322   tinyInfo.push_back(_start_time);
2323   tinyInfo.push_back(_end_time);
2324 }
2325
2326 void MEDCouplingTwoTimeSteps::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
2327 {
2328   int nbOfCompo=_array->getNumberOfComponents();
2329   for(int i=0;i<nbOfCompo;i++)
2330     tinyInfo.push_back(_array->getInfoOnComponent(i));
2331   for(int i=0;i<nbOfCompo;i++)
2332     tinyInfo.push_back(_end_array->getInfoOnComponent(i));
2333 }
2334
2335 void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
2336 {
2337   arrays.resize(2);
2338   if(_array!=0)
2339     _array->decrRef();
2340   if(_end_array!=0)
2341     _end_array->decrRef();
2342   DataArrayDouble *arr=0;
2343   if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2344     {
2345       arr=DataArrayDouble::New();
2346       arr->alloc(tinyInfoI[0],tinyInfoI[1]);
2347     }
2348   _array=arr;
2349   arrays[0]=arr;
2350   arr=0;
2351   if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2352     {
2353       arr=DataArrayDouble::New();
2354       arr->alloc(tinyInfoI[6],tinyInfoI[7]);
2355     }
2356   _end_array=arr;
2357   arrays[1]=arr;
2358 }
2359
2360 void MEDCouplingTwoTimeSteps::checkForUnserialization(const std::vector<int>& tinyInfoI, const std::vector<DataArrayDouble *>& arrays)
2361 {
2362   static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size two !";
2363   if(arrays.size()!=2)
2364     throw INTERP_KERNEL::Exception(MSG);
2365   if(_array!=0)
2366     _array->decrRef();
2367   if(_end_array!=0)
2368     _end_array->decrRef();
2369   _array=0; _end_array=0;
2370   if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2371     {
2372       if(!arrays[0])
2373         throw INTERP_KERNEL::Exception(MSG);
2374       arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
2375       _array=arrays[0]; _array->incrRef();
2376     }
2377   if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2378     {
2379       if(!arrays[1])
2380         throw INTERP_KERNEL::Exception(MSG);
2381       arrays[1]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
2382       _end_array=arrays[1]; _end_array->incrRef();
2383     }
2384 }
2385
2386 void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
2387 {
2388   MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
2389   _start_time=tinyInfoD[1];
2390   _end_time=tinyInfoD[2];
2391   _start_iteration=tinyInfoI[2];
2392   _start_order=tinyInfoI[3];
2393   _end_iteration=tinyInfoI[4];
2394   _end_order=tinyInfoI[5];
2395 }
2396
2397 /*!
2398  * idem getTinySerializationIntInformation except that it is for multi field fetch
2399  */
2400 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
2401 {
2402   tinyInfo.resize(4);
2403   tinyInfo[0]=_start_iteration;
2404   tinyInfo[1]=_start_order;
2405   tinyInfo[2]=_end_iteration;
2406   tinyInfo[3]=_end_order;
2407 }
2408
2409 /*!
2410  * idem getTinySerializationDbleInformation except that it is for multi field fetch
2411  */
2412 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
2413 {
2414   tinyInfo.resize(3);
2415   tinyInfo[0]=_time_tolerance;
2416   tinyInfo[1]=_start_time;
2417   tinyInfo[2]=_end_time;
2418 }
2419
2420 /*!
2421  * idem finishUnserialization except that it is for multi field fetch
2422  */
2423 void MEDCouplingTwoTimeSteps::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
2424 {
2425   _start_iteration=tinyInfoI[0];
2426   _start_order=tinyInfoI[1];
2427   _end_iteration=tinyInfoI[2];
2428   _end_order=tinyInfoI[3];
2429   _time_tolerance=tinyInfoD[0];
2430   _start_time=tinyInfoD[1];
2431   _end_time=tinyInfoD[2];
2432 }
2433
2434 std::vector< const DataArrayDouble *> MEDCouplingTwoTimeSteps::getArraysForTime(double time) const
2435 {
2436   if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance)
2437     {
2438       std::vector< const DataArrayDouble *> ret(2);
2439       ret[0]=_array;
2440       ret[1]=_end_array;
2441       return ret;
2442     }
2443   else
2444     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2445 }
2446
2447 void MEDCouplingTwoTimeSteps::setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner)
2448 {
2449   if(arrays.size()!=2)
2450     throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::setArrays : number of arrays must be two.");
2451   setArray(arrays.front(),owner);
2452   setEndArray(arrays.back(),owner);
2453 }
2454
2455 MEDCouplingLinearTime::MEDCouplingLinearTime(const MEDCouplingLinearTime& other, bool deepCopy):MEDCouplingTwoTimeSteps(other,deepCopy)
2456 {
2457 }
2458
2459 MEDCouplingLinearTime::MEDCouplingLinearTime()
2460 {
2461 }
2462
2463 std::string MEDCouplingLinearTime::getStringRepr() const
2464 {
2465   std::ostringstream stream;
2466   stream << REPR << " Time interval is defined by :\niteration_start=" << _start_iteration << " order_start=" << _start_order << " and time_start=" << _start_time << "\n";
2467   stream << "iteration_end=" << _end_iteration << " order_end=" << _end_order << " and end_time=" << _end_time << "\n";
2468   stream << "Time unit is : \"" << _time_unit << "\"";
2469   return stream.str();
2470 }
2471
2472 void MEDCouplingLinearTime::checkConsistencyLight() const
2473 {
2474   MEDCouplingTwoTimeSteps::checkConsistencyLight();
2475   if(std::fabs(_start_time-_end_time)<_time_tolerance)
2476     throw INTERP_KERNEL::Exception("Start time and end time are equals regarding time tolerance.");
2477 }
2478
2479 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::performCopyOrIncrRef(bool deepCopy) const
2480 {
2481   return new MEDCouplingLinearTime(*this,deepCopy);
2482 }
2483
2484 bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2485 {
2486   if(!MEDCouplingTimeDiscretization::areCompatible(other))
2487     return false;
2488   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2489   if(otherC==0)
2490     return false;
2491   if(_end_array==0 && otherC->_end_array==0)
2492     return true;
2493   if(_end_array==0 || otherC->_end_array==0)
2494     return false;
2495   if(_end_array->getNumberOfComponents()!=otherC->_end_array->getNumberOfComponents())
2496     return false;
2497   return true;
2498 }
2499
2500 bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
2501 {
2502   if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
2503     return false;
2504   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2505   bool ret=otherC!=0;
2506   if(!ret)
2507     reason.insert(0,"time discretization of this is LINEAR_TIME, other has a different time discretization.");
2508   return ret;
2509 }
2510
2511 bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2512 {
2513   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
2514     return false;
2515   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2516   return otherC!=0;
2517 }
2518
2519 bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2520 {
2521   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
2522     return false;
2523   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2524   if(otherC==0)
2525     return false;
2526   if(_end_array==0 && otherC->_end_array==0)
2527     return true;
2528   if(_end_array==0 || otherC->_end_array==0)
2529     return false;
2530   int nbC1=_end_array->getNumberOfComponents();
2531   int nbC2=otherC->_end_array->getNumberOfComponents();
2532   if(nbC1!=nbC2 && nbC2!=1)
2533     return false;
2534   return true;
2535 }
2536
2537 bool MEDCouplingLinearTime::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
2538 {
2539   if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
2540     return false;
2541   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2542   return otherC!=0;
2543 }
2544
2545 /*!
2546  * vals is expected to be of size 2*_array->getNumberOfTuples()==_array->getNumberOfTuples()+_end_array->getNumberOfTuples()
2547  */
2548 void MEDCouplingLinearTime::getValueForTime(double time, const std::vector<double>& vals, double *res) const
2549 {
2550   double alpha=(_end_time-time)/(_end_time-_start_time);
2551   std::size_t nbComp=vals.size()/2;
2552   std::transform(vals.begin(),vals.begin()+nbComp,res,std::bind2nd(std::multiplies<double>(),alpha));
2553   std::vector<double> tmp(nbComp);
2554   std::transform(vals.begin()+nbComp,vals.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2555   std::transform(tmp.begin(),tmp.end(),res,res,std::plus<double>());
2556 }
2557
2558 void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value) const
2559 {
2560   double alpha=(_end_time-time)/(_end_time-_start_time);
2561   int nbComp;
2562   if(_array)
2563     _array->getTuple(eltId,value);
2564   else
2565     throw INTERP_KERNEL::Exception("No start array existing.");
2566   nbComp=_array->getNumberOfComponents();
2567   std::transform(value,value+nbComp,value,std::bind2nd(std::multiplies<double>(),alpha));
2568   std::vector<double> tmp(nbComp);
2569   if(_end_array)
2570     _end_array->getTuple(eltId,&tmp[0]);
2571   else
2572     throw INTERP_KERNEL::Exception("No end array existing.");
2573   std::transform(tmp.begin(),tmp.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2574   std::transform(tmp.begin(),tmp.end(),value,value,std::plus<double>());
2575 }
2576
2577 void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
2578 {
2579   if(iteration==_start_iteration && order==_start_order)
2580     {
2581       if(_array)
2582         _array->getTuple(eltId,value);
2583       else
2584         throw INTERP_KERNEL::Exception("iteration order match with start time but no start array existing.");
2585     }
2586   if(iteration==_end_iteration && order==_end_order)
2587     {
2588       if(_end_array)
2589         _end_array->getTuple(eltId,value);
2590       else
2591         throw INTERP_KERNEL::Exception("iteration order match with end time but no end array existing.");
2592     }
2593   else
2594     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2595 }
2596
2597 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const MEDCouplingTimeDiscretization *other) const
2598 {
2599   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2600   if(!otherC)
2601     throw INTERP_KERNEL::Exception("LinearTime::aggregation on mismatched time discretization !");
2602   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Aggregate(getArray(),other->getArray());
2603   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Aggregate(getEndArray(),other->getEndArray());
2604   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2605   ret->setArray(arr1,0);
2606   ret->setEndArray(arr2,0);
2607   return ret;
2608 }
2609
2610 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
2611 {
2612   std::vector<const DataArrayDouble *> a(other.size());
2613   std::vector<const DataArrayDouble *> b(other.size());
2614   int i=0;
2615   for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
2616     {
2617       const MEDCouplingLinearTime *itC=dynamic_cast<const MEDCouplingLinearTime *>(*it);
2618       if(!itC)
2619         throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::aggregate on mismatched time discretization !");
2620       a[i]=itC->getArray();
2621       b[i]=itC->getEndArray();
2622     }
2623   MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
2624   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Aggregate(b);
2625   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2626   ret->setArray(arr,0);
2627   ret->setEndArray(arr2,0);
2628   return ret;
2629 }
2630
2631 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::meld(const MEDCouplingTimeDiscretization *other) const
2632 {
2633   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2634   if(!otherC)
2635     throw INTERP_KERNEL::Exception("LinearTime::meld on mismatched time discretization !");
2636   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Meld(getArray(),other->getArray());
2637   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Meld(getEndArray(),other->getEndArray());
2638   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2639   ret->setTimeTolerance(getTimeTolerance());
2640   ret->setArray(arr1,0);
2641   ret->setEndArray(arr2,0);
2642   return ret;
2643 }
2644
2645 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeDiscretization *other) const
2646 {
2647   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2648   if(!otherC)
2649     throw INTERP_KERNEL::Exception("LinearTime::dot on mismatched time discretization !");
2650   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Dot(getArray(),other->getArray());
2651   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Dot(getEndArray(),other->getEndArray());
2652   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2653   ret->setArray(arr1,0);
2654   ret->setEndArray(arr2,0);
2655   return ret;
2656 }
2657
2658 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::crossProduct(const MEDCouplingTimeDiscretization *other) const
2659 {
2660   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2661   if(!otherC)
2662     throw INTERP_KERNEL::Exception("LinearTime::crossProduct on mismatched time discretization !");
2663   MCAuto<DataArrayDouble> arr1=DataArrayDouble::CrossProduct(getArray(),other->getArray());
2664   MCAuto<DataArrayDouble> arr2=DataArrayDouble::CrossProduct(getEndArray(),other->getEndArray());
2665   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2666   ret->setArray(arr1,0);
2667   ret->setEndArray(arr2,0);
2668   return ret;
2669 }
2670
2671 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::max(const MEDCouplingTimeDiscretization *other) const
2672 {
2673   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2674   if(!otherC)
2675     throw INTERP_KERNEL::Exception("LinearTime::max on mismatched time discretization !");
2676   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2677   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Max(getArray(),other->getArray());
2678   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Max(getEndArray(),other->getEndArray());
2679   ret->setArray(arr1,0);
2680   ret->setEndArray(arr2,0);
2681   return ret;
2682 }
2683
2684 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::min(const MEDCouplingTimeDiscretization *other) const
2685 {
2686   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2687   if(!otherC)
2688     throw INTERP_KERNEL::Exception("LinearTime::min on mismatched time discretization !");
2689   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Min(getArray(),other->getArray());
2690   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Min(getEndArray(),other->getEndArray());
2691   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2692   ret->setArray(arr1,0);
2693   ret->setEndArray(arr2,0);
2694   return ret;
2695 }
2696
2697 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::add(const MEDCouplingTimeDiscretization *other) const
2698 {
2699   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2700   if(!otherC)
2701     throw INTERP_KERNEL::Exception("LinearTime::add on mismatched time discretization !");
2702   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Add(getArray(),other->getArray());
2703   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Add(getEndArray(),other->getEndArray());
2704   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2705   ret->setArray(arr1,0);
2706   ret->setEndArray(arr2,0);
2707   return ret;
2708 }
2709
2710 void MEDCouplingLinearTime::addEqual(const MEDCouplingTimeDiscretization *other)
2711 {
2712   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2713   if(!otherC)
2714     throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2715   if(!getArray())
2716     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array is NULL !");
2717   if(!getEndArray())
2718     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array (end) is NULL !");
2719   getArray()->addEqual(other->getArray());
2720   getEndArray()->addEqual(other->getEndArray());
2721 }
2722
2723 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::substract(const MEDCouplingTimeDiscretization *other) const
2724 {
2725   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2726   if(!otherC)
2727     throw INTERP_KERNEL::Exception("LinearTime::substract on mismatched time discretization !");
2728   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Substract(getArray(),other->getArray());
2729   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Substract(getEndArray(),other->getEndArray());
2730   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2731   ret->setArray(arr1,0);
2732   ret->setEndArray(arr2,0);
2733   return ret;
2734 }
2735
2736 void MEDCouplingLinearTime::substractEqual(const MEDCouplingTimeDiscretization *other)
2737 {
2738   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2739   if(!otherC)
2740     throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2741   if(!getArray())
2742     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array is NULL !");
2743   if(!getEndArray())
2744     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array (end) is NULL !");
2745   getArray()->substractEqual(other->getArray());
2746   getEndArray()->substractEqual(other->getEndArray());
2747 }
2748
2749 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::multiply(const MEDCouplingTimeDiscretization *other) const
2750 {
2751   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2752   if(!otherC)
2753     throw INTERP_KERNEL::Exception("LinearTime::multiply on mismatched time discretization !");
2754   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Multiply(getArray(),other->getArray());
2755   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Multiply(getEndArray(),other->getEndArray());
2756   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2757   ret->setArray(arr1,0);
2758   ret->setEndArray(arr2,0);
2759   return ret;
2760 }
2761
2762 void MEDCouplingLinearTime::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2763 {
2764   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2765   if(!otherC)
2766     throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2767   if(!getArray())
2768     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array is NULL !");
2769   if(!getEndArray())
2770     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array (end) is NULL !");
2771   getArray()->multiplyEqual(other->getArray());
2772   getEndArray()->multiplyEqual(other->getEndArray());
2773 }
2774
2775 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::divide(const MEDCouplingTimeDiscretization *other) const
2776 {
2777   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2778   if(!otherC)
2779     throw INTERP_KERNEL::Exception("LinearTime::divide on mismatched time discretization !");
2780   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Divide(getArray(),other->getArray());
2781   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Divide(getEndArray(),other->getEndArray());
2782   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2783   ret->setArray(arr1,0);
2784   ret->setEndArray(arr2,0);
2785   return ret;
2786 }
2787
2788 void MEDCouplingLinearTime::divideEqual(const MEDCouplingTimeDiscretization *other)
2789 {
2790   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2791   if(!otherC)
2792     throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2793   if(!getArray())
2794     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array is NULL !");
2795   if(!getEndArray())
2796     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array (end) is NULL !");
2797   getArray()->divideEqual(other->getArray());
2798   getEndArray()->divideEqual(other->getEndArray());
2799 }
2800
2801 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::pow(const MEDCouplingTimeDiscretization *other) const
2802 {
2803   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2804   if(!otherC)
2805     throw INTERP_KERNEL::Exception("LinearTime::pow on mismatched time discretization !");
2806   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Pow(getArray(),other->getArray());
2807   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Pow(getEndArray(),other->getEndArray());
2808   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2809   ret->setArray(arr1,0);
2810   ret->setEndArray(arr2,0);
2811   return ret;
2812 }
2813
2814 void MEDCouplingLinearTime::powEqual(const MEDCouplingTimeDiscretization *other)
2815 {
2816   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2817   if(!otherC)
2818     throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2819   if(!getArray())
2820     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array is NULL !");
2821   if(!getEndArray())
2822     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array (end) is NULL !");
2823   getArray()->powEqual(other->getArray());
2824   getEndArray()->powEqual(other->getEndArray());
2825 }