-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2024 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#define __MEDCOUPLINGTIMEDISCRETIZATION_TXX__
#include "MEDCouplingTimeDiscretization.hxx"
+#include "MEDCouplingMemArray.txx"
#include <cmath>
#include <sstream>
namespace MEDCoupling
{
+ template<class T>
+ const char MEDCouplingTimeDiscretizationSimple<T>::REPR[]="One time label.";
+
template<class T>
const double MEDCouplingTimeDiscretizationTemplate<T>::TIME_TOLERANCE_DFT=1.e-12;
template<class T>
void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyAttrFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
{
+ TimeHolder::copyTinyAttrFrom(other);
_time_tolerance=other._time_tolerance;
- _time_unit=other._time_unit;
}
template<class T>
void MEDCouplingTimeDiscretizationTemplate<T>::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate<T>& other)
{
- _time_unit=other._time_unit;
+ TimeHolder::copyTinyAttrFrom(other);
if(_array && other._array)
_array->copyStringInfoFrom(*other._array);
}
template<class T>
std::size_t MEDCouplingTimeDiscretizationTemplate<T>::getHeapMemorySizeWithoutChildren() const
{
- return _time_unit.capacity();
+ return getTimeUnit().capacity();
}
template<class T>
bool MEDCouplingTimeDiscretizationTemplate<T>::areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate<T> *other, std::string& reason) const
{
std::ostringstream oss; oss.precision(15);
- if(_time_unit!=other->_time_unit)
+ if(getTimeUnit()!=other->getTimeUnit())
{
- oss << "Field discretizations differ : this time unit = \"" << _time_unit << "\" and other time unit = \"" << other->_time_unit << "\" !";
+ oss << "Field discretizations differ : this time unit = \"" << getTimeUnit() << "\" and other time unit = \"" << other->getTimeUnit() << "\" !";
reason=oss.str();
return false;
}
return true;
if(_array==0 || other->_array==0)
return false;
- int nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
- int nbMin(std::min(nbC1,nbC2));
+ std::size_t nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
+ std::size_t nbMin(std::min(nbC1,nbC2));
if(nbC1!=nbC2 && nbMin!=1)
return false;
return true;
return true;
if(_array==0 || other->_array==0)
return false;
- int nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
+ std::size_t nbC1(_array->getNumberOfComponents()),nbC2(other->_array->getNumberOfComponents());
if(nbC1!=nbC2 && nbC2!=1)
return false;
return true;
}
template<class T>
- MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate<T>& other, bool deepCopy):_time_unit(other._time_unit),_time_tolerance(other._time_tolerance)
+ MEDCouplingTimeDiscretizationTemplate<T>::MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate<T>& other, bool deepCopy):TimeHolder(other),_time_tolerance(other._time_tolerance)
{
if(other._array)
_array=other._array->performCopyOrIncrRef(deepCopy);
arrays.resize(1);
arrays[0]=_array;
}
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::getTinySerializationIntInformation(std::vector<mcIdType>& tinyInfo) const
+ {
+ if(_array)
+ {
+ tinyInfo.push_back(_array->getNumberOfTuples());
+ tinyInfo.push_back(ToIdType(_array->getNumberOfComponents()));
+ }
+ else
+ {
+ tinyInfo.push_back(-1);
+ tinyInfo.push_back(-1);
+ }
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
+ {
+ tinyInfo.push_back(_time_tolerance);
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
+ {
+ std::size_t nbOfCompo(_array->getNumberOfComponents());
+ for(std::size_t i=0;i<nbOfCompo;i++)
+ tinyInfo.push_back(_array->getInfoOnComponent(i));
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::resizeForUnserialization(const std::vector<mcIdType>& tinyInfoI, std::vector<typename Traits<T>::ArrayType *>& arrays)
+ {
+ arrays.resize(1);
+ if(_array!=0)
+ _array->decrRef();
+ typename Traits<T>::ArrayType *arr=0;
+ if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
+ {
+ arr=Traits<T>::ArrayType::New();
+ arr->alloc(tinyInfoI[0],tinyInfoI[1]);
+ }
+ _array=arr;
+ arrays[0]=arr;
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::checkForUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<typename Traits<T>::ArrayType *>& arrays)
+ {
+ static const char MSG[]="MEDCouplingTimeDiscretization::checkForUnserialization : arrays in input is expected to have size one !";
+ if(arrays.size()!=1)
+ throw INTERP_KERNEL::Exception(MSG);
+ if(_array!=0)
+ _array->decrRef();
+ _array=0;
+ if(tinyInfoI[0]!=-1 && tinyInfoI[1]!=-1)
+ {
+ if(!arrays[0])
+ throw INTERP_KERNEL::Exception(MSG);
+ arrays[0]->checkNbOfTuplesAndComp(tinyInfoI[0],tinyInfoI[1],MSG);
+ _array=arrays[0];
+ _array->incrRef();
+ }
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationTemplate<T>::finishUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
+ {
+ _time_tolerance=tinyInfoD[0];
+ std::size_t nbOfCompo=_array->getNumberOfComponents();
+ for(std::size_t i=0;i<nbOfCompo;i++)
+ _array->setInfoOnComponent(i,tinyInfoS[i]);
+ }
+
+ /////////////////////////
+
+ template<class T>
+ std::string MEDCouplingTimeDiscretizationSimple<T>::getStringRepr() const
+ {
+ std::ostringstream stream;
+ stream << REPR << " Time is defined by iteration=" << _tk.getIteration() << " order=" << _tk.getOrder() << " and time=" << _tk.getTimeValue() << ".";
+ stream << "\nTime unit is : \"" << this->getTimeUnit() << "\"";
+ return stream.str();
+ }
+
+ template<class T>
+ double MEDCouplingTimeDiscretizationSimple<T>::getEndTime(int& iteration, int& order) const
+ {
+ throw INTERP_KERNEL::Exception("getEndTime : invalid for this type of time discr !");
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationSimple<T>::setEndIteration(int it)
+ {
+ throw INTERP_KERNEL::Exception("setEndIteration : invalid for this type of time discr !");
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationSimple<T>::setEndOrder(int order)
+ {
+ throw INTERP_KERNEL::Exception("setEndOrder : invalid for this type of time discr !");
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationSimple<T>::setEndTimeValue(double time)
+ {
+ throw INTERP_KERNEL::Exception("setEndTimeValue : invalid for this type of time discr !");
+ }
+
+ template<class T>
+ void MEDCouplingTimeDiscretizationSimple<T>::setEndTime(double time, int iteration, int order)
+ {
+ throw INTERP_KERNEL::Exception("setEndTime : invalid for this type of time discr !");
+ }
+
+ template<class T>
+ MEDCouplingTimeDiscretizationSimple<T>::MEDCouplingTimeDiscretizationSimple(const MEDCouplingTimeDiscretizationSimple<T>& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate<T>(other,deepCopy),_tk(other._tk)
+ {
+ }
}
#endif