]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDCoupling/MEDCouplingTimeDiscretization.txx
Salome HOME
c60dfc79a0e82b5ad17f1180d1294463fa09da2b
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingTimeDiscretization.txx
1 // Copyright (C) 2007-2016  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 (EDF R&D)
20
21 #ifndef __MEDCOUPLINGTIMEDISCRETIZATION_TXX__
22 #define __MEDCOUPLINGTIMEDISCRETIZATION_TXX__
23
24 #include "MEDCouplingTimeDiscretization.hxx"
25
26 #include <cmath>
27 #include <sstream>
28
29 namespace MEDCoupling
30 {
31   template<class T>
32   const char MEDCouplingTimeDiscretizationSimple<T>::REPR[]="One time label.";
33
34   template<class T>
35   const double MEDCouplingTimeDiscretizationTemplate<T>::TIME_TOLERANCE_DFT=1.e-12;
36   
37   template<class T>
38   void MEDCouplingTimeDiscretizationTemplate<T>::updateTime() const
39   {
40     if(_array)
41       updateTimeWith(*_array);
42   }
43   
44   template<class T>
45   void MEDCouplingTimeDiscretizationTemplate<T>::setArray(typename Traits<T>::ArrayType *array, TimeLabel *owner)
46   {
47     if(array!=_array)
48       {
49         if(_array)
50         _array->decrRef();
51         _array=array;
52         if(_array)
53           _array->incrRef();
54         if(owner)
55           owner->declareAsNew();
56       }
57   }
58   
59   template<class T>
60   void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
61   {
62     _time_tolerance=other._time_tolerance;
63     _time_unit=other._time_unit;
64   }
65   
66   template<class T>
67   void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
68   {
69     _time_unit=other._time_unit;
70     if(_array && other._array)
71       _array->copyStringInfoFrom(*other._array);
72   }
73
74   template<class T>
75   std::size_t MEDCouplingTimeDiscretizationTemplate<T>::getHeapMemorySizeWithoutChildren() const
76   {
77     return _time_unit.capacity();
78   }
79   
80   template<class T>
81   void MEDCouplingTimeDiscretizationTemplate<T>::checkConsistencyLight() const
82   {
83     if(!_array)
84       throw INTERP_KERNEL::Exception("Field invalid because no values set !");
85     if(_time_tolerance<0.)
86       throw INTERP_KERNEL::Exception("time tolerance is expected to be greater than 0. !");
87   }
88   
89   template<class T>
90   std::vector<const BigMemoryObject *> MEDCouplingTimeDiscretizationTemplate<T>::getDirectChildrenWithNull() const
91   {
92     std::vector<const BigMemoryObject *> ret;
93     ret.push_back(_array);
94     return ret;
95   }
96   
97   template<class T>
98   bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<T> *other, std::string& reason) const
99   {
100     std::ostringstream oss; oss.precision(15);
101     if(_time_unit!=other->_time_unit)
102       {
103         oss << "Field discretizations differ : this time unit = \"" << _time_unit << "\" and other time unit = \"" << other->_time_unit << "\" !";
104         reason=oss.str();
105         return false;
106       }
107     if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
108       {
109         oss << "Field discretizations differ : this time tolerance = \"" << _time_tolerance << "\" and other time tolerance = \"" << other->_time_tolerance << "\" !";
110         reason=oss.str();
111         return false;
112       }
113     if(_array==0 && other->_array==0)
114       return true;
115     if(_array==0 || other->_array==0)
116       {
117         reason="Field discretizations differ : Only one timediscretization between the two this and other has a DataArrayDouble for values defined";
118         return false;
119       }
120     if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
121       return false;
122     if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
123       return false;
124     return true;
125   }
126   
127   template<class T>
128   bool MEDCouplingTimeDiscretizationTemplate<T>::areCompatible(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
129   {
130     if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
131       return false;
132     if(_array==0 && other->_array==0)
133       return true;
134     if(_array==0 || other->_array==0)
135       return false;
136     if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
137       return false;
138     return true;
139   }
140   
141   template<class T>
142   bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
143   {
144     if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
145       return false;
146     if(_array==0 && other->_array==0)
147       return true;
148     if(_array==0 || other->_array==0)
149       return false;
150     int nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
151     int nbMin(std::min(nbC1,nbC2));
152     if(nbC1!=nbC2 && nbMin!=1)
153       return false;
154     return true;
155   }
156   
157   template<class T>
158   bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
159   {
160     if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
161       return false;
162     if(_array==0 && other->_array==0)
163       return true;
164     if(_array==0 || other->_array==0)
165       return false;
166     int nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
167     if(nbC1!=nbC2 && nbC2!=1)
168       return false;
169     return true;
170   }
171
172   template<class T>
173   MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate():_time_tolerance(TIME_TOLERANCE_DFT),_array(0)
174   {
175   }
176
177   template<class T>
178   MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate<T>& other, bool deepCopy):_time_unit(other._time_unit),_time_tolerance(other._time_tolerance)
179   {
180     if(other._array)
181       _array=other._array->performCopyOrIncrRef(deepCopy);
182     else
183       _array=0;
184   }
185   
186   template<class T>
187   MEDCouplingTimeDiscretizationTemplate<T>::~MEDCouplingTimeDiscretizationTemplate()
188   {
189     if(_array)
190       _array->decrRef();
191   }
192   
193   template<class T>
194   void MEDCouplingTimeDiscretizationTemplate<T>::setEndArray(typename Traits<T>::ArrayType *array, TimeLabel *owner)
195   {
196     throw INTERP_KERNEL::Exception("setEndArray not available for this type of time discretization !");
197   }
198   
199   template<class T>
200   void MEDCouplingTimeDiscretizationTemplate<T>::setArrays(const std::vector<typename Traits<T>::ArrayType *>& arrays, TimeLabel *owner)
201   {
202     if(arrays.size()!=1)
203       throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretization::setArrays : number of arrays must be one.");
204     setArray(arrays.back(),owner);
205   }
206   
207   template<class T>
208   const typename Traits<T>::ArrayType *MEDCouplingTimeDiscretizationTemplate<T>::getEndArray() const
209   {
210     throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
211   }
212   
213   template<class T>
214   typename Traits<T>::ArrayType *MEDCouplingTimeDiscretizationTemplate<T>::getEndArray()
215   {
216     throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
217   }
218   
219   template<class T>
220   void MEDCouplingTimeDiscretizationTemplate<T>::getArrays(std::vector<typename Traits<T>::ArrayType *>& arrays) const
221   {
222     arrays.resize(1);
223     arrays[0]=_array;
224   }
225   
226   template<class T>
227   std::string MEDCouplingTimeDiscretizationSimple<T>::getStringRepr() const
228   {
229     std::ostringstream stream;
230     stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
231     stream << "\nTime unit is : \"" << this->_time_unit << "\"";
232     return stream.str();
233   }
234   
235   template<class T>
236   double MEDCouplingTimeDiscretizationSimple<T>::getEndTime(int& iteration, int& order) const
237   {
238     throw INTERP_KERNEL::Exception("getEndTime : invalid for this type of time discr !");
239   }
240   
241   template<class T>
242   void MEDCouplingTimeDiscretizationSimple<T>::setEndIteration(int it)
243   {
244     throw INTERP_KERNEL::Exception("setEndIteration : invalid for this type of time discr !");
245   }
246   
247   template<class T>
248   void MEDCouplingTimeDiscretizationSimple<T>::setEndOrder(int order)
249   {
250     throw INTERP_KERNEL::Exception("setEndOrder : invalid for this type of time discr !");
251   }
252   
253   template<class T>
254   void MEDCouplingTimeDiscretizationSimple<T>::setEndTimeValue(double time)
255   {
256     throw INTERP_KERNEL::Exception("setEndTimeValue : invalid for this type of time discr !");
257   }
258   
259   template<class T>
260   void MEDCouplingTimeDiscretizationSimple<T>::setEndTime(double time, int iteration, int order)
261   {
262     throw INTERP_KERNEL::Exception("setEndTime : invalid for this type of time discr !");
263   }
264
265   template<class T>
266   MEDCouplingTimeDiscretizationSimple<T>::MEDCouplingTimeDiscretizationSimple(const MEDCouplingTimeDiscretizationSimple<T>& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate<T>(other,deepCopy),_tk(other._tk)
267   {
268   }
269 }
270
271 #endif