From 8da515e2cc663b5cb8aeda73640c61c9c276611d Mon Sep 17 00:00:00 2001 From: wolf Date: Fri, 5 May 2000 16:23:52 +0000 Subject: [PATCH] Implement some of the linear algebra. git-svn-id: https://svn.dealii.org/trunk@2810 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/block_sparse_matrix.h | 182 ++++++++++++++++-- 1 file changed, 164 insertions(+), 18 deletions(-) diff --git a/deal.II/lac/include/lac/block_sparse_matrix.h b/deal.II/lac/include/lac/block_sparse_matrix.h index fad7bd4c61..9d40cafb81 100644 --- a/deal.II/lac/include/lac/block_sparse_matrix.h +++ b/deal.II/lac/include/lac/block_sparse_matrix.h @@ -258,6 +258,76 @@ class BlockSparseMatrix : public Subscriptor */ number operator () (const unsigned int i, const unsigned int j) const; + + /** + * Matrix-vector multiplication: + * let $dst = M*src$ with $M$ + * being this matrix. + */ + template + void vmult (BlockVector &dst, + const BlockVector &src) const; + + /** + * Matrix-vector multiplication: + * let $dst = M^T*src$ with $M$ + * being this matrix. This + * function does the same as + * #vmult# but takes the + * transposed matrix. + */ + template + void Tvmult (BlockVector &dst, + const BlockVector &src) const; + + /** + * Adding Matrix-vector + * multiplication. Add $M*src$ on + * $dst$ with $M$ being this + * matrix. + */ + template + void vmult_add (BlockVector &dst, + const BlockVector &src) const; + + /** + * Adding Matrix-vector + * multiplication. Add $M^T*src$ + * to $dst$ with $M$ being this + * matrix. This function does the + * same as #vmult_add# but takes + * the transposed matrix. + */ + template + void Tvmult_add (BlockVector &dst, + const BlockVector &src) const; + + /** + * Return the norm of the vector + * $v$ with respect to the norm + * induced by this matrix, + * i.e. $\left(v,Mv\right)$. This + * is useful, e.g. in the finite + * element context, where the + * $L_2$ norm of a function + * equals the matrix norm with + * respect to the mass matrix of + * the vector representing the + * nodal values of the finite + * element function. Note that + * even though the function's + * name might suggest something + * different, for historic + * reasons not the norm but its + * square is returned, as defined + * above by the scalar product. + * + * Obviously, the matrix needs to + * be square for this operation. + */ + template + somenumber matrix_norm (const BlockVector &v) const; + private: /** * Pointer to the block sparsity @@ -306,7 +376,7 @@ operator = (const BlockSparseMatrix &m) *sparsity_pattern = *m.sparsity_pattern; for (unsigned int r=0; r::reinit () { for (unsigned int r=0; r::reinit (const BlockSparsityPattern +template inline -SparseMatrix +SparseMatrix & BlockSparseMatrix::block (const unsigned int row, const unsigned int column) { + Assert (row +template inline const SparseMatrix & BlockSparseMatrix::block (const unsigned int row, const unsigned int column) const { + Assert (row::clear () sparsity_pattern = 0; for (unsigned int r=0; r::empty () const { for (unsigned int r=0; r::set (const unsigned int i, const pair row_index = sparsity_pattern->row_indices.global_to_local (i), col_index = sparsity_pattern->column_indices.global_to_local (j); - sub_objects[row_index.first][col_index.first].set (row_index.second, - col_index.second, - value); + block(row_index.first,col_index.first).set (row_index.second, + col_index.second, + value); }; @@ -435,9 +511,9 @@ BlockSparseMatrix::add (const unsigned int i, const pair row_index = sparsity_pattern->row_indices.global_to_local (i), col_index = sparsity_pattern->column_indices.global_to_local (j); - sub_objects[row_index.first][col_index.first].add (row_index.second, - col_index.second, - value); + block(row_index.first,col_index.first).add (row_index.second, + col_index.second, + value); }; @@ -450,7 +526,7 @@ copy_from (const BlockSparseMatrix &source) { for (unsigned int r=0; r::operator () (const unsigned int i, const pair row_index = sparsity_pattern->row_indices.global_to_local (i), col_index = sparsity_pattern->column_indices.global_to_local (j); - return sub_objects[row_index.first][col_index.first] (row_index.second, - col_index.second); + return block(row_index.first,col_index.first) (row_index.second, + col_index.second); +}; + + + +template +template +void +BlockSparseMatrix:: +vmult (BlockVector &dst, + const BlockVector &src) const +{ + for (unsigned int row=0; row +template +void +BlockSparseMatrix:: +vmult_add (BlockVector &dst, + const BlockVector &src) const +{ + for (unsigned int row=0; row +template +void +BlockSparseMatrix:: +Tvmult (BlockVector &/*dst*/, + const BlockVector &/*src*/) const +{ + // presently not + // implemented. should be simple, + // but don't have the time right + // now. + Assert (false, ExcNotImplemented()); }; +template +template +void +BlockSparseMatrix:: +Tvmult_add (BlockVector &/*dst*/, + const BlockVector &/*src*/) const +{ + // presently not + // implemented. should be simple, + // but don't have the time right + // now. + Assert (false, ExcNotImplemented()); +}; + + #endif // __deal2__block_sparse_matrix_h -- 2.39.5