1 // Copyright (C) 2007-2023 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"
25 #include "MEDCouplingMemArray.txx"
33 const char MEDCouplingTimeDiscretizationSimple<T>::REPR[]="One time label.";
36 const double MEDCouplingTimeDiscretizationTemplate<T>::TIME_TOLERANCE_DFT=1.e-12;
39 void MEDCouplingTimeDiscretizationTemplate<T>::updateTime() const
42 updateTimeWith(*_array);
46 void MEDCouplingTimeDiscretizationTemplate<T>::setArray(typename Traits<T>::ArrayType *array, TimeLabel *owner)
56 owner->declareAsNew();
61 void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
63 TimeHolder::copyTinyAttrFrom(other);
64 _time_tolerance=other._time_tolerance;
68 void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
70 TimeHolder::copyTinyAttrFrom(other);
71 if(_array && other._array)
72 _array->copyStringInfoFrom(*other._array);
76 std::size_t MEDCouplingTimeDiscretizationTemplate<T>::getHeapMemorySizeWithoutChildren() const
78 return getTimeUnit().capacity();
82 void MEDCouplingTimeDiscretizationTemplate<T>::checkConsistencyLight() const
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. !");
91 std::vector<const BigMemoryObject *> MEDCouplingTimeDiscretizationTemplate<T>::getDirectChildrenWithNull() const
93 std::vector<const BigMemoryObject *> ret;
94 ret.push_back(_array);
99 bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<T> *other, std::string& reason) const
101 std::ostringstream oss; oss.precision(15);
102 if(getTimeUnit()!=other->getTimeUnit())
104 oss << "Field discretizations differ : this time unit = \"" << getTimeUnit() << "\" and other time unit = \"" << other->getTimeUnit() << "\" !";
108 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
110 oss << "Field discretizations differ : this time tolerance = \"" << _time_tolerance << "\" and other time tolerance = \"" << other->_time_tolerance << "\" !";
114 if(_array==0 && other->_array==0)
116 if(_array==0 || other->_array==0)
118 reason="Field discretizations differ : Only one timediscretization between the two this and other has a DataArrayDouble for values defined";
121 if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
123 if(_array->getNumberOfTuples()!=other->_array->getNumberOfTuples())
129 bool MEDCouplingTimeDiscretizationTemplate<T>::areCompatible(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
131 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
133 if(_array==0 && other->_array==0)
135 if(_array==0 || other->_array==0)
137 if(_array->getNumberOfComponents()!=other->_array->getNumberOfComponents())
143 bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
145 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
147 if(_array==0 && other->_array==0)
149 if(_array==0 || other->_array==0)
151 std::size_t nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
152 std::size_t nbMin(std::min(nbC1,nbC2));
153 if(nbC1!=nbC2 && nbMin!=1)
159 bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate<T> *other) const
161 if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
163 if(_array==0 && other->_array==0)
165 if(_array==0 || other->_array==0)
167 std::size_t nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
168 if(nbC1!=nbC2 && nbC2!=1)
174 MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate():_time_tolerance(TIME_TOLERANCE_DFT),_array(0)
179 MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate<T>& other, bool deepCopy):TimeHolder(other),_time_tolerance(other._time_tolerance)
182 _array=other._array->performCopyOrIncrRef(deepCopy);
188 MEDCouplingTimeDiscretizationTemplate<T>::~MEDCouplingTimeDiscretizationTemplate()
195 void MEDCouplingTimeDiscretizationTemplate<T>::setEndArray(typename Traits<T>::ArrayType *array, TimeLabel *owner)
197 throw INTERP_KERNEL::Exception("setEndArray not available for this type of time discretization !");
201 void MEDCouplingTimeDiscretizationTemplate<T>::setArrays(const std::vector<typename Traits<T>::ArrayType *>& arrays, TimeLabel *owner)
204 throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretization::setArrays : number of arrays must be one.");
205 setArray(arrays.back(),owner);
209 const typename Traits<T>::ArrayType *MEDCouplingTimeDiscretizationTemplate<T>::getEndArray() const
211 throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
215 typename Traits<T>::ArrayType *MEDCouplingTimeDiscretizationTemplate<T>::getEndArray()
217 throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !");
221 void MEDCouplingTimeDiscretizationTemplate<T>::getArrays(std::vector<typename Traits<T>::ArrayType *>& arrays) const
228 void MEDCouplingTimeDiscretizationTemplate<T>::getTinySerializationIntInformation(std::vector<mcIdType>& tinyInfo) const
232 tinyInfo.push_back(_array->getNumberOfTuples());
233 tinyInfo.push_back(ToIdType(_array->getNumberOfComponents()));
237 tinyInfo.push_back(-1);
238 tinyInfo.push_back(-1);
243 void MEDCouplingTimeDiscretizationTemplate<T>::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
245 tinyInfo.push_back(_time_tolerance);
249 void MEDCouplingTimeDiscretizationTemplate<T>::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
251 std::size_t nbOfCompo(_array->getNumberOfComponents());
252 for(std::size_t i=0;i<nbOfCompo;i++)
253 tinyInfo.push_back(_array->getInfoOnComponent(i));
257 void MEDCouplingTimeDiscretizationTemplate<T>::resizeForUnserialization(const std::vector<mcIdType>& tinyInfoI, std::vector<typename Traits<T>::ArrayType *>& arrays)
262 typename Traits<T>::ArrayType *arr=0;
263 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
265 arr=Traits<T>::ArrayType::New();
266 arr->alloc(tinyInfoI[0],tinyInfoI[1]);
273 void MEDCouplingTimeDiscretizationTemplate<T>::checkForUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<typename Traits<T>::ArrayType *>& arrays)
275 static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size one !";
277 throw INTERP_KERNEL::Exception(MSG);
281 if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
284 throw INTERP_KERNEL::Exception(MSG);
285 arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
292 void MEDCouplingTimeDiscretizationTemplate<T>::finishUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
294 _time_tolerance=tinyInfoD[0];
295 std::size_t nbOfCompo=_array->getNumberOfComponents();
296 for(std::size_t i=0;i<nbOfCompo;i++)
297 _array->setInfoOnComponent(i,tinyInfoS[i]);
300 /////////////////////////
303 std::string MEDCouplingTimeDiscretizationSimple<T>::getStringRepr() const
305 std::ostringstream stream;
306 stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
307 stream << "\nTime unit is : \"" << this->getTimeUnit() << "\"";
312 double MEDCouplingTimeDiscretizationSimple<T>::getEndTime(int& iteration, int& order) const
314 throw INTERP_KERNEL::Exception("getEndTime : invalid for this type of time discr !");
318 void MEDCouplingTimeDiscretizationSimple<T>::setEndIteration(int it)
320 throw INTERP_KERNEL::Exception("setEndIteration : invalid for this type of time discr !");
324 void MEDCouplingTimeDiscretizationSimple<T>::setEndOrder(int order)
326 throw INTERP_KERNEL::Exception("setEndOrder : invalid for this type of time discr !");
330 void MEDCouplingTimeDiscretizationSimple<T>::setEndTimeValue(double time)
332 throw INTERP_KERNEL::Exception("setEndTimeValue : invalid for this type of time discr !");
336 void MEDCouplingTimeDiscretizationSimple<T>::setEndTime(double time, int iteration, int order)
338 throw INTERP_KERNEL::Exception("setEndTime : invalid for this type of time discr !");
342 MEDCouplingTimeDiscretizationSimple<T>::MEDCouplingTimeDiscretizationSimple(const MEDCouplingTimeDiscretizationSimple<T>& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate<T>(other,deepCopy),_tk(other._tk)