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