From def5506b19f2764803743a2b304fac2dd754385e Mon Sep 17 00:00:00 2001 From: kronbichler Date: Wed, 15 Oct 2008 14:36:39 +0000 Subject: [PATCH] Update block matrix residual. git-svn-id: https://svn.dealii.org/trunk@17221 0785d39b-7218-0410-832d-ea1e28bc413d --- .../lac/trilinos_block_sparse_matrix.h | 203 +++++++++++++----- .../source/trilinos_block_sparse_matrix.cc | 102 +++++++++ .../lac/source/trilinos_precondition_block.cc | 2 +- 3 files changed, 257 insertions(+), 50 deletions(-) diff --git a/deal.II/lac/include/lac/trilinos_block_sparse_matrix.h b/deal.II/lac/include/lac/trilinos_block_sparse_matrix.h index afb5e31cc3..661f6b6d98 100644 --- a/deal.II/lac/include/lac/trilinos_block_sparse_matrix.h +++ b/deal.II/lac/include/lac/trilinos_block_sparse_matrix.h @@ -28,6 +28,8 @@ #ifdef DEAL_II_USE_TRILINOS +# define TrilinosScalar double + DEAL_II_NAMESPACE_OPEN @@ -338,20 +340,8 @@ namespace TrilinosWrappers * applicable if the matrix has * only one block. */ - void vmult (MPI::Vector &dst, - const MPI::Vector &src) const; - - /** - * Matrix-vector - * multiplication. Just like the - * previous function, but only - * applicable if the matrix has - * only one block, now applied to - * localized vectors (works only - * when run on one processor). - */ - void vmult (Vector &dst, - const Vector &src) const; + void vmult (VectorBase &dst, + const VectorBase &src) const; /** * Matrix-vector multiplication: @@ -431,21 +421,156 @@ namespace TrilinosWrappers * applicable if the matrix has * only one block. */ - void Tvmult (MPI::Vector &dst, - const MPI::Vector &src) const; + void Tvmult (VectorBase &dst, + const VectorBase &src) const; /** - * Matrix-vector - * multiplication. Just like the + * Compute the residual of an + * equation Mx=b, where + * the residual is defined to + * be r=b-Mx. Write the + * residual into @p dst. The + * l2 norm of + * the residual vector is + * returned. + * + * Source x and + * destination dst must + * not be the same vector. + * + * Note that both vectors have + * to be distributed vectors + * generated using the same Map + * as was used for the matrix + * in case you work on a + * distributed memory + * architecture, using the + * interface in the + * TrilinosWrappers::MPI::BlockVector + * class. + */ + TrilinosScalar residual (MPI::BlockVector &dst, + const MPI::BlockVector &x, + const MPI::BlockVector &b) const; + + /** + * Compute the residual of an + * equation Mx=b, where + * the residual is defined to + * be r=b-Mx. Write the + * residual into @p dst. The + * l2 norm of + * the residual vector is + * returned. + * + * Source x and + * destination dst must + * not be the same vector. + * + * Note that both vectors have + * to be distributed vectors + * generated using the same Map + * as was used for the matrix + * in case you work on a + * distributed memory + * architecture, using the + * interface in the + * TrilinosWrappers::BlockVector + * class. Since the block + * matrix is in general + * distributed among processes, + * this function only works + * when running the program on + * one processor. + */ + TrilinosScalar residual (BlockVector &dst, + const BlockVector &x, + const BlockVector &b) const; + + /** + * Compute the residual of an + * equation Mx=b, where + * the residual is defined to + * be r=b-Mx. Write the + * residual into @p dst. The + * l2 norm of + * the residual vector is + * returned. Just like the * previous function, but only - * applicable if the matrix has - * only one block, now applied to - * localized Trilinos vectors - * (works only when run on one - * processor). + * applicable if the matrix + * only has one block row. */ - void Tvmult (Vector &dst, - const Vector &src) const; + TrilinosScalar residual (MPI::BlockVector &dst, + const MPI::Vector &x, + const MPI::BlockVector &b) const; + + /** + * Compute the residual of an + * equation Mx=b, where + * the residual is defined to + * be r=b-Mx. Write the + * residual into @p dst. The + * l2 norm of + * the residual vector is + * returned. Just like the + * previous function, but only + * applicable if the matrix + * only has one block row. + */ + TrilinosScalar residual (BlockVector &dst, + const Vector &x, + const BlockVector &b) const; + + /** + * Compute the residual of an + * equation Mx=b, where + * the residual is defined to + * be r=b-Mx. Write the + * residual into @p dst. The + * l2 norm of + * the residual vector is + * returned. Just like the + * previous function, but only + * applicable if the matrix + * only has one block column. + */ + TrilinosScalar residual (MPI::Vector &dst, + const MPI::BlockVector &x, + const MPI::Vector &b) const; + + /** + * Compute the residual of an + * equation Mx=b, where + * the residual is defined to + * be r=b-Mx. Write the + * residual into @p dst. The + * l2 norm of + * the residual vector is + * returned. Just like the + * previous function, but only + * applicable if the matrix + * only has one block column. + */ + TrilinosScalar residual (Vector &dst, + const BlockVector &x, + const Vector &b) const; + + /** + * Compute the residual of an + * equation Mx=b, where + * the residual is defined to + * be r=b-Mx. Write the + * residual into @p dst. The + * l2 norm of + * the residual vector is + * returned. Just like the + * previous function, but only + * applicable if the matrix + * only has one block. + */ + TrilinosScalar residual (VectorBase &dst, + const VectorBase &x, + const VectorBase &b) const; /** * Make the clear() function in the @@ -562,18 +687,8 @@ namespace TrilinosWrappers inline void - BlockSparseMatrix::vmult (MPI::Vector &dst, - const MPI::Vector &src) const - { - BaseClass::vmult_nonblock_nonblock (dst, src); - } - - - - inline - void - BlockSparseMatrix::vmult (Vector &dst, - const Vector &src) const + BlockSparseMatrix::vmult (VectorBase &dst, + const VectorBase &src) const { BaseClass::vmult_nonblock_nonblock (dst, src); } @@ -642,18 +757,8 @@ namespace TrilinosWrappers inline void - BlockSparseMatrix::Tvmult (MPI::Vector &dst, - const MPI::Vector &src) const - { - BaseClass::Tvmult_nonblock_nonblock (dst, src); - } - - - - inline - void - BlockSparseMatrix::Tvmult (Vector &dst, - const Vector &src) const + BlockSparseMatrix::Tvmult (VectorBase &dst, + const VectorBase &src) const { BaseClass::Tvmult_nonblock_nonblock (dst, src); } diff --git a/deal.II/lac/source/trilinos_block_sparse_matrix.cc b/deal.II/lac/source/trilinos_block_sparse_matrix.cc index 696845078d..0995b26e7b 100644 --- a/deal.II/lac/source/trilinos_block_sparse_matrix.cc +++ b/deal.II/lac/source/trilinos_block_sparse_matrix.cc @@ -224,6 +224,108 @@ namespace TrilinosWrappers return n_nonzero; } + + + TrilinosScalar + BlockSparseMatrix::residual (MPI::BlockVector &dst, + const MPI::BlockVector &x, + const MPI::BlockVector &b) const + { + vmult (dst, x); + dst -= b; + dst *= -1.; + + return dst.l2_norm(); + } + + + + // TODO: In the following we + // use the same code as just + // above six more times. Use + // templates. + TrilinosScalar + BlockSparseMatrix::residual (BlockVector &dst, + const BlockVector &x, + const BlockVector &b) const + { + vmult (dst, x); + dst -= b; + dst *= -1.; + + return dst.l2_norm(); + } + + + + TrilinosScalar + BlockSparseMatrix::residual (MPI::BlockVector &dst, + const MPI::Vector &x, + const MPI::BlockVector &b) const + { + vmult (dst, x); + dst -= b; + dst *= -1.; + + return dst.l2_norm(); + } + + + + TrilinosScalar + BlockSparseMatrix::residual (BlockVector &dst, + const Vector &x, + const BlockVector &b) const + { + vmult (dst, x); + dst -= b; + dst *= -1.; + + return dst.l2_norm(); + } + + + + TrilinosScalar + BlockSparseMatrix::residual (MPI::Vector &dst, + const MPI::BlockVector &x, + const MPI::Vector &b) const + { + vmult (dst, x); + dst -= b; + dst *= -1.; + + return dst.l2_norm(); + } + + + + TrilinosScalar + BlockSparseMatrix::residual (Vector &dst, + const BlockVector &x, + const Vector &b) const + { + vmult (dst, x); + dst -= b; + dst *= -1.; + + return dst.l2_norm(); + } + + + + TrilinosScalar + BlockSparseMatrix::residual (VectorBase &dst, + const VectorBase &x, + const VectorBase &b) const + { + vmult (dst, x); + dst -= b; + dst *= -1.; + + return dst.l2_norm(); + } + } diff --git a/deal.II/lac/source/trilinos_precondition_block.cc b/deal.II/lac/source/trilinos_precondition_block.cc index fe1c8a72fd..3a4c837400 100755 --- a/deal.II/lac/source/trilinos_precondition_block.cc +++ b/deal.II/lac/source/trilinos_precondition_block.cc @@ -87,7 +87,7 @@ namespace TrilinosWrappers *defaultPrec = &Teuchos::dyn_cast > (*PM); - (*defaultPrec).initializeRight(tmpP); + (*defaultPrec).initializeUnspecified(tmpP); } // Set up the solver. -- 2.39.5