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 double MEDCouplingTimeDiscretizationTemplate<T>::TIME_TOLERANCE_DFT=1.e-12;
35 void MEDCouplingTimeDiscretizationTemplate<T>::updateTime() const
38 updateTimeWith(*_array);
42 void MEDCouplingTimeDiscretizationTemplate<T>::setArray(typename Traits<T>::ArrayType *array, TimeLabel *owner)
52 owner->declareAsNew();
57 void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
59 _time_tolerance=other._time_tolerance;
60 _time_unit=other._time_unit;
64 void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
66 _time_unit=other._time_unit;
67 if(_array && other._array)
68 _array->copyStringInfoFrom(*other._array);
72 std::size_t MEDCouplingTimeDiscretizationTemplate<T>::getHeapMemorySizeWithoutChildren() const
74 return _time_unit.capacity();
78 void MEDCouplingTimeDiscretizationTemplate<T>::checkConsistencyLight() const
81 throw INTERP_KERNEL::Exception("Field invalid because no values set !");
82 if(_time_tolerance<0.)
83 throw INTERP_KERNEL::Exception("time tolerance is expected to be greater than 0. !");
87 std::vector<const BigMemoryObject *> MEDCouplingTimeDiscretizationTemplate<T>::getDirectChildrenWithNull() const
89 std::vector<const BigMemoryObject *> ret;
90 ret.push_back(_array);
95 bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<T> *other, std::string& reason) const
97 std::ostringstream oss; oss.precision(15);
98 if(_time_unit!=other->_time_unit)
100 oss << "Field discretizations differ : this time unit = \"" << _time_unit << "\" and other time unit = \"" << other->_time_unit << "\" !";
104 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
106 oss << "Field discretizations differ : this time tolerance = \"" << _time_tolerance << "\" and other time tolerance = \"" << other->_time_tolerance << "\" !";
110 if(_array==0 && other->_array==0)
112 if(_array==0 || other->_array==0)
114 reason="Field discretizations differ : Only one timediscretization between the two this and other has a DataArrayDouble for values defined";
117 if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
119 if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
125 bool MEDCouplingTimeDiscretizationTemplate<T>::areCompatible(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
127 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
129 if(_array==0 && other->_array==0)
131 if(_array==0 || other->_array==0)
133 if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
139 bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
141 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
143 if(_array==0 && other->_array==0)
145 if(_array==0 || other->_array==0)
147 int nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
148 int nbMin(std::min(nbC1,nbC2));
149 if(nbC1!=nbC2 && nbMin!=1)
155 bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
157 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
159 if(_array==0 && other->_array==0)
161 if(_array==0 || other->_array==0)
163 int nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
164 if(nbC1!=nbC2 && nbC2!=1)
170 MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate():_time_tolerance(TIME_TOLERANCE_DFT),_array(0)
175 MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate<T>& other, bool deepCopy):_time_unit(other._time_unit),_time_tolerance(other._time_tolerance)
178 _array=other._array->performCopyOrIncrRef(deepCopy);
184 MEDCouplingTimeDiscretizationTemplate<T>::~MEDCouplingTimeDiscretizationTemplate()