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