Discontinuous Galerkin Library
#include "dg/algorithm.h"
dg::EllSparseBlockMat< value_type > Struct Template Reference

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...
 

Detailed Description

template<class value_type>
struct dg::EllSparseBlockMat< value_type >

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.

Constructor & Destructor Documentation

◆ EllSparseBlockMat() [1/2]

template<class value_type >
dg::EllSparseBlockMat< value_type >::EllSparseBlockMat ( )
default

default constructor does nothing

◆ EllSparseBlockMat() [2/2]

template<class value_type >
dg::EllSparseBlockMat< value_type >::EllSparseBlockMat ( int  num_block_rows,
int  num_block_cols,
int  num_blocks_per_line,
int  num_different_blocks,
int  n 
)
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())

Parameters
num_block_rowsnumber of rows num_rows. Each row contains blocks.
num_block_colsnumber of columns num_cols.
num_blocks_per_linenumber of blocks in each line blocks_per_line
num_different_blocksnumber of nonrecurrent blocks
neach block is of size nxn

Member Function Documentation

◆ asCuspMatrix()

template<class value_type >
cusp::coo_matrix< int, value_type, cusp::host_memory > dg::EllSparseBlockMat< value_type >::asCuspMatrix ( ) const

Convert to a cusp coordinate sparse matrix.

Returns
The matrix in coo sparse matrix format

◆ display()

template<class value_type >
void dg::EllSparseBlockMat< value_type >::display ( std::ostream &  os = std::cout,
bool  show_data = false 
) const

Display internal data to a stream.

Parameters
osthe output stream
show_dataif true, displays the whole data vector

◆ set_default_range()

template<class value_type >
void dg::EllSparseBlockMat< value_type >::set_default_range ( )
inline

Set right_range[0] = 0, right_range[1] = right_size

◆ set_left_size()

template<class value_type >
void dg::EllSparseBlockMat< value_type >::set_left_size ( int  new_left_size)
inline

Set left_size = new_left_size;

◆ set_right_size()

template<class value_type >
void dg::EllSparseBlockMat< value_type >::set_right_size ( int  new_right_size)
inline

Set right_size = new_right_size; set_default_range();

◆ symv()

template<class value_type >
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\]

Parameters
alphamultiplies input
xinput
betapremultiplies output
youtput may not alias input

◆ total_num_cols()

template<class value_type >
int dg::EllSparseBlockMat< value_type >::total_num_cols ( ) const
inline

total number of columns is num_cols*n*left_size*right_size

◆ total_num_rows()

template<class value_type >
int dg::EllSparseBlockMat< value_type >::total_num_rows ( ) const
inline

total number of rows is num_rows*n*left_size*right_size

Member Data Documentation

◆ blocks_per_line

template<class value_type >
int dg::EllSparseBlockMat< value_type >::blocks_per_line

number of blocks in each line

◆ cols_idx

template<class value_type >
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

◆ data

template<class value_type >
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.

◆ data_idx

template<class value_type >
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

◆ left_size

template<class value_type >
int dg::EllSparseBlockMat< value_type >::left_size

size of the left Kronecker delta

◆ n

template<class value_type >
int dg::EllSparseBlockMat< value_type >::n

each block has size n*n

◆ num_cols

template<class value_type >
int dg::EllSparseBlockMat< value_type >::num_cols

number of block columns

◆ num_rows

template<class value_type >
int dg::EllSparseBlockMat< value_type >::num_rows

number of block rows, each row contains blocks

◆ right_range

template<class value_type >
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

◆ right_size

template<class value_type >
int dg::EllSparseBlockMat< value_type >::right_size

size of the right Kronecker delta (is e.g 1 for a x - derivative)


The documentation for this struct was generated from the following file: