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

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

Detailed Description

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

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.

Note
This matrix type is used for the computation of boundary points in an mpi - distributed EllSparseBlockMat
Attention
We assume that the input vector in symv has the layout that is given by the Buffer vectors in dg::NearestNeighborComm
See also
dg::NearestNeighborComm

Constructor & Destructor Documentation

◆ CooSparseBlockMat() [1/2]

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

default constructor does nothing

◆ CooSparseBlockMat() [2/2]

template<class value_type >
dg::CooSparseBlockMat< value_type >::CooSparseBlockMat ( int  num_block_rows,
int  num_block_cols,
int  n,
int  left_size,
int  right_size 
)
inline

Allocate storage.

Parameters
num_block_rowsnumber of rows. Each row contains blocks.
num_block_colsnumber of columns.
neach block is of size nxn
left_sizesize of the left_size Kronecker delta
right_sizesize of the right_size Kronecker delta

Member Function Documentation

◆ add_value()

template<class value_type >
void dg::CooSparseBlockMat< value_type >::add_value ( int  row,
int  col,
const thrust::host_vector< value_type > &  element 
)
inline

Convenience function to assemble the matrix.

appends the given matrix entry to the existing matrix

Parameters
rowrow index
colcolumn index
elementnew block

◆ display()

template<class value_type >
void dg::CooSparseBlockMat< 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

◆ symv()

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

Parameters
alphamultiplies input
xinput
betapremultiplies output (cannot be anything other than 1, the given value is ignored)
youtput may not alias input
Attention
beta == 1 (anything else is ignored)

◆ total_num_cols()

template<class value_type >
int dg::CooSparseBlockMat< 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::CooSparseBlockMat< value_type >::total_num_rows ( ) const
inline

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

Member Data Documentation

◆ cols_idx

template<class value_type >
thrust::host_vector<int> dg::CooSparseBlockMat< value_type >::cols_idx

is of size num_entries and contains the column indices

◆ data

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

◆ data_idx

template<class value_type >
thrust::host_vector<int> dg::CooSparseBlockMat< value_type >::data_idx

is of size num_entries and contains indices into the data array

◆ left_size

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

size of the left Kronecker delta

◆ n

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

each block has size n*n

◆ num_cols

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

number of columns

◆ num_entries

template<class value_type >
int dg::CooSparseBlockMat< value_type >::num_entries

number of entries in the matrix

◆ num_rows

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

number of rows

◆ right_size

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

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

◆ rows_idx

template<class value_type >
thrust::host_vector<int> dg::CooSparseBlockMat< value_type >::rows_idx

is of size num_entries and contains the row indices


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