From: bangerth Date: Fri, 12 Feb 2010 23:46:54 +0000 (+0000) Subject: More documentation. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0afcaf64dcbf5874857ce387b4fd5665dc4b0374;p=dealii-svn.git More documentation. git-svn-id: https://svn.dealii.org/trunk@20581 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 e0bd18d487..5c6f04c54a 100644 --- a/deal.II/examples/step-16/step-16.cc +++ b/deal.II/examples/step-16/step-16.cc @@ -257,6 +257,13 @@ LaplaceProblem::LaplaceProblem (const unsigned int degree) {} + + // @sect4{LaplaceProblem::setup_system} + + // The following function extends what the + // corresponding one in step-6 did. The top + // part, apart from the additional output, + // does the same: template void LaplaceProblem::setup_system () { @@ -284,6 +291,28 @@ void LaplaceProblem::setup_system () solution.reinit (mg_dof_handler.n_dofs()); system_rhs.reinit (mg_dof_handler.n_dofs()); + // But it starts to be a wee bit different + // here, although this still doesn't have + // anything to do with multigrid + // methods. step-6 took care of boundary + // values and hanging nodes in a separate + // step after assembling the global matrix + // from local contributions. This works, + // but the same can be done in a slightly + // simpler way if we already take care of + // these constraints at the time of copying + // local contributions into the global + // matrix. To this end, we here do not just + // compute the constraints do to hanging + // nodes, but also due to zero boundary + // conditions. Both kinds of constraints + // can be put into the same object + // (constraints), and we will + // use this set of constraints later on to + // help us copy local contributions + // correctly into the global linear system + // right away, without the need for a later + // clean-up stage: constraints.clear (); DoFTools::make_hanging_node_constraints (mg_dof_handler, constraints); VectorTools::interpolate_boundary_values (mg_dof_handler, @@ -295,66 +324,81 @@ void LaplaceProblem::setup_system () sparsity_pattern.compress(); system_matrix.reinit (sparsity_pattern); - // The multi-level objects are - // resized to hold matrices for - // every level. The coarse level is - // zero (this is mandatory right - // now but may change in a future - // revision). Remark, that the - // finest level is nlevels-1. - // We first have to resize the - // container holding the - // SparseMatrix classes, since they - // have to release their - // SparsityPattern before it can be - // destroyed. - const unsigned int nlevels = triangulation.n_levels(); - - mg_interface_matrices.resize(0, nlevels-1); + // Now for the things that concern the + // multigrid data structures. First, we + // resize the multi-level objects to hold + // matrices and sparsity patterns for every + // level. The coarse level is zero (this is + // mandatory right now but may change in a + // future revision). Note that these + // functions take a complete, inclusive + // range here (not a starting index and + // size), so the finest level is + // n_levels-1. We first have + // to resize the container holding the + // SparseMatrix classes, since they have to + // release their SparsityPattern before the + // can be destroyed upon resizing. + const unsigned int n_levels = triangulation.n_levels(); + + mg_interface_matrices.resize(0, n_levels-1); mg_interface_matrices.clear (); - mg_matrices.resize(0, nlevels-1); + mg_matrices.resize(0, n_levels-1); mg_matrices.clear (); - mg_sparsity_patterns.resize(0, nlevels-1); - - // Now, we have to build a matrix - // on each level. Technically, we - // could use the matrix initialized - // above on the finest - // level. Beware that this is not - // true anymore with local - // refinement! - for (unsigned int level=0;level0) - { - ci_sparsity.reinit(mg_dof_handler.n_dofs(level), - mg_dof_handler.n_dofs(level)); - MGTools::make_sparsity_pattern(mg_dof_handler, ci_sparsity, level); - } - } + CompressedSparsityPattern csp; + csp.reinit(mg_dof_handler.n_dofs(level), + mg_dof_handler.n_dofs(level)); + MGTools::make_sparsity_pattern(mg_dof_handler, csp, level); -//And the same for the mg matrices -//for the interface. Note that there -//is no such interface on the coarsest level - for(unsigned int level=0; level void LaplaceProblem::assemble_system () { @@ -410,19 +454,23 @@ void LaplaceProblem::assemble_system () } - // Here is another assemble - // function. The integration core is - // the same as above. Only the loop - // goes over all existing cells now - // and the results must be entered - // into the correct matrix. Here comes - // the difference to global refinement - // into play. We have to fill the interface - // matrices correctly. + // @sect4{LaplaceProblem::assemble_multigrid} - // Since we only do multi-level - // preconditioning, no right-hand - // side is assembled here. + // The next function is the one that builds + // the linear operators (matrices) that + // define the multigrid method on each level + // of the mesh. The integration core is the + // same as above, but the loop below will go + // over all existing cells instead of just + // the active ones, and the results must be + // entered into the correct matrix. Note also + // that since we only do multi-level + // preconditioning, no right-hand side needs + // to be assembled here. + // + // Before we go there, however, we have to + // take care of a significant amount of book + // keeping: template void LaplaceProblem::assemble_multigrid () { @@ -439,13 +487,20 @@ void LaplaceProblem::assemble_multigrid () std::vector local_dof_indices (dofs_per_cell); + // Next a few things that are specific to + // building the multigrid data structures + // (since we only need them in the current + // function, rather than also elsewhere, we + // build them here instead of the + // setup_system function). std::vector > interface_dofs; std::vector > boundary_interface_dofs; for (unsigned int level = 0; level tmp (mg_dof_handler.n_dofs(level)); - interface_dofs.push_back (tmp); - boundary_interface_dofs.push_back (tmp); + interface_dofs.push_back (std::vector + (mg_dof_handler.n_dofs(level))); + boundary_interface_dofs.push_back (std::vector + (mg_dof_handler.n_dofs(level))); } MGTools::extract_inner_interface_dofs (mg_dof_handler, interface_dofs,