Salome HOME
Generalization of unstructured grid supported by the remapper.
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingMesh.cxx
index 48489218fdd5c05d9cb0d1e76937341278b72d7b..3408e9e22bddd3eb1de1b3f59ac1cf70b8ef407c 100644 (file)
@@ -113,22 +113,37 @@ bool MEDCouplingMesh::isEqual(const MEDCouplingMesh *other, double prec) const t
 }
 
 /*!
- * This method checks geo equivalence between two meshes : 'this' and 'other'.
- * If no exception is throw 'this' and 'other' are geometrically equivalent regarding 'levOfCheck' level.
- * This method is typically used to change the mesh of a field "safely" depending the 'levOfCheck' level considered.
- * So in case of success cell \c other[i] is equal to cell \c this[cellCor[i]]. If \a cellCor is null it means that for all i cell \c other[i] is equal to cell \c this[i].
+ * This method checks geo equivalence between two meshes : \a this and \a other.
+ * If no exception is thrown \a this and \a other are geometrically equivalent regarding \a levOfCheck level.
+ * This method is typically used to change the mesh of a field "safely" depending the \a levOfCheck level considered.
  * 
- * @param levOfCheck input that specifies the level of check specified. The possible values are listed below.
- * @param prec input that specifies precision for double float data used for comparison in meshes.
- * @param cellCor output array not always informed (depending 'levOfCheck' param) that gives the corresponding array for cells from 'other' to 'this'.
- * @param nodeCor output array not always informed (depending 'levOfCheck' param) that gives the corresponding array for nodes from 'other' to 'this'.
+ * In case of success cell \c other[i] is equal to the cell \c this[cellCor[i]].
+ * In case of success node \c other->getCoords()[i] is equal to the node \c this->getCoords()[nodeCor[i]].
+ *
+ * If \a cellCor is null (or Py_None) it means that for all #i cell in \a other is equal to cell # i in \a this.
+ *
+ * If \a nodeCor is null (or Py_None) it means that for all #i node in \a other is equal to node # i in \a this.
+ *
+ * So null (or Py_None) returned in \a cellCor and/or \a nodeCor means identity array. This is for optimization reason to avoid to build useless arrays
+ * for some \a levOfCheck (for example 0).
+ *
+ * **Warning a not null output does not mean that it is not identity !**
+ *
+ * \param [in] other - the mesh to be compared with \a this.
+ * \param [in] levOfCheck - input that specifies the level of check specified. The possible values are listed below.
+ * \param [in] prec - input that specifies precision for double float data used for comparison in meshes.
+ * \param [out] cellCor - output array not always informed (depending \a levOfCheck param) that gives the corresponding array for cells from \a other to \a this.
+ * \param [out] nodeCor - output array not always informed (depending \a levOfCheck param) that gives the corresponding array for nodes from \a other to \a this.
  *
  * Possible values for levOfCheck :
- *   - 0 for strict equality. This is the strongest level. 'cellCor' and 'nodeCor' params are never informed.
- *   - 10,11,12 for less strict equality. Two meshes are compared geometrically. In case of success 'cellCor' and 'nodeCor' are informed. Warning ! These equivalences are CPU/Mem costly. The 3 values correspond respectively to policy used for cell comparison (see MEDCouplingUMesh::zipConnectivityTraducer to have more details)
- *   - 20,21,22, for less strict equality. Two meshes are compared geometrically. The difference with the previous version is that nodes(coordinates) are expected to be the same between this and other. In case of success 'cellCor' is informed. Warning ! These equivalences are CPU/Mem costly. The 3 values correspond respectively to policy used for cell comparison (see MEDCouplingUMesh::zipConnectivityTraducer to have more details)
+ *   - 0 for strict equality. This is the strongest level. \a cellCor and \a nodeCor params are never informed.
+ *   - 10,11,12 (10+x) for less strict equality. Two meshes are compared geometrically. In case of success \a cellCor and \a nodeCor are informed. Warning ! These equivalences are CPU/Mem costly. The 3 values correspond respectively to policy used for cell comparison (see MEDCouplingUMesh::zipConnectivityTraducer to have more details)
+ *   - 20,21,22 (20+x), for less strict equality. Two meshes are compared geometrically. The difference with the previous version is that nodes(coordinates) are expected to be the same between this and other. In case of success \a cellCor is informed. Warning ! These equivalences are CPU/Mem costly. The 3 values correspond respectively to policy used for cell comparison (see MEDCouplingUMesh::zipConnectivityTraducer to have more details)
  *   - 1 for fast 'equality'. This is a lazy level. Just number of cells and number of nodes are considered here and 3 cells (begin,middle,end)
  *   - 2 for deep 'equality' as 0 option except that no control is done on all strings in mesh.
+ *
+ * So the most strict level of check is 0 (equality). The least strict is 12. If the level of check 12 throws, the 2 meshes \a this and \a other are not similar enough
+ * to be compared. An interpolation using MEDCouplingRemapper class should be then used.
  */
 void MEDCouplingMesh::checkGeoEquivalWith(const MEDCouplingMesh *other, int levOfCheck, double prec,
                                           DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception)
@@ -207,10 +222,12 @@ DataArrayInt *MEDCouplingMesh::getCellIdsFullyIncludedInNodeIds(const int *partB
 }
 
 /*!
- * This method checks fastly that 'this' and 'other' are equal. All common checks are done here.
+ * This method checks fastly that \a this and \a other are equal. All common checks are done here.
  */
 void MEDCouplingMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception)
 {
+  if(!other)
+    throw INTERP_KERNEL::Exception("MEDCouplingMesh::checkFastEquivalWith : input mesh is null !");
   if(getMeshDimension()!=other->getMeshDimension())
     throw INTERP_KERNEL::Exception("checkFastEquivalWith : Mesh dimensions are not equal !");
   if(getSpaceDimension()!=other->getSpaceDimension())
@@ -220,10 +237,12 @@ void MEDCouplingMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double
 }
 
 /*!
- * This method is very poor and looks only if 'this' and 'other' are candidate for merge of fields lying repectively on them.
+ * This method is very poor and looks only if \a this and \a other are candidate for merge of fields lying repectively on them.
  */
 bool MEDCouplingMesh::areCompatibleForMerge(const MEDCouplingMesh *other) const
 {
+  if(!other)
+    throw INTERP_KERNEL::Exception("MEDCouplingMesh::areCompatibleForMerge : input mesh is null !");
   if(getMeshDimension()!=other->getMeshDimension())
     return false;
   if(getSpaceDimension()!=other->getSpaceDimension())
@@ -254,7 +273,7 @@ MEDCouplingMesh *MEDCouplingMesh::buildPartRangeAndReduceNodes(int beginCellIds,
 }
 
 /*!
- * This method builds a field lying on 'this' with 'nbOfComp' components.
+ * This method builds a field lying on \a this with 'nbOfComp' components.
  * 'func' is a pointer that points to a function that takes 2 arrays in parameter and returns a boolean.
  * The first array is a in-param of size this->getSpaceDimension and the second an out param of size 'nbOfComp'.
  * The return field will have type specified by 't'. 't' is also used to determine where values of field will be
@@ -263,10 +282,11 @@ MEDCouplingMesh *MEDCouplingMesh::buildPartRangeAndReduceNodes(int beginCellIds,
  * The 'func' is a callback that takes as first parameter an input array of size 'this->getSpaceDimension()',
  * the second parameter is a pointer on a valid zone of size at least equal to 'nbOfComp' values. And too finish
  * the returned value is a boolean that is equal to False in case of invalid evaluation (log(0) for example...)
- * @param t type of field returned and specifies where the evaluation of func will be done.
- * @param nbOfComp number of components of returned field.
- * @param func pointer to a function that should return false if the evaluation failed. (division by 0. for example)
- * @return field with counter = 1.
+ * 
+ * \param t type of field returned and specifies where the evaluation of func will be done.
+ * \param nbOfComp number of components of returned field.
+ * \param func pointer to a function that should return false if the evaluation failed. (division by 0. for example)
+ * \return field with counter = 1.
  */
 MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, FunctionToEvaluate func) const
 {
@@ -283,6 +303,8 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbO
  */
 void MEDCouplingMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception)
 {
+  if(!other)
+    throw INTERP_KERNEL::Exception("MEDCouplingMesh::copyTinyStringsFrom : input mesh is null !");
   _name=other->_name;
   _description=other->_description;
   _time_unit=other->_time_unit;
@@ -290,7 +312,7 @@ void MEDCouplingMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) throw(IN
 
 /*!
  * This method copies all attributes that are \b NOT arrays in this.
- * All tiny attributes not usefully for state of 'this' are ignored.
+ * All tiny attributes not usefully for state of \a this are ignored.
  */
 void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception)
 {
@@ -509,6 +531,54 @@ MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(std::vector<const MEDCouplingMesh
   return MEDCouplingUMesh::MergeUMeshes(ms2);
 }
 
+/*!
+ * For example if \a type is INTERP_KERNEL::NORM_TRI3 , INTERP_KERNEL::NORM_POLYGON is returned.
+ * If \a type is INTERP_KERNEL::NORM_HEXA8 , INTERP_KERNEL::NORM_POLYHED is returned.
+ * 
+ * \param [in] type the geometric type for which the corresponding dynamic type, is asked.
+ * \return the corresponding dynamic type, able to store the input \a type.
+ * 
+ * \throw if type is equal to \c INTERP_KERNEL::NORM_ERROR or to an unexisting geometric type.
+ */
+INTERP_KERNEL::NormalizedCellType MEDCouplingMesh::GetCorrespondingPolyType(INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
+{
+  const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
+  return cm.getCorrespondingPolyType();
+}
+
+/*!
+ * \param [in] type the geometric type for which the number of nodes consituting it, is asked.
+ * \return number of nodes consituting the input geometric type \a type.
+ * 
+ * \throw if type is dynamic as \c INTERP_KERNEL::NORM_POLYHED , \c INTERP_KERNEL::NORM_POLYGON , \c INTERP_KERNEL::NORM_QPOLYG
+ * \throw if type is equal to \c INTERP_KERNEL::NORM_ERROR or to an unexisting geometric type.
+ */
+int MEDCouplingMesh::GetNumberOfNodesOfGeometricType(INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
+{
+  const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
+  if(cm.isDynamic())
+    throw INTERP_KERNEL::Exception("MEDCouplingMesh::GetNumberOfNodesOfGeometricType : the input geometric type is dynamic ! Impossible to return a fixed number of nodes constituting it !");
+  return (int) cm.getNumberOfNodes();
+}
+
+/*!
+ * \param [in] type the geometric type for which the status static/dynamic is asked.
+ * \return true for static geometric type, false for dynamic geometric type.
+ * 
+ * \throw if type is equal to \c INTERP_KERNEL::NORM_ERROR or to an unexisting geometric type.
+ */
+bool MEDCouplingMesh::IsStaticGeometricType(INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
+{
+  const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
+  return !cm.isDynamic();
+}
+
+bool MEDCouplingMesh::IsLinearGeometricType(INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
+{
+  const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
+  return !cm.isQuadratic();
+}
+
 /*!
  * \param [in] type the geometric type for which the dimension is asked.
  * \return the dimension associated to the input geometric type \a type.