From 50d57b273d913bea9cae638cf260f5faf5cd9b6f Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Sun, 21 Jul 2013 23:37:10 +0200
Subject: [PATCH] [Cleanup] int -> size_t whereever possible

---
 dune/tectonic/ellipticenergy.hh          | 10 ++++-----
 dune/tectonic/globalnonlinearity.hh      |  6 +++---
 dune/tectonic/globalruinanonlinearity.hh |  2 +-
 dune/tectonic/localfriction.hh           |  8 ++++----
 dune/tectonic/myblockproblem.hh          | 26 ++++++++++++------------
 src/one-body-sample.cc                   | 13 ++++++------
 src/solverfactory.cc                     |  8 ++++----
 src/solverfactory.hh                     |  4 ++--
 src/timestepping.hh                      |  2 +-
 src/timestepping/backward_euler.cc       | 12 +++++------
 src/timestepping/backward_euler.hh       |  2 +-
 src/timestepping/newmark.cc              | 12 +++++------
 src/timestepping/newmark.hh              |  2 +-
 13 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/dune/tectonic/ellipticenergy.hh b/dune/tectonic/ellipticenergy.hh
index 68c8e480..af295f83 100644
--- a/dune/tectonic/ellipticenergy.hh
+++ b/dune/tectonic/ellipticenergy.hh
@@ -11,7 +11,7 @@
 #include "localfriction.hh"
 
 namespace Dune {
-template <int dim> class EllipticEnergy {
+template <size_t dim> class EllipticEnergy {
 public:
   using SmallVector = FieldVector<double, dim>;
   using SmallMatrix = FieldMatrix<double, dim, dim>;
@@ -19,7 +19,7 @@ template <int dim> class EllipticEnergy {
   using NonlinearityType = LocalFriction<dim>;
 
   EllipticEnergy(SmallMatrix const &A, SmallVector const &b,
-                 shared_ptr<NonlinearityType const> phi, int ignore = dim)
+                 shared_ptr<NonlinearityType const> phi, size_t ignore = dim)
       : A(A), b(b), phi(phi), ignore(ignore) {}
 
   double operator()(SmallVector const &v) const {
@@ -32,9 +32,9 @@ template <int dim> class EllipticEnergy {
   SmallMatrix const &A;
   SmallVector const &b;
   shared_ptr<NonlinearityType const> const phi;
-  int const ignore; // Dimension that should be ignored; goes from 0
-                    // to dim-1; the special value dim means that no
-                    // dimension should be ignored
+  /* Dimension that should be ignored; goes from 0 to dim-1; the
+     special value dim means that no dimension should be ignored */
+  size_t const ignore;
 
   void gradient(SmallVector const &x, SmallVector &y) const {
     A.mv(x, y);
diff --git a/dune/tectonic/globalnonlinearity.hh b/dune/tectonic/globalnonlinearity.hh
index f0ad8933..a2816400 100644
--- a/dune/tectonic/globalnonlinearity.hh
+++ b/dune/tectonic/globalnonlinearity.hh
@@ -23,7 +23,7 @@ class GlobalNonlinearity {
   using VectorType = VectorTypeTEMPLATE;
   using LocalMatrixType = typename MatrixType::block_type;
   using LocalVectorType = typename VectorType::block_type;
-  static const int block_size = LocalVectorType::dimension;
+  size_t static const block_size = LocalVectorType::dimension;
   using FrictionType = LocalFriction<block_size>;
 
   double operator()(VectorType const &x) const {
@@ -38,7 +38,7 @@ class GlobalNonlinearity {
   /*
     Return a restriction of the outer function to the i'th node.
   */
-  virtual shared_ptr<LocalFriction<block_size>> restriction(int i) const = 0;
+  virtual shared_ptr<LocalFriction<block_size>> restriction(size_t i) const = 0;
 
   void addHessian(VectorType const &v, MatrixType &hessian) const {
     for (size_t i = 0; i < v.size(); ++i) {
@@ -77,7 +77,7 @@ class GlobalNonlinearity {
     }
   }
 
-  double regularity(int i, typename VectorType::block_type const &x) const {
+  double regularity(size_t i, typename VectorType::block_type const &x) const {
     auto const res = restriction(i);
     return res->regularity(x);
   }
diff --git a/dune/tectonic/globalruinanonlinearity.hh b/dune/tectonic/globalruinanonlinearity.hh
index 5a899ed2..3e1570ac 100644
--- a/dune/tectonic/globalruinanonlinearity.hh
+++ b/dune/tectonic/globalruinanonlinearity.hh
@@ -50,7 +50,7 @@ class GlobalRuinaNonlinearity
   /*
     Return a restriction of the outer function to the i'th node.
   */
-  shared_ptr<FrictionType> restriction(int i) const override {
+  shared_ptr<FrictionType> restriction(size_t i) const override {
     return restrictions[i];
   }
 
diff --git a/dune/tectonic/localfriction.hh b/dune/tectonic/localfriction.hh
index 490d663f..57289d2d 100644
--- a/dune/tectonic/localfriction.hh
+++ b/dune/tectonic/localfriction.hh
@@ -31,7 +31,7 @@ double dotFirstNormalised(VectorType const &x, VectorType const &y) {
 }
 
 namespace Dune {
-template <int dimension> class LocalFriction {
+template <size_t dimension> class LocalFriction {
 public:
   using VectorType = FieldVector<double, dimension>;
   using MatrixType = FieldMatrix<double, dimension, dimension>;
@@ -92,14 +92,14 @@ template <int dimension> class LocalFriction {
     double const tensorweight = (H2 - H1 / xnorm) / xnorm2;
     double const idweight = H1 / xnorm;
 
-    for (int i = 0; i < dimension; ++i)
-      for (int j = 0; j < i; ++j) {
+    for (size_t i = 0; i < dimension; ++i)
+      for (size_t j = 0; j < i; ++j) {
         double const entry = tensorweight * x[i] * x[j];
         A[i][j] += entry;
         A[j][i] += entry;
       }
 
-    for (int k = 0; k < dimension; ++k) {
+    for (size_t k = 0; k < dimension; ++k) {
       double const entry = tensorweight * x[k] * x[k];
       A[k][k] += entry + idweight;
     }
diff --git a/dune/tectonic/myblockproblem.hh b/dune/tectonic/myblockproblem.hh
index b94d3dcf..2f440a83 100644
--- a/dune/tectonic/myblockproblem.hh
+++ b/dune/tectonic/myblockproblem.hh
@@ -35,14 +35,14 @@ template <class ConvexProblemTypeTEMPLATE> class MyBlockProblem {
   using MatrixType = typename ConvexProblemType::MatrixType;
   using LocalVectorType = typename ConvexProblemType::LocalVectorType;
   using LocalMatrixType = typename ConvexProblemType::LocalMatrixType;
-  int static const block_size = ConvexProblemType::block_size;
-  int static const coarse_block_size = block_size;
+  size_t static const block_size = ConvexProblemType::block_size;
+  size_t static const coarse_block_size = block_size;
 
   /** \brief Solves one local system using a modified gradient method */
   class IterateObject;
 
   struct Linearization {
-    static const int block_size = coarse_block_size;
+    size_t static const block_size = coarse_block_size;
 
     using LocalMatrixType =
         typename MyBlockProblem<ConvexProblemType>::LocalMatrixType;
@@ -67,7 +67,7 @@ template <class ConvexProblemTypeTEMPLATE> class MyBlockProblem {
   std::string getOutput(bool header = false) const {
     if (header) {
       outStream.str("");
-      for (int j = 0; j < block_size; ++j)
+      for (size_t j = 0; j < block_size; ++j)
         outStream << "  trunc" << std::setw(2) << j;
     }
     std::string s = outStream.str();
@@ -81,7 +81,7 @@ template <class ConvexProblemTypeTEMPLATE> class MyBlockProblem {
                                Linearization const &linearization) const {
     projected_v = v;
     for (size_t i = 0; i < v.size(); ++i)
-      for (int j = 0; j < block_size; ++j)
+      for (size_t j = 0; j < block_size; ++j)
         if (linearization.truncation[i][j])
           projected_v[i][j] = 0;
   }
@@ -126,7 +126,7 @@ template <class ConvexProblemTypeTEMPLATE> class MyBlockProblem {
         continue;
       }
 
-      for (int j = 0; j < block_size; ++j)
+      for (size_t j = 0; j < block_size; ++j)
         if (linearization.ignore[i][j])
           linearization.truncation[i][j] = true;
     }
@@ -166,7 +166,7 @@ template <class ConvexProblemTypeTEMPLATE> class MyBlockProblem {
       auto const col_end = linearization.A[row].end();
       for (auto col_it = linearization.A[row].begin(); col_it != col_end;
            ++col_it) {
-        int const col = col_it.index();
+        size_t const col = col_it.index();
         for (size_t i = 0; i < col_it->N(); ++i) {
           auto const blockEnd = (*col_it)[i].end();
           for (auto blockIt = (*col_it)[i].begin(); blockIt != blockEnd;
@@ -177,12 +177,12 @@ template <class ConvexProblemTypeTEMPLATE> class MyBlockProblem {
         }
       }
 
-      for (int j = 0; j < block_size; ++j)
+      for (size_t j = 0; j < block_size; ++j)
         if (linearization.truncation[row][j])
           linearization.b[row][j] = 0.0;
     }
 
-    for (int j = 0; j < block_size; ++j)
+    for (size_t j = 0; j < block_size; ++j)
       outStream << std::setw(9) << linearization.truncation.countmasked(j);
   }
 
@@ -227,7 +227,7 @@ class MyBlockProblem<ConvexProblemTypeTEMPLATE>::IterateObject {
   }
 
   /** \brief Update the i-th block of the current iterate */
-  void updateIterate(LocalVectorType const &ui, int i) {
+  void updateIterate(LocalVectorType const &ui, size_t i) {
     u[i] = ui;
     return;
   }
@@ -238,10 +238,10 @@ class MyBlockProblem<ConvexProblemTypeTEMPLATE>::IterateObject {
    * \param ignore Set of degrees of freedom to leave untouched
    */
   void solveLocalProblem(
-      LocalVectorType &ui, int m,
+      LocalVectorType &ui, size_t m,
       typename Dune::BitSetVector<block_size>::const_reference ignore) {
     {
-      int ic =
+      size_t ic =
           block_size; // Special value that indicates nothing should be ignored
       switch (ignore.count()) {
         case 0: // Full problem
@@ -262,7 +262,7 @@ class MyBlockProblem<ConvexProblemTypeTEMPLATE>::IterateObject {
 
       auto const end = problem.A[m].end();
       for (auto it = problem.A[m].begin(); it != end; ++it) {
-        int const j = it.index();
+        size_t const j = it.index();
         if (j == m)
           localA = &(*it); // localA = A[m][m]
         else
diff --git a/src/one-body-sample.cc b/src/one-body-sample.cc
index a8166844..0ea095a8 100644
--- a/src/one-body-sample.cc
+++ b/src/one-body-sample.cc
@@ -91,13 +91,14 @@
 #include "state/ruinastateupdater.hh"
 #include "state/dieterichstateupdater.hh"
 
-int const dims = DIM;
+size_t const dims = DIM;
 
-template <class VectorType, class MatrixType, class FunctionType, int dims>
-Dune::shared_ptr<TimeSteppingScheme<VectorType, MatrixType, FunctionType, dims>>
+template <class VectorType, class MatrixType, class FunctionType, int dimension>
+Dune::shared_ptr<
+    TimeSteppingScheme<VectorType, MatrixType, FunctionType, dimension>>
 initTimeStepper(Config::scheme scheme,
                 FunctionType const &velocityDirichletFunction,
-                Dune::BitSetVector<dims> const &velocityDirichletNodes,
+                Dune::BitSetVector<dimension> const &velocityDirichletNodes,
                 MatrixType const &massMatrix, MatrixType const &stiffnessMatrix,
                 VectorType const &u_initial, VectorType const &v_initial,
                 VectorType const &a_initial) {
@@ -277,11 +278,11 @@ int main(int argc, char *argv[]) {
       }
       {
         double volume = 1.0;
-        for (int i = 0; i < dims; ++i)
+        for (size_t i = 0; i < dims; ++i)
           volume *= (upperRight[i] - lowerLeft[i]);
 
         double area = 1.0;
-        for (int i = 0; i < dims; ++i)
+        for (size_t i = 0; i < dims; ++i)
           if (i != 1)
             area *= (upperRight[i] - lowerLeft[i]);
 
diff --git a/src/solverfactory.cc b/src/solverfactory.cc
index 37cd0d40..cdd18852 100644
--- a/src/solverfactory.cc
+++ b/src/solverfactory.cc
@@ -11,9 +11,9 @@
 
 #include "solverfactory.hh"
 
-template <int dim, class BlockProblemType, class GridType>
+template <size_t dim, class BlockProblemType, class GridType>
 SolverFactory<dim, BlockProblemType, GridType>::SolverFactory(
-    Dune::ParameterTree const &parset, int refinements, GridType const &grid,
+    Dune::ParameterTree const &parset, size_t refinements, GridType const &grid,
     Dune::BitSetVector<dim> const &ignoreNodes)
     : baseEnergyNorm(linearBaseSolverStep),
       linearBaseSolver(&linearBaseSolverStep,
@@ -43,7 +43,7 @@ SolverFactory<dim, BlockProblemType, GridType>::SolverFactory(
   multigridStep->ignoreNodes_ = &ignoreNodes;
 }
 
-template <int dim, class BlockProblemType, class GridType>
+template <size_t dim, class BlockProblemType, class GridType>
 SolverFactory<dim, BlockProblemType, GridType>::~SolverFactory() {
   for (auto &x : transferOperators)
     delete x;
@@ -51,7 +51,7 @@ SolverFactory<dim, BlockProblemType, GridType>::~SolverFactory() {
   delete multigridStep;
 }
 
-template <int dim, class BlockProblemType, class GridType>
+template <size_t dim, class BlockProblemType, class GridType>
 typename SolverFactory<dim, BlockProblemType, GridType>::SolverType *
 SolverFactory<dim, BlockProblemType, GridType>::getSolver() {
   return multigridStep;
diff --git a/src/solverfactory.hh b/src/solverfactory.hh
index 45f4a0d6..4b8c533e 100644
--- a/src/solverfactory.hh
+++ b/src/solverfactory.hh
@@ -12,7 +12,7 @@
 #include <dune/solvers/transferoperators/compressedmultigridtransfer.hh>
 #include <dune/tnnmg/iterationsteps/tnnmgstep.hh>
 
-template <int dim, class BlockProblemTypeTEMPLATE, class GridType>
+template <size_t dim, class BlockProblemTypeTEMPLATE, class GridType>
 class SolverFactory {
 public:
   using BlockProblemType = BlockProblemTypeTEMPLATE;
@@ -26,7 +26,7 @@ class SolverFactory {
                                                        NonlinearSmootherType>;
 
 public:
-  SolverFactory(Dune::ParameterTree const &parset, int refinements,
+  SolverFactory(Dune::ParameterTree const &parset, size_t refinements,
                 GridType const &grid,
                 Dune::BitSetVector<dim> const &ignoreNodes);
 
diff --git a/src/timestepping.hh b/src/timestepping.hh
index fd247f6c..861d8475 100644
--- a/src/timestepping.hh
+++ b/src/timestepping.hh
@@ -3,7 +3,7 @@
 
 #include <dune/common/bitsetvector.hh>
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 class TimeSteppingScheme {
 public:
   void virtual nextTimeStep() = 0;
diff --git a/src/timestepping/backward_euler.cc b/src/timestepping/backward_euler.cc
index b95a0063..eef042e3 100644
--- a/src/timestepping/backward_euler.cc
+++ b/src/timestepping/backward_euler.cc
@@ -1,4 +1,4 @@
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 BackwardEuler<VectorType, MatrixType, FunctionType, dim>::BackwardEuler(
     MatrixType const &_A, MatrixType const &_M, VectorType const &_u_initial,
     VectorType const &_v_initial,
@@ -11,13 +11,13 @@ BackwardEuler<VectorType, MatrixType, FunctionType, dim>::BackwardEuler(
       dirichletNodes(_dirichletNodes),
       dirichletFunction(_dirichletFunction) {}
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 void BackwardEuler<VectorType, MatrixType, FunctionType, dim>::nextTimeStep() {
   v_o = v;
   u_o = u;
 }
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 void BackwardEuler<VectorType, MatrixType, FunctionType, dim>::setup(
     VectorType const &ell, double _tau, double time, VectorType &rhs,
     VectorType &iterate, MatrixType &AM) {
@@ -94,7 +94,7 @@ void BackwardEuler<VectorType, MatrixType, FunctionType, dim>::setup(
     }
 }
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 void BackwardEuler<VectorType, MatrixType, FunctionType, dim>::postProcess(
     VectorType const &iterate) {
   postProcessCalled = true;
@@ -105,7 +105,7 @@ void BackwardEuler<VectorType, MatrixType, FunctionType, dim>::postProcess(
   Arithmetic::addProduct(u, tau, v);
 }
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 void BackwardEuler<VectorType, MatrixType, FunctionType,
                    dim>::extractDisplacement(VectorType &displacement) const {
   if (!postProcessCalled)
@@ -114,7 +114,7 @@ void BackwardEuler<VectorType, MatrixType, FunctionType,
   displacement = u;
 }
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 void BackwardEuler<VectorType, MatrixType, FunctionType, dim>::extractVelocity(
     VectorType &velocity) const {
   if (!postProcessCalled)
diff --git a/src/timestepping/backward_euler.hh b/src/timestepping/backward_euler.hh
index 202c4420..98eb362b 100644
--- a/src/timestepping/backward_euler.hh
+++ b/src/timestepping/backward_euler.hh
@@ -1,7 +1,7 @@
 #ifndef DUNE_TECTONIC_TIMESTEPPING_BACKWARD_EULER_HH
 #define DUNE_TECTONIC_TIMESTEPPING_BACKWARD_EULER_HH
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 class BackwardEuler
     : public TimeSteppingScheme<VectorType, MatrixType, FunctionType, dim> {
 public:
diff --git a/src/timestepping/newmark.cc b/src/timestepping/newmark.cc
index 743b660d..f2190ac4 100644
--- a/src/timestepping/newmark.cc
+++ b/src/timestepping/newmark.cc
@@ -1,4 +1,4 @@
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 Newmark<VectorType, MatrixType, FunctionType, dim>::Newmark(
     MatrixType const &_A, MatrixType const &_M, VectorType const &_u_initial,
     VectorType const &_v_initial, VectorType const &_a_initial,
@@ -12,14 +12,14 @@ Newmark<VectorType, MatrixType, FunctionType, dim>::Newmark(
       dirichletNodes(_dirichletNodes),
       dirichletFunction(_dirichletFunction) {}
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 void Newmark<VectorType, MatrixType, FunctionType, dim>::nextTimeStep() {
   a_o = a;
   v_o = v;
   u_o = u;
 }
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 void Newmark<VectorType, MatrixType, FunctionType, dim>::setup(
     VectorType const &ell, double _tau, double time, VectorType &rhs,
     VectorType &iterate, MatrixType &AM) {
@@ -99,7 +99,7 @@ void Newmark<VectorType, MatrixType, FunctionType, dim>::setup(
     }
 }
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 void Newmark<VectorType, MatrixType, FunctionType, dim>::postProcess(
     VectorType const &iterate) {
   postProcessCalled = true;
@@ -118,7 +118,7 @@ void Newmark<VectorType, MatrixType, FunctionType, dim>::postProcess(
   Arithmetic::subtractProduct(a, 1.0, a_o);
 }
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 void Newmark<VectorType, MatrixType, FunctionType, dim>::extractDisplacement(
     VectorType &displacement) const {
   if (!postProcessCalled)
@@ -127,7 +127,7 @@ void Newmark<VectorType, MatrixType, FunctionType, dim>::extractDisplacement(
   displacement = u;
 }
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 void Newmark<VectorType, MatrixType, FunctionType, dim>::extractVelocity(
     VectorType &velocity) const {
   if (!postProcessCalled)
diff --git a/src/timestepping/newmark.hh b/src/timestepping/newmark.hh
index ff707a7e..f4dc7e60 100644
--- a/src/timestepping/newmark.hh
+++ b/src/timestepping/newmark.hh
@@ -1,7 +1,7 @@
 #ifndef DUNE_TECTONIC_TIMESTEPPING_NEWMARK_HH
 #define DUNE_TECTONIC_TIMESTEPPING_NEWMARK_HH
 
-template <class VectorType, class MatrixType, class FunctionType, int dim>
+template <class VectorType, class MatrixType, class FunctionType, size_t dim>
 class Newmark
     : public TimeSteppingScheme<VectorType, MatrixType, FunctionType, dim> {
 public:
-- 
GitLab