From 7f53ba0ad6eebec56c2936b923ac3ae728f41074 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 22 Aug 2016 15:33:40 +0200 Subject: [PATCH] Merge 'agy/br810_1' branch. --- doc/user/doxygen/Doxyfile_med_user.in | 2 + .../Bases/InterpKernelException.cxx | 4 + .../Bases/InterpKernelException.hxx | 1 + src/MEDCoupling/MEDCouplingField.cxx | 2 + src/MEDCoupling/MEDCouplingFieldDouble.cxx | 608 +++++------------- src/MEDCoupling/MEDCouplingFieldDouble.hxx | 61 +- src/MEDCoupling/MEDCouplingFieldInt.cxx | 113 +--- src/MEDCoupling/MEDCouplingFieldInt.hxx | 23 +- src/MEDCoupling/MEDCouplingFieldT.hxx | 92 +++ src/MEDCoupling/MEDCouplingFieldT.txx | 372 +++++++++++ .../MEDCouplingTimeDiscretization.cxx | 330 +++++----- .../MEDCouplingTimeDiscretization.hxx | 84 +-- .../MEDCouplingTimeDiscretization.txx | 33 + src/MEDCoupling/MEDCouplingTraits.cxx | 4 + src/MEDCoupling/MEDCouplingTraits.hxx | 6 + src/MEDCoupling/MEDCouplingUMesh.cxx | 134 ++-- .../MEDCouplingBasicsTest5.py | 45 +- src/MEDCoupling_Swig/MEDCouplingCommon.i | 12 + src/MEDLoader/MEDFileField.cxx | 534 +++++++++------ src/MEDLoader/MEDFileField.hxx | 38 +- src/MEDLoader/Swig/MEDLoaderCommon.i | 134 +--- src/MEDLoader/Swig/MEDLoaderTest3.py | 361 ++++++++++- 22 files changed, 1767 insertions(+), 1226 deletions(-) create mode 100644 src/MEDCoupling/MEDCouplingFieldT.hxx create mode 100644 src/MEDCoupling/MEDCouplingFieldT.txx 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/INTERP_KERNEL/Bases/InterpKernelException.cxx b/src/INTERP_KERNEL/Bases/InterpKernelException.cxx index 0560aff74..110fd7ba5 100644 --- a/src/INTERP_KERNEL/Bases/InterpKernelException.cxx +++ b/src/INTERP_KERNEL/Bases/InterpKernelException.cxx @@ -24,6 +24,10 @@ INTERP_KERNEL::Exception::Exception(const char *reason):_reason(reason) { } +INTERP_KERNEL::Exception::Exception(const std::string& reason):_reason(reason) +{ +} + INTERP_KERNEL::Exception::Exception(const char *reason, const char *file, int line):_reason(reason) { } diff --git a/src/INTERP_KERNEL/Bases/InterpKernelException.hxx b/src/INTERP_KERNEL/Bases/InterpKernelException.hxx index 8d68ab69c..d165bfe82 100644 --- a/src/INTERP_KERNEL/Bases/InterpKernelException.hxx +++ b/src/INTERP_KERNEL/Bases/InterpKernelException.hxx @@ -32,6 +32,7 @@ namespace INTERP_KERNEL { public: INTERPKERNEL_EXPORT Exception(const char *reason); + INTERPKERNEL_EXPORT Exception(const std::string& reason); INTERPKERNEL_EXPORT Exception(const char *reason, const char *file, int line); INTERPKERNEL_EXPORT ~Exception() throw (); INTERPKERNEL_EXPORT const char *what() const throw(); diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 293d8aede..4afc32168 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -236,6 +236,8 @@ NatureOfField MEDCouplingField::getNature() const void MEDCouplingField::setNature(NatureOfField nat) { MEDCouplingNatureOfField::GetRepr(nat);//generate a throw if nat not recognized + if(_type) + _type->checkCompatibilityWithNature(nat); _nature=nat; } diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index dc3693c3e..0ca5c3476 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -20,6 +20,8 @@ #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldTemplate.hxx" +#include "MEDCouplingFieldT.txx" +#include "MEDCouplingFieldInt.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingTimeDiscretization.hxx" #include "MEDCouplingFieldDiscretization.hxx" @@ -35,6 +37,7 @@ using namespace MEDCoupling; +template class MEDCouplingFieldT; /*! * Creates a new MEDCouplingFieldDouble, of given spatial type and time discretization. @@ -85,19 +88,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) -{ - _time_discr->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 _time_discr->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 @@ -108,7 +106,7 @@ std::string MEDCouplingFieldDouble::getTimeUnit() const */ void MEDCouplingFieldDouble::synchronizeTimeWithSupport() { - _time_discr->synchronizeTimeWith(_mesh); + timeDiscr()->synchronizeTimeWith(_mesh); } /*! @@ -137,38 +135,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**. @@ -208,7 +174,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::deepCopy() const */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const { - MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(td,deepCopy); + MEDCouplingTimeDiscretization *tdo=timeDiscr()->buildNewTimeReprFromThis(td,deepCopy); MCAuto disc; if(_type) disc=_type->clone(); @@ -267,7 +233,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::nodeToCellDiscretization() const else { std::ostringstream oss; oss << "MEDCouplingFieldDouble::nodeToCellDiscretization : Cell id #" << i << " has been detected to have no nodes !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -317,94 +283,6 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::cellToNodeDiscretization() const return ret.retn(); } -/*! - * Copies tiny info (component names, name and description) from an \a other field to - * \a this one. - * \warning The underlying mesh is not renamed (for safety reason). - * \param [in] other - the field to copy the tiny info from. - * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents() - */ -void MEDCouplingFieldDouble::copyTinyStringsFrom(const MEDCouplingField *other) -{ - MEDCouplingField::copyTinyStringsFrom(other); - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); - if(otherC) - { - _time_discr->copyTinyStringsFrom(*otherC->_time_discr); - } -} - -/*! - * Copies only times, order and iteration from an \a other field to - * \a this one. The underlying mesh is not impacted by this method. - * Arrays are not impacted neither. - * \param [in] other - the field to tiny attributes from. - * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents() - */ -void MEDCouplingFieldDouble::copyTinyAttrFrom(const MEDCouplingFieldDouble *other) -{ - if(other) - { - _time_discr->copyTinyAttrFrom(*other->_time_discr); - } -} - -void MEDCouplingFieldDouble::copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) -{ - copyTinyStringsFrom(other); - copyTinyAttrFrom(other); -} - -/*! - * Returns a string describing \a this field. This string is outputted by \c print - * Python command. The string includes info on - * - name, - * - description, - * - \ref MEDCouplingSpatialDisc "spatial discretization", - * - \ref MEDCouplingTemporalDisc "time discretization", - * - \ref NatureOfField, - * - components, - * - mesh. - * - * \return std::string - the string describing \a this field. - */ -std::string MEDCouplingFieldDouble::simpleRepr() const -{ - std::ostringstream ret; - ret << "FieldDouble with name : \"" << getName() << "\"\n"; - ret << "Description of field is : \"" << getDescription() << "\"\n"; - if(_type) - { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; } - else - { ret << "FieldDouble has no spatial discretization !\n"; } - if(_time_discr) - { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; } - else - { ret << "FieldDouble has no time discretization !\n"; } - ret << "FieldDouble nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n"; - if(getArray()) - { - if(getArray()->isAllocated()) - { - int nbOfCompo=getArray()->getNumberOfComponents(); - ret << "FieldDouble default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; - ret << "FieldDouble default array has following info on components : "; - for(int i=0;igetInfoOnComponent(i) << "\" "; - ret << "\n"; - } - else - { - ret << "Array set but not allocated !\n"; - } - } - if(_mesh) - ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr(); - else - ret << "Mesh support information : No mesh set !\n"; - return ret.str(); -} - /*! * Returns a string describing \a this field. The string includes info on * - name, @@ -426,8 +304,8 @@ std::string MEDCouplingFieldDouble::advancedRepr() const { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; } else { ret << "FieldDouble has no space discretization set !\n"; } - if(_time_discr) - { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; } + if(timeDiscr()) + { ret << "FieldDouble time discretization is : " << timeDiscr()->getStringRepr() << "\n"; } else { ret << "FieldDouble has no time discretization set !\n"; } if(getArray()) @@ -437,7 +315,7 @@ std::string MEDCouplingFieldDouble::advancedRepr() const else ret << "Mesh support information : No mesh set !\n"; std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); int arrayId=0; for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++,arrayId++) { @@ -457,48 +335,6 @@ std::string MEDCouplingFieldDouble::writeVTK(const std::string& fileName, bool i return MEDCouplingFieldDouble::WriteVTK(fileName,fs,isBinary); } -bool MEDCouplingFieldDouble::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const -{ - if(!other) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::isEqualIfNotWhy : other instance is NULL !"); - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); - if(!otherC) - { - reason="field given in input is not castable in MEDCouplingFieldDouble !"; - return false; - } - if(!MEDCouplingField::isEqualIfNotWhy(other,meshPrec,valsPrec,reason)) - return false; - if(!_time_discr->isEqualIfNotWhy(otherC->_time_discr,valsPrec,reason)) - { - reason.insert(0,"In FieldDouble time discretizations differ :"); - return false; - } - return true; -} - -/*! - * Checks equality of \a this and \a other field. Only numeric data is considered, - * i.e. names, description etc are not compared. - * \param [in] other - the field to compare with. - * \param [in] meshPrec - a precision used to compare node coordinates of meshes. - * \param [in] valsPrec - a precision used to compare data arrays of the two fields. - * \return bool - \c true if the two fields are equal, \c false else. - * \throw If \a other == NULL. - * \throw If the spatial discretization of \a this field is NULL. - */ -bool MEDCouplingFieldDouble::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const -{ - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); - if(!otherC) - return false; - if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec)) - return false; - if(!_time_discr->isEqualWithoutConsideringStr(otherC->_time_discr,valsPrec)) - return false; - return true; -} - /*! * This method states if \a this and 'other' are compatibles each other before performing any treatment. * This method is good for methods like : mergeFields. @@ -508,59 +344,10 @@ bool MEDCouplingFieldDouble::areCompatibleForMerge(const MEDCouplingField *other { if(!MEDCouplingField::areCompatibleForMerge(other)) return false; - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + const MEDCouplingFieldDouble *otherC(dynamic_cast(other)); if(!otherC) return false; - if(!_time_discr->areCompatible(otherC->_time_discr)) - return false; - return true; -} - -/*! - * This method is more strict than MEDCouplingField::areCompatibleForMerge method. - * This method is used for operation on fields to operate a first check before attempting operation. - */ -bool MEDCouplingFieldDouble::areStrictlyCompatible(const MEDCouplingField *other) const -{ - std::string tmp; - if(!MEDCouplingField::areStrictlyCompatible(other)) - return false; - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); - if(!otherC) - return false; - if(!_time_discr->areStrictlyCompatible(otherC->_time_discr,tmp)) - return false; - return true; -} - -/*! - * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatibleForMulDiv method except that - * number of components between \a this and 'other' can be different here (for operator*). - */ -bool MEDCouplingFieldDouble::areCompatibleForMul(const MEDCouplingField *other) const -{ - if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other)) - return false; - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); - if(!otherC) - return false; - if(!_time_discr->areStrictlyCompatibleForMul(otherC->_time_discr)) - return false; - return true; -} - -/*! - * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatibleForMulDiv method except that - * number of components between \a this and 'other' can be different here (for operator/). - */ -bool MEDCouplingFieldDouble::areCompatibleForDiv(const MEDCouplingField *other) const -{ - if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other)) - return false; - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); - if(!otherC) - return false; - if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr)) + if(!timeDiscr()->areCompatible(otherC->timeDiscr())) return false; return true; } @@ -573,7 +360,7 @@ bool MEDCouplingFieldDouble::areCompatibleForMeld(const MEDCouplingFieldDouble * { if(!MEDCouplingField::areStrictlyCompatible(other)) return false; - if(!_time_discr->areCompatibleForMeld(other->_time_discr)) + if(!timeDiscr()->areCompatibleForMeld(other->timeDiscr())) return false; return true; } @@ -641,7 +428,7 @@ void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool // _type->renumberCells(old2NewBg,check); std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); std::vector arrays2(arrays.size()); std::copy(arrays.begin(),arrays.end(),arrays2.begin()); _type->renumberArraysForCell(_mesh,arrays2,old2NewBg,check); // @@ -707,7 +494,7 @@ void MEDCouplingFieldDouble::renumberNodesWithoutMesh(const int *old2NewBg, int if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !"); std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) if(*iter) _type->renumberValuesOnNodes(eps,old2NewBg,newNbOfNodes,*iter); @@ -817,7 +604,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, ret->setDiscretization(MCAuto(disc->clonePart(partBg,partEnd))); ret->setMesh(m); std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); std::vector arrs; std::vector< MCAuto > arrsSafe; const int *arrSelBg=arrSelect->begin(); @@ -829,7 +616,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd); arrs.push_back(arr); arrsSafe.push_back(arr); } - ret->_time_discr->setArrays(arrs,0); + ret->timeDiscr()->setArrays(arrs,0); return ret.retn(); } @@ -853,7 +640,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPartRange(int begin, int ret->setDiscretization(MCAuto(disc->clonePartRange(begin,end,step))); ret->setMesh(m); std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); std::vector arrs; std::vector< MCAuto > arrsSafe; for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) @@ -872,63 +659,44 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPartRange(int begin, int } arrs.push_back(arr); arrsSafe.push_back(arr); } - ret->_time_discr->setArrays(arrs,0); + ret->timeDiscr()->setArrays(arrs,0); return ret.retn(); } -/*! - * Returns a type of \ref MEDCouplingTemporalDisc "time discretization" of \a this field. - * \return MEDCoupling::TypeOfTimeDiscretization - an enum item describing the time - * discretization type. - */ -TypeOfTimeDiscretization MEDCouplingFieldDouble::getTimeDiscretization() const +MEDCouplingFieldInt *MEDCouplingFieldDouble::convertToIntField() const { - return _time_discr->getEnum(); + MCAuto tmp(MEDCouplingFieldTemplate::New(*this)); + int t1,t2; + double t0(getTime(t1,t2)); + MCAuto ret(MEDCouplingFieldInt::New(*tmp,getTimeDiscretization())); + ret->setTime(t0,t1,t2); + if(getArray()) + { + MCAuto arr(getArray()->convertToIntArr()); + ret->setArray(arr); + } + return ret.retn(); } -MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type), - _time_discr(MEDCouplingTimeDiscretization::New(td)) +MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingFieldT(type,MEDCouplingTimeDiscretization::New(td)) { } /*! * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! ** */ -MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingField(ft,false), - _time_discr(MEDCouplingTimeDiscretization::New(td)) +MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingFieldT(ft,MEDCouplingTimeDiscretization::New(td),false) { } -MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy):MEDCouplingField(other,deepCopy), - _time_discr(dynamic_cast(other._time_discr->performCopyOrIncrRef(deepCopy))) +MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy):MEDCouplingFieldT(other,deepCopy) { } -MEDCouplingFieldDouble::MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type):MEDCouplingField(type,n),_time_discr(td) +MEDCouplingFieldDouble::MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type):MEDCouplingFieldT(type,n,td) { } -MEDCouplingFieldDouble::~MEDCouplingFieldDouble() -{ - delete _time_discr; -} - -/*! - * 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(); - _time_discr->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. @@ -969,7 +737,7 @@ void MEDCouplingFieldDouble::accumulate(double *res) const double MEDCouplingFieldDouble::getMaxValue() const { std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); double ret=-std::numeric_limits::max(); bool isExistingArr=false; for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) @@ -999,7 +767,7 @@ double MEDCouplingFieldDouble::getMaxValue() const double MEDCouplingFieldDouble::getMaxValue2(DataArrayInt*& tupleIds) const { std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); double ret=-std::numeric_limits::max(); bool isExistingArr=false; tupleIds=0; @@ -1033,7 +801,7 @@ double MEDCouplingFieldDouble::getMaxValue2(DataArrayInt*& tupleIds) const double MEDCouplingFieldDouble::getMinValue() const { std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); double ret=std::numeric_limits::max(); bool isExistingArr=false; for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) @@ -1063,7 +831,7 @@ double MEDCouplingFieldDouble::getMinValue() const double MEDCouplingFieldDouble::getMinValue2(DataArrayInt*& tupleIds) const { std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); double ret=-std::numeric_limits::max(); bool isExistingArr=false; tupleIds=0; @@ -1171,7 +939,7 @@ double MEDCouplingFieldDouble::getWeightedAverageValue(int compId, bool isWAbs) if(compId<0 || compId>=nbComps) { std::ostringstream oss; oss << "MEDCouplingFieldDouble::getWeightedAverageValue : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } INTERP_KERNEL::AutoPtr res=new double[nbComps]; getWeightedAverageValue(res,isWAbs); @@ -1199,7 +967,7 @@ double MEDCouplingFieldDouble::normL1(int compId) const if(compId<0 || compId>=nbComps) { std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL1 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } INTERP_KERNEL::AutoPtr res=new double[nbComps]; _type->normL1(_mesh,getArray(),res); @@ -1246,7 +1014,7 @@ double MEDCouplingFieldDouble::normL2(int compId) const if(compId<0 || compId>=nbComps) { std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL2 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } INTERP_KERNEL::AutoPtr res=new double[nbComps]; _type->normL2(_mesh,getArray(),res); @@ -1296,7 +1064,7 @@ double MEDCouplingFieldDouble::integral(int compId, bool isWAbs) const if(compId<0 || compId>=nbComps) { std::ostringstream oss; oss << "MEDCouplingFieldDouble::integral : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } INTERP_KERNEL::AutoPtr res=new double[nbComps]; _type->integral(_mesh,getArray(),isWAbs,res); @@ -1348,7 +1116,7 @@ void MEDCouplingFieldDouble::integral(bool isWAbs, double *res) const */ void MEDCouplingFieldDouble::getValueOnPos(int i, int j, int k, double *res) const { - const DataArrayDouble *arr=_time_discr->getArray(); + const DataArrayDouble *arr=timeDiscr()->getArray(); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnPos"); if(!((const MEDCouplingFieldDiscretization *)_type)) @@ -1372,7 +1140,7 @@ void MEDCouplingFieldDouble::getValueOnPos(int i, int j, int k, double *res) con */ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) const { - const DataArrayDouble *arr=_time_discr->getArray(); + const DataArrayDouble *arr=timeDiscr()->getArray(); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn"); if(!((const MEDCouplingFieldDiscretization *)_type)) @@ -1400,7 +1168,7 @@ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) con */ DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, int nbOfPoints) const { - const DataArrayDouble *arr=_time_discr->getArray(); + const DataArrayDouble *arr=timeDiscr()->getArray(); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnMulti"); if(!((const MEDCouplingFieldDiscretization *)_type)) @@ -1427,7 +1195,7 @@ DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, */ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, double *res) const { - std::vector< const DataArrayDouble *> arrs=_time_discr->getArraysForTime(time); + std::vector< const DataArrayDouble *> arrs=timeDiscr()->getArraysForTime(time); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn"); if(!((const MEDCouplingFieldDiscretization *)_type)) @@ -1439,7 +1207,7 @@ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, dou res2.resize(sz+(*iter)->getNumberOfComponents()); _type->getValueOn(*iter,_mesh,spaceLoc,&res2[sz]); } - _time_discr->getValueForTime(time,res2,res); + timeDiscr()->getValueForTime(time,res2,res); } /*! @@ -1452,7 +1220,7 @@ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, dou */ void MEDCouplingFieldDouble::applyLin(double a, double b, int compoId) { - _time_discr->applyLin(a,b,compoId); + timeDiscr()->applyLin(a,b,compoId); } /*! @@ -1464,7 +1232,7 @@ void MEDCouplingFieldDouble::applyLin(double a, double b, int compoId) */ void MEDCouplingFieldDouble::applyLin(double a, double b) { - _time_discr->applyLin(a,b); + timeDiscr()->applyLin(a,b); } /*! @@ -1479,7 +1247,7 @@ MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value) if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform operator = !"); int nbOfTuple=_type->getNumberOfTuples(_mesh); - _time_discr->setOrCreateUniformValueOnAllComponents(nbOfTuple,value); + timeDiscr()->setOrCreateUniformValueOnAllComponents(nbOfTuple,value); return *this; } @@ -1504,7 +1272,7 @@ void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, FunctionToEvaluate f if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !"); MCAuto loc=_type->getLocalizationOfDiscValues(_mesh); - _time_discr->fillFromAnalytic(loc,nbOfComp,func); + timeDiscr()->fillFromAnalytic(loc,nbOfComp,func); } /*! @@ -1551,7 +1319,7 @@ void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& f if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !"); MCAuto loc=_type->getLocalizationOfDiscValues(_mesh); - _time_discr->fillFromAnalytic(loc,nbOfComp,func); + timeDiscr()->fillFromAnalytic(loc,nbOfComp,func); } /*! @@ -1600,7 +1368,7 @@ void MEDCouplingFieldDouble::fillFromAnalyticCompo(int nbOfComp, const std::stri if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalyticCompo !"); MCAuto loc=_type->getLocalizationOfDiscValues(_mesh); - _time_discr->fillFromAnalyticCompo(loc,nbOfComp,func); + timeDiscr()->fillFromAnalyticCompo(loc,nbOfComp,func); } /*! @@ -1649,7 +1417,7 @@ void MEDCouplingFieldDouble::fillFromAnalyticNamedCompo(int nbOfComp, const std: if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalyticNamedCompo !"); MCAuto loc=_type->getLocalizationOfDiscValues(_mesh); - _time_discr->fillFromAnalyticNamedCompo(loc,nbOfComp,varsOrder,func); + timeDiscr()->fillFromAnalyticNamedCompo(loc,nbOfComp,varsOrder,func); } /*! @@ -1666,7 +1434,7 @@ void MEDCouplingFieldDouble::fillFromAnalyticNamedCompo(int nbOfComp, const std: */ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) { - _time_discr->applyFunc(nbOfComp,func); + timeDiscr()->applyFunc(nbOfComp,func); } /*! @@ -1690,7 +1458,7 @@ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val) if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform applyFunc !"); int nbOfTuple=_type->getNumberOfTuples(_mesh); - _time_discr->setUniformValue(nbOfTuple,nbOfComp,val); + timeDiscr()->setUniformValue(nbOfTuple,nbOfComp,val); } /*! @@ -1727,7 +1495,7 @@ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val) */ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func) { - _time_discr->applyFunc(nbOfComp,func); + timeDiscr()->applyFunc(nbOfComp,func); } @@ -1767,7 +1535,7 @@ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func) */ void MEDCouplingFieldDouble::applyFuncCompo(int nbOfComp, const std::string& func) { - _time_discr->applyFuncCompo(nbOfComp,func); + timeDiscr()->applyFuncCompo(nbOfComp,func); } /*! @@ -1806,7 +1574,7 @@ void MEDCouplingFieldDouble::applyFuncCompo(int nbOfComp, const std::string& fun */ void MEDCouplingFieldDouble::applyFuncNamedCompo(int nbOfComp, const std::vector& varsOrder, const std::string& func) { - _time_discr->applyFuncNamedCompo(nbOfComp,varsOrder,func); + timeDiscr()->applyFuncNamedCompo(nbOfComp,varsOrder,func); } /*! @@ -1838,7 +1606,7 @@ void MEDCouplingFieldDouble::applyFuncNamedCompo(int nbOfComp, const std::vector */ void MEDCouplingFieldDouble::applyFunc(const std::string& func) { - _time_discr->applyFunc(func); + timeDiscr()->applyFunc(func); } /*! @@ -1848,7 +1616,7 @@ void MEDCouplingFieldDouble::applyFunc(const std::string& func) */ void MEDCouplingFieldDouble::applyFuncFast32(const std::string& func) { - _time_discr->applyFuncFast32(func); + timeDiscr()->applyFuncFast32(func); } /*! @@ -1858,7 +1626,7 @@ void MEDCouplingFieldDouble::applyFuncFast32(const std::string& func) */ void MEDCouplingFieldDouble::applyFuncFast64(const std::string& func) { - _time_discr->applyFuncFast64(func); + timeDiscr()->applyFuncFast64(func); } /*! @@ -1929,7 +1697,7 @@ int MEDCouplingFieldDouble::getNumberOfValues() const void MEDCouplingFieldDouble::updateTime() const { MEDCouplingField::updateTime(); - updateTimeWith(*_time_discr); + updateTimeWith(*timeDiscr()); } std::size_t MEDCouplingFieldDouble::getHeapMemorySizeWithoutChildren() const @@ -1940,40 +1708,14 @@ std::size_t MEDCouplingFieldDouble::getHeapMemorySizeWithoutChildren() const std::vector MEDCouplingFieldDouble::getDirectChildrenWithNull() const { std::vector ret(MEDCouplingField::getDirectChildrenWithNull()); - if(_time_discr) + if(timeDiscr()) { - std::vector ret2(_time_discr->getDirectChildrenWithNull()); + std::vector ret2(timeDiscr()->getDirectChildrenWithNull()); ret.insert(ret.end(),ret2.begin(),ret2.end()); } return ret; } -/*! - * Sets \ref NatureOfField. - * \param [in] nat - an item of enum MEDCoupling::NatureOfField. - */ -void MEDCouplingFieldDouble::setNature(NatureOfField nat) -{ - MEDCouplingField::setNature(nat); - if(_type) - _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 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" or @@ -2003,10 +1745,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) -{ - _time_discr->setArray(array,this); -} +//void MEDCouplingFieldDouble::setArray(DataArrayDouble *array) /*! * Sets the data array holding values corresponding to an end of a time interval @@ -2016,10 +1755,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) -{ - _time_discr->setEndArray(array,this); -} +//void MEDCouplingFieldDouble::setEndArray(DataArrayDouble *array) /*! * Sets all data arrays needed to define the field values. @@ -2030,15 +1766,12 @@ 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) -{ - _time_discr->setArrays(arrs,this); -} +//void MEDCouplingFieldDouble::setArrays(const std::vector& arrs) void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector& tinyInfo) const { tinyInfo.clear(); - _time_discr->getTinySerializationStrInformation(tinyInfo); + timeDiscr()->getTinySerializationStrInformation(tinyInfo); tinyInfo.push_back(_name); tinyInfo.push_back(_desc); tinyInfo.push_back(getTimeUnit()); @@ -2055,9 +1788,9 @@ void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !"); tinyInfo.clear(); tinyInfo.push_back((int)_type->getEnum()); - tinyInfo.push_back((int)_time_discr->getEnum()); + tinyInfo.push_back((int)timeDiscr()->getEnum()); tinyInfo.push_back((int)_nature); - _time_discr->getTinySerializationIntInformation(tinyInfo); + timeDiscr()->getTinySerializationIntInformation(tinyInfo); std::vector tinyInfo2; _type->getTinySerializationIntInformation(tinyInfo2); tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); @@ -2073,7 +1806,7 @@ void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vectorgetTinySerializationDbleInformation(tinyInfo); + timeDiscr()->getTinySerializationDbleInformation(tinyInfo); std::vector tinyInfo2; _type->getTinySerializationDbleInformation(tinyInfo2); tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); @@ -2098,7 +1831,7 @@ void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector& ti tinyInfoITmp.pop_back(); std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); - _time_discr->resizeForUnserialization(tinyInfoI2,arrays); + timeDiscr()->resizeForUnserialization(tinyInfoI2,arrays); std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); _type->resizeForUnserialization(tinyInfoITmp3,dataInt); } @@ -2117,7 +1850,7 @@ void MEDCouplingFieldDouble::checkForUnserialization(const std::vector& tin tinyInfoITmp.pop_back(); std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); - _time_discr->checkForUnserialization(tinyInfoI2,arrays); + timeDiscr()->checkForUnserialization(tinyInfoI2,arrays); std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); _type->checkForUnserialization(tinyInfoITmp3,dataInt); } @@ -2134,7 +1867,7 @@ void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyI std::vector tmp1(tmp.begin(),tmp.end()-sz); std::vector tmp2(tmp.end()-sz,tmp.end()); // - _time_discr->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS); + timeDiscr()->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS); _nature=(NatureOfField)tinyInfoI[2]; _type->finishUnserialization(tmp2); int nbOfElemS=(int)tinyInfoS.size(); @@ -2151,7 +1884,7 @@ void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vectorgetArrays(arrays); + timeDiscr()->getArrays(arrays); _type->getSerializationIntArray(dataInt); } @@ -2270,7 +2003,7 @@ bool MEDCouplingFieldDouble::mergeNodes(double eps, double epsOnVals) if(!ret)//no nodes have been merged. return ret; std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) if(*iter) _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter); @@ -2309,7 +2042,7 @@ bool MEDCouplingFieldDouble::mergeNodesCenter(double eps, double epsOnVals) if(!ret)//no nodes have been merged. return ret; std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) if(*iter) _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter); @@ -2345,7 +2078,7 @@ bool MEDCouplingFieldDouble::zipCoords(double epsOnVals) if(meshC2->getNumberOfNodes()!=oldNbOfNodes) { std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) if(*iter) _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter); @@ -2386,7 +2119,7 @@ bool MEDCouplingFieldDouble::zipConnectivity(int compType, double epsOnVals) if(meshC2->getNumberOfCells()!=oldNbOfCells) { std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) if(*iter) _type->renumberValuesOnCells(epsOnVals,meshC,arr->getConstPointer(),meshC2->getNumberOfCells(),*iter); @@ -2418,7 +2151,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::extractSlice3D(const double *ori ret->setMesh(mesh2); MCAuto tupleIds=computeTupleIdsToSelectFromCellIds(cellIds->begin(),cellIds->end()); std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); int i=0; std::vector newArr(arrays.size()); std::vector< MCAuto > newArr2(arrays.size()); @@ -2462,7 +2195,7 @@ bool MEDCouplingFieldDouble::simplexize(int policy) if(oldNbOfCells==newNbOfCells) return false; std::vector arrays; - _time_discr->getArrays(arrays); + timeDiscr()->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) if(*iter) _type->renumberValuesOnCellsR(_mesh,arr->getConstPointer(),arr->getNbOfElems(),*iter); @@ -2485,8 +2218,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const { if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform doublyContractedProduct !"); - MEDCouplingTimeDiscretization *td=_time_discr->doublyContractedProduct(); - td->copyTinyAttrFrom(*_time_discr); + MEDCouplingTimeDiscretization *td=timeDiscr()->doublyContractedProduct(); + td->copyTinyAttrFrom(*timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("DoublyContractedProduct"); ret->setMesh(getMesh()); @@ -2508,8 +2241,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::determinant() const { if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform determinant !"); - MEDCouplingTimeDiscretization *td=_time_discr->determinant(); - td->copyTinyAttrFrom(*_time_discr); + MEDCouplingTimeDiscretization *td=timeDiscr()->determinant(); + td->copyTinyAttrFrom(*timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("Determinant"); ret->setMesh(getMesh()); @@ -2532,8 +2265,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenValues() const { if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenValues !"); - MEDCouplingTimeDiscretization *td=_time_discr->eigenValues(); - td->copyTinyAttrFrom(*_time_discr); + MEDCouplingTimeDiscretization *td=timeDiscr()->eigenValues(); + td->copyTinyAttrFrom(*timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("EigenValues"); ret->setMesh(getMesh()); @@ -2555,8 +2288,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenVectors() const { if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenVectors !"); - MEDCouplingTimeDiscretization *td=_time_discr->eigenVectors(); - td->copyTinyAttrFrom(*_time_discr); + MEDCouplingTimeDiscretization *td=timeDiscr()->eigenVectors(); + td->copyTinyAttrFrom(*timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("EigenVectors"); ret->setMesh(getMesh()); @@ -2580,8 +2313,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::inverse() const { if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform inverse !"); - MEDCouplingTimeDiscretization *td=_time_discr->inverse(); - td->copyTinyAttrFrom(*_time_discr); + MEDCouplingTimeDiscretization *td=timeDiscr()->inverse(); + td->copyTinyAttrFrom(*timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("Inversion"); ret->setMesh(getMesh()); @@ -2605,8 +2338,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::trace() const { if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform trace !"); - MEDCouplingTimeDiscretization *td=_time_discr->trace(); - td->copyTinyAttrFrom(*_time_discr); + MEDCouplingTimeDiscretization *td=timeDiscr()->trace(); + td->copyTinyAttrFrom(*timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("Trace"); ret->setMesh(getMesh()); @@ -2629,8 +2362,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::deviator() const { if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform deviator !"); - MEDCouplingTimeDiscretization *td=_time_discr->deviator(); - td->copyTinyAttrFrom(*_time_discr); + MEDCouplingTimeDiscretization *td=timeDiscr()->deviator(); + td->copyTinyAttrFrom(*timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("Deviator"); ret->setMesh(getMesh()); @@ -2651,8 +2384,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::magnitude() const { if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform magnitude !"); - MEDCouplingTimeDiscretization *td=_time_discr->magnitude(); - td->copyTinyAttrFrom(*_time_discr); + MEDCouplingTimeDiscretization *td=timeDiscr()->magnitude(); + td->copyTinyAttrFrom(*timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("Magnitude"); ret->setMesh(getMesh()); @@ -2671,8 +2404,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxPerTuple() const { if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform maxPerTuple !"); - MEDCouplingTimeDiscretization *td=_time_discr->maxPerTuple(); - td->copyTinyAttrFrom(*_time_discr); + MEDCouplingTimeDiscretization *td=timeDiscr()->maxPerTuple(); + td->copyTinyAttrFrom(*timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); std::ostringstream oss; oss << "Max_" << getName(); @@ -2693,7 +2426,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxPerTuple() const */ void MEDCouplingFieldDouble::changeNbOfComponents(int newNbOfComp, double dftValue) { - _time_discr->changeNbOfComponents(newNbOfComp,dftValue); + timeDiscr()->changeNbOfComponents(newNbOfComp,dftValue); } /*! @@ -2712,8 +2445,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std { if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform keepSelectedComponents !"); - MEDCouplingTimeDiscretization *td=_time_discr->keepSelectedComponents(compoIds); - td->copyTinyAttrFrom(*_time_discr); + MEDCouplingTimeDiscretization *td=timeDiscr()->keepSelectedComponents(compoIds); + td->copyTinyAttrFrom(*timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName(getName()); ret->setMesh(getMesh()); @@ -2734,7 +2467,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std */ void MEDCouplingFieldDouble::setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector& compoIds) { - _time_discr->setSelectedComponents(f->_time_discr,compoIds); + timeDiscr()->setSelectedComponents(f->timeDiscr(),compoIds); } /*! @@ -2745,7 +2478,7 @@ void MEDCouplingFieldDouble::setSelectedComponents(const MEDCouplingFieldDouble */ void MEDCouplingFieldDouble::sortPerTuple(bool asc) { - _time_discr->sortPerTuple(asc); + timeDiscr()->sortPerTuple(asc); } /*! @@ -2771,12 +2504,12 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFie if(!f1->areCompatibleForMerge(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MergeFields on them ! Check support mesh, field nature, and spatial and time discretisation."); const MEDCouplingMesh *m1(f1->getMesh()),*m2(f2->getMesh()); - if(!f1->_time_discr) + if(!f1->timeDiscr()) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no time discr of f1 !"); if(!f1->_type) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no spatial discr of f1 !"); - MEDCouplingTimeDiscretization *td=f1->_time_discr->aggregate(f2->_time_discr); - td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingTimeDiscretization *td=f1->timeDiscr()->aggregate(f2->timeDiscr()); + td->copyTinyAttrFrom(*f1->timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setName(f1->getName()); ret->setDescription(f1->getDescription()); @@ -2827,10 +2560,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vectorgetMesh()->buildUnstructured(); ms2[i]=ms[i]; } else { ms[i]=0; ms2[i]=0; } - tds[i]=a[i]->_time_discr; + tds[i]=a[i]->timeDiscr(); } MEDCouplingTimeDiscretization *td=tds[0]->aggregate(tds); - td->copyTinyAttrFrom(*(a[0]->_time_discr)); + td->copyTinyAttrFrom(*(a[0]->timeDiscr())); MCAuto ret=new MEDCouplingFieldDouble(a[0]->getNature(),td,a[0]->_type->clone()); ret->setName(a[0]->getName()); ret->setDescription(a[0]->getDescription()); @@ -2862,8 +2595,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MeldFields(const MEDCouplingFiel { if(!f1->areCompatibleForMeld(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MeldFields on them ! Check support mesh, field nature, and spatial and time discretisation."); - MEDCouplingTimeDiscretization *td=f1->_time_discr->meld(f2->_time_discr); - td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingTimeDiscretization *td=f1->timeDiscr()->meld(f2->timeDiscr()); + td->copyTinyAttrFrom(*f1->timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); @@ -2889,8 +2622,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::DotFields(const MEDCouplingField throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DotFields : input field is NULL !"); if(!f1->areStrictlyCompatibleForMulDiv(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply DotFields on them! Check support mesh, and spatial and time discretisation."); - MEDCouplingTimeDiscretization *td=f1->_time_discr->dot(f2->_time_discr); - td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingTimeDiscretization *td=f1->timeDiscr()->dot(f2->timeDiscr()); + td->copyTinyAttrFrom(*f1->timeDiscr()); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret; @@ -2920,8 +2653,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::CrossProductFields(const MEDCoup throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::CrossProductFields : input field is NULL !"); if(!f1->areStrictlyCompatibleForMulDiv(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply CrossProductFields on them! Check support mesh, and spatial and time discretisation."); - MEDCouplingTimeDiscretization *td=f1->_time_discr->crossProduct(f2->_time_discr); - td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingTimeDiscretization *td=f1->timeDiscr()->crossProduct(f2->timeDiscr()); + td->copyTinyAttrFrom(*f1->timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); @@ -2950,8 +2683,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MaxFields(const MEDCouplingField throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MaxFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MaxFields on them! Check support mesh, field nature, and spatial and time discretisation."); - MEDCouplingTimeDiscretization *td=f1->_time_discr->max(f2->_time_discr); - td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingTimeDiscretization *td=f1->timeDiscr()->max(f2->timeDiscr()); + td->copyTinyAttrFrom(*f1->timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); @@ -2980,8 +2713,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MinFields(const MEDCouplingField throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MinFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MinFields on them! Check support mesh, field nature, and spatial and time discretisation."); - MEDCouplingTimeDiscretization *td=f1->_time_discr->min(f2->_time_discr); - td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingTimeDiscretization *td=f1->timeDiscr()->min(f2->timeDiscr()); + td->copyTinyAttrFrom(*f1->timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); @@ -3000,8 +2733,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::negate() const { if(!((const MEDCouplingFieldDiscretization *)_type)) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform negate !"); - MEDCouplingTimeDiscretization *td=_time_discr->negate(); - td->copyTinyAttrFrom(*_time_discr); + MEDCouplingTimeDiscretization *td=timeDiscr()->negate(); + td->copyTinyAttrFrom(*timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setMesh(getMesh()); return ret.retn(); @@ -3026,8 +2759,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::AddFields(const MEDCouplingField throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::AddFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply AddFields on them! Check support mesh, field nature, and spatial and time discretisation."); - MEDCouplingTimeDiscretization *td=f1->_time_discr->add(f2->_time_discr); - td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingTimeDiscretization *td=f1->timeDiscr()->add(f2->timeDiscr()); + td->copyTinyAttrFrom(*f1->timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); @@ -3047,7 +2780,7 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCoupli { if(!areStrictlyCompatible(&other)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply += on them! Check support mesh, field nature, and spatial and time discretisation."); - _time_discr->addEqual(other._time_discr); + timeDiscr()->addEqual(other.timeDiscr()); return *this; } @@ -3070,8 +2803,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::SubstractFields(const MEDCouplin throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::SubstractFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply SubstractFields on them! Check support mesh, field nature, and spatial and time discretisation."); - MEDCouplingTimeDiscretization *td=f1->_time_discr->substract(f2->_time_discr); - td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingTimeDiscretization *td=f1->timeDiscr()->substract(f2->timeDiscr()); + td->copyTinyAttrFrom(*f1->timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); @@ -3091,7 +2824,7 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCoupli { if(!areStrictlyCompatible(&other)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply -= on them! Check support mesh, field nature, and spatial and time discretisation."); - _time_discr->substractEqual(other._time_discr); + timeDiscr()->substractEqual(other.timeDiscr()); return *this; } @@ -3121,8 +2854,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MultiplyFields(const MEDCoupling throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MultiplyFields : input field is NULL !"); if(!f1->areCompatibleForMul(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MultiplyFields on them! Check support mesh, and spatial and time discretisation."); - MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr); - td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingTimeDiscretization *td=f1->timeDiscr()->multiply(f2->timeDiscr()); + td->copyTinyAttrFrom(*f1->timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); @@ -3153,7 +2886,7 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCoupli { if(!areCompatibleForMul(&other)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply *= on them! Check support mesh, and spatial and time discretisation."); - _time_discr->multiplyEqual(other._time_discr); + timeDiscr()->multiplyEqual(other.timeDiscr()); _nature = NoNature; return *this; } @@ -3182,8 +2915,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::DivideFields(const MEDCouplingFi throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DivideFields : input field is NULL !"); if(!f1->areCompatibleForDiv(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply DivideFields on them! Check support mesh, and spatial and time discretisation."); - MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr); - td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingTimeDiscretization *td=f1->timeDiscr()->divide(f2->timeDiscr()); + td->copyTinyAttrFrom(*f1->timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); @@ -3210,7 +2943,7 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCoupli { if(!areCompatibleForDiv(&other)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply /= on them! Check support mesh, and spatial and time discretisation."); - _time_discr->divideEqual(other._time_discr); + timeDiscr()->divideEqual(other.timeDiscr()); _nature = NoNature; return *this; } @@ -3226,8 +2959,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::PowFields(const MEDCouplingField throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::PowFields : input field is NULL !"); if(!f1->areCompatibleForMul(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply PowFields on them! Check support mesh, and spatial and time discretisation."); - MEDCouplingTimeDiscretization *td=f1->_time_discr->pow(f2->_time_discr); - td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingTimeDiscretization *td=f1->timeDiscr()->pow(f2->timeDiscr()); + td->copyTinyAttrFrom(*f1->timeDiscr()); MCAuto ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); @@ -3247,7 +2980,7 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCoupli { if(!areCompatibleForDiv(&other)) throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply ^= on them! Check support mesh, and spatial and time discretisation."); - _time_discr->powEqual(other._time_discr); + timeDiscr()->powEqual(other.timeDiscr()); _nature = NoNature; return *this; } @@ -3297,7 +3030,7 @@ std::string MEDCouplingFieldDouble::WriteVTK(const std::string& fileName, const if(name.empty()) { std::ostringstream oss; oss << "MEDCouplingFieldDouble::WriteVTK : Field in pos #" << i << " has no name !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } TypeOfField typ=cur->getTypeOfField(); if(typ==ON_CELLS) @@ -3311,43 +3044,24 @@ std::string MEDCouplingFieldDouble::WriteVTK(const std::string& fileName, const return ret; } -void MEDCouplingFieldDouble::reprQuickOverview(std::ostream& stream) const -{ - stream << "MEDCouplingFieldDouble C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl; - const char *nat=0; - try - { - nat=MEDCouplingNatureOfField::GetRepr(_nature); - stream << "Nature of field : " << nat << ".\n"; - } - catch(INTERP_KERNEL::Exception& /*e*/) - { } - const MEDCouplingFieldDiscretization *fd(_type); - if(!fd) - stream << "No spatial discretization set !"; - else - fd->reprQuickOverview(stream); - stream << std::endl; - if(!_mesh) - stream << "\nNo mesh support defined !"; - else - { - std::ostringstream oss; - _mesh->reprQuickOverview(oss); - std::string tmp(oss.str()); - stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n')); - } - if(_time_discr) - { - const DataArrayDouble *arr=_time_discr->getArray(); - if(arr) - { - stream << "\n\nArray info : "; - arr->reprQuickOverview(stream); - } - else - { - stream << "\n\nNo data array set !"; - } - } +MEDCouplingTimeDiscretization *MEDCouplingFieldDouble::timeDiscr() +{ + MEDCouplingTimeDiscretizationTemplate *ret(_time_discr); + if(!ret) + return 0; + MEDCouplingTimeDiscretization *retc(dynamic_cast(ret)); + if(!retc) + throw INTERP_KERNEL::Exception("Field Double Null invalid type of time discr !"); + return retc; +} + +const MEDCouplingTimeDiscretization *MEDCouplingFieldDouble::timeDiscr() const +{ + const MEDCouplingTimeDiscretizationTemplate *ret(_time_discr); + if(!ret) + return 0; + const MEDCouplingTimeDiscretization *retc(dynamic_cast(ret)); + if(!retc) + throw INTERP_KERNEL::Exception("Field Double Null invalid type of time discr !"); + return retc; } diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 0e9ab5d37..4012646c4 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -18,38 +18,27 @@ // // Author : Anthony Geay (CEA/DEN) -#ifndef __PARAMEDMEM_MEDCOUPLINGFIELDDOUBLE_HXX__ -#define __PARAMEDMEM_MEDCOUPLINGFIELDDOUBLE_HXX__ +#ifndef __MEDCOUPLINGFIELDDOUBLE_HXX__ +#define __MEDCOUPLINGFIELDDOUBLE_HXX__ #include "MEDCoupling.hxx" -#include "MEDCouplingField.hxx" -#include "MEDCouplingTimeDiscretization.hxx" +#include "MEDCouplingFieldT.hxx" #include "MEDCouplingMemArray.hxx" namespace MEDCoupling { + class MEDCouplingFieldInt; class MEDCouplingFieldTemplate; - class MEDCouplingFieldDouble : public MEDCouplingField + class MEDCouplingFieldDouble : public MEDCouplingFieldT { 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); - MEDCOUPLING_EXPORT void copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other); - MEDCOUPLING_EXPORT std::string simpleRepr() const; MEDCOUPLING_EXPORT std::string advancedRepr() const; MEDCOUPLING_EXPORT std::string writeVTK(const std::string& fileName, bool isBinary=true) 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 bool areCompatibleForMerge(const MEDCouplingField *other) const; - MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingField *other) const; - MEDCOUPLING_EXPORT bool areCompatibleForMul(const MEDCouplingField *other) const; - MEDCOUPLING_EXPORT bool areCompatibleForDiv(const MEDCouplingField *other) const; MEDCOUPLING_EXPORT bool areCompatibleForMeld(const MEDCouplingFieldDouble *other) const; MEDCOUPLING_EXPORT void renumberCells(const int *old2NewBg, bool check=true); MEDCOUPLING_EXPORT void renumberCellsWithoutMesh(const int *old2NewBg, bool check=true); @@ -61,38 +50,11 @@ 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 MEDCouplingFieldInt *convertToIntField() const; 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; @@ -194,18 +156,17 @@ namespace MEDCoupling MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); MEDCOUPLING_EXPORT static std::string WriteVTK(const std::string& fileName, const std::vector& fs, bool isBinary=true); public: - MEDCOUPLING_EXPORT const MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() const { return _time_discr; } - MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() { return _time_discr; } - MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; + MEDCOUPLING_EXPORT const MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() const { return timeDiscr(); } + MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() { return timeDiscr(); } protected: - ~MEDCouplingFieldDouble(); + ~MEDCouplingFieldDouble() { } private: MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td); MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td); MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy); MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type); - private: - MEDCouplingTimeDiscretization *_time_discr; + MEDCouplingTimeDiscretization *timeDiscr(); + const MEDCouplingTimeDiscretization *timeDiscr() const; }; } diff --git a/src/MEDCoupling/MEDCouplingFieldInt.cxx b/src/MEDCoupling/MEDCouplingFieldInt.cxx index aab9a45f1..f6b6fa297 100644 --- a/src/MEDCoupling/MEDCouplingFieldInt.cxx +++ b/src/MEDCoupling/MEDCouplingFieldInt.cxx @@ -19,11 +19,15 @@ // Author : Yann Pora (EDF R&D) #include "MEDCouplingFieldInt.hxx" +#include "MEDCouplingFieldT.txx" +#include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingMesh.hxx" using namespace MEDCoupling; +template class MEDCouplingFieldT; + MEDCouplingFieldInt *MEDCouplingFieldInt::New(TypeOfField type, TypeOfTimeDiscretization td) { return new MEDCouplingFieldInt(type,td); @@ -34,109 +38,46 @@ MEDCouplingFieldInt *MEDCouplingFieldInt::New(const MEDCouplingFieldTemplate& ft return new MEDCouplingFieldInt(ft,td); } -void MEDCouplingFieldInt::checkConsistencyLight() const -{ - MEDCouplingField::checkConsistencyLight(); - _time_discr->checkConsistencyLight(); - _type->checkCoherencyBetween(_mesh,getArray()); -} - -std::string MEDCouplingFieldInt::simpleRepr() const -{ - std::ostringstream ret; - ret << "FieldInt with name : \"" << getName() << "\"\n"; - ret << "Description of field is : \"" << getDescription() << "\"\n"; - if(_type) - { ret << "FieldInt space discretization is : " << _type->getStringRepr() << "\n"; } - else - { ret << "FieldInt has no spatial discretization !\n"; } - if(_time_discr) - { ret << "FieldInt time discretization is : " << _time_discr->getStringRepr() << "\n"; } - else - { ret << "FieldInt has no time discretization !\n"; } - ret << "FieldInt nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n"; - if(getArray()) - { - if(getArray()->isAllocated()) - { - int nbOfCompo=getArray()->getNumberOfComponents(); - ret << "FieldInt default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; - ret << "FieldInt default array has following info on components : "; - for(int i=0;igetInfoOnComponent(i) << "\" "; - ret << "\n"; - } - else - { - ret << "Array set but not allocated !\n"; - } - } - if(_mesh) - ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr(); - else - ret << "Mesh support information : No mesh set !\n"; - return ret.str(); -} - -void MEDCouplingFieldInt::reprQuickOverview(std::ostream& stream) const -{ -} - -void MEDCouplingFieldInt::setTimeUnit(const std::string& unit) -{ - _time_discr->setTimeUnit(unit); -} - -std::string MEDCouplingFieldInt::getTimeUnit() const -{ - return _time_discr->getTimeUnit(); -} - -void MEDCouplingFieldInt::setTime(double val, int iteration, int order) -{ - _time_discr->setTime(val,iteration,order); -} - -double MEDCouplingFieldInt::getTime(int& iteration, int& order) const -{ - return _time_discr->getTime(iteration,order); -} - -void MEDCouplingFieldInt::setArray(DataArrayInt *array) -{ - _time_discr->setArray(array,this); -} - -const DataArrayInt *MEDCouplingFieldInt::getArray() const +MEDCouplingFieldInt::MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingFieldT(type,MEDCouplingTimeDiscretizationInt::New(td)) { - return _time_discr->getArray(); } -DataArrayInt *MEDCouplingFieldInt::getArray() +MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy):MEDCouplingFieldT(other,deepCopy) { - return _time_discr->getArray(); } -MEDCouplingFieldInt::MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type),_time_discr(MEDCouplingTimeDiscretizationInt::New(td)) +MEDCouplingFieldInt::MEDCouplingFieldInt(NatureOfField n, MEDCouplingTimeDiscretizationInt *td, MEDCouplingFieldDiscretization *type):MEDCouplingFieldT(type,n,td) { } -MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy):MEDCouplingField(other,deepCopy),_time_discr(dynamic_cast(other._time_discr->performCopyOrIncrRef(deepCopy))) +/*! + * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! ** + */ +MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingFieldT(ft,MEDCouplingTimeDiscretizationInt::New(td),false) { } -MEDCouplingFieldInt::MEDCouplingFieldInt(NatureOfField n, MEDCouplingTimeDiscretizationInt *td, MEDCouplingFieldDiscretization *type):MEDCouplingField(type,n),_time_discr(td) +MEDCouplingFieldInt *MEDCouplingFieldInt::deepCopy() const { + return cloneWithMesh(true); } -MEDCouplingFieldInt::~MEDCouplingFieldInt() +MEDCouplingFieldInt *MEDCouplingFieldInt::clone(bool recDeepCpy) const { - delete _time_discr; + return new MEDCouplingFieldInt(*this,recDeepCpy); } -/*! - * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! ** - */ -MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingField(ft,false),_time_discr(MEDCouplingTimeDiscretizationInt::New(td)) +MEDCouplingFieldDouble *MEDCouplingFieldInt::convertToDblField() const { + MCAuto tmp(MEDCouplingFieldTemplate::New(*this)); + int t1,t2; + double t0(getTime(t1,t2)); + MCAuto ret(MEDCouplingFieldDouble::New(*tmp,getTimeDiscretization())); + ret->setTime(t0,t1,t2); + if(getArray()) + { + MCAuto arr(getArray()->convertToDblArr()); + ret->setArray(arr); + } + return ret.retn(); } diff --git a/src/MEDCoupling/MEDCouplingFieldInt.hxx b/src/MEDCoupling/MEDCouplingFieldInt.hxx index 71dbda7bf..60ab3dead 100644 --- a/src/MEDCoupling/MEDCouplingFieldInt.hxx +++ b/src/MEDCoupling/MEDCouplingFieldInt.hxx @@ -22,39 +22,30 @@ #define __MEDCOUPLINGFIELDINT_HXX__ #include "MEDCoupling.hxx" -#include "MEDCouplingField.hxx" -#include "MEDCouplingTimeDiscretization.hxx" +#include "MEDCouplingFieldT.hxx" #include "MEDCouplingMemArray.hxx" #include namespace MEDCoupling { + class MEDCouplingFieldDouble; class MEDCouplingFieldTemplate; - class MEDCouplingFieldInt : public MEDCouplingField + class MEDCouplingFieldInt : public MEDCouplingFieldT { 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 MEDCouplingFieldDouble *convertToDblField() const; protected: MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td); MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy); MEDCouplingFieldInt(NatureOfField n, MEDCouplingTimeDiscretizationInt *td, MEDCouplingFieldDiscretization *type); MEDCouplingFieldInt(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td); - ~MEDCouplingFieldInt(); - private: - MEDCouplingTimeDiscretizationInt *_time_discr; + ~MEDCouplingFieldInt() { } }; } diff --git a/src/MEDCoupling/MEDCouplingFieldT.hxx b/src/MEDCoupling/MEDCouplingFieldT.hxx new file mode 100644 index 000000000..66f7843e9 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingFieldT.hxx @@ -0,0 +1,92 @@ +// Copyright (C) 2016 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (EDF R&D) + +#ifndef __MEDCOUPLINGFIELDT_HXX__ +#define __MEDCOUPLINGFIELDT_HXX__ + +#include "MEDCouplingField.hxx" +#include "MEDCouplingTraits.hxx" +#include "MEDCouplingTimeDiscretization.hxx" + +#include + +namespace MEDCoupling +{ + template + class MEDCouplingTimeDiscretizationTemplate; + + template + class MEDCouplingFieldT : public MEDCouplingField + { + protected: + MEDCouplingFieldT(const MEDCouplingFieldT& other, bool deepCopy); + MEDCouplingFieldT(const MEDCouplingField& other, MEDCouplingTimeDiscretizationTemplate *timeDiscr, bool deepCopy=true); + MEDCouplingFieldT(TypeOfField type, MEDCouplingTimeDiscretizationTemplate *timeDiscr); + MEDCouplingFieldT(MEDCouplingFieldDiscretization *type, NatureOfField n, MEDCouplingTimeDiscretizationTemplate *timeDiscr); + ~MEDCouplingFieldT(); + public: + MEDCOUPLING_EXPORT TypeOfTimeDiscretization getTimeDiscretization() const; + 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); } + 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); + MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingField *other) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const; + MEDCOUPLING_EXPORT std::string simpleRepr() const; + MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; + // specific + MEDCOUPLING_EXPORT bool areCompatibleForMul(const MEDCouplingField *other) const; + MEDCOUPLING_EXPORT bool areCompatibleForDiv(const MEDCouplingField *other) const; + MEDCOUPLING_EXPORT void copyTinyAttrFrom(const MEDCouplingFieldT *other); + MEDCOUPLING_EXPORT void copyAllTinyAttrFrom(const MEDCouplingFieldT *other); + protected: + MEDCouplingTimeDiscretizationTemplate *_time_discr; + }; +} + +#endif diff --git a/src/MEDCoupling/MEDCouplingFieldT.txx b/src/MEDCoupling/MEDCouplingFieldT.txx new file mode 100644 index 000000000..6df99f351 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingFieldT.txx @@ -0,0 +1,372 @@ +// Copyright (C) 2016 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (EDF R&D) + +#ifndef __MEDCOUPLINGFIELDT_TXX__ +#define __MEDCOUPLINGFIELDT_TXX__ + +#include "MEDCouplingTimeDiscretization.hxx" +#include "MEDCouplingMesh.hxx" + +namespace MEDCoupling +{ + template + 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) + { + } + + template + MEDCouplingFieldT::MEDCouplingFieldT(TypeOfField type, MEDCouplingTimeDiscretizationTemplate *timeDiscr):MEDCouplingField(type),_time_discr(timeDiscr) + { + } + + template + MEDCouplingFieldT::MEDCouplingFieldT(MEDCouplingFieldDiscretization *type, NatureOfField n, MEDCouplingTimeDiscretizationTemplate *timeDiscr):MEDCouplingField(type,n),_time_discr(timeDiscr) + { + } + + template + MEDCouplingFieldT::~MEDCouplingFieldT() + { + 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(); + } + + template + bool MEDCouplingFieldT::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const + { + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingFieldT::isEqualIfNotWhy : other instance is NULL !"); + const MEDCouplingFieldT *otherC(dynamic_cast *>(other)); + if(!otherC) + { + reason="field given in input is not castable in MEDCouplingFieldT !"; + return false; + } + if(!MEDCouplingField::isEqualIfNotWhy(other,meshPrec,valsPrec,reason)) + return false; + if(!_time_discr->isEqualIfNotWhy(otherC->_time_discr,T(valsPrec),reason)) + { + reason.insert(0,"In FieldT time discretizations differ :"); + return false; + } + return true; + } + + /*! + * Checks equality of \a this and \a other field. Only numeric data is considered, + * i.e. names, description etc are not compared. + * \param [in] other - the field to compare with. + * \param [in] meshPrec - a precision used to compare node coordinates of meshes. + * \param [in] valsPrec - a precision used to compare data arrays of the two fields. + * \return bool - \c true if the two fields are equal, \c false else. + * \throw If \a other == NULL. + * \throw If the spatial discretization of \a this field is NULL. + */ + template + bool MEDCouplingFieldT::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const + { + const MEDCouplingFieldT *otherC(dynamic_cast *>(other)); + if(!otherC) + return false; + if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec)) + return false; + if(!_time_discr->isEqualWithoutConsideringStr(otherC->_time_discr,T(valsPrec))) + return false; + return true; + } + + /*! + * Copies tiny info (component names, name and description) from an \a other field to + * \a this one. + * \warning The underlying mesh is not renamed (for safety reason). + * \param [in] other - the field to copy the tiny info from. + * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents() + */ + template + void MEDCouplingFieldT::copyTinyStringsFrom(const MEDCouplingField *other) + { + MEDCouplingField::copyTinyStringsFrom(other); + const MEDCouplingFieldT *otherC(dynamic_cast *>(other)); + if(otherC) + { + _time_discr->copyTinyStringsFrom(*otherC->_time_discr); + } + } + + /*! + * Copies only times, order and iteration from an \a other field to + * \a this one. The underlying mesh is not impacted by this method. + * Arrays are not impacted neither. + * \param [in] other - the field to tiny attributes from. + * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents() + */ + template + void MEDCouplingFieldT::copyTinyAttrFrom(const MEDCouplingFieldT *other) + { + if(other) + { + _time_discr->copyTinyAttrFrom(*other->_time_discr); + } + } + + template + void MEDCouplingFieldT::copyAllTinyAttrFrom(const MEDCouplingFieldT *other) + { + copyTinyStringsFrom(other); + copyTinyAttrFrom(other); + } + + /*! + * This method is more strict than MEDCouplingField::areCompatibleForMerge method. + * This method is used for operation on fields to operate a first check before attempting operation. + */ + template + bool MEDCouplingFieldT::areStrictlyCompatible(const MEDCouplingField *other) const + { + std::string tmp; + if(!MEDCouplingField::areStrictlyCompatible(other)) + return false; + const MEDCouplingFieldT *otherC(dynamic_cast *>(other)); + if(!otherC) + return false; + if(!_time_discr->areStrictlyCompatible(otherC->_time_discr,tmp)) + return false; + return true; + } + + template + bool MEDCouplingFieldT::areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const + { + if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other)) + return false; + const MEDCouplingFieldT *otherC(dynamic_cast *>(other)); + if(!otherC) + return false; + if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr)) + return false; + return true; + } + + /*! + * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatibleForMulDiv method except that + * number of components between \a this and 'other' can be different here (for operator/). + */ + template + bool MEDCouplingFieldT::areCompatibleForDiv(const MEDCouplingField *other) const + { + if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other)) + return false; + const MEDCouplingFieldT *otherC(dynamic_cast *>(other)); + if(!otherC) + return false; + if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr)) + return false; + return true; + } + + template + bool MEDCouplingFieldT::areCompatibleForMul(const MEDCouplingField *other) const + { + if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other)) + return false; + const MEDCouplingFieldT *otherC(dynamic_cast *>(other)); + if(!otherC) + return false; + if(!_time_discr->areStrictlyCompatibleForMul(otherC->_time_discr)) + return false; + return true; + } + + /*! + * Returns a string describing \a this field. This string is outputted by \c print + * Python command. The string includes info on + * - name, + * - description, + * - \ref MEDCouplingSpatialDisc "spatial discretization", + * - \ref MEDCouplingTemporalDisc "time discretization", + * - \ref NatureOfField, + * - components, + * - mesh. + * + * \return std::string - the string describing \a this field. + */ + template + std::string MEDCouplingFieldT::simpleRepr() const + { + std::ostringstream ret; + ret << Traits::FieldTypeName << " with name : \"" << getName() << "\"\n"; + ret << "Description of field is : \"" << getDescription() << "\"\n"; + if(_type) + { ret << Traits::FieldTypeName << " space discretization is : " << _type->getStringRepr() << "\n"; } + else + { ret << Traits::FieldTypeName << " has no spatial discretization !\n"; } + if(_time_discr) + { ret << Traits::FieldTypeName << " time discretization is : " << _time_discr->getStringRepr() << "\n"; } + else + { ret << Traits::FieldTypeName << " has no time discretization !\n"; } + ret << Traits::FieldTypeName << " nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n"; + if(getArray()) + { + if(getArray()->isAllocated()) + { + int nbOfCompo=getArray()->getNumberOfComponents(); + ret << Traits::FieldTypeName << " default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; + ret << Traits::FieldTypeName << " default array has following info on components : "; + for(int i=0;igetInfoOnComponent(i) << "\" "; + ret << "\n"; + } + else + { + ret << "Array set but not allocated !\n"; + } + } + if(_mesh) + ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr(); + else + ret << "Mesh support information : No mesh set !\n"; + return ret.str(); + } + + template + void MEDCouplingFieldT::reprQuickOverview(std::ostream& stream) const + { + stream << Traits::FieldTypeName << " C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl; + const char *nat(0); + try + { + nat=MEDCouplingNatureOfField::GetRepr(_nature); + stream << "Nature of field : " << nat << ".\n"; + } + catch(INTERP_KERNEL::Exception& e) + { } + const MEDCouplingFieldDiscretization *fd(_type); + if(!fd) + stream << "No spatial discretization set !"; + else + fd->reprQuickOverview(stream); + stream << std::endl; + if(!_mesh) + stream << "\nNo mesh support defined !"; + else + { + std::ostringstream oss; + _mesh->reprQuickOverview(oss); + std::string tmp(oss.str()); + stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n')); + } + if(_time_discr) + { + const typename Traits::ArrayType *arr(_time_discr->getArray()); + if(arr) + { + stream << "\n\nArray info : "; + arr->reprQuickOverview(stream); + } + else + { + stream << "\n\nNo data array set !"; + } + } + } + + /*! + * Returns a type of \ref MEDCouplingTemporalDisc "time discretization" of \a this field. + * \return MEDCoupling::TypeOfTimeDiscretization - an enum item describing the time + * discretization type. + */ + template + TypeOfTimeDiscretization MEDCouplingFieldT::getTimeDiscretization() const + { + return _time_discr->getEnum(); + } +} + +#endif diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index db9a43ade..dd334c4eb 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -80,13 +80,13 @@ bool MEDCouplingTimeDiscretization::areCompatibleForMeld(const MEDCouplingTimeDi return true; } -bool MEDCouplingTimeDiscretization::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const +bool MEDCouplingTimeDiscretization::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const { if(!areStrictlyCompatible(other,reason)) return false; - if(_array==other->_array) + if(_array==other->getArray()) return true; - return _array->isEqualIfNotWhy(*other->_array,prec,reason); + return _array->isEqualIfNotWhy(*other->getArray(),prec,reason); } bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const @@ -95,14 +95,14 @@ bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization return isEqualIfNotWhy(other,prec,reason); } -bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +bool MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const { std::string tmp; if(!areStrictlyCompatible(other,tmp)) return false; - if(_array==other->_array) + if(_array==other->getArray()) return true; - return _array->isEqualWithoutConsideringStr(*other->_array,prec); + return _array->isEqualWithoutConsideringStr(*other->getArray(),prec); } MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::buildNewTimeReprFromThis(TypeOfTimeDiscretization type, bool deepCopy) const @@ -184,34 +184,6 @@ void MEDCouplingTimeDiscretization::getTinySerializationStrInformation(std::vect tinyInfo.push_back(_array->getInfoOnComponent(i)); } -const DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray() const -{ - throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !"); -} - -DataArrayDouble *MEDCouplingTimeDiscretization::getEndArray() -{ - throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !"); -} - -void MEDCouplingTimeDiscretization::setEndArray(DataArrayDouble *array, TimeLabel *owner) -{ - throw INTERP_KERNEL::Exception("setEndArray not available for this type of time discretization !"); -} - -void MEDCouplingTimeDiscretization::setArrays(const std::vector& arrays, TimeLabel *owner) -{ - if(arrays.size()!=1) - throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretization::setArrays : number of arrays must be one."); - setArray(arrays.back(),owner); -} - -void MEDCouplingTimeDiscretization::getArrays(std::vector& arrays) const -{ - arrays.resize(1); - arrays[0]=_array; -} - bool MEDCouplingTimeDiscretization::isBefore(const MEDCouplingTimeDiscretization *other) const { int iteration,order; @@ -805,7 +777,7 @@ MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt() { } -MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate(other,deepCopy) +MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate(other,deepCopy),_tk(other._tk) { } @@ -833,6 +805,69 @@ MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::New(TypeOfTi } } +bool MEDCouplingTimeDiscretizationInt::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, int prec, std::string& reason) const +{ + if(prec!=0) + throw INTERP_KERNEL::Exception("isEqualIfNotWhy : only precision equal to 0 supported for int !"); + if(!other) + { + reason="Time discretization is NULL."; + return false; + } + const MEDCouplingTimeDiscretizationInt *otherC(dynamic_cast(other)); + if(!otherC) + throw INTERP_KERNEL::Exception("isEqualIfNotWhy : other is not a MEDCouplingTimeDiscretizationInt !"); + if(!MEDCouplingTimeDiscretizationTemplate::areStrictlyCompatible(other,reason)) + return false; + if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) + return false; + if(_array==other->getArray()) + return true; + return _array->isEqualIfNotWhy(*other->getArray(),reason); +} + +bool MEDCouplingTimeDiscretizationInt::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, int prec) const +{ + if(prec!=0) + throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretizationInt::isEqualWithoutConsideringStr : only precision 0 is supported !"); + const MEDCouplingTimeDiscretizationInt *otherC(dynamic_cast(other)); + if(!otherC) + throw INTERP_KERNEL::Exception("isEqualWithoutConsideringStr : other is not a MEDCouplingTimeDiscretizationInt !"); + std::string tmp; + if(!areStrictlyCompatible(other,tmp)) + return false; + std::string reason; + if(!_tk.isEqualIfNotWhy(otherC->_tk,_time_tolerance,reason)) + return false; + if(_array==other->getArray()) + return true; + return _array->isEqualWithoutConsideringStr(*(other->getArray())); +} + +double MEDCouplingTimeDiscretizationInt::getEndTime(int& iteration, int& order) const +{ + throw INTERP_KERNEL::Exception("getEndTime : invalid for this type of time discr !"); +} + +void MEDCouplingTimeDiscretizationInt::setEndIteration(int it) +{ + throw INTERP_KERNEL::Exception("setEndIteration : invalid for this type of time discr !"); +} + +void MEDCouplingTimeDiscretizationInt::setEndOrder(int order) +{ + throw INTERP_KERNEL::Exception("setEndOrder : invalid for this type of time discr !"); +} + +void MEDCouplingTimeDiscretizationInt::setEndTimeValue(double time) +{ + throw INTERP_KERNEL::Exception("setEndTimeValue : invalid for this type of time discr !"); +} + +void MEDCouplingTimeDiscretizationInt::setEndTime(double time, int iteration, int order) +{ + throw INTERP_KERNEL::Exception("setEndTime : invalid for this type of time discr !"); +} //////////////////////// @@ -861,7 +896,7 @@ bool MEDCouplingNoTimeLabel::areCompatible(const MEDCouplingTimeDiscretizationTe { if(!MEDCouplingTimeDiscretization::areCompatible(other)) return false; - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); return otherC!=0; } @@ -869,7 +904,7 @@ bool MEDCouplingNoTimeLabel::areStrictlyCompatible(const MEDCouplingTimeDiscreti { if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other,reason)) return false; - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); bool ret=otherC!=0; if(!ret) reason.insert(0,"time discretization of this is NO_TIME, other has a different time discretization."); @@ -880,7 +915,7 @@ bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDi { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other)) return false; - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); return otherC!=0; } @@ -888,7 +923,7 @@ bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDi { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) return false; - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); return otherC!=0; } @@ -896,13 +931,13 @@ bool MEDCouplingNoTimeLabel::areCompatibleForMeld(const MEDCouplingTimeDiscretiz { if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other)) return false; - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); return otherC!=0; } -bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const +bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const { - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); if(!otherC) { reason="This has time discretization NO_TIME, other not."; @@ -911,9 +946,9 @@ bool MEDCouplingNoTimeLabel::isEqualIfNotWhy(const MEDCouplingTimeDiscretization return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason); } -bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const { - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); if(!otherC) return false; return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); @@ -921,11 +956,11 @@ bool MEDCouplingNoTimeLabel::isEqualWithoutConsideringStr(const MEDCouplingTimeD MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const MEDCouplingTimeDiscretization *other) const { - const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + const MEDCouplingNoTimeLabel *otherC(dynamic_cast(other)); if(!otherC) throw INTERP_KERNEL::Exception("NoTimeLabel::aggregation on mismatched time discretization !"); - MCAuto arr=DataArrayDouble::Aggregate(getArray(),other->getArray()); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + MCAuto arr(DataArrayDouble::Aggregate(getArray(),other->getArray())); + MEDCouplingNoTimeLabel *ret(new MEDCouplingNoTimeLabel); ret->setArray(arr,0); return ret; } @@ -941,8 +976,8 @@ MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::aggregate(const std::vect throw INTERP_KERNEL::Exception("NoTimeLabel::aggregate on mismatched time discretization !"); a[i]=itC->getArray(); } - MCAuto arr=DataArrayDouble::Aggregate(a); - MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + MCAuto arr(DataArrayDouble::Aggregate(a)); + MEDCouplingNoTimeLabel *ret(new MEDCouplingNoTimeLabel); ret->setArray(arr,0); return ret; } @@ -1347,7 +1382,7 @@ bool MEDCouplingWithTimeStep::areCompatibleForMeld(const MEDCouplingTimeDiscreti return otherC!=0; } -bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const +bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const { const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); std::ostringstream oss; oss.precision(15); @@ -1361,7 +1396,7 @@ bool MEDCouplingWithTimeStep::isEqualIfNotWhy(const MEDCouplingTimeDiscretizatio return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason); } -bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const { const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); if(!otherC) @@ -1786,7 +1821,7 @@ bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCoupli { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other)) return false; - const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast(other)); return otherC!=0; } @@ -1794,7 +1829,7 @@ bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCoupli { if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) return false; - const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast(other)); return otherC!=0; } @@ -1802,13 +1837,13 @@ bool MEDCouplingConstOnTimeInterval::areCompatibleForMeld(const MEDCouplingTimeD { if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other)) return false; - const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast(other)); return otherC!=0; } -bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const +bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const { - const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast(other)); std::ostringstream oss; oss.precision(15); if(!otherC) { @@ -1822,9 +1857,9 @@ bool MEDCouplingConstOnTimeInterval::isEqualIfNotWhy(const MEDCouplingTimeDiscre return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason); } -bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +bool MEDCouplingConstOnTimeInterval::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const { - const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + const MEDCouplingConstOnTimeInterval *otherC(dynamic_cast(other)); if(!otherC) return false; if(!_start.isEqual(otherC->_start,_time_tolerance)) @@ -2087,9 +2122,7 @@ void MEDCouplingConstOnTimeInterval::powEqual(const MEDCouplingTimeDiscretizatio } MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& other, bool deepCopy):MEDCouplingTimeDiscretization(other,deepCopy), - _start_time(other._start_time),_end_time(other._end_time), - _start_iteration(other._start_iteration),_end_iteration(other._end_iteration), - _start_order(other._start_order),_end_order(other._end_order) + _start(other._start),_end(other._end) { if(other._end_array) _end_array=other._end_array->performCopyOrIncrRef(deepCopy); @@ -2110,8 +2143,8 @@ void MEDCouplingTwoTimeSteps::synchronizeTimeWith(const MEDCouplingMesh *mesh) throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::synchronizeTimeWith : mesh instance is NULL ! Impossible to synchronize time !"); int it=-1,order=-1; double val=mesh->getTime(it,order); - _start_time=val; _start_iteration=it; _start_order=order; - _end_time=val; _end_iteration=it; _end_order=order; + _start.setAllInfo(val,it,order); + _end.setAllInfo(val,it,order); std::string tUnit=mesh->getTimeUnit(); _time_unit=tUnit; } @@ -2134,12 +2167,8 @@ void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretizati const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(&other); if(!otherC) throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::copyTinyAttrFrom : mismatch of time discretization !"); - _start_time=otherC->_start_time; - _end_time=otherC->_end_time; - _start_iteration=otherC->_start_iteration; - _end_iteration=otherC->_end_iteration; - _start_order=otherC->_start_order; - _end_order=otherC->_end_order; + _start.copyFrom(otherC->_start); + _end.copyFrom(otherC->_end); } void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretizationTemplate& other) @@ -2173,51 +2202,19 @@ void MEDCouplingTwoTimeSteps::checkConsistencyLight() const throw INTERP_KERNEL::Exception("The number of tuples mismatch between the start and the end arrays !"); } -bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const +bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const { std::ostringstream oss; - const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(other); + const MEDCouplingTwoTimeSteps *otherC(dynamic_cast(other)); if(!otherC) { reason="This has time discretization LINEAR_TIME, other not."; return false; } - if(_start_iteration!=otherC->_start_iteration) - { - oss << "start iterations differ. this start iteration=" << _start_iteration << " other start iteration=" << otherC->_start_iteration; - reason=oss.str(); - return false; - } - if(_start_order!=otherC->_start_order) - { - oss << "start orders differ. this start order=" << _start_order << " other start order=" << otherC->_start_order; - reason=oss.str(); - return false; - } - if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance) - { - oss << "start times differ. this start time=" << _start_time << " other start time=" << otherC->_start_time; - reason=oss.str(); - return false; - } - if(_end_iteration!=otherC->_end_iteration) - { - oss << "end iterations differ. this end iteration=" << _end_iteration << " other end iteration=" << otherC->_end_iteration; - reason=oss.str(); - return false; - } - if(_end_order!=otherC->_end_order) - { - oss << "end orders differ. this end order=" << _end_order << " other end order=" << otherC->_end_order; - reason=oss.str(); - return false; - } - if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance) - { - oss << "end times differ. this end time=" << _end_time << " other end time=" << otherC->_end_time; - reason=oss.str(); - return false; - } + if(!_start.isEqualIfNotWhy(otherC->_start,_time_tolerance,reason)) + return false; + if(!_end.isEqualIfNotWhy(otherC->_end,_time_tolerance,reason)) + return false; if(_end_array!=otherC->_end_array) if(!_end_array->isEqualIfNotWhy(*otherC->_end_array,prec,reason)) { @@ -2227,22 +2224,14 @@ bool MEDCouplingTwoTimeSteps::isEqualIfNotWhy(const MEDCouplingTimeDiscretizatio return MEDCouplingTimeDiscretization::isEqualIfNotWhy(other,prec,reason); } -bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const +bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const { - const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(other); + const MEDCouplingTwoTimeSteps *otherC(dynamic_cast(other)); if(!otherC) return false; - if(_start_iteration!=otherC->_start_iteration) - return false; - if(_end_iteration!=otherC->_end_iteration) - return false; - if(_start_order!=otherC->_start_order) - return false; - if(_end_order!=otherC->_end_order) - return false; - if(std::fabs(_start_time-otherC->_start_time)>_time_tolerance) + if(!_start.isEqual(otherC->_start,_time_tolerance)) return false; - if(std::fabs(_end_time-otherC->_end_time)>_time_tolerance) + if(!_end.isEqual(otherC->_end,_time_tolerance)) return false; if(_end_array!=otherC->_end_array) if(!_end_array->isEqualWithoutConsideringStr(*otherC->_end_array,prec)) @@ -2250,7 +2239,7 @@ bool MEDCouplingTwoTimeSteps::isEqualWithoutConsideringStr(const MEDCouplingTime return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); } -MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_start_time(0.),_end_time(0.),_start_iteration(-1),_end_iteration(-1),_start_order(-1),_end_order(-1),_end_array(0) +MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps():_end_array(0) { } @@ -2267,10 +2256,10 @@ void MEDCouplingTwoTimeSteps::checkNoTimePresence() const void MEDCouplingTwoTimeSteps::checkTimePresence(double time) const { - if(time<_start_time-_time_tolerance || time>_end_time+_time_tolerance) + if(time<_start.getTimeValue()-_time_tolerance || time>_end.getTimeValue()+_time_tolerance) { std::ostringstream stream; - stream << "The field is defined between times " << _start_time << " and " << _end_time << " worderh tolerance "; + stream << "The field is defined between times " << _start.getTimeValue() << " and " << _end.getTimeValue() << " worderh tolerance "; stream << _time_tolerance << " and trying to access on time = " << time; throw INTERP_KERNEL::Exception(stream.str().c_str()); } @@ -2300,10 +2289,10 @@ void MEDCouplingTwoTimeSteps::setEndArray(DataArrayDouble *array, TimeLabel *own void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationIntInformation(tinyInfo); - tinyInfo.push_back(_start_iteration); - tinyInfo.push_back(_start_order); - tinyInfo.push_back(_end_iteration); - tinyInfo.push_back(_end_order); + tinyInfo.push_back(_start.getIteration()); + tinyInfo.push_back(_start.getOrder()); + tinyInfo.push_back(_end.getIteration()); + tinyInfo.push_back(_end.getOrder()); if(_end_array) { tinyInfo.push_back(_end_array->getNumberOfTuples()); @@ -2319,8 +2308,8 @@ void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation(std::vector& tinyInfo) const { MEDCouplingTimeDiscretization::getTinySerializationDbleInformation(tinyInfo); - tinyInfo.push_back(_start_time); - tinyInfo.push_back(_end_time); + tinyInfo.push_back(_start.getTimeValue()); + tinyInfo.push_back(_end.getTimeValue()); } void MEDCouplingTwoTimeSteps::getTinySerializationStrInformation(std::vector& tinyInfo) const @@ -2386,12 +2375,12 @@ void MEDCouplingTwoTimeSteps::checkForUnserialization(const std::vector& ti void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) { MEDCouplingTimeDiscretization::finishUnserialization(tinyInfoI,tinyInfoD,tinyInfoS); - _start_time=tinyInfoD[1]; - _end_time=tinyInfoD[2]; - _start_iteration=tinyInfoI[2]; - _start_order=tinyInfoI[3]; - _end_iteration=tinyInfoI[4]; - _end_order=tinyInfoI[5]; + _start.setTimeValue(tinyInfoD[1]); + _end.setTimeValue(tinyInfoD[2]); + _start.setIteration(tinyInfoI[2]); + _start.setOrder(tinyInfoI[3]); + _end.setIteration(tinyInfoI[4]); + _end.setOrder(tinyInfoI[5]); } /*! @@ -2400,10 +2389,10 @@ void MEDCouplingTwoTimeSteps::finishUnserialization(const std::vector& tiny void MEDCouplingTwoTimeSteps::getTinySerializationIntInformation2(std::vector& tinyInfo) const { tinyInfo.resize(4); - tinyInfo[0]=_start_iteration; - tinyInfo[1]=_start_order; - tinyInfo[2]=_end_iteration; - tinyInfo[3]=_end_order; + tinyInfo[0]=_start.getIteration(); + tinyInfo[1]=_start.getOrder(); + tinyInfo[2]=_end.getIteration(); + tinyInfo[3]=_end.getOrder(); } /*! @@ -2413,8 +2402,8 @@ void MEDCouplingTwoTimeSteps::getTinySerializationDbleInformation2(std::vector& tinyInfoI, const std::vector& tinyInfoD) { - _start_iteration=tinyInfoI[0]; - _start_order=tinyInfoI[1]; - _end_iteration=tinyInfoI[2]; - _end_order=tinyInfoI[3]; + _start.setIteration(tinyInfoI[0]); + _start.setOrder(tinyInfoI[1]); + _end.setIteration(tinyInfoI[2]); + _end.setOrder(tinyInfoI[3]); _time_tolerance=tinyInfoD[0]; - _start_time=tinyInfoD[1]; - _end_time=tinyInfoD[2]; + _start.setTimeValue(tinyInfoD[1]); + _end.setTimeValue(tinyInfoD[2]); } std::vector< const DataArrayDouble *> MEDCouplingTwoTimeSteps::getArraysForTime(double time) const { - if(time>_start_time-_time_tolerance && time<_end_time+_time_tolerance) + if(time>_start.getTimeValue()-_time_tolerance && time<_end.getTimeValue()+_time_tolerance) { std::vector< const DataArrayDouble *> ret(2); ret[0]=_array; @@ -2463,8 +2452,8 @@ MEDCouplingLinearTime::MEDCouplingLinearTime() std::string MEDCouplingLinearTime::getStringRepr() const { std::ostringstream stream; - stream << REPR << " Time interval is defined by :\niteration_start=" << _start_iteration << " order_start=" << _start_order << " and time_start=" << _start_time << "\n"; - stream << "iteration_end=" << _end_iteration << " order_end=" << _end_order << " and end_time=" << _end_time << "\n"; + stream << REPR << " Time interval is defined by :\niteration_start=" << _start.getIteration() << " order_start=" << _start.getOrder() << " and time_start=" << _start.getTimeValue() << "\n"; + stream << "iteration_end=" << _end.getIteration() << " order_end=" << _end.getOrder() << " and end_time=" << _end.getTimeValue() << "\n"; stream << "Time unit is : \"" << _time_unit << "\""; return stream.str(); } @@ -2472,7 +2461,7 @@ std::string MEDCouplingLinearTime::getStringRepr() const void MEDCouplingLinearTime::checkConsistencyLight() const { MEDCouplingTwoTimeSteps::checkConsistencyLight(); - if(std::fabs(_start_time-_end_time)<_time_tolerance) + if(std::fabs(_start.getTimeValue()-_end.getTimeValue())<_time_tolerance) throw INTERP_KERNEL::Exception("Start time and end time are equals regarding time tolerance."); } @@ -2547,7 +2536,7 @@ bool MEDCouplingLinearTime::areCompatibleForMeld(const MEDCouplingTimeDiscretiza */ void MEDCouplingLinearTime::getValueForTime(double time, const std::vector& vals, double *res) const { - double alpha=(_end_time-time)/(_end_time-_start_time); + double alpha=(_end.getTimeValue()-time)/(_end.getTimeValue()-_start.getTimeValue()); std::size_t nbComp=vals.size()/2; std::transform(vals.begin(),vals.begin()+nbComp,res,std::bind2nd(std::multiplies(),alpha)); std::vector tmp(nbComp); @@ -2557,7 +2546,7 @@ void MEDCouplingLinearTime::getValueForTime(double time, const std::vectorgetTuple(eltId,value); @@ -2576,14 +2565,14 @@ void MEDCouplingLinearTime::getValueOnTime(int eltId, double time, double *value void MEDCouplingLinearTime::getValueOnDiscTime(int eltId, int iteration, int order, double *value) const { - if(iteration==_start_iteration && order==_start_order) + if(iteration==_start.getIteration() && order==_start.getOrder()) { if(_array) _array->getTuple(eltId,value); else throw INTERP_KERNEL::Exception("iteration order match with start time but no start array existing."); } - if(iteration==_end_iteration && order==_end_order) + if(iteration==_end.getIteration() && order==_end.getOrder()) { if(_end_array) _end_array->getTuple(eltId,value); @@ -2620,9 +2609,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::aggregate(const std::vecto a[i]=itC->getArray(); b[i]=itC->getEndArray(); } - MCAuto arr=DataArrayDouble::Aggregate(a); - MCAuto arr2=DataArrayDouble::Aggregate(b); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr(DataArrayDouble::Aggregate(a)),arr2(DataArrayDouble::Aggregate(b)); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setArray(arr,0); ret->setEndArray(arr2,0); return ret; @@ -2633,9 +2621,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::meld(const MEDCouplingTime const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::meld on mismatched time discretization !"); - MCAuto arr1=DataArrayDouble::Meld(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::Meld(getEndArray(),other->getEndArray()); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr1(DataArrayDouble::Meld(getArray(),other->getArray())),arr2(DataArrayDouble::Meld(getEndArray(),other->getEndArray())); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setTimeTolerance(getTimeTolerance()); ret->setArray(arr1,0); ret->setEndArray(arr2,0); @@ -2647,9 +2634,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::dot(const MEDCouplingTimeD const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::dot on mismatched time discretization !"); - MCAuto arr1=DataArrayDouble::Dot(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::Dot(getEndArray(),other->getEndArray()); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr1(DataArrayDouble::Dot(getArray(),other->getArray())),arr2(DataArrayDouble::Dot(getEndArray(),other->getEndArray())); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setArray(arr1,0); ret->setEndArray(arr2,0); return ret; @@ -2660,9 +2646,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::crossProduct(const MEDCoup const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::crossProduct on mismatched time discretization !"); - MCAuto arr1=DataArrayDouble::CrossProduct(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::CrossProduct(getEndArray(),other->getEndArray()); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr1(DataArrayDouble::CrossProduct(getArray(),other->getArray())),arr2(DataArrayDouble::CrossProduct(getEndArray(),other->getEndArray())); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setArray(arr1,0); ret->setEndArray(arr2,0); return ret; @@ -2674,8 +2659,7 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::max(const MEDCouplingTimeD if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::max on mismatched time discretization !"); MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; - MCAuto arr1=DataArrayDouble::Max(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::Max(getEndArray(),other->getEndArray()); + MCAuto arr1(DataArrayDouble::Max(getArray(),other->getArray())),arr2(DataArrayDouble::Max(getEndArray(),other->getEndArray())); ret->setArray(arr1,0); ret->setEndArray(arr2,0); return ret; @@ -2686,9 +2670,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::min(const MEDCouplingTimeD const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::min on mismatched time discretization !"); - MCAuto arr1=DataArrayDouble::Min(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::Min(getEndArray(),other->getEndArray()); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr1(DataArrayDouble::Min(getArray(),other->getArray())),arr2(DataArrayDouble::Min(getEndArray(),other->getEndArray())); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setArray(arr1,0); ret->setEndArray(arr2,0); return ret; @@ -2699,9 +2682,8 @@ MEDCouplingTimeDiscretization *MEDCouplingLinearTime::add(const MEDCouplingTimeD const MEDCouplingLinearTime *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("LinearTime::add on mismatched time discretization !"); - MCAuto arr1=DataArrayDouble::Add(getArray(),other->getArray()); - MCAuto arr2=DataArrayDouble::Add(getEndArray(),other->getEndArray()); - MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + MCAuto arr1(DataArrayDouble::Add(getArray(),other->getArray())),arr2(DataArrayDouble::Add(getEndArray(),other->getEndArray())); + MEDCouplingLinearTime *ret(new MEDCouplingLinearTime); ret->setArray(arr1,0); ret->setEndArray(arr2,0); return ret; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index 2b88a67c5..1cb612bf9 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -57,6 +57,18 @@ namespace MEDCoupling MEDCOUPLING_EXPORT virtual void setStartOrder(int order) = 0; MEDCOUPLING_EXPORT virtual void setStartTime(double time, int iteration, int order) = 0; MEDCOUPLING_EXPORT virtual void setStartTimeValue(double time) = 0; + MEDCOUPLING_EXPORT virtual double getEndTime(int& iteration, int& order) const = 0; + MEDCOUPLING_EXPORT virtual void setEndIteration(int it) = 0; + MEDCOUPLING_EXPORT virtual void setEndOrder(int order) = 0; + MEDCOUPLING_EXPORT virtual void setEndTimeValue(double time) = 0; + MEDCOUPLING_EXPORT virtual void setEndTime(double time, int iteration, int order) = 0; + + MEDCOUPLING_EXPORT virtual void setEndArray(typename Traits::ArrayType *array, TimeLabel *owner); + MEDCOUPLING_EXPORT virtual void setArrays(const std::vector< typename Traits::ArrayType *>& arrays, TimeLabel *owner); + MEDCOUPLING_EXPORT virtual const typename Traits::ArrayType *getEndArray() const; + MEDCOUPLING_EXPORT virtual typename Traits::ArrayType *getEndArray(); + MEDCOUPLING_EXPORT virtual void getArrays(std::vector::ArrayType *>& arrays) const; + MEDCOUPLING_EXPORT virtual std::string getStringRepr() const = 0; MEDCOUPLING_EXPORT virtual TypeOfTimeDiscretization getEnum() const = 0; MEDCOUPLING_EXPORT virtual MEDCouplingTimeDiscretizationTemplate *performCopyOrIncrRef(bool deepCopy) const = 0; @@ -67,14 +79,17 @@ namespace MEDCoupling MEDCOUPLING_EXPORT virtual std::size_t getHeapMemorySizeWithoutChildren() const; MEDCOUPLING_EXPORT virtual std::vector getDirectChildrenWithNull() const; // + MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, T prec, std::string& reason) const = 0; + MEDCOUPLING_EXPORT virtual bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, T prec) const = 0; + // MEDCOUPLING_EXPORT virtual bool areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const; MEDCOUPLING_EXPORT virtual bool areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const; + MEDCOUPLING_EXPORT virtual ~MEDCouplingTimeDiscretizationTemplate(); protected: MEDCOUPLING_EXPORT MEDCouplingTimeDiscretizationTemplate(); MEDCOUPLING_EXPORT MEDCouplingTimeDiscretizationTemplate(const MEDCouplingTimeDiscretizationTemplate& other, bool deepCopy); - MEDCOUPLING_EXPORT virtual ~MEDCouplingTimeDiscretizationTemplate(); protected: std::string _time_unit; double _time_tolerance; @@ -113,9 +128,9 @@ namespace MEDCoupling public: MEDCOUPLING_EXPORT static MEDCouplingTimeDiscretization *New(TypeOfTimeDiscretization type); MEDCOUPLING_EXPORT virtual bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; + MEDCOUPLING_EXPORT virtual bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const; + MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const; MEDCOUPLING_EXPORT virtual bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const; - MEDCOUPLING_EXPORT virtual bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; MEDCOUPLING_EXPORT virtual MEDCouplingTimeDiscretization *buildNewTimeReprFromThis(TypeOfTimeDiscretization type, bool deepCopy) const; MEDCOUPLING_EXPORT virtual void synchronizeTimeWith(const MEDCouplingMesh *mesh) = 0; MEDCOUPLING_EXPORT virtual MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const = 0; @@ -146,20 +161,10 @@ namespace MEDCoupling MEDCOUPLING_EXPORT virtual void finishUnserialization2(const std::vector& tinyInfoI, const std::vector& tinyInfoD) = 0; MEDCOUPLING_EXPORT virtual void checkNoTimePresence() const = 0; MEDCOUPLING_EXPORT virtual void checkTimePresence(double time) const = 0; - MEDCOUPLING_EXPORT virtual void setEndArray(DataArrayDouble *array, TimeLabel *owner); - MEDCOUPLING_EXPORT virtual void setArrays(const std::vector& arrays, TimeLabel *owner); - MEDCOUPLING_EXPORT virtual const DataArrayDouble *getEndArray() const; - MEDCOUPLING_EXPORT virtual DataArrayDouble *getEndArray(); MEDCOUPLING_EXPORT virtual std::vector< const DataArrayDouble *> getArraysForTime(double time) const = 0; - MEDCOUPLING_EXPORT virtual void getValueForTime(double time, const std::vector& vals, double *res) const = 0; - MEDCOUPLING_EXPORT virtual void getArrays(std::vector& arrays) const; + MEDCOUPLING_EXPORT virtual void getValueForTime(double time, const std::vector& vals, double *res) const = 0; MEDCOUPLING_EXPORT virtual bool isBefore(const MEDCouplingTimeDiscretization *other) const; MEDCOUPLING_EXPORT virtual bool isStrictlyBefore(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT virtual double getEndTime(int& iteration, int& order) const = 0; - MEDCOUPLING_EXPORT virtual void setEndIteration(int it) = 0; - MEDCOUPLING_EXPORT virtual void setEndOrder(int order) = 0; - MEDCOUPLING_EXPORT virtual void setEndTimeValue(double time) = 0; - MEDCOUPLING_EXPORT virtual void setEndTime(double time, int iteration, int order) = 0; MEDCOUPLING_EXPORT virtual void getValueOnTime(int eltId, double time, double *value) const = 0; MEDCOUPLING_EXPORT virtual void getValueOnDiscTime(int eltId, int iteration, int order, double *value) const = 0; // @@ -205,9 +210,16 @@ namespace MEDCoupling void setStartOrder(int order) { _tk.setOrder(order); } void setStartTimeValue(double time) { _tk.setTimeValue(time); } void setStartTime(double time, int iteration, int order) { _tk.setAllInfo(time,iteration,order); } + double getEndTime(int& iteration, int& order) const; + void setEndIteration(int it); + void setEndOrder(int order); + void setEndTimeValue(double time); + void setEndTime(double time, int iteration, int order); std::string getStringRepr() const; TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } MEDCouplingTimeDiscretizationInt *performCopyOrIncrRef(bool deepCopy) const; + bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, int prec, std::string& reason) const; + bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, int prec) const; private: static const TypeOfTimeDiscretization DISCRETIZATION=ONE_TIME; MEDCOUPLING_EXPORT static const char REPR[]; @@ -240,8 +252,8 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void divideEqual(const MEDCouplingTimeDiscretization *other); MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const; MEDCOUPLING_EXPORT void powEqual(const MEDCouplingTimeDiscretization *other); - MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; - MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const; MEDCOUPLING_EXPORT bool areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const; MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const; @@ -303,8 +315,8 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void divideEqual(const MEDCouplingTimeDiscretization *other); MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const; MEDCOUPLING_EXPORT void powEqual(const MEDCouplingTimeDiscretization *other); - MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; - MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const; MEDCOUPLING_EXPORT bool areCompatible(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingTimeDiscretizationTemplate *other, std::string& reason) const; MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const; @@ -361,8 +373,8 @@ namespace MEDCoupling MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretizationTemplate *other) const; MEDCOUPLING_EXPORT bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const; - MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; - MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const; MEDCOUPLING_EXPORT std::vector< const DataArrayDouble *> getArraysForTime(double time) const; MEDCOUPLING_EXPORT void getValueForTime(double time, const std::vector& vals, double *res) const; MEDCOUPLING_EXPORT void getValueOnTime(int eltId, double time, double *value) const; @@ -425,22 +437,22 @@ namespace MEDCoupling MEDCOUPLING_EXPORT const DataArrayDouble *getEndArray() const; MEDCOUPLING_EXPORT DataArrayDouble *getEndArray(); MEDCOUPLING_EXPORT void checkConsistencyLight() const; - MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; - MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate *other, double prec, std::string& reason) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationTemplate *other, double prec) const; MEDCOUPLING_EXPORT void checkNoTimePresence() const; MEDCOUPLING_EXPORT void checkTimePresence(double time) const; MEDCOUPLING_EXPORT void getArrays(std::vector& arrays) const; MEDCOUPLING_EXPORT void setEndArray(DataArrayDouble *array, TimeLabel *owner); - MEDCOUPLING_EXPORT void setStartTime(double time, int iteration, int order) { _start_time=time; _start_iteration=iteration; _start_order=order; } - MEDCOUPLING_EXPORT void setEndTime(double time, int iteration, int order) { _end_time=time; _end_iteration=iteration; _end_order=order; } - MEDCOUPLING_EXPORT double getStartTime(int& iteration, int& order) const { iteration=_start_iteration; order=_start_order; return _start_time; } - MEDCOUPLING_EXPORT double getEndTime(int& iteration, int& order) const { iteration=_end_iteration; order=_end_order; return _end_time; } - MEDCOUPLING_EXPORT void setStartIteration(int it) { _start_iteration=it; } - MEDCOUPLING_EXPORT void setEndIteration(int it) { _end_iteration=it; } - MEDCOUPLING_EXPORT void setStartOrder(int order) { _start_order=order; } - MEDCOUPLING_EXPORT void setEndOrder(int order) { _end_order=order; } - MEDCOUPLING_EXPORT void setStartTimeValue(double time) { _start_time=time; } - MEDCOUPLING_EXPORT void setEndTimeValue(double time) { _end_time=time; } + MEDCOUPLING_EXPORT void setStartTime(double time, int iteration, int order) { _start.setAllInfo(time,iteration,order); } + MEDCOUPLING_EXPORT void setEndTime(double time, int iteration, int order) { _end.setAllInfo(time,iteration,order); } + MEDCOUPLING_EXPORT double getStartTime(int& iteration, int& order) const { return _start.getAllInfo(iteration,order); } + MEDCOUPLING_EXPORT double getEndTime(int& iteration, int& order) const { return _end.getAllInfo(iteration,order); } + MEDCOUPLING_EXPORT void setStartIteration(int it) { _start.setIteration(it); } + MEDCOUPLING_EXPORT void setEndIteration(int it) { _end.setIteration(it); } + MEDCOUPLING_EXPORT void setStartOrder(int order) { _start.setOrder(order); } + MEDCOUPLING_EXPORT void setEndOrder(int order) { _end.setOrder(order); } + MEDCOUPLING_EXPORT void setStartTimeValue(double time) { _start.setTimeValue(time); } + MEDCOUPLING_EXPORT void setEndTimeValue(double time) { _end.setTimeValue(time); } MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector& tinyInfo) const; MEDCOUPLING_EXPORT void getTinySerializationDbleInformation(std::vector& tinyInfo) const; MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector& tinyInfo) const; @@ -455,12 +467,8 @@ namespace MEDCoupling protected: static const char EXCEPTION_MSG[]; protected: - double _start_time; - double _end_time; - int _start_iteration; - int _end_iteration; - int _start_order; - int _end_order; + MEDCouplingTimeKeeper _start; + MEDCouplingTimeKeeper _end; DataArrayDouble *_end_array; }; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.txx b/src/MEDCoupling/MEDCouplingTimeDiscretization.txx index f03bedf7d..4d96c7cc8 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.txx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.txx @@ -186,6 +186,39 @@ namespace MEDCoupling if(_array) _array->decrRef(); } + + template + void MEDCouplingTimeDiscretizationTemplate::setEndArray(typename Traits::ArrayType *array, TimeLabel *owner) + { + throw INTERP_KERNEL::Exception("setEndArray not available for this type of time discretization !"); + } + + template + void MEDCouplingTimeDiscretizationTemplate::setArrays(const std::vector::ArrayType *>& arrays, TimeLabel *owner) + { + if(arrays.size()!=1) + throw INTERP_KERNEL::Exception("MEDCouplingTimeDiscretization::setArrays : number of arrays must be one."); + setArray(arrays.back(),owner); + } + + template + const typename Traits::ArrayType *MEDCouplingTimeDiscretizationTemplate::getEndArray() const + { + throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !"); + } + + template + typename Traits::ArrayType *MEDCouplingTimeDiscretizationTemplate::getEndArray() + { + throw INTERP_KERNEL::Exception("getEndArray not available for this type of time discretization !"); + } + + template + void MEDCouplingTimeDiscretizationTemplate::getArrays(std::vector::ArrayType *>& arrays) const + { + arrays.resize(1); + arrays[0]=_array; + } } #endif diff --git a/src/MEDCoupling/MEDCouplingTraits.cxx b/src/MEDCoupling/MEDCouplingTraits.cxx index a764675ee..0a30d982d 100644 --- a/src/MEDCoupling/MEDCouplingTraits.cxx +++ b/src/MEDCoupling/MEDCouplingTraits.cxx @@ -24,6 +24,10 @@ using namespace MEDCoupling; const char Traits::ArrayTypeName[]="DataArrayDouble"; +const char Traits::FieldTypeName[]="MEDCouplingFieldDouble"; + const char Traits::ArrayTypeName[]="DataArrayInt"; +const char Traits::FieldTypeName[]="MEDCouplingFieldInt"; + const char Traits::ArrayTypeName[]="DataArrayChar"; diff --git a/src/MEDCoupling/MEDCouplingTraits.hxx b/src/MEDCoupling/MEDCouplingTraits.hxx index c4b7ed7fd..40034550f 100644 --- a/src/MEDCoupling/MEDCouplingTraits.hxx +++ b/src/MEDCoupling/MEDCouplingTraits.hxx @@ -32,19 +32,25 @@ namespace MEDCoupling class DataArrayInt; class DataArrayDouble; class DataArrayChar; + class MEDCouplingFieldDouble; + class MEDCouplingFieldInt; template<> struct Traits { static const char ArrayTypeName[]; + static const char FieldTypeName[]; typedef DataArrayDouble ArrayType; + typedef MEDCouplingFieldDouble FieldType; }; template<> struct Traits { static const char ArrayTypeName[]; + static const char FieldTypeName[]; typedef DataArrayInt ArrayType; + typedef MEDCouplingFieldInt FieldType; }; template<> diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index f7f960cec..38da9fe17 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -236,7 +236,7 @@ void MEDCouplingUMesh::checkConsistency(double eps) const { std::ostringstream oss; oss << "MEDCouplingUMesh::checkConsistency : cell << #" << i<< " with type Type " << cm.getRepr() << " in 'this' whereas meshdim == " << meshDim << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int nbOfNodesInCell=ptrI[i+1]-ptrI[i]-1; if(!cm.isDynamic()) @@ -245,7 +245,7 @@ void MEDCouplingUMesh::checkConsistency(double eps) const std::ostringstream oss; oss << "MEDCouplingUMesh::checkConsistency : cell #" << i << " with static Type '" << cm.getRepr() << "' has " << cm.getNumberOfNodes(); oss << " nodes whereas in connectivity there is " << nbOfNodesInCell << " nodes ! Looks very bad !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(cm.isQuadratic() && cm.isDynamic() && meshDim == 2) if (nbOfNodesInCell % 2 || nbOfNodesInCell < 4) @@ -253,7 +253,7 @@ void MEDCouplingUMesh::checkConsistency(double eps) const std::ostringstream oss; oss << "MEDCouplingUMesh::checkConsistency : cell #" << i << " with quadratic type '" << cm.getRepr() << "' has " << nbOfNodesInCell; oss << " nodes. This should be even, and greater or equal than 4!! Looks very bad!"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } for(const int *w=ptr+ptrI[i]+1;w!=ptr+ptrI[i+1];w++) { @@ -263,20 +263,20 @@ void MEDCouplingUMesh::checkConsistency(double eps) const if(nodeId>=nbOfNodes) { std::ostringstream oss; oss << "Cell #" << i << " is built with node #" << nodeId << " whereas there are only " << nbOfNodes << " nodes in the mesh !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } else if(nodeId<-1) { std::ostringstream oss; oss << "Cell #" << i << " is built with node #" << nodeId << " in connectivity ! sounds bad !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } else { if((INTERP_KERNEL::NormalizedCellType)(ptr[ptrI[i]])!=INTERP_KERNEL::NORM_POLYHED) { std::ostringstream oss; oss << "Cell #" << i << " is built with node #-1 in connectivity ! sounds bad !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -355,7 +355,7 @@ void MEDCouplingUMesh::insertNextCell(INTERP_KERNEL::NormalizedCellType type, in { std::ostringstream oss; oss << "MEDCouplingUMesh::insertNextCell : Trying to push a " << cm.getRepr() << " cell with a size of " << size; oss << " ! Expecting " << cm.getNumberOfNodes() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int idx=_nodal_connec_index->back(); int val=idx+size+1; @@ -368,7 +368,7 @@ void MEDCouplingUMesh::insertNextCell(INTERP_KERNEL::NormalizedCellType type, in std::ostringstream oss; oss << "MEDCouplingUMesh::insertNextCell : cell type " << cm.getRepr() << " has a dimension " << cm.getDimension(); oss << " whereas Mesh Dimension of current UMesh instance is set to " << _mesh_dim << " ! Please invoke \"setMeshDimension\" method before or invoke "; oss << "\"MEDCouplingUMesh::New\" static method with 2 parameters name and meshDimension !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } @@ -1150,7 +1150,7 @@ void MEDCouplingUMesh::convertToPolyTypes(const int *cellIdsToConvertBg, const i { std::ostringstream oss; oss << "MEDCouplingUMesh::convertToPolyTypes : On rank #" << std::distance(cellIdsToConvertBg,iter) << " value is " << *iter << " which is not"; oss << " in range [0," << nbOfCells << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -1168,7 +1168,7 @@ void MEDCouplingUMesh::convertToPolyTypes(const int *cellIdsToConvertBg, const i { std::ostringstream oss; oss << "MEDCouplingUMesh::convertToPolyTypes : On rank #" << std::distance(cellIdsToConvertBg,iter) << " value is " << *iter << " which is not"; oss << " in range [0," << nbOfCells << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } for(int cellId=0;cellId& nodeIdsInUse) const else { std::ostringstream oss; oss << "MEDCouplingUMesh::computeNodeIdsAlg : In cell #" << i << " presence of node id " << conn[j] << " not in [0," << nbOfNodes << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -1532,7 +1532,7 @@ DataArrayInt *MEDCouplingUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const else { std::ostringstream oss; oss << "MEDCouplingUMesh::getNodeIdsInUse : In cell #" << i << " presence of node id " << conn[j] << " not in [0," << nbOfNodes << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } nbrOfNodesInUse=(int)std::count(traducer,traducer+nbOfNodes,1); @@ -1974,7 +1974,7 @@ bool MEDCouplingUMesh::areCellsIncludedIn(const MEDCouplingUMesh *other, int com std::ostringstream oss; oss << "MEDCouplingUMesh::areCellsIncludedIn : only following policies are possible : "; std::copy(possibleCompType,possibleCompType+sizeof(possibleCompType)/sizeof(int),std::ostream_iterator(oss," ")); oss << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } MCAuto o2n=mesh->zipConnectivityTraducer(compType,nbOfCells); arr=o2n->subArray(nbOfCells); @@ -2133,13 +2133,13 @@ void MEDCouplingUMesh::setPartOfMySelf(const int *cellIdsBg, const int *cellIdsE { std::ostringstream oss; oss << "MEDCouplingUMesh::setPartOfMySelf : Mismatch of meshdimensions ! this is equal to " << getMeshDimension(); oss << ", whereas other mesh dimension is set equal to " << otherOnSameCoordsThanThis.getMeshDimension() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int nbOfCellsToModify=(int)std::distance(cellIdsBg,cellIdsEnd); if(nbOfCellsToModify!=otherOnSameCoordsThanThis.getNumberOfCells()) { std::ostringstream oss; oss << "MEDCouplingUMesh::setPartOfMySelf : cells ids length (" << nbOfCellsToModify << ") do not match the number of cells of other mesh (" << otherOnSameCoordsThanThis.getNumberOfCells() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int nbOfCells=getNumberOfCells(); bool easyAssign=true; @@ -2154,7 +2154,7 @@ void MEDCouplingUMesh::setPartOfMySelf(const int *cellIdsBg, const int *cellIdsE else { std::ostringstream oss; oss << "MEDCouplingUMesh::setPartOfMySelf : On pos #" << std::distance(cellIdsBg,it) << " id is equal to " << *it << " which is not in [0," << nbOfCells << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } if(easyAssign) @@ -2182,13 +2182,13 @@ void MEDCouplingUMesh::setPartOfMySelfSlice(int start, int end, int step, const { std::ostringstream oss; oss << "MEDCouplingUMesh::setPartOfMySelfSlice : Mismatch of meshdimensions ! this is equal to " << getMeshDimension(); oss << ", whereas other mesh dimension is set equal to " << otherOnSameCoordsThanThis.getMeshDimension() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int nbOfCellsToModify=DataArray::GetNumberOfItemGivenBESRelative(start,end,step,"MEDCouplingUMesh::setPartOfMySelfSlice : "); if(nbOfCellsToModify!=otherOnSameCoordsThanThis.getNumberOfCells()) { std::ostringstream oss; oss << "MEDCouplingUMesh::setPartOfMySelfSlice : cells ids length (" << nbOfCellsToModify << ") do not match the number of cells of other mesh (" << otherOnSameCoordsThanThis.getNumberOfCells() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int nbOfCells=getNumberOfCells(); bool easyAssign=true; @@ -2204,7 +2204,7 @@ void MEDCouplingUMesh::setPartOfMySelfSlice(int start, int end, int step, const else { std::ostringstream oss; oss << "MEDCouplingUMesh::setPartOfMySelfSlice : On pos #" << i << " id is equal to " << it << " which is not in [0," << nbOfCells << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } if(easyAssign) @@ -2680,7 +2680,7 @@ void MEDCouplingUMesh::renumberNodesInConn(const INTERP_KERNEL::HashMap else { std::ostringstream oss; oss << "MEDCouplingUMesh::renumberNodesInConn(map) : presence in connectivity for cell #" << i << " of node #" << node << " : Not in map !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -2974,7 +2974,7 @@ INTERP_KERNEL::NormalizedCellType MEDCouplingUMesh::getTypeOfCell(int cellId) co else { std::ostringstream oss; oss << "MEDCouplingUMesh::getTypeOfCell : Requesting type of cell #" << cellId << " but it should be in [0," << _nodal_connec_index->getNbOfElems()-1 << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } @@ -3442,7 +3442,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildPartOfMySelfKeepCoordsSlice(int start, else { std::ostringstream oss; oss << "MEDCouplingUMesh::buildPartOfMySelfKeepCoordsSlice : On pos #" << i << " input cell id =" << work << " should be in [0," << ncell << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } MCAuto newConn=DataArrayInt::New(); newConn->alloc(newConnIPtr[0],1); @@ -3486,7 +3486,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildPartOfMySelfKeepCoords(const int *begin { free(connIndexRet); std::ostringstream oss; oss << "MEDCouplingUMesh::buildPartOfMySelfKeepCoords : On pos #" << std::distance(begin,work) << " input cell id =" << *work << " should be in [0," << ncell << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } int *connRet=(int *)malloc(connIndexRet[nbOfElemsRet]*sizeof(int)); @@ -4136,7 +4136,7 @@ double MEDCouplingUMesh::distanceToPoint(const double *ptBg, const double *ptEnd throw INTERP_KERNEL::Exception("MEDCouplingUMesh::distanceToPoint : only mesh dimension 2 and 1 are implemented !"); checkFullyDefined(); if((int)std::distance(ptBg,ptEnd)!=spaceDim) - { std::ostringstream oss; oss << "MEDCouplingUMesh::distanceToPoint : input point has to have dimension equal to the space dimension of this (" << spaceDim << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + { std::ostringstream oss; oss << "MEDCouplingUMesh::distanceToPoint : input point has to have dimension equal to the space dimension of this (" << spaceDim << ") !"; throw INTERP_KERNEL::Exception(oss.str()); } DataArrayInt *ret1=0; MCAuto pts=DataArrayDouble::New(); pts->useArray(ptBg,false,C_DEALLOC,1,spaceDim); MCAuto ret0=distanceToPoints(pts,ret1); @@ -4179,7 +4179,7 @@ DataArrayDouble *MEDCouplingUMesh::distanceToPoints(const DataArrayDouble *pts, if(pts->getNumberOfComponents()!=spaceDim) { std::ostringstream oss; oss << "MEDCouplingUMesh::distanceToPoints : input pts DataArrayDouble has " << pts->getNumberOfComponents() << " components whereas it should be equal to " << spaceDim << " (mesh spaceDimension) !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } checkFullyDefined(); int nbCells=getNumberOfCells(); @@ -5535,7 +5535,7 @@ DataArrayInt *MEDCouplingUMesh::convertLinearCellsToQuadratic3D1(DataArrayInt *& if(typ2==INTERP_KERNEL::NORM_ERROR) { std::ostringstream oss; oss << "MEDCouplingUMesh::convertLinearCellsToQuadratic3D1 : On cell #" << i << " the linear cell type does not support advanced quadratization !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } types.insert(typ2); newConn->pushBackSilent(typ2); newConn->pushBackValsSilent(cPtr+icPtr[0]+1,cPtr+icPtr[1]); @@ -6015,7 +6015,7 @@ void MEDCouplingUMesh::subDivide2DMesh(const int *nodeSubdived, const int *nodeI else { std::ostringstream oss; oss << "MEDCouplingUMesh::subDivide2DMesh : On polygon #" << i << " edgeid #" << j << " subedges mismatch : end subedge k!=start subedge k+1 !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } else @@ -6281,7 +6281,7 @@ void MEDCouplingUMesh::orientCorrectlyPolyhedrons() catch(INTERP_KERNEL::Exception& e) { std::ostringstream oss; oss << "Something wrong in polyhedron #" << i << " : " << e.what(); - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -6811,7 +6811,7 @@ DataArrayDouble *MEDCouplingUMesh::getBoundingBoxForBBTreeFast() const if(kk==0) { std::ostringstream oss; oss << "MEDCouplingUMesh::getBoundingBoxForBBTree : cell #" << i << " contains no valid nodeId !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } return ret.retn(); @@ -6959,7 +6959,7 @@ std::vector MEDCouplingUMesh::getDistributionOfTypes() const { std::ostringstream oss; oss << "MEDCouplingUMesh::getDistributionOfTypes : Type " << INTERP_KERNEL::CellModel::GetCellModel(typ).getRepr(); oss << " is not contiguous !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } types.insert(typ); ret[3*i]=typ; @@ -7052,7 +7052,7 @@ DataArrayInt *MEDCouplingUMesh::checkTypeConsistencyAndContig(const std::vector< { std::ostringstream oss; oss << "MEDCouplingUMesh::checkTypeConsistencyAndContig : the section " << kk << " points to the profile #" << idInIdsPerType; oss << ", and this profile contains a value " << *k << " should be in [0," << nbOfCellsOfCurType << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -7066,7 +7066,7 @@ DataArrayInt *MEDCouplingUMesh::checkTypeConsistencyAndContig(const std::vector< { std::ostringstream oss; oss << "MEDCouplingUMesh::checkTypeConsistencyAndContig : at section " << kk << " of code it points to the array #" << idInIdsPerType; oss << " should be in [0," << idsPerType.size() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } i=j; @@ -7190,7 +7190,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::emulateMEDMEMBDC(const MEDCouplingUMesh *nM1 ret->getMaxValue(tmp2); ret->decrRef(); std::ostringstream oss; oss << "MEDCouplingUMesh::emulateMEDMEMBDC : input N-1 mesh present a cell not in descending mesh ... Id of cell is " << tmp2 << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } nM1LevMeshIds=ret; // @@ -7325,7 +7325,7 @@ DataArrayInt *MEDCouplingUMesh::getLevArrPerCellTypes(const INTERP_KERNEL::Norma const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel((INTERP_KERNEL::NormalizedCellType)conn[*i]); std::ostringstream oss; oss << "MEDCouplingUMesh::getLevArrPerCellTypes : Cell #" << std::distance(connI,i); oss << " has a type " << cm.getRepr() << " not in input array of type !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } nbPerType=tmpb.retn(); @@ -7473,7 +7473,7 @@ DataArrayInt *MEDCouplingUMesh::convertNodalConnectivityToStaticGeoTypeMesh() co { std::ostringstream oss; oss << "MEDCouplingUMesh::convertNodalConnectivityToStaticGeoTypeMesh : this contains a single geo type (" << cm.getRepr() << ") but "; oss << "this type is dynamic ! Only static geometric type is possible for that type ! call convertNodalConnectivityToDynamicGeoTypeMesh instead !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int nbCells=getNumberOfCells(); int typi=(int)typ; @@ -7490,7 +7490,7 @@ DataArrayInt *MEDCouplingUMesh::convertNodalConnectivityToStaticGeoTypeMesh() co else { std::ostringstream oss; oss << "MEDCouplingUMesh::convertNodalConnectivityToStaticGeoTypeMesh : there something wrong in cell #" << i << " ! The type of cell is not those expected, or the length of nodal connectivity is not those expected (" << nbNodesPerCell-1 << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } return connOut.retn(); @@ -7671,7 +7671,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::keepSpecifiedCells(INTERP_KERNEL::Normalized { std::ostringstream oss; oss << "MEDCouplingUMesh::keepSpecifiedCells : Request on type " << type << " at place #" << std::distance(idsPerGeoTypeBg,work) << " value " << *work; oss << ". It should be in [0," << szOfType << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } MCAuto idsTokeep=DataArrayInt::New(); idsTokeep->alloc(sz+(int)std::distance(idsPerGeoTypeBg,idsPerGeoTypeEnd),1); int *idsPtr=idsTokeep->getPointer(); @@ -7788,7 +7788,7 @@ DataArrayDouble *MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell() const else { std::ostringstream oss; oss << "MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell : on cell #" << i << " presence of nodeId #" << *conn << " should be in [0," << nbOfNodes << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } int nbOfNodesInCell=nodalI[i+1]-nodalI[i]-1; @@ -7797,7 +7797,7 @@ DataArrayDouble *MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell() const else { std::ostringstream oss; oss << "MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell : on cell #" << i << " presence of cell with no nodes !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } else @@ -7811,7 +7811,7 @@ DataArrayDouble *MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell() const else { std::ostringstream oss; oss << "MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell : on cell polyhedron cell #" << i << " presence of nodeId #" << *it << " should be in [0," << nbOfNodes << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } if(!s.empty()) @@ -7819,7 +7819,7 @@ DataArrayDouble *MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell() const else { std::ostringstream oss; oss << "MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell : on polyhedron cell #" << i << " there are no nodes !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -7901,14 +7901,14 @@ DataArrayDouble *MEDCouplingUMesh::computePlaneEquationOf3DFaces() const else { std::ostringstream oss; oss << "MEDCouplingUMesh::computePlaneEquationOf3DFaces : invalid 2D cell #" << i << " ! This cell points to an invalid nodeId : " << nodeId << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } else { std::ostringstream oss; oss << "MEDCouplingUMesh::computePlaneEquationOf3DFaces : invalid 2D cell #" << i << " ! Must be constitued by more than 3 nodes !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } INTERP_KERNEL::inverseMatrix(matrix,4,matrix2); retPtr[0]=matrix2[3]; retPtr[1]=matrix2[7]; retPtr[2]=matrix2[11]; retPtr[3]=matrix2[15]; @@ -7988,7 +7988,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshes(std::vector > bb(sz); std::vector< const MEDCouplingUMesh * > aa(sz); @@ -8114,7 +8114,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesOnSameCoords(const std::vectorgetCoords(); int meshDim=meshes.front()->getMeshDimension(); @@ -8236,14 +8236,14 @@ void MEDCouplingUMesh::PutUMeshesOnSameAggregatedCoords(const std::vector res=DataArrayDouble::Aggregate(coords); @@ -8283,13 +8283,13 @@ void MEDCouplingUMesh::MergeNodesOnUMeshesSharingSameCoords(const std::vector p1(bgFace[j],bgFace[(j+1)%nbOfEdgesInFace]); std::pair p2(p1.second,p1.first); if(std::find(edgesOK.begin(),edgesOK.end(),p1)!=edgesOK.end()) - { std::ostringstream oss; oss << "Face #" << j << " of polyhedron looks bad !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + { std::ostringstream oss; oss << "Face #" << j << " of polyhedron looks bad !"; throw INTERP_KERNEL::Exception(oss.str()); } if(std::find(edgesFinished.begin(),edgesFinished.end(),p1)!=edgesFinished.end() || std::find(edgesFinished.begin(),edgesFinished.end(),p2)!=edgesFinished.end()) - { std::ostringstream oss; oss << "Face #" << j << " of polyhedron looks bad !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + { std::ostringstream oss; oss << "Face #" << j << " of polyhedron looks bad !"; throw INTERP_KERNEL::Exception(oss.str()); } std::list< std::pair >::iterator it=std::find(edgesOK.begin(),edgesOK.end(),p2); if(it!=edgesOK.end()) { @@ -10149,7 +10149,7 @@ void MEDCouplingUMesh::BuildIntersecting2DCellsFromEdges(double eps, const MEDCo catch(INTERP_KERNEL::Exception& e) { std::ostringstream oss; oss << "Error when computing residual of cell #" << i << " in source/m1 mesh ! Maybe the neighbours of this cell in mesh are not well connected !\n" << "The deep reason is the following : " << e.what(); - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } for(std::map::const_iterator it=mappRev.begin();it!=mappRev.end();it++) @@ -11004,7 +11004,7 @@ void MEDCouplingUMesh::ExtractFromIndexedArrays(const int *idsOfSelectBg, const else { std::ostringstream oss; oss << "MEDCouplingUMesh::ExtractFromIndexedArrays : id located on pos #" << i << " value is " << *idsIt << " ! Must be in [0," << nbOfGrps << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(lgth>=work[-1]) *work=lgth; @@ -11012,7 +11012,7 @@ void MEDCouplingUMesh::ExtractFromIndexedArrays(const int *idsOfSelectBg, const { std::ostringstream oss; oss << "MEDCouplingUMesh::ExtractFromIndexedArrays : id located on pos #" << i << " value is " << *idsIt << " and at this pos arrIndxIn[" << *idsIt; oss << "+1]-arrIndxIn[" << *idsIt << "] < 0 ! The input index array is bugged !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } arro->alloc(lgth,1); @@ -11026,7 +11026,7 @@ void MEDCouplingUMesh::ExtractFromIndexedArrays(const int *idsOfSelectBg, const { std::ostringstream oss; oss << "MEDCouplingUMesh::ExtractFromIndexedArrays : id located on pos #" << i << " value is " << *idsIt << " arrIndx[" << *idsIt << "] must be >= 0 and arrIndx["; oss << *idsIt << "+1] <= " << maxSizeOfArr << " (the size of arrIn)!"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } arrOut=arro.retn(); @@ -11078,7 +11078,7 @@ void MEDCouplingUMesh::ExtractFromIndexedArraysSlice(int idsOfSelectStart, int i else { std::ostringstream oss; oss << "MEDCouplingUMesh::ExtractFromIndexedArraysSlice : id located on pos #" << i << " value is " << idsIt << " ! Must be in [0," << nbOfGrps << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(lgth>=work[-1]) *work=lgth; @@ -11086,7 +11086,7 @@ void MEDCouplingUMesh::ExtractFromIndexedArraysSlice(int idsOfSelectStart, int i { std::ostringstream oss; oss << "MEDCouplingUMesh::ExtractFromIndexedArraysSlice : id located on pos #" << i << " value is " << idsIt << " and at this pos arrIndxIn[" << idsIt; oss << "+1]-arrIndxIn[" << idsIt << "] < 0 ! The input index array is bugged !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } arro->alloc(lgth,1); @@ -11100,7 +11100,7 @@ void MEDCouplingUMesh::ExtractFromIndexedArraysSlice(int idsOfSelectStart, int i { std::ostringstream oss; oss << "MEDCouplingUMesh::ExtractFromIndexedArraysSlice : id located on pos #" << i << " value is " << idsIt << " arrIndx[" << idsIt << "] must be >= 0 and arrIndx["; oss << idsIt << "+1] <= " << maxSizeOfArr << " (the size of arrIn)!"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } arrOut=arro.retn(); @@ -11147,7 +11147,7 @@ void MEDCouplingUMesh::SetPartOfIndexedArrays(const int *idsOfSelectBg, const in else { std::ostringstream oss; oss << "MEDCouplingUMesh::SetPartOfIndexedArrays : On pos #" << std::distance(idsOfSelectBg,it) << " value is " << *it << " not in [0," << nbOfTuples << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } srcArrIndexPtr=srcArrIndex->getConstPointer(); @@ -11207,13 +11207,13 @@ void MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx(const int *idsOfSelectBg, c else { std::ostringstream oss; oss << "MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx : On pos #" << std::distance(idsOfSelectBg,it) << " id (idsOfSelectBg[" << std::distance(idsOfSelectBg,it)<< "]) is " << *it << " arrIndxIn[id+1]-arrIndxIn[id]!=srcArrIndex[pos+1]-srcArrIndex[pos] !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } else { std::ostringstream oss; oss << "MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx : On pos #" << std::distance(idsOfSelectBg,it) << " value is " << *it << " not in [0," << nbOfTuples << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -11282,7 +11282,7 @@ DataArrayInt *MEDCouplingUMesh::ComputeSpreadZoneGraduallyFromSeedAlg(std::vecto if(*seedElt>=0 && *seedEltgetConstPointer(); const int *arrIndxPtr=arrIndxIn->getConstPointer(); @@ -11350,7 +11350,7 @@ void MEDCouplingUMesh::SetPartOfIndexedArraysSlice(int start, int end, int step, else { std::ostringstream oss; oss << "MEDCouplingUMesh::SetPartOfIndexedArraysSlice : On pos #" << i << " value is " << it << " not in [0," << nbOfTuples << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } srcArrIndexPtr=srcArrIndex->getConstPointer(); @@ -11413,13 +11413,13 @@ void MEDCouplingUMesh::SetPartOfIndexedArraysSameIdxSlice(int start, int end, in else { std::ostringstream oss; oss << "MEDCouplingUMesh::SetPartOfIndexedArraysSameIdxSlice : On pos #" << i << " id (idsOfSelectBg[" << i << "]) is " << it << " arrIndxIn[id+1]-arrIndxIn[id]!=srcArrIndex[pos+1]-srcArrIndex[pos] !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } else { std::ostringstream oss; oss << "MEDCouplingUMesh::SetPartOfIndexedArraysSameIdxSlice : On pos #" << i << " value is " << it << " not in [0," << nbOfTuples << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py index 534079086..ad084d3d0 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py @@ -4332,7 +4332,50 @@ class MEDCouplingBasicsTest5(unittest.TestCase): self.assertTrue(rd.isEqual(DataArrayInt([0,4,0,3,0,2,0,2,0,0,1,2,1,2,1,6,1,5,1,1,2,8,2,7,3,3,4,4,5,5,6,6,7,7,8,8]))) self.assertTrue(rdi.isEqual(DataArrayInt([0,2,4,6,8,9,10,12,14,16,18,19,20,22,24,25,27,28,29,31,33,35,36]))) pass - + + def testFieldIntIsOnStage2(self): + """ Very important test to check that isEqual of MEDCouplingFieldInt is OK !""" + m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1,2,3,4])) + m1=m1.buildUnstructured() ; m1.setName("mesh") + f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setMesh(m1) + arr1=DataArrayInt([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr1.setInfoOnComponents(["aa","bbb"]) + f1.setArray(arr1) ; f1.setName("f1") ; f1.setTime(2.,3,4) + # + m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1,2,3,4])) + m2=m2.buildUnstructured() ; m2.setName("mesh") + f2=MEDCouplingFieldInt(ON_CELLS) ; f2.setMesh(m2) + arr2=DataArrayInt([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr2.setInfoOnComponents(["aa","bbb"]) + f2.setArray(arr2) ; f2.setName("f1") ; f2.setTime(2.,3,4) + # + self.assertTrue(f1.isEqual(f2,1e-12,0.)) + f1.getArray()[:]*=2 + self.assertTrue(not f1.isEqual(f2,1e-12,0.)) + self.assertTrue(not f1.isEqualWithoutConsideringStr(f2,1e-12,0.)) + f1.getArray()[:]/=2 + self.assertTrue(f1.isEqual(f2,1e-12,0.)) + # + f1.setName("F1") + self.assertTrue(not f1.isEqual(f2,1e-12,0.)) + f1.setName("f1") + self.assertTrue(f1.isEqual(f2,1e-12,0.)) + # + f1.getArray().setInfoOnComponents(["aa","bbbb"]) + self.assertTrue(not f1.isEqual(f2,1e-12,0.)) + self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,0.)) + f1.getArray().setInfoOnComponents(["aa","bbb"]) + self.assertTrue(f1.isEqual(f2,1e-12,0.)) + # + f3=f2.deepCopy() + self.assertTrue(f1.isEqual(f3,1e-12,0.)) + # + for fd,expected in ((ON_NODES,False),(ON_CELLS,True)): + f4=MEDCouplingFieldInt(fd) ; f4.setMesh(m2) ; f4.setTime(2.,3,4) + arr4=DataArrayInt([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr4.setInfoOnComponents(["aa","bbb"]) + f4.setArray(arr4) ; f4.setName("f1") + self.assertEqual(f1.isEqual(f4,1e-12,0.),expected) + pass + pass + pass if __name__ == '__main__': diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 61088db71..eebe898c7 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -184,6 +184,7 @@ using namespace INTERP_KERNEL; %newobject MEDCoupling::MEDCouplingFieldDouble::getEndArray; %newobject MEDCoupling::MEDCouplingFieldDouble::MergeFields; %newobject MEDCoupling::MEDCouplingFieldDouble::MeldFields; +%newobject MEDCoupling::MEDCouplingFieldDouble::convertToIntField; %newobject MEDCoupling::MEDCouplingFieldDouble::doublyContractedProduct; %newobject MEDCoupling::MEDCouplingFieldDouble::determinant; %newobject MEDCoupling::MEDCouplingFieldDouble::eigenValues; @@ -230,7 +231,11 @@ using namespace INTERP_KERNEL; %newobject MEDCoupling::MEDCouplingFieldDouble::cellToNodeDiscretization; %newobject MEDCoupling::MEDCouplingFieldDouble::getValueOnMulti; %newobject MEDCoupling::MEDCouplingFieldInt::New; +%newobject MEDCoupling::MEDCouplingFieldInt::convertToDblField; %newobject MEDCoupling::MEDCouplingFieldInt::getArray; +%newobject MEDCoupling::MEDCouplingFieldInt::deepCopy; +%newobject MEDCoupling::MEDCouplingFieldInt::clone; +%newobject MEDCoupling::MEDCouplingFieldInt::cloneWithMesh; %newobject MEDCoupling::MEDCouplingFieldTemplate::New; %newobject MEDCoupling::MEDCouplingMesh::deepCopy; %newobject MEDCoupling::MEDCouplingMesh::clone; @@ -3773,6 +3778,8 @@ namespace MEDCoupling } }; + class MEDCouplingFieldInt; + class MEDCouplingFieldDouble : public MEDCoupling::MEDCouplingField { public: @@ -3786,6 +3793,7 @@ namespace MEDCoupling std::string simpleRepr() const throw(INTERP_KERNEL::Exception); std::string advancedRepr() const throw(INTERP_KERNEL::Exception); std::string writeVTK(const std::string& fileName, bool isBinary=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *convertToIntField() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *clone(bool recDeepCpy) const; MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const; MEDCouplingFieldDouble *deepCopy() const; @@ -5185,6 +5193,10 @@ namespace MEDCoupling std::string getTimeUnit() const throw(INTERP_KERNEL::Exception); void setTime(double val, int iteration, int order) throw(INTERP_KERNEL::Exception); void setArray(DataArrayInt *array) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *deepCopy() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *clone(bool recDeepCpy) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *cloneWithMesh(bool recDeepCpy) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *convertToDblField() const throw(INTERP_KERNEL::Exception); %extend { MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME) { diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 2b362ece3..648ef3259 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -26,6 +26,7 @@ #include "MEDFileFieldOverView.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingFieldDiscretization.hxx" #include "InterpKernelAutoPtr.hxx" @@ -300,7 +301,7 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !"); if(_type!=ON_GAUSS_PT) { - locIds->setName(oss.str().c_str()); + locIds->setName(oss.str()); glob.appendProfile(locIds); _profile=oss.str(); } @@ -366,7 +367,7 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& if(locIds) { MCAuto da5=locIds->selectByTupleId(da3->begin(),da3->end()); - da5->setName(oss.str().c_str()); + da5->setName(oss.str()); glob.appendProfile(da5); _profile=oss.str(); } @@ -374,7 +375,7 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& { if(!da3->isIota(nbOfEltsInWholeMesh)) { - da3->setName(oss.str().c_str()); + da3->setName(oss.str()); glob.appendProfile(da3); _profile=oss.str(); } @@ -468,7 +469,7 @@ void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const if(_end-_start!=nbValsInFile*nbi) { std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : The number of tuples to read is " << nbValsInFile << "*" << nbi << " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr)); } @@ -584,12 +585,12 @@ void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileF if(_start<0 || _start>=arr->getNumberOfTuples()) { std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(_end<0 || _end>arr->getNumberOfTuples()) { std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int nbOfCompo(arr->getNumberOfComponents()); DataArrayDouble *arrD(dynamic_cast(arr)); @@ -821,7 +822,7 @@ int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std: { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int *work=ptToFill; if(_profile.empty()) @@ -831,7 +832,7 @@ int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std: const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval; oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } for(int ii=codeOfMesh[3*found+2];iigetNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int offset2=codeOfMesh[3*found+2]; for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++) @@ -1270,11 +1271,25 @@ const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const void MEDFileFieldPerMeshPerType::getDimension(int& dim) const { - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); - int curDim=(int)cm.getDimension(); + const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type)); + int curDim((int)cm.getDimension()); dim=std::max(dim,curDim); } +bool MEDFileFieldPerMeshPerType::isUniqueLevel(int& dim) const +{ + const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type)); + int curDim((int)cm.getDimension()); + if(dim!=std::numeric_limits::max()) + { + if(dim!=curDim) + return false; + } + else + dim=curDim; + return true; +} + void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set& types) const { for(std::vector< MCAuto >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++) @@ -1465,7 +1480,7 @@ MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(locId>=0 && locId<(int)_field_pm_pt_pd.size()) return _field_pm_pt_pd[locId]; @@ -1482,7 +1497,7 @@ const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGive { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(locId>=0 && locId<(int)_field_pm_pt_pd.size()) return _field_pm_pt_pd[locId]; @@ -1775,6 +1790,14 @@ void MEDFileFieldPerMesh::getDimension(int& dim) const (*it)->getDimension(dim); } +bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const +{ + for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + if(!(*it)->isUniqueLevel(dim)) + return false; + return true; +} + void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set& types) const { for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) @@ -2184,7 +2207,7 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField t if(code.empty()) { std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } // std::vector< MCAuto > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end()); @@ -2211,7 +2234,7 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField t { std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes(); oss << " nodes in mesh !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc); } @@ -2237,7 +2260,7 @@ DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, c if(code.empty()) { std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } std::vector< MCAuto > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end()); std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end()); @@ -2257,7 +2280,7 @@ DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, c { std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes(); oss << " nodes in mesh !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl); @@ -2297,7 +2320,7 @@ MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType()); oss << "\"" << cm2.getRepr() << "\", "; } - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const @@ -2315,7 +2338,7 @@ const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAn const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType()); oss << "\"" << cm2.getRepr() << "\", "; } - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type) @@ -2451,7 +2474,7 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileField oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl; oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl; oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } return 0; } @@ -2672,7 +2695,7 @@ void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps) if(!(*it)->isEqual(*_pfls[id])) { std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -2690,7 +2713,7 @@ void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps) if(!(*it)->isEqual(*_locs[id],eps)) { std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -2968,7 +2991,7 @@ int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : "; for(it=_locs.begin();it!=_locs.end();it++) oss << "\"" << (*it)->getName() << "\", "; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } return std::distance(_locs.begin(),it); } @@ -2985,7 +3008,7 @@ const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) co std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : "; for(it=_pfls.begin();it!=_pfls.end();it++) oss << "\"" << (*it)->getName() << "\", "; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } return *it; } @@ -3021,7 +3044,7 @@ DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : "; for(it=_pfls.begin();it!=_pfls.end();it++) oss << "\"" << (*it)->getName() << "\", "; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } return *it; } @@ -3145,7 +3168,7 @@ void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl) if(!pfl->isEqual(*(*it))) { std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } pfl->incrRef(); @@ -3164,7 +3187,7 @@ void MEDFileFieldGlobs::appendLoc(const std::string& locName, INTERP_KERNEL::Nor if(!(*it)->isEqual(*obj,1e-12)) { std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } _locs.push_back(obj); @@ -4260,7 +4283,7 @@ int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& m oss << "Possible meshes are : "; for(std::vector::const_iterator it2=msg.begin();it2!=msg.end();it2++) oss << "\"" << (*it2) << "\" "; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh) @@ -4603,7 +4626,7 @@ void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDou if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples()) { std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } // end of check int start=copyTinyInfoFrom(field,arrOfVals); @@ -4622,7 +4645,7 @@ void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDou if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples()) { std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int start=copyTinyInfoFrom(field,arrOfVals); int pos=addNewEntryIfNecessary(m); @@ -4738,6 +4761,37 @@ bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const return false; } +MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto& arrOut, const MEDFileFieldNameScope& nasc) const +{ + static const char MSG0[]="MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is too complex to be able to extract a field ! Call getFieldOnMeshAtLevel method instead to deal with complexity !"; + if(_field_per_mesh.empty()) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !"); + if(_field_per_mesh.size()>1) + throw INTERP_KERNEL::Exception(MSG0); + if(_field_per_mesh[0].isNull()) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !"); + const MEDFileFieldPerMesh *pm(_field_per_mesh[0]); + std::set types; + pm->fillTypesOfFieldAvailable(types); + if(types.size()!=1) + throw INTERP_KERNEL::Exception(MSG0); + TypeOfField type(*types.begin()); + int meshDimRelToMax(0); + if(type==ON_NODES) + meshDimRelToMax=0; + else + { + int myDim(std::numeric_limits::max()); + bool isUnique(pm->isUniqueLevel(myDim)); + if(!isUnique) + throw INTERP_KERNEL::Exception(MSG0); + meshDimRelToMax=myDim-mesh->getMeshDimension(); + if(meshDimRelToMax>0) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !"); + } + return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc); +} + /*! * Returns a new MEDCouplingFieldDouble of given type lying on a given support. * \param [in] type - a spatial discretization of the new field. @@ -4792,8 +4846,7 @@ MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOf MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto& arrOut, const MEDFileFieldNameScope& nasc) const { MCAuto m(mesh->getMeshAtLevel(meshDimRelToMax,false)); - const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax); - const DataArrayInt *e=mesh->getNumberFieldAtLevel(1); + const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1)); if(meshDimRelToMax==1) (static_cast((MEDCouplingMesh *)m))->setMeshDimension(0); return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc); @@ -4878,7 +4931,7 @@ MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel( { std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field "; oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } MEDCouplingFieldDiscretization *disc=ret->getDiscretization(); if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !"); @@ -4901,7 +4954,7 @@ MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel( { std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field "; oss << "\"" << nasc.getName() << "\" not defined on all nodes !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } MCAuto nodeRenumSafe=nodeRenum->checkAndPreparePermutation(); if(!dynamic_cast((DataArray *)arrOut)) @@ -5438,7 +5491,7 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_i default: { std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } ret->setDtUnit(dtunit.c_str()); @@ -5492,7 +5545,7 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_i default: { std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } ret->setDtUnit(dtunit.c_str()); @@ -5501,7 +5554,7 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_i if(nbSteps<1) { std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } // med_int numdt,numit; @@ -5603,7 +5656,7 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_i default: { std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName,iteration,order) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } ret->setDtUnit(dtunit.c_str()); @@ -5629,7 +5682,7 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_i std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : "; for(std::vector< std::pair >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++) oss << "(" << (*iter).first << "," << (*iter).second << "), "; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(loadAll) ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0); @@ -5679,7 +5732,7 @@ int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, const std::string& fileNam if(fieldIdCFormat>=nbFields) { std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1)); @@ -5725,7 +5778,7 @@ int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fileName std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : "; for(std::vector::const_iterator it=fns.begin();it!=fns.end();it++) oss << "\"" << *it << "\" "; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } return nbOfStep2; } @@ -5763,7 +5816,7 @@ void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTE else { std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } @@ -5801,7 +5854,7 @@ void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_K else { std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } @@ -6347,9 +6400,9 @@ void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAut { if(!f) throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !"); - if(!((DataArray*)arr)) + if(arr.isNull()) throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !"); - DataArrayDouble *arrOutC=dynamic_cast((DataArray*)arr); + DataArrayDouble *arrOutC(dynamic_cast((DataArray*)arr)); if(!arrOutC) throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !"); f->setArray(arrOutC); @@ -6357,9 +6410,9 @@ void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAut DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto& arr) { - if(!((DataArray*)arr)) + if(arr.isNull()) throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !"); - DataArrayDouble *arrOutC=dynamic_cast((DataArray*)arr); + DataArrayDouble *arrOutC(dynamic_cast((DataArray*)arr)); if(!arrOutC) throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !"); arrOutC->incrRef(); @@ -6452,6 +6505,23 @@ MEDFileField1TS::MEDFileField1TS() _content=new MEDFileField1TSWithoutSDA; } +/*! + * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance + * method should be called (getFieldOnMeshAtLevel for example). + * But for normal usage of field in MED file world this method is the most efficient to fetch data. + * + * \param [in] mesh - the mesh the field is lying on + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * caller is to delete this field using decrRef() as it is no more needed. + */ +MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const +{ + MCAuto arrOut; + MCAuto ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull())); + MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); + return ret.retn(); +} + /*! * Returns a new MEDCouplingFieldDouble of a given type lying on * mesh entities of a given dimension of the first mesh in MED file. If \a this field @@ -6480,7 +6550,7 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int m if(getFileName().empty()) throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); MCAuto arrOut; - MCAuto ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()); + MCAuto ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull())); MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); return ret.retn(); } @@ -6512,7 +6582,7 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, in if(getFileName().empty()) throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !"); MCAuto arrOut; - MCAuto ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()); + MCAuto ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull())); MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); return ret.retn(); } @@ -6540,7 +6610,7 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, in MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const { MCAuto arrOut; - MCAuto ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()); + MCAuto ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull())); MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); return ret.retn(); } @@ -6569,7 +6639,7 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const { MCAuto arrOut; - MCAuto ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()); + MCAuto ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull())); MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); return ret.retn(); } @@ -6605,7 +6675,7 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, co if(getFileName().empty()) throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); MCAuto arrOut; - MCAuto ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()); + MCAuto ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull())); MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); return ret.retn(); } @@ -6808,12 +6878,11 @@ MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const } /*! - * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is + * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is * checked if its elements are sorted suitable for writing to MED file ("STB" stands for * "Sort By Type"), if not, an exception is thrown. * For more info, see \ref AdvMEDLoaderAPIFieldRW - * \param [in] field - the field to add to \a this. The field double values are ignored. - * \param [in] arrOfVals - the values of the field \a field used. + * \param [in] field - the field to add to \a this. * \throw If the name of \a field is empty. * \throw If the data array of \a field is not set. * \throw If the data array is already allocated but has different number of components @@ -6821,14 +6890,15 @@ MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const * \throw If the underlying mesh of \a field has no name. * \throw If elements in the mesh are not in the order suitable for writing to the MED file. */ -void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) +void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field) { + MCAuto field2(ConvertFieldIntToFieldDouble(field)); setFileName(""); - contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull()); + contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull()); } /*! - * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense + * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense * can be an aggregation of several MEDCouplingFieldDouble instances. * The mesh support of input parameter \a field is ignored here, it can be NULL. * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax, @@ -6837,8 +6907,7 @@ void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *fiel * This method will check that the field based on the computed support is coherent. If not an exception will be thrown. * A new profile is added only if no equal profile is missing. * For more info, see \ref AdvMEDLoaderAPIFieldRW - * \param [in] field - the field to add to \a this. The field double values and mesh support are ignored. - * \param [in] arrOfVals - the values of the field \a field used. + * \param [in] field - the field to add to \a this. * \param [in] mesh - the supporting mesh of \a field. * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES). * \param [in] profile - ids of mesh entities on which corresponding field values lie. @@ -6850,10 +6919,11 @@ void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *fiel * \throw If elements in \a mesh are not in the order suitable for writing to the MED file. * \sa setFieldNoProfileSBT() */ -void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) +void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) { + MCAuto field2(ConvertFieldIntToFieldDouble(field)); setFileName(""); - contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull()); + contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull()); } const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const @@ -6867,43 +6937,78 @@ const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const return ret; } -MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const { if(getFileName().empty()) throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); - MCAuto arrOut2; - MCAuto ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull()); - DataArrayInt *arrOutC=dynamic_cast((DataArray *)arrOut2); - if(!arrOutC) - throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !"); - arrOut=arrOutC; - arrOut->incrRef(); // arrOut2 dies at the end of the func - return ret.retn(); + MCAuto arrOut; + MCAuto ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull())); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); } DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto& arr) { - if(!((DataArray *)arr)) + if(arr.isNull()) throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !"); - DataArrayInt *arrC=dynamic_cast((DataArray *)arr); + DataArrayInt *arrC(dynamic_cast((DataArray *)arr)); if(!arrC) throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !"); arrC->incrRef(); return arrC; } +MCAuto MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto& arr) +{ + int t1,t2; + double t0(f->getTime(t1,t2)); + MCAuto arr2(DynamicCastSafe(arr)); + MCAuto ft(MEDCouplingFieldTemplate::New(*f)); + MCAuto ret(MEDCouplingFieldInt::New(*ft)); + ret->setTime(t0,t1,t2); ret->setArray(arr2); + return ret.retn(); +} + +MCAuto MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f) +{ + if(!f) + throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !"); + int t1,t2; + double t0(f->getTime(t1,t2)); + MCAuto ft(MEDCouplingFieldTemplate::New(*f)); + MCAuto ret(MEDCouplingFieldDouble::New(*ft)); + ret->setTime(t0,t1,t2); + return ret; +} + MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map >& extractDef, MEDFileMesh *mm) const { throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !"); } /*! - * Returns a new MEDCouplingFieldDouble of a given type lying on + * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance + * method should be called (getFieldOnMeshAtLevel for example). + * But for normal usage of field in MED file world this method is the most efficient to fetch data. + * + * \param [in] mesh - the mesh the field is lying on + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The + * caller is to delete this field using decrRef() as it is no more needed. + */ +MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const +{ + MCAuto arrOut; + MCAuto ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull())); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); +} + +/*! + * Returns a new MEDCouplingFieldInt of a given type lying on * the top level cells of the first mesh in MED file. If \a this field * has not been constructed via file reading, an exception is thrown. * For more info, see \ref AdvMEDLoaderAPIFieldRW * \param [in] type - a spatial discretization of interest. - * \param [out] arrOut - the DataArrayInt containing values of field. * \param [in] renumPol - specifies how to permute values of the result field according to * the optional numbers of cells and nodes, if any. The valid values are * - 0 - do not permute. @@ -6911,7 +7016,7 @@ MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map arr; - MCAuto ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + MCAuto arrOut; + MCAuto ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull())); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); } /*! - * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh. + * Returns a new MEDCouplingFieldInt of given type lying on a given mesh. * For more info, see \ref AdvMEDLoaderAPIFieldRW * \param [in] type - a spatial discretization of the new field. * \param [in] mesh - the supporting mesh. - * \param [out] arrOut - the DataArrayInt containing values of field. * \param [in] renumPol - specifies how to permute values of the result field according to * the optional numbers of cells and nodes, if any. The valid values are * - 0 - do not permute. @@ -6943,7 +7047,7 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, * - 2 - permute nodes. * - 3 - permute cells and nodes. * - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The * caller is to delete this field using decrRef() as it is no more needed. * \throw If no field of \a this is lying on \a mesh. * \throw If the mesh is empty. @@ -6951,20 +7055,19 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, * \sa getFieldAtLevel() * \sa getFieldOnMeshAtLevel() */ -MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const { - MCAuto arr; - MCAuto ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + MCAuto arrOut; + MCAuto ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull())); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); } /*! - * Returns a new MEDCouplingFieldDouble of a given type lying on a given support. + * Returns a new MEDCouplingFieldInt of a given type lying on a given support. * For more info, see \ref AdvMEDLoaderAPIFieldRW * \param [in] type - a spatial discretization of interest. * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities. - * \param [out] arrOut - the DataArrayInt containing values of field. * \param [in] mesh - the supporting mesh. * \param [in] renumPol - specifies how to permute values of the result field according to * the optional numbers of cells and nodes, if any. The valid values are @@ -6973,7 +7076,7 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField ty * - 2 - permute nodes. * - 3 - permute cells and nodes. * - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The * caller is to delete this field using decrRef() as it is no more needed. * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh. * \throw If no field of \a this is lying on \a mesh. @@ -6981,12 +7084,12 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField ty * \sa getFieldAtLevel() * \sa getFieldOnMeshAtLevel() */ -MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const { - MCAuto arr; - MCAuto ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + MCAuto arrOut; + MCAuto ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull())); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); } /*! @@ -6998,7 +7101,6 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField ty * \param [in] type - a spatial discretization of interest. * \param [in] mName - a name of the supporting mesh. * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities. - * \param [out] arrOut - the DataArrayInt containing values of field. * \param [in] renumPol - specifies how to permute values of the result field according to * the optional numbers of cells and nodes, if any. The valid values are * - 0 - do not permute. @@ -7006,7 +7108,7 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField ty * - 2 - permute nodes. * - 3 - permute cells and nodes. * - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The * caller is to delete this field using decrRef() as it is no more needed. * \throw If the MED file is not readable. * \throw If there is no mesh named \a mName in the MED file. @@ -7016,14 +7118,14 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField ty * \throw If no field values of the given \a type or given \a meshDimRelToMax are available. * \sa getFieldAtLevel() */ -MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const { if(getFileName().empty()) - throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); - MCAuto arr; - MCAuto ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); + MCAuto arrOut; + MCAuto ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); } /*! @@ -7139,7 +7241,7 @@ MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buil { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id; oss << " ! Should be in [0," << sz << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } if(ret->getNumberOfTS()>0) @@ -7177,7 +7279,7 @@ MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buil { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j; oss << " ! Should be in [0," << sz << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } if(ret->getNumberOfTS()>0) @@ -7254,7 +7356,7 @@ int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int orde std::vector< std::pair > vp=getIterations(); for(std::vector< std::pair >::const_iterator it2=vp.begin();it2!=vp.end();it2++) oss << "(" << (*it2).first << "," << (*it2).second << ") "; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const @@ -7364,7 +7466,7 @@ std::vector< std::pair > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeS else { std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } return ret; @@ -7397,7 +7499,7 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope() { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo; oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } cur->copyNameScope(*this); } @@ -7523,7 +7625,7 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, else { std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } for(int iii=0;iii > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const @@ -7641,14 +7743,14 @@ const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::ge if(pos<0 || pos>=(int)_time_steps.size()) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos]; if(item==0) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !"; oss << "\nTry to use following method eraseEmptyTS !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } return item; } @@ -7658,14 +7760,14 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeS if(pos<0 || pos>=(int)_time_steps.size()) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos]; if(item==0) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !"; oss << "\nTry to use following method eraseEmptyTS !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } return item; } @@ -7783,7 +7885,7 @@ std::vector< MCAuto > MEDFileAnyTypeFieldM if(ret1.size()!=sz) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } ts[i]=ret1; } @@ -7807,7 +7909,7 @@ std::vector< MCAuto > MEDFileAnyTypeFieldM if(!timeStep) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } items[i]=timeStep->splitDiscretizations(); } @@ -7858,7 +7960,7 @@ std::vector< MCAuto > MEDFileAnyTypeFieldM if(!timeStep) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } items[i]=timeStep->splitMultiDiscrPerGeoTypes(); if(szOut==std::numeric_limits::max()) @@ -7898,7 +8000,7 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCou { std::ostringstream oss; oss << MSG << "name ! should be \"" << _name; oss << "\" and it is set in input field to \"" << field->getName() << "\" !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(!arr) throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !"); @@ -7912,7 +8014,7 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::v { std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and "; oss << " number of components of element to append (" << compos.size() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(_infos!=compos) { @@ -7921,7 +8023,7 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::v oss << " But compo in input fields are : "; std::copy(compos.begin(),compos.end(),std::ostream_iterator(oss,", ")); oss << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } @@ -7937,7 +8039,7 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() con { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to "; oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -7974,7 +8076,7 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto=sz) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts); if(tsPtr) @@ -7982,7 +8084,7 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAutogetNumberOfComponents()!=(int)_infos.size()) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } _time_steps[i]=ts; @@ -8124,7 +8226,7 @@ MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFr default: { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } ret->setDtUnit(dtunit.c_str()); @@ -8154,7 +8256,7 @@ MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFr default: { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } ret->setDtUnit(dtunit.c_str()); @@ -8921,12 +9023,12 @@ int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiT if(f0->getMeshName()!=mesh->getName()) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(f1->getMeshName()!=mesh->getName()) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } int nts=f0->getNumberOfTS(); if(nts!=f1->getNumberOfTS()) @@ -8950,17 +9052,17 @@ int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiT if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder()) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh time step (" << f0cur->getMeshIteration() << ","<< f0cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder()) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh time step (" << f1cur->getMeshIteration() << ","<< f1cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder()) { std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : all the time steps must be the same ! it is not the case (" << f0cur->getIteration() << "," << f0cur->getOrder() << ")!=(" << f1cur->getIteration() << "," << f1cur->getOrder() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } return nts; @@ -9116,7 +9218,7 @@ MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const if(!item) { std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } const MEDFileField1TSWithoutSDA *itemC=dynamic_cast(item); if(itemC) @@ -9126,7 +9228,7 @@ MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const return ret.retn(); } std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } /*! @@ -9195,6 +9297,26 @@ MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type return ret.retn(); } +/*! + * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance + * method should be called (getFieldOnMeshAtLevel for example). + * But for normal usage of field in MED file world this method is the most efficient to fetch data. + * + * \param [in] iteration - the iteration number of a required time step. + * \param [in] order - the iteration order number of required time step. + * \param [in] mesh - the mesh the field is lying on + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * caller is to delete this field using decrRef() as it is no more needed. + */ +MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const +{ + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); + MCAuto arrOut; + MCAuto ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase())); + MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); + return ret.retn(); +} + /*! * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on * a given support. @@ -9219,7 +9341,7 @@ MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type */ MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const { - const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order); + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast(&myF1TS); if(!myF1TSC) throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !"); @@ -9563,14 +9685,36 @@ void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS * } /*! - * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on + * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance + * method should be called (getFieldOnMeshAtLevel for example). + * But for normal usage of field in MED file world this method is the most efficient to fetch data. + * + * \param [in] iteration - the iteration number of a required time step. + * \param [in] order - the iteration order number of required time step. + * \param [in] mesh - the mesh the field is lying on + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The + * caller is to delete this field using decrRef() as it is no more needed. + */ +MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const +{ + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); + const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast(&myF1TS)); + if(!myF1TSC) + throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !"); + MCAuto arrOut; + MCAuto ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase())); + MCAuto ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); +} + +/*! + * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on * mesh entities of a given dimension of the first mesh in MED file. * For more info, see \ref AdvMEDLoaderAPIFieldRW * \param [in] type - a spatial discretization of interest. * \param [in] iteration - the iteration number of a required time step. * \param [in] order - the iteration order number of required time step. * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities. - * \param [out] arrOut - the DataArrayInt containing values of field. * \param [in] renumPol - specifies how to permute values of the result field according to * the optional numbers of cells and nodes, if any. The valid values are * - 0 - do not permute. @@ -9578,33 +9722,32 @@ void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS * * - 2 - permute nodes. * - 3 - permute cells and nodes. * - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The * caller is to delete this field using decrRef() as it is no more needed. * \throw If the MED file is not readable. * \throw If there is no mesh in the MED file. * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh. * \throw If no field values of the required parameters are available. */ -MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const { - const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order); - const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast(&myF1TS); + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); + const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast(&myF1TS)); if(!myF1TSC) throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !"); MCAuto arr; - MCAuto ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + MCAuto ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase())); + MCAuto ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr)); + return ret2.retn(); } /*! - * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on + * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on * the top level cells of the first mesh in MED file. * For more info, see \ref AdvMEDLoaderAPIFieldRW * \param [in] type - a spatial discretization of interest. * \param [in] iteration - the iteration number of a required time step. * \param [in] order - the iteration order number of required time step. - * \param [out] arrOut - the DataArrayInt containing values of field. * \param [in] renumPol - specifies how to permute values of the result field according to * the optional numbers of cells and nodes, if any. The valid values are * - 0 - do not permute. @@ -9612,32 +9755,31 @@ MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type * - 2 - permute nodes. * - 3 - permute cells and nodes. * - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The * caller is to delete this field using decrRef() as it is no more needed. * \throw If the MED file is not readable. * \throw If there is no mesh in the MED file. * \throw If no field values of the required parameters are available. */ -MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const { - const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order); - const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast(&myF1TS); + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); + const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast(&myF1TS)); if(!myF1TSC) throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !"); MCAuto arr; - MCAuto ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + MCAuto ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase())); + MCAuto ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr)); + return ret2.retn(); } /*! - * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on + * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on * a given support. * For more info, see \ref AdvMEDLoaderAPIFieldRW * \param [in] type - a spatial discretization of interest. * \param [in] iteration - the iteration number of a required time step. * \param [in] order - the iteration order number of required time step. - * \param [out] arrOut - the DataArrayInt containing values of field. * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities. * \param [in] mesh - the supporting mesh. * \param [in] renumPol - specifies how to permute values of the result field according to @@ -9647,26 +9789,26 @@ MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField t * - 2 - permute nodes. * - 3 - permute cells and nodes. * - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The * caller is to delete this field using decrRef() as it is no more needed. * \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh. * \throw If no field of \a this is lying on \a mesh. * \throw If no field values of the required parameters are available. */ -MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const { - const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order); - const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast(&myF1TS); + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); + const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast(&myF1TS)); if(!myF1TSC) - throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !"); + throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !"); MCAuto arr; - MCAuto ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + MCAuto ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase())); + MCAuto ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr)); + return ret2.retn(); } /*! - * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a + * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a * given support. * For more info, see \ref AdvMEDLoaderAPIFieldRW * \param [in] type - a spatial discretization of the new field. @@ -9681,21 +9823,21 @@ MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfFiel * - 2 - permute nodes. * - 3 - permute cells and nodes. * - * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The * caller is to delete this field using decrRef() as it is no more needed. * \throw If no field of \a this is lying on \a mesh. * \throw If no field values of the required parameters are available. */ -MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const { - const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order); - const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast(&myF1TS); + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); + const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast(&myF1TS)); if(!myF1TSC) throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !"); MCAuto arr; - MCAuto ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + MCAuto ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase())); + MCAuto ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr)); + return ret2.retn(); } /*! @@ -9703,16 +9845,16 @@ MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfFiel * This method is called 'old' because the user should give the mesh name he wants to use for it's field. * This method is useful for MED2 file format when field on different mesh was autorized. */ -MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const +MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const { - const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order); - const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast(&myF1TS); + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); + const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast(&myF1TS)); if(!myF1TSC) throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !"); MCAuto arr; - MCAuto ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()); - arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); - return ret.retn(); + MCAuto ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase())); + MCAuto ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr)); + return ret2.retn(); } /*! @@ -9758,7 +9900,7 @@ MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const if(!item) { std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast(item); if(itemC) @@ -9768,11 +9910,11 @@ MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const return ret.retn(); } std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } /*! - * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of + * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of * the given field is checked if its elements are sorted suitable for writing to MED file * ("STB" stands for "Sort By Type"), if not, an exception is thrown. * For more info, see \ref AdvMEDLoaderAPIFieldRW @@ -9783,9 +9925,10 @@ MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const * \throw If the underlying mesh of \a field has no name. * \throw If elements in the mesh are not in the order suitable for writing to the MED file. */ -void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) +void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field) { - contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this); + MCAuto field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field)); + contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this); } /*! @@ -9810,9 +9953,10 @@ void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDoubl * \throw If elements in \a mesh are not in the order suitable for writing to the MED file. * \sa setFieldNoProfileSBT() */ -void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) +void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) { - contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this); + MCAuto field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field)); + contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this); } const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const @@ -9980,7 +10124,7 @@ std::vector MEDFileFields::getFieldsNames() const else { std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } return ret; @@ -10075,7 +10219,7 @@ try:MEDFileFieldGlobsReal(fileName) default: { std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << fileName << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } } } @@ -10096,7 +10240,7 @@ void MEDFileFields::writeLL(med_idt fid) const if(!elt) { std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } elt->writeLL(fid,*this); } @@ -10290,7 +10434,7 @@ void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds) if(*i<0 || *i>=(int)_fields.size()) { std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } b[*i]=false; } @@ -10313,7 +10457,7 @@ void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step) if(k<0 || k>=(int)_fields.size()) { std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } b[k]=false; } @@ -10378,7 +10522,7 @@ MEDFileFields *MEDFileFields::extractPart(const std::map fmtsOut(fmts->extractPart(extractDef,mm)); fsOut->pushField(fmtsOut); @@ -10391,7 +10535,7 @@ MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const if(i<0 || i>=(int)_fields.size()) { std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i]; if(!fmts) @@ -10406,7 +10550,7 @@ MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const else { std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } ret->shallowCpyGlobs(*this); return ret.retn(); @@ -10428,7 +10572,7 @@ MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endId if(*i<0 || *i>=(int)_fields.size()) { std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } fields[j]=_fields[*i]; } @@ -10564,7 +10708,7 @@ int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : "; std::copy(poss.begin(),poss.end(),std::ostream_iterator(oss,", ")); oss << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + throw INTERP_KERNEL::Exception(oss.str()); } MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0) diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index f12ef235d..a748d0b09 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -28,6 +28,7 @@ #include "MCAuto.hxx" #include "MEDCouplingRefCountObject.hxx" +#include "MEDCouplingFieldInt.hxx" #include "MEDCouplingMemArray.hxx" #include "NormalizedUnstructuredMesh.hxx" @@ -192,6 +193,7 @@ namespace MEDCoupling void loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc); void writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const; void getDimension(int& dim) const; + bool isUniqueLevel(int& dim) const; void fillTypesOfFieldAvailable(std::set& types) const; void fillFieldSplitedByType(std::vector< std::pair >& dads, std::vector& types, std::vector& pfls, std::vector& locs) const; int getIteration() const; @@ -255,6 +257,7 @@ namespace MEDCoupling void fillTypesOfFieldAvailable(std::set& types) const; std::vector< std::vector< std::pair > > getFieldSplitedByType(std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const; void getDimension(int& dim) const; + bool isUniqueLevel(int& dim) const; double getTime() const; int getIteration() const; int getOrder() const; @@ -517,6 +520,7 @@ namespace MEDCoupling MEDLOADER_EXPORT virtual DataArray *getOrCreateAndGetArray() = 0; MEDLOADER_EXPORT virtual const DataArray *getOrCreateAndGetArray() const = 0; public: + MEDLOADER_EXPORT MEDCouplingFieldDouble *fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto& arrOut, const MEDFileFieldNameScope& nasc) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto &arrOut, const MEDFileFieldNameScope& nasc) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto &arrOut, const MEDFileFieldNameScope& nasc) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto &arrOut, const MEDFileFieldNameScope& nasc) const; @@ -726,6 +730,7 @@ namespace MEDCoupling MEDLOADER_EXPORT static MEDFileField1TS *New(); MEDLOADER_EXPORT MEDFileIntField1TS *convertToInt(bool isDeepCpyGlobs=true) const; // + MEDLOADER_EXPORT MEDCouplingFieldDouble *field(const MEDFileMesh *mesh) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const; @@ -772,18 +777,21 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileField1TS *convertToDouble(bool isDeepCpyGlobs=true) const; MEDLOADER_EXPORT MEDFileAnyTypeField1TS *shallowCpy() const; // - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *field(const MEDFileMesh *mesh) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol=0) const; MEDLOADER_EXPORT DataArrayInt *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const; // - MEDLOADER_EXPORT void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals); - MEDLOADER_EXPORT void setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile); + MEDLOADER_EXPORT void setFieldNoProfileSBT(const MEDCouplingFieldInt *field); + MEDLOADER_EXPORT void setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile); MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArray() const; public: MEDLOADER_EXPORT static DataArrayInt *ReturnSafelyDataArrayInt(MCAuto& arr); + MEDLOADER_EXPORT static MCAuto SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto& arr); + MEDLOADER_EXPORT static MCAuto ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f); public: MEDLOADER_EXPORT MEDFileIntField1TS *extractPart(const std::map >& extractDef, MEDFileMesh *mm) const; private: @@ -1029,6 +1037,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileAnyTypeField1TS *getTimeStep(int iteration, int order) const; MEDLOADER_EXPORT MEDFileAnyTypeField1TS *getTimeStepGivenTime(double time, double eps=1e-8) const; // + MEDLOADER_EXPORT MEDCouplingFieldDouble *field(int iteration, int order, const MEDFileMesh *mesh) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const; @@ -1070,15 +1079,16 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileAnyTypeField1TS *getTimeStepAtPos(int pos) const; MEDLOADER_EXPORT MEDFileFieldMultiTS *convertToDouble(bool isDeepCpyGlobs=true) const; // - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol=0) const; - MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *field(int iteration, int order, const MEDFileMesh *mesh) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol=0) const; + MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol=0) const; MEDLOADER_EXPORT DataArrayInt *getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const; // - MEDLOADER_EXPORT void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals); - MEDLOADER_EXPORT void appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile); + MEDLOADER_EXPORT void appendFieldNoProfileSBT(const MEDCouplingFieldInt *field); + MEDLOADER_EXPORT void appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile); // MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArray(int iteration, int order) const; public: diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 08396b5bf..b50ddecbf 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -159,6 +159,7 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::buildNewEmpty; %newobject MEDCoupling::MEDFileFieldMultiTS::New; %newobject MEDCoupling::MEDFileFieldMultiTS::LoadSpecificEntities; +%newobject MEDCoupling::MEDFileFieldMultiTS::field; %newobject MEDCoupling::MEDFileFieldMultiTS::getFieldAtLevel; %newobject MEDCoupling::MEDFileFieldMultiTS::getFieldAtTopLevel; %newobject MEDCoupling::MEDFileFieldMultiTS::getFieldOnMeshAtLevel; @@ -166,15 +167,21 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileFieldMultiTS::getUndergroundDataArray; %newobject MEDCoupling::MEDFileFieldMultiTS::convertToInt; %newobject MEDCoupling::MEDFileIntFieldMultiTS::New; +%newobject MEDCoupling::MEDFileIntFieldMultiTS::field; %newobject MEDCoupling::MEDFileIntFieldMultiTS::LoadSpecificEntities; %newobject MEDCoupling::MEDFileIntFieldMultiTS::getUndergroundDataArray; %newobject MEDCoupling::MEDFileIntFieldMultiTS::convertToDouble; +%newobject MEDCoupling::MEDFileIntFieldMultiTS::getFieldAtLevel; +%newobject MEDCoupling::MEDFileIntFieldMultiTS::getFieldAtTopLevel; +%newobject MEDCoupling::MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel; +%newobject MEDCoupling::MEDFileIntFieldMultiTS::getFieldAtLevelOld; %newobject MEDCoupling::MEDFileAnyTypeField1TS::New; %newobject MEDCoupling::MEDFileAnyTypeField1TS::shallowCpy; %newobject MEDCoupling::MEDFileAnyTypeField1TS::deepCopy; %newobject MEDCoupling::MEDFileAnyTypeField1TS::extractPart; %newobject MEDCoupling::MEDFileField1TS::New; +%newobject MEDCoupling::MEDFileField1TS::field; %newobject MEDCoupling::MEDFileField1TS::getFieldAtLevel; %newobject MEDCoupling::MEDFileField1TS::getFieldAtTopLevel; %newobject MEDCoupling::MEDFileField1TS::getFieldOnMeshAtLevel; @@ -183,6 +190,11 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileField1TS::convertToInt; %newobject MEDCoupling::MEDFileIntField1TS::New; +%newobject MEDCoupling::MEDFileIntField1TS::field; +%newobject MEDCoupling::MEDFileIntField1TS::getFieldAtLevel; +%newobject MEDCoupling::MEDFileIntField1TS::getFieldAtTopLevel; +%newobject MEDCoupling::MEDFileIntField1TS::getFieldOnMeshAtLevel; +%newobject MEDCoupling::MEDFileIntField1TS::getFieldAtLevelOld; %newobject MEDCoupling::MEDFileIntField1TS::getUndergroundDataArray; %newobject MEDCoupling::MEDFileIntField1TS::convertToDouble; @@ -1991,6 +2003,7 @@ namespace MEDCoupling static MEDFileField1TS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception); static MEDFileField1TS *New(); MEDCoupling::MEDFileIntField1TS *convertToInt(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *field(const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); @@ -2126,8 +2139,14 @@ namespace MEDCoupling static MEDFileIntField1TS *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true) throw(INTERP_KERNEL::Exception); MEDCoupling::MEDFileField1TS *convertToDouble(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); // - void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception); - void setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); + void setFieldNoProfileSBT(const MEDCouplingFieldInt *field) throw(INTERP_KERNEL::Exception); + void setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *field(const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); %extend { MEDFileIntField1TS() throw(INTERP_KERNEL::Exception) @@ -2155,56 +2174,6 @@ namespace MEDCoupling return self->simpleRepr(); } - PyObject *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldAtLevel(type,meshDimRelToMax,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldAtTopLevel(type,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldOnMeshAtLevel(type,meshDimRelToMax,mesh,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldOnMeshAtLevel(type,mesh,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldAtLevelOld(type,mname,meshDimRelToMax,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - PyObject *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception) { DataArrayInt *ret1=0; @@ -2632,6 +2601,7 @@ namespace MEDCoupling static MEDFileFieldMultiTS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception); static MEDFileFieldMultiTS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception); // + MEDCouplingFieldDouble *field(int iteration, int order, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); @@ -2782,9 +2752,15 @@ namespace MEDCoupling static MEDFileIntFieldMultiTS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception); static MEDFileIntFieldMultiTS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception); // - void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception); - void appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); + void appendFieldNoProfileSBT(const MEDCouplingFieldInt *field) throw(INTERP_KERNEL::Exception); + void appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); MEDCoupling::MEDFileFieldMultiTS *convertToDouble(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *field(int iteration, int order, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); %extend { MEDFileIntFieldMultiTS() @@ -2820,56 +2796,6 @@ namespace MEDCoupling return self->simpleRepr(); } - PyObject *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldAtLevel(type,iteration,order,meshDimRelToMax,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldAtTopLevel(type,iteration,order,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldOnMeshAtLevel(type,iteration,order,meshDimRelToMax,mesh,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldOnMeshAtLevel(type,iteration,order,mesh,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1=0; - MEDCouplingFieldDouble *ret0=self->getFieldAtLevelOld(type,iteration,order,mname,meshDimRelToMax,ret1,renumPol); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - PyObject *getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception) { DataArrayInt *ret1=0; diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 69b96d107..0c6efa452 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -2578,8 +2578,7 @@ class MEDLoaderTest3(unittest.TestCase): def testInt32InMEDFileFieldStar1(self): fname="Pyfile63.med" f1=MEDLoaderDataForTest.buildVecFieldOnCells_1(); - arr=f1.getArray().convertToIntArr() - f1.setArray(None) + f1=f1.convertToIntField() m1=f1.getMesh() mm1=MEDFileUMesh.New() mm1.setCoords(m1.getCoords()) @@ -2587,19 +2586,17 @@ class MEDLoaderTest3(unittest.TestCase): mm1.setName(m1.getName()) mm1.write(fname,2) ff1=MEDFileIntField1TS() - ff1.setFieldNoProfileSBT(f1,arr) - a,b=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - self.assertEqual(b.getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]']) - self.assertTrue(b.isEqual(arr)) + ff1.setFieldNoProfileSBT(f1) + a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) + self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]']) self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ff1.write(fname,0) ff2=MEDFileAnyTypeField1TS.New(fname) self.assertEqual(ff2.getName(),"VectorFieldOnCells") self.assertEqual(ff2.getTime(),[0,1,2.0]) self.assertTrue(isinstance(ff2,MEDFileIntField1TS)) - a,b=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - self.assertEqual(b.getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]']) - self.assertTrue(b.isEqual(arr)) + a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1) + self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]']) self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ff2.setTime(1,2,3.) c=ff2.getUndergroundDataArray() ; c*=2 @@ -2608,42 +2605,40 @@ class MEDLoaderTest3(unittest.TestCase): self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)]) self.assertEqual(len(ffs1),2) self.assertTrue(isinstance(ffs1,MEDFileIntFieldMultiTS)) - a,b=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - self.assertTrue(b.isEqual(arr)) + a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1) self.assertTrue(a.isEqual(f1,1e-12,1e-12)) - a,b=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - self.assertTrue(b.isEqual(arr)) + a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1) self.assertTrue(a.isEqual(f1,1e-12,1e-12)) it=ffs1.__iter__() ; it.next() ; ff2bis=it.next() - a,b=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - self.assertTrue(b.isEqual(2*arr)) - f1.setTime(3.,1,2) - self.assertTrue(a.isEqual(f1,1e-12,1e-12)) + a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) + self.assertTrue(a.getArray().isEqual(2*f1.getArray())) + f1.setTime(3.,1,2) ; f1.getArray()[:]*=2 + self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ; f1.getArray()[:]/=2 bc=DataArrayInt(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]']) for it in ffs1: - a,b=it.getFieldOnMeshAtLevel(0,ON_CELLS,mm1) - bc+=b + a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1) + bc+=a.getArray() pass - self.assertTrue(bc.isEqual(3*arr)) - nf1=MEDCouplingFieldDouble(ON_NODES) + self.assertTrue(bc.isEqual(3*f1.getArray())) + nf1=MEDCouplingFieldInt(ON_NODES) nf1.setTime(9.,10,-1) nf1.setMesh(f1.getMesh()) narr=DataArrayInt(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=range(12) ; narr[:,1]=2*narr[:,0] - nf1.setName("VectorFieldOnNodes") + nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr) nff1=MEDFileIntField1TS.New() - nff1.setFieldNoProfileSBT(nf1,narr) + nff1.setFieldNoProfileSBT(nf1) self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]')) self.assertEqual(nff1.getTime(),[10,-1,9.0]) nff1.write(fname,0) # - nf2=MEDCouplingFieldDouble(ON_NODES) + nf2=MEDCouplingFieldInt(ON_NODES) nf2.setTime(19.,20,-11) nf2.setMesh(f1.getMesh()) narr2=DataArrayInt(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=range(8) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0] - nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) + nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2) nff2=MEDFileIntField1TS.New() npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl") - nff2.setFieldProfile(nf2,narr2,mm1,0,npfl) + nff2.setFieldProfile(nf2,mm1,0,npfl) nff2.getFieldWithProfile(ON_NODES,0,mm1) a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName()) self.assertTrue(b.isEqual(npfl)) @@ -2670,8 +2665,8 @@ class MEDLoaderTest3(unittest.TestCase): self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS)) self.assertTrue(isinstance(ffs[3],MEDFileIntFieldMultiTS)) # - self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(arr)) - self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*arr)) + self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray())) + self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray())) self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2)) self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr)) self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12)) @@ -5101,11 +5096,11 @@ class MEDLoaderTest3(unittest.TestCase): fmts=MEDFileIntFieldMultiTS() pflName="PFL" pfl=DataArrayInt([1,3,5]) ; pfl.setName(pflName) - f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(mesh) + f=MEDCouplingFieldInt(ON_CELLS) ; f.setMesh(mesh) fieldName="FieldOnCell" f.setTime(1.2,1,1) ; f.setName(fieldName) - arr=DataArrayInt([101,102,103]) - fmts.appendFieldProfile(f,arr,mm,0,pfl) + arr=DataArrayInt([101,102,103]) ; f.setArray(arr) + fmts.appendFieldProfile(f,mm,0,pfl) # mm.write(fname,2) fmts.write(fname,0) @@ -5120,13 +5115,311 @@ class MEDLoaderTest3(unittest.TestCase): self.assertEqual(pfltest.getName(),pflName) self.assertEqual(ftest.getName(),fieldName) self.assertTrue(ftest.isEqualWithoutConsideringStr(arr)) - ftest2,vals=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm) - self.assertTrue(vals.isEqualWithoutConsideringStr(arr)) + ftest2=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm) + self.assertTrue(ftest2.getArray().isEqualWithoutConsideringStr(arr)) self.assertEqual(ftest2.getTime(),f.getTime()) self.assertEqual(ftest2.getMesh().getNumberOfCells(),len(arr)) pass + def testMEDFileFieldEasyField1(self): + """Check for all spatial discretization of field (cells,nodes,elno,gauss) for double field that all is OK. Here no profile and only top level is considered.""" + ## Basic test on cells on top level + fname="Pyfile101.med" + fieldName="field1" + mm=MEDFileUMesh() + coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)]) + m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) + m.allocateCells() + m.insertNextCell(NORM_TRI3,[0,1,2]) + m.insertNextCell(NORM_TRI3,[3,4,5]) + m.insertNextCell(NORM_TRI3,[6,7,8]) + m.insertNextCell(NORM_TRI3,[9,10,11]) + m.insertNextCell(NORM_QUAD4,[100,101,102,103]) + m.insertNextCell(NORM_QUAD4,[104,105,106,107]) + mm[0]=m + mm.write(fname,2) + arr0=DataArrayDouble([10,11,12,13,100,101]) + f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m) + f.setName(fieldName) ; f.setTime(2.,6,7) + f0=f.deepCopy() + ff=MEDFileFieldMultiTS() ; ff.appendFieldNoProfileSBT(f) + ff.write(fname,0) + arr2=arr0+1000 ; f.setArray(arr2) + f.setTime(3.,8,9) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f) + ff.write(fname,0) + f1=f.deepCopy() + ## + mm=MEDFileMesh.New(fname) + f1ts=MEDFileField1TS(fname,fieldName,6,7) + ftst0=f1ts.field(mm) + self.assertTrue(f0.isEqual(ftst0,1e-12,1e-12)) + f1ts=MEDFileField1TS(fname,fieldName,8,9) + ftst1=f1ts.field(mm) + self.assertTrue(f1.isEqual(ftst1,1e-12,1e-12)) + fmts=MEDFileFieldMultiTS(fname,fieldName) + self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,1e-12)) + ## Basic test on nodes on top level + f2=MEDCouplingFieldDouble(ON_NODES) ; arr2=DataArrayDouble([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24) + f2.setName(fieldName) + mm.write(fname,2) + ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileField1TS(fname,fieldName,23,24) + self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,1e-12)) + fmts=MEDFileFieldMultiTS(fname,fieldName) + self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,1e-12)) + ## Node on elements + f3=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f3.setMesh(m) ; arr3=DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3) + f3.setName(fieldName) ; f3.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileField1TS(fname,fieldName,2,3) + self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12)) + ## Gauss + f4=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName) + f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,1.],[0.1,0.1, 0.2,0.2, 0.3,0.3, 0.4,0.4, 0.5,0.5],[0.2,0.3,0.1,0.05,0.35]) + f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5) + arr4=DataArrayDouble([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4) + f4.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileField1TS(fname,fieldName,4,5) + self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12)) + pass + + def testMEDFileFieldEasyField2(self): + """Same thantestMEDFileFieldEasyField1 except that here intfields are considered. + Check for all spatial discretization of field (cells,nodes,elno,gauss) for int field that all is OK. Here no profile and only top level is considered.""" + ## Basic test on cells on top level + fname="Pyfile102.med" + fieldName="field1" + mm=MEDFileUMesh() + coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)]) + m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) + m.allocateCells() + m.insertNextCell(NORM_TRI3,[0,1,2]) + m.insertNextCell(NORM_TRI3,[3,4,5]) + m.insertNextCell(NORM_TRI3,[6,7,8]) + m.insertNextCell(NORM_TRI3,[9,10,11]) + m.insertNextCell(NORM_QUAD4,[100,101,102,103]) + m.insertNextCell(NORM_QUAD4,[104,105,106,107]) + mm[0]=m + mm.write(fname,2) + arr0=DataArrayInt([10,11,12,13,100,101]) + f=MEDCouplingFieldInt(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m) + f.setName(fieldName) ; f.setTime(2.,6,7) + f0=f.deepCopy() + ff=MEDFileIntFieldMultiTS() ; ff.appendFieldNoProfileSBT(f) + ff.write(fname,0) + arr2=arr0+1000 ; f.setArray(arr2) + f.setTime(3.,8,9) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f) + ff.write(fname,0) + f1=f.deepCopy() + ## + mm=MEDFileMesh.New(fname) + f1ts=MEDFileIntField1TS(fname,fieldName,6,7) + ftst0=f1ts.field(mm) + self.assertTrue(f0.isEqual(ftst0,1e-12,1e-12)) + f1ts=MEDFileIntField1TS(fname,fieldName,8,9) + ftst1=f1ts.field(mm) + self.assertTrue(f1.isEqual(ftst1,1e-12,1e-12)) + fmts=MEDFileIntFieldMultiTS(fname,fieldName) + self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,1e-12)) + ## Basic test on nodes on top level + f2=MEDCouplingFieldInt(ON_NODES) ; arr2=DataArrayInt([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24) + f2.setName(fieldName) + mm.write(fname,2) + ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileIntField1TS(fname,fieldName,23,24) + self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,1e-12)) + fmts=MEDFileIntFieldMultiTS(fname,fieldName) + self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,1e-12)) + ## Node on elements + f3=MEDCouplingFieldInt(ON_GAUSS_NE) ; f3.setMesh(m) ; arr3=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3) + f3.setName(fieldName) ; f3.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileIntField1TS(fname,fieldName,2,3) + self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12)) + ## Gauss + f4=MEDCouplingFieldInt(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName) + f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,1.],[0.1,0.1, 0.2,0.2, 0.3,0.3, 0.4,0.4, 0.5,0.5],[0.2,0.3,0.1,0.05,0.35]) + f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5) + arr4=DataArrayInt([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4) + f4.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileIntField1TS(fname,fieldName,4,5) + self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12)) + pass + + def testMEDFileFieldEasyField3(self): + """Here a multi level mesh. And field on cells lying on different level of this mesh. Show how "field" method deal with that. Here on field double are considered.""" + fname="Pyfile103.med" + fieldName="field1" + mm=MEDFileUMesh() + coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)]) + m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) + m.allocateCells() + m.insertNextCell(NORM_TRI3,[0,1,2]) + m.insertNextCell(NORM_TRI3,[3,4,5]) + m.insertNextCell(NORM_TRI3,[6,7,8]) + m.insertNextCell(NORM_TRI3,[9,10,11]) + m.insertNextCell(NORM_QUAD4,[100,101,102,103]) + m.insertNextCell(NORM_QUAD4,[104,105,106,107]) + mm[-1]=m + m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo) + m0.allocateCells() + m0.insertNextCell(NORM_TETRA4,[3,2,5,0]) + m0.insertNextCell(NORM_TETRA4,[7,6,3,2]) + mm[0]=m0 + mm.write(fname,2) + # start slowly + f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2) + f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,1,2) + self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12)) + # here f1 lying on level -1 not 0 check if "field" method detect it ! + f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)])) + f1.setMesh(mm[-1]) # -1 is very important + f1.setTime(16.,3,4) + f1.checkConsistencyLight() + mm.write(fname,2) + f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,3,4) + self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12)) + # nodes on elements + f3=MEDCouplingFieldDouble(ON_GAUSS_NE) + f3.setMesh(mm[-1]) # this line is important + arr3=DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3) + f3.setName(fieldName) ; f3.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,2,3) + self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12)) + # gauss + f4=MEDCouplingFieldDouble(ON_GAUSS_PT) + f4.setMesh(mm[-1]) # this line is important + f4.setName(fieldName) + f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,1.],[0.1,0.1, 0.2,0.2, 0.3,0.3, 0.4,0.4, 0.5,0.5],[0.2,0.3,0.1,0.05,0.35]) + f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5) + arr4=DataArrayDouble([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4) + f4.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0) + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,4,5) + self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12)) + pass + + def testMEDFileFieldEasyField4(self): + """ Same than testMEDFileFieldEasyField3 but with integers""" + fname="Pyfile104.med" + fieldName="field1" + mm=MEDFileUMesh() + coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)]) + m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) + m.allocateCells() + m.insertNextCell(NORM_TRI3,[0,1,2]) + m.insertNextCell(NORM_TRI3,[3,4,5]) + m.insertNextCell(NORM_TRI3,[6,7,8]) + m.insertNextCell(NORM_TRI3,[9,10,11]) + m.insertNextCell(NORM_QUAD4,[100,101,102,103]) + m.insertNextCell(NORM_QUAD4,[104,105,106,107]) + mm[-1]=m + m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo) + m0.allocateCells() + m0.insertNextCell(NORM_TETRA4,[3,2,5,0]) + m0.insertNextCell(NORM_TETRA4,[7,6,3,2]) + mm[0]=m0 + mm.write(fname,2) + # start slowly + f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2) + f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,1,2) + self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12)) + # here f1 lying on level -1 not 0 check if "field" method detect it ! + f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)])) + f1.setMesh(mm[-1]) # -1 is very important + f1.setTime(16.,3,4) + f1.checkConsistencyLight() + mm.write(fname,2) + f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,3,4) + self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12)) + # nodes on elements + f3=MEDCouplingFieldInt(ON_GAUSS_NE) + f3.setMesh(mm[-1]) # this line is important + arr3=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3) + f3.setName(fieldName) ; f3.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,2,3) + self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12)) + # gauss + f4=MEDCouplingFieldInt(ON_GAUSS_PT) + f4.setMesh(mm[-1]) # this line is important + f4.setName(fieldName) + f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,1.],[0.1,0.1, 0.2,0.2, 0.3,0.3, 0.4,0.4, 0.5,0.5],[0.2,0.3,0.1,0.05,0.35]) + f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5) + arr4=DataArrayInt([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4) + f4.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0) + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,4,5) + self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12)) + pass + + def testMEDFileFieldEasyField5(self): + """More and more difficult now look at how profiles are managed by "field" method.""" + fname="Pyfile105.med" + fieldName="field1" + mm=MEDFileUMesh() + coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)]) + m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) + m.allocateCells() + m.insertNextCell(NORM_TRI3,[0,1,2]) + m.insertNextCell(NORM_TRI3,[3,4,5]) + m.insertNextCell(NORM_TRI3,[6,7,8]) + m.insertNextCell(NORM_TRI3,[9,10,11]) + m.insertNextCell(NORM_QUAD4,[100,101,102,103]) + m.insertNextCell(NORM_QUAD4,[104,105,106,107]) + mm[0]=m + mm.write(fname,2) + pfl=DataArrayInt([0,2,3,5]) ; pfl.setName("pfl") + m2=m.deepCopy()[pfl] ; m2.setName(m.getName()) + # + arr0=DataArrayDouble([10,11,12,13]) + f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m2) + f.setName(fieldName) ; f.setTime(2.,6,7) ; f.checkConsistencyLight() + ff=MEDFileFieldMultiTS() ; ff.appendFieldProfile(f,mm,0,pfl) # ff is a field on profile + ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7) + self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12)) + # more complicated -> multi level + m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo) + m0.allocateCells() + m0.insertNextCell(NORM_TETRA4,[3,2,5,0]) + m0.insertNextCell(NORM_TETRA4,[7,6,3,2]) + mm2=MEDFileUMesh() + mm2[0]=m0 ; mm2[-1]=m + # + ff=MEDFileField1TS() ; ff.setFieldProfile(f,mm2,-1,pfl) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7) + self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12)) + pass + pass if __name__ == "__main__": - unittest.main() + unittest.main() -- 2.39.2