Salome HOME
More check in MEDCouplingRemapper to help aggressive users of transferField, transfer...
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingCMesh.cxx
index 060fe57bddd9bf5df7e1555a093f750abefeaa53..20343e55c67855acf03d4842d5b0eafb822145b8 100644 (file)
@@ -128,11 +128,11 @@ std::vector<const BigMemoryObject *> MEDCouplingCMesh::getDirectChildren() const
  * @throw if other and this have not same mesh type.
  */
 void MEDCouplingCMesh::copyTinyStringsFrom(const MEDCouplingMesh *other)
-{ 
-  const MEDCouplingCMesh *otherC=dynamic_cast<const MEDCouplingCMesh *>(other);
+{
+  MEDCouplingStructuredMesh::copyTinyStringsFrom(other);
+  const MEDCouplingCMesh *otherC(dynamic_cast<const MEDCouplingCMesh *>(other));
   if(!otherC)
     throw INTERP_KERNEL::Exception("MEDCouplingCMesh::copyTinyStringsFrom : meshes have not same type !");
-  MEDCouplingStructuredMesh::copyTinyStringsFrom(other);
   if(_x_array && otherC->_x_array)
     _x_array->copyStringInfoFrom(*otherC->_x_array);
   if(_y_array && otherC->_y_array)
@@ -151,7 +151,7 @@ bool MEDCouplingCMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec
       reason="mesh given in input is not castable in MEDCouplingCMesh !";
       return false;
     }
-  if(!MEDCouplingMesh::isEqualIfNotWhy(other,prec,reason))
+  if(!MEDCouplingStructuredMesh::isEqualIfNotWhy(other,prec,reason))
     return false;
   const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array};
   const DataArrayDouble *otherArr[3]={otherC->_x_array,otherC->_y_array,otherC->_z_array};
@@ -202,14 +202,13 @@ void MEDCouplingCMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int ce
 
 /*!
  * Nothing is done here (except to check that the other is a ParaMEDMEM::MEDCouplingCMesh instance too).
- * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingCMesh, 'this' and 'other' are the same !
+ * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingCMesh, \a this and \a other are the same !
  */
 void MEDCouplingCMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
                                                        DataArrayInt *&cellCor) const
 {
-  const MEDCouplingCMesh *otherC=dynamic_cast<const MEDCouplingCMesh *>(other);
-  if(!otherC)
-    throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkDeepEquivalOnSameNodesWith : other is NOT a cartesian mesh ! Impossible to check equivalence !");
+  if(!isEqualWithoutConsideringStr(other,prec))
+    throw INTERP_KERNEL::Exception("MEDCouplingCMesh::checkDeepEquivalOnSameNodesWith : Meshes are not the same !");
 }
 
 void MEDCouplingCMesh::checkCoherency() const
@@ -275,75 +274,53 @@ void MEDCouplingCMesh::checkCoherency2(double eps) const
   checkCoherency1(eps);
 }
 
-int MEDCouplingCMesh::getNumberOfCells() const
+void MEDCouplingCMesh::getNodeGridStructure(int *res) const
 {
-  int ret=1;
-  if(_x_array)
-    ret*=_x_array->getNbOfElems()-1;
-  if(_y_array)
-    ret*=_y_array->getNbOfElems()-1;
-  if(_z_array)
-    ret*=_z_array->getNbOfElems()-1;
-  return ret;
+  std::vector<int> ret(getNodeGridStructure());
+  std::copy(ret.begin(),ret.end(),res);
 }
 
-int MEDCouplingCMesh::getNumberOfNodes() const
+std::vector<int> MEDCouplingCMesh::getNodeGridStructure() const
 {
-  int ret=1;
+  static const char MSG[]="MEDCouplingCMesh::getNodeGridStructure : mesh is invalid ! null vectors (X, Y or Z) must be put contiguously at the end !";
+  std::vector<int> ret;
+  bool isOK(true);
   if(_x_array)
-    ret*=_x_array->getNbOfElems();
+    {
+      if(!_x_array->isAllocated() || _x_array->getNumberOfComponents()!=1)
+        throw INTERP_KERNEL::Exception("MEDCouplingCMesh::getNodeGridStructure : X array exits but it is not allocated or with nb of components equal to one !");
+      ret.push_back(_x_array->getNumberOfTuples());
+    }
+  else
+    isOK=false;
   if(_y_array)
-    ret*=_y_array->getNbOfElems();
-  if(_z_array)
-    ret*=_z_array->getNbOfElems();
-  return ret;
-}
-
-void MEDCouplingCMesh::getSplitCellValues(int *res) const
-{
-  int meshDim(getMeshDimension());
-  for(int l=0;l<meshDim;l++)
     {
-      int val=1;
-      for(int p=0;p<meshDim-l-1;p++)
-        val*=getCoordsAt(p)->getNbOfElems()-1;
-      res[meshDim-l-1]=val;
+      if(!_y_array->isAllocated() || _y_array->getNumberOfComponents()!=1)
+        throw INTERP_KERNEL::Exception("MEDCouplingCMesh::getNodeGridStructure : Y array exits but it is not allocated or with nb of components equal to one !");
+      if(!isOK)
+        throw INTERP_KERNEL::Exception(MSG);
+      ret.push_back(_y_array->getNumberOfTuples());
     }
-}
-
-void MEDCouplingCMesh::getSplitNodeValues(int *res) const
-{
-  int spaceDim(getSpaceDimension());
-  for(int l=0;l<spaceDim;l++)
+  else
+    isOK=false;
+  if(_z_array)
     {
-      int val=1;
-      for(int p=0;p<spaceDim-l-1;p++)
-        val*=getCoordsAt(p)->getNbOfElems();
-      res[spaceDim-l-1]=val;
+      if(!_z_array->isAllocated() || _z_array->getNumberOfComponents()!=1)
+        throw INTERP_KERNEL::Exception("MEDCouplingCMesh::getNodeGridStructure : Z array exits but it is not allocated or with nb of components equal to one !");
+      if(!isOK)
+        throw INTERP_KERNEL::Exception(MSG);
+      ret.push_back(_z_array->getNumberOfTuples());
     }
-}
-
-void MEDCouplingCMesh::getNodeGridStructure(int *res) const
-{
-  int spaceDim(getSpaceDimension());
-  for(int i=0;i<spaceDim;i++)
-    res[i]=getCoordsAt(i)->getNbOfElems();
-}
-
-std::vector<int> MEDCouplingCMesh::getNodeGridStructure() const
-{
-  std::vector<int> ret(getSpaceDimension());
-  getNodeGridStructure(&ret[0]);
   return ret;
 }
 
 MEDCouplingStructuredMesh *MEDCouplingCMesh::buildStructuredSubPart(const std::vector< std::pair<int,int> >& cellPart) const
 {
   checkCoherency();
-  int dim(getMeshDimension());
+  int dim(getSpaceDimension());
   if(dim!=(int)cellPart.size())
     {
-      std::ostringstream oss; oss << "MEDCouplingCMesh::buildStructuredSubPart : the mesh dimension is " << dim << " and cell part size is " << cellPart.size() << " !";
+      std::ostringstream oss; oss << "MEDCouplingCMesh::buildStructuredSubPart : the space dimension is " << dim << " and cell part size is " << cellPart.size() << " !";
       throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
   MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> ret(dynamic_cast<MEDCouplingCMesh *>(deepCpy()));
@@ -357,59 +334,11 @@ MEDCouplingStructuredMesh *MEDCouplingCMesh::buildStructuredSubPart(const std::v
 
 /*!
  * Return the space dimension of \a this. It only considers the arrays along X, Y and Z to deduce that.
- * This method throws exceptions if the not null arrays defining this are not contiguouly at the end. For example X!=0,Y==0,Z!=0 will throw.
+ * This method throws exceptions if the not null arrays defining this are not contiguously at the end. For example X!=0,Y==0,Z!=0 will throw.
  */
 int MEDCouplingCMesh::getSpaceDimension() const
 {
-  static const char MSG[]="MEDCouplingCMesh::getSpaceDimension : mesh is invalid ! null vectors (X, Y or Z) must be put contiguously at the end !";
-  int ret(0);
-  bool isOK(true);
-  if(_x_array)
-    ret++;
-  else
-    isOK=false;
-  if(_y_array)
-    {
-      if(!isOK)
-        throw INTERP_KERNEL::Exception(MSG);
-      ret++;
-    }
-  else
-    isOK=false;
-  if(_z_array)
-    {
-      if(!isOK)
-        throw INTERP_KERNEL::Exception(MSG);
-      ret++;
-    }
-  return ret;
-}
-
-/*!
- * This method returns the mesh dimension of \a this. It can be different from space dimension in case of a not null dimension contains only one node.
- */
-int MEDCouplingCMesh::getMeshDimension() const
-{
-  int ret(getSpaceDimension());
-  if(_x_array)
-    {
-      if(_x_array->isAllocated())
-        if(_x_array->getNumberOfTuples()==1)
-          ret--;
-    }
-  if(_y_array)
-    {
-      if(_y_array->isAllocated())
-        if(_y_array->getNumberOfTuples()==1)
-          ret--;
-    }
-  if(_z_array)
-    {
-      if(_z_array->isAllocated())
-        if(_z_array->getNumberOfTuples()==1)
-          ret--;
-    }
-  return ret;
+  return (int)getNodeGridStructure().size();
 }
 
 void MEDCouplingCMesh::getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const
@@ -434,7 +363,7 @@ std::string MEDCouplingCMesh::simpleRepr() const
   double tt=getTime(tmpp1,tmpp2);
   ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
   ret << "Iteration : " << tmpp1  << " Order : " << tmpp2 << "\n";
-  ret << "Mesh and SpaceDimension dimension : " << getSpaceDimension() << "\n\nArrays :\n________\n\n";
+  ret << "Space dimension : " << getSpaceDimension() << "\n\nArrays :\n________\n\n";
   if(_x_array)
     {
       ret << "X Array :\n";
@@ -692,7 +621,7 @@ int MEDCouplingCMesh::getCellContainingPoint(const double *pos, double eps) cons
 
 void MEDCouplingCMesh::rotate(const double *center, const double *vector, double angle)
 {
-  throw INTERP_KERNEL::Exception("No rotation available on CMesh : Traduce it to StructuredMesh to apply it !");
+  throw INTERP_KERNEL::Exception("No rotation available on CMesh : Traduce it to untructured mesh to apply it !");
 }
 
 /*!
@@ -986,6 +915,11 @@ void MEDCouplingCMesh::reprQuickOverview(std::ostream& stream) const
     }
 }
 
+std::string MEDCouplingCMesh::getVTKFileExtension() const
+{
+  return std::string("vtr");
+}
+
 std::string MEDCouplingCMesh::getVTKDataSetType() const
 {
   return std::string("RectilinearGrid");