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