DOFMatrixBase.hpp 3.99 KB
Newer Older
1
2
#pragma once

3
#include <cmath>
4
5
6

#include <dune/common/timer.hh>

7
#include <amdis/LocalAssemblerList.hpp>
8
#include <amdis/common/Math.hpp>
9
#include <amdis/utility/MultiIndex.hpp>
10
#include <amdis/utility/TreePath.hpp>
11

12
13
namespace AMDiS
{
14
  template <class RowBasisType, class ColBasisType, class Backend>
Praetorius, Simon's avatar
Praetorius, Simon committed
15
  class DOFMatrixBase
16
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
17
18
19
  public:
    /// The type of the finite element space / basis of the row
    using RowBasis = RowBasisType;
20
    using RowLocalView = typename RowBasis::LocalView;
Praetorius, Simon's avatar
Praetorius, Simon committed
21
22
23

    /// The type of the finite element space / basis of the column
    using ColBasis = ColBasisType;
24
25
26
27
    using ColLocalView = typename ColBasis::LocalView;

    using Element = typename RowLocalView::Element;
    using Geometry = typename Element::Geometry;
Praetorius, Simon's avatar
Praetorius, Simon committed
28
29
30
31

    /// The index/size - type
    using size_type = typename RowBasis::size_type;

32
    using BaseMatrix = typename Backend::BaseMatrix;
33
    using ElementMatrix = Dune::DynamicMatrix<double>;
34

Praetorius, Simon's avatar
Praetorius, Simon committed
35
36
37
38
39
  public:
    /// Constructor. Constructs new BaseVector.
    DOFMatrixBase(RowBasis const& rowBasis, ColBasis const& colBasis)
      : rowBasis_(&rowBasis)
      , colBasis_(&colBasis)
40
    {
41
      operators_.init(rowBasis, colBasis);
42
    }
Praetorius, Simon's avatar
Praetorius, Simon committed
43
44
45
46
47
48
49
50
51
52
53
54
55

    /// Return the row-basis \ref rowBasis of the matrix
    RowBasis const& rowBasis() const
    {
      return *rowBasis_;
    }

    /// Return the col-basis \ref colBasis of the matrix
    ColBasis const& colBasis() const
    {
      return *colBasis_;
    }

56
57
58
59
60
61
62
63
64
65
66
67
    /// Return the data-matrix
    BaseMatrix const& matrix() const
    {
      return backend_.matrix();
    }

    /// Return the data-matrix
    BaseMatrix& matrix()
    {
      return backend_.matrix();
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
68
69
70
71
72
73
74
75
76
77
78
79
    /// Return the size of the \ref rowBasis_
    size_type rows() const
    {
      return rowBasis_->dimension();
    }

    /// Return the size of the \ref colBasis_
    size_type cols() const
    {
      return colBasis_->dimension();
    }

80
81
    /// Initialize the matrix for insertion, e.g. allocate the non-zero pattern
    /// If \p setToZero is true, the matrix is set to 0
82
    void init(bool asmMatrix);
83
84

    /// Finish the matrix insertion, e.g. cleanup or final insertion
85
    void finish(bool asmMatrix);
86
87

    /// Insert a block of values into the matrix (add to existing values)
88
89
    void insert(RowLocalView const& rowLocalView,
                ColLocalView const& colLocalView,
90
                ElementMatrix const& elementMatrix);
91
92
93
94
95
96
97
98

    /// Insert a single value into the matrix (add to existing value)
    template <class RowIndex, class ColIndex>
    void insert(RowIndex row, ColIndex col, typename Backend::value_type const& value)
    {
      backend_.insert(flatMultiIndex(row), flatMultiIndex(col), value);
    }

99
    /// Associate a local operator with this DOFMatrix
100
101
102
    template <class ContextTag, class Operator,
              class RowTreePath = RootTreePath, class ColTreePath = RootTreePath>
    void addOperator(ContextTag contextTag, Operator const& preOp,
103
                     RowTreePath row = {}, ColTreePath col = {});
104

105
106
107
    /// Assemble the matrix operators on the bound element.
    void assemble(RowLocalView const& rowLocalView,
                  ColLocalView const& colLocalView);
108

109
110
    /// Assemble all matrix operators, TODO: incooperate boundary conditions
    void assemble();
111

112
113
114
115
116
117
118
119
120
121
122
123
    /// \brief Deletes all rows with \p dirichletNodes != 0 and if \p apply is true, adds
    /// a one on the diagonal of the matrix.
    auto applyDirichletBC(std::vector<char> const& dirichletNodes)
    {
      return backend_.applyDirichletBC(dirichletNodes);
    }

    size_type nnz() const
    {
      return backend_.nnz();
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
124
  protected:
125
126
127
    /// The finite element space / basis associated with the rows/columns
    RowBasis const* rowBasis_;
    ColBasis const* colBasis_;
128
129

    /// Data backend
130
    Backend backend_;
131

132
133
134
135
136
    /// Dense matrix to store coefficients during \ref assemble()
    ElementMatrix elementMatrix_;

    /// List of operators associated to row/col node
    MatrixOperators<RowBasis,ColBasis> operators_;
137
138
139
  };

} // end namespace AMDiS
140
141

#include "DOFMatrixBase.inc.hpp"