Salome HOME
Merge from V6_main (04/10/2012)
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingDefinitionTime.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingDefinitionTime.hxx"
22 #include "MEDCouplingFieldDouble.hxx"
23
24 #include <cmath>
25
26 using namespace ParaMEDMEM;
27
28 const double MEDCouplingDefinitionTime::EPS_DFT=1e-15;
29
30 MEDCouplingDefinitionTimeSlice *MEDCouplingDefinitionTimeSlice::New(const MEDCouplingFieldDouble *f, int meshId, const std::vector<int>& arrId, int fieldId) throw(INTERP_KERNEL::Exception)
31 {
32   static const char msg[]="TimeSlice::New : mismatch of arrays number of a fieldDouble and its policy !!! Internal error !!!";
33   if(!f)
34     throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTimeSlice::New : empty field !");
35   switch(f->getTimeDiscretization())
36     {
37     case ONE_TIME:
38       {
39         if(arrId.size()!=1)
40           throw INTERP_KERNEL::Exception(msg);
41         return new MEDCouplingDefinitionTimeSliceInst(f,meshId,arrId[0],fieldId);
42       }
43     case CONST_ON_TIME_INTERVAL:
44       {
45         if(arrId.size()!=1)
46           throw INTERP_KERNEL::Exception(msg);
47         return new MEDCouplingDefinitionTimeSliceCstOnTI(f,meshId,arrId[0],fieldId);
48       }
49     case LINEAR_TIME:
50       {
51         if(arrId.size()!=2)
52           throw INTERP_KERNEL::Exception(msg);
53         return new MEDCouplingDefinitionTimeSliceLT(f,meshId,arrId[0],arrId[1],fieldId);
54       }
55     case NO_TIME:
56       throw INTERP_KERNEL::Exception("Invalide time discretization ! NO_TIME ! Impossible to build a definition time slice !");
57     default:
58       throw INTERP_KERNEL::Exception("Invalide time discretization : Not recognized !");
59     }
60 }
61
62 MEDCouplingDefinitionTimeSlice *MEDCouplingDefinitionTimeSlice::New(TypeOfTimeDiscretization type, const std::vector<int>& tiI, const std::vector<double>& tiD) throw(INTERP_KERNEL::Exception)
63 {
64   switch(type)
65     {
66     case ONE_TIME:
67       return MEDCouplingDefinitionTimeSliceInst::New(tiI,tiD);
68     case CONST_ON_TIME_INTERVAL:
69       return MEDCouplingDefinitionTimeSliceCstOnTI::New(tiI,tiD);
70     case LINEAR_TIME:
71       return MEDCouplingDefinitionTimeSliceLT::New(tiI,tiD);
72     default:
73       throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTimeSlice::New : unrecognized time discretization type !");
74     }
75 }
76
77 bool MEDCouplingDefinitionTimeSlice::isEqual(const MEDCouplingDefinitionTimeSlice& other, double eps) const
78 {
79   if(_mesh_id!=other._mesh_id)
80     return false;
81   if(_array_id!=other._array_id)
82     return false;
83   if(_field_id!=other._field_id)
84     return false;
85   return true;
86 }
87
88 int MEDCouplingDefinitionTimeSlice::getStartId() const
89 {
90   return _array_id;
91 }
92
93 int MEDCouplingDefinitionTimeSlice::getEndId() const
94 {
95   return _array_id;
96 }
97
98 void MEDCouplingDefinitionTimeSlice::appendRepr(std::ostream& stream) const
99 {
100   stream << " *** MeshId : " << _mesh_id << " ArrayId : " << _array_id;
101 }
102
103 MEDCouplingDefinitionTimeSlice::MEDCouplingDefinitionTimeSlice(const MEDCouplingFieldDouble *f, int meshId, int arrId, int fieldId) throw(INTERP_KERNEL::Exception):_mesh_id(meshId),_array_id(arrId),_field_id(fieldId)
104 {
105   int tmp1,tmp2;
106   double t1=f->getStartTime(tmp1,tmp2);
107   double t2=f->getEndTime(tmp1,tmp2);
108   if(t2<t1)
109     throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTimeSlice : End time strictly before Start time ...");
110 }
111
112 bool MEDCouplingDefinitionTimeSlice::isFullyIncludedInMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const
113 {
114   double t1=getStartTime();
115   double t2=getEndTime();
116   double o1=other->getStartTime();
117   double o2=other->getEndTime();
118   return o1>t1-eps && o2<t2+eps;
119 }
120
121 bool MEDCouplingDefinitionTimeSlice::isOverllapingWithMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const
122 {
123   double t1=getStartTime();
124   double t2=getEndTime();
125   double o1=other->getStartTime();
126   double o2=other->getEndTime();
127   return (o1<t1+eps && o2<t1+eps) || (o1>t2-eps && o2>t2-eps);
128 }
129
130 bool MEDCouplingDefinitionTimeSlice::isAfterMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const
131 {
132   double t2=getEndTime();
133   double o1=other->getStartTime();
134   double o2=other->getEndTime();
135   return (o1>t2-eps && o2>t2-eps);
136 }
137
138 bool MEDCouplingDefinitionTimeSlice::isBeforeMe(const MEDCouplingDefinitionTimeSlice *other, double eps) const
139 {
140   double t1=getStartTime();
141   double o1=other->getStartTime();
142   double o2=other->getEndTime();
143   return (o1<t1+eps && o2<t1+eps);
144 }
145
146 MEDCouplingDefinitionTimeSliceInst *MEDCouplingDefinitionTimeSliceInst::New(const std::vector<int>& tiI, const std::vector<double>& tiD)
147 {
148   MEDCouplingDefinitionTimeSliceInst *ret=new MEDCouplingDefinitionTimeSliceInst;
149   ret->unserialize(tiI,tiD);
150   return ret;
151 }
152
153 void MEDCouplingDefinitionTimeSliceInst::getTinySerializationInformation(std::vector<int>& tiI, std::vector<double>& tiD) const
154 {
155   tiI.resize(3);
156   tiI[0]=_mesh_id; tiI[1]=_array_id; tiI[2]=_field_id;
157   tiD.resize(1);
158   tiD[0]=_instant;
159 }
160
161 void MEDCouplingDefinitionTimeSliceInst::unserialize(const std::vector<int>& tiI, const std::vector<double>& tiD)
162 {
163   _mesh_id=tiI[0]; _array_id=tiI[1]; _field_id=tiI[2];
164   _instant=tiD[0];
165 }
166
167 TypeOfTimeDiscretization MEDCouplingDefinitionTimeSliceInst::getTimeType() const
168 {
169   return ONE_TIME;
170 }
171
172 MEDCouplingDefinitionTimeSlice *MEDCouplingDefinitionTimeSliceInst::copy() const
173 {
174   return new MEDCouplingDefinitionTimeSliceInst(*this);
175 }
176
177 bool MEDCouplingDefinitionTimeSliceInst::isEqual(const MEDCouplingDefinitionTimeSlice& other, double eps) const
178 {
179   if(!MEDCouplingDefinitionTimeSlice::isEqual(other,eps))
180     return false;
181   const MEDCouplingDefinitionTimeSliceInst *otherC=dynamic_cast<const MEDCouplingDefinitionTimeSliceInst *>(&other);
182   if(!otherC)
183     return false;
184   return fabs(otherC->_instant-_instant)<eps;
185 }
186
187 void MEDCouplingDefinitionTimeSliceInst::getHotSpotsTime(std::vector<double>& ret) const
188 {
189   ret.resize(1);
190   ret[0]=_instant;
191 }
192
193 void MEDCouplingDefinitionTimeSliceInst::getIdsOnTime(double tm, double eps, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception)
194 {
195   meshId=_mesh_id;
196   arrId=_array_id;
197   arrIdInField=0;
198   fieldId=_field_id;
199 }
200
201 bool MEDCouplingDefinitionTimeSliceInst::isContaining(double tmp, double eps) const
202 {
203   return fabs(tmp-_instant)<eps;
204 }
205
206 void MEDCouplingDefinitionTimeSliceInst::appendRepr(std::ostream& stream) const
207 {
208   stream << "single point " << _instant;
209   MEDCouplingDefinitionTimeSlice::appendRepr(stream);
210 }
211
212 double MEDCouplingDefinitionTimeSliceInst::getStartTime() const
213 {
214   return _instant;
215 }
216
217 double MEDCouplingDefinitionTimeSliceInst::getEndTime() const
218 {
219   return _instant;
220 }
221
222 MEDCouplingDefinitionTimeSliceInst::MEDCouplingDefinitionTimeSliceInst(const MEDCouplingFieldDouble *f, int meshId, int arrId, int fieldId) throw(INTERP_KERNEL::Exception):MEDCouplingDefinitionTimeSlice(f,meshId,arrId,fieldId)
223 {
224   int tmp1,tmp2;
225   double t1=f->getStartTime(tmp1,tmp2);
226   double t2=f->getEndTime(tmp1,tmp2);
227   double eps=f->getTimeTolerance();
228   if(fabs(t1-t2)>eps)
229     throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTimeSliceInst : times differs in this");
230   _instant=t1;
231 }
232
233 MEDCouplingDefinitionTimeSliceCstOnTI *MEDCouplingDefinitionTimeSliceCstOnTI::New(const std::vector<int>& tiI, const std::vector<double>& tiD)
234 {
235   MEDCouplingDefinitionTimeSliceCstOnTI *ret=new MEDCouplingDefinitionTimeSliceCstOnTI;
236   ret->unserialize(tiI,tiD);
237   return ret;
238 }
239
240 MEDCouplingDefinitionTimeSlice *MEDCouplingDefinitionTimeSliceCstOnTI::copy() const
241 {
242   return new MEDCouplingDefinitionTimeSliceCstOnTI(*this);
243 }
244
245 bool MEDCouplingDefinitionTimeSliceCstOnTI::isEqual(const MEDCouplingDefinitionTimeSlice& other, double eps) const
246 {
247   if(!MEDCouplingDefinitionTimeSlice::isEqual(other,eps))
248     return false;
249   const MEDCouplingDefinitionTimeSliceCstOnTI *otherC=dynamic_cast<const MEDCouplingDefinitionTimeSliceCstOnTI *>(&other);
250   if(!otherC)
251     return false;
252   if(fabs(otherC->_start-_start)>eps)
253     return false;
254   return fabs(otherC->_end-_end)<eps;
255 }
256
257 void MEDCouplingDefinitionTimeSliceCstOnTI::getHotSpotsTime(std::vector<double>& ret) const
258 {
259   ret.resize(1);
260   ret[0]=(_start+_end)/2.;
261 }
262
263 void MEDCouplingDefinitionTimeSliceCstOnTI::getIdsOnTime(double tm, double eps, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception)
264 {
265   meshId=_mesh_id;
266   arrId=_array_id;
267   arrIdInField=0;
268   fieldId=_field_id;
269 }
270
271 bool MEDCouplingDefinitionTimeSliceCstOnTI::isContaining(double tmp, double eps) const
272 {
273   return _start-eps<tmp && _end+eps>tmp;
274 }
275
276 void MEDCouplingDefinitionTimeSliceCstOnTI::appendRepr(std::ostream& stream) const
277 {
278   stream << "Constant on time interval [" << _start << "," << _end << "]";
279   MEDCouplingDefinitionTimeSlice::appendRepr(stream);
280 }
281
282 double MEDCouplingDefinitionTimeSliceCstOnTI::getStartTime() const
283 {
284   return _start;
285 }
286
287 double MEDCouplingDefinitionTimeSliceCstOnTI::getEndTime() const
288 {
289   return _end;
290 }
291
292 void MEDCouplingDefinitionTimeSliceCstOnTI::getTinySerializationInformation(std::vector<int>& tiI, std::vector<double>& tiD) const
293 {
294   tiI.resize(3);
295   tiI[0]=_mesh_id; tiI[1]=_array_id; tiI[2]=_field_id;
296   tiD.resize(2);
297   tiD[0]=_start; tiD[1]=_end;
298 }
299
300 void MEDCouplingDefinitionTimeSliceCstOnTI::unserialize(const std::vector<int>& tiI, const std::vector<double>& tiD)
301 {
302   _mesh_id=tiI[0]; _array_id=tiI[1]; _field_id=tiI[2];
303   _start=tiD[0]; _end=tiD[1];
304 }
305
306 TypeOfTimeDiscretization MEDCouplingDefinitionTimeSliceCstOnTI::getTimeType() const
307 {
308   return CONST_ON_TIME_INTERVAL;
309 }
310
311 MEDCouplingDefinitionTimeSliceCstOnTI::MEDCouplingDefinitionTimeSliceCstOnTI(const MEDCouplingFieldDouble *f, int meshId, int arrId, int fieldId) throw(INTERP_KERNEL::Exception):MEDCouplingDefinitionTimeSlice(f,meshId,arrId,fieldId)
312 {
313   int tmp1,tmp2;
314   double t1=f->getStartTime(tmp1,tmp2);
315   double t2=f->getEndTime(tmp1,tmp2);
316   _start=t1;
317   _end=t2;
318 }
319
320 MEDCouplingDefinitionTimeSliceLT *MEDCouplingDefinitionTimeSliceLT::New(const std::vector<int>& tiI, const std::vector<double>& tiD)
321 {
322   MEDCouplingDefinitionTimeSliceLT *ret=new MEDCouplingDefinitionTimeSliceLT;
323   ret->unserialize(tiI,tiD);
324   return ret;
325 }
326
327 MEDCouplingDefinitionTimeSlice *MEDCouplingDefinitionTimeSliceLT::copy() const
328 {
329   return new MEDCouplingDefinitionTimeSliceLT(*this);
330 }
331
332 bool MEDCouplingDefinitionTimeSliceLT::isEqual(const MEDCouplingDefinitionTimeSlice& other, double eps) const
333 {
334   if(!MEDCouplingDefinitionTimeSlice::isEqual(other,eps))
335     return false;
336   const MEDCouplingDefinitionTimeSliceLT *otherC=dynamic_cast<const MEDCouplingDefinitionTimeSliceLT *>(&other);
337   if(!otherC)
338     return false;
339   if(_array_id_end!=otherC->_array_id_end)
340     return false;
341   if(fabs(otherC->_start-_start)>eps)
342     return false;
343   return fabs(otherC->_end-_end)<eps;
344 }
345
346 void MEDCouplingDefinitionTimeSliceLT::getHotSpotsTime(std::vector<double>& ret) const
347 {
348   ret.resize(2);
349   ret[0]=_start;
350   ret[1]=_end;
351 }
352
353 void MEDCouplingDefinitionTimeSliceLT::getIdsOnTime(double tm, double eps, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception)
354 {
355   if(fabs(tm-_start)<eps)
356     {
357       meshId=_mesh_id;
358       arrId=_array_id;
359       arrIdInField=0;
360       fieldId=_field_id;
361       return ;
362     }
363   if(fabs(tm-_end)<eps)
364     {
365       meshId=_mesh_id;
366       arrId=_array_id_end;
367       arrIdInField=1;
368       fieldId=_field_id;
369       return ;
370     }
371   throw INTERP_KERNEL::Exception("LinearTime request not in boundary of this ! use hot spots !");
372 }
373
374 bool MEDCouplingDefinitionTimeSliceLT::isContaining(double tmp, double eps) const
375 {
376   return _start-eps<tmp && _end+eps>tmp;
377 }
378
379 void MEDCouplingDefinitionTimeSliceLT::appendRepr(std::ostream& stream) const
380 {
381   stream << "Linear on time interval [" << _start << "," << _end << "]";
382   MEDCouplingDefinitionTimeSlice::appendRepr(stream);
383   stream << " EndArrayId : " << _array_id_end;
384 }
385
386 double MEDCouplingDefinitionTimeSliceLT::getStartTime() const
387 {
388   return _start;
389 }
390
391 double MEDCouplingDefinitionTimeSliceLT::getEndTime() const
392 {
393   return _end;
394 }
395
396 int MEDCouplingDefinitionTimeSliceLT::getEndId() const
397 {
398   return _array_id_end;
399 }
400
401 void MEDCouplingDefinitionTimeSliceLT::getTinySerializationInformation(std::vector<int>& tiI, std::vector<double>& tiD) const
402 {
403   tiI.resize(4);
404   tiI[0]=_mesh_id; tiI[1]=_array_id; tiI[2]=_field_id; tiI[3]=_array_id_end;
405   tiD.resize(2);
406   tiD[0]=_start; tiD[1]=_end;
407 }
408
409 void MEDCouplingDefinitionTimeSliceLT::unserialize(const std::vector<int>& tiI, const std::vector<double>& tiD)
410 {
411   _mesh_id=tiI[0]; _array_id=tiI[1]; _field_id=tiI[2]; _array_id_end=tiI[3];
412   _start=tiD[0]; _end=tiD[1];
413 }
414
415 TypeOfTimeDiscretization MEDCouplingDefinitionTimeSliceLT::getTimeType() const
416 {
417   return LINEAR_TIME;
418 }
419
420 MEDCouplingDefinitionTimeSliceLT::MEDCouplingDefinitionTimeSliceLT(const MEDCouplingFieldDouble *f, int meshId, int arrId, int arr2Id, int fieldId) throw(INTERP_KERNEL::Exception):MEDCouplingDefinitionTimeSlice(f,meshId,arrId,fieldId),_array_id_end(arr2Id)
421 {
422   int tmp1,tmp2;
423   double t1=f->getStartTime(tmp1,tmp2);
424   double t2=f->getEndTime(tmp1,tmp2);
425   _start=t1;
426   _end=t2;
427 }
428
429 MEDCouplingDefinitionTime::MEDCouplingDefinitionTime():_eps(EPS_DFT)
430 {
431 }
432
433 MEDCouplingDefinitionTime::MEDCouplingDefinitionTime(const std::vector<const MEDCouplingFieldDouble *>& fs, const std::vector<int>& meshRefs, const std::vector<std::vector<int> >& arrRefs) throw(INTERP_KERNEL::Exception)
434 {
435   std::size_t sz=fs.size();
436   if(sz!=arrRefs.size())
437     throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime constructor : internal error ! should never happen !");
438   _slices.resize(sz);
439   for(std::size_t i=0;i<sz;i++)
440     {
441       if(arrRefs.empty())
442         throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime constructor : A field is null in list impossible to build a time definition !");
443       _slices[i]=MEDCouplingDefinitionTimeSlice::New(fs[i],meshRefs[i],arrRefs[i],(int)i);
444     }
445   if(sz<=1)
446     return ;
447   const MEDCouplingDefinitionTimeSlice *ref=_slices[0];
448   _eps=fs[0]->getTimeTolerance();
449   for(std::size_t i=1;i<sz;i++)
450     {
451       if(!ref->isAfterMe(_slices[i],_eps))
452         throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime constructors : the sequences of fields does NOT defines a stricly ascendant monotonic time sequence !");
453       // double t1=ref->getEndTime();
454       // double t2=_slices[i]->getStartTime();
455       // if(fabs(t1-t2)<_eps)
456       //   if(ref->getEndId() != _slices[i]->getStartId())
457       //     throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime constructor : 2 slices refers to the same time and underlying arrays differs !");
458       ref=_slices[i];
459     }
460 }
461
462 void MEDCouplingDefinitionTime::assign(const MEDCouplingDefinitionTime& other)
463 {
464   std::size_t sz=other._slices.size();
465   _slices.resize(sz);
466   for(std::size_t i=0;i<sz;i++)
467     _slices[i]=other._slices[i]->copy();
468 }
469
470 bool MEDCouplingDefinitionTime::isEqual(const MEDCouplingDefinitionTime& other) const
471 {
472   std::size_t sz=_slices.size();
473   if(sz!=other._slices.size())
474     return false;
475   for(std::size_t i=0;i<sz;i++)
476     if(!_slices[i]->isEqual(*other._slices[i],_eps))
477       return false;
478   return true;
479 }
480
481 void MEDCouplingDefinitionTime::getIdsOnTimeRight(double tm, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception)
482 {
483   std::vector<int> meshIds;
484   std::vector<int> arrIds;
485   std::vector<int> arrIdsInField;
486   std::vector<int> fieldIds;
487   getIdsOnTime(tm,meshIds,arrIds,arrIdsInField,fieldIds);
488   meshId=meshIds.back();
489   arrId=arrIds.back();
490   arrIdInField=arrIdsInField.back();
491   fieldId=fieldIds.back();
492 }
493
494 void MEDCouplingDefinitionTime::getIdsOnTimeLeft(double tm, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception)
495 {
496   std::vector<int> meshIds;
497   std::vector<int> arrIds;
498   std::vector<int> arrIdsInField;
499   std::vector<int> fieldIds;
500   getIdsOnTime(tm,meshIds,arrIds,arrIdsInField,fieldIds);
501   meshId=meshIds.front();
502   arrId=arrIds.front();
503   arrIdInField=arrIdsInField.front();
504   fieldId=fieldIds.front();
505 }
506
507 void MEDCouplingDefinitionTime::getIdsOnTime(double tm, std::vector<int>& meshIds, std::vector<int>& arrIds, std::vector<int>& arrIdsInField, std::vector<int>& fieldIds) const throw(INTERP_KERNEL::Exception)
508 {
509   std::vector<int> ids;
510   int id=0;
511   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingDefinitionTimeSlice> >::const_iterator it=_slices.begin();it!=_slices.end();it++,id++)
512     if((*it)->isContaining(tm,_eps))
513       ids.push_back(id);
514   if(ids.empty())
515     throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime::getIdsOnTime : No matching slice for such time !");
516   std::size_t sz=ids.size();
517   if(sz>2)
518     throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime::getIdsOnTime : Too many slices match this time !");
519   //
520   meshIds.resize(sz);
521   arrIds.resize(sz);
522   arrIdsInField.resize(sz);
523   fieldIds.resize(sz);
524   for(std::size_t i=0;i<sz;i++)
525     _slices[ids[i]]->getIdsOnTime(tm,_eps,meshIds[i],arrIds[i],arrIdsInField[i],fieldIds[i]);
526 }
527
528 std::vector<double> MEDCouplingDefinitionTime::getHotSpotsTime() const
529 {
530   std::vector<double> ret;
531   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingDefinitionTimeSlice> >::const_iterator it=_slices.begin();it!=_slices.end();it++)
532     {
533       std::vector<double> tmp;
534       (*it)->getHotSpotsTime(tmp);
535       if(!ret.empty())
536         {
537           if(fabs(ret.back()-tmp.front())>_eps)
538             ret.insert(ret.end(),tmp.begin(),tmp.end());
539           else
540             ret.insert(ret.end(),tmp.begin()+1,tmp.end());
541         }
542       else
543         ret.insert(ret.end(),tmp.begin(),tmp.end());
544     }
545   return ret;
546 }
547
548 void MEDCouplingDefinitionTime::appendRepr(std::ostream& stream) const
549 {
550   stream << "Time definition :\n";
551   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingDefinitionTimeSlice> >::const_iterator it=_slices.begin();it!=_slices.end();it++)
552     {
553       stream << " - ";
554       (*it)->appendRepr(stream);
555       stream << std::endl;
556     }
557 }
558
559 void MEDCouplingDefinitionTime::getTinySerializationInformation(std::vector<int>& tinyInfoI, std::vector<double>& tinyInfoD) const
560 {
561   int sz=(int)_slices.size();
562   tinyInfoD.resize(1);
563   tinyInfoD[0]=_eps;
564   tinyInfoI.resize(3*sz+2);
565   tinyInfoI[0]=sz;
566   std::vector<int> coreData;
567   for(int i=0;i<sz;i++)
568     {
569       std::vector<int> tmp1;
570       std::vector<double> tmp2;
571       tinyInfoI[i+2]=(int)_slices[i]->getTimeType();
572       _slices[i]->getTinySerializationInformation(tmp1,tmp2);
573       tinyInfoI[i+sz+2]=(int)tmp1.size();
574       tinyInfoI[i+2*sz+2]=(int)tmp2.size();
575       coreData.insert(coreData.end(),tmp1.begin(),tmp1.end());
576       tinyInfoD.insert(tinyInfoD.end(),tmp2.begin(),tmp2.end());
577     }
578   tinyInfoI[1]=(int)coreData.size();
579   tinyInfoI.insert(tinyInfoI.end(),coreData.begin(),coreData.end());
580 }
581
582 void MEDCouplingDefinitionTime::unserialize(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD)
583 {
584   int sz=tinyInfoI[0];
585   _slices.resize(sz);
586   _eps=tinyInfoD[0];
587   int offset1=0;
588   int offset2=1;
589   for(int i=0;i<sz;i++)
590     {
591       TypeOfTimeDiscretization ty=(TypeOfTimeDiscretization) tinyInfoI[i+2];  
592       int sz1=tinyInfoI[i+sz+2];
593       int sz2=tinyInfoI[i+2*sz+2];
594       std::vector<int> tmp1(tinyInfoI.begin()+3*sz+2+offset1,tinyInfoI.begin()+3*sz+2+offset1+sz1);
595       std::vector<double> tmp2(tinyInfoD.begin()+offset2,tinyInfoD.begin()+offset2+sz2);
596       MEDCouplingDefinitionTimeSlice *pt=MEDCouplingDefinitionTimeSlice::New(ty,tmp1,tmp2);
597       _slices[i]=pt;
598       offset1+=sz1;
599       offset2+=sz2;
600     }
601 }
602