From: wolf Date: Wed, 24 May 2000 10:43:56 +0000 (+0000) Subject: Implement residual for block matrices. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac9bcb550ddb1ac70a4b03b0bc7cc8c2687a94ea;p=dealii-svn.git Implement residual for block matrices. git-svn-id: https://svn.dealii.org/trunk@2931 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/block_sparse_matrix.h b/deal.II/lac/include/lac/block_sparse_matrix.h index 6abdfc39a0..9512228649 100644 --- a/deal.II/lac/include/lac/block_sparse_matrix.h +++ b/deal.II/lac/include/lac/block_sparse_matrix.h @@ -368,6 +368,21 @@ class BlockSparseMatrix : public Subscriptor matrix_scalar_product (const BlockVector &u, const BlockVector &v) const; + /** + * Compute the residual of an + * equation #Ax=b#, where the + * residual is defined to be + * #r=b-Ax# with #x# typically + * being an approximate of the + * true solution of the + * equation. Write the residual + * into #dst#. + */ + template + somenumber residual (BlockVector &dst, + const BlockVector &x, + const BlockVector &b) const; + /** * Return a (constant) reference * to the underlying sparsity @@ -649,6 +664,53 @@ matrix_scalar_product (const BlockVector &u, +template +template +somenumber +BlockSparseMatrix:: +residual (BlockVector &dst, + const BlockVector &x, + const BlockVector &b) const +{ + // in block notation, the residual is + // #r_i = b_i - \sum_j A_ij x_j#. + // this can be written as + // #r_i = b_i - A_i0 x_0 - \sum_{j>0} A_ij x_j#. + // + // for the first two terms, we can + // call the residual function of + // A_i0. for the other terms, we + // use vmult_add. however, we want + // to subtract, so in order to + // avoid a temporary vector, we + // perform a sign change of the + // first two term before, and after + // adding up + for (unsigned int row=0; row &sparsity) }; + template void BlockSparseMatrix::clear ()