From: Maien Hamed Date: Thu, 25 Jun 2015 12:35:56 +0000 (+0200) Subject: Added second template argument to BlockMatrixArray representing generic BlockVector X-Git-Tag: v8.3.0-rc1~86^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae5d234a0f9fcb7fd672e85bfbed1ffda36deb31;p=dealii.git Added second template argument to BlockMatrixArray representing generic BlockVector --- diff --git a/include/deal.II/lac/block_matrix_array.h b/include/deal.II/lac/block_matrix_array.h index 9cdc19c497..640d0e9921 100644 --- a/include/deal.II/lac/block_matrix_array.h +++ b/include/deal.II/lac/block_matrix_array.h @@ -31,9 +31,6 @@ DEAL_II_NAMESPACE_OPEN -template class BlockVector; -template class Vector; - /*! @addtogroup Matrix2 *@{ */ @@ -117,7 +114,7 @@ template class Vector; * @author Guido Kanschat * @date 2000-2005, 2010 */ -template +template > class BlockMatrixArray : public Subscriptor { public: @@ -165,7 +162,7 @@ public: void enter (const MATRIX &matrix, const unsigned int row, const unsigned int col, - const double prefix = 1., + const number prefix = 1., const bool transpose = false); /** @@ -186,39 +183,39 @@ public: /** * Matrix-vector multiplication. */ - void vmult (BlockVector &dst, - const BlockVector &src) const; + void vmult (BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const; /** * Matrix-vector multiplication adding to dst. */ - void vmult_add (BlockVector &dst, - const BlockVector &src) const; + void vmult_add(BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const; /** * Transposed matrix-vector multiplication. */ - void Tvmult (BlockVector &dst, - const BlockVector &src) const; + void Tvmult (BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const; /** * Transposed matrix-vector multiplication adding to dst. */ - void Tvmult_add (BlockVector &dst, - const BlockVector &src) const; + void Tvmult_add (BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const; /** * Matrix scalar product between two vectors (at least for a symmetric * matrix). */ - number matrix_scalar_product (const BlockVector &u, - const BlockVector &v) const; + number matrix_scalar_product (const BLOCK_VECTOR &u, + const BLOCK_VECTOR &v) const; /** * Compute $u^T M u$. This is the square of the norm induced by the matrix * assuming the matrix is symmetric positive definitive. */ - number matrix_norm_square (const BlockVector &u) const; + number matrix_norm_square (const BLOCK_VECTOR &u) const; /** * Print the block structure as a LaTeX-array. This output will not be very @@ -282,7 +279,7 @@ protected: template Entry (const MATRIX &matrix, size_type row, size_type col, - double prefix, bool transpose); + number prefix, bool transpose); /** * Copy constructor invalidating the old object. Since it is only used for @@ -312,7 +309,7 @@ protected: /** * Factor in front of the matrix block. */ - double prefix; + number prefix; /** * Indicates that matrix block must be transposed for multiplication. @@ -322,7 +319,7 @@ protected: /** * The matrix block itself. */ - PointerMatrixBase > *matrix; + PointerMatrixBase *matrix; }; /** @@ -398,9 +395,9 @@ private: * @ingroup Preconditioners * @author Guido Kanschat, 2001, 2005 */ -template +template > class BlockTrianglePrecondition - : private BlockMatrixArray + : private BlockMatrixArray { public: /** @@ -434,32 +431,32 @@ public: void enter (const MATRIX &matrix, const size_type row, const size_type col, - const double prefix = 1., + const number prefix = 1., const bool transpose = false); /** * Preconditioning. */ - void vmult (BlockVector &dst, - const BlockVector &src) const; + void vmult (BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const; /** * Preconditioning adding to dst. */ - void vmult_add (BlockVector &dst, - const BlockVector &src) const; + void vmult_add (BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const; /** * Transposed preconditioning */ - void Tvmult (BlockVector &dst, - const BlockVector &src) const; + void Tvmult (BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const; /** * Transposed preconditioning adding to dst. */ - void Tvmult_add (BlockVector &dst, - const BlockVector &src) const; + void Tvmult_add (BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const; /** * Make function of base class available. @@ -506,7 +503,7 @@ private: * Add all off-diagonal contributions and return the entry of the diagonal * element for one row. */ - void do_row (BlockVector &dst, + void do_row (BLOCK_VECTOR &dst, size_type row_num) const; /** @@ -519,34 +516,34 @@ private: #ifndef DOXYGEN //--------------------------------------------------------------------------- -template +template template inline -BlockMatrixArray::Entry::Entry ( +BlockMatrixArray::Entry::Entry ( const MATRIX &m, size_type row, size_type col, - double prefix, + number prefix, bool transpose) : row (row), col (col), prefix (prefix), transpose (transpose), - matrix (new_pointer_matrix_base(m, Vector(), typeid(*this).name())) + matrix (new_pointer_matrix_base(m, typename BLOCK_VECTOR::BlockType(), typeid(*this).name())) {} -template +template template inline void -BlockMatrixArray::enter ( +BlockMatrixArray::enter ( const MATRIX &matrix, unsigned int row, unsigned int col, - double prefix, + number prefix, bool transpose) { Assert(row::enter ( } -template +template template inline void -BlockMatrixArray::print_latex (STREAM &out) const +BlockMatrixArray::print_latex (STREAM &out) const { out << "\\begin{array}{" << std::string(n_block_cols(), 'c') @@ -567,7 +564,7 @@ BlockMatrixArray::print_latex (STREAM &out) const Table<2,std::string> array(n_block_rows(), n_block_cols()); - typedef std::map > *, std::string> NameMap; + typedef std::map *, std::string> NameMap; NameMap matrix_names; typename std::vector::const_iterator m = entries.begin(); @@ -580,7 +577,7 @@ BlockMatrixArray::print_latex (STREAM &out) const { std::pair x = matrix_names.insert( - std::pair >*, std::string> (m->matrix, + std::pair*, std::string> (m->matrix, std::string("M"))); std::ostringstream stream; stream << matrix_number++; @@ -618,15 +615,15 @@ BlockMatrixArray::print_latex (STREAM &out) const out << "\\end{array}" << std::endl; } -template +template template inline void -BlockTrianglePrecondition::enter (const MATRIX &matrix, +BlockTrianglePrecondition::enter (const MATRIX &matrix, size_type row, size_type col, - double prefix, bool transpose) + number prefix, bool transpose) { - BlockMatrixArray::enter(matrix, row, col, prefix, transpose); + BlockMatrixArray::enter(matrix, row, col, prefix, transpose); } diff --git a/include/deal.II/lac/pointer_matrix.h b/include/deal.II/lac/pointer_matrix.h index f4a5bac95c..6181ca95e9 100644 --- a/include/deal.II/lac/pointer_matrix.h +++ b/include/deal.II/lac/pointer_matrix.h @@ -32,9 +32,8 @@ template class SparseMatrix; template class BlockSparseMatrix; template class SparseMatrixEZ; template class BlockSparseMatrixEZ; -template class BlockMatrixArray; template class TridiagonalMatrix; - +template class BlockMatrixArray; /*! @addtogroup Matrix2 *@{ @@ -549,11 +548,11 @@ new_pointer_matrix_base(const BlockSparseMatrixEZ &matrix, const VECTOR * * @relates PointerMatrixBase @relates PointerMatrix */ -template -PointerMatrixBase > * -new_pointer_matrix_base(const BlockMatrixArray &matrix, const BlockVector &, const char *name = "PointerMatrix") +template > +PointerMatrixBase * +new_pointer_matrix_base(const BlockMatrixArray &matrix, const BLOCK_VECTOR &, const char *name = "PointerMatrix") { - return new PointerMatrix, BlockVector >(&matrix, name); + return new PointerMatrix, BlockVector >(&matrix, name); } diff --git a/source/lac/block_matrix_array.cc b/source/lac/block_matrix_array.cc index e5ac5df4db..edfe73058c 100644 --- a/source/lac/block_matrix_array.cc +++ b/source/lac/block_matrix_array.cc @@ -17,12 +17,13 @@ #include #include #include +#include DEAL_II_NAMESPACE_OPEN -template -BlockMatrixArray::Entry::Entry (const Entry &e) +template +BlockMatrixArray::Entry::Entry (const Entry &e) : row(e.row), col(e.col), @@ -36,25 +37,24 @@ BlockMatrixArray::Entry::Entry (const Entry &e) -template -BlockMatrixArray::Entry::~Entry () +template +BlockMatrixArray::Entry::~Entry () { if (matrix) delete matrix; } - -template -BlockMatrixArray::BlockMatrixArray () +template +BlockMatrixArray::BlockMatrixArray () : block_rows (0), block_cols (0) {} -template -BlockMatrixArray::BlockMatrixArray ( +template +BlockMatrixArray::BlockMatrixArray ( const unsigned int n_block_rows, const unsigned int n_block_cols) : block_rows (n_block_rows), @@ -62,9 +62,9 @@ BlockMatrixArray::BlockMatrixArray ( {} -template +template void -BlockMatrixArray::initialize ( +BlockMatrixArray::initialize ( const unsigned int n_block_rows, const unsigned int n_block_cols) { @@ -74,9 +74,9 @@ BlockMatrixArray::initialize ( -template +template void -BlockMatrixArray::reinit ( +BlockMatrixArray::reinit ( const unsigned int n_block_rows, const unsigned int n_block_cols) { @@ -87,27 +87,27 @@ BlockMatrixArray::reinit ( -template +template void -BlockMatrixArray::clear () +BlockMatrixArray::clear () { entries.clear(); } -template +template void -BlockMatrixArray::vmult_add (BlockVector &dst, - const BlockVector &src) const +BlockMatrixArray::vmult_add (BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const { - GrowingVectorMemory > mem; + GrowingVectorMemory mem; Assert (dst.n_blocks() == block_rows, ExcDimensionMismatch(dst.n_blocks(), block_rows)); Assert (src.n_blocks() == block_cols, ExcDimensionMismatch(src.n_blocks(), block_cols)); - typename VectorMemory >::Pointer p_aux(mem); - Vector &aux = *p_aux; + typename VectorMemory::Pointer p_aux(mem); + typename BLOCK_VECTOR::BlockType &aux = *p_aux; typename std::vector::const_iterator m = entries.begin(); typename std::vector::const_iterator end = entries.end(); @@ -126,10 +126,10 @@ BlockMatrixArray::vmult_add (BlockVector &dst, -template +template void -BlockMatrixArray::vmult (BlockVector &dst, - const BlockVector &src) const +BlockMatrixArray::vmult (BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const { dst = 0.; vmult_add (dst, src); @@ -138,12 +138,12 @@ BlockMatrixArray::vmult (BlockVector &dst, -template +template void -BlockMatrixArray::Tvmult_add (BlockVector &dst, - const BlockVector &src) const +BlockMatrixArray::Tvmult_add (BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const { - GrowingVectorMemory > mem; + GrowingVectorMemory mem; Assert (dst.n_blocks() == block_cols, ExcDimensionMismatch(dst.n_blocks(), block_cols)); Assert (src.n_blocks() == block_rows, @@ -152,8 +152,8 @@ BlockMatrixArray::Tvmult_add (BlockVector &dst, typename std::vector::const_iterator m = entries.begin(); typename std::vector::const_iterator end = entries.end(); - typename VectorMemory >::Pointer p_aux(mem); - Vector &aux = *p_aux; + typename VectorMemory::Pointer p_aux(mem); + typename BLOCK_VECTOR::BlockType &aux = *p_aux; for (; m != end ; ++m) { @@ -168,10 +168,10 @@ BlockMatrixArray::Tvmult_add (BlockVector &dst, -template +template void -BlockMatrixArray::Tvmult (BlockVector &dst, - const BlockVector &src) const +BlockMatrixArray::Tvmult (BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const { dst = 0.; Tvmult_add (dst, src); @@ -180,20 +180,20 @@ BlockMatrixArray::Tvmult (BlockVector &dst, -template +template number -BlockMatrixArray::matrix_scalar_product ( - const BlockVector &u, - const BlockVector &v) const +BlockMatrixArray::matrix_scalar_product ( + const BLOCK_VECTOR &u, + const BLOCK_VECTOR &v) const { - GrowingVectorMemory > mem; + GrowingVectorMemory mem; Assert (u.n_blocks() == block_rows, ExcDimensionMismatch(u.n_blocks(), block_rows)); Assert (v.n_blocks() == block_cols, ExcDimensionMismatch(v.n_blocks(), block_cols)); - typename VectorMemory >::Pointer p_aux(mem); - Vector &aux = *p_aux; + typename VectorMemory::Pointer p_aux(mem); + typename BLOCK_VECTOR::BlockType &aux = *p_aux; typename std::vector::const_iterator m; typename std::vector::const_iterator end = entries.end(); @@ -220,28 +220,28 @@ BlockMatrixArray::matrix_scalar_product ( -template +template number -BlockMatrixArray::matrix_norm_square ( - const BlockVector &u) const +BlockMatrixArray::matrix_norm_square ( + const BLOCK_VECTOR &u) const { return matrix_scalar_product(u,u); } -template +template unsigned int -BlockMatrixArray::n_block_rows () const +BlockMatrixArray::n_block_rows () const { return block_rows; } -template +template unsigned int -BlockMatrixArray::n_block_cols () const +BlockMatrixArray::n_block_cols () const { return block_cols; } @@ -250,47 +250,47 @@ BlockMatrixArray::n_block_cols () const //--------------------------------------------------------------------------- -template -BlockTrianglePrecondition::BlockTrianglePrecondition() - : BlockMatrixArray (), +template +BlockTrianglePrecondition::BlockTrianglePrecondition() + : BlockMatrixArray (), backward(false) {} -template -BlockTrianglePrecondition::BlockTrianglePrecondition( +template +BlockTrianglePrecondition::BlockTrianglePrecondition( const unsigned int block_rows) : - BlockMatrixArray (block_rows, block_rows), + BlockMatrixArray (block_rows, block_rows), backward(false) {} -template +template void -BlockTrianglePrecondition::reinit ( +BlockTrianglePrecondition::reinit ( const unsigned int n) { - BlockMatrixArray::reinit(n,n); + BlockMatrixArray::reinit(n,n); } -template +template void -BlockTrianglePrecondition::do_row ( - BlockVector &dst, +BlockTrianglePrecondition::do_row ( + BLOCK_VECTOR &dst, size_type row_num) const { - GrowingVectorMemory > mem; - typename std::vector::Entry>::const_iterator + GrowingVectorMemory mem; + typename std::vector::Entry>::const_iterator m = this->entries.begin(); - typename std::vector::Entry>::const_iterator + typename std::vector::Entry>::const_iterator end = this->entries.end(); - std::vector::Entry>::const_iterator> + std::vector::Entry>::const_iterator> diagonals; - typename VectorMemory >::Pointer p_aux(mem); - Vector &aux = *p_aux; + typename VectorMemory::Pointer p_aux(mem); + typename BLOCK_VECTOR::BlockType &aux = *p_aux; aux.reinit(dst.block(row_num), true); @@ -357,18 +357,18 @@ BlockTrianglePrecondition::do_row ( -template +template void -BlockTrianglePrecondition::vmult_add ( - BlockVector &dst, - const BlockVector &src) const +BlockTrianglePrecondition::vmult_add ( + BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const { Assert (dst.n_blocks() == n_block_rows(), ExcDimensionMismatch(dst.n_blocks(), n_block_rows())); Assert (src.n_blocks() == n_block_cols(), ExcDimensionMismatch(src.n_blocks(), n_block_cols())); - BlockVector aux; + BLOCK_VECTOR aux; aux.reinit(dst); vmult(aux, src); dst.add(aux); @@ -376,11 +376,11 @@ BlockTrianglePrecondition::vmult_add ( -template +template void -BlockTrianglePrecondition::vmult ( - BlockVector &dst, - const BlockVector &src) const +BlockTrianglePrecondition::vmult ( + BLOCK_VECTOR &dst, + const BLOCK_VECTOR &src) const { Assert (dst.n_blocks() == n_block_rows(), ExcDimensionMismatch(dst.n_blocks(), n_block_rows())); @@ -402,21 +402,21 @@ BlockTrianglePrecondition::vmult ( } -template +template void -BlockTrianglePrecondition::Tvmult ( - BlockVector &, - const BlockVector &) const +BlockTrianglePrecondition::Tvmult ( + BLOCK_VECTOR &, + const BLOCK_VECTOR &) const { Assert (false, ExcNotImplemented()); } -template +template void -BlockTrianglePrecondition::Tvmult_add ( - BlockVector &, - const BlockVector &) const +BlockTrianglePrecondition::Tvmult_add ( + BLOCK_VECTOR &, + const BLOCK_VECTOR &) const { Assert (false, ExcNotImplemented()); } @@ -426,4 +426,7 @@ template class BlockMatrixArray; template class BlockTrianglePrecondition; template class BlockTrianglePrecondition; +template class BlockMatrixArray; +template class BlockMatrixArray; + DEAL_II_NAMESPACE_CLOSE