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