From: guido Date: Wed, 8 Jan 2003 14:39:39 +0000 (+0000) Subject: MGMatrix and MGMatrixSelect in new file X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fedb2af3bd728920634a106c869aa75b54d1bfac;p=dealii-svn.git MGMatrix and MGMatrixSelect in new file git-svn-id: https://svn.dealii.org/trunk@6887 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/multigrid/mg_matrix.h b/deal.II/deal.II/include/multigrid/mg_matrix.h new file mode 100644 index 0000000000..16160b59ce --- /dev/null +++ b/deal.II/deal.II/include/multigrid/mg_matrix.h @@ -0,0 +1,297 @@ +//-------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2003 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//-------------------------------------------------------------------- +#ifndef __deal2__mg_matrix_h +#define __deal2__mg_matrix_h + +#include + +/** + * Multilevel matrix. This class implements the interface defined by + * @ref{MGMatrixBase}, using @ref{MGLevelObject} of an arbitrary + * matrix class. + * + * @author Guido Kanschat, 2002 + */ +template +class MGMatrix : public MGMatrixBase, + public SmartPointer > +{ + public: + /** + * Constructor. The argument is + * handed over to the + * @p{SmartPointer} constructor. + */ + MGMatrix (MGLevelObject* = 0); + + /** + * Matrix-vector-multiplication on + * a certain level. + */ + virtual void vmult(unsigned int level, VECTOR& dst, + const VECTOR& src) const; + + /** + * Adding matrix-vector-multiplication on + * a certain level. + */ + virtual void vmult_add(unsigned int level, VECTOR& dst, + const VECTOR& src) const; + + /** + * Transpose + * matrix-vector-multiplication on + * a certain level. + */ + virtual void Tvmult(unsigned int level, VECTOR& dst, + const VECTOR& src) const; + + /** + * Adding transpose + * matrix-vector-multiplication on + * a certain level. + */ + virtual void Tvmult_add(unsigned int level, VECTOR& dst, + const VECTOR& src) const; +}; + + +/** + * Multilevel matrix selecting from block matrices. This class + * implements the interface defined by @ref{MGMatrixBase}. The + * template parameter @p{MATRIX} should be a block matrix class like + * @ref{BlockSparseMatrix} or @p{BlockSparseMatrixEZ}. Then, this + * class stores a pointer to a @ref{MGLevelObject} of this matrix + * class. In each @p{vmult}, the block selected on initialization will + * be multiplied with the vector provided. + * + * @author Guido Kanschat, 2002 + */ +template +class MGMatrixSelect : public MGMatrixBase >, + public SmartPointer > +{ + public: + /** + * Constructor. @p{row} and + * @p{col} are the coordinate of + * the selected block. The other + * argument is handed over to the + * @p{SmartPointer} constructor. + */ + MGMatrixSelect (const unsigned int row = 0, + const unsigned int col = 0, + MGLevelObject* = 0); + + /** + * Select the block for + * multiplication. + */ + void select_block (const unsigned int row, + const unsigned int col); + + /** + * Matrix-vector-multiplication on + * a certain level. + */ + virtual void vmult(unsigned int level, Vector& dst, + const Vector& src) const; + + /** + * Adding matrix-vector-multiplication on + * a certain level. + */ + virtual void vmult_add(unsigned int level, Vector& dst, + const Vector& src) const; + + /** + * Transpose + * matrix-vector-multiplication on + * a certain level. + */ + virtual void Tvmult(unsigned int level, Vector& dst, + const Vector& src) const; + + /** + * Adding transpose + * matrix-vector-multiplication on + * a certain level. + */ + virtual void Tvmult_add(unsigned int level, Vector& dst, + const Vector& src) const; + + private: + /** + * Row coordinate of selected block. + */ + unsigned int row; + /** + * Column coordinate of selected block. + */ + unsigned int col; + +}; + + +/*----------------------------------------------------------------------*/ + +template +MGMatrix::MGMatrix (MGLevelObject* p) + : + SmartPointer > (p) +{} + + + +template +void +MGMatrix::vmult (unsigned int level, + VECTOR& dst, + const VECTOR& src) const +{ + Assert((SmartPointer >) *this != 0, + ExcNotInitialized()); + + const MGLevelObject& m = **this; + m[level].vmult(dst, src); +} + + +template +void +MGMatrix::vmult_add (unsigned int level, + VECTOR& dst, + const VECTOR& src) const +{ + Assert((SmartPointer >) *this != 0, + ExcNotInitialized()); + + const MGLevelObject& m = **this; + m[level].vmult_add(dst, src); +} + + +template +void +MGMatrix::Tvmult (unsigned int level, + VECTOR& dst, + const VECTOR& src) const +{ + Assert((SmartPointer >) *this != 0, + ExcNotInitialized()); + + const MGLevelObject& m = **this; + m[level].Tvmult(dst, src); +} + + +template +void +MGMatrix::Tvmult_add (unsigned int level, + VECTOR& dst, + const VECTOR& src) const +{ + Assert((SmartPointer >) *this != 0, + ExcNotInitialized()); + + const MGLevelObject& m = **this; + m[level].Tvmult_add(dst, src); +} + + +/*----------------------------------------------------------------------*/ + +template +MGMatrixSelect:: +MGMatrixSelect (const unsigned int row, + const unsigned int col, + MGLevelObject* p) + : + SmartPointer > (p), + row(row), + col(col) +{} + + + +template +void +MGMatrixSelect:: +select_block (const unsigned int brow, + const unsigned int bcol) +{ + row = brow; + col = bcol; +} + + +template +void +MGMatrixSelect:: +vmult (unsigned int level, + Vector& dst, + const Vector& src) const +{ + Assert((SmartPointer >) *this != 0, + ExcNotInitialized()); + + const MGLevelObject& m = **this; + m[level].block(row, col).vmult(dst, src); +} + + +template +void +MGMatrixSelect:: +vmult_add (unsigned int level, + Vector& dst, + const Vector& src) const +{ + Assert((SmartPointer >) *this != 0, + ExcNotInitialized()); + + const MGLevelObject& m = **this; + m[level].block(row, col).vmult_add(dst, src); +} + + +template +void +MGMatrixSelect:: +Tvmult (unsigned int level, + Vector& dst, + const Vector& src) const +{ + Assert((SmartPointer >) *this != 0, + ExcNotInitialized()); + + const MGLevelObject& m = **this; + m[level].block(row, col).Tvmult(dst, src); +} + + +template +void +MGMatrixSelect:: +Tvmult_add (unsigned int level, + Vector& dst, + const Vector& src) const +{ + Assert((SmartPointer >) *this != 0, + ExcNotInitialized()); + + const MGLevelObject& m = **this; + m[level].block(row, col).Tvmult_add(dst, src); +} + +#endif