From: kanschat Date: Fri, 16 May 2008 14:44:42 +0000 (+0000) Subject: add Dirichlet boundary conditions to multigrid. Thanks to Seungil Kim X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb7ba0c08a67813ff9f2447d27b8f75ea5bd3812;p=dealii-svn.git add Dirichlet boundary conditions to multigrid. Thanks to Seungil Kim git-svn-id: https://svn.dealii.org/trunk@16112 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/examples/step-16/step-16.cc b/deal.II/examples/step-16/step-16.cc index 3b5ff0c249..e0eb83d938 100644 --- a/deal.II/examples/step-16/step-16.cc +++ b/deal.II/examples/step-16/step-16.cc @@ -129,10 +129,17 @@ void LaplaceProblem::setup_system () { mg_dof_handler.distribute_dofs (fe); - std::cout << " Number of degrees of freedom: " - << mg_dof_handler.n_dofs() - << std::endl; - + // Here we output not only the + // degrees of freedom on the finest + // level, but also in the + // multilevel structure + deallog << "Number of degrees of freedom: " + << mg_dof_handler.n_dofs(); + for (unsigned int l=0;l::assemble_system () for (unsigned int i=0; i::assemble_system () }; }; - // Again use zero boundary values: -// std::map@ boundary_values; -// VectorTools::interpolate_boundary_values (mg_dof_handler, -// 0, -// ZeroFunction@(), -// boundary_values); -// MatrixTools::apply_boundary_values (boundary_values, -// system_matrix, -// solution, -// system_rhs); + // The Dirichlet boundary + // conditions on the finest level + // are handled as usual. + std::map boundary_values; + + VectorTools::interpolate_boundary_values (mg_dof_handler, + 0, + ZeroFunction(), + boundary_values); + + + MatrixTools::apply_boundary_values (boundary_values, + system_matrix, + solution, + system_rhs); + + } @@ -329,12 +341,10 @@ void LaplaceProblem::assemble_multigrid () for (unsigned int i=0; i::assemble_multigrid () mg_matrices[level].add (local_dof_indices[i], local_dof_indices[j], cell_matrix(i,j)); - }; - }; + } + } - // Again use zero boundary values: -// std::map@ boundary_values; -// VectorTools::interpolate_boundary_values (mg_dof_handler, -// 0, -// ZeroFunction@(), -// boundary_values); -// MatrixTools::apply_boundary_values (boundary_values, -// system_matrix, -// solution, -// system_rhs); + // Now we have to eliminate the + // boundary nodes on all + // levels. This is done exactly in + // the same fashion as on the + // finest level. Therefore, we need + // a function map first. On the + // other hand, since we use + // multigrid only as a + // preconditioner, we always use + // homogeneous boundary conditions + // and the ZeroFunction will be + // sufficient in all cases; using a + // different function here would + // not hurt on the other hand, + // since the values are ignored. + + typename FunctionMap::type dirichlet_boundary; + ZeroFunction homogeneous_dirichlet_bc (1); + dirichlet_boundary[0] = &homogeneous_dirichlet_bc; + + // Next we generate the set of + // dof indices to be eliminated on + // each level. + std::vector > boundary_indices(triangulation.n_levels()); + MGTools::make_boundary_list (mg_dof_handler, + dirichlet_boundary, + boundary_indices); + + // And finally we eliminate these + // degrees of freedom from every + // matrix in the multilevel hierarchy. + const unsigned int nlevels = triangulation.n_levels(); + for (unsigned int level=0;level::solve () cg.solve (system_matrix, solution, system_rhs, preconditioner); - - std::cout << " " << solver_control.last_step() - << " CG iterations needed to obtain convergence." - << std::endl; } @@ -505,7 +539,7 @@ void LaplaceProblem::run () { for (unsigned int cycle=0; cycle<6; ++cycle) { - std::cout << "Cycle " << cycle << ':' << std::endl; + deallog << "Cycle " << cycle << std::endl; if (cycle == 0) { @@ -518,18 +552,6 @@ void LaplaceProblem::run () // the grid once globally. else triangulation.refine_global (1); - - // Write some output and do all - // the things that we have - // already seen in the previous - // examples. - std::cout << " Number of active cells: " - << triangulation.n_active_cells() - << std::endl - << " Total number of cells: " - << triangulation.n_cells() - << std::endl; - setup_system (); assemble_system (); assemble_multigrid (); @@ -546,8 +568,6 @@ void LaplaceProblem::run () // further. int main () { - deallog.depth_console (0); - LaplaceProblem<2> laplace_problem_2d; laplace_problem_2d.run ();