From 9e2dadcbc408c0e6540e5b0232130cd6d203f541 Mon Sep 17 00:00:00 2001
From: Simon Praetorius <simon.praetorius@tu-dresden.de>
Date: Sat, 15 Sep 2018 00:11:35 +0200
Subject: [PATCH] cleanup of DOFMatrix and removed name member

---
 examples/stokes0.cc                         |   4 +-
 examples/stokes1.cc                         |   4 +-
 examples/vecellipt.cc                       |   4 +-
 src/amdis/Assembler.inc.hpp                 |   2 +-
 src/amdis/ProblemInstat.inc.hpp             |   2 +-
 src/amdis/ProblemStat.hpp                   |   8 +-
 src/amdis/ProblemStat.inc.hpp               |   2 +-
 src/amdis/linear_algebra/DOFVectorBase.hpp  |  23 +---
 src/amdis/linear_algebra/istl/DOFMatrix.hpp |   2 +-
 src/amdis/linear_algebra/mtl/DOFMatrix.hpp  | 132 +++++++++-----------
 src/amdis/linear_algebra/mtl/DOFVector.hpp  |  67 ++++------
 11 files changed, 98 insertions(+), 152 deletions(-)

diff --git a/examples/stokes0.cc b/examples/stokes0.cc
index 7118684a..c74c88b5 100644
--- a/examples/stokes0.cc
+++ b/examples/stokes0.cc
@@ -78,8 +78,8 @@ int main(int argc, char** argv)
 
     // write matrix to file
     mtl::io::matrix_market_ostream out("matrix_stokes0.mtx");
-    out << prob.getSystemMatrix().getMatrix();
-    std::cout << prob.getSystemMatrix().getMatrix() << '\n';
+    out << prob.getSystemMatrix().matrix();
+    std::cout << prob.getSystemMatrix().matrix() << '\n';
 
     prob.solve(adaptInfo);
 
diff --git a/examples/stokes1.cc b/examples/stokes1.cc
index e0effcce..8ae36a30 100644
--- a/examples/stokes1.cc
+++ b/examples/stokes1.cc
@@ -79,8 +79,8 @@ int main(int argc, char** argv)
 
     // write matrix to file
     mtl::io::matrix_market_ostream out("matrix_stokes1.mtx");
-    out << prob.getSystemMatrix().getMatrix();
-    std::cout << prob.getSystemMatrix().getMatrix() << '\n';
+    out << prob.getSystemMatrix().matrix();
+    std::cout << prob.getSystemMatrix().matrix() << '\n';
 
     prob.solve(adaptInfo);
 
diff --git a/examples/vecellipt.cc b/examples/vecellipt.cc
index e87f870d..ea4e9f05 100644
--- a/examples/vecellipt.cc
+++ b/examples/vecellipt.cc
@@ -41,9 +41,9 @@ int main(int argc, char** argv)
   // write matrix to file
   if (Parameters::get<int>("elliptMesh->global refinements").value_or(0) < 4) {
     mtl::io::matrix_market_ostream out("matrix.mtx");
-    out << prob.getSystemMatrix().getMatrix();
+    out << prob.getSystemMatrix().matrix();
 
-    std::cout << prob.getSystemMatrix().getMatrix() << '\n';
+    std::cout << prob.getSystemMatrix().matrix() << '\n';
   }
 
   prob.solve(adaptInfo);
diff --git a/src/amdis/Assembler.inc.hpp b/src/amdis/Assembler.inc.hpp
index f073f40c..60fb97c2 100644
--- a/src/amdis/Assembler.inc.hpp
+++ b/src/amdis/Assembler.inc.hpp
@@ -203,7 +203,7 @@ std::size_t Assembler<Traits>::finishMatrixVector(
     });
   });
 
-  return matrix.getNnz();
+  return matrix.nnz();
 }
 
 } // end namespace AMDiS
diff --git a/src/amdis/ProblemInstat.inc.hpp b/src/amdis/ProblemInstat.inc.hpp
index e6ee9c7f..502f9d9a 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()));
 }
 
 
diff --git a/src/amdis/ProblemStat.hpp b/src/amdis/ProblemStat.hpp
index 874df466..e0e08a43 100644
--- a/src/amdis/ProblemStat.hpp
+++ b/src/amdis/ProblemStat.hpp
@@ -275,9 +275,9 @@ namespace AMDiS
 
     void createMatricesAndVectors()
     {
-      systemMatrix_ = std::make_shared<SystemMatrix>(*globalBasis_, *globalBasis_, "mat");
-      solution_ = std::make_shared<SystemVector>(*globalBasis_, "solution");
-      rhs_ = std::make_shared<SystemVector>(*globalBasis_, "rhs");
+      systemMatrix_ = std::make_shared<SystemMatrix>(*globalBasis_, *globalBasis_);
+      solution_ = std::make_shared<SystemVector>(*globalBasis_);
+      rhs_ = std::make_shared<SystemVector>(*globalBasis_);
 
       AMDiS::forEachNode_(localView_->tree(), [&,this](auto const& node, auto treePath)
       {
@@ -286,8 +286,6 @@ namespace AMDiS
         for (std::size_t j = 0; j < estimates_[i].size(); j++)
           estimates_[i][j] = 0.0; // TODO: Remove when estimate() is implemented
       });
-
-      rhs_ = std::make_shared<SystemVector>(*globalBasis_, "rhs");
     }
 
     void createSolver()
diff --git a/src/amdis/ProblemStat.inc.hpp b/src/amdis/ProblemStat.inc.hpp
index 934882d5..833b31c8 100644
--- a/src/amdis/ProblemStat.inc.hpp
+++ b/src/amdis/ProblemStat.inc.hpp
@@ -281,7 +281,7 @@ solve(AdaptInfo& adaptInfo, bool createMatrixData, bool storeMatrixData)
 
   solution_->compress();
 
-  linearSolver_->solve(systemMatrix_->getMatrix(), solution_->vector(), rhs_->vector(),
+  linearSolver_->solve(systemMatrix_->matrix(), solution_->vector(), rhs_->vector(),
                       solverInfo);
 
   if (solverInfo.getInfo() > 0) {
diff --git a/src/amdis/linear_algebra/DOFVectorBase.hpp b/src/amdis/linear_algebra/DOFVectorBase.hpp
index 2b3902ee..1b5586d1 100644
--- a/src/amdis/linear_algebra/DOFVectorBase.hpp
+++ b/src/amdis/linear_algebra/DOFVectorBase.hpp
@@ -2,29 +2,14 @@
 
 namespace AMDiS
 {
-  template <class GlobalBasisType>
   class DOFVectorBase
   {
   public:
-    using GlobalBasis = GlobalBasisType;
-    using SizeType = std::size_t;
+    /// Virtual destructor
+    ~DOFVectorBase() = default;
 
-    DOFVectorBase(GlobalBasisType const& basis)
-      : basis_(basis)
-    {}
-
-    SizeType size() const
-    {
-      return basis_.dimension();
-    }
-
-    GlobalBasis const& basis() const
-    {
-      return GlobalBasis;
-    }
-
-  private:
-    GlobalBasis const& basis_;
+    /// Change dimension of DOFVector to dimension of basis
+    virtual void compress() = 0;
   };
 
 } // end namespace AMDiS
diff --git a/src/amdis/linear_algebra/istl/DOFMatrix.hpp b/src/amdis/linear_algebra/istl/DOFMatrix.hpp
index e256a05e..fbaaa635 100644
--- a/src/amdis/linear_algebra/istl/DOFMatrix.hpp
+++ b/src/amdis/linear_algebra/istl/DOFMatrix.hpp
@@ -136,7 +136,7 @@ namespace AMDiS
       initialized = false;
     }
 
-    std::size_t getNnz()
+    std::size_t nnz()
     {
       return matrix->nonzeroes();
     }
diff --git a/src/amdis/linear_algebra/mtl/DOFMatrix.hpp b/src/amdis/linear_algebra/mtl/DOFMatrix.hpp
index dba705f9..0b748f5d 100644
--- a/src/amdis/linear_algebra/mtl/DOFMatrix.hpp
+++ b/src/amdis/linear_algebra/mtl/DOFMatrix.hpp
@@ -22,17 +22,17 @@ namespace AMDiS
 {
   /// \brief The basic container that stores a base matrix and a corresponding
   /// row/column feSpace.
-  template <class RowFeSpaceType,
-            class ColFeSpaceType,
+  template <class RowBasisType,
+            class ColBasisType,
             class ValueType = double>
   class DOFMatrix
   {
   public:
     /// The type of the finite element space / basis of the row
-    using RowFeSpace = RowFeSpaceType;
+    using RowBasis = RowBasisType;
 
     /// The type of the finite element space / basis of the column
-    using ColFeSpace = ColFeSpaceType;
+    using ColBasis = ColBasisType;
 
     /// The matrix type of the underlying base matrix
     using BaseMatrix = mtl::compressed2D<ValueType>;
@@ -51,68 +51,58 @@ namespace AMDiS
 
   public:
     /// Constructor. Constructs new BaseMatrix.
-    DOFMatrix(RowFeSpace const& rowFeSpace,
-              ColFeSpace const& colFeSpace,
-              std::string name)
-      : rowFeSpace(rowFeSpace)
-      , colFeSpace(colFeSpace)
-      , name(name)
-      , matrix(ClonablePtr<BaseMatrix>::make())
+    DOFMatrix(RowBasis const& rowBasis,
+              ColBasis const& colBasis)
+      : rowBasis_(&rowBasis)
+      , colBasis_(&colBasis)
+      , matrix_(ClonablePtr<BaseMatrix>::make())
     {}
 
     /// Constructor. Takes pointer of data-matrix.
-    DOFMatrix(RowFeSpace const& rowFeSpace,
-              ColFeSpace const& colFeSpace,
-              std::string name,
+    DOFMatrix(RowBasis const& rowBasis,
+              ColBasis const& colBasis,
               BaseMatrix& matrix_ref)
-      : rowFeSpace(rowFeSpace)
-      , colFeSpace(colFeSpace)
-      , name(name)
-      , matrix(matrix_ref)
+      : rowBasis_(&rowBasis)
+      , colBasis_(&colBasis)
+      , matrix_(matrix_ref)
     {}
 
-    /// Return the row-basis \ref rowFeSpace of the matrix
-    RowFeSpace const& getRowFeSpace() const
+    /// Return the row-basis \ref rowBasis_ of the matrix
+    RowBasis const& rowBasis() const
     {
-      return rowFeSpace;
+      return *rowBasis_;
     }
 
-    /// Return the col-basis \ref colFeSpace of the matrix
-    ColFeSpace const& getColFeSpace() const
+    /// Return the col-basis \ref colBasis_ of the matrix
+    ColBasis const& colBasis() const
     {
-      return colFeSpace;
+      return *colBasis_;
     }
 
     /// Return a reference to the data-matrix \ref matrix
-    BaseMatrix& getMatrix()
+    BaseMatrix& matrix()
     {
-      assert( !insertionMode );
-      return *matrix;
+      assert( !insertionMode_ );
+      return *matrix_;
     }
 
     /// Return a reference to the data-matrix \ref matrix
-    BaseMatrix const& getMatrix() const
+    BaseMatrix const& matrix() const
     {
-      assert( !insertionMode );
-      return *matrix;
+      assert( !insertionMode_ );
+      return *matrix_;
     }
 
     /// Return the size of the row \ref feSpace
     size_type N() const
     {
-      return rowFeSpace.size();
+      return rowBasis_->size();
     }
 
     /// Return the size of the column \ref feSpace
     size_type M() const
     {
-      return colFeSpace.size();
-    }
-
-    /// Return the \ref name of this matrix
-    std::string getName() const
-    {
-      return name;
+      return colBasis_->size();
     }
 
 
@@ -125,34 +115,34 @@ namespace AMDiS
     auto operator()(FlatIndex row, FlatIndex col)
     {
       size_type r = row[0], c = col[0];
-      test_exit_dbg( insertionMode, "Inserter not initilized!");
+      test_exit_dbg( insertionMode_, "Inserter not initilized!");
       test_exit_dbg( r < N() && c < M() ,
           "Indices out of range [0,", N(), ")x[0,", M(), ")" );
-      return (*inserter)[r][c];
+      return (*inserter_)[r][c];
     }
 
     auto operator()(BlockIndex row, BlockIndex col)
     {
       size_type r = row[0], c = col[0];
-      test_exit_dbg( insertionMode, "Inserter not initilized!");
+      test_exit_dbg( insertionMode_, "Inserter not initilized!");
       test_exit_dbg( r < N() && c < M() ,
           "Indices out of range [0,", N(), ")x[0,", M(), ")" );
-      return (*inserter)[r][c];
+      return (*inserter_)[r][c];
     }
 
     /// Create inserter. Assumes that no inserter is currently active on this matrix.
     void init(bool prepareForInsertion)
     {
-      test_exit(!insertionMode && !inserter, "Matrix already in insertion mode!");
+      test_exit(!insertionMode_ && !inserter_, "Matrix already in insertion mode!");
 
       calculateSlotSize();
-      matrix->change_dim(rowFeSpace.dimension(), colFeSpace.dimension());
-      test_exit(num_rows(*matrix) == rowFeSpace.dimension() && num_cols(*matrix) == colFeSpace.dimension(),
+      matrix_->change_dim(rowBasis_->dimension(), colBasis_->dimension());
+      test_exit(num_rows(*matrix_) == rowBasis_->dimension() && num_cols(*matrix_) == colBasis_->dimension(),
         "Wrong dimensions in matrix");
       if (prepareForInsertion) {
-        set_to_zero(*matrix);
-        inserter = new Inserter(*matrix, slot_size);
-        insertionMode = true;
+        set_to_zero(*matrix_);
+        inserter_ = new Inserter(*matrix_, slotSize_);
+        insertionMode_ = true;
       }
     }
 
@@ -160,15 +150,15 @@ namespace AMDiS
     /// final construction of the matrix.
     void finish()
     {
-      delete inserter;
-      inserter = NULL;
-      insertionMode = false;
+      delete inserter_;
+      inserter_ = NULL;
+      insertionMode_ = false;
     }
 
     /// Return the number of nonzeros in the matrix
-    std::size_t getNnz() const
+    std::size_t nnz() const
     {
-      return matrix->nnz();
+      return matrix_->nnz();
     }
 
     /// \brief Deletes all rows with \p dirichletNodes != 0 and if \p apply is true, adds
@@ -178,9 +168,9 @@ namespace AMDiS
       std::list<Triplet<value_type>> columns;
 
       // Define the property maps
-      auto row   = mtl::mat::row_map(*matrix);
-      auto col   = mtl::mat::col_map(*matrix);
-      auto value = mtl::mat::value_map(*matrix);
+      auto row   = mtl::mat::row_map(*matrix_);
+      auto col   = mtl::mat::col_map(*matrix_);
+      auto value = mtl::mat::value_map(*matrix_);
 
       // iterate over the matrix
 #if 0
@@ -198,7 +188,7 @@ namespace AMDiS
       }
 #endif
 
-      for (auto r : mtl::rows_of(*matrix)) {   // rows or columns
+      for (auto r : mtl::rows_of(*matrix_)) {   // rows or columns
         if (dirichletNodes[r.value()]) {
           for (auto i : mtl::nz_of(r)) {          // non-zeros within
             // set identity row
@@ -273,12 +263,12 @@ namespace AMDiS
     // Estimates the slot-size used in the inserter to reserve enough space per row.
     void calculateSlotSize()
     {
-      slot_size = 0;
+      slotSize_ = 0;
 
-      if (num_rows(*matrix) != 0)
-        slot_size = int(double(matrix->nnz()) / num_rows(*matrix) * 1.2);
-      if (slot_size < MIN_NNZ_PER_ROW)
-        slot_size = MIN_NNZ_PER_ROW;
+      if (num_rows(*matrix_) != 0)
+        slotSize_ = int(double(matrix_->nnz()) / num_rows(*matrix_) * 1.2);
+      if (slotSize_ < MIN_NNZ_PER_ROW)
+        slotSize_ = MIN_NNZ_PER_ROW;
     }
 
   private:
@@ -286,28 +276,22 @@ namespace AMDiS
     static constexpr int MIN_NNZ_PER_ROW = 50;
 
     /// The finite element space / basis of the row
-    RowFeSpace const& rowFeSpace;
+    RowBasis const* rowBasis_;
 
     /// The finite element space / basis of the column
-    ColFeSpace const& colFeSpace;
-
-    /// The name of the DOFMatrix
-    std::string name;
+    ColBasis const* colBasis_;
 
     /// The data-matrix (can hold a new BaseMatrix or a pointer to external data
-    ClonablePtr<BaseMatrix> matrix;
+    ClonablePtr<BaseMatrix> matrix_;
 
     /// A pointer to the inserter. Created in \ref init and destroyed in \ref finish
-    Inserter* inserter = NULL;
+    Inserter* inserter_ = nullptr;
 
     /// A flag that indicates whether the matrix is in insertion mode
-    bool insertionMode = false;
+    bool insertionMode_ = false;
 
     /// The size of the slots used to insert values per row
-    int slot_size = MIN_NNZ_PER_ROW;
-
-    // friend class declarations
-    template <class, class> friend class SystemMatrix;
+    int slotSize_ = MIN_NNZ_PER_ROW;
   };
 
 } // end namespace AMDiS
diff --git a/src/amdis/linear_algebra/mtl/DOFVector.hpp b/src/amdis/linear_algebra/mtl/DOFVector.hpp
index 789d9270..1679e1ed 100644
--- a/src/amdis/linear_algebra/mtl/DOFVector.hpp
+++ b/src/amdis/linear_algebra/mtl/DOFVector.hpp
@@ -11,14 +11,16 @@
 #include <amdis/Output.hpp>
 #include <amdis/common/ClonablePtr.hpp>
 #include <amdis/common/ScalarTypes.hpp>
+#include <amdis/linear_algebra/DOFVectorBase.hpp>
 #include <amdis/linear_algebra/mtl/MTLDenseVector.hpp>
 #include <amdis/utility/MultiIndex.hpp>
 
 namespace AMDiS
 {
   /// The basic container that stores a base vector and a corresponding basis
-  template <class GlobalBasis, class RangeType = double>
+  template <class GlobalBasis, class ValueType = double>
   class DOFVector
+      : public DOFVectorBase
   {
     using Self = DOFVector;
 
@@ -27,28 +29,25 @@ namespace AMDiS
     using Basis = GlobalBasis;
 
     /// The type of the base vector
-    using BaseVector = MTLDenseVector<RangeType>;
+    using BaseVector = MTLDenseVector<ValueType>;
 
     /// The index/size - type
     using size_type  = typename GlobalBasis::size_type;
 
     /// The type of the elements of the DOFVector
-    using range_type = RangeType;
+    using value_type = ValueType;
 
     /// Constructor. Constructs new BaseVector.
-    DOFVector(GlobalBasis const& basis, std::string name)
+    DOFVector(GlobalBasis const& basis)
       : basis_(&basis)
-      , name_(name)
       , vector_(ClonablePtr<BaseVector>::make())
     {
       compress();
     }
 
     /// Constructor. Takes reference to existing BaseVector
-    DOFVector(GlobalBasis const& basis, std::string name,
-              BaseVector& vector_ref)
+    DOFVector(GlobalBasis const& basis, BaseVector& vector_ref)
       : basis_(&basis)
-      , name_(name)
       , vector_(vector_ref)
     {}
 
@@ -76,18 +75,12 @@ namespace AMDiS
       return basis_->dimension();
     }
 
-    /// Return the \ref name of this vector
-    std::string name() const
-    {
-      return name_;
-    }
-
     /// Resize the \ref vector to the size of the \ref basis.
-    void compress()
+    virtual void compress() override
     {
       if (num_rows(*vector_) != size()) {
         resize(size());
-        *vector_ = range_type(0);
+        *vector_ = value_type(0);
       }
     }
 
@@ -100,7 +93,7 @@ namespace AMDiS
 
     /// Access the entry \p i of the \ref vector with read-access.
     template <class Index>
-    range_type const& operator[](Index idx) const
+    value_type const& operator[](Index idx) const
     {
       auto const i = flatMultiIndex(idx);
       test_exit_dbg( i < num_rows(*vector_) ,
@@ -110,7 +103,7 @@ namespace AMDiS
 
     /// Access the entry \p i of the \ref vector with write-access.
     template <class Index>
-    range_type& operator[](Index idx)
+    value_type& operator[](Index idx)
     {
       auto const i = flatMultiIndex(idx);
       test_exit_dbg( i < num_rows(*vector_) ,
@@ -118,14 +111,6 @@ namespace AMDiS
       return (*vector_)[i];
     }
 
-    /// \brief interpolate a function \p f to the basis \ref basis and store the
-    /// coefficients in \ref vector.
-    template <class F>
-    void interpol(F&& f)
-    {
-      Dune::Functions::interpolate(*basis_, *this, std::forward<F>(f));
-    }
-
     /// Scale each DOFVector by the factor \p s.
     template <class Scalar>
     std::enable_if_t< Concepts::Arithmetic<Scalar>, Self&>
@@ -154,41 +139,35 @@ namespace AMDiS
     /// The finite element space / basis associated with the data vector
     Basis const* basis_;
 
-    /// The name of the DOFVector (used in file-writing)
-    std::string	name_;
-
     /// The data-vector (can hold a new BaseVector or a pointer to external data
     ClonablePtr<BaseVector> vector_;
-
-    // friend class declarations
-    template <class, class> friend class SystemVector;
   };
 
 #if DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
   // Deduction rules
   template <class GlobalBasis>
-  DOFVector(GlobalBasis const& basis, std::string name)
+  DOFVector(GlobalBasis const& basis)
     -> DOFVector<GlobalBasis, double>;
 
-  template <class GlobalBasis, class RangeType>
-  DOFVector(GlobalBasis const& basis, std::string name, MTLDenseVector<RangeType>& coefficients)
-    -> DOFVector<GlobalBasis, RangeType>;
+  template <class GlobalBasis, class ValueType>
+  DOFVector(GlobalBasis const& basis, MTLDenseVector<ValueType>& coefficients)
+    -> DOFVector<GlobalBasis, ValueType>;
 #endif
 
   /// Constructor a dofvector from given basis and name
-  template <class GlobalBasis, class RangeType = double>
-  DOFVector<GlobalBasis, RangeType>
-  makeDOFVector(GlobalBasis const& basis, std::string name)
+  template <class GlobalBasis, class ValueType = double>
+  DOFVector<GlobalBasis, ValueType>
+  makeDOFVector(GlobalBasis const& basis)
   {
-    return {basis, name};
+    return {basis};
   }
 
   /// Constructor a dofvector from given basis, name, and coefficient vector
-  template <class GlobalBasis, class RangeType>
-  DOFVector<GlobalBasis, RangeType>
-  makeDOFVector(GlobalBasis const& basis, std::string name, MTLDenseVector<RangeType>& coefficients)
+  template <class GlobalBasis, class ValueType>
+  DOFVector<GlobalBasis, ValueType>
+  makeDOFVector(GlobalBasis const& basis, MTLDenseVector<ValueType>& coefficients)
   {
-    return {basis, name, coefficients};
+    return {basis, coefficients};
   }
 
 } // end namespace AMDiS
-- 
GitLab