From 4d9aeb2f2cad8fecebc960789a4bc45853ac72f2 Mon Sep 17 00:00:00 2001
From: Simon Praetorius <simon.praetorius@tu-dresden.de>
Date: Wed, 25 Sep 2019 18:02:56 +0200
Subject: [PATCH] Removed runner from SolverInterface and Preconditioner from
 RunnerInterface

---
 src/amdis/BiLinearForm.hpp                    |  5 ++--
 src/amdis/BoundaryCondition.hpp               |  2 +-
 src/amdis/LinearAlgebra.hpp                   |  8 -----
 src/amdis/linearalgebra/AttributeSet.hpp      | 29 -------------------
 src/amdis/linearalgebra/DOFMapping.hpp        |  2 +-
 src/amdis/linearalgebra/LinearSolver.hpp      | 19 ++++--------
 .../linearalgebra/LinearSolverInterface.hpp   | 12 ++------
 src/amdis/linearalgebra/ParallelIndexSet.hpp  |  2 +-
 src/amdis/linearalgebra/RunnerInterface.hpp   |  7 +----
 src/amdis/linearalgebra/mtl/KrylovRunner.hpp  | 26 +----------------
 src/amdis/linearalgebra/mtl/MatrixBackend.hpp |  4 +--
 src/amdis/linearalgebra/mtl/UmfpackRunner.hpp |  1 -
 src/amdis/linearalgebra/mtl/VectorBackend.hpp |  6 ++--
 test/ParallelIndexSetTest.cpp                 |  2 +-
 14 files changed, 21 insertions(+), 104 deletions(-)

diff --git a/src/amdis/BiLinearForm.hpp b/src/amdis/BiLinearForm.hpp
index 56667e8a..992afd5f 100644
--- a/src/amdis/BiLinearForm.hpp
+++ b/src/amdis/BiLinearForm.hpp
@@ -36,10 +36,8 @@ namespace AMDiS
     using ColBasis = CB;
     using ColLocalView = typename ColBasis::LocalView;
 
-    using Traits = typename Backend::Traits;
-
     /// The type of the matrix filled on an element with local contributions
-    using ElementMatrix = FlatMatrix<typename Traits::CoefficientType>;
+    using ElementMatrix = FlatMatrix<T>;
 
   public:
     /// Constructor. Wraps the reference into a non-destroying shared_ptr or moves the basis into a new shared_ptr.
@@ -50,6 +48,7 @@ namespace AMDiS
       operators_.init(*Super::rowBasis(), *Super::colBasis());
     }
 
+    /// Prepare the matrix for insertion. Clears all the entries.
     void init(SymmetryStructure symmetry = SymmetryStructure::unknown)
     {
       Super::init(symmetry);
diff --git a/src/amdis/BoundaryCondition.hpp b/src/amdis/BoundaryCondition.hpp
index 1c25f838..aa6c1340 100644
--- a/src/amdis/BoundaryCondition.hpp
+++ b/src/amdis/BoundaryCondition.hpp
@@ -17,7 +17,7 @@ namespace AMDiS
       , id_(id)
     {}
 
-    BoundaryCondition(BoundaryManagerBase& boundaryManager, BoundaryType id)
+    BoundaryCondition(BoundaryManagerBase const& boundaryManager, BoundaryType id)
       : BoundaryCondition(Dune::stackobject_to_shared_ptr(boundaryManager), id)
     {}
 
diff --git a/src/amdis/LinearAlgebra.hpp b/src/amdis/LinearAlgebra.hpp
index ce3ef3fe..ff7a21a9 100644
--- a/src/amdis/LinearAlgebra.hpp
+++ b/src/amdis/LinearAlgebra.hpp
@@ -17,14 +17,6 @@
 #include <amdis/linearalgebra/eigen/MatrixBackend.hpp>
 #include <amdis/linearalgebra/eigen/VectorBackend.hpp>
 
-#elif HAVE_PETSC
-
-#include <amdis/linearalgebra/petsc/Constraints.hpp>
-#include <amdis/linearalgebra/petsc/SolverCreator.hpp>
-#include <amdis/linearalgebra/petsc/Traits.hpp>
-#include <amdis/linearalgebra/petsc/MatrixBackend.hpp>
-#include <amdis/linearalgebra/petsc/VectorBackend.hpp>
-
 #else // ISTL
 
 #include <amdis/linearalgebra/istl/Constraints.hpp>
diff --git a/src/amdis/linearalgebra/AttributeSet.hpp b/src/amdis/linearalgebra/AttributeSet.hpp
index 8b453794..a88c2e1b 100644
--- a/src/amdis/linearalgebra/AttributeSet.hpp
+++ b/src/amdis/linearalgebra/AttributeSet.hpp
@@ -24,32 +24,6 @@ namespace AMDiS
     };
   };
 
-  inline DefaultAttributeSet::Type attributeSet(std::string str)
-  {
-    if (str == "owner")
-      return DefaultAttributeSet::owner;
-    else if (str == "overlap")
-      return DefaultAttributeSet::overlap;
-    else if (str == "copy")
-      return DefaultAttributeSet::copy;
-    else
-      return DefaultAttributeSet::unknown;
-  }
-
-  inline std::string to_string(DefaultAttributeSet::Type state)
-  {
-    switch (state) {
-      case DefaultAttributeSet::owner:
-        return "owner";
-      case DefaultAttributeSet::overlap:
-        return "overlap";
-      case DefaultAttributeSet::copy:
-        return "copy";
-      default:
-        return "unknown";
-    }
-  }
-
 
   /// Default attribute set used to classify DOFs. Can be specialized for own
   /// Communication type `C`.
@@ -73,7 +47,4 @@ namespace AMDiS
     using type = typename AttributeSet<TL>::type;
   };
 
-  template <class C>
-  using AttributeSet_t = typename AttributeSet<C>::type;
-
 } // end namespace AMDiS
diff --git a/src/amdis/linearalgebra/DOFMapping.hpp b/src/amdis/linearalgebra/DOFMapping.hpp
index b32d8e88..bb937024 100644
--- a/src/amdis/linearalgebra/DOFMapping.hpp
+++ b/src/amdis/linearalgebra/DOFMapping.hpp
@@ -148,7 +148,7 @@ namespace AMDiS
   class ParallelDofMapping
   {
     using ParallelIndexSet = PIS;
-    using Attribute = AttributeSet_t<PIS>;
+    using Attribute = typename AttributeSet<PIS>::type;
     using RemoteIndices = Dune::RemoteIndices<ParallelIndexSet>;
 
   public:
diff --git a/src/amdis/linearalgebra/LinearSolver.hpp b/src/amdis/linearalgebra/LinearSolver.hpp
index faaf2851..85df7242 100644
--- a/src/amdis/linearalgebra/LinearSolver.hpp
+++ b/src/amdis/linearalgebra/LinearSolver.hpp
@@ -27,7 +27,6 @@ namespace AMDiS
     using Self = LinearSolver;
     using Super = LinearSolverInterface<Traits>;
 
-    using RunnerBase = typename Super::RunnerBase;
     using Mat = typename Traits::Mat;
     using Vec = typename Traits::Vec;
     using Comm = typename Traits::Comm;
@@ -45,15 +44,9 @@ namespace AMDiS
   public:
     /// Constructor
     explicit LinearSolver(std::string prefix)
-      : runner_(std::make_shared<Runner>(prefix))
+      : runner_(prefix)
     {}
 
-    /// Implements \ref LinearSolverInterface::runner()
-    virtual std::shared_ptr<RunnerBase> runner() override
-    {
-      return runner_;
-    }
-
   private:
     /// Implements \ref LinearSolverInterface::solveSystemImpl()
     void solveImpl(Mat const& A, Vec& x, Vec const& b, Comm& comm, SolverInfo& solverInfo) override
@@ -61,22 +54,22 @@ namespace AMDiS
       Dune::Timer t;
       if (solverInfo.doCreateMatrixData()) {
         // init matrix or wrap block-matrix or ...
-        runner_->init(A, comm);
+        runner_.init(A, comm);
       }
 
       if (solverInfo.info() > 0)
         msg("prepare solver needed {} seconds", t.elapsed());
 
-      int error = runner_->solve(A, x, b, solverInfo);
+      int error = runner_.solve(A, x, b, solverInfo);
       solverInfo.setError(error);
 
       if (!solverInfo.doStoreMatrixData())
-        runner_->exit();
+        runner_.exit();
     }
 
   private:
-    /// redirect the implementation to a runner. Implements a \ref RunnerInterface
-    std::shared_ptr<Runner> runner_;
+    /// redirect the implementation to a runner. Implementing a \ref RunnerInterface
+    Runner runner_;
   };
 
 } // end namespace AMDiS
diff --git a/src/amdis/linearalgebra/LinearSolverInterface.hpp b/src/amdis/linearalgebra/LinearSolverInterface.hpp
index f0f79817..083878a5 100644
--- a/src/amdis/linearalgebra/LinearSolverInterface.hpp
+++ b/src/amdis/linearalgebra/LinearSolverInterface.hpp
@@ -11,20 +11,15 @@
  * systems.
  */
 
-#include <amdis/common/TypeTraits.hpp>
-
-#include <amdis/linearalgebra/PreconditionerInterface.hpp>
-#include <amdis/linearalgebra/RunnerInterface.hpp>
-#include <amdis/linearalgebra/SolverInfo.hpp>
-
 namespace AMDiS
 {
+  class SolverInfo;
+
   /// Abstract base class for linear solvers
   template <class Traits>
   class LinearSolverInterface
   {
   protected:
-    using RunnerBase = RunnerInterface<Traits>;
     using Mat = typename Traits::Mat;
     using Vec = typename Traits::Vec;
     using Comm = typename Traits::Comm;
@@ -48,9 +43,6 @@ namespace AMDiS
       solveImpl(A, x, b, comm, solverInfo);
     }
 
-    // return the runner/worker corresponding to this solver (optional)
-    virtual std::shared_ptr<RunnerBase> runner() { return {}; };
-
   private:
     /// main methods that all solvers must implement
     virtual void solveImpl(Mat const& A, Vec& x, Vec const& b, Comm& comm, SolverInfo& solverInfo) = 0;
diff --git a/src/amdis/linearalgebra/ParallelIndexSet.hpp b/src/amdis/linearalgebra/ParallelIndexSet.hpp
index d55db5f1..cb69b4ee 100644
--- a/src/amdis/linearalgebra/ParallelIndexSet.hpp
+++ b/src/amdis/linearalgebra/ParallelIndexSet.hpp
@@ -17,7 +17,7 @@ namespace AMDiS
   inline void buildParallelIndexSet(Basis const& basis, ParallelIndexSet& pis)
   {
     Dune::Timer t;
-    using Attribute = AttributeSet_t<ParallelIndexSet>;
+    using Attribute = typename AttributeSet<ParallelIndexSet>::type;
     using GI = typename ParallelIndexSet::GlobalIndex;
     using LI = typename ParallelIndexSet::LocalIndex;
 
diff --git a/src/amdis/linearalgebra/RunnerInterface.hpp b/src/amdis/linearalgebra/RunnerInterface.hpp
index d0941e4d..4f46d3e4 100644
--- a/src/amdis/linearalgebra/RunnerInterface.hpp
+++ b/src/amdis/linearalgebra/RunnerInterface.hpp
@@ -1,7 +1,6 @@
 #pragma once
 
-#include <amdis/common/TypeTraits.hpp>
-#include <amdis/linearalgebra/PreconditionerInterface.hpp>
+#include <amdis/Output.hpp>
 
 namespace AMDiS
 {
@@ -12,7 +11,6 @@ namespace AMDiS
   class RunnerInterface
   {
   protected:
-    using PreconBase = PreconditionerInterface<Traits>;
     using Mat = typename Traits::Mat;
     using Vec = typename Traits::Vec;
     using Comm = typename Traits::Comm;
@@ -36,9 +34,6 @@ namespace AMDiS
       error_exit("Must be implemented by derived class.");
       return 0;
     }
-
-    virtual std::shared_ptr<PreconBase> leftPrecon() { return {}; }
-    virtual std::shared_ptr<PreconBase> rightPrecon() { return {}; }
   };
 
 } // end namespace AMDiS
diff --git a/src/amdis/linearalgebra/mtl/KrylovRunner.hpp b/src/amdis/linearalgebra/mtl/KrylovRunner.hpp
index 54548b0e..a17f1feb 100644
--- a/src/amdis/linearalgebra/mtl/KrylovRunner.hpp
+++ b/src/amdis/linearalgebra/mtl/KrylovRunner.hpp
@@ -28,7 +28,7 @@ namespace AMDiS
     using Matrix = typename Traits::Mat;
     using Vector = typename Traits::Vec;
     using Comm = typename Traits::Comm;
-    using PreconBase = typename Super::PreconBase;
+    using PreconBase = PreconditionerInterface<Traits>;
 
   public:
     /// Constructor.
@@ -41,30 +41,6 @@ namespace AMDiS
       Parameters::get(prefix + "->print cycle", printCycle_);
     }
 
-    /// Implements \ref RunnerInterface::lLeftPrecon(), Returns \ref L_
-    std::shared_ptr<PreconBase> leftPrecon() override
-    {
-      return L_;
-    }
-
-    /// Implements \ref RunnerInterface::rightPrecon(), Returns \ref R_
-    std::shared_ptr<PreconBase> rightPrecon() override
-    {
-      return R_;
-    }
-
-    /// Set a new left preconditioner \ref L_
-    void setLeftPrecon(std::shared_ptr<PreconBase> const& precon)
-    {
-      L_ = precon;
-    }
-
-    /// Set a new right preconditioner \ref R_
-    void setRightPrecon(std::shared_ptr<PreconBase> const& precon)
-    {
-      R_ = precon;
-    }
-
     /// Implementation of \ref RunnerInterface::init()
     void init(Matrix const& A, Comm& comm) override
     {
diff --git a/src/amdis/linearalgebra/mtl/MatrixBackend.hpp b/src/amdis/linearalgebra/mtl/MatrixBackend.hpp
index a26dc34e..ea4c0e71 100644
--- a/src/amdis/linearalgebra/mtl/MatrixBackend.hpp
+++ b/src/amdis/linearalgebra/mtl/MatrixBackend.hpp
@@ -15,11 +15,11 @@
 namespace AMDiS
 {
   /// \brief The basic container that stores a base matrix
-  template <class T>
+  template <class TraitsType>
   class MatrixBackend
   {
   public:
-    using Traits = T;
+    using Traits = TraitsType;
 
     /// The matrix type of the underlying base matrix
     using BaseMatrix = typename Traits::Mat;
diff --git a/src/amdis/linearalgebra/mtl/UmfpackRunner.hpp b/src/amdis/linearalgebra/mtl/UmfpackRunner.hpp
index aa49fb7e..643cfbaf 100644
--- a/src/amdis/linearalgebra/mtl/UmfpackRunner.hpp
+++ b/src/amdis/linearalgebra/mtl/UmfpackRunner.hpp
@@ -32,7 +32,6 @@ namespace AMDiS
     using Vector = typename Traits::Vec;
     using Comm = typename Traits::Comm;
     using Super = RunnerInterface<Traits>;
-    using PreconBase = typename Super::PreconBase;
 
     using SolverType = mtl::mat::umfpack::solver<Matrix>;
 
diff --git a/src/amdis/linearalgebra/mtl/VectorBackend.hpp b/src/amdis/linearalgebra/mtl/VectorBackend.hpp
index 4fddc501..884e2fd5 100644
--- a/src/amdis/linearalgebra/mtl/VectorBackend.hpp
+++ b/src/amdis/linearalgebra/mtl/VectorBackend.hpp
@@ -7,12 +7,12 @@
 
 namespace AMDiS
 {
-  /// The basic container that stores a base vector data
-  template <class T>
+  /// \brief The basic container that stores a base vector data
+  template <class TraitsType>
   class VectorBackend
   {
   public:
-    using Traits = T;
+    using Traits = TraitsType;
 
     /// The type of the base vector
     using BaseVector = typename Traits::Vec;
diff --git a/test/ParallelIndexSetTest.cpp b/test/ParallelIndexSetTest.cpp
index e2bda6c7..c4739cf1 100644
--- a/test/ParallelIndexSetTest.cpp
+++ b/test/ParallelIndexSetTest.cpp
@@ -43,7 +43,7 @@ void test_basis(Basis const& basis, std::string gridName, std::string basisName)
   buildParallelIndexSet(basis, pis);
 
   using IdType = typename ParallelIndexSet::GlobalIndex;
-  using Attribute = AttributeSet_t<ParallelIndexSet>;
+  using Attribute = typename AttributeSet<ParallelIndexSet>::type;
   std::vector<std::vector<std::pair<IdType,Attribute>>> data(world.size());
 
   std::size_t owner = 0, notOwner = 0;
-- 
GitLab