-// Copyright (C) 2016 CEA/DEN, EDF R&D
+// Copyright (C) 2016-2020 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
}
return ret.retn();
}
+
+ template<class T>
+ bool MEDCouplingFieldT<T>::isEqual(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec) const
+ {
+ std::string tmp;
+ return isEqualIfNotWhy(other,meshPrec,valsPrec,tmp);
+ }
template<class T>
- bool MEDCouplingFieldT<T>::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const
+ bool MEDCouplingFieldT<T>::isEqualIfNotWhy(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec, std::string& reason) const
{
if(!other)
throw INTERP_KERNEL::Exception("MEDCouplingFieldT::isEqualIfNotWhy : other instance is NULL !");
- const MEDCouplingFieldT<T> *otherC(dynamic_cast<const MEDCouplingFieldT<T> *>(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;
* \throw If the spatial discretization of \a this field is NULL.
*/
template<class T>
- bool MEDCouplingFieldT<T>::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const
+ bool MEDCouplingFieldT<T>::isEqualWithoutConsideringStr(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec) const
{
- const MEDCouplingFieldT<T> *otherC(dynamic_cast<const MEDCouplingFieldT<T> *>(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;
}
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".<br>
+ * \ref py_mcfielddouble_renumberCells "Here is a Python example".
+ * \endif
+ */
+ template<class T>
+ void MEDCouplingFieldT<T>::renumberCells(const mcIdType *old2NewBg, bool check)
+ {
+ renumberCellsWithoutMesh(old2NewBg,check);
+ MCAuto<MEDCouplingMesh> 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<class T>
+ void MEDCouplingFieldT<T>::renumberCellsWithoutMesh(const mcIdType *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<T>::ArrayType *> arrays;
+ timeDiscrSafe()->getArrays(arrays);
+ std::vector<DataArray *> 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.
{
if(getArray()->isAllocated())
{
- int nbOfCompo=getArray()->getNumberOfComponents();
+ std::size_t nbOfCompo=getArray()->getNumberOfComponents();
ret << Traits<T>::FieldTypeName << " default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
ret << Traits<T>::FieldTypeName << " default array has following info on components : ";
- for(int i=0;i<nbOfCompo;i++)
+ for(std::size_t i=0;i<nbOfCompo;i++)
ret << "\"" << getArray()->getInfoOnComponent(i) << "\" ";
ret << "\n";
}
nat=MEDCouplingNatureOfField::GetRepr(_nature);
stream << "Nature of field : " << nat << ".\n";
}
- catch(INTERP_KERNEL::Exception& e)
+ catch(INTERP_KERNEL::Exception&)
{ }
const MEDCouplingFieldDiscretization *fd(_type);
if(!fd)
}
/*!
- * 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 (
* \sa MEDCoupling::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const, MEDCouplingFieldDouble::buildSubPartRange
*/
template<class T>
- typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPart(const int *partBg, const int *partEnd) const
+ typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPart(const mcIdType *partBg, const mcIdType *partEnd) const
{
if(_type.isNull())
throw INTERP_KERNEL::Exception("MEDCouplingFieldT::buildSubPart : Expecting a not NULL spatial discretization !");
- DataArrayInt *arrSelect;
+ DataArrayIdType *arrSelect;
MCAuto<MEDCouplingMesh> m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect);
- MCAuto<DataArrayInt> arrSelect2(arrSelect);
+ MCAuto<DataArrayIdType> arrSelect2(arrSelect);
MCAuto< typename Traits<T>::FieldType > ret(clone(false));//quick shallow copy.
const MEDCouplingFieldDiscretization *disc=getDiscretization();
if(disc)
timeDiscrSafe()->getArrays(arrays);
std::vector<typename Traits<T>::ArrayType *> arrs;
std::vector< MCAuto< typename Traits<T>::ArrayType > > arrsSafe;
- const int *arrSelBg=arrSelect->begin();
- const int *arrSelEnd=arrSelect->end();
+ const mcIdType *arrSelBg=arrSelect->begin();
+ const mcIdType *arrSelEnd=arrSelect->end();
for(typename std::vector<typename Traits<T>::ArrayType *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
{
typename Traits<T>::ArrayType *arr(0);
}
/*!
- * 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** (
* \sa MEDCouplingFieldDouble::buildSubPartRange
*/
template<class T>
- typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPart(const DataArrayInt *part) const
+ typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPart(const DataArrayIdType *part) const
{
if(part==0)
throw INTERP_KERNEL::Exception("MEDCouplingFieldT::buildSubPart : not empty array must be passed to this method !");
* \sa MEDCouplingFieldDouble::buildSubPart
*/
template<class T>
- typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPartRange(int begin, int end, int step) const
+ typename Traits<T>::FieldType *MEDCouplingFieldT<T>::buildSubPartRange(mcIdType begin, mcIdType end, mcIdType step) const
{
if(_type.isNull())
throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
- DataArrayInt *arrSelect;
- int beginOut,endOut,stepOut;
+ DataArrayIdType *arrSelect;
+ mcIdType beginOut,endOut,stepOut;
MCAuto<MEDCouplingMesh> m(_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect));
- MCAuto<DataArrayInt> arrSelect2(arrSelect);
+ MCAuto<DataArrayIdType> arrSelect2(arrSelect);
MCAuto< typename Traits<T>::FieldType > ret(clone(false));//quick shallow copy.
const MEDCouplingFieldDiscretization *disc=getDiscretization();
if(disc)
{
if(arrSelect)
{
- const int *arrSelBg=arrSelect->begin();
- const int *arrSelEnd=arrSelect->end();
+ const mcIdType *arrSelBg=arrSelect->begin();
+ const mcIdType *arrSelEnd=arrSelect->end();
arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
}
else
* @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
*/
template<class T>
- void MEDCouplingFieldT<T>::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
+ void MEDCouplingFieldT<T>::getTinySerializationIntInformation(std::vector<mcIdType>& 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)timeDiscrSafe()->getEnum());
- tinyInfo.push_back((int)_nature);
+ tinyInfo.push_back(ToIdType(_type->getEnum()));
+ tinyInfo.push_back(ToIdType(timeDiscrSafe()->getEnum()));
+ tinyInfo.push_back(ToIdType(_nature));
timeDiscrSafe()->getTinySerializationIntInformation(tinyInfo);
- std::vector<int> tinyInfo2;
+ std::vector<mcIdType> tinyInfo2;
_type->getTinySerializationIntInformation(tinyInfo2);
tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
- tinyInfo.push_back((int)tinyInfo2.size());
+ tinyInfo.push_back(ToIdType(tinyInfo2.size()));
}
/*!
* \sa checkForUnserialization
*/
template<class T>
- void MEDCouplingFieldT<T>::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays)
+ void MEDCouplingFieldT<T>::resizeForUnserialization(const std::vector<mcIdType>& tinyInfoI, DataArrayIdType *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays)
{
if(_type.isNull())
throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
dataInt=0;
- std::vector<int> tinyInfoITmp(tinyInfoI);
- int sz=tinyInfoITmp.back();
+ std::vector<mcIdType> tinyInfoITmp(tinyInfoI);
+ mcIdType sz=tinyInfoITmp.back();
tinyInfoITmp.pop_back();
- std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
- std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
+ std::vector<mcIdType> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
+ std::vector<mcIdType> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
timeDiscrSafe()->resizeForUnserialization(tinyInfoI2,arrays);
- std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
+ std::vector<mcIdType> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
_type->resizeForUnserialization(tinyInfoITmp3,dataInt);
}
* \sa resizeForUnserialization
*/
template<class T>
- void MEDCouplingFieldT<T>::checkForUnserialization(const std::vector<int>& tinyInfoI, const DataArrayInt *dataInt, const std::vector<typename Traits<T>::ArrayType *>& arrays)
+ void MEDCouplingFieldT<T>::checkForUnserialization(const std::vector<mcIdType>& tinyInfoI, const DataArrayIdType *dataInt, const std::vector<typename Traits<T>::ArrayType *>& arrays)
{
if(_type.isNull())
throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
- std::vector<int> tinyInfoITmp(tinyInfoI);
- int sz=tinyInfoITmp.back();
+ std::vector<mcIdType> tinyInfoITmp(tinyInfoI);
+ mcIdType sz=tinyInfoITmp.back();
tinyInfoITmp.pop_back();
- std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
- std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
+ std::vector<mcIdType> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
+ std::vector<mcIdType> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
timeDiscrSafe()->checkForUnserialization(tinyInfoI2,arrays);
- std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
+ std::vector<mcIdType> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
_type->checkForUnserialization(tinyInfoITmp3,dataInt);
}
template<class T>
- void MEDCouplingFieldT<T>::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
+ void MEDCouplingFieldT<T>::finishUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
{
if(_type.isNull())
throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
- std::vector<int> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
+ std::vector<mcIdType> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
//
std::vector<double> tmp(tinyInfoD);
- int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it
+ mcIdType sz=ToIdType(tinyInfoD.back());//very bad, lack of time to improve it
tmp.pop_back();
std::vector<double> tmp1(tmp.begin(),tmp.end()-sz);
std::vector<double> tmp2(tmp.end()-sz,tmp.end());
timeDiscrSafe()->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS);
_nature=(NatureOfField)tinyInfoI[2];
_type->finishUnserialization(tmp2);
- int nbOfElemS=(int)tinyInfoS.size();
+ std::size_t nbOfElemS=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.
+ * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsibilities of the caller.
* The values returned must be consulted only in readonly mode.
*/
template<class T>
- void MEDCouplingFieldT<T>::serialize(DataArrayInt *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays) const
+ void MEDCouplingFieldT<T>::serialize(DataArrayIdType *&dataInt, std::vector<typename Traits<T>::ArrayType *>& arrays) const
{
if(_type.isNull())
throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !");