From 8f72feb23b472a821b5a80b35e403bb86b337af6 Mon Sep 17 00:00:00 2001
From: Max Kahnt <max.kahnt@fu-berlin.de>
Date: Fri, 19 Feb 2016 22:26:13 +0100
Subject: [PATCH] Refactor typenames, typedefs. Fix warnings.

---
 .../iterationsteps/projectedblockgsstep.cc    | 16 +++++++-------
 .../iterationsteps/projectedblockgsstep.hh    | 22 +++++++++----------
 .../iterationsteps/trustregiongsstep.cc       | 20 ++++++++---------
 .../iterationsteps/trustregiongsstep.hh       |  9 +++-----
 4 files changed, 31 insertions(+), 36 deletions(-)

diff --git a/dune/solvers/iterationsteps/projectedblockgsstep.cc b/dune/solvers/iterationsteps/projectedblockgsstep.cc
index 770f7654..25c4f71d 100644
--- a/dune/solvers/iterationsteps/projectedblockgsstep.cc
+++ b/dune/solvers/iterationsteps/projectedblockgsstep.cc
@@ -1,9 +1,9 @@
 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 // vi: set et ts=8 sw=4 sts=4:
 
-template<class MatrixType, class DiscFuncType>
+template<class MatrixType, class VectorType>
 inline
-void ProjectedBlockGSStep<MatrixType, DiscFuncType>::iterate()
+void ProjectedBlockGSStep<MatrixType, VectorType>::iterate()
 {
     if (hasObstacle_->size()!= (unsigned int)this->x_->size())
         DUNE_THROW(SolverError, "Size of hasObstacle (" << hasObstacle_->size()
@@ -18,7 +18,7 @@ void ProjectedBlockGSStep<MatrixType, DiscFuncType>::iterate()
             continue;
 
         bool zeroDiagonal = false;
-        for (int j=0; j<BlockSize; j++) {
+        for (size_t j=0; j<BlockSize; j++) {
             // When using this solver as part of a truncated multigrid solver,
             // the diagonal entries of the matrix may get completely truncated
             // away.  In this case we just do nothing here.
@@ -45,19 +45,19 @@ void ProjectedBlockGSStep<MatrixType, DiscFuncType>::iterate()
 
             // Solve the local constraint minimization problem
             // We use a projected Gauss-Seidel, for lack of anything better
-            BoxConstraint<field_type,BlockSize> defectObstacle = (*obstacles_)[i];
+            Obstacle defectObstacle = (*obstacles_)[i];
             defectObstacle -= x;
 
             // Initial correction
             v = 0;
 
-            for (int j=0; j< ((BlockSize==1) ? 1 : 20); j++) {
+            for (size_t j=0; j< ((BlockSize==1) ? 1 : 20); j++) {
 
-                for (int k=0; k<BlockSize; k++) {
+                for (size_t k=0; k<BlockSize; k++) {
 
                     // Compute residual
-                    field_type sr = 0;
-                    for (int l=0; l<BlockSize; l++)
+                    Field sr = 0;
+                    for (size_t l=0; l<BlockSize; l++)
                         sr += mat[i][i][k][l] * v[l];
 
                     sr = r[k] - sr;
diff --git a/dune/solvers/iterationsteps/projectedblockgsstep.hh b/dune/solvers/iterationsteps/projectedblockgsstep.hh
index ba267af4..c361cae0 100644
--- a/dune/solvers/iterationsteps/projectedblockgsstep.hh
+++ b/dune/solvers/iterationsteps/projectedblockgsstep.hh
@@ -8,32 +8,30 @@
 #include "blockgsstep.hh"
 #include <dune/solvers/common/boxconstraint.hh>
 
-template<class MatrixType, class DiscFuncType>
-class ProjectedBlockGSStep : public BlockGSStep<MatrixType, DiscFuncType>
+template<class MatrixType, class VectorType>
+class ProjectedBlockGSStep : public BlockGSStep<MatrixType, VectorType>
 {
-
-    typedef typename DiscFuncType::block_type VectorBlock;
-
-    typedef typename DiscFuncType::field_type field_type;
+    using VectorBlock = typename VectorType::block_type;
+    using Field = typename VectorType::field_type;
 
     enum {BlockSize = VectorBlock::dimension};
 
 public:
-
     //! Default constructor.  Doesn't init anything
     ProjectedBlockGSStep() {}
 
     //! Constructor with a linear problem
-    ProjectedBlockGSStep(const MatrixType& mat, DiscFuncType& x, const DiscFuncType& rhs)
-        : BlockGSStep<MatrixType,DiscFuncType>(mat, x, rhs)
+    ProjectedBlockGSStep(const MatrixType& mat, VectorType& x, const VectorType& rhs)
+        : BlockGSStep<MatrixType,VectorType>(mat, x, rhs)
     {}
 
     //! Perform one iteration
     virtual void iterate();
 
-    const Dune::BitSetVector<BlockSize>* hasObstacle_;
-
-    const std::vector<BoxConstraint<field_type,BlockSize> >* obstacles_;
+    using HasObstacle = Dune::BitSetVector<BlockSize>;
+    using Obstacle = BoxConstraint<Field, BlockSize>;
+    const HasObstacle* hasObstacle_;
+    const std::vector<Obstacle>* obstacles_;
 };
 
 #include "projectedblockgsstep.cc"
diff --git a/dune/solvers/iterationsteps/trustregiongsstep.cc b/dune/solvers/iterationsteps/trustregiongsstep.cc
index 1fe72231..f06d68c3 100644
--- a/dune/solvers/iterationsteps/trustregiongsstep.cc
+++ b/dune/solvers/iterationsteps/trustregiongsstep.cc
@@ -14,16 +14,16 @@ void TrustRegionGSStep<MatrixType, VectorType>::iterate()
 {
     const MatrixType& mat = *this->mat_;
     VectorType& x = *this->x_;
-    const std::vector<BoxConstraint<field_type,blocksize> >& obstacles = *this->obstacles_;
+    const std::vector<BoxConstraint<Field,BlockSize> >& obstacles = *this->obstacles_;
 
     for (size_t i=0; i<x.size(); i++) {
 
         // Dirichlet nodes in this block
-        std::bitset<blocksize> ignoreNodes(0);
+        std::bitset<BlockSize> ignoreNodes(0);
         if (this->ignoreNodes_)
             ignoreNodes = (*this->ignoreNodes_)[i];
 
-        if (ignoreNodes.count() == blocksize)
+        if (ignoreNodes.count() == BlockSize)
             continue;
 
         VectorBlock blockResidual;
@@ -32,16 +32,16 @@ void TrustRegionGSStep<MatrixType, VectorType>::iterate()
         mat[i][i].umv(x[i], blockResidual);
 
         // scalar gauss-seidel
-        for (int j=0; j<blocksize; j++) {
+        for (size_t j=0; j<BlockSize; j++) {
 
             if (ignoreNodes[j])
                 continue;
 
             // Compute residual
-            field_type r = blockResidual[j] - mat[i][i][j] * x[i];
+            Field r = blockResidual[j] - mat[i][i][j] * x[i];
             r += mat[i][i][j][j] * x[i][j];
 
-            const field_type& diag = mat[i][i][j][j];
+            const Field& diag = mat[i][i][j][j];
 
             // Find local minimum
             if (diag > 0) {
@@ -63,11 +63,11 @@ void TrustRegionGSStep<MatrixType, VectorType>::iterate()
 
                 // 1d problem is concave or linear.
                 // Minimum is attained at one of the boundaries
-                field_type lBound = obstacles[i].lower(j);
-                field_type uBound = obstacles[i].upper(j);
+                Field lBound = obstacles[i].lower(j);
+                Field uBound = obstacles[i].upper(j);
 
-                field_type lValue = 0.5*diag*lBound*lBound - r*lBound;
-                field_type uValue = 0.5*diag*uBound*uBound - r*uBound;
+                Field lValue = 0.5*diag*lBound*lBound - r*lBound;
+                Field uValue = 0.5*diag*uBound*uBound - r*uBound;
 
                 x[i][j] = (lValue < uValue) ? lBound : uBound;
 
diff --git a/dune/solvers/iterationsteps/trustregiongsstep.hh b/dune/solvers/iterationsteps/trustregiongsstep.hh
index f3328bcb..3cba0679 100644
--- a/dune/solvers/iterationsteps/trustregiongsstep.hh
+++ b/dune/solvers/iterationsteps/trustregiongsstep.hh
@@ -17,15 +17,12 @@
     template<class MatrixType, class VectorType>
     class TrustRegionGSStep : public ProjectedBlockGSStep<MatrixType, VectorType>
     {
+        using VectorBlock = typename VectorType::block_type;
+        using Field = VectorType::field_type;
 
-        typedef typename VectorType::block_type VectorBlock;
-
-        enum {blocksize = VectorBlock::dimension};
-
-        typedef typename VectorType::field_type field_type;
+        enum {BlockSize = VectorBlock::dimension};
 
     public:
-
         //! Default constructor.  Doesn't init anything
         TrustRegionGSStep() {}
 
-- 
GitLab