From 22205f304e87f77d40487506e9f4380c5f54115c Mon Sep 17 00:00:00 2001 From: wolf Date: Mon, 12 Jul 2004 18:18:25 +0000 Subject: [PATCH] Undo Guido's changes. Use a better way to disambiguate which vmult function is used by moving them to the derived classes, and providing for unambiguous names in the base class. git-svn-id: https://svn.dealii.org/trunk@9515 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/block_matrix_base.h | 322 ++++++++++++------ deal.II/lac/include/lac/block_sparse_matrix.h | 189 ++++++++++ .../include/lac/petsc_block_sparse_matrix.h | 159 +++++++++ .../lac/petsc_parallel_block_sparse_matrix.h | 160 +++++++++ 4 files changed, 717 insertions(+), 113 deletions(-) diff --git a/deal.II/lac/include/lac/block_matrix_base.h b/deal.II/lac/include/lac/block_matrix_base.h index b3132ff106..919bbd5179 100644 --- a/deal.II/lac/include/lac/block_matrix_base.h +++ b/deal.II/lac/include/lac/block_matrix_base.h @@ -18,7 +18,6 @@ #include #include #include -#include #include @@ -488,99 +487,8 @@ class BlockMatrixBase : public Subscriptor */ template void add_scaled (const value_type factor, - const BlockMatrixType &matrix); - - /** - * Matrix-vector multiplication: - * let $dst = M*src$ with $M$ - * being this matrix. - */ - template - void vmult (BlockVectorType &dst, - const BlockVectorType &src) const; - - /** - * Matrix-vector - * multiplication. Just like the - * previous function, but only - * applicable if the matrix has - * only one block column. - */ - template - void vmult (BlockVectorType &dst, - const VectorType &src) const; - - /** - * Matrix-vector - * multiplication. Just like the - * previous function, but only - * applicable if the matrix has - * only one block row. - */ - template - void vmult (VectorType &dst, - const BlockVectorType &src) const; - - /** - * Matrix-vector - * multiplication. Just like the - * previous function, but only - * applicable if the matrix has - * only one block. - */ - template - void vmult (Vector &dst, - const Vector &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 (BlockVectorType &dst, - const BlockVectorType &src) const; + const BlockMatrixType &matrix); - /** - * Matrix-vector - * multiplication. Just like the - * previous function, but only - * applicable if the matrix has - * only one block row. - */ - template - void Tvmult (BlockVectorType &dst, - const VectorType &src) const; - - /** - * Matrix-vector - * multiplication. Just like the - * previous function, but only - * applicable if the matrix has - * only one block column. - */ - template - void Tvmult (VectorType &dst, - const BlockVectorType &src) const; - - /** - * Matrix-vector - * multiplication. Just like the - * previous function, but only - * applicable if the matrix has - * only one block. - */ - template - void Tvmult (Vector &dst, - const Vector &src) const; - /** * Adding Matrix-vector * multiplication. Add $M*src$ on @@ -604,8 +512,8 @@ class BlockMatrixBase : public Subscriptor template void Tvmult_add (BlockVectorType &dst, const BlockVectorType &src) const; - - /** + + /** * Return the norm of the vector * v with respect to the * norm induced by this matrix, @@ -768,6 +676,186 @@ class BlockMatrixBase : public Subscriptor * therefore export this function. */ void collect_sizes (); + + /** + * Matrix-vector multiplication: + * let $dst = M*src$ with $M$ + * being this matrix. + * + * Due to problems with deriving template + * arguments between the block and + * non-block versions of the vmult/Tvmult + * functions, the actual functions are + * implemented in derived classes, with + * implementations forwarding the calls + * to the implementations provided here + * under a unique name for which template + * arguments can be derived by the + * compiler. + */ + template + void vmult_block_block (BlockVectorType &dst, + const BlockVectorType &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block column. + * + * Due to problems with deriving template + * arguments between the block and + * non-block versions of the vmult/Tvmult + * functions, the actual functions are + * implemented in derived classes, with + * implementations forwarding the calls + * to the implementations provided here + * under a unique name for which template + * arguments can be derived by the + * compiler. + */ + template + void vmult_block_nonblock (BlockVectorType &dst, + const VectorType &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block row. + * + * Due to problems with deriving template + * arguments between the block and + * non-block versions of the vmult/Tvmult + * functions, the actual functions are + * implemented in derived classes, with + * implementations forwarding the calls + * to the implementations provided here + * under a unique name for which template + * arguments can be derived by the + * compiler. + */ + template + void vmult_nonblock_block (VectorType &dst, + const BlockVectorType &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block. + * + * Due to problems with deriving template + * arguments between the block and + * non-block versions of the vmult/Tvmult + * functions, the actual functions are + * implemented in derived classes, with + * implementations forwarding the calls + * to the implementations provided here + * under a unique name for which template + * arguments can be derived by the + * compiler. + */ + template + void vmult_nonblock_nonblock (VectorType &dst, + const VectorType &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. + * + * Due to problems with deriving template + * arguments between the block and + * non-block versions of the vmult/Tvmult + * functions, the actual functions are + * implemented in derived classes, with + * implementations forwarding the calls + * to the implementations provided here + * under a unique name for which template + * arguments can be derived by the + * compiler. + */ + template + void Tvmult_block_block (BlockVectorType &dst, + const BlockVectorType &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block row. + * + * Due to problems with deriving template + * arguments between the block and + * non-block versions of the vmult/Tvmult + * functions, the actual functions are + * implemented in derived classes, with + * implementations forwarding the calls + * to the implementations provided here + * under a unique name for which template + * arguments can be derived by the + * compiler. + */ + template + void Tvmult_block_nonblock (BlockVectorType &dst, + const VectorType &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block column. + * + * Due to problems with deriving template + * arguments between the block and + * non-block versions of the vmult/Tvmult + * functions, the actual functions are + * implemented in derived classes, with + * implementations forwarding the calls + * to the implementations provided here + * under a unique name for which template + * arguments can be derived by the + * compiler. + */ + template + void Tvmult_nonblock_block (VectorType &dst, + const BlockVectorType &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block. + * + * Due to problems with deriving template + * arguments between the block and + * non-block versions of the vmult/Tvmult + * functions, the actual functions are + * implemented in derived classes, with + * implementations forwarding the calls + * to the implementations provided here + * under a unique name for which template + * arguments can be derived by the + * compiler. + */ + template + void Tvmult_nonblock_nonblock (VectorType &dst, + const VectorType &src) const; + /** * Make the iterator class a @@ -1356,8 +1444,9 @@ add_scaled (const value_type factor, template template void -BlockMatrixBase::vmult (BlockVectorType &dst, - const BlockVectorType &src) const +BlockMatrixBase:: +vmult_block_block (BlockVectorType &dst, + const BlockVectorType &src) const { Assert (dst.n_blocks() == n_block_rows(), ExcDimensionMismatch(dst.n_blocks(), n_block_rows())); @@ -1380,8 +1469,9 @@ template template void -BlockMatrixBase::vmult (VectorType &dst, - const BlockVectorType &src) const +BlockMatrixBase:: +vmult_nonblock_block (VectorType &dst, + const BlockVectorType &src) const { Assert (n_block_rows() == 1, ExcDimensionMismatch(1, n_block_rows())); @@ -1399,8 +1489,9 @@ template template void -BlockMatrixBase::vmult (BlockVectorType &dst, - const VectorType &src) const +BlockMatrixBase:: +vmult_block_nonblock (BlockVectorType &dst, + const VectorType &src) const { Assert (dst.n_blocks() == n_block_rows(), ExcDimensionMismatch(dst.n_blocks(), n_block_rows())); @@ -1415,10 +1506,11 @@ BlockMatrixBase::vmult (BlockVectorType &dst, template -template +template void -BlockMatrixBase::vmult (Vector &dst, - const Vector &src) const +BlockMatrixBase:: +vmult_nonblock_nonblock (VectorType &dst, + const VectorType &src) const { Assert (1 == n_block_rows(), ExcDimensionMismatch(1, n_block_rows())); @@ -1457,8 +1549,9 @@ BlockMatrixBase::vmult_add (BlockVectorType &dst, template template void -BlockMatrixBase::Tvmult (BlockVectorType &dst, - const BlockVectorType &src) const +BlockMatrixBase:: +Tvmult_block_block (BlockVectorType &dst, + const BlockVectorType &src) const { Assert (dst.n_blocks() == n_block_cols(), ExcDimensionMismatch(dst.n_blocks(), n_block_cols())); @@ -1481,8 +1574,9 @@ template template void -BlockMatrixBase::Tvmult (BlockVectorType &dst, - const VectorType &src) const +BlockMatrixBase:: +Tvmult_block_nonblock (BlockVectorType &dst, + const VectorType &src) const { Assert (dst.n_blocks() == n_block_cols(), ExcDimensionMismatch(dst.n_blocks(), n_block_cols())); @@ -1501,8 +1595,9 @@ template template void -BlockMatrixBase::Tvmult (VectorType &dst, - const BlockVectorType &src) const +BlockMatrixBase:: +Tvmult_nonblock_block (VectorType &dst, + const BlockVectorType &src) const { Assert (1 == n_block_cols(), ExcDimensionMismatch(1, n_block_cols())); @@ -1518,10 +1613,11 @@ BlockMatrixBase::Tvmult (VectorType &dst, template -template +template void -BlockMatrixBase::Tvmult (Vector &dst, - const Vector &src) const +BlockMatrixBase:: +Tvmult_nonblock_nonblock (VectorType &dst, + const VectorType &src) const { Assert (1 == n_block_cols(), ExcDimensionMismatch(1, n_block_cols())); diff --git a/deal.II/lac/include/lac/block_sparse_matrix.h b/deal.II/lac/include/lac/block_sparse_matrix.h index a4d9869d8b..0f6fa0b19a 100644 --- a/deal.II/lac/include/lac/block_sparse_matrix.h +++ b/deal.II/lac/include/lac/block_sparse_matrix.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -206,6 +207,97 @@ class BlockSparseMatrix : public BlockMatrixBase > */ unsigned int n_actually_nonzero_elements () 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. Just like the + * previous function, but only + * applicable if the matrix has + * only one block column. + */ + template + void vmult (BlockVector &dst, + const Vector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block row. + */ + template + void vmult (Vector &dst, + const BlockVector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block. + */ + template + void vmult (Vector &dst, + const Vector &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; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block row. + */ + template + void Tvmult (BlockVector &dst, + const Vector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block column. + */ + template + void Tvmult (Vector &dst, + const BlockVector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block. + */ + template + void Tvmult (Vector &dst, + const Vector &src) const; + /** * Apply the Jacobi * preconditioner, which @@ -333,6 +425,103 @@ class BlockSparseMatrix : public BlockMatrixBase > +template +template +inline +void +BlockSparseMatrix::vmult (BlockVector &dst, + const BlockVector &src) const +{ + BaseClass::vmult_block_block (dst, src); +} + + + +template +template +inline +void +BlockSparseMatrix::vmult (BlockVector &dst, + const Vector &src) const +{ + BaseClass::vmult_block_nonblock (dst, src); +} + + + +template +template +inline +void +BlockSparseMatrix::vmult (Vector &dst, + const BlockVector &src) const +{ + BaseClass::vmult_nonblock_block (dst, src); +} + + + +template +template +inline +void +BlockSparseMatrix::vmult (Vector &dst, + const Vector &src) const +{ + BaseClass::vmult_nonblock_nonblock (dst, src); +} + + +template +template +inline +void +BlockSparseMatrix::Tvmult (BlockVector &dst, + const BlockVector &src) const +{ + BaseClass::Tvmult_block_block (dst, src); +} + + + +template +template +inline +void +BlockSparseMatrix::Tvmult (BlockVector &dst, + const Vector &src) const +{ + BaseClass::Tvmult_block_nonblock (dst, src); +} + + + +template +template +inline +void +BlockSparseMatrix::Tvmult (Vector &dst, + const BlockVector &src) const +{ + BaseClass::Tvmult_nonblock_block (dst, src); +} + + + +template +template +inline +void +BlockSparseMatrix::Tvmult (Vector &dst, + const Vector &src) const +{ + BaseClass::Tvmult_nonblock_nonblock (dst, src); +} + template template diff --git a/deal.II/lac/include/lac/petsc_block_sparse_matrix.h b/deal.II/lac/include/lac/petsc_block_sparse_matrix.h index 8b296e457f..d12c1d5b0c 100644 --- a/deal.II/lac/include/lac/petsc_block_sparse_matrix.h +++ b/deal.II/lac/include/lac/petsc_block_sparse_matrix.h @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -163,6 +164,84 @@ namespace PETScWrappers void reinit (const unsigned int n_block_rows, const unsigned int n_block_columns); + /** + * Matrix-vector multiplication: + * let $dst = M*src$ with $M$ + * being this matrix. + */ + void vmult (BlockVector &dst, + const BlockVector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block column. + */ + void vmult (BlockVector &dst, + const Vector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block row. + */ + void vmult (Vector &dst, + const BlockVector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block. + */ + void vmult (Vector &dst, + const Vector &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. + */ + void Tvmult (BlockVector &dst, + const BlockVector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block row. + */ + void Tvmult (BlockVector &dst, + const Vector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block column. + */ + void Tvmult (Vector &dst, + const BlockVector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block. + */ + void Tvmult (Vector &dst, + const Vector &src) const; /** * This function collects the @@ -204,6 +283,86 @@ namespace PETScWrappers /*@}*/ + +// ------------- inline and template functions ----------------- + + inline + void + BlockSparseMatrix::vmult (BlockVector &dst, + const BlockVector &src) const + { + BaseClass::vmult_block_block (dst, src); + } + + + + inline + void + BlockSparseMatrix::vmult (BlockVector &dst, + const Vector &src) const + { + BaseClass::vmult_block_nonblock (dst, src); + } + + + + inline + void + BlockSparseMatrix::vmult (Vector &dst, + const BlockVector &src) const + { + BaseClass::vmult_nonblock_block (dst, src); + } + + + + inline + void + BlockSparseMatrix::vmult (Vector &dst, + const Vector &src) const + { + BaseClass::vmult_nonblock_nonblock (dst, src); + } + + + inline + void + BlockSparseMatrix::Tvmult (BlockVector &dst, + const BlockVector &src) const + { + BaseClass::Tvmult_block_block (dst, src); + } + + + + inline + void + BlockSparseMatrix::Tvmult (BlockVector &dst, + const Vector &src) const + { + BaseClass::Tvmult_block_nonblock (dst, src); + } + + + + inline + void + BlockSparseMatrix::Tvmult (Vector &dst, + const BlockVector &src) const + { + BaseClass::Tvmult_nonblock_block (dst, src); + } + + + + inline + void + BlockSparseMatrix::Tvmult (Vector &dst, + const Vector &src) const + { + BaseClass::Tvmult_nonblock_nonblock (dst, src); + } + } diff --git a/deal.II/lac/include/lac/petsc_parallel_block_sparse_matrix.h b/deal.II/lac/include/lac/petsc_parallel_block_sparse_matrix.h index daf5c5168b..4cea47c377 100644 --- a/deal.II/lac/include/lac/petsc_parallel_block_sparse_matrix.h +++ b/deal.II/lac/include/lac/petsc_parallel_block_sparse_matrix.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #ifdef DEAL_II_USE_PETSC @@ -166,6 +167,85 @@ namespace PETScWrappers void reinit (const unsigned int n_block_rows, const unsigned int n_block_columns); + /** + * Matrix-vector multiplication: + * let $dst = M*src$ with $M$ + * being this matrix. + */ + void vmult (BlockVector &dst, + const BlockVector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block column. + */ + void vmult (BlockVector &dst, + const Vector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block row. + */ + void vmult (Vector &dst, + const BlockVector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block. + */ + void vmult (Vector &dst, + const Vector &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. + */ + void Tvmult (BlockVector &dst, + const BlockVector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block row. + */ + void Tvmult (BlockVector &dst, + const Vector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block column. + */ + void Tvmult (Vector &dst, + const BlockVector &src) const; + + /** + * Matrix-vector + * multiplication. Just like the + * previous function, but only + * applicable if the matrix has + * only one block. + */ + void Tvmult (Vector &dst, + const Vector &src) const; + /** * This function collects the * sizes of the sub-objects and @@ -198,6 +278,86 @@ namespace PETScWrappers /*@}*/ + +// ------------- inline and template functions ----------------- + + inline + void + BlockSparseMatrix::vmult (BlockVector &dst, + const BlockVector &src) const + { + BaseClass::vmult_block_block (dst, src); + } + + + + inline + void + BlockSparseMatrix::vmult (BlockVector &dst, + const Vector &src) const + { + BaseClass::vmult_block_nonblock (dst, src); + } + + + + inline + void + BlockSparseMatrix::vmult (Vector &dst, + const BlockVector &src) const + { + BaseClass::vmult_nonblock_block (dst, src); + } + + + + inline + void + BlockSparseMatrix::vmult (Vector &dst, + const Vector &src) const + { + BaseClass::vmult_nonblock_nonblock (dst, src); + } + + + inline + void + BlockSparseMatrix::Tvmult (BlockVector &dst, + const BlockVector &src) const + { + BaseClass::Tvmult_block_block (dst, src); + } + + + + inline + void + BlockSparseMatrix::Tvmult (BlockVector &dst, + const Vector &src) const + { + BaseClass::Tvmult_block_nonblock (dst, src); + } + + + + inline + void + BlockSparseMatrix::Tvmult (Vector &dst, + const BlockVector &src) const + { + BaseClass::Tvmult_nonblock_block (dst, src); + } + + + + inline + void + BlockSparseMatrix::Tvmult (Vector &dst, + const Vector &src) const + { + BaseClass::Tvmult_nonblock_nonblock (dst, src); + } + } } -- 2.39.5