1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #ifndef __MEDCOUPLINGTIMEDISCRETIZATION_TXX__
22 #define __MEDCOUPLINGTIMEDISCRETIZATION_TXX__
24 #include "MEDCouplingTimeDiscretization.hxx"
32 const char MEDCouplingTimeDiscretizationSimple<T>::REPR[]="One time label.";
35 const double MEDCouplingTimeDiscretizationTemplate<T>::TIME_TOLERANCE_DFT=1.e-12;
38 void MEDCouplingTimeDiscretizationTemplate<T>::updateTime() const
41 updateTimeWith(*_array);
45 void MEDCouplingTimeDiscretizationTemplate<T>::setArray(typename Traits<T>::ArrayType *array, TimeLabel *owner)
55 owner->declareAsNew();
60 void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
62 _time_tolerance=other._time_tolerance;
63 _time_unit=other._time_unit;
67 void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
69 _time_unit=other._time_unit;
70 if(_array && other._array)
71 _array->copyStringInfoFrom(*other._array);
75 std::size_t MEDCouplingTimeDiscretizationTemplate<T>::getHeapMemorySizeWithoutChildren() const
77 return _time_unit.capacity();
81 void MEDCouplingTimeDiscretizationTemplate<T>::checkConsistencyLight() const
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. !");
90 std::vector<const BigMemoryObject *> MEDCouplingTimeDiscretizationTemplate<T>::getDirectChildrenWithNull() const
92 std::vector<const BigMemoryObject *> ret;
93 ret.push_back(_array);
98 bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<T> *other, std::string& reason) const
100 std::ostringstream oss; oss.precision(15);
101 if(_time_unit!=other->_time_unit)
103 oss << "Field discretizations differ : this time unit = \"" << _time_unit << "\" and other time unit = \"" << other->_time_unit << "\" !";
107 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
109 oss << "Field discretizations differ : this time tolerance = \"" << _time_tolerance << "\" and other time tolerance = \"" << other->_time_tolerance << "\" !";
113 if(_array==0 && other->_array==0)
115 if(_array==0 || other->_array==0)
117 reason="Field discretizations differ : Only one timediscretization between the two this and other has a DataArrayDouble for values defined";
120 if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
122 if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
128 bool MEDCouplingTimeDiscretizationTemplate<T>::areCompatible(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
130 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
132 if(_array==0 && other->_array==0)
134 if(_array==0 || other->_array==0)
136 if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
142 bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
144 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
146 if(_array==0 && other->_array==0)
148 if(_array==0 || other->_array==0)
150 int nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
151 int nbMin(std::min(nbC1,nbC2));
152 if(nbC1!=nbC2 && nbMin!=1)
158 bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
160 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
162 if(_array==0 && other->_array==0)
164 if(_array==0 || other->_array==0)
166 int nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
167 if(nbC1!=nbC2 && nbC2!=1)
173 MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate():_time_tolerance(TIME_TOLERANCE_DFT),_array(0)
178 MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate<T>& other, bool deepCopy):_time_unit(other._time_unit),_time_tolerance(other._time_tolerance)
181 _array=other._array->performCopyOrIncrRef(deepCopy);
187 MEDCouplingTimeDiscretizationTemplate<T>::~MEDCouplingTimeDiscretizationTemplate()
194 void MEDCouplingTimeDiscretizationTemplate<T>::setEndArray(typename Traits<T>::ArrayType *array, TimeLabel *owner)
196 throw INTERP_KERNEL::Exception("setEndArray not available for this type of time discretization !");
200 void MEDCouplingTimeDiscretizationTemplate<T>::setArrays(const std::vector<typename Traits<T>::ArrayType *>& arrays, TimeLabel *owner)
203 throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretization::setArrays : number of arrays must be one.");
204 setArray(arrays.back(),owner);
208 const typename Traits<T>::ArrayType *MEDCouplingTimeDiscretizationTemplate<T>::getEndArray() const
210 throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
214 typename Traits<T>::ArrayType *MEDCouplingTimeDiscretizationTemplate<T>::getEndArray()
216 throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
220 void MEDCouplingTimeDiscretizationTemplate<T>::getArrays(std::vector<typename Traits<T>::ArrayType *>& arrays) const
227 std::string MEDCouplingTimeDiscretizationSimple<T>::getStringRepr() const
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 << "\"";
236 double MEDCouplingTimeDiscretizationSimple<T>::getEndTime(int& iteration, int& order) const
238 throw INTERP_KERNEL::Exception("getEndTime : invalid for this type of time discr !");
242 void MEDCouplingTimeDiscretizationSimple<T>::setEndIteration(int it)
244 throw INTERP_KERNEL::Exception("setEndIteration : invalid for this type of time discr !");
248 void MEDCouplingTimeDiscretizationSimple<T>::setEndOrder(int order)
250 throw INTERP_KERNEL::Exception("setEndOrder : invalid for this type of time discr !");
254 void MEDCouplingTimeDiscretizationSimple<T>::setEndTimeValue(double time)
256 throw INTERP_KERNEL::Exception("setEndTimeValue : invalid for this type of time discr !");
260 void MEDCouplingTimeDiscretizationSimple<T>::setEndTime(double time, int iteration, int order)
262 throw INTERP_KERNEL::Exception("setEndTime : invalid for this type of time discr !");
266 MEDCouplingTimeDiscretizationSimple<T>::MEDCouplingTimeDiscretizationSimple(const MEDCouplingTimeDiscretizationSimple<T>& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate<T>(other,deepCopy),_tk(other._tk)