From: David Wells Date: Sat, 9 Jan 2016 19:18:17 +0000 (-0500) Subject: Improve the refine_mesh function. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe46fbdf723d6d13952f955d780576a1a06a8792;p=code-gallery.git Improve the refine_mesh function. --- diff --git a/cdr/solver/cdr.cc b/cdr/solver/cdr.cc index 3c37619..0be13d4 100644 --- a/cdr/solver/cdr.cc +++ b/cdr/solver/cdr.cc @@ -231,15 +231,15 @@ void CDRProblem::time_iterate() template void CDRProblem::refine_mesh() { - parallel::distributed::SolutionTransfer - solution_transfer(dof_handler); - Vector estimated_error_per_cell(triangulation.n_active_cells()); KellyErrorEstimator::estimate (dof_handler, QGauss(fe.degree + 1), typename FunctionMap::type(), locally_relevant_solution, estimated_error_per_cell); - // Poor man's version of refine and coarsen + // This solver uses a crude refinement strategy where cells with relatively + // high errors are refined and cells with relatively low errors are + // coarsened. The maximum refinement level is capped to prevent run-away + // refinement. for (const auto &cell : triangulation.active_cell_iterators()) { if (std::abs(estimated_error_per_cell[cell->active_cell_index()]) >= 1e-3) @@ -261,9 +261,14 @@ void CDRProblem::refine_mesh() } } + // Transferring the solution between different grids is ultimately just a + // few function calls but they must be made in exactly the right order. + parallel::distributed::SolutionTransfer + solution_transfer(dof_handler); + triangulation.prepare_coarsening_and_refinement(); solution_transfer.prepare_for_coarsening_and_refinement - (locally_relevant_solution); + (locally_relevant_solution); triangulation.execute_coarsening_and_refinement(); setup_dofs();