Discontinuous Galerkin Library
#include "dg/algorithm.h"
|
Coo Sparse Block Matrix format. More...
Public Member Functions | |
CooSparseBlockMat ()=default | |
default constructor does nothing More... | |
CooSparseBlockMat (int num_block_rows, int num_block_cols, int n, int left_size, int right_size) | |
Allocate storage. More... | |
void | add_value (int row, int col, const thrust::host_vector< value_type > &element) |
Convenience function to assemble the matrix. More... | |
int | total_num_rows () const |
total number of rows is num_rows*n*left_size*right_size More... | |
int | total_num_cols () const |
total number of columns is num_cols*n*left_size*right_size More... | |
void | symv (SharedVectorTag, SerialTag, value_type alpha, const value_type **x, value_type beta, value_type *RESTRICT y) const |
Apply the matrix to a vector. More... | |
void | display (std::ostream &os=std::cout, bool show_data=false) const |
Display internal data to a stream. More... | |
Public Attributes | |
thrust::host_vector< value_type > | data |
The data array is of size n*n*num_different_blocks and contains the blocks. More... | |
thrust::host_vector< int > | cols_idx |
is of size num_entries and contains the column indices More... | |
thrust::host_vector< int > | rows_idx |
is of size num_entries and contains the row indices More... | |
thrust::host_vector< int > | data_idx |
is of size num_entries and contains indices into the data array More... | |
int | num_rows |
number of rows More... | |
int | num_cols |
number of columns More... | |
int | num_entries |
number of entries in the matrix More... | |
int | n |
each block has size n*n More... | |
int | left_size |
size of the left Kronecker delta More... | |
int | right_size |
size of the right Kronecker delta (is e.g 1 for a x - derivative) More... | |
Coo Sparse Block Matrix format.
The basis of this format is the well-known coordinate sparse matrix format. The clue is that instead of a values array we use an index array with indices into a data array that contains the actual blocks. This safes storage if the number of nonrecurrent blocks is small.
\[ M = \begin{pmatrix} A & & B& & & \\ & C & & & & \\ & & & & & \\ & A & & & B & C \end{pmatrix} \rightarrow \text{data}=(A,B,C)\quad \text{rows_idx} = ( 0,0,1,3,3,3) \quad\text{cols_idx} = (0,2,1,1,4,5) \]
where \(A,\ B,\ C,\ 0\) are \(n\times n\) block matrices. The matrix M in this example has num_rows=4
, num_cols=6
, num_entries=6
.
The indices and blocks are those of a one-dimensional problem. When we want to apply the matrix to a multidimensional vector we can multiply it by Kronecker deltas of the form
\[ 1_\mathrm{left}\otimes M \otimes 1_\mathrm{right}\]
where \( 1\) are diagonal matrices of variable size and \( M\) is our one-dimensional matrix.
EllSparseBlockMat
symv
has the layout that is given by the Buffer vectors in dg::NearestNeighborComm
dg::NearestNeighborComm
|
default |
default constructor does nothing
|
inline |
Allocate storage.
num_block_rows | number of rows. Each row contains blocks. |
num_block_cols | number of columns. |
n | each block is of size nxn |
left_size | size of the left_size Kronecker delta |
right_size | size of the right_size Kronecker delta |
|
inline |
Convenience function to assemble the matrix.
appends the given matrix entry to the existing matrix
row | row index |
col | column index |
element | new block |
void dg::CooSparseBlockMat< value_type >::display | ( | std::ostream & | os = std::cout , |
bool | show_data = false |
||
) | const |
Display internal data to a stream.
os | the output stream |
show_data | if true, displays the whole data vector |
void dg::CooSparseBlockMat< value_type >::symv | ( | SharedVectorTag | , |
SerialTag | , | ||
value_type | alpha, | ||
const value_type ** | x, | ||
value_type | beta, | ||
value_type *RESTRICT | y | ||
) | const |
Apply the matrix to a vector.
alpha | multiplies input |
x | input |
beta | premultiplies output (cannot be anything other than 1, the given value is ignored) |
y | output may not alias input |
|
inline |
total number of columns is num_cols*n*left_size*right_size
|
inline |
total number of rows is num_rows*n*left_size*right_size
thrust::host_vector<int> dg::CooSparseBlockMat< value_type >::cols_idx |
is of size num_entries
and contains the column indices
thrust::host_vector<value_type> dg::CooSparseBlockMat< value_type >::data |
The data array is of size n*n*num_different_blocks
and contains the blocks.
thrust::host_vector<int> dg::CooSparseBlockMat< value_type >::data_idx |
is of size num_entries
and contains indices into the data array
int dg::CooSparseBlockMat< value_type >::left_size |
size of the left Kronecker delta
int dg::CooSparseBlockMat< value_type >::n |
each block has size n*n
int dg::CooSparseBlockMat< value_type >::num_cols |
number of columns
int dg::CooSparseBlockMat< value_type >::num_entries |
number of entries in the matrix
int dg::CooSparseBlockMat< value_type >::num_rows |
number of rows
int dg::CooSparseBlockMat< value_type >::right_size |
size of the right Kronecker delta (is e.g 1 for a x - derivative)
thrust::host_vector<int> dg::CooSparseBlockMat< value_type >::rows_idx |
is of size num_entries
and contains the row indices