Salome HOME
typo-fix by Kunda
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingTimeDiscretization.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingTimeDiscretization.txx"
22 #include "MCAuto.hxx"
23 #include "MEDCouplingMemArray.hxx"
24 #include "MEDCouplingMesh.hxx"
25
26 #include <iterator>
27 #include <algorithm>
28 #include <functional>
29
30 using namespace MEDCoupling;
31
32 template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate<double>;
33 template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate<float>;
34 template class MEDCoupling::MEDCouplingTimeDiscretizationSimple<float>;
35 template class MEDCoupling::MEDCouplingTimeDiscretizationTemplate<int>;
36 template class MEDCoupling::MEDCouplingTimeDiscretizationSimple<int>;
37
38 const char MEDCouplingNoTimeLabel::EXCEPTION_MSG[]="MEDCouplingNoTimeLabel::setTime : no time info attached.";
39
40 const char MEDCouplingNoTimeLabel::REPR[]="No time label defined.";
41
42 const char MEDCouplingWithTimeStep::EXCEPTION_MSG[]="No data on this time.";
43
44 const char MEDCouplingWithTimeStep::REPR[]="One time label.";
45
46 const char MEDCouplingConstOnTimeInterval::EXCEPTION_MSG[]="No data on this time.";
47
48 const char MEDCouplingConstOnTimeInterval::REPR[]="Constant on a time interval.";
49
50 const char MEDCouplingTwoTimeSteps::EXCEPTION_MSG[]="No data on this time.";
51
52 const char MEDCouplingLinearTime::REPR[]="Linear time between 2 time steps.";
53
54 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDiscretization type)
55 {
56   switch(type)
57   {
58     case MEDCouplingNoTimeLabel::DISCRETIZATION:
59       return new MEDCouplingNoTimeLabel;
60     case MEDCouplingWithTimeStep::DISCRETIZATION:
61       return new MEDCouplingWithTimeStep;
62     case MEDCouplingConstOnTimeInterval::DISCRETIZATION:
63       return new MEDCouplingConstOnTimeInterval;
64     case MEDCouplingLinearTime::DISCRETIZATION:
65       return new MEDCouplingLinearTime;
66     default:
67       throw INTERP_KERNEL::Exception("Time discretization not implemented yet");
68   }
69 }
70
71 bool MEDCouplingTimeDiscretization::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
72 {
73   if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
74     return false;
75   if(_array==0 && other->_array==0)
76     return true;
77   if(_array==0 || other->_array==0)
78     return false;
79   if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
80     return false;
81   return true;
82 }
83
84 bool MEDCouplingTimeDiscretization::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
85 {
86   if(!areStrictlyCompatible(other,reason))
87     return false;
88   if(_array==other->getArray())
89     return true;
90   return _array->isEqualIfNotWhy(*other->getArray(),prec,reason);
91 }
92
93 bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
94 {
95   std::string reason;
96   return isEqualIfNotWhy(other,prec,reason);
97 }
98
99 bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
100 {
101   std::string tmp;
102   if(!areStrictlyCompatible(other,tmp))
103     return false;
104   if(_array==other->getArray())
105     return true;
106   return _array->isEqualWithoutConsideringStr(*other->getArray(),prec);
107 }
108
109 MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(TypeOfTimeDiscretization type, bool deepCopy) const
110 {
111   MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(type);
112   ret->setTimeUnit(getTimeUnit());
113   const DataArrayDouble *arrSrc=getArray();
114   MCAuto<DataArrayDouble> arr;
115   if(arrSrc)
116     arr=arrSrc->performCopyOrIncrRef(deepCopy);
117   ret->setArray(arr,0);
118   return ret;
119 }
120
121 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<int>& 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<int>& 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(int 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(int 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(int 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 MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple<int>(other,deepCopy)
698 {
699 }
700
701 MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::performCopyOrIncrRef(bool deepCopy) const
702 {
703   return new MEDCouplingTimeDiscretizationInt(*this,deepCopy);
704 }
705
706 MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::New(TypeOfTimeDiscretization type)
707 {
708   switch(type)
709   {
710     case MEDCouplingTimeDiscretizationInt::DISCRETIZATION:
711       return new MEDCouplingTimeDiscretizationInt;
712     default:
713       throw INTERP_KERNEL::Exception("Time discretization not implemented yet for integers !");
714   }
715 }
716
717 bool MEDCouplingTimeDiscretizationInt::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<int> *other, int 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 MEDCouplingTimeDiscretizationInt *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationInt *>(other));
727   if(!otherC)
728     throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationInt !");
729   if(!MEDCouplingTimeDiscretizationTemplate<int>::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 MEDCouplingTimeDiscretizationInt::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<int> *other, int prec) const
739 {
740   if(prec!=0)
741     throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationInt::isEqualWithoutConsideringStr : only precision 0 is supported !");
742   const MEDCouplingTimeDiscretizationInt *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationInt *>(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 MEDCouplingTimeDiscretizationFloat::MEDCouplingTimeDiscretizationFloat(const MEDCouplingTimeDiscretizationFloat& other, bool deepCopy):MEDCouplingTimeDiscretizationSimple<float>(other,deepCopy)
759 {
760 }
761
762 MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::performCopyOrIncrRef(bool deepCopy) const
763 {
764   return new MEDCouplingTimeDiscretizationFloat(*this,deepCopy);
765 }
766
767 MEDCouplingTimeDiscretizationFloat *MEDCouplingTimeDiscretizationFloat::New(TypeOfTimeDiscretization type)
768 {
769   switch(type)
770   {
771     case MEDCouplingTimeDiscretizationFloat::DISCRETIZATION:
772       return new MEDCouplingTimeDiscretizationFloat;
773     default:
774       throw INTERP_KERNEL::Exception("Time discretization not implemented yet for integers !");
775   }
776 }
777
778 bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec, std::string& reason) const
779 {
780   if(!other)
781     {
782       reason="Time discretization is NULL.";
783       return false;
784     }
785   const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationFloat *>(other));
786   if(!otherC)
787     throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationFloat !");
788   if(!MEDCouplingTimeDiscretizationTemplate<float>::areStrictlyCompatible(other,reason))
789     return false;
790   if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
791     return false;
792   if(_array==other->getArray())
793     return true;
794   return _array->isEqualIfNotWhy(*other->getArray(),prec,reason);
795 }
796
797 bool MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec) const
798 {
799   if(prec!=0)
800     throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationFloat::isEqualWithoutConsideringStr : only precision 0 is supported !");
801   const MEDCouplingTimeDiscretizationFloat *otherC(dynamic_cast<const MEDCouplingTimeDiscretizationFloat *>(other));
802   if(!otherC)
803     throw INTERP_KERNEL::Exception("isEqualWithoutConsideringStr : other is not a MEDCouplingTimeDiscretizationFloat !");
804   std::string tmp;
805   if(!areStrictlyCompatible(other,tmp))
806     return false;
807   std::string reason;
808   if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
809     return false;
810   if(_array==other->getArray())
811     return true;
812   return _array->isEqualWithoutConsideringStr(*(other->getArray()),prec);
813 }
814
815 ////////////////////////
816
817 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel()
818 {
819 }
820
821 MEDCouplingNoTimeLabel::MEDCouplingNoTimeLabel(const MEDCouplingTimeDiscretization& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy)
822 {
823 }
824
825 std::string MEDCouplingNoTimeLabel::getStringRepr() const
826 {
827   std::ostringstream stream;
828   stream << REPR;
829   stream << "\nTime unit is : \"" << getTimeUnit() << "\"";
830   return stream.str();
831 }
832
833 void MEDCouplingNoTimeLabel::synchronizeTimeWith(const MEDCouplingMesh *mesh)
834 {
835   throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::synchronizeTimeWith : impossible to synchronize time with a MEDCouplingMesh because the time discretization is incompatible with it !");
836 }
837
838 bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
839 {
840   if(!MEDCouplingTimeDiscretization::areCompatible(other))
841     return false;
842   const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
843   return otherC!=0;
844 }
845
846 bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
847 {
848   if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
849     return false;
850   const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
851   bool ret=otherC!=0;
852   if(!ret)
853     reason.insert(0,"time discretization of this is NO_TIME, other has a different time discretization.");
854   return ret;
855 }
856
857 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
858 {
859   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
860     return false;
861   const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
862   return otherC!=0;
863 }
864
865 bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
866 {
867   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
868     return false;
869   const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
870   return otherC!=0;
871 }
872
873 bool MEDCouplingNoTimeLabel::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
874 {
875   if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
876     return false;
877   const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
878   return otherC!=0;
879 }
880
881 bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
882 {
883   const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
884   if(!otherC)
885     {
886       reason="This has time discretization NO_TIME, other not.";
887       return false;
888     }
889   return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
890 }
891
892 bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
893 {
894   const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
895   if(!otherC)
896     return false;
897   return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
898 }
899
900 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCouplingTimeDiscretization *other) const
901 {
902   const MEDCouplingNoTimeLabel *otherC(dynamic_cast<const MEDCouplingNoTimeLabel *>(other));
903   if(!otherC)
904     throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !");
905   MCAuto<DataArrayDouble> arr(DataArrayDouble::Aggregate(getArray(),other->getArray()));
906   MEDCouplingNoTimeLabel *ret(new MEDCouplingNoTimeLabel);
907   ret->setArray(arr,0);
908   return ret;
909 }
910
911 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
912 {
913   std::vector<const DataArrayDouble *> a(other.size());
914   int i=0;
915   for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
916     {
917       const MEDCouplingNoTimeLabel *itC=dynamic_cast<const MEDCouplingNoTimeLabel *>(*it);
918       if(!itC)
919         throw INTERP_KERNEL::Exception("NoTimeLabel::aggregate on mismatched time discretization !");
920       a[i]=itC->getArray();
921     }
922   MCAuto<DataArrayDouble> arr(DataArrayDouble::Aggregate(a));
923   MEDCouplingNoTimeLabel *ret(new MEDCouplingNoTimeLabel);
924   ret->setArray(arr,0);
925   return ret;
926 }
927
928 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::meld(const MEDCouplingTimeDiscretization *other) const
929 {
930   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
931   if(!otherC)
932     throw INTERP_KERNEL::Exception("NoTimeLabel::meld on mismatched time discretization !");
933   MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
934   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
935   ret->setTimeTolerance(getTimeTolerance());
936   ret->setArray(arr,0);
937   return ret;
938 }
939
940 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::dot(const MEDCouplingTimeDiscretization *other) const
941 {
942   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
943   if(!otherC)
944     throw INTERP_KERNEL::Exception("NoTimeLabel::dot on mismatched time discretization !");
945   MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
946   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
947   ret->setArray(arr,0);
948   return ret;
949 }
950
951 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::crossProduct(const MEDCouplingTimeDiscretization *other) const
952 {
953   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
954   if(!otherC)
955     throw INTERP_KERNEL::Exception("NoTimeLabel::crossProduct on mismatched time discretization !");
956   MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
957   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
958   ret->setArray(arr,0);
959   return ret;
960 }
961
962 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::max(const MEDCouplingTimeDiscretization *other) const
963 {
964   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
965   if(!otherC)
966     throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
967   MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
968   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
969   ret->setArray(arr,0);
970   return ret;
971 }
972
973 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::min(const MEDCouplingTimeDiscretization *other) const
974 {
975   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
976   if(!otherC)
977     throw INTERP_KERNEL::Exception("NoTimeLabel::max on mismatched time discretization !");
978   MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
979   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
980   ret->setArray(arr,0);
981   return ret;
982 }
983
984 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::add(const MEDCouplingTimeDiscretization *other) const
985 {
986   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
987   if(!otherC)
988     throw INTERP_KERNEL::Exception("NoTimeLabel::add on mismatched time discretization !");
989   MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
990   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
991   ret->setArray(arr,0);
992   return ret;
993 }
994
995 void MEDCouplingNoTimeLabel::addEqual(const MEDCouplingTimeDiscretization *other)
996 {
997   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
998   if(!otherC)
999     throw INTERP_KERNEL::Exception("NoTimeLabel::addEqual on mismatched time discretization !");
1000   if(!getArray())
1001     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::addEqual : Data Array is NULL !");
1002   getArray()->addEqual(other->getArray());
1003 }
1004
1005 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::substract(const MEDCouplingTimeDiscretization *other) const
1006 {
1007   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1008   if(!otherC)
1009     throw INTERP_KERNEL::Exception("NoTimeLabel::substract on mismatched time discretization !");
1010   if(!getArray())
1011     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substract : Data Array is NULL !");
1012   MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1013   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1014   ret->setArray(arr,0);
1015   return ret;
1016 }
1017
1018 void MEDCouplingNoTimeLabel::substractEqual(const MEDCouplingTimeDiscretization *other)
1019 {
1020   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1021   if(!otherC)
1022     throw INTERP_KERNEL::Exception("NoTimeLabel::substractEqual on mismatched time discretization !");
1023   if(!getArray())
1024     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::substractEqual : Data Array is NULL !");
1025   getArray()->substractEqual(other->getArray());
1026 }
1027
1028 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::multiply(const MEDCouplingTimeDiscretization *other) const
1029 {
1030   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1031   if(!otherC)
1032     throw INTERP_KERNEL::Exception("NoTimeLabel::multiply on mismatched time discretization !");
1033   MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1034   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1035   ret->setArray(arr,0);
1036   return ret;
1037 }
1038
1039 void MEDCouplingNoTimeLabel::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1040 {
1041   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1042   if(!otherC)
1043     throw INTERP_KERNEL::Exception("NoTimeLabel::multiplyEqual on mismatched time discretization !");
1044   if(!getArray())
1045     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::multiplyEqual : Data Array is NULL !");
1046   getArray()->multiplyEqual(other->getArray());
1047 }
1048
1049 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::divide(const MEDCouplingTimeDiscretization *other) const
1050 {
1051   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1052   if(!otherC)
1053     throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
1054   MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1055   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1056   ret->setArray(arr,0);
1057   return ret;
1058 }
1059
1060 void MEDCouplingNoTimeLabel::divideEqual(const MEDCouplingTimeDiscretization *other)
1061 {
1062   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1063   if(!otherC)
1064     throw INTERP_KERNEL::Exception("NoTimeLabel::divideEqual on mismatched time discretization !");
1065   if(!getArray())
1066     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::divideEqual : Data Array is NULL !");
1067   getArray()->divideEqual(other->getArray());
1068 }
1069
1070 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::pow(const MEDCouplingTimeDiscretization *other) const
1071 {
1072   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1073   if(!otherC)
1074     throw INTERP_KERNEL::Exception("pow on mismatched time discretization !");
1075   MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
1076   MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel;
1077   ret->setArray(arr,0);
1078   return ret;
1079 }
1080
1081 void MEDCouplingNoTimeLabel::powEqual(const MEDCouplingTimeDiscretization *other)
1082 {
1083   const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
1084   if(!otherC)
1085     throw INTERP_KERNEL::Exception("NoTimeLabel::powEqual on mismatched time discretization !");
1086   if(!getArray())
1087     throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::powEqual : Data Array is NULL !");
1088   getArray()->powEqual(other->getArray());
1089 }
1090
1091 MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCopyOrIncrRef(bool deepCopy) const
1092 {
1093   return new MEDCouplingNoTimeLabel(*this,deepCopy);
1094 }
1095
1096 void MEDCouplingNoTimeLabel::checkTimePresence(double time) const
1097 {
1098   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1099 }
1100
1101 std::vector< const DataArrayDouble *> MEDCouplingNoTimeLabel::getArraysForTime(double time) const
1102 {
1103   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1104 }
1105
1106 void MEDCouplingNoTimeLabel::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1107 {
1108   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1109 }
1110
1111 bool MEDCouplingNoTimeLabel::isBefore(const MEDCouplingTimeDiscretization *other) const
1112 {
1113   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1114 }
1115
1116 bool MEDCouplingNoTimeLabel::isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const
1117 {
1118   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1119 }
1120
1121 double MEDCouplingNoTimeLabel::getStartTime(int& iteration, int& order) const
1122 {
1123   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1124 }
1125
1126 double MEDCouplingNoTimeLabel::getEndTime(int& iteration, int& order) const
1127 {
1128   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1129 }
1130
1131 void MEDCouplingNoTimeLabel::setStartIteration(int it)
1132 {
1133   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1134 }
1135
1136 void MEDCouplingNoTimeLabel::setEndIteration(int it)
1137 {
1138   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1139 }
1140
1141 void MEDCouplingNoTimeLabel::setStartOrder(int order)
1142 {
1143   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1144 }
1145
1146 void MEDCouplingNoTimeLabel::setEndOrder(int order)
1147 {
1148   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1149 }
1150
1151 void MEDCouplingNoTimeLabel::setStartTimeValue(double time)
1152 {
1153   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1154 }
1155
1156 void MEDCouplingNoTimeLabel::setEndTimeValue(double time)
1157 {
1158   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1159 }
1160
1161 void MEDCouplingNoTimeLabel::setStartTime(double time, int iteration, int order)
1162 {
1163   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1164 }
1165
1166 void MEDCouplingNoTimeLabel::setEndTime(double time, int iteration, int order)
1167 {
1168   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1169 }
1170
1171 void MEDCouplingNoTimeLabel::getValueOnTime(int eltId, double time, double *value) const
1172 {
1173   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1174 }
1175
1176 void MEDCouplingNoTimeLabel::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1177 {
1178   throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1179 }
1180
1181 /*!
1182  * idem getTinySerializationIntInformation except that it is for multi field fetch
1183  */
1184 void MEDCouplingNoTimeLabel::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1185 {
1186   tinyInfo.clear();
1187 }
1188
1189 /*!
1190  * idem getTinySerializationDbleInformation except that it is for multi field fetch
1191  */
1192 void MEDCouplingNoTimeLabel::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1193 {
1194   tinyInfo.resize(1);
1195   tinyInfo[0]=_time_tolerance;
1196 }
1197
1198 /*!
1199  * idem finishUnserialization except that it is for multi field fetch
1200  */
1201 void MEDCouplingNoTimeLabel::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1202 {
1203   _time_tolerance=tinyInfoD[0];
1204 }
1205
1206 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep(const MEDCouplingWithTimeStep& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy),_tk(other._tk)
1207 {
1208 }
1209
1210 MEDCouplingWithTimeStep::MEDCouplingWithTimeStep()
1211 {
1212 }
1213
1214 std::string MEDCouplingWithTimeStep::getStringRepr() const
1215 {
1216   std::ostringstream stream;
1217   stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
1218   stream << "\nTime unit is : \"" << getTimeUnit() << "\"";
1219   return stream.str();
1220 }
1221
1222 void MEDCouplingWithTimeStep::synchronizeTimeWith(const MEDCouplingMesh *mesh)
1223 {
1224   if(!mesh)
1225     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
1226   int it=-1,order=-1;
1227   double val=mesh->getTime(it,order);
1228   _tk.setAllInfo(val,it,order);
1229   std::string tUnit(mesh->getTimeUnit());
1230   setTimeUnit(tUnit);
1231 }
1232
1233 void MEDCouplingWithTimeStep::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1234 {
1235   MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1236   tinyInfo.push_back(_tk.getIteration());
1237   tinyInfo.push_back(_tk.getOrder());
1238 }
1239
1240 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1241 {
1242   MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1243   tinyInfo.push_back(_tk.getTimeValue());
1244 }
1245
1246 void MEDCouplingWithTimeStep::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1247 {
1248   MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1249   _tk.setTimeValue(tinyInfoD[1]);
1250   _tk.setIteration(tinyInfoI[2]);
1251   _tk.setOrder(tinyInfoI[3]);
1252 }
1253
1254 /*!
1255  * idem getTinySerializationIntInformation except that it is for multi field fetch
1256  */
1257 void MEDCouplingWithTimeStep::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1258 {
1259   tinyInfo.resize(2);
1260   tinyInfo[0]=_tk.getIteration();
1261   tinyInfo[1]=_tk.getOrder();
1262 }
1263
1264 /*!
1265  * idem getTinySerializationDbleInformation except that it is for multi field fetch
1266  */
1267 void MEDCouplingWithTimeStep::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1268 {
1269   tinyInfo.resize(2);
1270   tinyInfo[0]=_time_tolerance;
1271   tinyInfo[1]=_tk.getTimeValue();
1272 }
1273
1274 /*!
1275  * idem finishUnserialization except that it is for multi field fetch
1276  */
1277 void MEDCouplingWithTimeStep::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1278 {
1279   _tk.setIteration(tinyInfoI[0]);
1280   _tk.setOrder(tinyInfoI[1]);
1281   _time_tolerance=tinyInfoD[0];
1282   _tk.setTimeValue(tinyInfoD[1]);
1283 }
1284
1285 bool MEDCouplingWithTimeStep::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1286 {
1287   if(!MEDCouplingTimeDiscretization::areCompatible(other))
1288     return false;
1289   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1290   return otherC!=0;
1291 }
1292
1293 bool MEDCouplingWithTimeStep::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
1294 {
1295   if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1296     return false;
1297   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1298   bool ret=otherC!=0;
1299   if(!ret)
1300     reason.insert(0,"time discretization of this is ONE_TIME, other has a different time discretization.");
1301   return ret;
1302 }
1303
1304 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1305 {
1306   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1307     return false;
1308   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1309   return otherC!=0;
1310 }
1311
1312 bool MEDCouplingWithTimeStep::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1313 {
1314   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1315     return false;
1316   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1317   return otherC!=0;
1318 }
1319
1320 bool MEDCouplingWithTimeStep::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1321 {
1322   if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1323     return false;
1324   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1325   return otherC!=0;
1326 }
1327
1328 bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
1329 {
1330   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1331   std::ostringstream oss; oss.precision(15);
1332   if(!otherC)
1333     {
1334       reason="This has time discretization ONE_TIME, other not.";
1335       return false;
1336     }
1337   if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason))
1338     return false;
1339   return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1340 }
1341
1342 bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
1343 {
1344   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1345   if(!otherC)
1346     return false;
1347   if(!_tk.isEqual(otherC->_tk,_time_tolerance))
1348      return false;
1349   return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1350 }
1351
1352 void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
1353 {
1354   MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1355   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(&other);
1356   if(!otherC)
1357     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::copyTinyAttrFrom : mismatch of time discretization !");
1358   _tk.copyFrom(otherC->_tk);
1359 }
1360
1361 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCouplingTimeDiscretization *other) const
1362 {
1363   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1364   if(!otherC)
1365     throw INTERP_KERNEL::Exception("WithTimeStep::aggregation on mismatched time discretization !");
1366   MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1367   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1368   ret->setArray(arr,0);
1369   return ret;
1370 }
1371
1372 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1373 {
1374   std::vector<const DataArrayDouble *> a(other.size());
1375   int i=0;
1376   for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1377     {
1378       const MEDCouplingWithTimeStep *itC=dynamic_cast<const MEDCouplingWithTimeStep *>(*it);
1379       if(!itC)
1380         throw INTERP_KERNEL::Exception("WithTimeStep::aggregate on mismatched time discretization !");
1381       a[i]=itC->getArray();
1382     }
1383   MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1384   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1385   ret->setArray(arr,0);
1386   return ret;
1387 }
1388
1389 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::meld(const MEDCouplingTimeDiscretization *other) const
1390 {
1391   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1392   if(!otherC)
1393     throw INTERP_KERNEL::Exception("WithTimeStep::meld on mismatched time discretization !");
1394   MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1395   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1396   ret->setArray(arr,0);
1397   return ret;
1398 }
1399
1400 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::dot(const MEDCouplingTimeDiscretization *other) const
1401 {
1402   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1403   if(!otherC)
1404     throw INTERP_KERNEL::Exception("WithTimeStep::dot on mismatched time discretization !");
1405   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1406   MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1407   ret->setArray(arr,0);
1408   return ret;
1409 }
1410
1411 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::crossProduct(const MEDCouplingTimeDiscretization *other) const
1412 {
1413   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1414   if(!otherC)
1415     throw INTERP_KERNEL::Exception("WithTimeStep::crossProduct on mismatched time discretization !");
1416   MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1417   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1418   ret->setArray(arr,0);
1419   return ret;
1420 }
1421
1422 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::max(const MEDCouplingTimeDiscretization *other) const
1423 {
1424   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1425   if(!otherC)
1426     throw INTERP_KERNEL::Exception("WithTimeStep::max on mismatched time discretization !");
1427   MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1428   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1429   ret->setArray(arr,0);
1430   return ret;
1431 }
1432
1433 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::min(const MEDCouplingTimeDiscretization *other) const
1434 {
1435   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1436   if(!otherC)
1437     throw INTERP_KERNEL::Exception("WithTimeStep::min on mismatched time discretization !");
1438   MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1439   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1440   ret->setArray(arr,0);
1441   return ret;
1442 }
1443
1444 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::add(const MEDCouplingTimeDiscretization *other) const
1445 {
1446   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1447   if(!otherC)
1448     throw INTERP_KERNEL::Exception("WithTimeStep::add on mismatched time discretization !");
1449   MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1450   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1451   ret->setArray(arr,0);
1452   int tmp1,tmp2;
1453   double tmp3=getStartTime(tmp1,tmp2);
1454   ret->setStartTime(tmp3,tmp1,tmp2);
1455   return ret;
1456 }
1457
1458 void MEDCouplingWithTimeStep::addEqual(const MEDCouplingTimeDiscretization *other)
1459 {
1460   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1461   if(!otherC)
1462     throw INTERP_KERNEL::Exception("WithTimeStep::addEqual on mismatched time discretization !");
1463   if(!getArray())
1464     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::addEqual : Data Array is NULL !");
1465   getArray()->addEqual(other->getArray());
1466 }
1467
1468 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::substract(const MEDCouplingTimeDiscretization *other) const
1469 {
1470   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1471   if(!otherC)
1472     throw INTERP_KERNEL::Exception("WithTimeStep::substract on mismatched time discretization !");
1473   MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1474   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1475   ret->setArray(arr,0);
1476   int tmp1,tmp2;
1477   double tmp3=getStartTime(tmp1,tmp2);
1478   ret->setStartTime(tmp3,tmp1,tmp2);
1479   return ret;
1480 }
1481
1482 void MEDCouplingWithTimeStep::substractEqual(const MEDCouplingTimeDiscretization *other)
1483 {
1484   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1485   if(!otherC)
1486     throw INTERP_KERNEL::Exception("WithTimeStep::substractEqual on mismatched time discretization !");
1487   if(!getArray())
1488     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::substractEqual : Data Array is NULL !");
1489   getArray()->substractEqual(other->getArray());
1490 }
1491
1492 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::multiply(const MEDCouplingTimeDiscretization *other) const
1493 {
1494   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1495   if(!otherC)
1496     throw INTERP_KERNEL::Exception("WithTimeStep::multiply on mismatched time discretization !");
1497   MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1498   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1499   ret->setArray(arr,0);
1500   int tmp1,tmp2;
1501   double tmp3=getStartTime(tmp1,tmp2);
1502   ret->setStartTime(tmp3,tmp1,tmp2);
1503   return ret;
1504 }
1505
1506 void MEDCouplingWithTimeStep::multiplyEqual(const MEDCouplingTimeDiscretization *other)
1507 {
1508   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1509   if(!otherC)
1510     throw INTERP_KERNEL::Exception("WithTimeStep::multiplyEqual on mismatched time discretization !");
1511   if(!getArray())
1512     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::multiplyEqual : Data Array is NULL !");
1513   getArray()->multiplyEqual(other->getArray());
1514 }
1515
1516 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::divide(const MEDCouplingTimeDiscretization *other) const
1517 {
1518   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1519   if(!otherC)
1520     throw INTERP_KERNEL::Exception("WithTimeStep::divide on mismatched time discretization !");
1521   MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
1522   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1523   ret->setArray(arr,0);
1524   int tmp1,tmp2;
1525   double tmp3=getStartTime(tmp1,tmp2);
1526   ret->setStartTime(tmp3,tmp1,tmp2);
1527   return ret;
1528 }
1529
1530 void MEDCouplingWithTimeStep::divideEqual(const MEDCouplingTimeDiscretization *other)
1531 {
1532   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1533   if(!otherC)
1534     throw INTERP_KERNEL::Exception("WithTimeStep::divideEqual on mismatched time discretization !");
1535   if(!getArray())
1536     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::divideEqual : Data Array is NULL !");
1537   getArray()->divideEqual(other->getArray());
1538 }
1539
1540 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::pow(const MEDCouplingTimeDiscretization *other) const
1541 {
1542   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1543   if(!otherC)
1544     throw INTERP_KERNEL::Exception("WithTimeStep::pow on mismatched time discretization !");
1545   MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
1546   MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep;
1547   ret->setArray(arr,0);
1548   int tmp1,tmp2;
1549   double tmp3=getStartTime(tmp1,tmp2);
1550   ret->setStartTime(tmp3,tmp1,tmp2);
1551   return ret;
1552 }
1553
1554 void MEDCouplingWithTimeStep::powEqual(const MEDCouplingTimeDiscretization *other)
1555 {
1556   const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
1557   if(!otherC)
1558     throw INTERP_KERNEL::Exception("WithTimeStep::powEqual on mismatched time discretization !");
1559   if(!getArray())
1560     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::powEqual : Data Array is NULL !");
1561   getArray()->powEqual(other->getArray());
1562 }
1563
1564 MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCopyOrIncrRef(bool deepCopy) const
1565 {
1566   return new MEDCouplingWithTimeStep(*this,deepCopy);
1567 }
1568
1569 void MEDCouplingWithTimeStep::checkNoTimePresence() const
1570 {
1571   throw INTERP_KERNEL::Exception("No time specified on a field defined on one time");
1572 }
1573
1574 void MEDCouplingWithTimeStep::checkTimePresence(double time) const
1575 {
1576   _tk.checkTimePresence(time,_time_tolerance);
1577 }
1578
1579 std::vector< const DataArrayDouble *> MEDCouplingWithTimeStep::getArraysForTime(double time) const
1580 {
1581   if(std::fabs(time-_tk.getTimeValue())<=_time_tolerance)
1582     {
1583       std::vector< const DataArrayDouble *> ret(1);
1584       ret[0]=_array;
1585       return ret;
1586     }
1587   else
1588     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1589 }
1590
1591 void MEDCouplingWithTimeStep::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1592 {
1593   std::copy(vals.begin(),vals.end(),res);
1594 }
1595
1596 void MEDCouplingWithTimeStep::getValueOnTime(int eltId, double time, double *value) const
1597 {
1598   if(std::fabs(time-_tk.getTimeValue())<=_time_tolerance)
1599     if(_array)
1600       _array->getTuple(eltId,value);
1601     else
1602       throw INTERP_KERNEL::Exception("No array existing.");
1603   else
1604     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1605 }
1606
1607 void MEDCouplingWithTimeStep::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1608 {
1609   if(_tk.getIteration()==iteration && _tk.getOrder()==order)
1610     if(_array)
1611       _array->getTuple(eltId,value);
1612     else
1613       throw INTERP_KERNEL::Exception("No array existing.");
1614   else
1615     throw INTERP_KERNEL::Exception("No data on this discrete time.");
1616 }
1617
1618 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval()
1619 {
1620 }
1621
1622 void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
1623 {
1624   MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
1625   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(&other);
1626   if(!otherC)
1627     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::copyTinyAttrFrom : mismatch of time discretization !");
1628   _start.copyFrom(otherC->_start);
1629   _end.copyFrom(otherC->_end);
1630 }
1631
1632 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1633 {
1634   MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
1635   tinyInfo.push_back(_start.getIteration());
1636   tinyInfo.push_back(_start.getOrder());
1637   tinyInfo.push_back(_end.getIteration());
1638   tinyInfo.push_back(_end.getOrder());
1639 }
1640
1641 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1642 {
1643   MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
1644   tinyInfo.push_back(_start.getTimeValue());
1645   tinyInfo.push_back(_end.getTimeValue());
1646 }
1647
1648 void MEDCouplingConstOnTimeInterval::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1649 {
1650   MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
1651   _start.setTimeValue(tinyInfoD[1]);
1652   _end.setTimeValue(tinyInfoD[2]);
1653   _start.setIteration(tinyInfoI[2]);
1654   _start.setOrder(tinyInfoI[3]);
1655   _end.setIteration(tinyInfoI[4]);
1656   _end.setOrder(tinyInfoI[5]);
1657 }
1658
1659 /*!
1660  * idem getTinySerializationIntInformation except that it is for multi field fetch
1661  */
1662 void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
1663 {
1664   tinyInfo.resize(4);
1665   tinyInfo[0]=_start.getIteration();
1666   tinyInfo[1]=_start.getOrder();
1667   tinyInfo[2]=_end.getIteration();
1668   tinyInfo[3]=_end.getOrder();
1669 }
1670
1671 /*!
1672  * idem getTinySerializationDbleInformation except that it is for multi field fetch
1673  */
1674 void MEDCouplingConstOnTimeInterval::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
1675 {
1676   tinyInfo.resize(3);
1677   tinyInfo[0]=_time_tolerance;
1678   tinyInfo[1]=_start.getTimeValue();
1679   tinyInfo[2]=_end.getTimeValue();
1680 }
1681
1682 /*!
1683  * idem finishUnserialization except that it is for multi field fetch
1684  */
1685 void MEDCouplingConstOnTimeInterval::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
1686 {
1687   _start.setIteration(tinyInfoI[0]);
1688   _start.setOrder(tinyInfoI[1]);
1689   _end.setIteration(tinyInfoI[2]);
1690   _end.setOrder(tinyInfoI[3]);
1691   _time_tolerance=tinyInfoD[0];
1692   _start.setTimeValue(tinyInfoD[1]);
1693   _end.setTimeValue(tinyInfoD[2]);
1694 }
1695
1696 MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCopy):
1697   MEDCouplingTimeDiscretization(other,deepCopy),_start(other._start),_end(other._end)
1698 {
1699 }
1700
1701 std::string MEDCouplingConstOnTimeInterval::getStringRepr() const
1702 {
1703   std::ostringstream stream;
1704   stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n";
1705   stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n";
1706   stream << "\nTime unit is : \"" << getTimeUnit() << "\"";
1707   return stream.str();
1708 }
1709
1710 void MEDCouplingConstOnTimeInterval::synchronizeTimeWith(const MEDCouplingMesh *mesh)
1711 {
1712   if(!mesh)
1713     throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
1714   int it=-1,order=-1;
1715   double val=mesh->getTime(it,order);
1716   _start.setAllInfo(val,it,order);
1717   _end.setAllInfo(val,it,order);
1718   std::string tUnit(mesh->getTimeUnit());
1719   setTimeUnit(tUnit);
1720 }
1721
1722 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::performCopyOrIncrRef(bool deepCopy) const
1723 {
1724   return new MEDCouplingConstOnTimeInterval(*this,deepCopy);
1725 }
1726
1727 std::vector< const DataArrayDouble *> MEDCouplingConstOnTimeInterval::getArraysForTime(double time) const
1728 {
1729   if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
1730     {
1731       std::vector< const DataArrayDouble *> ret(1);
1732       ret[0]=_array;
1733       return ret;
1734     }
1735   else
1736     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1737 }
1738
1739 void MEDCouplingConstOnTimeInterval::getValueForTime(double time, const std::vector<double>& vals, double *res) const
1740 {
1741   std::copy(vals.begin(),vals.end(),res);
1742 }
1743
1744 bool MEDCouplingConstOnTimeInterval::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1745 {
1746   if(!MEDCouplingTimeDiscretization::areCompatible(other))
1747     return false;
1748   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1749   return otherC!=0;
1750 }
1751
1752 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
1753 {
1754   if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
1755     return false;
1756   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1757   bool ret=otherC!=0;
1758   if(!ret)
1759     reason.insert(0,"time discretization of this is CONST_ON_TIME_INTERVAL, other has a different time discretization.");
1760   return ret;
1761 }
1762
1763 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1764 {
1765   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
1766     return false;
1767   const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1768   return otherC!=0;
1769 }
1770
1771 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
1772 {
1773   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
1774     return false;
1775   const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1776   return otherC!=0;
1777 }
1778
1779 bool MEDCouplingConstOnTimeInterval::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
1780 {
1781   if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
1782     return false;
1783   const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1784   return otherC!=0;
1785 }
1786
1787 bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
1788 {
1789   const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1790   std::ostringstream oss; oss.precision(15);
1791   if(!otherC)
1792     {
1793       reason="This has time discretization CONST_ON_TIME_INTERVAL, other not.";
1794       return false;
1795     }
1796   if(!_start.isEqualIfNotWhy(otherC->_start,_time_tolerance,reason))
1797     return false;
1798   if(!_end.isEqualIfNotWhy(otherC->_end,_time_tolerance,reason))
1799     return false;
1800   return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
1801 }
1802
1803 bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
1804 {
1805   const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other));
1806   if(!otherC)
1807     return false;
1808   if(!_start.isEqual(otherC->_start,_time_tolerance))
1809     return false;
1810   if(!_end.isEqual(otherC->_end,_time_tolerance))
1811     return false;
1812   return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
1813 }
1814
1815 void MEDCouplingConstOnTimeInterval::getValueOnTime(int eltId, double time, double *value) const
1816 {
1817   if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
1818     if(_array)
1819       _array->getTuple(eltId,value);
1820     else
1821       throw INTERP_KERNEL::Exception("No array existing.");
1822   else
1823     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1824 }
1825
1826 void MEDCouplingConstOnTimeInterval::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
1827 {
1828   if(iteration>=_start.getIteration() && iteration<=_end.getIteration())
1829     if(_array)
1830       _array->getTuple(eltId,value);
1831     else
1832       throw INTERP_KERNEL::Exception("No array existing.");
1833   else
1834     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
1835 }
1836
1837 void MEDCouplingConstOnTimeInterval::checkNoTimePresence() const
1838 {
1839   throw INTERP_KERNEL::Exception("No time specified on a field defined as constant on one time interval");
1840 }
1841
1842 void MEDCouplingConstOnTimeInterval::checkTimePresence(double time) const
1843 {
1844   if(time<_start.getTimeValue()-_time_tolerance || time>_end.getTimeValue()+_time_tolerance)
1845     {
1846       std::ostringstream stream;
1847       stream << "The field is defined between times " << _start.getTimeValue() << " and " << _end.getTimeValue() << " worderh tolerance ";
1848       stream << _time_tolerance << " and trying to access on time = " << time;
1849       throw INTERP_KERNEL::Exception(stream.str().c_str());
1850     }
1851 }
1852
1853 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const MEDCouplingTimeDiscretization *other) const
1854 {
1855   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1856   if(!otherC)
1857     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregation on mismatched time discretization !");
1858   MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(getArray(),other->getArray());
1859   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1860   ret->setArray(arr,0);
1861   return ret;
1862 }
1863
1864 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
1865 {
1866   std::vector<const DataArrayDouble *> a(other.size());
1867   int i=0;
1868   for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
1869     {
1870       const MEDCouplingConstOnTimeInterval *itC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(*it);
1871       if(!itC)
1872         throw INTERP_KERNEL::Exception("ConstOnTimeInterval::aggregate on mismatched time discretization !");
1873       a[i]=itC->getArray();
1874     }
1875   MCAuto<DataArrayDouble> arr=DataArrayDouble::Aggregate(a);
1876   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1877   ret->setArray(arr,0);
1878   return ret;
1879 }
1880
1881 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::meld(const MEDCouplingTimeDiscretization *other) const
1882 {
1883   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1884   if(!otherC)
1885     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::meld on mismatched time discretization !");
1886   MCAuto<DataArrayDouble> arr=DataArrayDouble::Meld(getArray(),other->getArray());
1887   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1888   ret->setTimeTolerance(getTimeTolerance());
1889   ret->setArray(arr,0);
1890   return ret;
1891 }
1892
1893 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::dot(const MEDCouplingTimeDiscretization *other) const
1894 {
1895   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1896   if(!otherC)
1897     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::dot on mismatched time discretization !");
1898   MCAuto<DataArrayDouble> arr=DataArrayDouble::Dot(getArray(),other->getArray());
1899   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1900   ret->setArray(arr,0);
1901   return ret;
1902 }
1903
1904 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::crossProduct(const MEDCouplingTimeDiscretization *other) const
1905 {
1906   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1907   if(!otherC)
1908     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::crossProduct on mismatched time discretization !");
1909   MCAuto<DataArrayDouble> arr=DataArrayDouble::CrossProduct(getArray(),other->getArray());
1910   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1911   ret->setArray(arr,0);
1912   return ret;
1913 }
1914
1915 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::max(const MEDCouplingTimeDiscretization *other) const
1916 {
1917   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1918   if(!otherC)
1919     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::max on mismatched time discretization !");
1920   MCAuto<DataArrayDouble> arr=DataArrayDouble::Max(getArray(),other->getArray());
1921   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1922   ret->setArray(arr,0);
1923   return ret;
1924 }
1925
1926 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::min(const MEDCouplingTimeDiscretization *other) const
1927 {
1928   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1929   if(!otherC)
1930     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::min on mismatched time discretization !");
1931   MCAuto<DataArrayDouble> arr=DataArrayDouble::Min(getArray(),other->getArray());
1932   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1933   ret->setArray(arr,0);
1934   return ret;
1935 }
1936
1937 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::add(const MEDCouplingTimeDiscretization *other) const
1938 {
1939   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1940   if(!otherC)
1941     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::add on mismatched time discretization !");
1942   MCAuto<DataArrayDouble> arr=DataArrayDouble::Add(getArray(),other->getArray());
1943   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1944   ret->setArray(arr,0);
1945   int tmp1,tmp2;
1946   double tmp3=getStartTime(tmp1,tmp2);
1947   ret->setStartTime(tmp3,tmp1,tmp2);
1948   tmp3=getEndTime(tmp1,tmp2);
1949   ret->setEndTime(tmp3,tmp1,tmp2);
1950   return ret;
1951 }
1952
1953 void MEDCouplingConstOnTimeInterval::addEqual(const MEDCouplingTimeDiscretization *other)
1954 {
1955   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1956   if(!otherC)
1957     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::addEqual on mismatched time discretization !");
1958   if(!getArray())
1959     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractaddEqual : Data Array is NULL !");
1960   getArray()->addEqual(other->getArray());
1961 }
1962
1963 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::substract(const MEDCouplingTimeDiscretization *other) const
1964 {
1965   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1966   if(!otherC)
1967     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substract on mismatched time discretization !");
1968   MCAuto<DataArrayDouble> arr=DataArrayDouble::Substract(getArray(),other->getArray());
1969   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1970   ret->setArray(arr,0);
1971   int tmp1,tmp2;
1972   double tmp3=getStartTime(tmp1,tmp2);
1973   ret->setStartTime(tmp3,tmp1,tmp2);
1974   tmp3=getEndTime(tmp1,tmp2);
1975   ret->setEndTime(tmp3,tmp1,tmp2);
1976   return ret;
1977 }
1978
1979 void MEDCouplingConstOnTimeInterval::substractEqual(const MEDCouplingTimeDiscretization *other)
1980 {
1981   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1982   if(!otherC)
1983     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::substractEqual on mismatched time discretization !");
1984   if(!getArray())
1985     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::substractEqual : Data Array is NULL !");
1986   getArray()->substractEqual(other->getArray());
1987 }
1988
1989 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::multiply(const MEDCouplingTimeDiscretization *other) const
1990 {
1991   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
1992   if(!otherC)
1993     throw INTERP_KERNEL::Exception("multiply on mismatched time discretization !");
1994   MCAuto<DataArrayDouble> arr=DataArrayDouble::Multiply(getArray(),other->getArray());
1995   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
1996   ret->setArray(arr,0);
1997   int tmp1,tmp2;
1998   double tmp3=getStartTime(tmp1,tmp2);
1999   ret->setStartTime(tmp3,tmp1,tmp2);
2000   tmp3=getEndTime(tmp1,tmp2);
2001   ret->setEndTime(tmp3,tmp1,tmp2);
2002   return ret;
2003 }
2004
2005 void MEDCouplingConstOnTimeInterval::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2006 {
2007   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2008   if(!otherC)
2009     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::multiplyEqual on mismatched time discretization !");
2010   if(!getArray())
2011     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::multiplyEqual : Data Array is NULL !");
2012   getArray()->multiplyEqual(other->getArray());
2013 }
2014
2015 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::divide(const MEDCouplingTimeDiscretization *other) const
2016 {
2017   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2018   if(!otherC)
2019     throw INTERP_KERNEL::Exception("divide on mismatched time discretization !");
2020   MCAuto<DataArrayDouble> arr=DataArrayDouble::Divide(getArray(),other->getArray());
2021   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2022   ret->setArray(arr,0);
2023   int tmp1,tmp2;
2024   double tmp3=getStartTime(tmp1,tmp2);
2025   ret->setStartTime(tmp3,tmp1,tmp2);
2026   tmp3=getEndTime(tmp1,tmp2);
2027   ret->setEndTime(tmp3,tmp1,tmp2);
2028   return ret;
2029 }
2030
2031 void MEDCouplingConstOnTimeInterval::divideEqual(const MEDCouplingTimeDiscretization *other)
2032 {
2033   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2034   if(!otherC)
2035     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::divideEqual on mismatched time discretization !");
2036   if(!getArray())
2037     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::divideEqual : Data Array is NULL !");
2038   getArray()->divideEqual(other->getArray());
2039 }
2040
2041 MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::pow(const MEDCouplingTimeDiscretization *other) const
2042 {
2043   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2044   if(!otherC)
2045     throw INTERP_KERNEL::Exception("pow on mismatched time discretization !");
2046   MCAuto<DataArrayDouble> arr=DataArrayDouble::Pow(getArray(),other->getArray());
2047   MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval;
2048   ret->setArray(arr,0);
2049   int tmp1,tmp2;
2050   double tmp3=getStartTime(tmp1,tmp2);
2051   ret->setStartTime(tmp3,tmp1,tmp2);
2052   tmp3=getEndTime(tmp1,tmp2);
2053   ret->setEndTime(tmp3,tmp1,tmp2);
2054   return ret;
2055 }
2056
2057 void MEDCouplingConstOnTimeInterval::powEqual(const MEDCouplingTimeDiscretization *other)
2058 {
2059   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
2060   if(!otherC)
2061     throw INTERP_KERNEL::Exception("ConstOnTimeInterval::powEqual on mismatched time discretization !");
2062   if(!getArray())
2063     throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::powEqual : Data Array is NULL !");
2064   getArray()->powEqual(other->getArray());
2065 }
2066
2067 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy),
2068                                                                                                       _start(other._start),_end(other._end)
2069 {
2070   if(other._end_array)
2071     _end_array=other._end_array->performCopyOrIncrRef(deepCopy);
2072   else
2073     _end_array=0;
2074 }
2075
2076 void MEDCouplingTwoTimeSteps::updateTime() const
2077 {
2078   MEDCouplingTimeDiscretization::updateTime();
2079   if(_end_array)
2080     updateTimeWith(*_end_array);
2081 }
2082
2083 void MEDCouplingTwoTimeSteps::synchronizeTimeWith(const MEDCouplingMesh *mesh)
2084 {
2085   if(!mesh)
2086     throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !");
2087   int it=-1,order=-1;
2088   double val=mesh->getTime(it,order);
2089   _start.setAllInfo(val,it,order);
2090   _end.setAllInfo(val,it,order);
2091   std::string tUnit(mesh->getTimeUnit());
2092   setTimeUnit(tUnit);
2093 }
2094
2095 std::size_t MEDCouplingTwoTimeSteps::getHeapMemorySizeWithoutChildren() const
2096 {
2097   return MEDCouplingTimeDiscretization::getHeapMemorySizeWithoutChildren();
2098 }
2099
2100 std::vector<const BigMemoryObject *> MEDCouplingTwoTimeSteps::getDirectChildrenWithNull() const
2101 {
2102   std::vector<const BigMemoryObject *> ret(MEDCouplingTimeDiscretization::getDirectChildrenWithNull());
2103   ret.push_back(_end_array);
2104   return ret;
2105 }
2106
2107 void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
2108 {
2109   MEDCouplingTimeDiscretization::copyTinyAttrFrom(other);
2110   const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2111   if(!otherC)
2112     throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::copyTinyAttrFrom : mismatch of time discretization !");
2113   _start.copyFrom(otherC->_start);
2114   _end.copyFrom(otherC->_end);
2115 }
2116
2117 void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate<double>& other)
2118 {
2119   MEDCouplingTimeDiscretization::copyTinyStringsFrom(other);
2120   const MEDCouplingTwoTimeSteps *otherC=dynamic_cast<const MEDCouplingTwoTimeSteps *>(&other);
2121   if(!otherC)
2122     throw INTERP_KERNEL::Exception("Trying to operate copyTinyStringsFrom on different field type (two times//one time) !");
2123   if(_end_array && otherC->_end_array)
2124     _end_array->copyStringInfoFrom(*otherC->_end_array);
2125 }
2126
2127 const DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray() const
2128 {
2129   return _end_array;
2130 }
2131
2132 DataArrayDouble *MEDCouplingTwoTimeSteps::getEndArray()
2133 {
2134   return _end_array;
2135 }
2136
2137 void MEDCouplingTwoTimeSteps::checkConsistencyLight() const
2138 {
2139   MEDCouplingTimeDiscretization::checkConsistencyLight();
2140   if(!_end_array)
2141     throw INTERP_KERNEL::Exception("No end array specified !");
2142   if(_array->getNumberOfComponents()!=_end_array->getNumberOfComponents())
2143     throw INTERP_KERNEL::Exception("The number of components mismatch between the start and the end arrays !");
2144   if(_array->getNumberOfTuples()!=_end_array->getNumberOfTuples())
2145     throw INTERP_KERNEL::Exception("The number of tuples mismatch between the start and the end arrays !");
2146 }
2147
2148 bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec, std::string& reason) const
2149 {
2150   std::ostringstream oss;
2151   const MEDCouplingTwoTimeSteps *otherC(dynamic_cast<const MEDCouplingTwoTimeSteps *>(other));
2152   if(!otherC)
2153     {
2154       reason="This has time discretization LINEAR_TIME, other not.";
2155       return false;
2156     }
2157   if(!_start.isEqualIfNotWhy(otherC->_start,_time_tolerance,reason))
2158     return false;
2159   if(!_end.isEqualIfNotWhy(otherC->_end,_time_tolerance,reason))
2160     return false;
2161   if(_end_array!=otherC->_end_array)
2162     if(!_end_array->isEqualIfNotWhy(*otherC->_end_array,prec,reason))
2163       {
2164         reason.insert(0,"end arrays differ for linear time.");
2165         return false;
2166       }
2167   return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason);
2168 }
2169
2170 bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate<double> *other, double prec) const
2171 {
2172   const MEDCouplingTwoTimeSteps *otherC(dynamic_cast<const MEDCouplingTwoTimeSteps *>(other));
2173   if(!otherC)
2174     return false;
2175   if(!_start.isEqual(otherC->_start,_time_tolerance))
2176     return false;
2177   if(!_end.isEqual(otherC->_end,_time_tolerance))
2178     return false;
2179   if(_end_array!=otherC->_end_array)
2180     if(!_end_array->isEqualWithoutConsideringStr(*otherC->_end_array,prec))
2181       return false;
2182   return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec);
2183 }
2184
2185 MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_end_array(0)
2186 {
2187 }
2188
2189 MEDCouplingTwoTimeSteps::~MEDCouplingTwoTimeSteps()
2190 {
2191   if(_end_array)
2192     _end_array->decrRef();
2193 }
2194
2195 void MEDCouplingTwoTimeSteps::checkNoTimePresence() const
2196 {
2197   throw INTERP_KERNEL::Exception("The field presents a time to be specified in every access !");
2198 }
2199
2200 void MEDCouplingTwoTimeSteps::checkTimePresence(double time) const
2201 {
2202   if(time<_start.getTimeValue()-_time_tolerance || time>_end.getTimeValue()+_time_tolerance)
2203     {
2204       std::ostringstream stream;
2205       stream << "The field is defined between times " << _start.getTimeValue() << " and " << _end.getTimeValue() << " worderh tolerance ";
2206       stream << _time_tolerance << " and trying to access on time = " << time;
2207       throw INTERP_KERNEL::Exception(stream.str().c_str());
2208     }
2209 }
2210
2211 void MEDCouplingTwoTimeSteps::getArrays(std::vector<DataArrayDouble *>& arrays) const
2212 {
2213   arrays.resize(2);
2214   arrays[0]=_array;
2215   arrays[1]=_end_array;
2216 }
2217
2218 void MEDCouplingTwoTimeSteps::setEndArray(DataArrayDouble *array, TimeLabel *owner)
2219 {
2220   if(array!=_end_array)
2221     {
2222       if(_end_array)
2223         _end_array->decrRef();
2224       _end_array=array;
2225       if(_end_array)
2226         _end_array->incrRef();
2227       if(owner)
2228         owner->declareAsNew();
2229     }
2230 }
2231
2232 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
2233 {
2234   MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo);
2235   tinyInfo.push_back(_start.getIteration());
2236   tinyInfo.push_back(_start.getOrder());
2237   tinyInfo.push_back(_end.getIteration());
2238   tinyInfo.push_back(_end.getOrder());
2239   if(_end_array)
2240     {
2241       tinyInfo.push_back(_end_array->getNumberOfTuples());
2242       tinyInfo.push_back(_end_array->getNumberOfComponents());
2243     }
2244   else
2245     {
2246       tinyInfo.push_back(-1);
2247       tinyInfo.push_back(-1);
2248     }
2249 }
2250
2251 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
2252 {
2253   MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo);
2254   tinyInfo.push_back(_start.getTimeValue());
2255   tinyInfo.push_back(_end.getTimeValue());
2256 }
2257
2258 void MEDCouplingTwoTimeSteps::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
2259 {
2260   int nbOfCompo=_array->getNumberOfComponents();
2261   for(int i=0;i<nbOfCompo;i++)
2262     tinyInfo.push_back(_array->getInfoOnComponent(i));
2263   for(int i=0;i<nbOfCompo;i++)
2264     tinyInfo.push_back(_end_array->getInfoOnComponent(i));
2265 }
2266
2267 void MEDCouplingTwoTimeSteps::resizeForUnserialization(const std::vector<int>& tinyInfoI, std::vector<DataArrayDouble *>& arrays)
2268 {
2269   arrays.resize(2);
2270   if(_array!=0)
2271     _array->decrRef();
2272   if(_end_array!=0)
2273     _end_array->decrRef();
2274   DataArrayDouble *arr=0;
2275   if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2276     {
2277       arr=DataArrayDouble::New();
2278       arr->alloc(tinyInfoI[0],tinyInfoI[1]);
2279     }
2280   _array=arr;
2281   arrays[0]=arr;
2282   arr=0;
2283   if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2284     {
2285       arr=DataArrayDouble::New();
2286       arr->alloc(tinyInfoI[6],tinyInfoI[7]);
2287     }
2288   _end_array=arr;
2289   arrays[1]=arr;
2290 }
2291
2292 void MEDCouplingTwoTimeSteps::checkForUnserialization(const std::vector<int>& tinyInfoI, const std::vector<DataArrayDouble *>& arrays)
2293 {
2294   static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size two !";
2295   if(arrays.size()!=2)
2296     throw INTERP_KERNEL::Exception(MSG);
2297   if(_array!=0)
2298     _array->decrRef();
2299   if(_end_array!=0)
2300     _end_array->decrRef();
2301   _array=0; _end_array=0;
2302   if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
2303     {
2304       if(!arrays[0])
2305         throw INTERP_KERNEL::Exception(MSG);
2306       arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
2307       _array=arrays[0]; _array->incrRef();
2308     }
2309   if(tinyInfoI[6]!=-1 && tinyInfoI[7]!=-1)
2310     {
2311       if(!arrays[1])
2312         throw INTERP_KERNEL::Exception(MSG);
2313       arrays[1]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
2314       _end_array=arrays[1]; _end_array->incrRef();
2315     }
2316 }
2317
2318 void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
2319 {
2320   MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS);
2321   _start.setTimeValue(tinyInfoD[1]);
2322   _end.setTimeValue(tinyInfoD[2]);
2323   _start.setIteration(tinyInfoI[2]);
2324   _start.setOrder(tinyInfoI[3]);
2325   _end.setIteration(tinyInfoI[4]);
2326   _end.setOrder(tinyInfoI[5]);
2327 }
2328
2329 /*!
2330  * idem getTinySerializationIntInformation except that it is for multi field fetch
2331  */
2332 void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation2(std::vector<int>& tinyInfo) const
2333 {
2334   tinyInfo.resize(4);
2335   tinyInfo[0]=_start.getIteration();
2336   tinyInfo[1]=_start.getOrder();
2337   tinyInfo[2]=_end.getIteration();
2338   tinyInfo[3]=_end.getOrder();
2339 }
2340
2341 /*!
2342  * idem getTinySerializationDbleInformation except that it is for multi field fetch
2343  */
2344 void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation2(std::vector<double>& tinyInfo) const
2345 {
2346   tinyInfo.resize(3);
2347   tinyInfo[0]=_time_tolerance;
2348   tinyInfo[1]=_start.getTimeValue();
2349   tinyInfo[2]=_end.getTimeValue();
2350 }
2351
2352 /*!
2353  * idem finishUnserialization except that it is for multi field fetch
2354  */
2355 void MEDCouplingTwoTimeSteps::finishUnserialization2(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
2356 {
2357   _start.setIteration(tinyInfoI[0]);
2358   _start.setOrder(tinyInfoI[1]);
2359   _end.setIteration(tinyInfoI[2]);
2360   _end.setOrder(tinyInfoI[3]);
2361   _time_tolerance=tinyInfoD[0];
2362   _start.setTimeValue(tinyInfoD[1]);
2363   _end.setTimeValue(tinyInfoD[2]);
2364 }
2365
2366 std::vector< const DataArrayDouble *> MEDCouplingTwoTimeSteps::getArraysForTime(double time) const
2367 {
2368   if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance)
2369     {
2370       std::vector< const DataArrayDouble *> ret(2);
2371       ret[0]=_array;
2372       ret[1]=_end_array;
2373       return ret;
2374     }
2375   else
2376     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2377 }
2378
2379 void MEDCouplingTwoTimeSteps::setArrays(const std::vector<DataArrayDouble *>& arrays, TimeLabel *owner)
2380 {
2381   if(arrays.size()!=2)
2382     throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::setArrays : number of arrays must be two.");
2383   setArray(arrays.front(),owner);
2384   setEndArray(arrays.back(),owner);
2385 }
2386
2387 MEDCouplingLinearTime::MEDCouplingLinearTime(const MEDCouplingLinearTime& other, bool deepCopy):MEDCouplingTwoTimeSteps(other,deepCopy)
2388 {
2389 }
2390
2391 MEDCouplingLinearTime::MEDCouplingLinearTime()
2392 {
2393 }
2394
2395 std::string MEDCouplingLinearTime::getStringRepr() const
2396 {
2397   std::ostringstream stream;
2398   stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n";
2399   stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n";
2400   stream << "Time unit is : \"" << getTimeUnit() << "\"";
2401   return stream.str();
2402 }
2403
2404 void MEDCouplingLinearTime::checkConsistencyLight() const
2405 {
2406   MEDCouplingTwoTimeSteps::checkConsistencyLight();
2407   if(std::fabs(_start.getTimeValue()-_end.getTimeValue())<_time_tolerance)
2408     throw INTERP_KERNEL::Exception("Start time and end time are equals regarding time tolerance.");
2409 }
2410
2411 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::performCopyOrIncrRef(bool deepCopy) const
2412 {
2413   return new MEDCouplingLinearTime(*this,deepCopy);
2414 }
2415
2416 bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2417 {
2418   if(!MEDCouplingTimeDiscretization::areCompatible(other))
2419     return false;
2420   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2421   if(otherC==0)
2422     return false;
2423   if(_end_array==0 && otherC->_end_array==0)
2424     return true;
2425   if(_end_array==0 || otherC->_end_array==0)
2426     return false;
2427   if(_end_array->getNumberOfComponents()!=otherC->_end_array->getNumberOfComponents())
2428     return false;
2429   return true;
2430 }
2431
2432 bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<double> *other, std::string& reason) const
2433 {
2434   if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason))
2435     return false;
2436   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2437   bool ret=otherC!=0;
2438   if(!ret)
2439     reason.insert(0,"time discretization of this is LINEAR_TIME, other has a different time discretization.");
2440   return ret;
2441 }
2442
2443 bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2444 {
2445   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
2446     return false;
2447   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2448   return otherC!=0;
2449 }
2450
2451 bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<double> *other) const
2452 {
2453   if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
2454     return false;
2455   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2456   if(otherC==0)
2457     return false;
2458   if(_end_array==0 && otherC->_end_array==0)
2459     return true;
2460   if(_end_array==0 || otherC->_end_array==0)
2461     return false;
2462   int nbC1=_end_array->getNumberOfComponents();
2463   int nbC2=otherC->_end_array->getNumberOfComponents();
2464   if(nbC1!=nbC2 && nbC2!=1)
2465     return false;
2466   return true;
2467 }
2468
2469 bool MEDCouplingLinearTime::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
2470 {
2471   if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
2472     return false;
2473   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2474   return otherC!=0;
2475 }
2476
2477 /*!
2478  * vals is expected to be of size 2*_array->getNumberOfTuples()==_array->getNumberOfTuples()+_end_array->getNumberOfTuples()
2479  */
2480 void MEDCouplingLinearTime::getValueForTime(double time, const std::vector<double>& vals, double *res) const
2481 {
2482   double alpha=(_end.getTimeValue()-time)/(_end.getTimeValue()-_start.getTimeValue());
2483   std::size_t nbComp=vals.size()/2;
2484   std::transform(vals.begin(),vals.begin()+nbComp,res,std::bind2nd(std::multiplies<double>(),alpha));
2485   std::vector<double> tmp(nbComp);
2486   std::transform(vals.begin()+nbComp,vals.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2487   std::transform(tmp.begin(),tmp.end(),res,res,std::plus<double>());
2488 }
2489
2490 void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value) const
2491 {
2492   double alpha=(_end.getTimeValue()-time)/(_end.getTimeValue()-_start.getTimeValue());
2493   int nbComp;
2494   if(_array)
2495     _array->getTuple(eltId,value);
2496   else
2497     throw INTERP_KERNEL::Exception("No start array existing.");
2498   nbComp=_array->getNumberOfComponents();
2499   std::transform(value,value+nbComp,value,std::bind2nd(std::multiplies<double>(),alpha));
2500   std::vector<double> tmp(nbComp);
2501   if(_end_array)
2502     _end_array->getTuple(eltId,&tmp[0]);
2503   else
2504     throw INTERP_KERNEL::Exception("No end array existing.");
2505   std::transform(tmp.begin(),tmp.end(),tmp.begin(),std::bind2nd(std::multiplies<double>(),1-alpha));
2506   std::transform(tmp.begin(),tmp.end(),value,value,std::plus<double>());
2507 }
2508
2509 void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const
2510 {
2511   if(iteration==_start.getIteration() && order==_start.getOrder())
2512     {
2513       if(_array)
2514         _array->getTuple(eltId,value);
2515       else
2516         throw INTERP_KERNEL::Exception("iteration order match with start time but no start array existing.");
2517     }
2518   if(iteration==_end.getIteration() && order==_end.getOrder())
2519     {
2520       if(_end_array)
2521         _end_array->getTuple(eltId,value);
2522       else
2523         throw INTERP_KERNEL::Exception("iteration order match with end time but no end array existing.");
2524     }
2525   else
2526     throw INTERP_KERNEL::Exception(EXCEPTION_MSG);
2527 }
2528
2529 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const MEDCouplingTimeDiscretization *other) const
2530 {
2531   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2532   if(!otherC)
2533     throw INTERP_KERNEL::Exception("LinearTime::aggregation on mismatched time discretization !");
2534   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Aggregate(getArray(),other->getArray());
2535   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Aggregate(getEndArray(),other->getEndArray());
2536   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2537   ret->setArray(arr1,0);
2538   ret->setEndArray(arr2,0);
2539   return ret;
2540 }
2541
2542 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const std::vector<const MEDCouplingTimeDiscretization *>& other) const
2543 {
2544   std::vector<const DataArrayDouble *> a(other.size());
2545   std::vector<const DataArrayDouble *> b(other.size());
2546   int i=0;
2547   for(std::vector<const MEDCouplingTimeDiscretization *>::const_iterator it=other.begin();it!=other.end();it++,i++)
2548     {
2549       const MEDCouplingLinearTime *itC=dynamic_cast<const MEDCouplingLinearTime *>(*it);
2550       if(!itC)
2551         throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::aggregate on mismatched time discretization !");
2552       a[i]=itC->getArray();
2553       b[i]=itC->getEndArray();
2554     }
2555   MCAuto<DataArrayDouble> arr(DataArrayDouble::Aggregate(a)),arr2(DataArrayDouble::Aggregate(b));
2556   MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2557   ret->setArray(arr,0);
2558   ret->setEndArray(arr2,0);
2559   return ret;
2560 }
2561
2562 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::meld(const MEDCouplingTimeDiscretization *other) const
2563 {
2564   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2565   if(!otherC)
2566     throw INTERP_KERNEL::Exception("LinearTime::meld on mismatched time discretization !");
2567   MCAuto<DataArrayDouble> arr1(DataArrayDouble::Meld(getArray(),other->getArray())),arr2(DataArrayDouble::Meld(getEndArray(),other->getEndArray()));
2568   MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2569   ret->setTimeTolerance(getTimeTolerance());
2570   ret->setArray(arr1,0);
2571   ret->setEndArray(arr2,0);
2572   return ret;
2573 }
2574
2575 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeDiscretization *other) const
2576 {
2577   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2578   if(!otherC)
2579     throw INTERP_KERNEL::Exception("LinearTime::dot on mismatched time discretization !");
2580   MCAuto<DataArrayDouble> arr1(DataArrayDouble::Dot(getArray(),other->getArray())),arr2(DataArrayDouble::Dot(getEndArray(),other->getEndArray()));
2581   MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2582   ret->setArray(arr1,0);
2583   ret->setEndArray(arr2,0);
2584   return ret;
2585 }
2586
2587 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::crossProduct(const MEDCouplingTimeDiscretization *other) const
2588 {
2589   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2590   if(!otherC)
2591     throw INTERP_KERNEL::Exception("LinearTime::crossProduct on mismatched time discretization !");
2592   MCAuto<DataArrayDouble> arr1(DataArrayDouble::CrossProduct(getArray(),other->getArray())),arr2(DataArrayDouble::CrossProduct(getEndArray(),other->getEndArray()));
2593   MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2594   ret->setArray(arr1,0);
2595   ret->setEndArray(arr2,0);
2596   return ret;
2597 }
2598
2599 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::max(const MEDCouplingTimeDiscretization *other) const
2600 {
2601   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2602   if(!otherC)
2603     throw INTERP_KERNEL::Exception("LinearTime::max on mismatched time discretization !");
2604   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2605   MCAuto<DataArrayDouble> arr1(DataArrayDouble::Max(getArray(),other->getArray())),arr2(DataArrayDouble::Max(getEndArray(),other->getEndArray()));
2606   ret->setArray(arr1,0);
2607   ret->setEndArray(arr2,0);
2608   return ret;
2609 }
2610
2611 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::min(const MEDCouplingTimeDiscretization *other) const
2612 {
2613   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2614   if(!otherC)
2615     throw INTERP_KERNEL::Exception("LinearTime::min on mismatched time discretization !");
2616   MCAuto<DataArrayDouble> arr1(DataArrayDouble::Min(getArray(),other->getArray())),arr2(DataArrayDouble::Min(getEndArray(),other->getEndArray()));
2617   MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2618   ret->setArray(arr1,0);
2619   ret->setEndArray(arr2,0);
2620   return ret;
2621 }
2622
2623 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::add(const MEDCouplingTimeDiscretization *other) const
2624 {
2625   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2626   if(!otherC)
2627     throw INTERP_KERNEL::Exception("LinearTime::add on mismatched time discretization !");
2628   MCAuto<DataArrayDouble> arr1(DataArrayDouble::Add(getArray(),other->getArray())),arr2(DataArrayDouble::Add(getEndArray(),other->getEndArray()));
2629   MEDCouplingLinearTime *ret(new MEDCouplingLinearTime);
2630   ret->setArray(arr1,0);
2631   ret->setEndArray(arr2,0);
2632   return ret;
2633 }
2634
2635 void MEDCouplingLinearTime::addEqual(const MEDCouplingTimeDiscretization *other)
2636 {
2637   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2638   if(!otherC)
2639     throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2640   if(!getArray())
2641     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array is NULL !");
2642   if(!getEndArray())
2643     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::addEqual : Data Array (end) is NULL !");
2644   getArray()->addEqual(other->getArray());
2645   getEndArray()->addEqual(other->getEndArray());
2646 }
2647
2648 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::substract(const MEDCouplingTimeDiscretization *other) const
2649 {
2650   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2651   if(!otherC)
2652     throw INTERP_KERNEL::Exception("LinearTime::substract on mismatched time discretization !");
2653   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Substract(getArray(),other->getArray());
2654   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Substract(getEndArray(),other->getEndArray());
2655   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2656   ret->setArray(arr1,0);
2657   ret->setEndArray(arr2,0);
2658   return ret;
2659 }
2660
2661 void MEDCouplingLinearTime::substractEqual(const MEDCouplingTimeDiscretization *other)
2662 {
2663   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2664   if(!otherC)
2665     throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2666   if(!getArray())
2667     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array is NULL !");
2668   if(!getEndArray())
2669     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::substractEqual : Data Array (end) is NULL !");
2670   getArray()->substractEqual(other->getArray());
2671   getEndArray()->substractEqual(other->getEndArray());
2672 }
2673
2674 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::multiply(const MEDCouplingTimeDiscretization *other) const
2675 {
2676   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2677   if(!otherC)
2678     throw INTERP_KERNEL::Exception("LinearTime::multiply on mismatched time discretization !");
2679   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Multiply(getArray(),other->getArray());
2680   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Multiply(getEndArray(),other->getEndArray());
2681   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2682   ret->setArray(arr1,0);
2683   ret->setEndArray(arr2,0);
2684   return ret;
2685 }
2686
2687 void MEDCouplingLinearTime::multiplyEqual(const MEDCouplingTimeDiscretization *other)
2688 {
2689   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2690   if(!otherC)
2691     throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2692   if(!getArray())
2693     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array is NULL !");
2694   if(!getEndArray())
2695     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::multiplyEqual : Data Array (end) is NULL !");
2696   getArray()->multiplyEqual(other->getArray());
2697   getEndArray()->multiplyEqual(other->getEndArray());
2698 }
2699
2700 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::divide(const MEDCouplingTimeDiscretization *other) const
2701 {
2702   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2703   if(!otherC)
2704     throw INTERP_KERNEL::Exception("LinearTime::divide on mismatched time discretization !");
2705   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Divide(getArray(),other->getArray());
2706   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Divide(getEndArray(),other->getEndArray());
2707   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2708   ret->setArray(arr1,0);
2709   ret->setEndArray(arr2,0);
2710   return ret;
2711 }
2712
2713 void MEDCouplingLinearTime::divideEqual(const MEDCouplingTimeDiscretization *other)
2714 {
2715   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2716   if(!otherC)
2717     throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2718   if(!getArray())
2719     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array is NULL !");
2720   if(!getEndArray())
2721     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::divideEqual : Data Array (end) is NULL !");
2722   getArray()->divideEqual(other->getArray());
2723   getEndArray()->divideEqual(other->getEndArray());
2724 }
2725
2726 MEDCouplingTimeDiscretization *MEDCouplingLinearTime::pow(const MEDCouplingTimeDiscretization *other) const
2727 {
2728   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2729   if(!otherC)
2730     throw INTERP_KERNEL::Exception("LinearTime::pow on mismatched time discretization !");
2731   MCAuto<DataArrayDouble> arr1=DataArrayDouble::Pow(getArray(),other->getArray());
2732   MCAuto<DataArrayDouble> arr2=DataArrayDouble::Pow(getEndArray(),other->getEndArray());
2733   MEDCouplingLinearTime *ret=new MEDCouplingLinearTime;
2734   ret->setArray(arr1,0);
2735   ret->setEndArray(arr2,0);
2736   return ret;
2737 }
2738
2739 void MEDCouplingLinearTime::powEqual(const MEDCouplingTimeDiscretization *other)
2740 {
2741   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
2742   if(!otherC)
2743     throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !");
2744   if(!getArray())
2745     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array is NULL !");
2746   if(!getEndArray())
2747     throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array (end) is NULL !");
2748   getArray()->powEqual(other->getArray());
2749   getEndArray()->powEqual(other->getEndArray());
2750 }