5#include <dune/common/shared_ptr.hh>
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>
23 template <
class T,
template <
class>
class MatrixImpl>
27 using Impl = MatrixImpl<T>;
32 template <
class RowBasis,
class ColBasis>
34 :
impl_(rowBasis.indexDistribution(), colBasis.indexDistribution())
42 template <
class SparsityPattern>
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)
66 impl_.insert(row, col, value);
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)
76 assert(r.size() * c.size() == localMatrix.size());
77 assert(r.size() == localMatrix.rows());
78 assert(c.size() == localMatrix.cols());
80 const bool optimized = std::is_same_v<RowLocalView,ColLocalView>
81 && std::uintptr_t(&r) == std::uintptr_t(&c);
84 impl_.scatter(nodeIndices(r), localMatrix);
86 impl_.scatter(nodeIndices(r), nodeIndices(c), localMatrix);
91 REQUIRES(Concepts::MultiIndex<Idx>)>
92 void zeroRows(std::vector<Idx>
const& ind,
bool diag)
94 impl_.zeroRows(ind, diag);
98 template <
class RowIdx,
class ColIdx,
99 REQUIRES(Concepts::MultiIndex<RowIdx>),
100 REQUIRES(Concepts::MultiIndex<ColIdx>)>
101 void zeroRows(std::vector<RowIdx>
const& rowInd, std::vector<ColIdx>
const& colInd,
bool diag)
103 assert(rowInd.size() == colInd.size());
104 impl_.zeroRows(rowInd, colInd, diag);
108 template <
class Idx,
class VecX,
class VecB,
109 REQUIRES(Concepts::MultiIndex<Idx>)>
112 impl_.zeroRowsColumns(ind, diag, x.impl(), b.impl());
117 REQUIRES(Concepts::MultiIndex<Idx>)>
120 impl_.zeroRowsColumns(ind, diag);
124 template <
class RowIdx,
class ColIdx,
class VecX,
class VecB,
125 REQUIRES(Concepts::MultiIndex<RowIdx>),
126 REQUIRES(Concepts::MultiIndex<ColIdx>)>
127 void zeroRowsColumns(std::vector<RowIdx>
const& rowInd, std::vector<ColIdx>
const& colInd,
bool diag, VecX
const& x, VecB& b)
129 assert(rowInd.size() == colInd.size());
130 impl_.zeroRowsColumns(rowInd, colInd, diag, x.impl(), b.impl());
134 template <
class RowIdx,
class ColIdx,
135 REQUIRES(Concepts::MultiIndex<RowIdx>),
136 REQUIRES(Concepts::MultiIndex<ColIdx>)>
137 void zeroRowsColumns(std::vector<RowIdx>
const& rowInd, std::vector<ColIdx>
const& colInd,
bool diag)
139 assert(rowInd.size() == colInd.size());
140 impl_.zeroRowsColumns(rowInd, colInd, diag);
Definition: MatrixFacade.hpp:25
void zeroRowsColumns(std::vector< RowIdx > const &rowInd, std::vector< ColIdx > const &colInd, bool diag, VecX const &x, VecB &b)
Set all entries of the specified rows and columns to zero and the diagonal elements defined as pairs ...
Definition: MatrixFacade.hpp:127
void init()
Initialize the matrix for insertion while keeping the pattern unchanged.
Definition: MatrixFacade.hpp:49
std::size_t nnz() const
Number of nonzeros in the matrix.
Definition: MatrixFacade.hpp:144
void init(SparsityPattern const &pattern)
Initialize the matrix for insertion and allocate the non-zero pattern.
Definition: MatrixFacade.hpp:43
MatrixFacade(RowBasis const &rowBasis, ColBasis const &colBasis)
Definition: MatrixFacade.hpp:33
Impl impl_
The matrix backend.
Definition: MatrixFacade.hpp:151
void zeroRowsColumns(std::vector< RowIdx > const &rowInd, std::vector< ColIdx > const &colInd, bool diag)
Set all entries of the specified rows and columns to zero and the diagonal elements defined as pairs ...
Definition: MatrixFacade.hpp:137
void zeroRowsColumns(std::vector< Idx > const &ind, bool diag)
Set all entries of the specified rows and columns==rows to zero and the main diagonal element to 1 if...
Definition: MatrixFacade.hpp:118
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
void zeroRowsColumns(std::vector< Idx > const &ind, bool diag, VecX const &x, VecB &b)
Set all entries of the specified rows and columns==rows to zero and the diagonal element to 1 if diag...
Definition: MatrixFacade.hpp:110
void zeroRows(std::vector< Idx > const &ind, bool diag)
Set all entries of the specified rows to zero and the diagonal element to diag
Definition: MatrixFacade.hpp:92
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 zeroRows(std::vector< RowIdx > const &rowInd, std::vector< ColIdx > const &colInd, bool diag)
Set all entries of the specified rows to zero and the diagonal element to diag
Definition: MatrixFacade.hpp:101
Impl const & impl() const
Return the underlying matrix backend.
Definition: MatrixFacade.hpp:38
A general sparsity pattern implementation using the full pattern of the basis by adding all local ind...
Definition: SparsityPattern.hpp:15