Salome HOME
Some factorization before integration of ParaMEDMEM into medcoupling python module
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingStructuredMesh.cxx
index 9ea7ddb9358d116f9c6b1feec74c7bb3ed62262c..e39a599a46dadc13bef9799f44cb0e98baa8b511 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  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
@@ -33,7 +33,7 @@ MEDCouplingStructuredMesh::MEDCouplingStructuredMesh()
 {
 }
 
-MEDCouplingStructuredMesh::MEDCouplingStructuredMesh(const MEDCouplingStructuredMesh& other, bool deepCopy):MEDCouplingMesh(other)
+MEDCouplingStructuredMesh::MEDCouplingStructuredMesh(const MEDCouplingStructuredMesh& other, bool deepCpy):MEDCouplingMesh(other)
 {
 }
 
@@ -56,7 +56,7 @@ bool MEDCouplingStructuredMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, do
   return MEDCouplingMesh::isEqualIfNotWhy(other,prec,reason);
 }
 
-INTERP_KERNEL::NormalizedCellType MEDCouplingStructuredMesh::getTypeOfCell(int cellId) const
+INTERP_KERNEL::NormalizedCellType MEDCouplingStructuredMesh::getTypeOfCell(std::size_t cellId) const
 {
   return GetGeoTypeGivenMeshDimension(getMeshDimension());
 }
@@ -85,12 +85,12 @@ std::set<INTERP_KERNEL::NormalizedCellType> MEDCouplingStructuredMesh::getAllGeo
   return ret2;
 }
 
-int MEDCouplingStructuredMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
+std::size_t MEDCouplingStructuredMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
 {
-  int ret=getNumberOfCells();
+  std::size_t ret(getNumberOfCells());
   if(type==getTypeOfCell(0))
     return ret;
-  const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getTypeOfCell(0));
+  const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getTypeOfCell(0)));
   std::ostringstream oss; oss << "MEDCouplingStructuredMesh::getNumberOfCellsWithType : no specified type ! Type available is " << cm.getRepr() << " !";
   throw INTERP_KERNEL::Exception(oss.str().c_str());
 }
@@ -140,7 +140,7 @@ DataArrayInt *MEDCouplingStructuredMesh::computeEffectiveNbOfNodesPerCell() cons
   return computeNbOfNodesPerCell();
 }
 
-void MEDCouplingStructuredMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
+void MEDCouplingStructuredMesh::getNodeIdsOfCell(std::size_t cellId, std::vector<int>& conn) const
 {
   int meshDim=getMeshDimension();
   int tmpCell[3],tmpNode[3];
@@ -338,6 +338,10 @@ void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile,
 
 /*!
  * Creates a new unstructured mesh (MEDCoupling1SGTUMesh) from \a this structured one.
+ *
+ * In the returned mesh, the nodes are ordered with the first axis varying first: (X0,Y0), (X1,Y0),  ... (X0,Y1), (X1,Y1), ...
+ * and the cells are ordered with the same logic, i.e. in (i,j) notation: (0,0), (1,0), (2,0), ... (0,1), (1,1), ...
+ *
  *  \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
  * delete this array using decrRef() as it is no more needed. 
  *  \throw If \a this->getMeshDimension() is not among [1,2,3].
@@ -381,6 +385,10 @@ MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTSubLevelMesh() const
 
 /*!
  * Creates a new unstructured mesh (MEDCouplingUMesh) from \a this structured one.
+ *
+ * In the returned mesh, the nodes are ordered with the first axis varying first: (X0,Y0), (X1,Y0),  ... (X0,Y1), (X1,Y1), ...
+ * and the cells are ordered with the same logic, i.e. in (i,j) notation: (0,0), (1,0), (2,0), ... (0,1), (1,1), ...
+ *
  *  \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
  * delete this array using decrRef() as it is no more needed. 
  *  \throw If \a this->getMeshDimension() is not among [1,2,3].
@@ -403,10 +411,8 @@ MEDCouplingUMesh *MEDCouplingStructuredMesh::buildUnstructured() const
  */
 MEDCouplingMesh *MEDCouplingStructuredMesh::buildPart(const int *start, const int *end) const
 {
-  MEDCouplingUMesh *um=buildUnstructured();
-  MEDCouplingMesh *ret=um->buildPart(start,end);
-  um->decrRef();
-  return ret;
+  MCAuto<MEDCouplingUMesh> um(buildUnstructured());
+  return um->buildPart(start,end);
 }
 
 MEDCouplingMesh *MEDCouplingStructuredMesh::buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const
@@ -429,10 +435,8 @@ MEDCouplingMesh *MEDCouplingStructuredMesh::buildPartAndReduceNodes(const int *s
     }
   else
     {
-      MEDCouplingUMesh *um=buildUnstructured();
-      MEDCouplingMesh *ret=um->buildPartAndReduceNodes(start,end,arr);
-      um->decrRef();
-      return ret;
+      MCAuto<MEDCouplingUMesh> um(buildUnstructured());
+      return um->buildPartAndReduceNodes(start,end,arr);
     }
 }
 
@@ -453,17 +457,16 @@ MEDCouplingFieldDouble *MEDCouplingStructuredMesh::buildOrthogonalField() const
 {
   if(getMeshDimension()!=2)
     throw INTERP_KERNEL::Exception("Expected a MEDCouplingStructuredMesh with meshDim == 2 !");
-  MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME);
-  DataArrayDouble *array=DataArrayDouble::New();
-  int nbOfCells=getNumberOfCells();
+  MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(ON_CELLS,NO_TIME));
+  MCAuto<DataArrayDouble> array(DataArrayDouble::New());
+  int nbOfCells(getNumberOfCells());
   array->alloc(nbOfCells,3);
-  double *vals=array->getPointer();
+  double *vals(array->getPointer());
   for(int i=0;i<nbOfCells;i++)
     { vals[3*i]=0.; vals[3*i+1]=0.; vals[3*i+2]=1.; }
   ret->setArray(array);
-  array->decrRef();
   ret->setMesh(this);
-  return ret;
+  return ret.retn();
 }
 
 void MEDCouplingStructuredMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const
@@ -962,11 +965,11 @@ std::vector< std::vector<int> > MEDCouplingStructuredMesh::ComputeSignaturePerAx
 
 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity1D(const int *nodeStBg)
 {
-  int nbOfCells(*nodeStBg-1);
+  std::size_t nbOfCells(*nodeStBg-1);
   MCAuto<DataArrayInt> conn(DataArrayInt::New());
   conn->alloc(2*nbOfCells,1);
   int *cp=conn->getPointer();
-  for(int i=0;i<nbOfCells;i++)
+  for(std::size_t i=0;i<nbOfCells;i++)
     {
       cp[2*i+0]=i;
       cp[2*i+1]=i+1;
@@ -976,14 +979,13 @@ DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity1D(const int *
 
 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity2D(const int *nodeStBg)
 {
-  int n1=nodeStBg[0]-1;
-  int n2=nodeStBg[1]-1;
+  std::size_t n1(nodeStBg[0]-1),n2(nodeStBg[1]-1);
   MCAuto<DataArrayInt> conn(DataArrayInt::New());
   conn->alloc(4*n1*n2,1);
-  int *cp=conn->getPointer();
-  int pos=0;
-  for(int j=0;j<n2;j++)
-    for(int i=0;i<n1;i++,pos++)
+  int *cp(conn->getPointer());
+  std::size_t pos(0);
+  for(std::size_t j=0;j<n2;j++)
+    for(std::size_t i=0;i<n1;i++,pos++)
       {
         cp[4*pos+0]=i+1+j*(n1+1);
         cp[4*pos+1]=i+j*(n1+1);
@@ -995,16 +997,14 @@ DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity2D(const int *
 
 DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity3D(const int *nodeStBg)
 {
-  int n1=nodeStBg[0]-1;
-  int n2=nodeStBg[1]-1;
-  int n3=nodeStBg[2]-1;
+  std::size_t n1(nodeStBg[0]-1),n2(nodeStBg[1]-1),n3(nodeStBg[2]-1);
   MCAuto<DataArrayInt> conn(DataArrayInt::New());
   conn->alloc(8*n1*n2*n3,1);
-  int *cp=conn->getPointer();
-  int pos=0;
-  for(int k=0;k<n3;k++)
-    for(int j=0;j<n2;j++)
-      for(int i=0;i<n1;i++,pos++)
+  int *cp(conn->getPointer());
+  std::size_t pos(0);
+  for(std::size_t k=0;k<n3;k++)
+    for(std::size_t j=0;j<n2;j++)
+      for(std::size_t i=0;i<n1;i++,pos++)
         {
           int tmp=(n1+1)*(n2+1);
           cp[8*pos+0]=i+1+j*(n1+1)+k*tmp;
@@ -1239,10 +1239,10 @@ int MEDCouplingStructuredMesh::getNodeIdFromPos(int i, int j, int k) const
 }
 
 
-int MEDCouplingStructuredMesh::getNumberOfCells() const
+std::size_t MEDCouplingStructuredMesh::getNumberOfCells() const
 {
   std::vector<int> ngs(getNodeGridStructure());
-  int ret(1);
+  std::size_t ret(1);
   bool isCatched(false);
   std::size_t ii(0);
   for(std::vector<int>::const_iterator it=ngs.begin();it!=ngs.end();it++,ii++)
@@ -1956,7 +1956,7 @@ DataArrayInt *MEDCouplingStructuredMesh::BuildExplicitIdsFrom(const std::vector<
  * \param [in] st - the structure of grid ( \b without considering ghost cells).
  * \param [in] part - the part in the structure ( \b without considering ghost cells) contained in grid whose structure is defined by \a st.
  * \param [in] factor - the factor, the tuples in \a da will be multiply by.
- * \param [in,out] da - The DataArray in wich only tuples specified by \a part will be modified.
+ * \param [in,out] da - The DataArray in which only tuples specified by \a part will be modified.
  *
  * \sa BuildExplicitIdsFrom
  */
@@ -2037,7 +2037,7 @@ void MEDCouplingStructuredMesh::MultiplyPartOf(const std::vector<int>& st, const
  * \param [in] part - the part in the structure ( \b without considering ghost cells) contained in grid whose structure is defined by \a st.
  * \param [in] ghostSize - \a ghostSize must be >= 0.
  * \param [in] factor - the factor, the tuples in \a da will be multiply by.
- * \param [in,out] da - The DataArray in wich only tuples specified by \a part will be modified.
+ * \param [in,out] da - The DataArray in which only tuples specified by \a part will be modified.
  *
  * \sa MultiplyPartOf, PutInGhostFormat
  */