//
// 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"
}
/*!
- * 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
}
/*!
- * 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
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".<br>
- * \ref py_mcfielddouble_renumberCells "Here is a Python example".
- * \endif
- */
-void MEDCouplingFieldDouble::renumberCells(const int *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).
- */
-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<DataArrayDouble *> arrays;
- timeDiscr()->getArrays(arrays);
- std::vector<DataArray *> 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.
* \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".<br>
* 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)
{
return getArray()->findIdsInRange(vmin,vmax);
}
-MEDCouplingFieldInt *MEDCouplingFieldDouble::convertToIntField() const
+template<class U>
+typename Traits<U>::FieldType *ConvertToUField(const MEDCouplingFieldDouble *self)
{
- MCAuto<MEDCouplingFieldTemplate> tmp(MEDCouplingFieldTemplate::New(*this));
+ MCAuto<MEDCouplingFieldTemplate> tmp(MEDCouplingFieldTemplate::New(*self));
int t1,t2;
- double t0(getTime(t1,t2));
- MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*tmp,getTimeDiscretization()));
+ double t0(self->getTime(t1,t2));
+ MCAuto<typename Traits<U>::FieldType > ret(Traits<U>::FieldType::New(*tmp,self->getTimeDiscretization()));
ret->setTime(t0,t1,t2);
- if(getArray())
+ if(self->getArray())
{
- MCAuto<DataArrayInt> arr(getArray()->convertToIntArr());
+ MCAuto<typename Traits<U>::ArrayType> arr(self->getArray()->convertToOtherTypeOfArr<U>());
ret->setArray(arr);
}
return ret.retn();
}
+MEDCouplingFieldInt *MEDCouplingFieldDouble::convertToIntField() const
+{
+ return ConvertToUField<int>(this);
+}
+
+MEDCouplingFieldFloat *MEDCouplingFieldDouble::convertToFloatField() const
+{
+ return ConvertToUField<float>(this);
+}
+
MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingFieldT<double>(type,MEDCouplingTimeDiscretization::New(td))
{
}
/*!
* 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.
/*!
* 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.
* \throw If \a other == NULL.
* \throw If any of the meshes is not well defined.
* \throw If the two meshes do not match.
- * \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_changeUnderlyingMesh "Here is a C++ example".<br>
* \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".<br>
* \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)
{
* \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)
{
* \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)
{
* \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)
{
if(_type.isNull())
throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipConnectivity !");
MCAuto<MEDCouplingUMesh> meshC2((MEDCouplingUMesh *)meshC->deepCopy());
- int oldNbOfCells=meshC2->getNumberOfCells();
+ std::size_t oldNbOfCells(meshC2->getNumberOfCells());
MCAuto<DataArrayInt> arr=meshC2->zipConnectivityTraducer(compType);
if(meshC2->getNumberOfCells()!=oldNbOfCells)
{
/*!
* 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.
*