From: bangerth Date: Wed, 6 Jan 2010 13:14:57 +0000 (+0000) Subject: Remove functions and variables we don't need any more. Catch X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a7f5b6fffb4cc5990baba7cbbfadd307e3dd71d;p=dealii-svn.git Remove functions and variables we don't need any more. Catch exceptions that may be thrown by nested solvers. git-svn-id: https://svn.dealii.org/trunk@20313 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/examples/step-42/step-42.cc b/deal.II/examples/step-42/step-42.cc index 3d97a248d6..5544d05ec4 100644 --- a/deal.II/examples/step-42/step-42.cc +++ b/deal.II/examples/step-42/step-42.cc @@ -101,9 +101,7 @@ class StokesProblem void setup_dofs (); void assemble_system (); void assemble_multigrid (); - void solve_schur (); - void solve_block (); - void solve_mg (); + void solve (); void find_dofs_on_lower_level (std::vector > &lower_dofs, std::vector > &boundary_dofs); @@ -131,7 +129,6 @@ class StokesProblem MGLevelObject > mg_interface_matrices; std::vector > mg_dofs_per_component; - std_cxx1x::shared_ptr::type> A_preconditioner; std::vector::type> > mg_A_preconditioner; }; @@ -246,9 +243,20 @@ void InverseMatrix::vmult (Vector &dst, dst = 0; - cg.solve (*matrix, dst, src, *preconditioner); + try + { + cg.solve (*matrix, dst, src, *preconditioner); + } + catch (...) + { + std::cout << "Failure in " << __PRETTY_FUNCTION__ << std::endl; + abort (); + } - std::cout << " Preconditioner CG steps: " << solver_control.last_step() << std::endl; + std::cout << " Preconditioner CG steps: " << solver_control.last_step() + << " " + << matrix->m() + << std::endl; } template @@ -365,7 +373,6 @@ StokesProblem::StokesProblem (const unsigned int degree) template void StokesProblem::setup_dofs () { - A_preconditioner.reset (); mg_A_preconditioner.resize (0); system_matrix.clear (); @@ -556,15 +563,6 @@ void StokesProblem::assemble_system () local_dof_indices, system_matrix, system_rhs); } - - - std::cout << " Computing preconditioner..." << std::endl << std::flush; - - A_preconditioner - = std_cxx1x::shared_ptr::type>(new typename InnerPreconditioner::type()); - A_preconditioner->initialize (system_matrix.block(0,0), - typename InnerPreconditioner::type::AdditionalData()); - } @@ -696,45 +694,6 @@ void StokesProblem::assemble_multigrid () } -template -void StokesProblem::solve_block () -{ - SparseMatrix pressure_mass_matrix; - pressure_mass_matrix.reinit(sparsity_pattern.block(1,1)); - pressure_mass_matrix.copy_from(system_matrix.block(1,1)); - system_matrix.block(1,1) = 0; - - SparseILU pmass_preconditioner; - pmass_preconditioner.initialize (pressure_mass_matrix, - SparseILU::AdditionalData()); - - InverseMatrix,SparseILU > - m_inverse (pressure_mass_matrix, pmass_preconditioner); - - BlockSchurPreconditioner::type, - SparseILU > - preconditioner (system_matrix, m_inverse, *A_preconditioner); - - SolverControl solver_control (system_matrix.m(), - 1e-6*system_rhs.l2_norm()); - GrowingVectorMemory > vector_memory; - SolverGMRES >::AdditionalData gmres_data; - gmres_data.max_n_tmp_vectors = 100; - - SolverGMRES > gmres(solver_control, vector_memory, - gmres_data); - - gmres.solve(system_matrix, solution, system_rhs, - preconditioner); - - constraints.distribute (solution); - - std::cout << " " - << solver_control.last_step() - << " block GMRES iterations"; -} - - template class SchurComplementSmoother { @@ -810,8 +769,17 @@ vmult (BlockVector &dst, m_inverse (system_matrix->block(1,1), preconditioner); - cg.solve (schur_complement, dst.block(1), schur_rhs, - m_inverse); + try + { + cg.solve (schur_complement, dst.block(1), schur_rhs, + m_inverse); + } + catch (...) + { + std::cout << "Failure in " << __PRETTY_FUNCTION__ << std::endl; + std::cout << schur_rhs.l2_norm () << std::endl; + abort (); + } // no constraints to be taken care of here @@ -855,7 +823,7 @@ Tvmult (BlockVector &, template -void StokesProblem::solve_mg () +void StokesProblem::solve () { assemble_multigrid (); typedef PreconditionMG, MGTransferPrebuilt > > @@ -915,10 +883,16 @@ void StokesProblem::solve_mg () gmres_data); // PreconditionIdentity precondition_identity; - gmres.solve(system_matrix, solution, system_rhs, - preconditioner); - //gmres.solve(system_matrix, solution, system_rhs, - // precondition_identity); + try + { + gmres.solve(system_matrix, solution, system_rhs, + preconditioner); + } + catch (...) + { + std::cout << "Failure in " << __PRETTY_FUNCTION__ << std::endl; + abort (); + } constraints.distribute (solution); @@ -928,140 +902,6 @@ void StokesProblem::solve_mg () } -template -void StokesProblem::solve_schur () -{ - const InverseMatrix, - typename InnerPreconditioner::type> - A_inverse (system_matrix.block(0,0), *A_preconditioner); - Vector tmp (solution.block(0).size()); - - - { - Vector schur_rhs (solution.block(1).size()); - A_inverse.vmult (tmp, system_rhs.block(0)); - system_matrix.block(1,0).vmult (schur_rhs, tmp); - schur_rhs -= system_rhs.block(1); - - SchurComplement::type> - schur_complement (system_matrix, A_inverse); - - // The usual control structures for - // the solver call are created... - SolverControl solver_control (solution.block(1).size(), - 1e-6*schur_rhs.l2_norm()); - SolverCG<> cg (solver_control); - - - - SparseILU preconditioner; - preconditioner.initialize (system_matrix.block(1,1), - SparseILU::AdditionalData()); - - InverseMatrix,SparseILU > - m_inverse (system_matrix.block(1,1), preconditioner); - - - cg.solve (schur_complement, solution.block(1), schur_rhs, - m_inverse); - - - constraints.distribute (solution); - - std::cout << " " - << solver_control.last_step() - << " outer CG Schur complement iterations for pressure" - << std::flush - << std::endl; - } - - - { - system_matrix.block(0,1).vmult (tmp, solution.block(1)); - tmp *= -1; - tmp += system_rhs.block(0); - - A_inverse.vmult (solution.block(0), tmp); - - constraints.distribute (solution); - } - - -} - - -template -void StokesProblem::find_dofs_on_lower_level (std::vector > &dof_lower_level, - std::vector > &boundary_dof_lower_level) -{ - const unsigned int dofs_per_cell = fe.dofs_per_cell; - const unsigned int dofs_per_face = fe.dofs_per_face; - - std::vector local_dof_indices (dofs_per_cell); - std::vector face_dof_indices (dofs_per_face); - - typename MGDoFHandler::cell_iterator cell = dof_handler.begin(), - endc = dof_handler.end(); - - for (; cell!=endc; ++cell) - { - std::vector cell_dofs(dofs_per_cell); - std::vector boundary_cell_dofs(dofs_per_cell); - const unsigned int level = cell->level(); - cell->get_mg_dof_indices (local_dof_indices); - for (unsigned int face_nr=0; - face_nr::faces_per_cell; ++face_nr) - { - typename DoFHandler::face_iterator face = cell->face(face_nr); - if(!cell->at_boundary(face_nr)) - { - //interior face - typename MGDoFHandler::cell_iterator neighbor - = cell->neighbor(face_nr); - // Do refinement face - // from the coarse side - if (neighbor->level() < cell->level()) - { - for(unsigned int j=0; j::faces_per_cell; ++inner_face_nr) - { - const unsigned int neighbor_face_nr = (face_nr+inner_face_nr)%GeometryInfo::faces_per_cell; - if(!cell->at_boundary(neighbor_face_nr)) - { - //other face is interior - typename MGDoFHandler::cell_iterator neighbor - = cell->neighbor(neighbor_face_nr); - // Do refinement face - // from the coarse side - if (neighbor->level() < cell->level()) - { - for(unsigned int j=0; j void @@ -1164,7 +1004,7 @@ void StokesProblem::run () assemble_system (); std::cout << " Solving..." << std::flush; - solve_mg (); + solve (); output_results (refinement_cycle);