From: Daniel Arndt Date: Mon, 15 Aug 2016 12:04:38 +0000 (+0200) Subject: Allow to specify minlevel and maxlevel in the Multigrid constructor X-Git-Tag: v8.5.0-rc1~642^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ccff13a5362d087405f63a4c64ffb5109e902b3;p=dealii.git Allow to specify minlevel and maxlevel in the Multigrid constructor --- diff --git a/include/deal.II/multigrid/multigrid.h b/include/deal.II/multigrid/multigrid.h index b8b4fa788a..749b920a11 100644 --- a/include/deal.II/multigrid/multigrid.h +++ b/include/deal.II/multigrid/multigrid.h @@ -81,8 +81,11 @@ public: typedef const VectorType const_vector_type; /** - * Constructor. The DoFHandler is used to determine the highest possible - * level. transfer is an object performing prolongation and + * Constructor. The DoFHandler is used to check whether the provided + * minlevel and maxlevel are in the range of valid levels. + * If maxlevel is set to the default value, the highest valid + * level is used. + * transfer is an object performing prolongation and * restriction. * * This function already initializes the vectors which will be used later in @@ -96,11 +99,12 @@ public: const MGTransferBase &transfer, const MGSmootherBase &pre_smooth, const MGSmootherBase &post_smooth, - Cycle cycle = v_cycle); + Cycle cycle = v_cycle, + const unsigned int minlevel = 0, + const unsigned int maxlevel = numbers::invalid_unsigned_int); /** - * Constructor. Same as above but you can determine the multigrid - * levels to use yourself. + * Constructor. Same as above but without checking validity of minlevel and maxlevel. */ Multigrid(const unsigned int minlevel, const unsigned int maxlevel, @@ -422,21 +426,18 @@ private: template template -Multigrid::Multigrid (const DoFHandler &mg_dof_handler, +Multigrid::Multigrid (const DoFHandler &mg_dof_handler, const MGMatrixBase &matrix, const MGCoarseGridBase &coarse, const MGTransferBase &transfer, const MGSmootherBase &pre_smooth, const MGSmootherBase &post_smooth, - Cycle cycle) + Cycle cycle, + const unsigned int min_level, + const unsigned int max_level) : cycle_type(cycle), - minlevel(0), - maxlevel(mg_dof_handler.get_triangulation().n_global_levels()-1), - defect(minlevel,maxlevel), - solution(minlevel,maxlevel), - t(minlevel,maxlevel), - defect2(minlevel,maxlevel), + minlevel(min_level), matrix(&matrix, typeid(*this).name()), coarse(&coarse, typeid(*this).name()), transfer(&transfer, typeid(*this).name()), @@ -445,7 +446,24 @@ Multigrid::Multigrid (const DoFHandler &mg_dof_handler edge_down(0, typeid(*this).name()), edge_up(0, typeid(*this).name()), debug(0) -{} +{ + const unsigned int dof_handler_max_level + = mg_dof_handler.get_triangulation().n_global_levels()-1; + if (max_level == numbers::invalid_unsigned_int) + maxlevel = dof_handler_max_level; + else + maxlevel = max_level; + + Assert (maxlevel <= dof_handler_max_level, + ExcLowerRangeType(dof_handler_max_level, max_level)); + Assert (minlevel <= maxlevel, + ExcLowerRangeType(max_level, min_level)); + + defect.resize(minlevel,maxlevel); + solution.resize(minlevel,maxlevel); + t.resize(minlevel,maxlevel); + defect2.resize(minlevel,maxlevel); +} diff --git a/include/deal.II/multigrid/multigrid.templates.h b/include/deal.II/multigrid/multigrid.templates.h index 5270febce7..e185cd98cb 100644 --- a/include/deal.II/multigrid/multigrid.templates.h +++ b/include/deal.II/multigrid/multigrid.templates.h @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 1999 - 2015 by the deal.II authors +// Copyright (C) 1999 - 2016 by the deal.II authors // // This file is part of the deal.II library. // diff --git a/tests/multigrid/step-16-03.cc b/tests/multigrid/step-16-03.cc index 4630093df1..0d069340bd 100644 --- a/tests/multigrid/step-16-03.cc +++ b/tests/multigrid/step-16-03.cc @@ -384,13 +384,15 @@ void LaplaceProblem::solve () mg::Matrix<> mg_interface_up(mg_interface_matrices); mg::Matrix<> mg_interface_down(mg_interface_matrices); - Multigrid > mg(min_level, - triangulation.n_global_levels()-1, + Multigrid > mg(mg_dof_handler, mg_matrix, coarse_grid_solver, mg_transfer, mg_smoother, - mg_smoother); + mg_smoother, + Multigrid >::v_cycle, + min_level, + triangulation.n_global_levels()-1); mg.set_edge_matrices(mg_interface_down, mg_interface_up); PreconditionMG, MGTransferPrebuilt > >