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