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