Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
Classes | Public Types | Public Member Functions | Protected Attributes | Private Attributes | List of all members
BlockMatrixArray< number, BlockVectorType > Class Template Reference

#include <deal.II/lac/block_matrix_array.h>

Inheritance diagram for BlockMatrixArray< number, BlockVectorType >:
[legend]

Classes

class  Entry
 

Public Types

using size_type = types::global_dof_index
 

Public Member Functions

 BlockMatrixArray ()
 
 BlockMatrixArray (const unsigned int n_block_rows, const unsigned int n_block_cols)
 
void initialize (const unsigned int n_block_rows, const unsigned int n_block_cols)
 
void reinit (const unsigned int n_block_rows, const unsigned int n_block_cols)
 
template<typename MatrixType >
void enter (const MatrixType &matrix, const unsigned int row, const unsigned int col, const number prefix=1., const bool transpose=false)
 
void clear ()
 
unsigned int n_block_rows () const
 
unsigned int n_block_cols () const
 
void vmult (BlockVectorType &dst, const BlockVectorType &src) const
 
void vmult_add (BlockVectorType &dst, const BlockVectorType &src) const
 
void Tvmult (BlockVectorType &dst, const BlockVectorType &src) const
 
void Tvmult_add (BlockVectorType &dst, const BlockVectorType &src) const
 
number matrix_scalar_product (const BlockVectorType &u, const BlockVectorType &v) const
 
number matrix_norm_square (const BlockVectorType &u) const
 
template<class StreamType >
void print_latex (StreamType &out) const
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
 Subscriptor (Subscriptor &&) noexcept
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
Subscriptoroperator= (Subscriptor &&) noexcept
 
void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
template<typename StreamType >
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Protected Attributes

std::vector< Entryentries
 

Private Attributes

unsigned int block_rows
 
unsigned int block_cols
 

Additional Inherited Members

- Static Public Member Functions inherited from Subscriptor
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 

Detailed Description

template<typename number = double, typename BlockVectorType = BlockVector<number>>
class BlockMatrixArray< number, BlockVectorType >

Block matrix composed of different single matrices; these matrices may even be of different types.

Given a set of arbitrary matrices Ai, this class implements a block matrix with block entries of the form Mjk = sjkAi. Each Ai may be used several times with different prefix. The matrices are not copied into the BlockMatrixArray object, but rather a PointerMatrix referencing each of them will be stored along with factors and transposition flags.

Non-zero entries are registered by the function enter(), zero entries are not stored at all. Using enter() with the same location (i,j) several times will add the corresponding matrices in matrix-vector multiplications. These matrices will not be actually added, but the multiplications with them will be summed up.

Note
This mechanism makes it impossible to access single entries of BlockMatrixArray. In particular, (block) relaxation preconditioners based on PreconditionRelaxation or PreconditionBlock cannot be used with this class. If you need a preconditioner for a BlockMatrixArray object, use BlockTrianglePrecondition.

Requirements on MatrixType

The template argument MatrixType is a class providing the matrix- vector multiplication functions vmult(), Tvmult(), vmult_add() and Tvmult_add() used in this class, but with arguments of type Vector<number> instead of BlockVector<number>. Every matrix which can be used by PointerMatrix is allowed, in particular SparseMatrix is a possible entry type.

Example program

We document the relevant parts of examples/doxygen/block_matrix_array.cc.

Obviously, we have to include the header file containing the definition of BlockMatrixArray:

#include <deal.II/lac/block_matrix_array.h>

First, we set up some matrices to be entered into the blocks.

int main()
{
A.fill(&Adata[0][0]);
B1.fill(&B1data[0][0]);
B2.fill(&B2data[0][0]);
C.fill(&Cdata[0][0]);

Now, we are ready to build a 2x2 BlockMatrixArray.

First, we enter the matrix A multiplied by 2 in the upper left block

matrix.enter(A, 0, 0, 2.);

Now -1 times B1 in the upper right block.

matrix.enter(B1, 0, 1, -1.);

We add the transpose of B2 to the upper right block and continue in a similar fashion. In the end, the block matrix structure is printed into an LaTeX table.

matrix.enter(B2, 0, 1, 1., true);
matrix.enter(B2, 1, 0, 1.);
matrix.enter(B1, 1, 0, -1., true);
matrix.enter(C, 1, 1);
matrix.print_latex(deallog);

Now, we set up vectors to be multiplied with this matrix and do a multiplication.

std::vector<unsigned int> block_sizes(2);
block_sizes[0] = 4;
block_sizes[1] = 2;
BlockVector<double> result(block_sizes);
BlockVector<double> x(block_sizes);
BlockVector<double> y(block_sizes);
for (unsigned int i = 0; i < result.size(); ++i)
result(i) = i;
matrix.vmult(y, result);

Finally, we solve a linear system with BlockMatrixArray, using no preconditioning and the conjugate gradient method.

SolverControl control(100, 1.e-10);
cg.solve(matrix, x, y, id);
x.add(-1., result);
deallog << "Error " << x.l2_norm() << std::endl;

The remaining code of this sample program concerns preconditioning and is described in the documentation of BlockTrianglePrecondition.

Deprecated:
This class has been superseded by BlockLinearOperator.
See also
Block (linear algebra)
Author
Guido Kanschat
Date
2000-2005, 2010

Definition at line 118 of file block_matrix_array.h.


The documentation for this class was generated from the following files:
SolverCG
Definition: solver_cg.h:96
BlockVector
Definition: block_linear_operator.h:41
Physics::Elasticity::Kinematics::C
SymmetricTensor< 2, dim, Number > C(const Tensor< 2, dim, Number > &F)
PreconditionIdentity
Definition: precondition.h:78
LAPACKSupport::matrix
Contents is actually a matrix.
Definition: lapack_support.h:60
FullMatrix< float >
SolverControl
Definition: solver_control.h:65
BlockMatrixArray
Definition: block_matrix_array.h:118