From de3a841400ce86a9e2a0519b2bb280a0d9e4ab58 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Mon, 1 May 2000 13:31:05 +0000 Subject: [PATCH] continuing on MG git-svn-id: https://svn.dealii.org/trunk@2776 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/multigrid/multigrid.templates.h | 17 +++--- deal.II/deal.II/source/multigrid/mg_base.cc | 11 ++-- tests/deal.II/mglocal.cc | 54 ++++++++----------- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/deal.II/deal.II/include/multigrid/multigrid.templates.h b/deal.II/deal.II/include/multigrid/multigrid.templates.h index c11731dc35..51384d716e 100644 --- a/deal.II/deal.II/include/multigrid/multigrid.templates.h +++ b/deal.II/deal.II/include/multigrid/multigrid.templates.h @@ -117,7 +117,8 @@ Multigrid::copy_to_mg (const Vector& osrc) // Delete values on refinement edge, // since restriction will add them again. for (unsigned int i=0; i::print_vector (const unsigned int level, const Vector& v, const char* name) const { - Vector out_vector; - const DoFHandler* dof = mg_dof_handler; + Vector out_vector(dof->n_dofs()); + + out_vector = -10000; + const unsigned int dofs_per_cell = mg_dof_handler->get_fe().dofs_per_cell; vector global_dof_indices (dofs_per_cell); vector level_dof_indices (dofs_per_cell); - DoFHandler::cell_iterator - global_cell = dof->begin(level); - MGDoFHandler::cell_iterator - level_cell = mg_dof_handler->begin(level); + DoFHandler::active_cell_iterator + global_cell = dof->begin_active(level); + MGDoFHandler::active_cell_iterator + level_cell = mg_dof_handler->begin_active(level); const MGDoFHandler::cell_iterator endc = mg_dof_handler->end(level); diff --git a/deal.II/deal.II/source/multigrid/mg_base.cc b/deal.II/deal.II/source/multigrid/mg_base.cc index 630e8c3ef1..cc3bd3c254 100644 --- a/deal.II/deal.II/source/multigrid/mg_base.cc +++ b/deal.II/deal.II/source/multigrid/mg_base.cc @@ -43,7 +43,7 @@ MGBase::vcycle(const MGSmootherBase &pre_smooth, const MGCoarseGridSolver &coarse_grid_solver) { level_mgstep (maxlevel, pre_smooth, post_smooth, coarse_grid_solver); - abort (); +// abort (); } @@ -63,6 +63,8 @@ MGBase::level_mgstep(const unsigned int level, if (level == minlevel) { coarse_grid_solver(level, solution[level], defect[level]); + sprintf(name, "MG%d-solution",level); + print_vector(level, solution[level], name); return; } @@ -99,13 +101,14 @@ MGBase::level_mgstep(const unsigned int level, solution[level] += t; - // smoothing (modify solution again) -//TODO: what happens here? smooth overwrites the solution[level], -//TODO: so the previous two statements should have no effect. No? + // post-smoothing + post_smooth.smooth(level, solution[level], defect[level]); sprintf(name, "MG%d-post",level); print_vector(level, solution[level], name); + + delete[] name; } diff --git a/tests/deal.II/mglocal.cc b/tests/deal.II/mglocal.cc index 35312ffb1d..e2294b4372 100644 --- a/tests/deal.II/mglocal.cc +++ b/tests/deal.II/mglocal.cc @@ -104,12 +104,12 @@ int main() cell->set_refine_flag(); tr.execute_coarsening_and_refinement(); - tr.refine_global(1); + tr.refine_global(2); dof.distribute_dofs(*fe); const unsigned int size = dof.n_dofs(); deallog << "DoFs " << size << endl; deallog << "Levels: " << tr.n_levels() << endl; - for (unsigned int step=1;step < 5; ++step) + for (unsigned int step=14;step < 15; ++step) { deallog << "smoothing-steps" << step << endl; SparsityPattern structure(size, dof.max_couplings_between_dofs()); @@ -130,6 +130,16 @@ int main() hanging_nodes.condense(A); hanging_nodes.condense(f); + if (true) + { + ofstream out_file("MGf"); + DataOut<2> out; + out.attach_dof_handler(dof); + out.add_data_vector(f, "v"); + out.build_patches(5); + out.write_gnuplot(out_file); + } + Vector u; u.reinit(f); PrimitiveVectorMemory<> mem; @@ -149,7 +159,7 @@ int main() } equation.build_mgmatrix(mgA, mgdof, quadrature); - SolverControl cgcontrol(20,0., false, false); + SolverControl cgcontrol(2000,1.e-14, false, false); PrimitiveVectorMemory<> cgmem; SolverCG<> cgsolver(cgcontrol, cgmem); PreconditionIdentity cgprec; @@ -175,11 +185,18 @@ Multigrid<2> multigrid(mgdof, hanging_nodes, mgstruct, mgA, transfer, tr.n_level hanging_nodes.distribute(u); DataOut<2> out; - ofstream ofile("out.gnuplot"); + char* name = new char[100]; + + sprintf(name, "MG-Q%d-%d", degree, step); + + ofstream ofile(name); out.attach_dof_handler(dof); out.add_data_vector(u,"u"); - out.build_patches(4); + out.add_data_vector(f,"f"); + out.build_patches(5); out.write_gnuplot(ofile); + + delete[] name; } deallog.pop(); } @@ -190,34 +207,9 @@ double RHSFunction::value (const Point&p, const unsigned int) const { -// return 1.; + return 1.; return p(0)*p(0)+p(1)*p(1); return (2.1)*(sin(p(0))* sin(p(1))); } - - -void write_gnuplot (const MGDoFHandler<2>& dofs, const Vector& v, unsigned int level, - ostream &out) -{ - MGDoFHandler<2>::cell_iterator cell; - MGDoFHandler<2>::cell_iterator endc = dofs.end(level); - - Vector values(dofs.get_fe().dofs_per_cell); - - unsigned int cell_index=0; - for (cell=dofs.begin(level); cell!=endc; ++cell, ++cell_index) - { - cell->get_mg_dof_values(v, values); - - out << cell->vertex(0) << " " << values(0) << endl; - out << cell->vertex(1) << " " << values(1) << endl; - out << endl; - out << cell->vertex(3) << " " << values(3) << endl; - out << cell->vertex(2) << " " << values(2) << endl; - out << endl; - out << endl; - } - out << endl; -} -- 2.39.5