From: guido Date: Mon, 10 May 1999 14:58:51 +0000 (+0000) Subject: test mg for Q1-Q4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37ccabeece7f53e0576ed605d7b2841777ac5abc;p=dealii-svn.git test mg for Q1-Q4 git-svn-id: https://svn.dealii.org/trunk@1309 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/deal.II/mg.cc b/tests/deal.II/mg.cc index 29aa26de2b..356fdfbfd3 100644 --- a/tests/deal.II/mg.cc +++ b/tests/deal.II/mg.cc @@ -1,4 +1,5 @@ // $Id$ +/* (c) Guido Kanschat, 1999 */ // deal_II_libraries.g=-ldeal_II_2d.g // deal_II_libraries=-ldeal_II_2d @@ -50,87 +51,95 @@ class MGSmootherLAC }; -main(int argc, const char** argv) +main() { - unsigned int refine; - if (argc<=1) - { - cerr << "Usage:" << argv[0] << " " << endl; - refine = 0; - } - else - refine = atoi(argv[1]); - - Helmholtz equation; RHSFunction<2> rhs; - QGauss3<2> quadrature; - - FELinear<2> fe; - Triangulation<2> tr; - MGDoFHandler<2> mgdof(&tr); - DoFHandler<2>& dof(mgdof); - - GridGenerator::hyper_cube(tr,-1.,1.); - tr.refine_global(refine); - dof.distribute_dofs(fe); - - const unsigned int size = dof.n_dofs(); - - SparseMatrixStruct structure(size, dof.max_couplings_between_dofs()); - dof.make_sparsity_pattern(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(100, 1.e-15); - SolverCG, Vector >solver(control, mem); - - PreconditionIdentity > precondition; - solver.solve(A,u,f,precondition); + QGauss5<2> quadrature; - u = 0.; - vector mgstruct(tr.n_levels()); - MGMatrix > mgA(0,tr.n_levels()-1); - for (unsigned int i=0;i fe1; + FEQ2<2> fe2; + FEQ3<2> fe3; + FEQ4<2> fe4; + for (unsigned int degree=1;degree<=4;degree++) { - mgstruct[i].reinit(mgdof.n_dofs(i), mgdof.n_dofs(i), - mgdof.max_couplings_between_dofs()); - mgdof.make_sparsity_pattern(i, mgstruct[i]); - mgstruct[i].compress(); - - mgA[i].reinit(mgstruct[i]); - } - equation.build_mgmatrix(mgA, mgdof, quadrature); - - SolverControl cgcontrol(10,0., false, false); + Triangulation<2> tr; + MGDoFHandler<2> mgdof(&tr); + DoFHandler<2>& dof(mgdof); - PrimitiveVectorMemory > cgmem; - SolverCG, Vector > cgsolver(cgcontrol, cgmem); - PreconditionIdentity > cgprec; - MGCoarseGridLACIteration, Vector >, - SparseMatrix, PreconditionIdentity > > - coarse(cgsolver, mgA[0], cgprec); - - MGSmootherLAC smoother(mgA); - MGTransferPrebuilt transfer; - transfer.build_matrices(mgdof); - - deallog << "Levels: " << tr.n_levels() << endl; - - MG<2> multigrid(mgdof, mgA, transfer); - PreconditionMG, Vector > - mgprecondition(multigrid, smoother, smoother, coarse); + GridGenerator::hyper_cube(tr,-1.,1.); - solver.solve(A, u, f, mgprecondition); - - cerr << "OK" << endl; + 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 < 5; ++step) + { + tr.refine_global(1); + dof.distribute_dofs(*fe); + + const unsigned int size = dof.n_dofs(); + deallog << "DoFs " << size << endl; + deallog << "Levels: " << tr.n_levels() << endl; + + SparseMatrixStruct structure(size, dof.max_couplings_between_dofs()); + dof.make_sparsity_pattern(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(100, 1.e-12); + SolverCG, Vector >solver(control, mem); + + PreconditionIdentity > precondition; + solver.solve(A,u,f,precondition); + + u = 0.; + vector mgstruct(tr.n_levels()); + MGMatrix > mgA(0,tr.n_levels()-1); + for (unsigned int i=0;i > cgmem; + SolverCG, Vector > cgsolver(cgcontrol, cgmem); + PreconditionIdentity > cgprec; + MGCoarseGridLACIteration, Vector >, + SparseMatrix, PreconditionIdentity > > + coarse(cgsolver, mgA[0], cgprec); + + MGSmootherLAC smoother(mgA); + MGTransferPrebuilt transfer; + transfer.build_matrices(mgdof); + + + MG<2> multigrid(mgdof, mgA, transfer); + PreconditionMG, Vector > + mgprecondition(multigrid, smoother, smoother, coarse); + + solver.solve(A, u, f, mgprecondition); + } + deallog.pop(); + } } template