Salome HOME
Merge branch 'master' of https://codev-tuleap.cea.fr/plugins/git/salome/medcoupling
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingField.cxx
old mode 100755 (executable)
new mode 100644 (file)
index bf5c05a..5da1e13
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2007-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
 
 #include <sstream>
 
-using namespace ParaMEDMEM;
+using namespace MEDCoupling;
 
-bool MEDCouplingField::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const
+void MEDCouplingField::checkConsistencyLight() const
+{
+  if(!_mesh)
+    throw INTERP_KERNEL::Exception("Field invalid because no mesh specified !");
+  if(_type.isNull())
+    throw INTERP_KERNEL::Exception("MEDCouplingField::checkConsistencyLight : no spatial discretization !");
+}
+
+bool MEDCouplingField::isEqualIfNotWhyProtected(const MEDCouplingField *other, double meshPrec, std::string& reason) const
 {
   if(!other)
     throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualIfNotWhy : other instance is NULL !");
@@ -49,7 +57,7 @@ bool MEDCouplingField::isEqualIfNotWhy(const MEDCouplingField *other, double mes
       reason=oss.str();
       return false;
     }
-  if(!_type->isEqualIfNotWhy(other->_type,valsPrec,reason))
+  if(!_type->isEqualIfNotWhy(other->_type,meshPrec,reason))
     {
       reason.insert(0,"Spatial discretizations differ :");
       return false;
@@ -69,37 +77,22 @@ bool MEDCouplingField::isEqualIfNotWhy(const MEDCouplingField *other, double mes
   return ret;
 }
 
-/*!
- * Checks if \a this and another MEDCouplingField are fully equal.
- *  \param [in] other - the field to compare with \a this one.
- *  \param [in] meshPrec - precision used to compare node coordinates of the underlying mesh.
- *  \param [in] valsPrec - precision used to compare field values.
- *  \return bool - \c true if the two fields are equal, \c false else.
- *  \throw If \a other is NULL.
- */
-bool MEDCouplingField::isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const
-{
-  std::string tmp;
-  return isEqualIfNotWhy(other,meshPrec,valsPrec,tmp);
-}
-
 /*!
  * Checks if \a this and another MEDCouplingField are equal. The textual
  * information like names etc. is not considered.
  *  \param [in] other - the field to compare with \a this one.
  *  \param [in] meshPrec - precision used to compare node coordinates of the underlying mesh.
- *  \param [in] valsPrec - precision used to compare field values.
  *  \return bool - \c true if the two fields are equal, \c false else.
  *  \throw If \a other is NULL.
  *  \throw If the spatial discretization of \a this field is NULL.
  */
-bool MEDCouplingField::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const
+bool MEDCouplingField::isEqualWithoutConsideringStrProtected(const MEDCouplingField *other, double meshPrec) const
 {
   if(!other)
     throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : input field is NULL !");
   if(!_type)
     throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : spatial discretization of this is NULL !");
-  if(!_type->isEqualWithoutConsideringStr(other->_type,valsPrec))
+  if(!_type->isEqualWithoutConsideringStr(other->_type,meshPrec))
     return false;
   if(_nature!=other->_nature)
     return false;
@@ -121,7 +114,9 @@ bool MEDCouplingField::areCompatibleForMerge(const MEDCouplingField *other) cons
 {
   if(!other)
     throw INTERP_KERNEL::Exception("MEDCouplingField::areCompatibleForMerge : input field is NULL !");
-  if(!_type->isEqual(other->_type,1.))
+  if(!_type || !other->_type)
+    throw INTERP_KERNEL::Exception("MEDCouplingField::areCompatibleForMerge : this or other has a nullptr spatial discretization !");
+  if(_type->getEnum()!=other->_type->getEnum())
     return false;
   if(_nature!=other->_nature)
     return false;
@@ -145,6 +140,21 @@ bool MEDCouplingField::areStrictlyCompatible(const MEDCouplingField *other) cons
   return _mesh==other->_mesh;
 }
 
+/*!
+ * This method is less strict than MEDCouplingField::areStrictlyCompatible method.
+ * The difference is that the nature is not checked.
+ * This method is used for multiplication and division on fields to operate a first check before attempting operation.
+ */
+bool MEDCouplingField::areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const
+{
+  if(!other)
+    throw INTERP_KERNEL::Exception("MEDCouplingField::areStrictlyCompatible : input field is NULL !");
+  if(!_type->isEqual(other->_type,1.e-12))
+    return false;
+  return _mesh==other->_mesh;
+}
+
+
 void MEDCouplingField::updateTime() const
 {
   if(_mesh)
@@ -171,8 +181,8 @@ std::vector<const BigMemoryObject *> MEDCouplingField::getDirectChildrenWithNull
 
 /*!
  * Returns a type of \ref MEDCouplingSpatialDisc "spatial discretization" of \a this
- * field in terms of enum ParaMEDMEM::TypeOfField. 
- * \return ParaMEDMEM::TypeOfField - the type of \a this field.
+ * field in terms of enum MEDCoupling::TypeOfField. 
+ * \return MEDCoupling::TypeOfField - the type of \a this field.
  * \throw If the geometric type is empty.
  */
 TypeOfField MEDCouplingField::getTypeOfField() const
@@ -184,7 +194,7 @@ TypeOfField MEDCouplingField::getTypeOfField() const
 
 /*!
  * Returns the nature of \a this field. This information is very important during
- * interpolation process using ParaMEDMEM::MEDCouplingRemapper or ParaMEDMEM::InterpKernelDEC.
+ * interpolation process using MEDCoupling::MEDCouplingRemapper or MEDCoupling::InterpKernelDEC.
  * In other context than the two mentioned above, this attribute is unimportant. This
  * attribute is not stored in the MED file.
  * For more information of the semantics and the influence of this attribute to the
@@ -199,7 +209,7 @@ NatureOfField MEDCouplingField::getNature() const
 
 /*!
  * Sets the nature of \a this field. This information is very important during
- * interpolation process using ParaMEDMEM::MEDCouplingRemapper or ParaMEDMEM::InterpKernelDEC.
+ * interpolation process using MEDCoupling::MEDCouplingRemapper or MEDCoupling::InterpKernelDEC.
  * In other context than the two mentioned above, this attribute is unimportant. This
  * attribute is not stored in the MED file.
  * For more information of the semantics and the influence of this attribute to the
@@ -213,6 +223,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;
 }
 
@@ -323,7 +335,7 @@ void MEDCouplingField::setGaussLocalizationOnType(INTERP_KERNEL::NormalizedCellT
  *  \throw If type of any cell in \a begin differs from that of cell # \a begin[0].
  *  \throw If the range [_begin_,_end_) is empty.
  */
-void MEDCouplingField::setGaussLocalizationOnCells(const int *begin, const int *end, const std::vector<double>& refCoo,
+void MEDCouplingField::setGaussLocalizationOnCells(const mcIdType *begin, const mcIdType *end, const std::vector<double>& refCoo,
                                                    const std::vector<double>& gsCoo, const std::vector<double>& wg)
 {
   if(!_mesh)
@@ -351,7 +363,8 @@ void MEDCouplingField::clearGaussLocalizations()
  *          problem.
  *  \param [in] locId - the id of the Gauss localization object of interest.
  *         It must be in range <em> 0 <= locId < getNbOfGaussLocalization() </em>.
- *  \return \ref MEDCouplingGaussLocalization & - the Gauss localization object.
+ *  \return \ref MEDCoupling::MEDCouplingGaussLocalization "MEDCouplingGaussLocalization" & - the
+ *  Gauss localization object.
  *  \throw If \a this field is not on Gauss points.
  *  \throw If \a locId is not within the valid range.
  *  \throw If the spatial discretization of \a this field is NULL.
@@ -366,13 +379,13 @@ MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int locId)
 /*!
  * Returns an id of the Gauss localization object corresponding to a given cell type.
  *  \param [in] type - the cell type of interest.
- *  \return int - the id of the Gauss localization object.
+ *  \return mcIdType - the id of the Gauss localization object.
  *  \throw If \a this field is not on Gauss points.
  *  \throw If the spatial discretization of \a this field is NULL.
  *  \throw If no Gauss localization object found for the given cell \a type.
  *  \throw If more than one Gauss localization object found for the given cell \a type.
  */
-int MEDCouplingField::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const
+mcIdType MEDCouplingField::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const
 {
   if(!((const MEDCouplingFieldDiscretization *)_type))
     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdOfOneType method !");
@@ -382,11 +395,11 @@ int MEDCouplingField::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedC
 /*!
  * Returns ids of Gauss localization objects corresponding to a given cell type.
  *  \param [in] type - the cell type of interest.
- *  \return std::set<int> - ids of the Gauss localization object.
+ *  \return std::set<mcIdType> - ids of the Gauss localization object.
  *  \throw If \a this field is not on Gauss points.
  *  \throw If the spatial discretization of \a this field is NULL
  */
-std::set<int> MEDCouplingField::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const
+std::set<mcIdType> MEDCouplingField::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const
 {
   if(!((const MEDCouplingFieldDiscretization *)_type))
     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdsOfOneType method !");
@@ -396,11 +409,11 @@ std::set<int> MEDCouplingField::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::
 /*!
  * Returns number of Gauss localization objects available. Implicitly all ids in
  * [0,getNbOfGaussLocalization()) are valid Gauss localization ids. 
- *  \return int - the number of available Gauss localization objects.
+ *  \return mcIdType - the number of available Gauss localization objects.
  *  \throw If \a this field is not on Gauss points.
  *  \throw If the spatial discretization of \a this field is NULL.
  */
-int MEDCouplingField::getNbOfGaussLocalization() const
+mcIdType MEDCouplingField::getNbOfGaussLocalization() const
 {
   if(!((const MEDCouplingFieldDiscretization *)_type))
     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNbOfGaussLocalization method !");
@@ -410,12 +423,12 @@ int MEDCouplingField::getNbOfGaussLocalization() const
 /*!
  * Returns an id of the Gauss localization object corresponding to a type of a given cell.
  *  \param [in] cellId - an id of the cell of interest.
- *  \return int - the id of the Gauss localization object.
+ *  \return mcIdType - the id of the Gauss localization object.
  *  \throw If \a this field is not on Gauss points.
  *  \throw If the spatial discretization of \a this field is NULL.
  *  \throw If no Gauss localization object found for the given cell.
  */
-int MEDCouplingField::getGaussLocalizationIdOfOneCell(int cellId) const
+mcIdType MEDCouplingField::getGaussLocalizationIdOfOneCell(mcIdType cellId) const
 {
   if(!((const MEDCouplingFieldDiscretization *)_type))
     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdOfOneCell method !");
@@ -432,7 +445,7 @@ int MEDCouplingField::getGaussLocalizationIdOfOneCell(int cellId) const
  *  \throw If \a locId is not within the valid range.
  *  \throw If the spatial discretization of \a this field is NULL.
  */
-void MEDCouplingField::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const
+void MEDCouplingField::getCellIdsHavingGaussLocalization(int locId, std::vector<mcIdType>& cellIds) const
 {
   cellIds.clear();
   if(!((const MEDCouplingFieldDiscretization *)_type))
@@ -445,7 +458,7 @@ void MEDCouplingField::getCellIdsHavingGaussLocalization(int locId, std::vector<
  * \warning This method is const, so the returned object is not apt for modification.
  *  \param [in] locId - the id of the Gauss localization object of interest.
  *         It must be in range <em> 0 <= locId < getNbOfGaussLocalization() </em>.
- *  \return \ref const MEDCouplingGaussLocalization & - the Gauss localization object.
+ *  \return const \ref MEDCouplingGaussLocalization & - the Gauss localization object.
  *  \throw If \a this field is not on Gauss points.
  *  \throw If \a locId is not within the valid range.
  *  \throw If the spatial discretization of \a this field is NULL.
@@ -487,13 +500,13 @@ MEDCouplingField::MEDCouplingField(const MEDCouplingField& other, bool deepCopy)
 
 /*!
  * Returns a new MEDCouplingMesh constituted by some cells of the underlying mesh of \a
- * this filed, and returns ids of entities (nodes, cells, Gauss points) lying on the 
+ * this field, and returns ids of entities (nodes, cells, Gauss points) lying on the
  * specified cells. The cells to include to the result mesh are specified by an array of
  * cell ids. The new mesh shares the coordinates array with the underlying mesh. 
  *  \param [in] start - an array of cell ids to include to the result mesh.
  *  \param [in] end - specifies the end of the array \a start, so that
  *              the last value of \a start is \a end[ -1 ].
- *  \param [out] di - a new instance of DataArrayInt holding the ids of entities (nodes,
+ *  \param [out] di - a new instance of DataArrayIdType holding the ids of entities (nodes,
  *         cells, Gauss points). The caller is to delete this array using decrRef() as it
  *         is no more needed.  
  *  \return MEDCouplingMesh * - a new instance of MEDCouplingMesh. The caller is to
@@ -502,7 +515,7 @@ MEDCouplingField::MEDCouplingField(const MEDCouplingField& other, bool deepCopy)
  *  \throw If the mesh is not set.
  * \sa buildSubMeshDataRange()
  */
-MEDCouplingMesh *MEDCouplingField::buildSubMeshData(const int *start, const int *end, DataArrayInt *&di) const
+MEDCouplingMesh *MEDCouplingField::buildSubMeshData(const mcIdType *start, const mcIdType *end, DataArrayIdType *&di) const
 {
   if(!((const MEDCouplingFieldDiscretization *)_type))
     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call buildSubMeshData method !");
@@ -519,7 +532,7 @@ MEDCouplingMesh *MEDCouplingField::buildSubMeshData(const int *start, const int
  * 
  * \sa MEDCouplingField::buildSubMeshData
  */
-MEDCouplingMesh *MEDCouplingField::buildSubMeshDataRange(int begin, int end, int step, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const
+MEDCouplingMesh *MEDCouplingField::buildSubMeshDataRange(mcIdType begin, mcIdType end, mcIdType step, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType *&di) const
 {
   if(!((const MEDCouplingFieldDiscretization *)_type))
     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call buildSubMeshDataRange method !");
@@ -528,9 +541,9 @@ MEDCouplingMesh *MEDCouplingField::buildSubMeshDataRange(int begin, int end, int
 
 /*!
  * This method returns tuples ids implied by the mesh selection of the  cell ids contained in array defined as an interval [start;end).
- * \return a newly allocated DataArrayInt instance containing tuples ids.
+ * \return a newly allocated DataArrayIdType instance containing tuples ids.
  */
-DataArrayInt *MEDCouplingField::computeTupleIdsToSelectFromCellIds(const int *startCellIds, const int *endCellIds) const
+DataArrayIdType *MEDCouplingField::computeTupleIdsToSelectFromCellIds(const mcIdType *startCellIds, const mcIdType *endCellIds) const
 {
   if(!((const MEDCouplingFieldDiscretization *)_type))
     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call computeTupleIdsToSelectFromCellIds method !");
@@ -540,11 +553,11 @@ DataArrayInt *MEDCouplingField::computeTupleIdsToSelectFromCellIds(const int *st
 /*!
  * Returns number of tuples expected regarding the spatial discretization of \a this
  * field and number of entities in the underlying mesh. This method behaves exactly as MEDCouplingFieldDouble::getNumberOfTuples.
- *  \return int - the number of expected tuples.
+ *  \return mcIdType - the number of expected tuples.
  *  \throw If the spatial discretization of \a this field is NULL.
  *  \throw If the mesh is not set.
  */
-int MEDCouplingField::getNumberOfTuplesExpected() const
+mcIdType MEDCouplingField::getNumberOfTuplesExpected() const
 {
   if(!((const MEDCouplingFieldDiscretization *)_type))
     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNumberOfTuplesExpected method !");
@@ -567,11 +580,11 @@ void MEDCouplingField::setDiscretization(MEDCouplingFieldDiscretization *newDisc
 /*!
  * Returns number of mesh entities in the underlying mesh of \a this field regarding the
  * spatial discretization.
- *  \return int - the number of mesh entities porting the field values.
+ *  \return mcIdType - the number of mesh entities porting the field values.
  *  \throw If the spatial discretization of \a this field is NULL.
  *  \throw If the mesh is not set.
  */
-int MEDCouplingField::getNumberOfMeshPlacesExpected() const
+mcIdType MEDCouplingField::getNumberOfMeshPlacesExpected() const
 {
   if(!((const MEDCouplingFieldDiscretization *)_type))
     throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNumberOfMeshPlacesExpected method !");
@@ -610,7 +623,7 @@ void MEDCouplingField::copyTinyStringsFrom(const MEDCouplingField *other)
  * \throw If input code point to invalid zones in spatial discretization.
  * \throw If spatial discretization in \a this requires a mesh and those mesh is invalid (null,...)
  */
-int MEDCouplingField::getNumberOfTuplesExpectedRegardingCode(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const
+mcIdType MEDCouplingField::getNumberOfTuplesExpectedRegardingCode(const std::vector<mcIdType>& code, const std::vector<const DataArrayIdType *>& idsPerType) const
 {
   const MEDCouplingFieldDiscretization *t(_type);
   if(!t)