From 396f3b92991dda86b9e45fcad4ead168f7a7b103 Mon Sep 17 00:00:00 2001 From: bangerth Date: Wed, 1 Aug 2007 21:31:40 +0000 Subject: [PATCH] Simplify and speed up computations git-svn-id: https://svn.dealii.org/trunk@14872 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/examples/step-27/step-27.cc | 129 +++++++++++----------------- 1 file changed, 50 insertions(+), 79 deletions(-) diff --git a/deal.II/examples/step-27/step-27.cc b/deal.II/examples/step-27/step-27.cc index 4c4d2d2319..4a7a043214 100644 --- a/deal.II/examples/step-27/step-27.cc +++ b/deal.II/examples/step-27/step-27.cc @@ -72,9 +72,8 @@ class LaplaceProblem void assemble_system (); void solve (); void create_coarse_grid (); - void refine_grid (); void estimate_smoothness (Vector &smoothness_indicators) const; - void output_results (const unsigned int cycle) const; + void postprocess (const unsigned int cycle); Triangulation triangulation; @@ -178,6 +177,8 @@ void LaplaceProblem::setup_system () system_matrix.reinit (sparsity_pattern); } + + template void LaplaceProblem::assemble_system () { @@ -264,16 +265,6 @@ void LaplaceProblem::solve () } -unsigned int -int_pow (const unsigned int x, - const unsigned int n) -{ - unsigned int p=1; - for (unsigned int i=0; i void @@ -445,10 +436,11 @@ estimate_smoothness (Vector &smoothness_indicators) const - template -void LaplaceProblem::refine_grid () +void LaplaceProblem::postprocess (const unsigned int cycle) { + Assert (cycle < 10, ExcNotImplemented()); + Vector estimated_error_per_cell (triangulation.n_active_cells()); KellyErrorEstimator::estimate (dof_handler, face_quadrature_collection, @@ -459,67 +451,7 @@ void LaplaceProblem::refine_grid () Vector smoothness_indicators (triangulation.n_active_cells()); estimate_smoothness (smoothness_indicators); - GridRefinement::refine_and_coarsen_fixed_number (triangulation, - estimated_error_per_cell, - 0.3, 0.03); - - float max_smoothness = 0, - min_smoothness = smoothness_indicators.linfty_norm(); - { - typename hp::DoFHandler::active_cell_iterator - cell = dof_handler.begin_active(), - endc = dof_handler.end(); - for (unsigned int index=0; cell!=endc; ++cell, ++index) - if (cell->refine_flag_set()) - { - max_smoothness = std::max (max_smoothness, - smoothness_indicators(index)); - min_smoothness = std::min (min_smoothness, - smoothness_indicators(index)); - } - } - const float cutoff_smoothness = (max_smoothness + min_smoothness) / 2; - { - typename hp::DoFHandler::active_cell_iterator - cell = dof_handler.begin_active(), - endc = dof_handler.end(); - for (unsigned int index=0; cell!=endc; ++cell, ++index) - if (cell->refine_flag_set() - && - (smoothness_indicators(index) > cutoff_smoothness) - && - !(cell->active_fe_index() == fe_collection.size() - 1)) - { - cell->clear_refine_flag(); - cell->set_active_fe_index (std::min (cell->active_fe_index() + 1, - fe_collection.size() - 1)); - } - } - - triangulation.execute_coarsening_and_refinement (); -} - - - -template -void LaplaceProblem::output_results (const unsigned int cycle) const -{ - Assert (cycle < 10, ExcNotImplemented()); - - { - const std::string filename = "grid-" + - Utilities::int_to_string (cycle, 2) + - ".eps"; - std::ofstream output (filename.c_str()); - - GridOut grid_out; - grid_out.write_eps (triangulation, output); - } - { - Vector smoothness_indicators (triangulation.n_active_cells()); - estimate_smoothness (smoothness_indicators); - Vector fe_indices (triangulation.n_active_cells()); { typename hp::DoFHandler::active_cell_iterator @@ -543,6 +475,48 @@ void LaplaceProblem::output_results (const unsigned int cycle) const std::ofstream output (filename.c_str()); data_out.write_gmv (output); } + + { + GridRefinement::refine_and_coarsen_fixed_number (triangulation, + estimated_error_per_cell, + 0.3, 0.03); + + float max_smoothness = 0, + min_smoothness = smoothness_indicators.linfty_norm(); + { + typename hp::DoFHandler::active_cell_iterator + cell = dof_handler.begin_active(), + endc = dof_handler.end(); + for (unsigned int index=0; cell!=endc; ++cell, ++index) + if (cell->refine_flag_set()) + { + max_smoothness = std::max (max_smoothness, + smoothness_indicators(index)); + min_smoothness = std::min (min_smoothness, + smoothness_indicators(index)); + } + } + + const float cutoff_smoothness = (max_smoothness + min_smoothness) / 2; + { + typename hp::DoFHandler::active_cell_iterator + cell = dof_handler.begin_active(), + endc = dof_handler.end(); + for (unsigned int index=0; cell!=endc; ++cell, ++index) + if (cell->refine_flag_set() + && + (smoothness_indicators(index) > cutoff_smoothness) + && + !(cell->active_fe_index() == fe_collection.size() - 1)) + { + cell->clear_refine_flag(); + cell->set_active_fe_index (std::min (cell->active_fe_index() + 1, + fe_collection.size() - 1)); + } + } + + triangulation.execute_coarsening_and_refinement (); + } } @@ -622,15 +596,12 @@ void LaplaceProblem<2>::create_coarse_grid () template void LaplaceProblem::run () { - for (unsigned int cycle=0; cycle<3; ++cycle) + for (unsigned int cycle=0; cycle<5; ++cycle) { std::cout << "Cycle " << cycle << ':' << std::endl; if (cycle == 0) create_coarse_grid (); - else - refine_grid (); - std::cout << " Number of active cells: " << triangulation.n_active_cells() @@ -650,7 +621,7 @@ void LaplaceProblem::run () solve (); - output_results (cycle); + postprocess (cycle); } } -- 2.39.5