Discontinuous Galerkin Library
#include "dg/algorithm.h"
|
Ell Sparse Block Matrix format. More...
Public Member Functions | |
EllSparseBlockMat ()=default | |
default constructor does nothing | |
EllSparseBlockMat (int num_block_rows, int num_block_cols, int num_blocks_per_line, int num_different_blocks, int n) | |
Allocate storage. | |
template<class other_real_type , template< class > class Other_Vector> | |
EllSparseBlockMat (const EllSparseBlockMat< other_real_type, Other_Vector > &src) | |
int | total_num_rows () const |
total number of rows is num_rows*n*left_size*right_size | |
int | total_num_cols () const |
total number of columns is num_cols*n*left_size*right_size | |
dg::SparseMatrix< int, real_type, thrust::host_vector > | asCuspMatrix () const |
Convert to a sparse matrix. | |
template<class value_type > | |
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. | |
template<class value_type > | |
void | symv (SharedVectorTag, CudaTag, value_type alpha, const value_type *x, value_type beta, value_type *y) const |
void | set_default_range () |
Set right_range[0] = 0, right_range[1] = right_size | |
void | set_right_size (int new_right_size) |
Set right_size = new_right_size; set_default_range(); | |
void | set_left_size (int new_left_size) |
Set left_size = new_left_size; | |
void | display (std::ostream &os=std::cout, bool show_data=false) const |
Display internal data to a stream. | |
template<class value_type > | |
void | launch_multiply_kernel (SerialTag, value_type alpha, const value_type *x_ptr, value_type beta, value_type *y_ptr) const |
Public Attributes | |
Vector< real_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. | |
Vector< int > | cols_idx |
is of size num_rows*num_blocks_per_line and contains the column indices % n into the vector | |
Vector< int > | data_idx |
has the same size as cols_idx and contains indices into the data array, i.e. the block number | |
Vector< int > | right_range |
range (can be used to apply the matrix to only part of the right rows | |
int | num_rows |
number of block rows, each row contains blocks | |
int | num_cols |
number of block columns | |
int | blocks_per_line |
number of blocks in each line | |
int | n |
each block has size n*n | |
int | left_size |
size of the left Kronecker delta | |
int | right_size |
size of the right Kronecker delta (is e.g 1 for a x - derivative) | |
Static Public Attributes | |
static constexpr int | invalid_index = -1 |
Friends | |
template<class other_real_type , template< class > class Other_Vector> | |
class | EllSparseBlockMat |
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 |
|
inline |
dg::SparseMatrix< int, real_type, thrust::host_vector > dg::EllSparseBlockMat< real_type, Vector >::asCuspMatrix | ( | ) | const |
Convert to a sparse matrix.
void dg::EllSparseBlockMat< real_type, Vector >::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::EllSparseBlockMat< real_type, Vector >::launch_multiply_kernel | ( | SerialTag | , |
value_type | alpha, | ||
const value_type * | x_ptr, | ||
value_type | beta, | ||
value_type * | y_ptr ) const |
|
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();
|
inline |
|
inline |
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 |
value_type | value_type = real_type*value_type must be possible |
|
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
|
friend |
int dg::EllSparseBlockMat< real_type, Vector >::blocks_per_line |
number of blocks in each line
Vector<int> dg::EllSparseBlockMat< real_type, Vector >::cols_idx |
is of size num_rows*num_blocks_per_line and contains the column indices % n into the vector
Vector<real_type> dg::EllSparseBlockMat< real_type, Vector >::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.
Vector<int> dg::EllSparseBlockMat< real_type, Vector >::data_idx |
has the same size as cols_idx and contains indices into the data array, i.e. the block number
|
staticconstexpr |
Value used to pad the rows of the cols_idx array The data_idx must always be valid
int dg::EllSparseBlockMat< real_type, Vector >::left_size |
size of the left Kronecker delta
int dg::EllSparseBlockMat< real_type, Vector >::n |
each block has size n*n
int dg::EllSparseBlockMat< real_type, Vector >::num_cols |
number of block columns
int dg::EllSparseBlockMat< real_type, Vector >::num_rows |
number of block rows, each row contains blocks
Vector<int> dg::EllSparseBlockMat< real_type, Vector >::right_range |
range (can be used to apply the matrix to only part of the right rows
int dg::EllSparseBlockMat< real_type, Vector >::right_size |
size of the right Kronecker delta (is e.g 1 for a x - derivative)