Discontinuous Galerkin Library
#include "dg/algorithm.h"
|
Ell Sparse Block Matrix format. More...
Public Member Functions | |
EllSparseBlockMat ()=default | |
default constructor does nothing More... | |
EllSparseBlockMat (int num_block_rows, int num_block_cols, int num_blocks_per_line, int num_different_blocks, int n) | |
Allocate storage. 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... | |
cusp::coo_matrix< int, value_type, cusp::host_memory > | asCuspMatrix () const |
Convert to a cusp coordinate sparse matrix. More... | |
void | symv (SharedVectorTag, SerialTag, value_type alpha, const value_type *RESTRICT x, value_type beta, value_type *RESTRICT y) const |
Apply the matrix to a vector. More... | |
void | set_default_range () |
Set right_range[0] = 0, right_range[1] = right_size More... | |
void | set_right_size (int new_right_size) |
Set right_size = new_right_size; set_default_range(); More... | |
void | set_left_size (int new_left_size) |
Set left_size = new_left_size; 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. The first block is contained in the first n*n elements, then comes the next block, etc. More... | |
thrust::host_vector< int > | cols_idx |
is of size num_rows*num_blocks_per_line and contains the column indices % n into the vector More... | |
thrust::host_vector< int > | data_idx |
has the same size as cols_idx and contains indices into the data array, i.e. the block number More... | |
thrust::host_vector< int > | right_range |
range (can be used to apply the matrix to only part of the right rows More... | |
int | num_rows |
number of block rows, each row contains blocks More... | |
int | num_cols |
number of block columns More... | |
int | blocks_per_line |
number of blocks in each line 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... | |
Ell Sparse Block Matrix format.
The basis of this format is the ell sparse matrix format, i.e. a format where the number of entries per line is fixed. 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. 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
\[ M = \begin{pmatrix} B & C & & & & \\ A & B & C & & & \\ & A & B & C & & \\ & & A & B & C & \\ & & &...& & \end{pmatrix}\rightarrow \text{data} = ( A, B, C, 0)\quad \text{cols_idx} = ( 0,0,1,0,1,2,1,2,3,2,3,4,...) \quad \text{data_idx} = ( 3,1,2,0,1,2,0,1,2,0,1,2,...)\]
where \(A,\ B,\ C,\ 0\) are \(n\times n\) block matrices. The 0 is used for padding in order to keep the number of elements per line constant as 3 (in this example blocks_per_line=3
, num_different_blocks=4
). The matrix M has num_rows
rows and num_cols
columns of blocks.
\[ 1_\mathrm{left}\otimes M \otimes 1_\mathrm{right}\]
where \( 1\) are diagonal matrices of variable size and \( M\) is our one-dimensional matrix.
|
default |
default constructor does nothing
|
inline |
Allocate storage.
Initializes left_size = right_size = 1
, right_range[0] = 0
and right_range[1] = 1
, data(num_different_blocks*n*n), cols_idx( num_block_rows*num_blocks_per_line), data_idx(cols_idx.size())
num_block_rows | number of rows num_rows . Each row contains blocks. |
num_block_cols | number of columns num_cols . |
num_blocks_per_line | number of blocks in each line blocks_per_line |
num_different_blocks | number of nonrecurrent blocks |
n | each block is of size nxn |
cusp::coo_matrix< int, value_type, cusp::host_memory > dg::EllSparseBlockMat< value_type >::asCuspMatrix | ( | ) | const |
Convert to a cusp coordinate sparse matrix.
void dg::EllSparseBlockMat< 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 |
|
inline |
Set right_range[0] = 0, right_range[1] = right_size
|
inline |
Set left_size = new_left_size;
|
inline |
Set right_size = new_right_size; set_default_range();
void dg::EllSparseBlockMat< value_type >::symv | ( | SharedVectorTag | , |
SerialTag | , | ||
value_type | alpha, | ||
const value_type *RESTRICT | x, | ||
value_type | beta, | ||
value_type *RESTRICT | y | ||
) | const |
Apply the matrix to a vector.
\[ y= \alpha M x + \beta y\]
alpha | multiplies input |
x | input |
beta | premultiplies output |
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
int dg::EllSparseBlockMat< value_type >::blocks_per_line |
number of blocks in each line
thrust::host_vector<int> dg::EllSparseBlockMat< value_type >::cols_idx |
is of size num_rows*num_blocks_per_line and contains the column indices % n into the vector
thrust::host_vector<value_type> dg::EllSparseBlockMat< value_type >::data |
The data array is of size n*n*num_different_blocks and contains the blocks. The first block is contained in the first n*n elements, then comes the next block, etc.
thrust::host_vector<int> dg::EllSparseBlockMat< value_type >::data_idx |
has the same size as cols_idx and contains indices into the data array, i.e. the block number
int dg::EllSparseBlockMat< value_type >::left_size |
size of the left Kronecker delta
int dg::EllSparseBlockMat< value_type >::n |
each block has size n*n
int dg::EllSparseBlockMat< value_type >::num_cols |
number of block columns
int dg::EllSparseBlockMat< value_type >::num_rows |
number of block rows, each row contains blocks
thrust::host_vector<int> dg::EllSparseBlockMat< value_type >::right_range |
range (can be used to apply the matrix to only part of the right rows
int dg::EllSparseBlockMat< value_type >::right_size |
size of the right Kronecker delta (is e.g 1 for a x - derivative)