From b6a20add46d8548bddba5f6659862c307726751c Mon Sep 17 00:00:00 2001
From: Simon Praetorius <simon.praetorius@tu-dresden.de>
Date: Wed, 4 Jul 2018 15:52:46 +0200
Subject: [PATCH] Some small corrections and interface cleanup

---
 examples/ellipt.cc               |  2 +-
 src/amdis/Assembler.inc.hpp      |  2 +-
 src/amdis/ProblemInstat.inc.hpp  |  2 +-
 src/amdis/ProblemStat.hpp        | 53 ++++++++++++++++++--------------
 src/amdis/utility/CMakeLists.txt |  2 ++
 src/amdis/utility/TreeData.hpp   |  1 -
 6 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/examples/ellipt.cc b/examples/ellipt.cc
index 67b30e6f..396737c3 100644
--- a/examples/ellipt.cc
+++ b/examples/ellipt.cc
@@ -55,7 +55,7 @@ int main(int argc, char** argv)
   std::vector<double> errH1; errH1.reserve(numLevels);
   std::vector<double> widths; widths.reserve(numLevels);
   for (int i = 0; i < numLevels; ++i) {
-    prob.getGrid()->globalRefine(1);
+    prob.grid().globalRefine(1);
     auto gridView = prob.gridView();
 
     double h = 0;
diff --git a/src/amdis/Assembler.inc.hpp b/src/amdis/Assembler.inc.hpp
index 5ab4ed18..f073f40c 100644
--- a/src/amdis/Assembler.inc.hpp
+++ b/src/amdis/Assembler.inc.hpp
@@ -1,8 +1,8 @@
 #pragma once
 
 #include <dune/functions/functionspacebases/subspacebasis.hh>
-#include <dune/typetree/traversal.hh>
 #include <amdis/utility/TreePath.hpp>
+#include <amdis/utility/Visitor.hpp>
 
 #include <amdis/common/Math.hpp>
 
diff --git a/src/amdis/ProblemInstat.inc.hpp b/src/amdis/ProblemInstat.inc.hpp
index 9005f11f..47c2d4f9 100644
--- a/src/amdis/ProblemInstat.inc.hpp
+++ b/src/amdis/ProblemInstat.inc.hpp
@@ -45,7 +45,7 @@ void ProblemInstat<Traits>::createUhOld()
   if (oldSolution)
     warning("oldSolution already created\n");
   else // create oldSolution
-    oldSolution.reset(new SystemVector(*problemStat.globalBasis(), name + "_uOld"));
+    oldSolution.reset(new SystemVector(problemStat.globalBasis(), name + "_uOld"));
 }
 
 
diff --git a/src/amdis/ProblemStat.hpp b/src/amdis/ProblemStat.hpp
index 033a6b65..9e36f2ca 100644
--- a/src/amdis/ProblemStat.hpp
+++ b/src/amdis/ProblemStat.hpp
@@ -40,6 +40,10 @@
 
 namespace AMDiS
 {
+  // forward declaration
+  template <class Traits>
+  class ProblemInstat;
+
   template <class Traits>
   class ProblemStat
       : public ProblemStatBase
@@ -47,6 +51,8 @@ namespace AMDiS
   {
     using Self = ProblemStat;
 
+    friend class ProblemInstat<Traits>;
+
   public: // typedefs and static constants
 
     using GlobalBasis = typename Traits::GlobalBasis;
@@ -153,15 +159,18 @@ namespace AMDiS
 
   public: // get-methods
 
-    /// Returns a pointer to system-matrix, \ref systemMatrix_
-    std::shared_ptr<SystemMatrix> getSystemMatrix()       { return systemMatrix_; }
-    std::shared_ptr<SystemMatrix> getSystemMatrix() const { return systemMatrix_; }
+    /// Returns a reference to system-matrix, \ref systemMatrix_
+    SystemMatrix&       getSystemMatrix()       { return *systemMatrix_; }
+    SystemMatrix const& getSystemMatrix() const { return *systemMatrix_; }
+
+    /// Returns a reference to the solution vector, \ref solution_
+    SystemVector&       getSolutionVector()       { return *solution_; }
+    SystemVector const& getSolutionVector() const { return *solution_; }
+
+    /// Return a reference to the rhs system-vector, \ref rhs
+    SystemVector&       getRhsVector()       { return *rhs_; }
+    SystemVector const& getRhsVector() const { return *rhs_; }
 
-    /// Returns a pointer to the solution vector, \ref solution_
-    std::shared_ptr<SystemVector> getSolutionVector() const
-    {
-      return solution_;
-    }
 
     /// Return a mutable view to a solution component
     template <class TreePath = RootTreePath>
@@ -180,27 +189,25 @@ namespace AMDiS
     }
 
 
-    /// Return a point to the rhs system-vector, \ref rhs
-    std::shared_ptr<SystemVector> getRhsVector()       { return rhs_; }
-    std::shared_ptr<SystemVector> getRhsVector() const { return rhs_; }
-
-
-    /// Return a pointer to the linear solver, \ref linearSolver
-    std::shared_ptr<LinearSolverType> getSolver() { return linearSolver_; }
+    /// Return a reference to the linear solver, \ref linearSolver
+    LinearSolverType&       getSolver()       { return *linearSolver_; }
+    LinearSolverType const& getSolver() const { return *linearSolver_; }
 
+    /// Set a new linear solver for the problem
     void setSolver(std::shared_ptr<LinearSolverType> const& solver)
     {
       linearSolver_ = solver;
     }
 
-    /// Return a pointer to the grid, \ref grid
-    std::shared_ptr<Grid> getGrid() { return grid_; }
+    /// Return a reference to the grid, \ref grid
+    Grid&       grid()       { return *grid_; }
+    Grid const& grid() const { return *grid_; }
 
-    /// Set the mesh. Stores pointer to passed reference and initializes feSpaces
+    /// Set the grid. Stores pointer and initializes feSpaces
     /// matrices and vectors, as well as the file-writer.
-    void setGrid(Grid& grid)
+    void setGrid(std::shared_ptr<Grid> const& grid)
     {
-      grid_ = Dune::stackobject_to_shared_ptr(grid);
+      grid_ = grid;
 
       createGlobalBasis();
       createMatricesAndVectors();
@@ -208,10 +215,10 @@ namespace AMDiS
     }
 
     /// Return the gridView of the leaf-level
-    auto const& gridView() { return globalBasis_->gridView(); }
+    GridView const& gridView() { return globalBasis_->gridView(); }
 
     /// Return the \ref feSpaces
-    std::shared_ptr<GlobalBasis> const& globalBasis() { return globalBasis_; }
+    GlobalBasis const& globalBasis() { return *globalBasis_; }
 
 
     /// Implementation of \ref ProblemStatBase::getName
@@ -240,7 +247,7 @@ namespace AMDiS
 
     void createGlobalBasis(std::false_type)
     {
-      error_exit("Can not create GlobalBasis from type. Pass a BasisCreator instead!");
+      error_exit("Cannot create GlobalBasis from type. Pass a BasisCreator instead!");
     }
 
     void createGrid()
diff --git a/src/amdis/utility/CMakeLists.txt b/src/amdis/utility/CMakeLists.txt
index 69b9b57d..bef683e0 100644
--- a/src/amdis/utility/CMakeLists.txt
+++ b/src/amdis/utility/CMakeLists.txt
@@ -10,6 +10,8 @@ install(FILES
     MultiIndex.hpp
     RangeType.hpp
     String.hpp
+    Traversal.hpp
     TreeData.hpp
     TreePath.hpp
+    Visitor.hpp
 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/amdis/utility)
diff --git a/src/amdis/utility/TreeData.hpp b/src/amdis/utility/TreeData.hpp
index 68ae7a11..760a8e44 100644
--- a/src/amdis/utility/TreeData.hpp
+++ b/src/amdis/utility/TreeData.hpp
@@ -5,7 +5,6 @@
 #include <utility>
 #include <vector>
 
-//#include <dune/typetree/traversal.hh>
 #include <dune/typetree/typetree.hh>
 #include <amdis/utility/Visitor.hpp>
 
-- 
GitLab