From: guido Date: Thu, 15 Aug 2002 18:23:00 +0000 (+0000) Subject: Matrix template argument in MG removed X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=249331a21ebb01799b8e7f9c070c93748fe72c6a;p=dealii-svn.git Matrix template argument in MG removed git-svn-id: https://svn.dealii.org/trunk@6329 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/multigrid/mg_base.h b/deal.II/deal.II/include/multigrid/mg_base.h index fe070b9e0d..a0747d7c1c 100644 --- a/deal.II/deal.II/include/multigrid/mg_base.h +++ b/deal.II/deal.II/include/multigrid/mg_base.h @@ -105,6 +105,62 @@ class MGLevelObject : public Subscriptor }; +/** + * Multilevel matrix base. This class sets up the interface needed by + * multilevel algorithms. It has no relation to the actual matrix type + * and takes the vector class as only template argument. + * + * Usually, the derived class @ref{MGMatrix}, operating on an + * @ref{MGLevelObject} of matrices will be sufficient for applications. + * + * @author Guido Kanschat, 2002 + */ +template +class MGMatrixBase : public Subscriptor +{ + public: + /* + * Virtual destructor. + */ + virtual ~MGMatrixBase(); + + /** + * Matrix-vector-multiplication on + * a certain level. + */ + virtual void vmult(unsigned int level, VECTOR& dst, + const VECTOR& src) const = 0; +}; + + +/** + * 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; + +}; + /** * Coarse grid solver using LAC iterative methods. @@ -297,6 +353,26 @@ MGLevelObject::get_maxlevel () const return minlevel + objects.size() - 1; }; +/*----------------------------------------------------------------------*/ + +template +MGMatrix::MGMatrix (MGLevelObject* p) + : + SmartPointer > (p) +{} + + + +template +void +MGMatrix::vmult (unsigned int level, + VECTOR& dst, + const VECTOR& src) const +{ + const MGLevelObject& m = **this; + m[level].vmult(dst, src); +} + /* ------------------ Functions for MGCoarseGridLACIteration ------------ */ diff --git a/deal.II/deal.II/include/multigrid/multigrid.h b/deal.II/deal.II/include/multigrid/multigrid.h index eb890b259a..9b9e6f745a 100644 --- a/deal.II/deal.II/include/multigrid/multigrid.h +++ b/deal.II/deal.II/include/multigrid/multigrid.h @@ -87,6 +87,7 @@ class Multigrid : public Subscriptor */ template Multigrid(const MGDoFHandler& mg_dof_handler, + const MGMatrixBase& matrix, const MGTransfer& transfer, const MGSmoother& pre_smooth, const MGSmoother& post_smooth, @@ -114,9 +115,8 @@ class Multigrid : public Subscriptor * function is done in * @p{level_mgstep}. */ - template - void vcycle(const MGLevelObject& matrix, - const COARSE& cgs); + template + void vcycle(const COARSE& cgs); /** * Print a level vector using @@ -143,10 +143,9 @@ class Multigrid : public Subscriptor * is used to solve the matrix of * this level. */ - template - void level_mgstep (const unsigned int level, - const MGLevelObject& matrix, - const COARSE& cgs); + template + void level_mgstep (const unsigned int level, + const COARSE& cgs); /** * Level for coarse grid solution. */ @@ -178,6 +177,11 @@ class Multigrid : public Subscriptor private: + /** + * The matrix for each level. + */ + SmartPointer > matrix; + /** * Object for grid tranfer. */ @@ -200,7 +204,7 @@ class Multigrid : public Subscriptor DeclException2(ExcSwitchedLevels, int, int, << "minlevel and maxlevel switched, should be: " << arg1 << "<=" << arg2); - template friend class PreconditionMG; + template friend class PreconditionMG; }; @@ -216,7 +220,7 @@ class Multigrid : public Subscriptor * * @author Guido Kanschat, 1999, 2000, 2001, 2002 */ -template +template class PreconditionMG : public Subscriptor { public: @@ -228,7 +232,6 @@ class PreconditionMG : public Subscriptor */ PreconditionMG(const MGDoFHandler& mg_dof, Multigrid& mg, - const MGLevelObject& matrix, const TRANSFER& transfer, const COARSE& coarse); @@ -282,15 +285,6 @@ class PreconditionMG : public Subscriptor */ SmartPointer > multigrid; - /** - * Matrices for each level. The - * matrices are prepared by the - * constructor of @p{Multigrid} and - * can be accessed for - * assembling. - */ - SmartPointer > level_matrices; - /** * Object for grid tranfer. */ @@ -311,6 +305,7 @@ class PreconditionMG : public Subscriptor template template Multigrid::Multigrid (const MGDoFHandler& mg_dof_handler, + const MGMatrixBase& matrix, const MGTransfer& transfer, const MGSmoother& pre_smooth, const MGSmoother& post_smooth, @@ -318,23 +313,23 @@ Multigrid::Multigrid (const MGDoFHandler& mg_dof_handler, const unsigned int max_level) : minlevel(min_level), - maxlevel(std::min(mg_dof_handler.get_tria().n_levels()-1, - max_level)), - defect(minlevel,maxlevel), - solution(minlevel,maxlevel), - t(minlevel,maxlevel), - transfer(&transfer), - pre_smooth(&pre_smooth), - post_smooth(&post_smooth) + maxlevel(std::min(mg_dof_handler.get_tria().n_levels()-1, + max_level)), + defect(minlevel,maxlevel), + solution(minlevel,maxlevel), + t(minlevel,maxlevel), + matrix(&matrix), + transfer(&transfer), + pre_smooth(&pre_smooth), + post_smooth(&post_smooth) { }; template -template +template void Multigrid::level_mgstep(const unsigned int level, - const MGLevelObject& matrix, const COARSE &coarse_grid_solver) { #ifdef MG_DEBUG @@ -364,7 +359,7 @@ Multigrid::level_mgstep(const unsigned int level, #endif // t = -A*solution[level] - matrix[level].vmult(t[level], solution[level]); + matrix->vmult(level, t[level], solution[level]); t[level].scale(-1); // make t rhs of lower level @@ -383,7 +378,7 @@ Multigrid::level_mgstep(const unsigned int level, // edge_vmult(level, defect[level-1], defect[level]); // do recursion - level_mgstep(level-1, matrix, coarse_grid_solver); + level_mgstep(level-1, coarse_grid_solver); // reset size of the auxiliary // vector, since it has been @@ -415,10 +410,9 @@ Multigrid::level_mgstep(const unsigned int level, template -template +template void -Multigrid::vcycle(const MGLevelObject& matrix, - const COARSE &coarse_grid_solver) +Multigrid::vcycle(const COARSE &coarse_grid_solver) { // The defect vector has been // initialized by copy_to_mg. Now @@ -432,7 +426,7 @@ Multigrid::vcycle(const MGLevelObject& matrix, t[level].reinit(defect[level]); } - level_mgstep (maxlevel, matrix, coarse_grid_solver); + level_mgstep (maxlevel, coarse_grid_solver); // abort (); } @@ -440,25 +434,23 @@ Multigrid::vcycle(const MGLevelObject& matrix, /* ------------------------------------------------------------------- */ -template -PreconditionMG +template +PreconditionMG ::PreconditionMG(const MGDoFHandler& mg_dof_handler, Multigrid& mg, - const MGLevelObject& matrix, const TRANSFER& transfer, const COARSE& coarse) : mg_dof_handler(&mg_dof_handler), multigrid(&mg), - level_matrices(&matrix), transfer(&transfer), coarse(&coarse) {} -template +template void -PreconditionMG::vmult ( +PreconditionMG::vmult ( VECTOR& dst, const VECTOR& src) const { @@ -466,7 +458,7 @@ PreconditionMG::vmult ( multigrid->defect, src); - multigrid->vcycle(*level_matrices, *coarse); + multigrid->vcycle(*coarse); transfer->copy_from_mg(*mg_dof_handler, dst, @@ -474,9 +466,9 @@ PreconditionMG::vmult ( } -template +template void -PreconditionMG::vmult_add ( +PreconditionMG::vmult_add ( VECTOR& dst, const VECTOR& src) const { @@ -484,7 +476,7 @@ PreconditionMG::vmult_add ( multigrid->defect, src); - multigrid->vcycle(*level_matrices, *coarse); + multigrid->vcycle(*coarse); transfer->copy_from_mg_add(*mg_dof_handler, dst, @@ -492,9 +484,9 @@ PreconditionMG::vmult_add ( } -template +template void -PreconditionMG::Tvmult ( +PreconditionMG::Tvmult ( VECTOR&, const VECTOR&) const { @@ -502,9 +494,9 @@ PreconditionMG::Tvmult ( } -template +template void -PreconditionMG::Tvmult_add ( +PreconditionMG::Tvmult_add ( VECTOR&, const VECTOR&) const { diff --git a/deal.II/deal.II/source/multigrid/mg_base.cc b/deal.II/deal.II/source/multigrid/mg_base.cc index 6fe65ce039..fa934a7e98 100644 --- a/deal.II/deal.II/source/multigrid/mg_base.cc +++ b/deal.II/deal.II/source/multigrid/mg_base.cc @@ -26,9 +26,19 @@ {}; + template + MGMatrixBase::~MGMatrixBase() + {}; + + // Explicit instantiations template class MGTransfer >; template class MGTransfer >; template class MGTransfer >; template class MGTransfer >; + + template class MGMatrixBase >; + template class MGMatrixBase >; + template class MGMatrixBase >; + template class MGMatrixBase >;