From f7efc3eeb62e96b82661c2528279444944bc18d7 Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Fri, 31 Jan 2020 17:35:11 +0100
Subject: [PATCH] [linear] Move scaleLinearSystem to its own header

---
 dumux/linear/CMakeLists.txt       |  1 +
 dumux/linear/amgbackend.hh        | 31 ------------------
 dumux/linear/scalelinearsystem.hh | 54 +++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 31 deletions(-)
 create mode 100644 dumux/linear/scalelinearsystem.hh

diff --git a/dumux/linear/CMakeLists.txt b/dumux/linear/CMakeLists.txt
index 115cb9a3ed..6cdfe68ee2 100644
--- a/dumux/linear/CMakeLists.txt
+++ b/dumux/linear/CMakeLists.txt
@@ -7,6 +7,7 @@ linearsolveracceptsmultitypematrix.hh
 matrixconverter.hh
 parallelhelpers.hh
 pdesolver.hh
+scalelinearsystem.hh
 scotchbackend.hh
 seqsolverbackend.hh
 solver.hh
diff --git a/dumux/linear/amgbackend.hh b/dumux/linear/amgbackend.hh
index 1f35a28577..e8c4052b2c 100644
--- a/dumux/linear/amgbackend.hh
+++ b/dumux/linear/amgbackend.hh
@@ -47,37 +47,6 @@
 
 namespace Dumux {
 
-/*!
- * \ingroup Linear
- * \brief Scale the linear system by the inverse of
- * its (block-)diagonal entries.
- *
- * \param matrix the matrix to scale
- * \param rhs the right hand side vector to scale
- */
-template <class Matrix, class Vector>
-void scaleLinearSystem(Matrix& matrix, Vector& rhs)
-{
-    typename Matrix::RowIterator row = matrix.begin();
-    for(; row != matrix.end(); ++row)
-    {
-        using size_type = typename Matrix::size_type;
-        size_type rowIdx = row.index();
-
-        using MatrixBlock = typename Matrix::block_type;
-        MatrixBlock diagonal = matrix[rowIdx][rowIdx];
-        diagonal.invert();
-
-        using VectorBlock = typename Vector::block_type;
-        const VectorBlock b = rhs[rowIdx];
-        diagonal.mv(b, rhs[rowIdx]);
-
-        typename Matrix::ColIterator col = row->begin();
-        for (; col != row->end(); ++col)
-            col->leftmultiply(diagonal);
-    }
-}
-
 /*!
  * \ingroup Linear
  * \brief A linear solver based on the ISTL AMG preconditioner
diff --git a/dumux/linear/scalelinearsystem.hh b/dumux/linear/scalelinearsystem.hh
new file mode 100644
index 0000000000..ddafe932ea
--- /dev/null
+++ b/dumux/linear/scalelinearsystem.hh
@@ -0,0 +1,54 @@
+// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+// vi: set et ts=4 sw=4 sts=4:
+/*****************************************************************************
+ *   See the file COPYING for full copying permissions.                      *
+ *                                                                           *
+ *   This program is free software: you can redistribute it and/or modify    *
+ *   it under the terms of the GNU General Public License as published by    *
+ *   the Free Software Foundation, either version 3 of the License, or       *
+ *   (at your option) any later version.                                     *
+ *                                                                           *
+ *   This program is distributed in the hope that it will be useful,         *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
+ *   GNU General Public License for more details.                            *
+ *                                                                           *
+ *   You should have received a copy of the GNU General Public License       *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
+ *****************************************************************************/
+/*!
+ * \file
+ * \ingroup Linear
+ * \brief Free function to scale a linear system
+ */
+#ifndef DUMUX_LINEAR_SCALELINEARSYSTEM_HH
+#define DUMUX_LINEAR_SCALELINEARSYSTEM_HH
+
+namespace Dumux {
+
+/*!
+ * \ingroup Linear
+ * \brief Scale the linear system by the inverse of
+ * its (block-)diagonal entries.
+ *
+ * \param matrix the matrix to scale
+ * \param rhs the right hand side vector to scale
+ */
+template <class Matrix, class Vector>
+void scaleLinearSystem(Matrix& matrix, Vector& rhs)
+{
+    for (auto rowIt = matrix.begin(); rowIt != matrix.end(); ++rowIt)
+    {
+        auto rowIdx = rowIt.index();
+        auto diagonal = matrix[rowIdx][rowIdx];
+        diagonal.invert();
+
+        const auto b = rhs[rowIdx];
+        diagonal.mv(b, rhs[rowIdx]);
+
+        for (auto& col : *rowIt)
+            col.leftmultiply(diagonal);
+    }
+}
+
+} // end namespace Dumux
-- 
GitLab