template <int dim>
void HeatEquation<dim>::refine_mesh ()
{
Vector<float> estimated_error_per_cell (triangulation.n_active_cells());
KellyErrorEstimator<dim>::estimate (dof_handler,
QGauss<dim-1>(fe.degree+1),
typename FunctionMap<dim>::type(),
present_solution,
estimated_error_per_cell);
GridRefinement::refine_and_coarsen_fixed_number (triangulation,
estimated_error_per_cell,
0.6, 0.4);
if (triangulation.n_levels() > max_grid_level)
for (auto cell = triangulation.begin_active(max_grid_level); cell != triangulation.end(); ++cell)
cell->clear_refine_flag ();
for (auto cell = triangulation.begin_active(min_grid_level); cell != triangulation.end_active(min_grid_level); ++cell)
cell->clear_coarsen_flag ();
triangulation.prepare_coarsening_and_refinement ();
SolutionTransfer<dim> solution_transfer(dof_handler);
solution_transfer.prepare_for_coarsening_and_refinement(present_solution);
triangulation.execute_coarsening_and_refinement();
dof_handler.distribute_dofs(fe);
Vector<double> tmp(dof_handler.n_dofs());
solution_transfer.interpolate(present_solution, tmp);
present_solution = tmp;
solution_transfer.interpolate(old_solution, tmp);
old_solution = tmp;
set_boundary_values ();
constraint_matrix.clear();
DoFTools::make_hanging_node_constraints(dof_handler,
constraint_matrix);
constraint_matrix.close();
constraint_matrix.distribute (present_solution);
constraint_matrix.distribute(old_solution);
setup_system (false);
}