From b84dc4116ea0bffd2225507e3701b78f47285690 Mon Sep 17 00:00:00 2001 From: guido Date: Mon, 19 Aug 2002 10:50:22 +0000 Subject: [PATCH] MGCoarseGrid base class introduced git-svn-id: https://svn.dealii.org/trunk@6335 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/multigrid/mg_base.h | 28 ++++++- deal.II/deal.II/include/multigrid/multigrid.h | 79 ++++++++++--------- deal.II/deal.II/source/multigrid/mg_base.cc | 40 ++++++---- 3 files changed, 92 insertions(+), 55 deletions(-) diff --git a/deal.II/deal.II/include/multigrid/mg_base.h b/deal.II/deal.II/include/multigrid/mg_base.h index a0747d7c1c..cdd8886d03 100644 --- a/deal.II/deal.II/include/multigrid/mg_base.h +++ b/deal.II/deal.II/include/multigrid/mg_base.h @@ -162,6 +162,32 @@ class MGMatrix : public MGMatrixBase, }; +/** + * Base class for coarse grid solvers. This defines the virtual + * parenthesis operator, being the interface used by multigrid + * methods. Any implementation will be done by derived classes. + * + * @author Guido Kanschat, 2002 + */ +template +class MGCoarseGrid : public Subscriptor +{ + public: + /** + * Virtual destructor. + */ + virtual ~MGCoarseGrid (); + + /** + * Solver method implemented by + * derived classes. + */ + virtual void operator() (const unsigned int level, + VECTOR &dst, + const VECTOR &src) const = 0; +}; + + /** * Coarse grid solver using LAC iterative methods. * This is a little wrapper, transforming a triplet of iterative @@ -174,7 +200,7 @@ class MGMatrix : public MGMatrixBase, * @author Guido Kanschat, 1999 */ template > -class MGCoarseGridLACIteration : public Subscriptor +class MGCoarseGridLACIteration : public MGCoarseGrid { public: /** diff --git a/deal.II/deal.II/include/multigrid/multigrid.h b/deal.II/deal.II/include/multigrid/multigrid.h index 9b9e6f745a..301691ced1 100644 --- a/deal.II/deal.II/include/multigrid/multigrid.h +++ b/deal.II/deal.II/include/multigrid/multigrid.h @@ -24,6 +24,12 @@ #include +//TODO:[GK] Cleanup +// Move MGSmoother to mg_base.h +// move definitions of virtual destructors to mg_base.templates.h +// move MGCoarseGridLACIteration to mg_coarse.h +// + /** * Implementation of the multigrid method. * @@ -88,6 +94,7 @@ class Multigrid : public Subscriptor template Multigrid(const MGDoFHandler& mg_dof_handler, const MGMatrixBase& matrix, + const MGCoarseGrid& coarse, const MGTransfer& transfer, const MGSmoother& pre_smooth, const MGSmoother& post_smooth, @@ -115,8 +122,7 @@ class Multigrid : public Subscriptor * function is done in * @p{level_mgstep}. */ - template - void vcycle(const COARSE& cgs); + void vcycle(); /** * Print a level vector using @@ -143,9 +149,7 @@ class Multigrid : public Subscriptor * is used to solve the matrix of * this level. */ - template - void level_mgstep (const unsigned int level, - const COARSE& cgs); + void level_mgstep (const unsigned int level); /** * Level for coarse grid solution. */ @@ -182,10 +186,16 @@ class Multigrid : public Subscriptor */ SmartPointer > matrix; + /** + * The matrix for each level. + */ + SmartPointer > coarse; + /** * Object for grid tranfer. */ SmartPointer > transfer; + /** * The pre-smoothing object. */ @@ -204,7 +214,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; }; @@ -220,7 +230,7 @@ class Multigrid : public Subscriptor * * @author Guido Kanschat, 1999, 2000, 2001, 2002 */ -template +template class PreconditionMG : public Subscriptor { public: @@ -232,8 +242,7 @@ class PreconditionMG : public Subscriptor */ PreconditionMG(const MGDoFHandler& mg_dof, Multigrid& mg, - const TRANSFER& transfer, - const COARSE& coarse); + const TRANSFER& transfer); /** * Preconditioning operator. @@ -288,12 +297,7 @@ class PreconditionMG : public Subscriptor /** * Object for grid tranfer. */ - SmartPointer transfer; - - /** - * The coarse grid solver. - */ - SmartPointer coarse; + SmartPointer transfer; }; @@ -306,6 +310,7 @@ template template Multigrid::Multigrid (const MGDoFHandler& mg_dof_handler, const MGMatrixBase& matrix, + const MGCoarseGrid& coarse, const MGTransfer& transfer, const MGSmoother& pre_smooth, const MGSmoother& post_smooth, @@ -319,6 +324,7 @@ Multigrid::Multigrid (const MGDoFHandler& mg_dof_handler, solution(minlevel,maxlevel), t(minlevel,maxlevel), matrix(&matrix), + coarse(&coarse), transfer(&transfer), pre_smooth(&pre_smooth), post_smooth(&post_smooth) @@ -327,10 +333,8 @@ Multigrid::Multigrid (const MGDoFHandler& mg_dof_handler, template -template void -Multigrid::level_mgstep(const unsigned int level, - const COARSE &coarse_grid_solver) +Multigrid::level_mgstep(const unsigned int level) { #ifdef MG_DEBUG char *name = new char[100]; @@ -342,7 +346,7 @@ Multigrid::level_mgstep(const unsigned int level, if (level == minlevel) { - coarse_grid_solver(level, solution[level], defect[level]); + (*coarse)(level, solution[level], defect[level]); #ifdef MG_DEBUG sprintf(name, "MG%d-solution",level); print_vector(level, solution[level], name); @@ -378,7 +382,7 @@ Multigrid::level_mgstep(const unsigned int level, // edge_vmult(level, defect[level-1], defect[level]); // do recursion - level_mgstep(level-1, coarse_grid_solver); + level_mgstep(level-1); // reset size of the auxiliary // vector, since it has been @@ -410,9 +414,8 @@ Multigrid::level_mgstep(const unsigned int level, template -template void -Multigrid::vcycle(const COARSE &coarse_grid_solver) +Multigrid::vcycle() { // The defect vector has been // initialized by copy_to_mg. Now @@ -426,7 +429,7 @@ Multigrid::vcycle(const COARSE &coarse_grid_solver) t[level].reinit(defect[level]); } - level_mgstep (maxlevel, coarse_grid_solver); + level_mgstep (maxlevel); // abort (); } @@ -434,23 +437,21 @@ Multigrid::vcycle(const COARSE &coarse_grid_solver) /* ------------------------------------------------------------------- */ -template -PreconditionMG +template +PreconditionMG ::PreconditionMG(const MGDoFHandler& mg_dof_handler, Multigrid& mg, - const TRANSFER& transfer, - const COARSE& coarse) + const TRANSFER& transfer) : mg_dof_handler(&mg_dof_handler), multigrid(&mg), - transfer(&transfer), - coarse(&coarse) + transfer(&transfer) {} -template +template void -PreconditionMG::vmult ( +PreconditionMG::vmult ( VECTOR& dst, const VECTOR& src) const { @@ -458,7 +459,7 @@ PreconditionMG::vmult ( multigrid->defect, src); - multigrid->vcycle(*coarse); + multigrid->vcycle(); transfer->copy_from_mg(*mg_dof_handler, dst, @@ -466,9 +467,9 @@ PreconditionMG::vmult ( } -template +template void -PreconditionMG::vmult_add ( +PreconditionMG::vmult_add ( VECTOR& dst, const VECTOR& src) const { @@ -476,7 +477,7 @@ PreconditionMG::vmult_add ( multigrid->defect, src); - multigrid->vcycle(*coarse); + multigrid->vcycle(); transfer->copy_from_mg_add(*mg_dof_handler, dst, @@ -484,9 +485,9 @@ PreconditionMG::vmult_add ( } -template +template void -PreconditionMG::Tvmult ( +PreconditionMG::Tvmult ( VECTOR&, const VECTOR&) const { @@ -494,9 +495,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 fa934a7e98..2a072db83a 100644 --- a/deal.II/deal.II/source/multigrid/mg_base.cc +++ b/deal.II/deal.II/source/multigrid/mg_base.cc @@ -21,24 +21,34 @@ - template - MGTransfer::~MGTransfer() - {}; +template +MGTransfer::~MGTransfer() +{}; - template - MGMatrixBase::~MGMatrixBase() - {}; +template +MGMatrixBase::~MGMatrixBase() +{}; - // Explicit instantiations +template +MGCoarseGrid::~MGCoarseGrid() +{}; - template class MGTransfer >; - template class MGTransfer >; - template class MGTransfer >; - template class MGTransfer >; - template class MGMatrixBase >; - template class MGMatrixBase >; - template class MGMatrixBase >; - template class 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 >; + +template class MGCoarseGrid >; +template class MGCoarseGrid >; +template class MGCoarseGrid >; +template class MGCoarseGrid >; -- 2.39.5