From: guido Date: Wed, 26 Sep 2001 14:17:13 +0000 (+0000) Subject: enable disabling of multigrid X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aae463f1d9b2d4635b36934e6fa29af63529a3ce;p=dealii-svn.git enable disabling of multigrid git-svn-id: https://svn.dealii.org/trunk@5104 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/source/dofs/dof_renumbering.cc b/deal.II/deal.II/source/dofs/dof_renumbering.cc index 6dfeda85d0..33484dea77 100644 --- a/deal.II/deal.II/source/dofs/dof_renumbering.cc +++ b/deal.II/deal.II/source/dofs/dof_renumbering.cc @@ -25,11 +25,14 @@ #include #include #include +#include +#include + +#ifdef ENABLE_MULTIGRID #include #include #include -#include -#include +#endif #include #include @@ -263,6 +266,7 @@ void DoFRenumbering::Cuthill_McKee (DoFHandler &dof_handler }; +#ifdef ENABLE_MULTIGRID template void DoFRenumbering::Cuthill_McKee (MGDoFHandler &dof_handler, const unsigned int level, @@ -427,7 +431,7 @@ void DoFRenumbering::Cuthill_McKee (MGDoFHandler &dof_handler // thus needs an own function dof_handler.renumber_dofs (level, new_number); }; - +#endif template @@ -616,7 +620,7 @@ DoFRenumbering::cell_wise_dg (DoFHandler& dof, } - +#ifdef ENABLE_MULTIGRID template void DoFRenumbering::cell_wise_dg (MGDoFHandler& dof, @@ -670,6 +674,7 @@ DoFRenumbering::cell_wise_dg (MGDoFHandler& dof, dof.renumber_dofs(level, reverse); } +#endif /** * Provide comparator for DoFCellAccessors @@ -720,7 +725,7 @@ DoFRenumbering::downstream_dg (DoFHandler& dof, } - +#ifdef ENABLE_MULTIGRID template void DoFRenumbering::downstream_dg (MGDoFHandler& dof, @@ -739,7 +744,7 @@ DoFRenumbering::downstream_dg (MGDoFHandler& dof, cell_wise_dg(dof, level, ordered_cells); } - +#endif template @@ -766,12 +771,6 @@ void DoFRenumbering::Cuthill_McKee (DoFHandler&, const bool, const std::vector&); -template -void DoFRenumbering::Cuthill_McKee (MGDoFHandler&, - const unsigned int, - const bool, - const std::vector&); - template void DoFRenumbering::component_wise (DoFHandler&, const std::vector&); @@ -781,23 +780,31 @@ template void DoFRenumbering::cell_wise_dg (DoFHandler&, const std::vector::cell_iterator>&); -template -void DoFRenumbering::cell_wise_dg (MGDoFHandler&, - const unsigned int, - const std::vector::cell_iterator>&); - template void DoFRenumbering::downstream_dg (DoFHandler&, const Point&); -template -void DoFRenumbering::downstream_dg (MGDoFHandler&, - const unsigned int, - const Point&); - template void DoFRenumbering::sort_selected_dofs_back (DoFHandler &, const std::vector &); template void DoFRenumbering::random (DoFHandler &); + +#ifdef ENABLE_MULTIGRID +template +void DoFRenumbering::Cuthill_McKee (MGDoFHandler&, + const unsigned int, + const bool, + const std::vector&); +template +void DoFRenumbering::cell_wise_dg (MGDoFHandler&, + const unsigned int, + const std::vector::cell_iterator>&); + +template +void DoFRenumbering::downstream_dg (MGDoFHandler&, + const unsigned int, + const Point&); + +#endif diff --git a/deal.II/deal.II/source/dofs/dof_tools.cc b/deal.II/deal.II/source/dofs/dof_tools.cc index 29b164b480..0ebc434783 100644 --- a/deal.II/deal.II/source/dofs/dof_tools.cc +++ b/deal.II/deal.II/source/dofs/dof_tools.cc @@ -21,8 +21,6 @@ #include #include #include -#include -#include #include #include #include @@ -31,6 +29,11 @@ #include #include +#ifdef ENABLE_MULTIGRID +#include +#include +#endif + #include #include @@ -899,6 +902,7 @@ DoFTools::extract_dofs (const DoFHandler &dof, } +#ifdef ENABLE_MULTIGRID template void DoFTools::extract_level_dofs(const unsigned int level, @@ -929,7 +933,7 @@ DoFTools::extract_level_dofs(const unsigned int level, } } } - +#endif #if deal_II_dimension != 1 @@ -2341,11 +2345,13 @@ DoFTools::distribute_cell_to_dof_vector (const DoFHandler &do template void DoFTools::extract_dofs(const DoFHandler& dof, const std::vector& component_select, std::vector& selected_dofs); + +#ifdef ENABLE_MULTIGRID template void DoFTools::extract_level_dofs(const unsigned int level, const MGDoFHandler& dof, const std::vector& component_select, std::vector& selected_dofs); - +#endif #if deal_II_dimension != 1 template diff --git a/deal.II/deal.II/source/grid/intergrid_map.cc b/deal.II/deal.II/source/grid/intergrid_map.cc index b39b094a9d..6fa4bf0b68 100644 --- a/deal.II/deal.II/source/grid/intergrid_map.cc +++ b/deal.II/deal.II/source/grid/intergrid_map.cc @@ -19,11 +19,13 @@ #include #include #include -#include -#include #include #include +#ifdef ENABLE_MULTIGRID +#include +#include +#endif // helper function to aquire the number of levels within a grid template @@ -215,6 +217,7 @@ InterGridMap::memory_consumption () const // explicit instantiations template class InterGridMap; template class InterGridMap; -template class InterGridMap; - +#ifdef ENABLE_MULTIGRID +template class InterGridMap; +#endif diff --git a/tests/multigrid/mg1.cc b/tests/multigrid/mg1.cc new file mode 100644 index 0000000000..453a58ca1e --- /dev/null +++ b/tests/multigrid/mg1.cc @@ -0,0 +1,205 @@ +//---------------------------- mg.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 1998, 1999, 2000, 2001 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- mg.cc --------------------------- + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +MappingQ1<2> mapping; + +#include "helmholtz.h" + +#include + + +template +class RHSFunction : public Function +{ + public: + virtual double value (const Point&, + const unsigned int) const; +}; + + +class MGSmootherLAC : public MGSmootherBase +{ + private: + SmartPointer > >matrices; + public: + MGSmootherLAC(MGLevelObject >&); + + virtual void smooth (const unsigned int level, + Vector &u, + const Vector &rhs) const; + +}; + +int main() +{ + try + { + std::ofstream logfile("mg.output"); + deallog.attach(logfile); + deallog.depth_console(0); + + Helmholtz equation; + RHSFunction<2> rhs; + QGauss5<2> quadrature; + + FE_Q<2> fe1(1); + FE_Q<2> fe2(2); + FE_Q<2> fe3(3); + FE_Q<2> fe4(4); + for (unsigned int degree=1;degree<=3;degree++) + { + Triangulation<2> tr; + MGDoFHandler<2> mgdof(tr); + DoFHandler<2>& dof(mgdof); + + GridGenerator::hyper_cube(tr,-1.,1.); + + FiniteElement<2>* fe; + switch(degree) + { + case 1: fe = &fe1; deallog.push("Q1"); break; + case 2: fe = &fe2; deallog.push("Q2"); break; + case 3: fe = &fe3; deallog.push("Q3"); break; + case 4: fe = &fe4; deallog.push("Q4"); break; + } + + for (unsigned int step=0;step < 3; ++step) + { + tr.refine_global(1); + dof.distribute_dofs(*fe); + + ConstraintMatrix hanging_nodes; + DoFTools::make_hanging_node_constraints(dof, hanging_nodes); + hanging_nodes.close(); + + const unsigned int size = dof.n_dofs(); + deallog << "DoFs " << size << std::endl; + deallog << "Levels: " << tr.n_levels() << std::endl; + + SparsityPattern structure(size, dof.max_couplings_between_dofs()); + DoFTools::make_sparsity_pattern(dof, structure); + structure.compress(); + + SparseMatrix A(structure); + Vector f(size); + + equation.build_all(A,f,dof, quadrature, rhs); + + Vector u; + u.reinit(f); + PrimitiveVectorMemory<> mem; + SolverControl control(1000, 1.e-10,false , true); + SolverCG<> solver(control, mem); + + u = 0.; + MGLevelObject mgstruct(0, tr.n_levels()-1); + MGLevelObject > mgA(0,tr.n_levels()-1); + for (unsigned int i=0;i cgmem; + SolverCG<> cgsolver(cgcontrol, cgmem); + PreconditionIdentity cgprec; + MGCoarseGridLACIteration, SparseMatrix, PreconditionIdentity> + coarse(cgsolver, mgA[0], cgprec); + + MGSmootherLAC smoother(mgA); + MGTransferPrebuilt transfer; + transfer.build_matrices(mgdof); + + +Multigrid<2> multigrid(mgdof, hanging_nodes, mgstruct, mgA, transfer); + PreconditionMG > + mgprecondition(multigrid, smoother, smoother, coarse); + + solver.solve(A, u, f, mgprecondition); + } + deallog.pop(); + } + + } + catch (const SolverControl::NoConvergence& e) + { + deallog << "Step " << e.last_step + << " Residual " << e.last_residual << std::endl; + } +} + +template +double +RHSFunction::value (const Point&, + const unsigned int) const +{ + return 1.; +} + +MGSmootherLAC::MGSmootherLAC(MGLevelObject >& matrix) + : + matrices(&matrix) +{} + +void +MGSmootherLAC::smooth (const unsigned int level, + Vector &u, + const Vector &rhs) const +{ + SolverControl control(2,1.e-300,false,false); + PrimitiveVectorMemory<> mem; + SolverRichardson<> rich(control, mem); + PreconditionSSOR<> prec; + prec.initialize((*matrices)[level], 1.); + + try + { + rich.solve((*matrices)[level], u, rhs, prec); + } + catch (const SolverControl::NoConvergence&) + { + } +} diff --git a/tests/multigrid/mg1.checked b/tests/multigrid/mg1.checked new file mode 100644 index 0000000000..60791912fc --- /dev/null +++ b/tests/multigrid/mg1.checked @@ -0,0 +1,37 @@ + +DEAL:Q1::DoFs 9 +DEAL:Q1::Levels: 2 +DEAL:Q1:cg::Starting +DEAL:Q1:cg::Convergence step 3 +DEAL:Q1::DoFs 25 +DEAL:Q1::Levels: 3 +DEAL:Q1:cg::Starting +DEAL:Q1:cg::Convergence step 4 +DEAL:Q1::DoFs 81 +DEAL:Q1::Levels: 4 +DEAL:Q1:cg::Starting +DEAL:Q1:cg::Convergence step 5 +DEAL:Q2::DoFs 25 +DEAL:Q2::Levels: 2 +DEAL:Q2:cg::Starting +DEAL:Q2:cg::Convergence step 5 +DEAL:Q2::DoFs 81 +DEAL:Q2::Levels: 3 +DEAL:Q2:cg::Starting +DEAL:Q2:cg::Convergence step 6 +DEAL:Q2::DoFs 289 +DEAL:Q2::Levels: 4 +DEAL:Q2:cg::Starting +DEAL:Q2:cg::Convergence step 6 +DEAL:Q3::DoFs 49 +DEAL:Q3::Levels: 2 +DEAL:Q3:cg::Starting +DEAL:Q3:cg::Convergence step 6 +DEAL:Q3::DoFs 169 +DEAL:Q3::Levels: 3 +DEAL:Q3:cg::Starting +DEAL:Q3:cg::Convergence step 6 +DEAL:Q3::DoFs 625 +DEAL:Q3::Levels: 4 +DEAL:Q3:cg::Starting +DEAL:Q3:cg::Convergence step 6