From: Guido Kanschat Date: Sun, 30 Apr 2000 15:51:40 +0000 (+0000) Subject: debugging MG, mglocal.testcase produces errors, sorry X-Git-Tag: v8.0.0~20628 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac748daf62dee3b2c84d1fcda4339e878b10569c;p=dealii.git debugging MG, mglocal.testcase produces errors, sorry git-svn-id: https://svn.dealii.org/trunk@2775 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/multigrid/mg_base.h b/deal.II/deal.II/include/multigrid/mg_base.h index 4d6b2e755e..4e0396528e 100644 --- a/deal.II/deal.II/include/multigrid/mg_base.h +++ b/deal.II/deal.II/include/multigrid/mg_base.h @@ -391,7 +391,15 @@ class MGBase : public Subscriptor Vector &dst, const Vector &src, const Vector &rhs) = 0; - + + /** + * Print a level vector using + * @ref{DoFHandler}. + */ + virtual void print_vector (const unsigned int level, + const Vector& v, + const char* name) const = 0; + private: /** * Auxiliary vector. diff --git a/deal.II/deal.II/include/multigrid/multigrid.h b/deal.II/deal.II/include/multigrid/multigrid.h index 7cfa21e1ae..1098c4fb96 100644 --- a/deal.II/deal.II/include/multigrid/multigrid.h +++ b/deal.II/deal.II/include/multigrid/multigrid.h @@ -105,6 +105,14 @@ class Multigrid : public MGBase const Vector &src, const Vector &rhs); + /** + * Print a level vector using + * @ref{DoFHandler}. + */ + virtual void print_vector (const unsigned int level, + const Vector& v, + const char* name) const; + /** * Read-only access to level matrices. */ diff --git a/deal.II/deal.II/include/multigrid/multigrid.templates.h b/deal.II/deal.II/include/multigrid/multigrid.templates.h index 77d7be4f8b..c11731dc35 100644 --- a/deal.II/deal.II/include/multigrid/multigrid.templates.h +++ b/deal.II/deal.II/include/multigrid/multigrid.templates.h @@ -15,6 +15,7 @@ #include +#include #include #include #include @@ -154,6 +155,9 @@ Multigrid::copy_from_mg(Vector &dst) const // traverse all cells and copy the // data appropriately to the output // vector + + // Is the level monotonuosly increasing? + for (; level_cell != endc; ++level_cell, ++global_cell) { const unsigned int level = level_cell->level(); @@ -176,4 +180,51 @@ Multigrid::copy_from_mg(Vector &dst) const } + +template +void +Multigrid::print_vector (const unsigned int level, + const Vector& v, + const char* name) const +{ + Vector out_vector; + + const DoFHandler* dof = mg_dof_handler; + + 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); + const MGDoFHandler::cell_iterator + endc = mg_dof_handler->end(level); + + // traverse all cells and copy the + // data appropriately to the output + // vector + for (; level_cell != endc; ++level_cell, ++global_cell) + { + global_cell->get_dof_indices (global_dof_indices); + level_cell->get_mg_dof_indices(level_dof_indices); + + // copy level-wise data to + // global vector + for (unsigned int i=0; i out; + out.attach_dof_handler(*dof); + out.add_data_vector(out_vector, "v"); + out.build_patches(5); + out.write_gnuplot(out_file); +} + #endif + diff --git a/deal.II/deal.II/source/multigrid/mg_base.cc b/deal.II/deal.II/source/multigrid/mg_base.cc index 9b9e927d3b..630e8c3ef1 100644 --- a/deal.II/deal.II/source/multigrid/mg_base.cc +++ b/deal.II/deal.II/source/multigrid/mg_base.cc @@ -18,33 +18,8 @@ #include -//TODO: this function is only for debugging purposes and should be removed sometimes -template -static -void print_vector(ostream& s, const VECTOR& v, const char* text) -{ - const unsigned int n = (unsigned int)(sqrt(v.size())+.3); - unsigned int k=0; - - s << endl << "splot '-' title '" << text << "'" << endl; - - // write the vector entries in a - // kind of square - for (unsigned int i=0;irestrict_and_add (level, defect[level-1], t); -// print_vector(cout,defect[level-1],"Dl-1"); // do recursion level_mgstep(level-1, pre_smooth, post_smooth, coarse_grid_solver); @@ -111,16 +91,22 @@ MGBase::level_mgstep(const unsigned int level, t.reinit(solution[level].size()); // do coarse grid correction -// print_vector(cout,solution[level-1],"Sl-1"); + transfer->prolongate(level, t, solution[level-1]); -// print_vector(cout,t,"T"); + + sprintf(name, "MG%d-cgc",level); + print_vector(level, t, name); + 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_smooth.smooth(level, solution[level], defect[level]); -}; + + sprintf(name, "MG%d-post",level); + print_vector(level, solution[level], name); +} ////////////////////////////////////////////////////////////////////// diff --git a/tests/deal.II/Makefile.in b/tests/deal.II/Makefile.in index d9a50cd784..167c34ce06 100644 --- a/tests/deal.II/Makefile.in +++ b/tests/deal.II/Makefile.in @@ -65,7 +65,8 @@ endif @$(CXX) $(flags) -c $< -o $@ -all: grid_test.check dof_test.check fe_tables.check gradients.check \ +all: grid_generator.check grid_test.check dof_test.check \ + fe_tables.check gradients.check \ constraints.check mg.check mglocal.check wave-test-3.check second_derivatives.check exe: $(all:.check=.testcase) benchmark @@ -171,6 +172,21 @@ grid_test.testcase: $(grid_test-o-files) $(libdeal3d) $(libraries) @$(CXX) $(flags) -o $@ $^ +############################################################ + +grid_generator-cc-files = grid_generator.cc + +ifeq ($(debug-mode),on) +grid_generator-o-files = $(grid_generator-cc-files:.cc=.go) +else +grid_generator-o-files = $(grid_generator-cc-files:.cc=.o) +endif + +grid_generator.testcase: $(grid_generator-o-files) $(libdeal3d) $(libraries) + @echo =====linking======= $< + @$(CXX) $(flags) -o $@ $^ + + ############################################################ second_derivatives-cc-files = second_derivatives.cc diff --git a/tests/deal.II/mglocal.cc b/tests/deal.II/mglocal.cc index 5c7ca30739..35312ffb1d 100644 --- a/tests/deal.II/mglocal.cc +++ b/tests/deal.II/mglocal.cc @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -69,10 +69,10 @@ extern void write_gnuplot (const MGDoFHandler<2>& dofs, int main() { ofstream logfile("mglocal.output"); - logfile.setf(ios::fixed); - logfile.precision (3); +// logfile.setf(ios::fixed); +// logfile.precision (3); deallog.attach(logfile); - deallog.depth_console(0); +// deallog.depth_console(0); Helmholtz equation; RHSFunction<2> rhs; @@ -82,7 +82,7 @@ int main() FEQ2<2> fe2; FEQ3<2> fe3; FEQ4<2> fe4; - for (unsigned int degree=1;degree<=1;degree++) + for (unsigned int degree=1;degree<=4;degree++) { Triangulation<2> tr; MGDoFHandler<2> mgdof(tr); @@ -104,7 +104,7 @@ int main() cell->set_refine_flag(); tr.execute_coarsening_and_refinement(); - tr.refine_global(2); + tr.refine_global(1); dof.distribute_dofs(*fe); const unsigned int size = dof.n_dofs(); deallog << "DoFs " << size << endl; @@ -133,8 +133,8 @@ int main() Vector u; u.reinit(f); PrimitiveVectorMemory<> mem; - SolverControl control(20, 1.e-12, true); - SolverRichardson<> solver(control, mem); + SolverControl control(20, 1.e-8, true); + SolverCG<> solver(control, mem); MGLevelObject mgstruct(0, tr.n_levels()-1); MGLevelObject > mgA(0,tr.n_levels()-1); @@ -173,6 +173,13 @@ Multigrid<2> multigrid(mgdof, hanging_nodes, mgstruct, mgA, transfer, tr.n_level solver.solve(A, u, f, mgprecondition); hanging_nodes.distribute(u); + + DataOut<2> out; + ofstream ofile("out.gnuplot"); + out.attach_dof_handler(dof); + out.add_data_vector(u,"u"); + out.build_patches(4); + out.write_gnuplot(ofile); } deallog.pop(); }