X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingFieldT.txx;h=6e51e5af94ef7b8e6dda2218c967216dbeb6c2dd;hb=ac1df6b0ba8b337555fb39610c89f678d889580d;hp=61e2aa1bf8ffd1fecb0775650d7eb00cafb4dca2;hpb=3531e8f47b047f0176ec094e51ab2474284f3cd9;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingFieldT.txx b/src/MEDCoupling/MEDCouplingFieldT.txx index 61e2aa1bf..6e51e5af9 100644 --- a/src/MEDCoupling/MEDCouplingFieldT.txx +++ b/src/MEDCoupling/MEDCouplingFieldT.txx @@ -117,21 +117,22 @@ namespace MEDCoupling } return ret.retn(); } + + template + bool MEDCouplingFieldT::isEqual(const MEDCouplingFieldT *other, double meshPrec, T valsPrec) const + { + std::string tmp; + return isEqualIfNotWhy(other,meshPrec,valsPrec,tmp); + } template - bool MEDCouplingFieldT::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const + bool MEDCouplingFieldT::isEqualIfNotWhy(const MEDCouplingFieldT *other, double meshPrec, T 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)) + if(!isEqualIfNotWhyProtected(other,meshPrec,reason)) return false; - if(!_time_discr->isEqualIfNotWhy(otherC->_time_discr,T(valsPrec),reason)) + if(!_time_discr->isEqualIfNotWhy(other->_time_discr,T(valsPrec),reason)) { reason.insert(0,"In FieldT time discretizations differ :"); return false; @@ -150,14 +151,13 @@ namespace MEDCoupling * \throw If the spatial discretization of \a this field is NULL. */ template - bool MEDCouplingFieldT::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const + bool MEDCouplingFieldT::isEqualWithoutConsideringStr(const MEDCouplingFieldT *other, double meshPrec, T valsPrec) const { - const MEDCouplingFieldT *otherC(dynamic_cast *>(other)); - if(!otherC) + if(!other) return false; - if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec)) + if(!isEqualWithoutConsideringStrProtected(other,meshPrec)) return false; - if(!_time_discr->isEqualWithoutConsideringStr(otherC->_time_discr,T(valsPrec))) + if(!_time_discr->isEqualWithoutConsideringStr(other->_time_discr,valsPrec)) return false; return true; } @@ -203,6 +203,78 @@ namespace MEDCoupling copyTinyAttrFrom(other); } + /*! + * Permutes values of \a this field according to a given permutation array for cells + * renumbering. The underlying mesh is deeply copied and its cells are also permuted. + * The number of cells remains the same; for that the permutation array \a old2NewBg + * should not contain equal ids. + * ** Warning, this method modifies the mesh aggreagated by \a this (by performing a deep copy ) **. + * + * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is + * to be equal to \a this->getMesh()->getNumberOfCells(). + * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation + * array, so that its maximal cell id to correspond to (be less than) the number + * of cells in mesh. This new array is then used for the renumbering. If \a + * check == \c false, \a old2NewBg is used as is, that is less secure as validity + * of ids in \a old2NewBg is not checked. + * \throw If the mesh is not set. + * \throw If the spatial discretization of \a this field is NULL. + * \throw If \a check == \c true and \a old2NewBg contains equal ids. + * \throw If mesh nature does not allow renumbering (e.g. structured mesh). + * + * \if ENABLE_EXAMPLES + * \ref cpp_mcfielddouble_renumberCells "Here is a C++ example".
+ * \ref py_mcfielddouble_renumberCells "Here is a Python example". + * \endif + */ + template + void MEDCouplingFieldT::renumberCells(const int *old2NewBg, bool check) + { + renumberCellsWithoutMesh(old2NewBg,check); + MCAuto m(_mesh->deepCopy()); + m->renumberCells(old2NewBg,check); + setMesh(m); + updateTime(); + } + + /*! + * Permutes values of \a this field according to a given permutation array for cells + * renumbering. The underlying mesh is \b not permuted. + * The number of cells remains the same; for that the permutation array \a old2NewBg + * should not contain equal ids. + * This method performs a part of job of renumberCells(). The reasonable use of this + * method is only for multi-field instances lying on the same mesh to avoid a + * systematic duplication and renumbering of _mesh attribute. + * \warning Use this method with a lot of care! + * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is + * to be equal to \a this->getMesh()->getNumberOfCells(). + * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation + * array, so that its maximal cell id to correspond to (be less than) the number + * of cells in mesh. This new array is then used for the renumbering. If \a + * check == \c false, \a old2NewBg is used as is, that is less secure as validity + * of ids in \a old2NewBg is not checked. + * \throw If the mesh is not set. + * \throw If the spatial discretization of \a this field is NULL. + * \throw If \a check == \c true and \a old2NewBg contains equal ids. + * \throw If mesh nature does not allow renumbering (e.g. structured mesh). + */ + template + void MEDCouplingFieldT::renumberCellsWithoutMesh(const int *old2NewBg, bool check) + { + if(!_mesh) + throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !"); + if(_type.isNull()) + throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !"); + // + _type->renumberCells(old2NewBg,check); + std::vector< typename MEDCoupling::Traits::ArrayType *> arrays; + timeDiscrSafe()->getArrays(arrays); + std::vector arrays2(arrays.size()); std::copy(arrays.begin(),arrays.end(),arrays2.begin()); + _type->renumberArraysForCell(_mesh,arrays2,old2NewBg,check); + // + updateTime(); + } + /*! * 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. @@ -369,7 +441,7 @@ namespace MEDCoupling } /*! - * Builds a newly created field, that the caller will have the responsability to deal with. + * Builds a newly created field, that the caller will have the responsibility to deal with. * \n This method makes the assumption that \a this field is correctly defined when this method is called (\a this->checkConsistencyLight() returns without any exception thrown), **no check of this will be done**. * \n This method returns a restriction of \a this so that only tuple ids specified in [ \a partBg , \a partEnd ) will be contained in the returned field. * \n Parameter [\a partBg, \a partEnd ) specifies **cell ids whatever the spatial discretization** of \a this ( @@ -432,7 +504,7 @@ namespace MEDCoupling } /*! - * Builds a newly created field, that the caller will have the responsability to deal with (decrRef()). + * Builds a newly created field, that the caller will have the responsibility to deal with (decrRef()). * This method makes the assumption that the field is correctly defined when this method is called, no check of this will be done. * This method returns a restriction of \a this so that only tuples with ids specified in \a part will be contained in the returned field. * Parameter \a part specifies **cell ids whatever the spatial discretization of this** (