5#include <dune/istl/matrixindexset.hh>
7#include <amdis/common/Index.hpp>
8#include <amdis/linearalgebra/SymmetryStructure.hpp>
17 template <
class Basis>
18 SparsityPattern(Basis
const& basis, SymmetryStructure symmetry = SymmetryStructure::unknown)
19 : rows_(basis.dimension())
21 , pattern_(rows_, cols_)
26 template <
class RowBasis,
class ColBasis>
28 SymmetryStructure = SymmetryStructure::unknown)
29 : rows_(rowBasis.dimension())
30 , cols_(colBasis.dimension())
31 , pattern_(rows_, cols_)
33 if (uintptr_t(&rowBasis) == uintptr_t(&colBasis))
36 init(rowBasis, colBasis);
54 assert(rows_ == pattern_.rows());
56 for (std::size_t r = 0; r < rows_; ++r)
58 return (sum + rows_ - 1) / rows_;
64 return pattern_.rowsize(r);
68 std::size_t
nnz()
const
70 return pattern_.size();
74 template <
class Matrix>
77 pattern_.exportIdx(matrix);
83 template <
class Basis>
84 void init(Basis
const& basis)
86 auto localView = basis.localView();
87 for (
const auto& element : elements(basis.gridView())) {
88 localView.bind(element);
90 for (std::size_t i = 0, size = localView.size(); i < size; ++i) {
92 auto row = localView.index(i);
93 for (std::size_t j = 0; j < size; ++j) {
95 auto col = localView.index(j);
96 pattern_.add(row, col);
103 template <
class RowBasis,
class ColBasis>
104 void init(RowBasis
const& rowBasis, ColBasis
const& colBasis)
106 auto rowLocalView = rowBasis.localView();
107 auto colLocalView = colBasis.localView();
108 for (
const auto& element : elements(rowBasis.gridView())) {
109 rowLocalView.bind(element);
110 colLocalView.bind(element);
112 for (std::size_t i = 0; i < rowLocalView.size(); ++i) {
114 auto row = rowLocalView.index(i);
115 for (std::size_t j = 0; j < colLocalView.size(); ++j) {
117 auto col = colLocalView.index(j);
118 pattern_.add(row, col);
127 Dune::MatrixIndexSet pattern_;
A general sparsity pattern implementation using the full pattern of the basis by adding all local ind...
Definition: SparsityPattern.hpp:15
std::size_t nnz() const
Total number of non-zeros.
Definition: SparsityPattern.hpp:68
std::size_t rows() const
Number of rows in the matrix.
Definition: SparsityPattern.hpp:40
std::size_t rowSize(std::size_t r) const
Number of non-zeros in row r.
Definition: SparsityPattern.hpp:62
std::size_t avgRowSize() const
Average number of non-zeros per row.
Definition: SparsityPattern.hpp:52
void applyTo(Matrix &matrix) const
Initialize a matrix with the non-zero structure.
Definition: SparsityPattern.hpp:75
std::size_t cols() const
Number of columns in the matrix.
Definition: SparsityPattern.hpp:46