X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingFieldDouble.cxx;h=d88b627f2f4fd6628455567f1396282a49fef069;hb=e7835cba1eb17f50ef4e130c2cb8d0f54bc25083;hp=ef7ead1701b771f0bdbfebee86a49fd9b6be218c;hpb=1755dbe71b2fd46cd796464e8aa410d51e033b0d;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index ef7ead170..d88b627f2 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -16,18 +16,20 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Anthony Geay (CEA/DEN) +// Author : Anthony Geay (EDF R&D) #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingFieldT.txx" #include "MEDCouplingFieldInt.hxx" +#include "MEDCouplingFieldFloat.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingTimeDiscretization.hxx" #include "MEDCouplingFieldDiscretization.hxx" #include "MCAuto.txx" #include "MEDCouplingVoronoi.hxx" #include "MEDCouplingNatureOfField.hxx" +#include "MEDCouplingMemArray.txx" #include "InterpKernelAutoPtr.hxx" #include "InterpKernelGaussCoords.hxx" @@ -174,9 +176,9 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::deepCopy() const * \endif * \sa clone() */ -MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const +MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const { - MEDCouplingTimeDiscretization *tdo=timeDiscr()->buildNewTimeReprFromThis(td,deepCopy); + MEDCouplingTimeDiscretization *tdo=timeDiscr()->buildNewTimeReprFromThis(td,deepCpy); MCAuto disc; if(_type) disc=_type->clone(); @@ -188,8 +190,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfT } /*! - * This method converts a field on nodes (\a this) to a cell field (returned field). The convertion is a \b non \b conservative remapping ! - * This method is useful only for users that need a fast convertion from node to cell spatial discretization. The algorithm applied is simply to attach + * This method converts a field on nodes (\a this) to a cell field (returned field). The conversion is a \b non \b conservative remapping ! + * This method is useful only for users that need a fast conversion from node to cell spatial discretization. The algorithm applied is simply to attach * to each cell the average of values on nodes constituting this cell. * * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The @@ -244,8 +246,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::nodeToCellDiscretization() const } /*! - * This method converts a field on cell (\a this) to a node field (returned field). The convertion is a \b non \b conservative remapping ! - * This method is useful only for users that need a fast convertion from cell to node spatial discretization. The algorithm applied is simply to attach + * This method converts a field on cell (\a this) to a node field (returned field). The conversion is a \b non \b conservative remapping ! + * This method is useful only for users that need a fast conversion from cell to node spatial discretization. The algorithm applied is simply to attach * to each node the average of values on cell sharing this node. If \a this lies on a mesh having orphan nodes the values applied on them will be NaN (division by 0.). * * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The @@ -367,76 +369,6 @@ bool MEDCouplingFieldDouble::areCompatibleForMeld(const MEDCouplingFieldDouble * return true; } -/*! - * 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 - */ -void MEDCouplingFieldDouble::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). - */ -void MEDCouplingFieldDouble::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 arrays; - timeDiscr()->getArrays(arrays); - std::vector arrays2(arrays.size()); std::copy(arrays.begin(),arrays.end(),arrays2.begin()); - _type->renumberArraysForCell(_mesh,arrays2,old2NewBg,check); - // - updateTime(); -} - /*! * Permutes values of \a this field according to a given permutation array for node * renumbering. The underlying mesh is deeply copied and its nodes are also permuted. @@ -449,7 +381,7 @@ void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool * \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). - * \throw If values at merged nodes deffer more than \a eps. + * \throw If values at merged nodes differ more than \a eps. * * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_renumberNodes "Here is a C++ example".
@@ -489,7 +421,7 @@ void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg, double eps) * the values differ more than \a eps, an exception is thrown. * \throw If the mesh is not set. * \throw If the spatial discretization of \a this field is NULL. - * \throw If values at merged nodes deffer more than \a eps. + * \throw If values at merged nodes differ more than \a eps. */ void MEDCouplingFieldDouble::renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps) { @@ -522,21 +454,32 @@ DataArrayInt *MEDCouplingFieldDouble::findIdsInRange(double vmin, double vmax) c return getArray()->findIdsInRange(vmin,vmax); } -MEDCouplingFieldInt *MEDCouplingFieldDouble::convertToIntField() const +template +typename Traits::FieldType *ConvertToUField(const MEDCouplingFieldDouble *self) { - MCAuto tmp(MEDCouplingFieldTemplate::New(*this)); + MCAuto tmp(MEDCouplingFieldTemplate::New(*self)); int t1,t2; - double t0(getTime(t1,t2)); - MCAuto ret(MEDCouplingFieldInt::New(*tmp,getTimeDiscretization())); + double t0(self->getTime(t1,t2)); + MCAuto::FieldType > ret(Traits::FieldType::New(*tmp,self->getTimeDiscretization())); ret->setTime(t0,t1,t2); - if(getArray()) + if(self->getArray()) { - MCAuto arr(getArray()->convertToIntArr()); + MCAuto::ArrayType> arr(self->getArray()->convertToOtherTypeOfArr()); ret->setArray(arr); } return ret.retn(); } +MEDCouplingFieldInt *MEDCouplingFieldDouble::convertToIntField() const +{ + return ConvertToUField(this); +} + +MEDCouplingFieldFloat *MEDCouplingFieldDouble::convertToFloatField() const +{ + return ConvertToUField(this); +} + MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingFieldT(type,MEDCouplingTimeDiscretization::New(td)) { } @@ -548,7 +491,7 @@ MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& f { } -MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy):MEDCouplingFieldT(other,deepCopy) +MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCpy):MEDCouplingFieldT(other,deepCpy) { } @@ -616,7 +559,7 @@ double MEDCouplingFieldDouble::getMaxValue() const /*! * Returns the maximal value and all its locations within \a this scalar field. * Only the first of available data arrays is checked. - * \param [out] tupleIds - a new instance of DataArrayInt containg indices of + * \param [out] tupleIds - a new instance of DataArrayInt containing indices of * tuples holding the maximal value. The caller is to delete it using * decrRef() as it is no more needed. * \return double - the maximal value among all values of the first array of \a this filed. @@ -680,7 +623,7 @@ double MEDCouplingFieldDouble::getMinValue() const /*! * Returns the minimal value and all its locations within \a this scalar field. * Only the first of available data arrays is checked. - * \param [out] tupleIds - a new instance of DataArrayInt containg indices of + * \param [out] tupleIds - a new instance of DataArrayInt containing indices of * tuples holding the minimal value. The caller is to delete it using * decrRef() as it is no more needed. * \return double - the minimal value among all values of the first array of \a this filed. @@ -1626,126 +1569,6 @@ double MEDCouplingFieldDouble::getIJK(int cellId, int nodeIdInCell, int compoId) */ //void MEDCouplingFieldDouble::setArrays(const std::vector& arrs) -void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector& tinyInfo) const -{ - tinyInfo.clear(); - timeDiscr()->getTinySerializationStrInformation(tinyInfo); - tinyInfo.push_back(_name); - tinyInfo.push_back(_desc); - tinyInfo.push_back(getTimeUnit()); -} - -/*! - * This method retrieves some critical values to resize and prepare remote instance. - * The first two elements returned in tinyInfo correspond to the parameters to give in constructor. - * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny. - */ -void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector& tinyInfo) const -{ - if(_type.isNull()) - 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)timeDiscr()->getEnum()); - tinyInfo.push_back((int)_nature); - timeDiscr()->getTinySerializationIntInformation(tinyInfo); - std::vector tinyInfo2; - _type->getTinySerializationIntInformation(tinyInfo2); - tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); - tinyInfo.push_back((int)tinyInfo2.size()); -} - -/*! - * This method retrieves some critical values to resize and prepare remote instance. - * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny. - */ -void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector& tinyInfo) const -{ - if(_type.isNull()) - throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !"); - tinyInfo.clear(); - timeDiscr()->getTinySerializationDbleInformation(tinyInfo); - std::vector tinyInfo2; - _type->getTinySerializationDbleInformation(tinyInfo2); - tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); - tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it -} - -/*! - * This method has to be called to the new instance filled by CORBA, MPI, File... - * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied. - * @param dataInt out parameter. If not null the pointer is already owned by \a this after the call of this method. In this case no decrRef must be applied. - * @param arrays out parameter is a vector resized to the right size. The pointers in the vector is already owned by \a this after the call of this method. - * No decrRef must be applied to every instances in returned vector. - * \sa checkForUnserialization - */ -void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector& tinyInfoI, DataArrayInt *&dataInt, std::vector& arrays) -{ - if(_type.isNull()) - throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); - dataInt=0; - std::vector tinyInfoITmp(tinyInfoI); - int sz=tinyInfoITmp.back(); - tinyInfoITmp.pop_back(); - std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); - std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); - timeDiscr()->resizeForUnserialization(tinyInfoI2,arrays); - std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); - _type->resizeForUnserialization(tinyInfoITmp3,dataInt); -} - -/*! - * This method is extremely close to resizeForUnserialization except that here the arrays in \a dataInt and in \a arrays are attached in \a this - * after having checked that size is correct. This method is used in python pickeling context to avoid copy of data. - * \sa resizeForUnserialization - */ -void MEDCouplingFieldDouble::checkForUnserialization(const std::vector& tinyInfoI, const DataArrayInt *dataInt, const std::vector& arrays) -{ - if(_type.isNull()) - throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); - std::vector tinyInfoITmp(tinyInfoI); - int sz=tinyInfoITmp.back(); - tinyInfoITmp.pop_back(); - std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); - std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); - timeDiscr()->checkForUnserialization(tinyInfoI2,arrays); - std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); - _type->checkForUnserialization(tinyInfoITmp3,dataInt); -} - -void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) -{ - if(_type.isNull()) - throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !"); - std::vector tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end()); - // - std::vector tmp(tinyInfoD); - int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it - tmp.pop_back(); - std::vector tmp1(tmp.begin(),tmp.end()-sz); - std::vector tmp2(tmp.end()-sz,tmp.end()); - // - timeDiscr()->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS); - _nature=(NatureOfField)tinyInfoI[2]; - _type->finishUnserialization(tmp2); - int nbOfElemS=(int)tinyInfoS.size(); - _name=tinyInfoS[nbOfElemS-3]; - _desc=tinyInfoS[nbOfElemS-2]; - setTimeUnit(tinyInfoS[nbOfElemS-1]); -} - -/*! - * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller. - * The values returned must be consulted only in readonly mode. - */ -void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector& arrays) const -{ - if(_type.isNull()) - throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !"); - timeDiscr()->getArrays(arrays); - _type->getSerializationIntArray(dataInt); -} - /*! * Tries to set an \a other mesh as the support of \a this field. An attempt fails, if * a current and the \a other meshes are different with use of specified equality @@ -1764,7 +1587,7 @@ void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector @@ -1812,7 +1635,7 @@ void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, * \throw If any of the meshes is not set or is not well defined. * \throw If the two meshes do not match. * \throw If the two fields are not coherent for merge. - * \throw If field values at merged nodes (if any) deffer more than \a eps. + * \throw If field values at merged nodes (if any) differ more than \a eps. * * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_substractInPlaceDM "Here is a C++ example".
@@ -1845,7 +1668,7 @@ void MEDCouplingFieldDouble::substractInPlaceDM(const MEDCouplingFieldDouble *f, * \throw If the mesh is not well defined. * \throw If the spatial discretization of \a this field is NULL. * \throw If the data array is not set. - * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals. + * \throw If field values at merged nodes (if any) differ more than \a epsOnVals. */ bool MEDCouplingFieldDouble::mergeNodes(double eps, double epsOnVals) { @@ -1884,7 +1707,7 @@ bool MEDCouplingFieldDouble::mergeNodes(double eps, double epsOnVals) * \throw If the mesh is not well defined. * \throw If the spatial discretization of \a this field is NULL. * \throw If the data array is not set. - * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals. + * \throw If field values at merged nodes (if any) differ more than \a epsOnVals. */ bool MEDCouplingFieldDouble::mergeNodesCenter(double eps, double epsOnVals) { @@ -1921,7 +1744,7 @@ bool MEDCouplingFieldDouble::mergeNodesCenter(double eps, double epsOnVals) * \throw If the mesh is not well defined. * \throw If the spatial discretization of \a this field is NULL. * \throw If the data array is not set. - * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals. + * \throw If field values at merged nodes (if any) differ more than \a epsOnVals. */ bool MEDCouplingFieldDouble::zipCoords(double epsOnVals) { @@ -1962,7 +1785,7 @@ bool MEDCouplingFieldDouble::zipCoords(double epsOnVals) * \throw If the mesh is not well defined. * \throw If the spatial discretization of \a this field is NULL. * \throw If the data array is not set. - * \throw If field values at merged cells (if any) deffer more than \a epsOnVals. + * \throw If field values at merged cells (if any) differ more than \a epsOnVals. */ bool MEDCouplingFieldDouble::zipConnectivity(int compType, double epsOnVals) { @@ -1972,7 +1795,7 @@ bool MEDCouplingFieldDouble::zipConnectivity(int compType, double epsOnVals) if(_type.isNull()) throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipConnectivity !"); MCAuto meshC2((MEDCouplingUMesh *)meshC->deepCopy()); - int oldNbOfCells=meshC2->getNumberOfCells(); + std::size_t oldNbOfCells(meshC2->getNumberOfCells()); MCAuto arr=meshC2->zipConnectivityTraducer(compType); if(meshC2->getNumberOfCells()!=oldNbOfCells) { @@ -2136,7 +1959,6 @@ MCAuto MEDCouplingFieldDouble::convertQuadraticCellsToLi if(!disc2) throw INTERP_KERNEL::Exception("convertQuadraticCellsToLinear : Not a ON_GAUSS_PT field"); std::set gt2(umesh->getAllGeoTypes()); - const DataArrayDouble *arr(getArray()); std::vector< MCAuto > cellIdsV; std::vector< MCAuto > meshesV; std::vector< MEDCouplingGaussLocalization > glV; @@ -2191,7 +2013,7 @@ MCAuto MEDCouplingFieldDouble::convertQuadraticCellsToLi /*! * This is expected to be a 3 components vector field on nodes (if not an exception will be thrown). \a this is also expected to lie on a MEDCouplingPointSet mesh. - * Finaly \a this is also expected to be consistent. + * Finally \a this is also expected to be consistent. * In these conditions this method returns a newly created field (to be dealed by the caller). * The returned field will also 3 compo vector field be on nodes lying on the same mesh than \a this. * @@ -3100,12 +2922,12 @@ MCAuto MEDCouplingFieldDouble::voronoizeGen(const Voroni ptsInReal=gl.localizePtsInRefCooForEachCell(vorCellsForCurDisc->getCoords(),subMesh); } int nbPtsPerCell(vorCellsForCurDisc->getNumberOfNodes()); - for(std::size_t i=0;i elt(vorCellsForCurDisc->clone(false)); - MCAuto coo(ptsInReal->selectByTupleIdSafeSlice(i*nbPtsPerCell,(i+1)*nbPtsPerCell,1)); - elt->setCoords(coo); - cells[ids[i]]=elt; + MCAuto coo4(ptsInReal->selectByTupleIdSafeSlice(j*nbPtsPerCell,(j+1)*nbPtsPerCell,1)); + elt->setCoords(coo4); + cells[ids[j]]=elt; } } std::vector< const MEDCouplingUMesh * > cellsPtr(VecAutoToVecOfCstPt(cells));