From 6ee9cbe7ece9247462c40607c0f2082e633a75f6 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 23 Aug 2016 18:54:39 +0200 Subject: [PATCH] On the road --- doc/user/doxygen/Doxyfile_med_user.in | 2 + src/MEDCoupling/MEDCouplingFieldDouble.cxx | 89 ++-------------------- src/MEDCoupling/MEDCouplingFieldDouble.hxx | 28 ------- src/MEDCoupling/MEDCouplingFieldInt.cxx | 53 ------------- src/MEDCoupling/MEDCouplingFieldInt.hxx | 9 --- src/MEDCoupling/MEDCouplingFieldT.hxx | 31 ++++++++ src/MEDCoupling/MEDCouplingFieldT.txx | 67 ++++++++++++++++ src/MEDCoupling/MEDCouplingTraits.hxx | 4 + 8 files changed, 111 insertions(+), 172 deletions(-) diff --git a/doc/user/doxygen/Doxyfile_med_user.in b/doc/user/doxygen/Doxyfile_med_user.in index 77989d387..fd9598241 100644 --- a/doc/user/doxygen/Doxyfile_med_user.in +++ b/doc/user/doxygen/Doxyfile_med_user.in @@ -140,6 +140,8 @@ FILE_PATTERNS = InterpKernelDEC.*xx \ MEDCouplingCurveLinearMesh.*xx \ MEDCouplingMappedExtrudedMesh.*xx \ MEDCouplingFieldDouble.*xx \ + MEDCouplingFieldInt.*xx \ + MEDCouplingFieldT.*xx \ MEDCouplingField.*xx \ MEDCouplingNatureOfFieldEnum \ MEDCouplingNatureOfField.hxx \ diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 64f4a24a7..976d798e0 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -87,19 +87,14 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::New(const MEDCouplingFieldTempla * Sets a time \a unit of \a this field. For more info, see \ref MEDCouplingFirstSteps3. * \param [in] unit \a unit (string) in which time is measured. */ -void MEDCouplingFieldDouble::setTimeUnit(const std::string& unit) -{ - timeDiscr()->setTimeUnit(unit); -} +//void MEDCouplingFieldDouble::setTimeUnit(const std::string& unit) /*! * Returns a time unit of \a this field. * \return a string describing units in which time is measured. */ -std::string MEDCouplingFieldDouble::getTimeUnit() const -{ - return timeDiscr()->getTimeUnit(); -} +//std::string MEDCouplingFieldDouble::getTimeUnit() const + /*! * This method if possible the time information (time unit, time iteration, time unit and time value) with its support @@ -139,38 +134,6 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::clone(bool recDeepCpy) const return new MEDCouplingFieldDouble(*this,recDeepCpy); } -/*! - * Returns a new MEDCouplingFieldDouble which is a copy of \a this one. The data - * of \a this field is copied either deep or shallow depending on \a recDeepCpy - * parameter. But the underlying mesh is always deep copied. - * Data that can be copied either deeply or shallow are: - * - \ref MEDCouplingTemporalDisc "temporal discretization" data that holds array(s) - * of field values, - * - \ref MEDCouplingSpatialDisc "a spatial discretization". - * - * This method behaves exactly like clone() except that here the underlying **mesh is - * always deeply duplicated**, whatever the value \a recDeepCpy parameter. - * The result of \c cloneWithMesh(true) is exactly the same as that of deepCopy(). - * So the resulting field can not be used together with \a this one in the methods - * like operator+(), operator*() etc. To avoid deep copying the underlying mesh, - * the user can call clone(). - * \param [in] recDeepCpy - if \c true, the copy of the underlying data arrays is - * deep, else all data arrays of \a this field are shared by the new field. - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The - * caller is to delete this field using decrRef() as it is no more needed. - * \sa clone() - */ -MEDCouplingFieldDouble *MEDCouplingFieldDouble::cloneWithMesh(bool recDeepCpy) const -{ - MCAuto ret=clone(recDeepCpy); - if(_mesh) - { - MCAuto mCpy=_mesh->deepCopy(); - ret->setMesh(mCpy); - } - return ret.retn(); -} - /*! * Returns a new MEDCouplingFieldDouble which is a deep copy of \a this one **including * the mesh**. @@ -907,22 +870,6 @@ MEDCouplingFieldDouble::MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeD { } -/*! - * Checks if \a this field is correctly defined, else an exception is thrown. - * \throw If the mesh is not set. - * \throw If the data array is not set. - * \throw If the spatial discretization of \a this field is NULL. - * \throw If \a this->getTimeTolerance() < 0. - * \throw If the temporal discretization data is incorrect. - * \throw If mesh data does not correspond to field data. - */ -void MEDCouplingFieldDouble::checkConsistencyLight() const -{ - MEDCouplingField::checkConsistencyLight(); - timeDiscr()->checkConsistencyLight(); - _type->checkCoherencyBetween(_mesh,getArray()); -} - /*! * Accumulate values of a given component of \a this field. * \param [in] compId - the index of the component of interest. @@ -1953,20 +1900,7 @@ void MEDCouplingFieldDouble::setNature(NatureOfField nat) _type->checkCompatibilityWithNature(nat); } -/*! - * This method synchronizes time information (time, iteration, order, time unit) regarding the information in \c this->_mesh. - * \throw If no mesh is set in this. Or if \a this is not compatible with time setting (typically NO_TIME) - */ -void MEDCouplingFieldDouble::synchronizeTimeWithMesh() -{ - if(!_mesh) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::synchronizeTimeWithMesh : no mesh set in this !"); - int it=-1,ordr=-1; - double val=_mesh->getTime(it,ordr); - std::string timeUnit(_mesh->getTimeUnit()); - setTime(val,it,ordr); - setTimeUnit(timeUnit); -} + /*! * Returns a value of \a this field of type either @@ -1997,10 +1931,7 @@ double MEDCouplingFieldDouble::getIJK(int cellId, int nodeIdInCell, int compoId) * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field * (see getNumberOfTuples()), but this size is not checked here. */ -void MEDCouplingFieldDouble::setArray(DataArrayDouble *array) -{ - timeDiscr()->setArray(array,this); -} +//void MEDCouplingFieldDouble::setArray(DataArrayDouble *array) /*! * Sets the data array holding values corresponding to an end of a time interval @@ -2010,10 +1941,7 @@ void MEDCouplingFieldDouble::setArray(DataArrayDouble *array) * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field * (see getNumberOfTuples()), but this size is not checked here. */ -void MEDCouplingFieldDouble::setEndArray(DataArrayDouble *array) -{ - timeDiscr()->setEndArray(array,this); -} +//void MEDCouplingFieldDouble::setEndArray(DataArrayDouble *array) /*! * Sets all data arrays needed to define the field values. @@ -2024,10 +1952,7 @@ void MEDCouplingFieldDouble::setEndArray(DataArrayDouble *array) * \throw If number of arrays in \a arrs does not correspond to type of * \ref MEDCouplingTemporalDisc "temporal discretization" of \a this field. */ -void MEDCouplingFieldDouble::setArrays(const std::vector& arrs) -{ - timeDiscr()->setArrays(arrs,this); -} +//void MEDCouplingFieldDouble::setArrays(const std::vector& arrs) void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector& tinyInfo) const { diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 07e16e42e..a1a7a519a 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -34,8 +34,6 @@ namespace MEDCoupling public: MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME); MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME); - MEDCOUPLING_EXPORT void setTimeUnit(const std::string& unit); - MEDCOUPLING_EXPORT std::string getTimeUnit() const; MEDCOUPLING_EXPORT void synchronizeTimeWithSupport(); MEDCOUPLING_EXPORT void copyTinyStringsFrom(const MEDCouplingField *other); MEDCOUPLING_EXPORT void copyTinyAttrFrom(const MEDCouplingFieldDouble *other); @@ -60,38 +58,12 @@ namespace MEDCoupling MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildSubPartRange(int begin, int end, int step) const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *deepCopy() const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *clone(bool recDeepCpy) const; - MEDCOUPLING_EXPORT MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *nodeToCellDiscretization() const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *cellToNodeDiscretization() const; MEDCOUPLING_EXPORT TypeOfTimeDiscretization getTimeDiscretization() const; - MEDCOUPLING_EXPORT void checkConsistencyLight() const; MEDCOUPLING_EXPORT void setNature(NatureOfField nat); - MEDCOUPLING_EXPORT void setTimeTolerance(double val) { _time_discr->setTimeTolerance(val); } - MEDCOUPLING_EXPORT double getTimeTolerance() const { return _time_discr->getTimeTolerance(); } - MEDCOUPLING_EXPORT void setIteration(int it) { _time_discr->setIteration(it); } - MEDCOUPLING_EXPORT void setEndIteration(int it) { _time_discr->setEndIteration(it); } - MEDCOUPLING_EXPORT void setOrder(int order) { _time_discr->setOrder(order); } - MEDCOUPLING_EXPORT void setEndOrder(int order) { _time_discr->setEndOrder(order); } - MEDCOUPLING_EXPORT void setTimeValue(double val) { _time_discr->setTimeValue(val); } - MEDCOUPLING_EXPORT void setEndTimeValue(double val) { _time_discr->setEndTimeValue(val); } - MEDCOUPLING_EXPORT void setTime(double val, int iteration, int order) { _time_discr->setTime(val,iteration,order); } - MEDCOUPLING_EXPORT void synchronizeTimeWithMesh(); - MEDCOUPLING_EXPORT void setStartTime(double val, int iteration, int order) { _time_discr->setStartTime(val,iteration,order); } - MEDCOUPLING_EXPORT void setEndTime(double val, int iteration, int order) { _time_discr->setEndTime(val,iteration,order); } - MEDCOUPLING_EXPORT double getTime(int& iteration, int& order) const { return _time_discr->getTime(iteration,order); } - MEDCOUPLING_EXPORT double getStartTime(int& iteration, int& order) const { return _time_discr->getStartTime(iteration,order); } - MEDCOUPLING_EXPORT double getEndTime(int& iteration, int& order) const { return _time_discr->getEndTime(iteration,order); } - MEDCOUPLING_EXPORT double getIJ(int tupleId, int compoId) const { return getArray()->getIJ(tupleId,compoId); } MEDCOUPLING_EXPORT double getIJK(int cellId, int nodeIdInCell, int compoId) const; - MEDCOUPLING_EXPORT void setArray(DataArrayDouble *array); - MEDCOUPLING_EXPORT void setEndArray(DataArrayDouble *array); - MEDCOUPLING_EXPORT void setArrays(const std::vector& arrs); - MEDCOUPLING_EXPORT const DataArrayDouble *getArray() const { return _time_discr->getArray(); } - MEDCOUPLING_EXPORT DataArrayDouble *getArray() { return _time_discr->getArray(); } - MEDCOUPLING_EXPORT const DataArrayDouble *getEndArray() const { return _time_discr->getEndArray(); } - MEDCOUPLING_EXPORT DataArrayDouble *getEndArray() { return _time_discr->getEndArray(); } - MEDCOUPLING_EXPORT std::vector getArrays() const { std::vector ret; _time_discr->getArrays(ret); return ret; } MEDCOUPLING_EXPORT double accumulate(int compId) const; MEDCOUPLING_EXPORT void accumulate(double *res) const; MEDCOUPLING_EXPORT double getMaxValue() const; diff --git a/src/MEDCoupling/MEDCouplingFieldInt.cxx b/src/MEDCoupling/MEDCouplingFieldInt.cxx index cc4938f34..30fc263bb 100644 --- a/src/MEDCoupling/MEDCouplingFieldInt.cxx +++ b/src/MEDCoupling/MEDCouplingFieldInt.cxx @@ -37,13 +37,6 @@ MEDCouplingFieldInt *MEDCouplingFieldInt::New(const MEDCouplingFieldTemplate& ft return new MEDCouplingFieldInt(ft,td); } -void MEDCouplingFieldInt::checkConsistencyLight() const -{ - MEDCouplingField::checkConsistencyLight(); - timeDiscr()->checkConsistencyLight(); - _type->checkCoherencyBetween(_mesh,getArray()); -} - std::string MEDCouplingFieldInt::simpleRepr() const { std::ostringstream ret; @@ -85,41 +78,6 @@ void MEDCouplingFieldInt::reprQuickOverview(std::ostream& stream) const { } -void MEDCouplingFieldInt::setTimeUnit(const std::string& unit) -{ - timeDiscr()->setTimeUnit(unit); -} - -std::string MEDCouplingFieldInt::getTimeUnit() const -{ - return timeDiscr()->getTimeUnit(); -} - -void MEDCouplingFieldInt::setTime(double val, int iteration, int order) -{ - timeDiscr()->setTime(val,iteration,order); -} - -double MEDCouplingFieldInt::getTime(int& iteration, int& order) const -{ - return timeDiscr()->getTime(iteration,order); -} - -void MEDCouplingFieldInt::setArray(DataArrayInt *array) -{ - timeDiscr()->setArray(array,this); -} - -const DataArrayInt *MEDCouplingFieldInt::getArray() const -{ - return timeDiscr()->getArray(); -} - -DataArrayInt *MEDCouplingFieldInt::getArray() -{ - return timeDiscr()->getArray(); -} - MEDCouplingFieldInt::MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingFieldT(type,MEDCouplingTimeDiscretizationInt::New(td)) { } @@ -144,17 +102,6 @@ MEDCouplingFieldInt *MEDCouplingFieldInt::deepCopy() const return cloneWithMesh(true); } -MEDCouplingFieldInt *MEDCouplingFieldInt::cloneWithMesh(bool recDeepCpy) const -{ - MCAuto ret(clone(recDeepCpy)); - if(_mesh) - { - MCAuto mCpy(_mesh->deepCopy()); - ret->setMesh(mCpy); - } - return ret.retn(); -} - MEDCouplingFieldInt *MEDCouplingFieldInt::clone(bool recDeepCpy) const { return new MEDCouplingFieldInt(*this,recDeepCpy); diff --git a/src/MEDCoupling/MEDCouplingFieldInt.hxx b/src/MEDCoupling/MEDCouplingFieldInt.hxx index 38c746378..1701f8ccb 100644 --- a/src/MEDCoupling/MEDCouplingFieldInt.hxx +++ b/src/MEDCoupling/MEDCouplingFieldInt.hxx @@ -36,19 +36,10 @@ namespace MEDCoupling public: MEDCOUPLING_EXPORT static MEDCouplingFieldInt *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME); MEDCOUPLING_EXPORT static MEDCouplingFieldInt *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME); - MEDCOUPLING_EXPORT void checkConsistencyLight() const; MEDCOUPLING_EXPORT std::string simpleRepr() const; MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; - MEDCOUPLING_EXPORT void setTimeUnit(const std::string& unit); - MEDCOUPLING_EXPORT std::string getTimeUnit() const; - MEDCOUPLING_EXPORT void setTime(double val, int iteration, int order); - MEDCOUPLING_EXPORT double getTime(int& iteration, int& order) const; - MEDCOUPLING_EXPORT void setArray(DataArrayInt *array); - MEDCOUPLING_EXPORT const DataArrayInt *getArray() const; - MEDCOUPLING_EXPORT DataArrayInt *getArray(); MEDCOUPLING_EXPORT MEDCouplingFieldInt *deepCopy() const; MEDCOUPLING_EXPORT MEDCouplingFieldInt *clone(bool recDeepCpy) const; - MEDCOUPLING_EXPORT MEDCouplingFieldInt *cloneWithMesh(bool recDeepCpy) const; MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const; MEDCOUPLING_EXPORT void copyTinyStringsFrom(const MEDCouplingField *other); diff --git a/src/MEDCoupling/MEDCouplingFieldT.hxx b/src/MEDCoupling/MEDCouplingFieldT.hxx index 6f88381ee..9dc0fe0e5 100644 --- a/src/MEDCoupling/MEDCouplingFieldT.hxx +++ b/src/MEDCoupling/MEDCouplingFieldT.hxx @@ -22,6 +22,7 @@ #define __MEDCOUPLINGFIELDT_HXX__ #include "MEDCouplingField.hxx" +#include "MEDCouplingTraits.hxx" #include "MEDCouplingTimeDiscretization.hxx" namespace MEDCoupling @@ -38,6 +39,36 @@ namespace MEDCoupling MEDCouplingFieldT(TypeOfField type, MEDCouplingTimeDiscretizationTemplate *timeDiscr); MEDCouplingFieldT(MEDCouplingFieldDiscretization *type, NatureOfField n, MEDCouplingTimeDiscretizationTemplate *timeDiscr); ~MEDCouplingFieldT(); + public: + MEDCOUPLING_EXPORT virtual typename Traits::FieldType *clone(bool recDeepCpy) const = 0; + MEDCOUPLING_EXPORT void checkConsistencyLight() const; + MEDCOUPLING_EXPORT typename Traits::FieldType *cloneWithMesh(bool recDeepCpy) const; + MEDCOUPLING_EXPORT void setArray(typename Traits::ArrayType *array) { _time_discr->setArray(array,this); } + MEDCOUPLING_EXPORT void setEndArray(typename Traits::ArrayType *array) { _time_discr->setEndArray(array,this); } + MEDCOUPLING_EXPORT const typename Traits::ArrayType *getArray() const { return _time_discr->getArray(); } + MEDCOUPLING_EXPORT typename Traits::ArrayType *getArray() { return _time_discr->getArray(); } + MEDCOUPLING_EXPORT const typename Traits::ArrayType *getEndArray() const { return _time_discr->getEndArray(); } + MEDCOUPLING_EXPORT typename Traits::ArrayType *getEndArray() { return _time_discr->getEndArray(); } + MEDCOUPLING_EXPORT void setArrays(const std::vector::ArrayType *>& arrs) { _time_discr->setArrays(arrs,this); } + MEDCOUPLING_EXPORT std::vector::ArrayType *> getArrays() const { std::vector::ArrayType *> ret; _time_discr->getArrays(ret); return ret; } + MEDCOUPLING_EXPORT void setTimeUnit(const std::string& unit) { _time_discr->setTimeUnit(unit); } + MEDCOUPLING_EXPORT std::string getTimeUnit() const { return _time_discr->getTimeUnit(); } + MEDCOUPLING_EXPORT void setTimeTolerance(double val) { _time_discr->setTimeTolerance(val); } + MEDCOUPLING_EXPORT double getTimeTolerance() const { return _time_discr->getTimeTolerance(); } + MEDCOUPLING_EXPORT void setIteration(int it) { _time_discr->setIteration(it); } + MEDCOUPLING_EXPORT void setEndIteration(int it) { _time_discr->setEndIteration(it); } + MEDCOUPLING_EXPORT void setOrder(int order) { _time_discr->setOrder(order); } + MEDCOUPLING_EXPORT void setEndOrder(int order) { _time_discr->setEndOrder(order); } + MEDCOUPLING_EXPORT void setTimeValue(double val) { _time_discr->setTimeValue(val); } + MEDCOUPLING_EXPORT void setEndTimeValue(double val) { _time_discr->setEndTimeValue(val); } + MEDCOUPLING_EXPORT void setTime(double val, int iteration, int order) { _time_discr->setTime(val,iteration,order); } + MEDCOUPLING_EXPORT void synchronizeTimeWithMesh(); + MEDCOUPLING_EXPORT void setStartTime(double val, int iteration, int order) { _time_discr->setStartTime(val,iteration,order); } + MEDCOUPLING_EXPORT void setEndTime(double val, int iteration, int order) { _time_discr->setEndTime(val,iteration,order); } + MEDCOUPLING_EXPORT double getTime(int& iteration, int& order) const { return _time_discr->getTime(iteration,order); } + MEDCOUPLING_EXPORT double getStartTime(int& iteration, int& order) const { return _time_discr->getStartTime(iteration,order); } + MEDCOUPLING_EXPORT double getEndTime(int& iteration, int& order) const { return _time_discr->getEndTime(iteration,order); } + MEDCOUPLING_EXPORT T getIJ(int tupleId, int compoId) const { return getArray()->getIJ(tupleId,compoId); } protected: MEDCouplingTimeDiscretizationTemplate *_time_discr; }; diff --git a/src/MEDCoupling/MEDCouplingFieldT.txx b/src/MEDCoupling/MEDCouplingFieldT.txx index fac31b705..459134b2f 100644 --- a/src/MEDCoupling/MEDCouplingFieldT.txx +++ b/src/MEDCoupling/MEDCouplingFieldT.txx @@ -22,6 +22,7 @@ #define __MEDCOUPLINGFIELDT_TXX__ #include "MEDCouplingTimeDiscretization.hxx" +#include "MEDCouplingMesh.hxx" namespace MEDCoupling { @@ -29,6 +30,23 @@ namespace MEDCoupling MEDCouplingFieldT::MEDCouplingFieldT(const MEDCouplingFieldT& other, bool deepCopy):MEDCouplingField(other,deepCopy),_time_discr(other._time_discr->performCopyOrIncrRef(deepCopy)) { } + + /*! + * Checks if \a this field is correctly defined, else an exception is thrown. + * \throw If the mesh is not set. + * \throw If the data array is not set. + * \throw If the spatial discretization of \a this field is NULL. + * \throw If \a this->getTimeTolerance() < 0. + * \throw If the temporal discretization data is incorrect. + * \throw If mesh data does not correspond to field data. + */ + template + void MEDCouplingFieldT::checkConsistencyLight() const + { + MEDCouplingField::checkConsistencyLight(); + _time_discr->checkConsistencyLight(); + _type->checkCoherencyBetween(_mesh,getArray()); + } template MEDCouplingFieldT::MEDCouplingFieldT(const MEDCouplingField& other, MEDCouplingTimeDiscretizationTemplate *timeDiscr, bool deepCopy):MEDCouplingField(other,deepCopy),_time_discr(timeDiscr) @@ -50,6 +68,55 @@ namespace MEDCoupling { delete _time_discr; } + + /*! + * This method synchronizes time information (time, iteration, order, time unit) regarding the information in \c this->_mesh. + * \throw If no mesh is set in this. Or if \a this is not compatible with time setting (typically NO_TIME) + */ + template + void MEDCouplingFieldT::synchronizeTimeWithMesh() + { + if(!_mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldT::synchronizeTimeWithMesh : no mesh set in this !"); + int it(-1),ordr(-1); + double val(_mesh->getTime(it,ordr)); + std::string timeUnit(_mesh->getTimeUnit()); + setTime(val,it,ordr); + setTimeUnit(timeUnit); + } + + /*! + * Returns a new MEDCouplingFieldDouble which is a copy of \a this one. The data + * of \a this field is copied either deep or shallow depending on \a recDeepCpy + * parameter. But the underlying mesh is always deep copied. + * Data that can be copied either deeply or shallow are: + * - \ref MEDCouplingTemporalDisc "temporal discretization" data that holds array(s) + * of field values, + * - \ref MEDCouplingSpatialDisc "a spatial discretization". + * + * This method behaves exactly like clone() except that here the underlying **mesh is + * always deeply duplicated**, whatever the value \a recDeepCpy parameter. + * The result of \c cloneWithMesh(true) is exactly the same as that of deepCopy(). + * So the resulting field can not be used together with \a this one in the methods + * like operator+(), operator*() etc. To avoid deep copying the underlying mesh, + * the user can call clone(). + * \param [in] recDeepCpy - if \c true, the copy of the underlying data arrays is + * deep, else all data arrays of \a this field are shared by the new field. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * caller is to delete this field using decrRef() as it is no more needed. + * \sa clone() + */ + template + typename Traits::FieldType *MEDCouplingFieldT::cloneWithMesh(bool recDeepCpy) const + { + MCAuto< typename Traits::FieldType > ret(clone(recDeepCpy)); + if(_mesh) + { + MCAuto mCpy=_mesh->deepCopy(); + ret->setMesh(mCpy); + } + return ret.retn(); + } } #endif diff --git a/src/MEDCoupling/MEDCouplingTraits.hxx b/src/MEDCoupling/MEDCouplingTraits.hxx index c4b7ed7fd..3b0ce94b0 100644 --- a/src/MEDCoupling/MEDCouplingTraits.hxx +++ b/src/MEDCoupling/MEDCouplingTraits.hxx @@ -32,12 +32,15 @@ namespace MEDCoupling class DataArrayInt; class DataArrayDouble; class DataArrayChar; + class MEDCouplingFieldDouble; + class MEDCouplingFieldInt; template<> struct Traits { static const char ArrayTypeName[]; typedef DataArrayDouble ArrayType; + typedef MEDCouplingFieldDouble FieldType; }; template<> @@ -45,6 +48,7 @@ namespace MEDCoupling { static const char ArrayTypeName[]; typedef DataArrayInt ArrayType; + typedef MEDCouplingFieldInt FieldType; }; template<> -- 2.39.2