9#include <kernel/adjacency/graph.hpp>
10#include <kernel/lafem/vector_mirror.hpp>
11#include <kernel/lafem/matrix_mirror_buffer.hpp>
12#include <kernel/lafem/sparse_matrix_bcsr.hpp>
13#include <kernel/lafem/sparse_matrix_csr.hpp>
14#include <kernel/lafem/sparse_matrix_banded.hpp>
31 template<
typename DT_,
typename IT_>
98 template<
int bw_,
int bh_>
171 for(IT_ i(0); i < IT_(buffer.
num_rows()); ++i)
174 const IT_ ridx = mir_idx_r[i];
177 for(IT_ j(row_ptr_b[i]); j < row_ptr_b[i+1]; ++j)
183 const IT_ cidx = mir_idx_c[col_idx_b[j]];
186 for(IT_ k(row_ptr_a[ridx]); k < row_ptr_a[ridx+1]; ++k)
188 if(col_idx_a[k] == cidx)
213 const DT_ alpha = DT_(1))
const
236 for(IT_ i(0); i < IT_(buffer.
num_rows()); ++i)
239 const IT_ ridx = mir_idx_r[i];
242 for(IT_ j(row_ptr_b[i]); j < row_ptr_b[i+1]; ++j)
245 const IT_ cidx = mir_idx_c[col_idx_b[j]];
248 for(IT_ k(row_ptr_a[ridx]); k < row_ptr_a[ridx+1]; ++k)
250 if(col_idx_a[k] == cidx)
252 val_a[k] += alpha*val_b[j];
269 template<
int bw_,
int bh_>
297 for(IT_ i(0); i < IT_(buffer.
num_rows()); ++i)
300 const IT_ ridx = mir_idx_r[i];
303 for(IT_ j(row_ptr_b[i]); j < row_ptr_b[i+1]; ++j)
309 const IT_ cidx = mir_idx_c[col_idx_b[j]];
312 for(IT_ k(row_ptr_a[ridx]); k < row_ptr_a[ridx+1]; ++k)
314 if(col_idx_a[k] == cidx)
336 template<
int bw_,
int bh_>
340 const DT_ alpha = DT_(1))
const
365 for(IT_ i(0); i < IT_(buffer.
num_rows()); ++i)
368 const IT_ ridx = mir_idx_r[i];
371 for(IT_ j(row_ptr_b[i]); j < row_ptr_b[i+1]; ++j)
374 const IT_ cidx = mir_idx_c[col_idx_b[j]];
377 for(IT_ k(row_ptr_a[ridx]); k < row_ptr_a[ridx+1]; ++k)
379 if(col_idx_a[k] == cidx)
381 val_a[k].axpy(alpha, val_b[j]);
617 template<
typename MT_>
631 const Index* dom_ptr = mat_graph.get_domain_ptr();
632 const Index* img_idx = mat_graph.get_image_idx();
641 std::map<Index,Index> col_map;
642 for(
Index i(0); i < ncols; ++i)
643 col_map.emplace(cidx[i], i);
647 for(
Index i(0); i < nrows; ++i)
649 const Index irow = ridx[i];
650 for(
Index j(dom_ptr[irow]); j < dom_ptr[irow+1]; ++j)
652 if(col_map.find(img_idx[j]) != col_map.end())
658 Adjacency::Graph graph(nrows, ncols, count);
659 Index* row_ptr = graph.get_domain_ptr();
660 Index* col_idx = graph.get_image_idx();
663 row_ptr[0] =
Index(0);
664 for(
Index i(0); i < nrows; ++i)
666 const Index irow = ridx[i];
667 Index k = row_ptr[i];
668 for(
Index j(dom_ptr[irow]); j < dom_ptr[irow+1]; ++j)
670 auto it = col_map.find(img_idx[j]);
671 if(it != col_map.end())
673 col_idx[k] = it->second;
679 XASSERT(row_ptr[nrows] == count);
682 graph.sort_indices();
#define XASSERT(expr)
Assertion macro definition.
Adjacency Graph implementation.
Matrix Mirror Buffer class template.
Index num_rows() const
Retrieve matrix row count.
Index num_cols() const
Retrieve matrix column count.
Index entries_per_nonzero() const
Retrieve entries per non zero element count.
Matrix-Mirror class template.
IT_ IndexType
index-type typedef
void scatter_axpy(LAFEM::SparseMatrixCSR< DT_, IT_ > &matrix, const LAFEM::MatrixMirrorBuffer< DT_, IT_ > &buffer, const DT_ alpha=DT_(1)) const
Performs a scatter-axpy-operation on an operator matrix.
MatrixMirror(MatrixMirror &&other)
move constructor
LAFEM::VectorMirror< DT_, IT_ > VectorMirrorType
vector mirror type
const VectorMirrorType & _row_mirror
row-mirror reference
MatrixMirror(const VectorMirrorType &row_mirror, const VectorMirrorType &col_mirror)
Constructor.
DT_ DataType
data-type typedef
void gather(LAFEM::MatrixMirrorBuffer< DT_, IT_ > &buffer, const LAFEM::SparseMatrixBCSR< DT_, IT_, bw_, bh_ > &matrix) const
Performs a gather-operation on an operator matrix.
LAFEM::MatrixMirrorBuffer< DT_, IT_ > create_buffer(const LAFEM::SparseMatrixBanded< DT_, IT_ > &matrix) const
Creates a buffer matrix based on a banded template matrix.
void scatter_axpy(LAFEM::SparseMatrixBCSR< DT_, IT_, bw_, bh_ > &matrix, const LAFEM::MatrixMirrorBuffer< DT_, IT_ > &buffer, const DT_ alpha=DT_(1)) const
Performs a scatter-axpy-operation on an operator matrix.
const VectorMirrorType & get_row_mirror() const
virtual ~MatrixMirror()
virtual destructor
LAFEM::MatrixMirrorBuffer< DT_, IT_ > create_buffer(const LAFEM::SparseMatrixBCSR< DT_, IT_, bw_, bh_ > &matrix) const
Creates a buffer matrix based on a BCSR template matrix.
const VectorMirrorType & get_col_mirror() const
LAFEM::MatrixMirrorBuffer< DT_, IT_ > create_buffer(const LAFEM::SparseMatrixCSR< DT_, IT_ > &matrix) const
Creates a buffer matrix based on a CSR template matrix.
const VectorMirrorType & _col_mirror
col-mirror reference
void gather(LAFEM::MatrixMirrorBuffer< DT_, IT_ > &buffer, const LAFEM::SparseMatrixCSR< DT_, IT_ > &matrix) const
Performs a gather-operation on an operator matrix.
CSR based blocked sparse matrix.
Index num_rows() const
Retrieve matrix row count.
Index num_cols() const
Retrieve matrix column count.
Index num_cols() const
Retrieve matrix column count.
Index num_rows() const
Retrieve matrix row count.
Handles vector prolongation, restriction and serialization.
Index num_indices() const
Returns the number of indices in the mirror.
void format(const T_ &value)
Formats the array elements to a given value, i.e. sets all elements to the same value.
Tiny Matrix class template.
@ injectify
Render-Injectified mode.
std::uint64_t Index
Index data type.