7#include <dune/istl/bcrsmatrix.hh>
8#include <dune/istl/matrixindexset.hh>
10#include <amdis/Output.hpp>
11#include <amdis/linearalgebra/SparsityPattern.hpp>
12#include <amdis/linearalgebra/SymmetryStructure.hpp>
13#include <amdis/linearalgebra/istl/VectorBackend.hpp>
17 template <
class T,
class =
void>
20 using type = Dune::FieldMatrix<T,1,1>;
29 template <
class T,
class CommType>
34 using BaseMatrix = Dune::BCRSMatrix<typename BlockMatrixType<T>::type>;
63 Comm const& comm()
const {
return comm_; }
88 test_exit_dbg( initialized_,
"Occupation pattern not initialized!");
89 test_exit_dbg( r < matrix_.N() && c < matrix_.M() ,
90 "Indices out of range [0,{})x[0,{})", matrix_.N(), matrix_.M() );
91 matrix_[r][c] += value;
94 template <
class Ind,
class LocalMat>
95 void scatter(Ind
const& idx, LocalMat
const& mat)
97 scatter(idx, idx, mat);
100 template <
class RowInd,
class ColInd,
class LocalMat>
101 void scatter(RowInd
const& rows, ColInd
const& cols, LocalMat
const& mat)
103 test_exit_dbg( initialized_,
"Occupation pattern not initialized!");
106 matrix_[rows[i]][cols[j]] += mat[i][j];
110 template <
class RowInd>
115 auto cIt = matrix_[i].begin();
116 auto cEndIt = matrix_[i].end();
118 for (; cIt != cEndIt; ++cIt)
119 *cIt = (diag && i == cIt.index() ? T(1) : T(0));
124 template <
class RowInd,
class ColInd>
125 void zeroRows(RowInd
const& rowInd, ColInd
const& colInd,
bool diag)
128 auto rowIt = rowInd.begin();
129 auto rowEnd = rowInd.end();
130 auto colIt = colInd.begin();
131 for (; rowIt != rowEnd; ++rowIt,++colIt) {
132 auto cIt = matrix_[*rowIt].begin();
133 auto cEndIt = matrix_[*rowIt].end();
135 for (; cIt != cEndIt; ++cIt)
136 *cIt = (diag && *colIt == cIt.index() ? T(1) : T(0));
141 template <
class RowInd,
class ColInd>
144 assert(rowInd.size() == colInd.size());
146 std::vector<bool> colBitVec(matrix_.M(),
false);
147 for (std::size_t i = 0; i < colInd.size(); ++i)
148 colBitVec[colInd[i]] =
true;
152 auto cIt = matrix_[i].begin();
153 auto cEndIt = matrix_[i].end();
154 for (; cIt != cEndIt; ++cIt)
159 for (
size_type i = 0; i < matrix_.N(); ++i) {
160 auto cIt = matrix_[i].begin();
161 auto cEndIt = matrix_[i].end();
163 for (; cIt != cEndIt; ++cIt) {
164 if (colBitVec[cIt.index()]) {
166 b->vector()[i] -= (*cIt) * x->vector()[cIt.index()];
174 for (std::size_t i = 0; i < rowInd.size(); ++i) {
175 test_exit_dbg(matrix_.exists(rowInd[i], colInd[i]),
176 "The entry (",rowInd[i],
",",colInd[i],
") does not yet exist. Must be inserted in the pattern.");
177 matrix_[rowInd[i]][colInd[i]] = 1;
181 template <
class RowInd>
182 void zeroRowsColumns(RowInd
const& rowInd,
bool diag)
187 template <
class RowInd>
188 void zeroRowsColumns(RowInd
const& rowInd,
bool diag, ISTLBlockVector<T>
const& x, ISTLBlockVector<T>& b)
193 template <
class RowInd,
class ColInd>
194 void zeroRowsColumns(RowInd
const& rowInd, ColInd
const& colInd,
bool diag)
199 template <
class RowInd,
class ColInd>
200 void zeroRowsColumns(RowInd
const& rowInd, ColInd
const& colInd,
bool diag, ISTLBlockVector<T>
const& x, ISTLBlockVector<T>& b)
208 return matrix_.nonzeroes();
215 bool initialized_ =
false;
Definition: MatrixBackend.hpp:31
void init()
Set all entries to zero while keeping the occupation pattern intact.
Definition: MatrixBackend.hpp:73
std::size_t nnz() const
Return the number of entries allocated in the sparsity pattern of the matrix.
Definition: MatrixBackend.hpp:206
typename BaseMatrix::size_type size_type
The index/size - type.
Definition: MatrixBackend.hpp:43
Dune::BCRSMatrix< typename BlockMatrixType< T >::type > BaseMatrix
The matrix type of the underlying base matrix.
Definition: MatrixBackend.hpp:34
BaseMatrix const & matrix() const
Return the data-vector vector.
Definition: MatrixBackend.hpp:52
void zeroRowsColumnsImpl(RowInd const &rowInd, ColInd const &colInd, bool diag, ISTLBlockVector< T > const *x=nullptr, ISTLBlockVector< T > *b=nullptr)
Set all entries of the specified rows and columns to zero and the diagonal element to diag
Definition: MatrixBackend.hpp:142
BaseMatrix & matrix()
Return the data-vector vector.
Definition: MatrixBackend.hpp:58
void zeroRows(RowInd const &rowInd, ColInd const &colInd, bool diag)
Set all entries of the specified rows to zero and the diagonal element to diag
Definition: MatrixBackend.hpp:125
void init(SparsityPattern const &pattern)
Create occupation pattern and apply it to the matrix.
Definition: MatrixBackend.hpp:66
ISTLBCRSMatrix(Comm const &comm, Comm const &)
Constructor. Constructs new BaseVector.
Definition: MatrixBackend.hpp:47
void zeroRows(RowInd const &rowInd, bool diag)
Set all entries of the specified rows to zero and the diagonal element to diag
Definition: MatrixBackend.hpp:111
typename BaseMatrix::block_type value_type
The type of the elements of the DOFMatrix.
Definition: MatrixBackend.hpp:40
CommType Comm
Communication type.
Definition: MatrixBackend.hpp:37
void insert(size_type r, size_type c, value_type const &value)
Insert a single value into the matrix (add to existing value)
Definition: MatrixBackend.hpp:86
Definition: VectorBackend.hpp:28
A general sparsity pattern implementation using the full pattern of the basis by adding all local ind...
Definition: SparsityPattern.hpp:15
void applyTo(Matrix &matrix) const
Initialize a matrix with the non-zero structure.
Definition: SparsityPattern.hpp:75
Definition: MatrixBackend.hpp:19