From cad0be1ff5904ae11b35c80f00316e288ab3e2bd Mon Sep 17 00:00:00 2001 From: guido Date: Thu, 1 Apr 2004 06:59:54 +0000 Subject: [PATCH] SparseMatrix operates on BlockVector git-svn-id: https://svn.dealii.org/trunk@8934 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/c-4-0.html | 7 +++ deal.II/lac/include/lac/sparse_matrix.h | 46 +++++++++--------- .../lac/include/lac/sparse_matrix.templates.h | 48 +++++++++---------- deal.II/lac/source/sparse_matrix.double.cc | 3 +- deal.II/lac/source/sparse_matrix.float.cc | 3 +- deal.II/lac/source/sparse_matrix_vector.in.h | 23 +++++---- 6 files changed, 73 insertions(+), 57 deletions(-) diff --git a/deal.II/doc/news/c-4-0.html b/deal.II/doc/news/c-4-0.html index 0e2b98131e..5693a2465b 100644 --- a/deal.II/doc/news/c-4-0.html +++ b/deal.II/doc/news/c-4-0.html @@ -368,6 +368,13 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK

lac

    +
  1. Improved: The matrix-vector operations of SparseMatrix accept arguments of type BlockVector. +
    + (GK/2004/03/31) +

    +
  2. Fixed: The SparseMatrix iterator classes had various interesting bugs when rows of the matrix were completely empty. These should now be fixed. diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index 13bd6003f5..fe253ae393 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -370,18 +370,20 @@ namespace internals } } +//TODO: Add multithreading to the other vmult functions. /** - * Sparse matrix. This class implements the function to store values in the - * locations of a sparse matrix denoted by a @ref SparsityPattern. The - * separation of sparsity pattern and values is done since one can store data - * elements of different type in these locations without the SparsityPattern - * having to know this, and more importantly one can associate more than one - * matrix with the same sparsity pattern. + * Sparse matrix. This class implements the function to store values + * in the locations of a sparse matrix denoted by a + * SparsityPattern. The separation of sparsity pattern and values is + * done since one can store data elements of different type in these + * locations without the SparsityPattern having to know this, and more + * importantly one can associate more than one matrix with the same + * sparsity pattern. * * @ref Instantiations some - * @author several, 1994-2003 + * @author several, 1994-2004 */ template class SparseMatrix : public virtual Subscriptor @@ -907,9 +909,9 @@ class SparseMatrix : public virtual Subscriptor * Source and destination must * not be the same vector. */ - template - void vmult (Vector &dst, - const Vector &src) const; + template + void vmult (OutVector& dst, + const InVector& src) const; /** * Matrix-vector multiplication: @@ -922,9 +924,9 @@ class SparseMatrix : public virtual Subscriptor * Source and destination must * not be the same vector. */ - template - void Tvmult (Vector &dst, - const Vector &src) const; + template + void Tvmult (OutVector& dst, + const InVector& src) const; /** * Adding Matrix-vector @@ -936,9 +938,9 @@ class SparseMatrix : public virtual Subscriptor * Source and destination must * not be the same vector. */ - template - void vmult_add (Vector &dst, - const Vector &src) const; + template + void vmult_add (OutVector& dst, + const InVector& src) const; /** * Adding Matrix-vector @@ -953,9 +955,9 @@ class SparseMatrix : public virtual Subscriptor * Source and destination must * not be the same vector. */ - template - void Tvmult_add (Vector &dst, - const Vector &src) const; + template + void Tvmult_add (OutVector& dst, + const InVector& src) const; /** * Return the square of the norm @@ -1508,9 +1510,9 @@ class SparseMatrix : public virtual Subscriptor * in the case of enabled * multithreading. */ - template - void threaded_vmult (Vector &dst, - const Vector &src, + template + void threaded_vmult (OutVector& dst, + const InVector& src, const unsigned int begin_row, const unsigned int end_row) const; diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index a7d25e4326..0a3547f79b 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -277,10 +277,10 @@ SparseMatrix::add_scaled (const number factor, template -template +template void -SparseMatrix::vmult (Vector& dst, - const Vector& src) const +SparseMatrix::vmult (OutVector& dst, + const InVector& src) const { Assert (cols != 0, ExcMatrixNotInitialized()); Assert (val != 0, ExcMatrixNotInitialized()); @@ -314,13 +314,13 @@ SparseMatrix::vmult (Vector& dst, // correct type right away: typedef void (SparseMatrix::*mem_fun_p) - (Vector &, - const Vector &, + (OutVector &, + const InVector &, const unsigned int , const unsigned int) const; const mem_fun_p comp = (&SparseMatrix:: - template threaded_vmult); + template threaded_vmult); Threads::ThreadGroup<> threads; for (unsigned int i=0; i::vmult (Vector& dst, // do it in an oldfashioned way const number *val_ptr = &val[cols->rowstart[0]]; const unsigned int *colnum_ptr = &cols->colnums[cols->rowstart[0]]; - somenumber *dst_ptr = &dst(0); + typename OutVector::iterator dst_ptr = dst.begin(); for (unsigned int row=0; rowrowstart[row+1]]; while (val_ptr != val_end_of_row) s += *val_ptr++ * src(*colnum_ptr++); @@ -350,10 +350,10 @@ SparseMatrix::vmult (Vector& dst, template -template +template void -SparseMatrix::threaded_vmult (Vector &dst, - const Vector &src, +SparseMatrix::threaded_vmult (OutVector &dst, + const InVector &src, const unsigned int begin_row, const unsigned int end_row) const { @@ -363,10 +363,10 @@ SparseMatrix::threaded_vmult (Vector &dst, const number *val_ptr = &val[cols->rowstart[begin_row]]; const unsigned int *colnum_ptr = &cols->colnums[cols->rowstart[begin_row]]; - somenumber *dst_ptr = &dst(begin_row); + typename OutVector::iterator dst_ptr = dst.begin() + begin_row; for (unsigned int row=begin_row; rowrowstart[row+1]]; while (val_ptr != val_end_of_row) s += *val_ptr++ * src(*colnum_ptr++); @@ -376,10 +376,10 @@ SparseMatrix::threaded_vmult (Vector &dst, template -template +template void -SparseMatrix::Tvmult (Vector& dst, - const Vector& src) const +SparseMatrix::Tvmult (OutVector& dst, + const InVector& src) const { Assert (val != 0, ExcMatrixNotInitialized()); Assert (cols != 0, ExcMatrixNotInitialized()); @@ -402,10 +402,10 @@ SparseMatrix::Tvmult (Vector& dst, template -template +template void -SparseMatrix::vmult_add (Vector& dst, - const Vector& src) const +SparseMatrix::vmult_add (OutVector& dst, + const InVector& src) const { Assert (cols != 0, ExcMatrixNotInitialized()); Assert (val != 0, ExcMatrixNotInitialized()); @@ -417,10 +417,10 @@ SparseMatrix::vmult_add (Vector& dst, const unsigned int n_rows = m(); const number *val_ptr = &val[cols->rowstart[0]]; const unsigned int *colnum_ptr = &cols->colnums[cols->rowstart[0]]; - somenumber *dst_ptr = &dst(0); + typename OutVector::iterator dst_ptr = dst.begin(); for (unsigned int row=0; rowrowstart[row+1]]; while (val_ptr != val_end_of_row) s += *val_ptr++ * src(*colnum_ptr++); @@ -430,10 +430,10 @@ SparseMatrix::vmult_add (Vector& dst, template -template +template void -SparseMatrix::Tvmult_add (Vector& dst, - const Vector& src) const +SparseMatrix::Tvmult_add (OutVector& dst, + const InVector& src) const { Assert (val != 0, ExcMatrixNotInitialized()); Assert (cols != 0, ExcMatrixNotInitialized()); diff --git a/deal.II/lac/source/sparse_matrix.double.cc b/deal.II/lac/source/sparse_matrix.double.cc index 67a3b2b192..62a5533d77 100644 --- a/deal.II/lac/source/sparse_matrix.double.cc +++ b/deal.II/lac/source/sparse_matrix.double.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -13,6 +13,7 @@ #include +#include #define TYPEMAT double diff --git a/deal.II/lac/source/sparse_matrix.float.cc b/deal.II/lac/source/sparse_matrix.float.cc index 7aae94aac1..05c6bd3a74 100644 --- a/deal.II/lac/source/sparse_matrix.float.cc +++ b/deal.II/lac/source/sparse_matrix.float.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -13,6 +13,7 @@ #include +#include #define TYPEMAT float diff --git a/deal.II/lac/source/sparse_matrix_vector.in.h b/deal.II/lac/source/sparse_matrix_vector.in.h index c30794a372..cdd09856da 100644 --- a/deal.II/lac/source/sparse_matrix_vector.in.h +++ b/deal.II/lac/source/sparse_matrix_vector.in.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -17,17 +17,22 @@ // TYPEMAT and TYPEVEC are defined in sparsematrix?.cc template void SparseMatrix:: -vmult (Vector &, - const Vector &) const; +vmult (Vector &, const Vector &) const; template void SparseMatrix:: -Tvmult (Vector &, - const Vector &) const; +Tvmult (Vector &, const Vector &) const; template void SparseMatrix:: -vmult_add (Vector &, - const Vector &) const; +vmult_add (Vector &, const Vector &) const; template void SparseMatrix:: -Tvmult_add (Vector &, - const Vector &) const; +Tvmult_add (Vector &, const Vector &) const; + +template void SparseMatrix:: +vmult (BlockVector &, const BlockVector &) const; +template void SparseMatrix:: +Tvmult (BlockVector &, const BlockVector &) const; +template void SparseMatrix:: +vmult_add (BlockVector &, const BlockVector &) const; +template void SparseMatrix:: +Tvmult_add (BlockVector &, const BlockVector &) const; template TYPEVEC SparseMatrix:: -- 2.39.5