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