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