From f07b5cef4a8a3902ab7f95152429709b2e59f306 Mon Sep 17 00:00:00 2001 From: Baerbel Jannsen Date: Wed, 10 Mar 2010 00:33:36 +0000 Subject: [PATCH] tests on adaptively refined grids git-svn-id: https://svn.dealii.org/trunk@20775 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/multigrid/transfer_system_04.cc | 8 +- tests/multigrid/transfer_system_05.cc | 16 +- .../multigrid/transfer_system_adaptive_01.cc | 33 +-- .../transfer_system_adaptive_01/cmp/generic | 24 --- .../multigrid/transfer_system_adaptive_02.cc | 176 ++++++++++++++++ .../multigrid/transfer_system_adaptive_03.cc | 170 ++++++++++++++++ .../multigrid/transfer_system_adaptive_04.cc | 179 +++++++++++++++++ .../multigrid/transfer_system_adaptive_05.cc | 174 ++++++++++++++++ .../multigrid/transfer_system_adaptive_06.cc | 181 +++++++++++++++++ .../multigrid/transfer_system_adaptive_07.cc | 181 +++++++++++++++++ .../multigrid/transfer_system_adaptive_08.cc | 188 ++++++++++++++++++ .../multigrid/transfer_system_adaptive_09.cc | 175 ++++++++++++++++ 12 files changed, 1445 insertions(+), 60 deletions(-) delete mode 100644 tests/multigrid/transfer_system_adaptive_01/cmp/generic create mode 100644 tests/multigrid/transfer_system_adaptive_02.cc create mode 100644 tests/multigrid/transfer_system_adaptive_03.cc create mode 100644 tests/multigrid/transfer_system_adaptive_04.cc create mode 100644 tests/multigrid/transfer_system_adaptive_05.cc create mode 100644 tests/multigrid/transfer_system_adaptive_06.cc create mode 100644 tests/multigrid/transfer_system_adaptive_07.cc create mode 100644 tests/multigrid/transfer_system_adaptive_08.cc create mode 100644 tests/multigrid/transfer_system_adaptive_09.cc diff --git a/tests/multigrid/transfer_system_04.cc b/tests/multigrid/transfer_system_04.cc index 6f99ca3b1d..468cdc997a 100644 --- a/tests/multigrid/transfer_system_04.cc +++ b/tests/multigrid/transfer_system_04.cc @@ -109,12 +109,12 @@ void check (const FiniteElement& fe) 0, 0, block_component, block_component); - // use only the first half of all - // components std::vector > dofs_per_block(tr.n_levels(), std::vector(2)); MGTools::count_dofs_per_block(mg_dof_handler, dofs_per_block, block_component); - FullMatrix prolong_0_1 (dofs_per_block[1][0],dofs_per_block[0][0]); - FullMatrix prolong_1_2 (dofs_per_block[2][0],dofs_per_block[1][0]); + FullMatrix prolong_0_1 (dofs_per_block[1][0], + dofs_per_block[0][0]); + FullMatrix prolong_1_2 (dofs_per_block[2][0], + dofs_per_block[1][0]); deallog << "Level 0->1" << std::endl; make_matrix (transfer, 1, prolong_0_1); diff --git a/tests/multigrid/transfer_system_05.cc b/tests/multigrid/transfer_system_05.cc index a01524824f..9454c1e24d 100644 --- a/tests/multigrid/transfer_system_05.cc +++ b/tests/multigrid/transfer_system_05.cc @@ -65,8 +65,6 @@ void check (const FiniteElement& fe, const unsigned int selected_block) selected_block, selected_block, block_component, block_component); - // use only the first half of all - // components std::vector dofs_per_block(3); DoFTools::count_dofs_per_block(mg_dof_handler, dofs_per_block, block_component); std::vector > mg_dofs_per_block(tr.n_levels(), std::vector(3)); @@ -102,6 +100,20 @@ void check (const FiniteElement& fe, const unsigned int selected_block) deallog << ' ' << (int) v[l](i); deallog << std::endl; } + + for(unsigned int l=0; l #include #include -#include #include #include #include @@ -88,25 +87,20 @@ void print_matrix (const FullMatrix &m) template void refine_mesh (Triangulation &triangulation) { - bool cell_refined = false; + bool cell_refined = false; for (typename Triangulation::active_cell_iterator cell = triangulation.begin_active(); cell != triangulation.end(); ++cell) { const Point p = cell->center(); bool positive = p(0) > 0; - //if (dim>1 && p(1) <= 0) - // positive = false; - //if (dim>2 && p(2) <= 0) - // positive = false; if (positive) { cell->set_refine_flag(); cell_refined = true; } } - //Wenn nichts verfeinert wurde bisher, global verfeinern! - if(!cell_refined) + if(!cell_refined)//if no cell was selected for refinement, refine global for (typename Triangulation::active_cell_iterator cell = triangulation.begin_active(); cell != triangulation.end(); ++cell) @@ -133,13 +127,6 @@ void check (const FiniteElement& fe) GridGenerator::subdivided_hyper_rectangle (tr, subdivisions, bottom_left, top_right, true); refine_mesh(tr); -// tr.refine_global(1); - std::ostringstream out_filename; - out_filename<< "gitter.eps"; - std::ofstream grid_output(out_filename.str().c_str()); - GridOut grid_out; - grid_out.write_eps (tr, grid_output); - MGDoFHandler mg_dof_handler(tr); mg_dof_handler.distribute_dofs(fe); @@ -156,29 +143,15 @@ void check (const FiniteElement& fe) for (unsigned int level=0; level > boundary_indices(tr.n_levels()); - typename FunctionMap::type dirichlet_boundary; - ZeroFunction dirichlet_bc(fe.n_components()); - dirichlet_boundary[0] = &dirichlet_bc; - - MGTools::make_boundary_list (mg_dof_handler, dirichlet_boundary, - boundary_indices); - MGTransferPrebuilt > transfer; - transfer.build_matrices(mg_dof_handler);//, boundary_indices); + transfer.build_matrices(mg_dof_handler); FullMatrix prolong_0_1 (mg_dof_handler.n_dofs(1), mg_dof_handler.n_dofs(0)); -// FullMatrix prolong_1_2 (mg_dof_handler.n_dofs(2), -// mg_dof_handler.n_dofs(1)); deallog << "Level 0->1" << std::endl; make_matrix (transfer, 1, prolong_0_1); print_matrix (prolong_0_1); - - //deallog << "Level 1->2" << std::endl; - //make_matrix (transfer, 2, prolong_1_2); - //print_matrix (prolong_1_2); } diff --git a/tests/multigrid/transfer_system_adaptive_01/cmp/generic b/tests/multigrid/transfer_system_adaptive_01/cmp/generic deleted file mode 100644 index 5e104addf1..0000000000 --- a/tests/multigrid/transfer_system_adaptive_01/cmp/generic +++ /dev/null @@ -1,24 +0,0 @@ - -DEAL::FESystem<2>[FE_Q<2>(1)^2] -DEAL::Global dofs: 22 -DEAL::Level 0 dofs: 12 -DEAL::Level 1 dofs: 18 -DEAL::Level 0->1 -DEAL::0 1.000 0 0 0 0 0 0 0 0 0 0 -DEAL::0 0.5000 0 0 0.5000 0 0 0 0 0 0 0 -DEAL::0 0.5000 0 0.5000 0 0 0 0 0 0 0 0 -DEAL::0 0.2500 0 0.2500 0.2500 0.2500 0 0 0 0 0 0 -DEAL::0 0 0 0 1.000 0 0 0 0 0 0 0 -DEAL::0 0 0 0 0.5000 0.5000 0 0 0 0 0 0 -DEAL::0 0 0 1.000 0 0 0 0 0 0 0 0 -DEAL::0 0 0 0.5000 0 0.5000 0 0 0 0 0 0 -DEAL::0 0 0 0 0 1.000 0 0 0 0 0 0 -DEAL::0 0 0 0 0 0 0 1.000 0 0 0 0 -DEAL::0 0 0 0 0 0 0 0.5000 0 0 0.5000 0 -DEAL::0 0 0 0 0 0 0 0.5000 0 0.5000 0 0 -DEAL::0 0 0 0 0 0 0 0.2500 0 0.2500 0.2500 0.2500 -DEAL::0 0 0 0 0 0 0 0 0 0 1.000 0 -DEAL::0 0 0 0 0 0 0 0 0 0 0.5000 0.5000 -DEAL::0 0 0 0 0 0 0 0 0 1.000 0 0 -DEAL::0 0 0 0 0 0 0 0 0 0.5000 0 0.5000 -DEAL::0 0 0 0 0 0 0 0 0 0 0 1.000 diff --git a/tests/multigrid/transfer_system_adaptive_02.cc b/tests/multigrid/transfer_system_adaptive_02.cc new file mode 100644 index 0000000000..1529df157b --- /dev/null +++ b/tests/multigrid/transfer_system_adaptive_02.cc @@ -0,0 +1,176 @@ +//---------------------------------------------------------------------------- +// transfer.cc,v 1.13 2005/12/30 16:07:03 guido Exp +// Version: +// +// Copyright (C) 2000 - 2007, 2009, 2010 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. +// +//---------------------------------------------------------------------------- + +// test like _01 but with boundary conditions +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + +template +void +reinit_vector (const dealii::MGDoFHandler &mg_dof, + MGLevelObject > &v) +{ + for (unsigned int level=v.get_minlevel(); + level<=v.get_maxlevel();++level) + { + unsigned int n = mg_dof.n_dofs (level); + v[level].reinit(n); + } + +} + + +template +void +make_matrix (const Transfer &transfer, + const unsigned int high_level, + FullMatrix &matrix) +{ + Vector src (matrix.n()); + Vector dst (matrix.m()); + for (unsigned int i=0; i &m) +{ + for (unsigned int i=0; i +void refine_mesh (Triangulation &triangulation) +{ + bool cell_refined = false; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + const Point p = cell->center(); + bool positive = p(0) > 0; + if (positive) + { + cell->set_refine_flag(); + cell_refined = true; + } + } + if(!cell_refined)//if no cell was selected for refinement, refine global + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + cell->set_refine_flag(); + triangulation.execute_coarsening_and_refinement (); +} + + + +template +void check (const FiniteElement& fe) +{ + deallog << fe.get_name() << std::endl; + + Triangulation tr; + + std::vector subdivisions (dim, 1); + subdivisions[0] = 2; + + const Point bottom_left = (dim == 2 ? + Point(-1,-1) : Point(-1,-1,-1)); + const Point top_right = (dim == 2 ? + Point(1,1) : Point(1,1,1)); + GridGenerator::subdivided_hyper_rectangle (tr, + subdivisions, bottom_left, top_right, true); + refine_mesh(tr); + + MGDoFHandler mg_dof_handler(tr); + mg_dof_handler.distribute_dofs(fe); + + deallog << "Global dofs: " << mg_dof_handler.n_dofs() << std::endl; + for(unsigned int l=0; l > boundary_indices(tr.n_levels()); + typename FunctionMap::type dirichlet_boundary; + ZeroFunction dirichlet_bc(fe.n_components()); + dirichlet_boundary[3] = &dirichlet_bc; + + MGTools::make_boundary_list (mg_dof_handler, dirichlet_boundary, + boundary_indices); + + MGTransferPrebuilt > transfer; + transfer.build_matrices(mg_dof_handler, boundary_indices); + + FullMatrix prolong_0_1 (mg_dof_handler.n_dofs(1), + mg_dof_handler.n_dofs(0)); + + deallog << "Level 0->1" << std::endl; + make_matrix (transfer, 1, prolong_0_1); + print_matrix (prolong_0_1); +} + + +int main() +{ + std::ofstream logfile("transfer_system_adaptive_02/output"); + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + +//TODO: do in 1d + check (FESystem<2>(FE_Q<2>(1),2)); +} diff --git a/tests/multigrid/transfer_system_adaptive_03.cc b/tests/multigrid/transfer_system_adaptive_03.cc new file mode 100644 index 0000000000..28cb3820e7 --- /dev/null +++ b/tests/multigrid/transfer_system_adaptive_03.cc @@ -0,0 +1,170 @@ +//---------------------------------------------------------------------------- +// transfer.cc,v 1.13 2005/12/30 16:07:03 guido Exp +// Version: +// +// Copyright (C) 2000 - 2007, 2009, 2010 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. +// +//---------------------------------------------------------------------------- + +// test like _01 but with TransferSelect + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + +template +void +reinit_vector (const dealii::MGDoFHandler &mg_dof, + MGLevelObject > &v) +{ + for (unsigned int level=v.get_minlevel(); + level<=v.get_maxlevel();++level) + { + unsigned int n = mg_dof.n_dofs (level); + v[level].reinit(n); + } + +} + + +template +void +make_matrix (const Transfer &transfer, + const unsigned int high_level, + FullMatrix &matrix) +{ + Vector src (matrix.n()); + Vector dst (matrix.m()); + for (unsigned int i=0; i &m) +{ + for (unsigned int i=0; i +void refine_mesh (Triangulation &triangulation) +{ + bool cell_refined = false; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + const Point p = cell->center(); + bool positive = p(0) > 0; + if (positive) + { + cell->set_refine_flag(); + cell_refined = true; + } + } + if(!cell_refined)//if no cell was selected for refinement, refine global + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + cell->set_refine_flag(); + triangulation.execute_coarsening_and_refinement (); +} + + + +template +void check (const FiniteElement& fe) +{ + deallog << fe.get_name() << std::endl; + + Triangulation tr; + + std::vector subdivisions (dim, 1); + subdivisions[0] = 2; + + const Point bottom_left = (dim == 2 ? + Point(-1,-1) : Point(-1,-1,-1)); + const Point top_right = (dim == 2 ? + Point(1,1) : Point(1,1,1)); + GridGenerator::subdivided_hyper_rectangle (tr, + subdivisions, bottom_left, top_right, true); + refine_mesh(tr); + + MGDoFHandler mg_dof_handler(tr); + mg_dof_handler.distribute_dofs(fe); + + deallog << "Global dofs: " << mg_dof_handler.n_dofs() << std::endl; + for(unsigned int l=0; l block_selected(2,0U); + MGTransferSelect transfer; + transfer.build_matrices(mg_dof_handler, mg_dof_handler, 0, 0, block_selected, block_selected); + + FullMatrix prolong_0_1 (mg_dof_handler.n_dofs(1), + mg_dof_handler.n_dofs(0)); + + deallog << "Level 0->1" << std::endl; + make_matrix (transfer, 1, prolong_0_1); + print_matrix (prolong_0_1); +} + + +int main() +{ + std::ofstream logfile("transfer_system_adaptive_03/output"); + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + +//TODO: do in 1d + check (FESystem<2>(FE_Q<2>(1),2)); +} diff --git a/tests/multigrid/transfer_system_adaptive_04.cc b/tests/multigrid/transfer_system_adaptive_04.cc new file mode 100644 index 0000000000..824b944f66 --- /dev/null +++ b/tests/multigrid/transfer_system_adaptive_04.cc @@ -0,0 +1,179 @@ +//---------------------------------------------------------------------------- +// transfer.cc,v 1.13 2005/12/30 16:07:03 guido Exp +// Version: +// +// Copyright (C) 2000 - 2007, 2009, 2010 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. +// +//---------------------------------------------------------------------------- + +// test like _03 but with boundary conditions +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + +template +void +reinit_vector (const dealii::MGDoFHandler &mg_dof, + MGLevelObject > &v) +{ + for (unsigned int level=v.get_minlevel(); + level<=v.get_maxlevel();++level) + { + unsigned int n = mg_dof.n_dofs (level); + v[level].reinit(n); + } + +} + + +template +void +make_matrix (const Transfer &transfer, + const unsigned int high_level, + FullMatrix &matrix) +{ + Vector src (matrix.n()); + Vector dst (matrix.m()); + for (unsigned int i=0; i &m) +{ + for (unsigned int i=0; i +void refine_mesh (Triangulation &triangulation) +{ + bool cell_refined = false; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + const Point p = cell->center(); + bool positive = p(0) > 0; + if (positive) + { + cell->set_refine_flag(); + cell_refined = true; + } + } + if(!cell_refined)//if no cell was selected for refinement, refine global + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + cell->set_refine_flag(); + triangulation.execute_coarsening_and_refinement (); +} + + + +template +void check (const FiniteElement& fe) +{ + deallog << fe.get_name() << std::endl; + + Triangulation tr; + + std::vector subdivisions (dim, 1); + subdivisions[0] = 2; + + const Point bottom_left = (dim == 2 ? + Point(-1,-1) : Point(-1,-1,-1)); + const Point top_right = (dim == 2 ? + Point(1,1) : Point(1,1,1)); + GridGenerator::subdivided_hyper_rectangle (tr, + subdivisions, bottom_left, top_right, true); + refine_mesh(tr); + + MGDoFHandler mg_dof_handler(tr); + mg_dof_handler.distribute_dofs(fe); + + deallog << "Global dofs: " << mg_dof_handler.n_dofs() << std::endl; + for(unsigned int l=0; l > boundary_indices(tr.n_levels()); + typename FunctionMap::type dirichlet_boundary; + ZeroFunction dirichlet_bc(fe.n_components()); + dirichlet_boundary[3] = &dirichlet_bc; + + MGTools::make_boundary_list (mg_dof_handler, dirichlet_boundary, + boundary_indices); + + std::vector block_selected(2,0U); + MGTransferSelect transfer; + transfer.build_matrices(mg_dof_handler, + mg_dof_handler, 0,0, block_selected, + block_selected, boundary_indices); + + FullMatrix prolong_0_1 (mg_dof_handler.n_dofs(1), + mg_dof_handler.n_dofs(0)); + + deallog << "Level 0->1" << std::endl; + make_matrix (transfer, 1, prolong_0_1); + print_matrix (prolong_0_1); +} + + +int main() +{ + std::ofstream logfile("transfer_system_adaptive_04/output"); + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + +//TODO: do in 1d + check (FESystem<2>(FE_Q<2>(1),2)); +} diff --git a/tests/multigrid/transfer_system_adaptive_05.cc b/tests/multigrid/transfer_system_adaptive_05.cc new file mode 100644 index 0000000000..adb4e26347 --- /dev/null +++ b/tests/multigrid/transfer_system_adaptive_05.cc @@ -0,0 +1,174 @@ +//---------------------------------------------------------------------------- +// transfer.cc,v 1.13 2005/12/30 16:07:03 guido Exp +// Version: +// +// Copyright (C) 2000 - 2007, 2009, 2010 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. +// +//---------------------------------------------------------------------------- + +// test like _03 but with a TransferSelect that selects only the first vector component + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + +template +void +reinit_vector (const dealii::MGDoFHandler &mg_dof, + MGLevelObject > &v) +{ + for (unsigned int level=v.get_minlevel(); + level<=v.get_maxlevel();++level) + { + unsigned int n = mg_dof.n_dofs (level); + v[level].reinit(n); + } + +} + + +template +void +make_matrix (const Transfer &transfer, + const unsigned int high_level, + FullMatrix &matrix) +{ + Vector src (matrix.n()); + Vector dst (matrix.m()); + for (unsigned int i=0; i &m) +{ + for (unsigned int i=0; i +void refine_mesh (Triangulation &triangulation) +{ + bool cell_refined = false; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + const Point p = cell->center(); + bool positive = p(0) > 0; + if (positive) + { + cell->set_refine_flag(); + cell_refined = true; + } + } + if(!cell_refined)//if no cell was selected for refinement, refine global + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + cell->set_refine_flag(); + triangulation.execute_coarsening_and_refinement (); +} + + + +template +void check (const FiniteElement& fe) +{ + deallog << fe.get_name() << std::endl; + + Triangulation tr; + + std::vector subdivisions (dim, 1); + subdivisions[0] = 2; + + const Point bottom_left = (dim == 2 ? + Point(-1,-1) : Point(-1,-1,-1)); + const Point top_right = (dim == 2 ? + Point(1,1) : Point(1,1,1)); + GridGenerator::subdivided_hyper_rectangle (tr, + subdivisions, bottom_left, top_right, true); + refine_mesh(tr); + + MGDoFHandler mg_dof_handler(tr); + mg_dof_handler.distribute_dofs(fe); + + deallog << "Global dofs: " << mg_dof_handler.n_dofs() << std::endl; + for(unsigned int l=0; l block_selected(2); + block_selected[0] = 0; + block_selected[1] = 1; + MGTransferSelect transfer; + transfer.build_matrices(mg_dof_handler, mg_dof_handler, 0, 0, block_selected, block_selected); + + // use only the first half of all + // components + FullMatrix prolong_0_1 (mg_dof_handler.n_dofs(1)/2, + mg_dof_handler.n_dofs(0)/2); + + deallog << "Level 0->1" << std::endl; + make_matrix (transfer, 1, prolong_0_1); + print_matrix (prolong_0_1); +} + + +int main() +{ + std::ofstream logfile("transfer_system_adaptive_05/output"); + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + +//TODO: do in 1d + check (FESystem<2>(FE_Q<2>(1),2)); +} diff --git a/tests/multigrid/transfer_system_adaptive_06.cc b/tests/multigrid/transfer_system_adaptive_06.cc new file mode 100644 index 0000000000..e3caf99f9a --- /dev/null +++ b/tests/multigrid/transfer_system_adaptive_06.cc @@ -0,0 +1,181 @@ +//---------------------------------------------------------------------------- +// transfer.cc,v 1.13 2005/12/30 16:07:03 guido Exp +// Version: +// +// Copyright (C) 2000 - 2007, 2009, 2010 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. +// +//---------------------------------------------------------------------------- + +// test like _05 but with boundary conditions +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + +template +void +reinit_vector (const dealii::MGDoFHandler &mg_dof, + MGLevelObject > &v) +{ + for (unsigned int level=v.get_minlevel(); + level<=v.get_maxlevel();++level) + { + unsigned int n = mg_dof.n_dofs (level); + v[level].reinit(n); + } + +} + + +template +void +make_matrix (const Transfer &transfer, + const unsigned int high_level, + FullMatrix &matrix) +{ + Vector src (matrix.n()); + Vector dst (matrix.m()); + for (unsigned int i=0; i &m) +{ + for (unsigned int i=0; i +void refine_mesh (Triangulation &triangulation) +{ + bool cell_refined = false; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + const Point p = cell->center(); + bool positive = p(0) > 0; + if (positive) + { + cell->set_refine_flag(); + cell_refined = true; + } + } + if(!cell_refined)//if no cell was selected for refinement, refine global + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + cell->set_refine_flag(); + triangulation.execute_coarsening_and_refinement (); +} + + + +template +void check (const FiniteElement& fe) +{ + deallog << fe.get_name() << std::endl; + + Triangulation tr; + + std::vector subdivisions (dim, 1); + subdivisions[0] = 2; + + const Point bottom_left = (dim == 2 ? + Point(-1,-1) : Point(-1,-1,-1)); + const Point top_right = (dim == 2 ? + Point(1,1) : Point(1,1,1)); + GridGenerator::subdivided_hyper_rectangle (tr, + subdivisions, bottom_left, top_right, true); + refine_mesh(tr); + + MGDoFHandler mg_dof_handler(tr); + mg_dof_handler.distribute_dofs(fe); + + deallog << "Global dofs: " << mg_dof_handler.n_dofs() << std::endl; + for(unsigned int l=0; l > boundary_indices(tr.n_levels()); + typename FunctionMap::type dirichlet_boundary; + ZeroFunction dirichlet_bc(fe.n_components()); + dirichlet_boundary[3] = &dirichlet_bc; + + MGTools::make_boundary_list (mg_dof_handler, dirichlet_boundary, + boundary_indices); + + std::vector block_selected(2); + block_selected[0] = 0; + block_selected[1] = 1; + MGTransferSelect transfer; + transfer.build_matrices(mg_dof_handler, mg_dof_handler, 0, 0, block_selected, block_selected, boundary_indices); + + // use only the first half of all + // components + FullMatrix prolong_0_1 (mg_dof_handler.n_dofs(1)/2, + mg_dof_handler.n_dofs(0)/2); + + deallog << "Level 0->1" << std::endl; + make_matrix (transfer, 1, prolong_0_1); + print_matrix (prolong_0_1); +} + + +int main() +{ + std::ofstream logfile("transfer_system_adaptive_06/output"); + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + +//TODO: do in 1d + check (FESystem<2>(FE_Q<2>(1),2)); +} diff --git a/tests/multigrid/transfer_system_adaptive_07.cc b/tests/multigrid/transfer_system_adaptive_07.cc new file mode 100644 index 0000000000..486bec837d --- /dev/null +++ b/tests/multigrid/transfer_system_adaptive_07.cc @@ -0,0 +1,181 @@ +//---------------------------------------------------------------------------- +// transfer.cc,v 1.13 2005/12/30 16:07:03 guido Exp +// Version: +// +// Copyright (C) 2000 - 2007, 2009, 2010 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. +// +//---------------------------------------------------------------------------- + +// test like _05 but with a TransferSelect that selects the first two vector +// components as the first block + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + +template +void +reinit_vector (const dealii::MGDoFHandler &mg_dof, + MGLevelObject > &v) +{ + for (unsigned int level=v.get_minlevel(); + level<=v.get_maxlevel();++level) + { + unsigned int n = mg_dof.n_dofs (level); + v[level].reinit(n); + } + +} + + +template +void +make_matrix (const Transfer &transfer, + const unsigned int high_level, + FullMatrix &matrix) +{ + Vector src (matrix.n()); + Vector dst (matrix.m()); + for (unsigned int i=0; i &m) +{ + for (unsigned int i=0; i +void refine_mesh (Triangulation &triangulation) +{ + bool cell_refined = false; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + const Point p = cell->center(); + bool positive = p(0) > 0; + if (positive) + { + cell->set_refine_flag(); + cell_refined = true; + } + } + if(!cell_refined)//if no cell was selected for refinement, refine global + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + cell->set_refine_flag(); + triangulation.execute_coarsening_and_refinement (); +} + + + +template +void check (const FiniteElement& fe) +{ + deallog << fe.get_name() << std::endl; + + Triangulation tr; + + std::vector subdivisions (dim, 1); + subdivisions[0] = 2; + + const Point bottom_left = (dim == 2 ? + Point(-1,-1) : Point(-1,-1,-1)); + const Point top_right = (dim == 2 ? + Point(1,1) : Point(1,1,1)); + GridGenerator::subdivided_hyper_rectangle (tr, + subdivisions, bottom_left, top_right, true); + refine_mesh(tr); + + MGDoFHandler mg_dof_handler(tr); + mg_dof_handler.distribute_dofs(fe); + + std::vector block_selected(3,0); + block_selected[2] = 1; + + deallog << "Global dofs: " << mg_dof_handler.n_dofs() << std::endl; + for(unsigned int l=0; l transfer; + transfer.build_matrices(mg_dof_handler, mg_dof_handler, + 0, 0, block_selected, block_selected); + + std::vector > + dofs_per_block(tr.n_levels(), std::vector(2)); + MGTools::count_dofs_per_block(mg_dof_handler, + dofs_per_block, block_selected); + + FullMatrix prolong_0_1 (dofs_per_block[1][0], + dofs_per_block[0][0]); + + deallog << "Level 0->1" << std::endl; + make_matrix (transfer, 1, prolong_0_1); + print_matrix (prolong_0_1); +} + + +int main() +{ + std::ofstream logfile("transfer_system_adaptive_07/output"); + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + +//TODO: do in 1d + check (FESystem<2>(FE_Q<2>(1),3)); +} diff --git a/tests/multigrid/transfer_system_adaptive_08.cc b/tests/multigrid/transfer_system_adaptive_08.cc new file mode 100644 index 0000000000..e8e9beb48f --- /dev/null +++ b/tests/multigrid/transfer_system_adaptive_08.cc @@ -0,0 +1,188 @@ +//---------------------------------------------------------------------------- +// transfer.cc,v 1.13 2005/12/30 16:07:03 guido Exp +// Version: +// +// Copyright (C) 2000 - 2007, 2009, 2010 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. +// +//---------------------------------------------------------------------------- + +// test like _07 but with boundary conditions + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + +template +void +reinit_vector (const dealii::MGDoFHandler &mg_dof, + MGLevelObject > &v) +{ + for (unsigned int level=v.get_minlevel(); + level<=v.get_maxlevel();++level) + { + unsigned int n = mg_dof.n_dofs (level); + v[level].reinit(n); + } + +} + + +template +void +make_matrix (const Transfer &transfer, + const unsigned int high_level, + FullMatrix &matrix) +{ + Vector src (matrix.n()); + Vector dst (matrix.m()); + for (unsigned int i=0; i &m) +{ + for (unsigned int i=0; i +void refine_mesh (Triangulation &triangulation) +{ + bool cell_refined = false; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + const Point p = cell->center(); + bool positive = p(0) > 0; + if (positive) + { + cell->set_refine_flag(); + cell_refined = true; + } + } + if(!cell_refined)//if no cell was selected for refinement, refine global + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + cell->set_refine_flag(); + triangulation.execute_coarsening_and_refinement (); +} + + + +template +void check (const FiniteElement& fe) +{ + deallog << fe.get_name() << std::endl; + + Triangulation tr; + + std::vector subdivisions (dim, 1); + subdivisions[0] = 2; + + const Point bottom_left = (dim == 2 ? + Point(-1,-1) : Point(-1,-1,-1)); + const Point top_right = (dim == 2 ? + Point(1,1) : Point(1,1,1)); + GridGenerator::subdivided_hyper_rectangle (tr, + subdivisions, bottom_left, top_right, true); + refine_mesh(tr); + + MGDoFHandler mg_dof_handler(tr); + mg_dof_handler.distribute_dofs(fe); + + std::vector block_selected(3,0); + block_selected[2] = 1; + + deallog << "Global dofs: " << mg_dof_handler.n_dofs() << std::endl; + for(unsigned int l=0; l > boundary_indices(tr.n_levels()); + typename FunctionMap::type dirichlet_boundary; + ZeroFunction dirichlet_bc(fe.n_components()); + dirichlet_boundary[3] = &dirichlet_bc; + + MGTools::make_boundary_list (mg_dof_handler, dirichlet_boundary, + boundary_indices); + + MGTransferSelect transfer; + transfer.build_matrices(mg_dof_handler, mg_dof_handler, + 0, 0, block_selected, block_selected, boundary_indices); + + std::vector > + dofs_per_block(tr.n_levels(), std::vector(2)); + MGTools::count_dofs_per_block(mg_dof_handler, + dofs_per_block, block_selected); + + FullMatrix prolong_0_1 (dofs_per_block[1][0], + dofs_per_block[0][0]); + + deallog << "Level 0->1" << std::endl; + make_matrix (transfer, 1, prolong_0_1); + print_matrix (prolong_0_1); +} + + +int main() +{ + std::ofstream logfile("transfer_system_adaptive_08/output"); + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + +//TODO: do in 1d + check (FESystem<2>(FE_Q<2>(1),3)); +} diff --git a/tests/multigrid/transfer_system_adaptive_09.cc b/tests/multigrid/transfer_system_adaptive_09.cc new file mode 100644 index 0000000000..da0114eb37 --- /dev/null +++ b/tests/multigrid/transfer_system_adaptive_09.cc @@ -0,0 +1,175 @@ +//---------------------------------------------------------------------------- +// transfer.cc,v 1.13 2005/12/30 16:07:03 guido Exp +// Version: +// +// Copyright (C) 2000 - 2007, 2009, 2010 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. +// +//---------------------------------------------------------------------------- + +// like _08, but checks the copy_to_mg and copy_from_mg of MGTransferSelect + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + + +template +void refine_mesh (Triangulation &triangulation) +{ + bool cell_refined = false; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + const Point p = cell->center(); + bool positive = p(0) > 0; + if (positive) + { + cell->set_refine_flag(); + cell_refined = true; + } + } + if(!cell_refined)//if no cell was selected for refinement, refine global + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + cell->set_refine_flag(); + triangulation.execute_coarsening_and_refinement (); +} + +template +void check (const FiniteElement& fe, const unsigned int selected_block) +{ + deallog << fe.get_name() << std::endl; + + Triangulation tr; + std::vector subdivisions (dim, 1); + subdivisions[0] = 2; + + const Point bottom_left = (dim == 2 ? + Point(-1,-1) : Point(-1,-1,-1)); + const Point top_right = (dim == 2 ? + Point(1,1) : Point(1,1,1)); + GridGenerator::subdivided_hyper_rectangle (tr, + subdivisions, bottom_left, top_right, true); + refine_mesh(tr); + + std::ostringstream out_filename; + out_filename << "gitter.eps"; + + std::ofstream grid_output (out_filename.str().c_str()); + GridOut grid_out; + grid_out.write_eps (tr, grid_output); + + + MGDoFHandler mg_dof_handler(tr); + mg_dof_handler.distribute_dofs(fe); + + std::vector block_component(5,0); + block_component[2]=1; + block_component[3]=1; + block_component[4]=2; + + DoFRenumbering::component_wise (mg_dof_handler, block_component); + for (unsigned int level=0; level transfer; + + transfer.build_matrices(mg_dof_handler, mg_dof_handler, + selected_block, selected_block, + block_component, block_component); + + std::vector dofs_per_block(3); + DoFTools::count_dofs_per_block(mg_dof_handler, dofs_per_block, block_component); + std::vector > mg_dofs_per_block(tr.n_levels(), std::vector(3)); + MGTools::count_dofs_per_block(mg_dof_handler, mg_dofs_per_block, block_component); + + deallog << "Global dofs:"; + for (unsigned int i=0;i u; + u.reinit (dofs_per_block); + for (unsigned int i=0;i > v(0,tr.n_levels()-1); + for(unsigned int l=0; l(FE_Q<2>(1),5),0); + check (FESystem<2>(FE_Q<2>(1),5),1); + check (FESystem<2>(FE_Q<2>(1),5),2); +} -- 2.39.5