From: Matthias Maier Date: Sat, 12 Aug 2017 04:48:28 +0000 (-0500) Subject: lac/schur_complement_03: Modernize test X-Git-Tag: v9.0.0-rc1~1295^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6cc4e534fa4cf2dd5b848056cec5f75f609a3fc;p=dealii.git lac/schur_complement_03: Modernize test --- diff --git a/tests/lac/schur_complement_03.cc b/tests/lac/schur_complement_03.cc index 3232a35320..a43997030a 100644 --- a/tests/lac/schur_complement_03.cc +++ b/tests/lac/schur_complement_03.cc @@ -12,9 +12,10 @@ * the top level of the deal.II distribution. * * --------------------------------------------------------------------- - * - * Author: Wolfgang Bangerth, Texas A&M University, 2008 */ + +#include "../tests.h" + #include #include #include @@ -49,6 +50,7 @@ #include #include #include + namespace Step22 { using namespace dealii; @@ -62,7 +64,6 @@ namespace Step22 void setup_dofs (); void assemble_system (); void solve (); - void output_results (const unsigned int refinement_cycle) const; void refine_mesh (); const unsigned int degree; Triangulation triangulation; @@ -74,6 +75,7 @@ namespace Step22 BlockVector solution; BlockVector system_rhs; }; + template class BoundaryValues : public Function { @@ -84,6 +86,7 @@ namespace Step22 virtual void vector_value (const Point &p, Vector &value) const; }; + template double BoundaryValues::value (const Point &p, @@ -95,6 +98,7 @@ namespace Step22 return (p[0] < 0 ? -1 : (p[0] > 0 ? 1 : 0)); return 0; } + template void BoundaryValues::vector_value (const Point &p, @@ -103,6 +107,7 @@ namespace Step22 for (unsigned int c=0; cn_components; ++c) values(c) = BoundaryValues::value (p, c); } + template class RightHandSide : public Function { @@ -113,6 +118,7 @@ namespace Step22 virtual void vector_value (const Point &p, Vector &value) const; }; + template double RightHandSide::value (const Point &/*p*/, @@ -120,6 +126,7 @@ namespace Step22 { return 0; } + template void RightHandSide::vector_value (const Point &p, @@ -128,6 +135,7 @@ namespace Step22 for (unsigned int c=0; cn_components; ++c) values(c) = RightHandSide::value (p, c); } + template StokesProblem::StokesProblem (const unsigned int degree) : @@ -137,6 +145,7 @@ namespace Step22 FE_Q(degree), 1), dof_handler (triangulation) {} + template void StokesProblem::setup_dofs () { @@ -162,7 +171,7 @@ namespace Step22 DoFTools::count_dofs_per_block (dof_handler, dofs_per_block, block_component); const unsigned int n_u = dofs_per_block[0], n_p = dofs_per_block[1]; - std::cout << " Number of active cells: " + deallog << " Number of active cells: " << triangulation.n_active_cells() << std::endl << " Number of degrees of freedom: " @@ -189,6 +198,7 @@ namespace Step22 system_rhs.block(1).reinit (n_p); system_rhs.collect_sizes (); } + template void StokesProblem::assemble_system () { @@ -213,6 +223,7 @@ namespace Step22 std::vector > symgrad_phi_u (dofs_per_cell); std::vector div_phi_u (dofs_per_cell); std::vector phi_p (dofs_per_cell); + typename DoFHandler::active_cell_iterator cell = dof_handler.begin_active(), endc = dof_handler.end(); @@ -257,6 +268,7 @@ namespace Step22 system_matrix, system_rhs); } } + template void StokesProblem::solve () { @@ -305,35 +317,12 @@ namespace Step22 x = postprocess_schur_solution (A_inv,B,y,f); constraints.distribute (solution); - std::cout << " " + deallog << " " << solver_control_S.last_step() << " outer CG Schur complement iterations for pressure" << std::endl; } - template - void - StokesProblem::output_results (const unsigned int refinement_cycle) const - { - std::vector solution_names (dim, "velocity"); - solution_names.push_back ("pressure"); - std::vector - data_component_interpretation - (dim, DataComponentInterpretation::component_is_part_of_vector); - data_component_interpretation - .push_back (DataComponentInterpretation::component_is_scalar); - DataOut data_out; - data_out.attach_dof_handler (dof_handler); - data_out.add_data_vector (solution, solution_names, - DataOut::type_dof_data, - data_component_interpretation); - data_out.build_patches (); - std::ostringstream filename; - filename << "solution-" - << Utilities::int_to_string (refinement_cycle, 2) - << ".vtk"; - std::ofstream output (filename.str().c_str()); - data_out.write_vtk (output); - } + template void StokesProblem::refine_mesh () @@ -351,12 +340,13 @@ namespace Step22 0.3, 0.0); triangulation.execute_coarsening_and_refinement (); } + template void StokesProblem::run () { { std::vector subdivisions (dim, 1); -// subdivisions[0] = 4; + const Point bottom_left = (dim == 2 ? Point(-2,-1) : Point(-2,0,-1)); @@ -378,50 +368,24 @@ namespace Step22 for (unsigned int refinement_cycle = 0; refinement_cycle<2; ++refinement_cycle) { - std::cout << "Refinement cycle " << refinement_cycle << std::endl; + deallog << "Refinement cycle " << refinement_cycle << std::endl; if (refinement_cycle > 0) refine_mesh (); setup_dofs (); - std::cout << " Assembling..." << std::endl << std::flush; + deallog << " Assembling..." << std::endl << std::flush; assemble_system (); - std::cout << " Solving..." << std::flush; + deallog << " Solving..." << std::flush; solve (); - //output_results (refinement_cycle); - std::cout << std::endl; + deallog << std::endl; } } } int main () { - try - { - using namespace dealii; - using namespace Step22; - StokesProblem<2> flow_problem(1); - flow_problem.run (); - } - catch (std::exception &exc) - { - std::cerr << std::endl << std::endl - << "----------------------------------------------------" - << std::endl; - std::cerr << "Exception on processing: " << std::endl - << exc.what() << std::endl - << "Aborting!" << std::endl - << "----------------------------------------------------" - << std::endl; - return 1; - } - catch (...) - { - std::cerr << std::endl << std::endl - << "----------------------------------------------------" - << std::endl; - std::cerr << "Unknown exception!" << std::endl - << "Aborting!" << std::endl - << "----------------------------------------------------" - << std::endl; - return 1; - } - return 0; + initlog(); + deallog.depth_file(1); + + using namespace Step22; + StokesProblem<2> flow_problem(1); + flow_problem.run (); } diff --git a/tests/lac/schur_complement_03.output b/tests/lac/schur_complement_03.output index 2b58626cbb..be5119686d 100644 --- a/tests/lac/schur_complement_03.output +++ b/tests/lac/schur_complement_03.output @@ -1,12 +1,13 @@ -Refinement cycle 0 - Number of active cells: 16 - Number of degrees of freedom: 187 (162+25) - Assembling... - Solving... 9 outer CG Schur complement iterations for pressure - -Refinement cycle 1 - Number of active cells: 40 - Number of degrees of freedom: 441 (386+55) - Assembling... - Solving... 11 outer CG Schur complement iterations for pressure +DEAL::Refinement cycle 0 +DEAL:: Number of active cells: 16 +DEAL:: Number of degrees of freedom: 187 (162+25) +DEAL:: Assembling... +DEAL:: Solving...DEAL:: 9 outer CG Schur complement iterations for pressure +DEAL:: +DEAL::Refinement cycle 1 +DEAL:: Number of active cells: 40 +DEAL:: Number of degrees of freedom: 441 (386+55) +DEAL:: Assembling... +DEAL:: Solving...DEAL:: 11 outer CG Schur complement iterations for pressure +DEAL::