AMDiS  0.1
The Adaptive Multi-Dimensional Simulation Toolbox
MatrixFacade.hpp
1 #pragma once
2 
3 #include <type_traits>
4 
5 #include <dune/common/shared_ptr.hh>
6 
7 #include <amdis/common/Concepts.hpp>
8 #include <amdis/common/ConceptsBase.hpp>
9 #include <amdis/common/TypeTraits.hpp>
10 #include <amdis/functions/NodeIndices.hpp>
11 #include <amdis/typetree/MultiIndex.hpp>
12 
13 namespace AMDiS
14 {
23  template <class T, template <class> class MatrixImpl>
24  class MatrixFacade
25  {
26  using Self = MatrixFacade;
27  using Impl = MatrixImpl<T>;
28 
29  public:
32  template <class RowBasis, class ColBasis>
33  MatrixFacade(RowBasis const& rowBasis, ColBasis const& colBasis)
34  : impl_(rowBasis, colBasis)
35  {}
36 
38  Impl const& impl() const { return impl_; }
39  Impl& impl() { return impl_; }
40 
42  template <class SparsityPattern>
43  void init(SparsityPattern const& pattern)
44  {
45  impl_.init(pattern);
46  }
47 
49  void init()
50  {
51  impl_.init();
52  }
53 
55  void finish()
56  {
57  impl_.finish();
58  }
59 
61  template <class RowIndex, class ColIndex,
62  REQUIRES(Concepts::MultiIndex<RowIndex>),
63  REQUIRES(Concepts::MultiIndex<ColIndex>)>
64  void insert(RowIndex const& row, ColIndex const& col, typename Impl::value_type const& value)
65  {
66  impl_.insert(row, col, value);
67  }
68 
71  template <class RowLocalView, class ColLocalView, class LocalMatrix,
72  REQUIRES(Concepts::LocalView<RowLocalView>),
73  REQUIRES(Concepts::LocalView<ColLocalView>)>
74  void scatter(RowLocalView const& r, ColLocalView const& c, LocalMatrix const& localMatrix)
75  {
76  assert(r.size() * c.size() == localMatrix.size());
77  assert(r.size() == localMatrix.rows());
78  assert(c.size() == localMatrix.cols());
79 
80  const bool optimized = std::is_same_v<RowLocalView,ColLocalView>
81  && r.tree().treeIndex() == c.tree().treeIndex();
82 
83  if (optimized)
84  impl_.scatter(nodeIndices(r), localMatrix);
85  else
86  impl_.scatter(nodeIndices(r), nodeIndices(c), localMatrix);
87  }
88 
90  std::size_t nnz() const
91  {
92  return impl_.nnz();
93  }
94 
95  protected:
97  Impl impl_;
98  };
99 
100 } // end namespace AMDiS
void scatter(RowLocalView const &r, ColLocalView const &c, LocalMatrix const &localMatrix)
Definition: MatrixFacade.hpp:74
void finish()
Finish the matrix insertion, e.g. cleanup or final insertion.
Definition: MatrixFacade.hpp:55
std::size_t nnz() const
Number of nonzeros in the matrix.
Definition: MatrixFacade.hpp:90
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
MatrixFacade(RowBasis const &rowBasis, ColBasis const &colBasis)
Definition: MatrixFacade.hpp:33
A general sparsity pattern implementation using the full pattern of the basis by adding all local ind...
Definition: SparsityPattern.hpp:14
void insert(RowIndex const &row, ColIndex const &col, typename Impl::value_type const &value)
Insert a single value into the matrix (add to existing value)
Definition: MatrixFacade.hpp:64
void init(SparsityPattern const &pattern)
Initialize the matrix for insertion and allocate the non-zero pattern.
Definition: MatrixFacade.hpp:43
Impl impl_
The matrix backend.
Definition: MatrixFacade.hpp:97
void init()
Initialize the matrix for insertion while keeping the pattern unchanged.
Definition: MatrixFacade.hpp:49
auto nodeIndices(LocalView const &localView, Node const &node)
Returns a range over (flat) DOF indices on a node, given by the localView.
Definition: NodeIndices.hpp:13
Impl const & impl() const
Return the underlying matrix backend.
Definition: MatrixFacade.hpp:38