From 9eca581e53ff076e378b8b7b25e301b98857c144 Mon Sep 17 00:00:00 2001
From: Kilian <kilian.weishaupt@iws.uni-stuttgart.de>
Date: Mon, 6 Apr 2020 20:57:56 +0200
Subject: [PATCH] [linear][seqsolverbackend] Use
 preconditionerBlockLevel<Matrix>() internally

---
 dumux/linear/seqsolverbackend.hh | 74 ++++++++++++++++----------------
 1 file changed, 36 insertions(+), 38 deletions(-)

diff --git a/dumux/linear/seqsolverbackend.hh b/dumux/linear/seqsolverbackend.hh
index ffe04084fe..1a25083919 100644
--- a/dumux/linear/seqsolverbackend.hh
+++ b/dumux/linear/seqsolverbackend.hh
@@ -183,10 +183,10 @@ class ILUnBiCGSTABBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqILU<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::BiCGSTABSolver<Vector>;
 
@@ -221,10 +221,10 @@ class SORBiCGSTABBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqSOR<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::BiCGSTABSolver<Vector>;
 
@@ -259,10 +259,10 @@ class SSORBiCGSTABBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqSSOR<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::BiCGSTABSolver<Vector>;
 
@@ -297,10 +297,10 @@ class GSBiCGSTABBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqGS<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::BiCGSTABSolver<Vector>;
 
@@ -334,10 +334,10 @@ class JacBiCGSTABBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqJac<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::BiCGSTABSolver<Vector>;
 
@@ -371,10 +371,10 @@ class ILUnCGBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqILU<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::CGSolver<Vector>;
 
@@ -408,10 +408,10 @@ class SORCGBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqSOR<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::CGSolver<Vector>;
 
@@ -445,10 +445,10 @@ class SSORCGBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqSSOR<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::CGSolver<Vector>;
 
@@ -482,10 +482,10 @@ class GSCGBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqGS<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::CGSolver<Vector>;
 
@@ -518,10 +518,10 @@ class JacCGBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqJac<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::CGSolver<Vector>;
 
@@ -556,10 +556,10 @@ class SSORRestartedGMResBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqSSOR<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::RestartedGMResSolver<Vector>;
 
@@ -593,10 +593,10 @@ class ILU0BiCGSTABBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqILU<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::BiCGSTABSolver<Vector>;
 
@@ -629,10 +629,10 @@ class ILU0CGBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqILU<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::CGSolver<Vector>;
 
@@ -666,10 +666,10 @@ class ILU0RestartedGMResBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqILU<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::RestartedGMResSolver<Vector>;
 
@@ -704,10 +704,10 @@ class ILUnRestartedGMResBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         using Preconditioner = Dune::SeqILU<Matrix, Vector, Vector, precondBlockLevel>;
         using Solver = Dune::RestartedGMResSolver<Vector>;
 
@@ -732,11 +732,11 @@ class ExplicitDiagonalSolver : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel: set this to more than one if the matrix to solve is nested multiple times
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
         Vector rhs(b);
+        constexpr auto precondBlockLevel = preconditionerBlockLevel<Matrix>();
         Dune::SeqJac<Matrix, Vector, Vector, precondBlockLevel> jac(A, 1, 1.0);
         jac.pre(x, rhs);
         jac.apply(x, rhs);
@@ -764,8 +764,7 @@ class SuperLUBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel is unused and just here for compatibility with iterative solvers
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
         static_assert(isBCRSMatrix<Matrix>::value, "SuperLU only works with BCRS matrices!");
@@ -825,8 +824,7 @@ class UMFPackBackend : public LinearSolver
 public:
     using LinearSolver::LinearSolver;
 
-    // precondBlockLevel is unused and just here for compatibility with iterative solvers
-    template<int precondBlockLevel = 1, class Matrix, class Vector>
+    template<int pBlDummy = 1, class Matrix, class Vector>
     bool solve(const Matrix& A, Vector& x, const Vector& b)
     {
         static_assert(isBCRSMatrix<Matrix>::value, "UMFPack only works with BCRS matrices!");
@@ -966,7 +964,7 @@ public:
     using LinearSolver::LinearSolver;
 
     // Solve saddle-point problem using a Schur complement based preconditioner
-    template<int precondBlockLevel = 2, class Matrix, class Vector>
+    template<int pBlDummy = 2, class Matrix, class Vector>
     bool solve(const Matrix& M, Vector& x, const Vector& b)
     {
         BlockDiagILU0Preconditioner<Matrix, Vector, Vector> preconditioner(M);
@@ -1151,7 +1149,7 @@ public:
     using LinearSolver::LinearSolver;
 
     // Solve saddle-point problem using a Schur complement based preconditioner
-    template<int precondBlockLevel = 2, class Matrix, class Vector>
+    template<int pBlDummy = 2, class Matrix, class Vector>
     bool solve(const Matrix& m, Vector& x, const Vector& b)
     {
         //! \todo Check whether the default accumulation mode atOnceAccu is needed.
-- 
GitLab