0, 0,
block_component, block_component);
- // use only the first half of all
- // components
std::vector<std::vector<unsigned int> > dofs_per_block(tr.n_levels(), std::vector<unsigned int>(2));
MGTools::count_dofs_per_block(mg_dof_handler, dofs_per_block, block_component);
- FullMatrix<double> prolong_0_1 (dofs_per_block[1][0],dofs_per_block[0][0]);
- FullMatrix<double> prolong_1_2 (dofs_per_block[2][0],dofs_per_block[1][0]);
+ FullMatrix<double> prolong_0_1 (dofs_per_block[1][0],
+ dofs_per_block[0][0]);
+ FullMatrix<double> 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);
selected_block, selected_block,
block_component, block_component);
- // use only the first half of all
- // components
std::vector<unsigned int> dofs_per_block(3);
DoFTools::count_dofs_per_block(mg_dof_handler, dofs_per_block, block_component);
std::vector<std::vector<unsigned int> > mg_dofs_per_block(tr.n_levels(), std::vector<unsigned int>(3));
deallog << ' ' << (int) v[l](i);
deallog << std::endl;
}
+
+ for(unsigned int l=0; l<tr.n_levels(); ++l)
+ for (unsigned int i=0;i<v[l].size();++i)
+ v[l](i) = i;
+
+ u=0;
+ transfer.copy_from_mg(mg_dof_handler, u, v);
+ deallog << "Global" << std::endl;
+ for (unsigned int i=0; i<u.block(selected_block).size();++i)
+ deallog << ' ' << (int) u.block(selected_block)(i);
+ deallog << std::endl;
+ for (unsigned int i=0; i<u.size();++i)
+ deallog << ' ' << (int) u(i);
+ deallog << std::endl;
}
#include <grid/tria_accessor.h>
#include <grid/tria_iterator.h>
#include <grid/grid_generator.h>
-#include <grid/grid_out.h>
#include <dofs/dof_renumbering.h>
#include <dofs/dof_tools.h>
#include <fe/fe_q.h>
template<int dim>
void refine_mesh (Triangulation<dim> &triangulation)
{
- bool cell_refined = false;
+ bool cell_refined = false;
for (typename Triangulation<dim>::active_cell_iterator
cell = triangulation.begin_active();
cell != triangulation.end(); ++cell)
{
const Point<dim> 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<dim>::active_cell_iterator
cell = triangulation.begin_active();
cell != triangulation.end(); ++cell)
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<dim> mg_dof_handler(tr);
mg_dof_handler.distribute_dofs(fe);
for (unsigned int level=0; level<tr.n_levels(); ++level)
DoFRenumbering::component_wise (mg_dof_handler, level);
- std::vector<std::set<unsigned int> > boundary_indices(tr.n_levels());
- typename FunctionMap<dim>::type dirichlet_boundary;
- ZeroFunction<dim> dirichlet_bc(fe.n_components());
- dirichlet_boundary[0] = &dirichlet_bc;
-
- MGTools::make_boundary_list (mg_dof_handler, dirichlet_boundary,
- boundary_indices);
-
MGTransferPrebuilt<Vector<double> > transfer;
- transfer.build_matrices(mg_dof_handler);//, boundary_indices);
+ transfer.build_matrices(mg_dof_handler);
FullMatrix<double> prolong_0_1 (mg_dof_handler.n_dofs(1),
mg_dof_handler.n_dofs(0));
-// FullMatrix<double> 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);
}
+++ /dev/null
-
-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
--- /dev/null
+//----------------------------------------------------------------------------
+// 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 <base/function.h>
+#include <base/logstream.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+#include <grid/tria.h>
+#include <grid/tria_accessor.h>
+#include <grid/tria_iterator.h>
+#include <grid/grid_generator.h>
+#include <grid/grid_out.h>
+#include <dofs/dof_renumbering.h>
+#include <dofs/dof_tools.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+#include <multigrid/mg_dof_handler.h>
+#include <multigrid/mg_transfer.h>
+#include <multigrid/mg_tools.h>
+#include <multigrid/mg_level_object.h>
+
+#include <fstream>
+#include <iomanip>
+#include <iomanip>
+#include <algorithm>
+
+using namespace std;
+
+template <int dim, typename number, int spacedim>
+void
+reinit_vector (const dealii::MGDoFHandler<dim,spacedim> &mg_dof,
+ MGLevelObject<dealii::Vector<number> > &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 <typename Transfer>
+void
+make_matrix (const Transfer &transfer,
+ const unsigned int high_level,
+ FullMatrix<double> &matrix)
+{
+ Vector<double> src (matrix.n());
+ Vector<double> dst (matrix.m());
+ for (unsigned int i=0; i<src.size(); ++i)
+ {
+ src = 0;
+ src(i) = 1;
+ transfer.prolongate (high_level, dst, src);
+ for (unsigned int j=0; j<dst.size(); ++j)
+ matrix(j,i) = dst(j);
+ }
+}
+
+
+
+void print_matrix (const FullMatrix<double> &m)
+{
+ for (unsigned int i=0; i<m.m(); ++i)
+ {
+ for (unsigned int j=0; j<m.n(); ++j)
+ deallog << m(i,j) << ' ';
+ deallog << std::endl;
+ }
+}
+
+
+template<int dim>
+void refine_mesh (Triangulation<dim> &triangulation)
+{
+ bool cell_refined = false;
+ for (typename Triangulation<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ {
+ const Point<dim> 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<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ cell->set_refine_flag();
+ triangulation.execute_coarsening_and_refinement ();
+}
+
+
+
+template <int dim>
+void check (const FiniteElement<dim>& fe)
+{
+ deallog << fe.get_name() << std::endl;
+
+ Triangulation<dim> tr;
+
+ std::vector<unsigned int> subdivisions (dim, 1);
+ subdivisions[0] = 2;
+
+ const Point<dim> bottom_left = (dim == 2 ?
+ Point<dim>(-1,-1) : Point<dim>(-1,-1,-1));
+ const Point<dim> top_right = (dim == 2 ?
+ Point<dim>(1,1) : Point<dim>(1,1,1));
+ GridGenerator::subdivided_hyper_rectangle (tr,
+ subdivisions, bottom_left, top_right, true);
+ refine_mesh(tr);
+
+ MGDoFHandler<dim> 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<tr.n_levels(); ++l)
+ {
+ deallog << "Level " << l << " dofs:";
+ deallog << ' ' << mg_dof_handler.n_dofs(l);
+ deallog << std::endl;
+ }
+
+ DoFRenumbering::component_wise (mg_dof_handler);
+ for (unsigned int level=0; level<tr.n_levels(); ++level)
+ DoFRenumbering::component_wise (mg_dof_handler, level);
+
+ std::vector<std::set<unsigned int> > boundary_indices(tr.n_levels());
+ typename FunctionMap<dim>::type dirichlet_boundary;
+ ZeroFunction<dim> dirichlet_bc(fe.n_components());
+ dirichlet_boundary[3] = &dirichlet_bc;
+
+ MGTools::make_boundary_list (mg_dof_handler, dirichlet_boundary,
+ boundary_indices);
+
+ MGTransferPrebuilt<Vector<double> > transfer;
+ transfer.build_matrices(mg_dof_handler, boundary_indices);
+
+ FullMatrix<double> 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));
+}
--- /dev/null
+//----------------------------------------------------------------------------
+// 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 <base/function.h>
+#include <base/logstream.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+#include <grid/tria.h>
+#include <grid/tria_accessor.h>
+#include <grid/tria_iterator.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_renumbering.h>
+#include <dofs/dof_tools.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+#include <multigrid/mg_dof_handler.h>
+#include <multigrid/mg_transfer.h>
+#include <multigrid/mg_transfer_component.h>
+#include <multigrid/mg_tools.h>
+#include <multigrid/mg_level_object.h>
+
+#include <fstream>
+#include <iomanip>
+#include <iomanip>
+#include <algorithm>
+
+using namespace std;
+
+template <int dim, typename number, int spacedim>
+void
+reinit_vector (const dealii::MGDoFHandler<dim,spacedim> &mg_dof,
+ MGLevelObject<dealii::Vector<number> > &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 <typename Transfer>
+void
+make_matrix (const Transfer &transfer,
+ const unsigned int high_level,
+ FullMatrix<double> &matrix)
+{
+ Vector<double> src (matrix.n());
+ Vector<double> dst (matrix.m());
+ for (unsigned int i=0; i<src.size(); ++i)
+ {
+ src = 0;
+ src(i) = 1;
+ transfer.prolongate (high_level, dst, src);
+ for (unsigned int j=0; j<dst.size(); ++j)
+ matrix(j,i) = dst(j);
+ }
+}
+
+
+
+void print_matrix (const FullMatrix<double> &m)
+{
+ for (unsigned int i=0; i<m.m(); ++i)
+ {
+ for (unsigned int j=0; j<m.n(); ++j)
+ deallog << m(i,j) << ' ';
+ deallog << std::endl;
+ }
+}
+
+
+template<int dim>
+void refine_mesh (Triangulation<dim> &triangulation)
+{
+ bool cell_refined = false;
+ for (typename Triangulation<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ {
+ const Point<dim> 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<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ cell->set_refine_flag();
+ triangulation.execute_coarsening_and_refinement ();
+}
+
+
+
+template <int dim>
+void check (const FiniteElement<dim>& fe)
+{
+ deallog << fe.get_name() << std::endl;
+
+ Triangulation<dim> tr;
+
+ std::vector<unsigned int> subdivisions (dim, 1);
+ subdivisions[0] = 2;
+
+ const Point<dim> bottom_left = (dim == 2 ?
+ Point<dim>(-1,-1) : Point<dim>(-1,-1,-1));
+ const Point<dim> top_right = (dim == 2 ?
+ Point<dim>(1,1) : Point<dim>(1,1,1));
+ GridGenerator::subdivided_hyper_rectangle (tr,
+ subdivisions, bottom_left, top_right, true);
+ refine_mesh(tr);
+
+ MGDoFHandler<dim> 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<tr.n_levels(); ++l)
+ {
+ deallog << "Level " << l << " dofs:";
+ deallog << ' ' << mg_dof_handler.n_dofs(l);
+ deallog << std::endl;
+ }
+
+ DoFRenumbering::component_wise (mg_dof_handler);
+ for (unsigned int level=0; level<tr.n_levels(); ++level)
+ DoFRenumbering::component_wise (mg_dof_handler, level);
+
+ std::vector<unsigned int> block_selected(2,0U);
+ MGTransferSelect<double> transfer;
+ transfer.build_matrices(mg_dof_handler, mg_dof_handler, 0, 0, block_selected, block_selected);
+
+ FullMatrix<double> 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));
+}
--- /dev/null
+//----------------------------------------------------------------------------
+// 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 <base/function.h>
+#include <base/logstream.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+#include <grid/tria.h>
+#include <grid/tria_accessor.h>
+#include <grid/tria_iterator.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_renumbering.h>
+#include <dofs/dof_tools.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+#include <multigrid/mg_dof_handler.h>
+#include <multigrid/mg_transfer.h>
+#include <multigrid/mg_transfer_component.h>
+#include <multigrid/mg_tools.h>
+#include <multigrid/mg_level_object.h>
+
+#include <fstream>
+#include <iomanip>
+#include <iomanip>
+#include <algorithm>
+
+using namespace std;
+
+template <int dim, typename number, int spacedim>
+void
+reinit_vector (const dealii::MGDoFHandler<dim,spacedim> &mg_dof,
+ MGLevelObject<dealii::Vector<number> > &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 <typename Transfer>
+void
+make_matrix (const Transfer &transfer,
+ const unsigned int high_level,
+ FullMatrix<double> &matrix)
+{
+ Vector<double> src (matrix.n());
+ Vector<double> dst (matrix.m());
+ for (unsigned int i=0; i<src.size(); ++i)
+ {
+ src = 0;
+ src(i) = 1;
+ transfer.prolongate (high_level, dst, src);
+ for (unsigned int j=0; j<dst.size(); ++j)
+ matrix(j,i) = dst(j);
+ }
+}
+
+
+
+void print_matrix (const FullMatrix<double> &m)
+{
+ for (unsigned int i=0; i<m.m(); ++i)
+ {
+ for (unsigned int j=0; j<m.n(); ++j)
+ deallog << m(i,j) << ' ';
+ deallog << std::endl;
+ }
+}
+
+
+template<int dim>
+void refine_mesh (Triangulation<dim> &triangulation)
+{
+ bool cell_refined = false;
+ for (typename Triangulation<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ {
+ const Point<dim> 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<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ cell->set_refine_flag();
+ triangulation.execute_coarsening_and_refinement ();
+}
+
+
+
+template <int dim>
+void check (const FiniteElement<dim>& fe)
+{
+ deallog << fe.get_name() << std::endl;
+
+ Triangulation<dim> tr;
+
+ std::vector<unsigned int> subdivisions (dim, 1);
+ subdivisions[0] = 2;
+
+ const Point<dim> bottom_left = (dim == 2 ?
+ Point<dim>(-1,-1) : Point<dim>(-1,-1,-1));
+ const Point<dim> top_right = (dim == 2 ?
+ Point<dim>(1,1) : Point<dim>(1,1,1));
+ GridGenerator::subdivided_hyper_rectangle (tr,
+ subdivisions, bottom_left, top_right, true);
+ refine_mesh(tr);
+
+ MGDoFHandler<dim> 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<tr.n_levels(); ++l)
+ {
+ deallog << "Level " << l << " dofs:";
+ deallog << ' ' << mg_dof_handler.n_dofs(l);
+ deallog << std::endl;
+ }
+
+ DoFRenumbering::component_wise (mg_dof_handler);
+ for (unsigned int level=0; level<tr.n_levels(); ++level)
+ DoFRenumbering::component_wise (mg_dof_handler, level);
+
+ std::vector<std::set<unsigned int> > boundary_indices(tr.n_levels());
+ typename FunctionMap<dim>::type dirichlet_boundary;
+ ZeroFunction<dim> dirichlet_bc(fe.n_components());
+ dirichlet_boundary[3] = &dirichlet_bc;
+
+ MGTools::make_boundary_list (mg_dof_handler, dirichlet_boundary,
+ boundary_indices);
+
+ std::vector<unsigned int> block_selected(2,0U);
+ MGTransferSelect<double> transfer;
+ transfer.build_matrices(mg_dof_handler,
+ mg_dof_handler, 0,0, block_selected,
+ block_selected, boundary_indices);
+
+ FullMatrix<double> 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));
+}
--- /dev/null
+//----------------------------------------------------------------------------
+// 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 <base/function.h>
+#include <base/logstream.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+#include <grid/tria.h>
+#include <grid/tria_accessor.h>
+#include <grid/tria_iterator.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_renumbering.h>
+#include <dofs/dof_tools.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+#include <multigrid/mg_dof_handler.h>
+#include <multigrid/mg_transfer.h>
+#include <multigrid/mg_transfer_component.h>
+#include <multigrid/mg_tools.h>
+#include <multigrid/mg_level_object.h>
+
+#include <fstream>
+#include <iomanip>
+#include <iomanip>
+#include <algorithm>
+
+using namespace std;
+
+template <int dim, typename number, int spacedim>
+void
+reinit_vector (const dealii::MGDoFHandler<dim,spacedim> &mg_dof,
+ MGLevelObject<dealii::Vector<number> > &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 <typename Transfer>
+void
+make_matrix (const Transfer &transfer,
+ const unsigned int high_level,
+ FullMatrix<double> &matrix)
+{
+ Vector<double> src (matrix.n());
+ Vector<double> dst (matrix.m());
+ for (unsigned int i=0; i<src.size(); ++i)
+ {
+ src = 0;
+ src(i) = 1;
+ transfer.prolongate (high_level, dst, src);
+ for (unsigned int j=0; j<dst.size(); ++j)
+ matrix(j,i) = dst(j);
+ }
+}
+
+
+
+void print_matrix (const FullMatrix<double> &m)
+{
+ for (unsigned int i=0; i<m.m(); ++i)
+ {
+ for (unsigned int j=0; j<m.n(); ++j)
+ deallog << m(i,j) << ' ';
+ deallog << std::endl;
+ }
+}
+
+
+template<int dim>
+void refine_mesh (Triangulation<dim> &triangulation)
+{
+ bool cell_refined = false;
+ for (typename Triangulation<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ {
+ const Point<dim> 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<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ cell->set_refine_flag();
+ triangulation.execute_coarsening_and_refinement ();
+}
+
+
+
+template <int dim>
+void check (const FiniteElement<dim>& fe)
+{
+ deallog << fe.get_name() << std::endl;
+
+ Triangulation<dim> tr;
+
+ std::vector<unsigned int> subdivisions (dim, 1);
+ subdivisions[0] = 2;
+
+ const Point<dim> bottom_left = (dim == 2 ?
+ Point<dim>(-1,-1) : Point<dim>(-1,-1,-1));
+ const Point<dim> top_right = (dim == 2 ?
+ Point<dim>(1,1) : Point<dim>(1,1,1));
+ GridGenerator::subdivided_hyper_rectangle (tr,
+ subdivisions, bottom_left, top_right, true);
+ refine_mesh(tr);
+
+ MGDoFHandler<dim> 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<tr.n_levels(); ++l)
+ {
+ deallog << "Level " << l << " dofs:";
+ deallog << ' ' << mg_dof_handler.n_dofs(l);
+ deallog << std::endl;
+ }
+
+ DoFRenumbering::component_wise (mg_dof_handler);
+ for (unsigned int level=0; level<tr.n_levels(); ++level)
+ DoFRenumbering::component_wise (mg_dof_handler, level);
+
+ std::vector<unsigned int> block_selected(2);
+ block_selected[0] = 0;
+ block_selected[1] = 1;
+ MGTransferSelect<double> 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<double> 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));
+}
--- /dev/null
+//----------------------------------------------------------------------------
+// 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 <base/function.h>
+#include <base/logstream.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+#include <grid/tria.h>
+#include <grid/tria_accessor.h>
+#include <grid/tria_iterator.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_renumbering.h>
+#include <dofs/dof_tools.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+#include <multigrid/mg_dof_handler.h>
+#include <multigrid/mg_transfer.h>
+#include <multigrid/mg_transfer_component.h>
+#include <multigrid/mg_tools.h>
+#include <multigrid/mg_level_object.h>
+
+#include <fstream>
+#include <iomanip>
+#include <iomanip>
+#include <algorithm>
+
+using namespace std;
+
+template <int dim, typename number, int spacedim>
+void
+reinit_vector (const dealii::MGDoFHandler<dim,spacedim> &mg_dof,
+ MGLevelObject<dealii::Vector<number> > &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 <typename Transfer>
+void
+make_matrix (const Transfer &transfer,
+ const unsigned int high_level,
+ FullMatrix<double> &matrix)
+{
+ Vector<double> src (matrix.n());
+ Vector<double> dst (matrix.m());
+ for (unsigned int i=0; i<src.size(); ++i)
+ {
+ src = 0;
+ src(i) = 1;
+ transfer.prolongate (high_level, dst, src);
+ for (unsigned int j=0; j<dst.size(); ++j)
+ matrix(j,i) = dst(j);
+ }
+}
+
+
+
+void print_matrix (const FullMatrix<double> &m)
+{
+ for (unsigned int i=0; i<m.m(); ++i)
+ {
+ for (unsigned int j=0; j<m.n(); ++j)
+ deallog << m(i,j) << ' ';
+ deallog << std::endl;
+ }
+}
+
+
+template<int dim>
+void refine_mesh (Triangulation<dim> &triangulation)
+{
+ bool cell_refined = false;
+ for (typename Triangulation<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ {
+ const Point<dim> 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<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ cell->set_refine_flag();
+ triangulation.execute_coarsening_and_refinement ();
+}
+
+
+
+template <int dim>
+void check (const FiniteElement<dim>& fe)
+{
+ deallog << fe.get_name() << std::endl;
+
+ Triangulation<dim> tr;
+
+ std::vector<unsigned int> subdivisions (dim, 1);
+ subdivisions[0] = 2;
+
+ const Point<dim> bottom_left = (dim == 2 ?
+ Point<dim>(-1,-1) : Point<dim>(-1,-1,-1));
+ const Point<dim> top_right = (dim == 2 ?
+ Point<dim>(1,1) : Point<dim>(1,1,1));
+ GridGenerator::subdivided_hyper_rectangle (tr,
+ subdivisions, bottom_left, top_right, true);
+ refine_mesh(tr);
+
+ MGDoFHandler<dim> 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<tr.n_levels(); ++l)
+ {
+ deallog << "Level " << l << " dofs:";
+ deallog << ' ' << mg_dof_handler.n_dofs(l);
+ deallog << std::endl;
+ }
+
+ DoFRenumbering::component_wise (mg_dof_handler);
+ for (unsigned int level=0; level<tr.n_levels(); ++level)
+ DoFRenumbering::component_wise (mg_dof_handler, level);
+
+ std::vector<std::set<unsigned int> > boundary_indices(tr.n_levels());
+ typename FunctionMap<dim>::type dirichlet_boundary;
+ ZeroFunction<dim> dirichlet_bc(fe.n_components());
+ dirichlet_boundary[3] = &dirichlet_bc;
+
+ MGTools::make_boundary_list (mg_dof_handler, dirichlet_boundary,
+ boundary_indices);
+
+ std::vector<unsigned int> block_selected(2);
+ block_selected[0] = 0;
+ block_selected[1] = 1;
+ MGTransferSelect<double> 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<double> 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));
+}
--- /dev/null
+//----------------------------------------------------------------------------
+// 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 <base/function.h>
+#include <base/logstream.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+#include <grid/tria.h>
+#include <grid/tria_accessor.h>
+#include <grid/tria_iterator.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_renumbering.h>
+#include <dofs/dof_tools.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+#include <multigrid/mg_dof_handler.h>
+#include <multigrid/mg_transfer.h>
+#include <multigrid/mg_transfer_component.h>
+#include <multigrid/mg_tools.h>
+#include <multigrid/mg_level_object.h>
+
+#include <fstream>
+#include <iomanip>
+#include <iomanip>
+#include <algorithm>
+
+using namespace std;
+
+template <int dim, typename number, int spacedim>
+void
+reinit_vector (const dealii::MGDoFHandler<dim,spacedim> &mg_dof,
+ MGLevelObject<dealii::Vector<number> > &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 <typename Transfer>
+void
+make_matrix (const Transfer &transfer,
+ const unsigned int high_level,
+ FullMatrix<double> &matrix)
+{
+ Vector<double> src (matrix.n());
+ Vector<double> dst (matrix.m());
+ for (unsigned int i=0; i<src.size(); ++i)
+ {
+ src = 0;
+ src(i) = 1;
+ transfer.prolongate (high_level, dst, src);
+ for (unsigned int j=0; j<dst.size(); ++j)
+ matrix(j,i) = dst(j);
+ }
+}
+
+
+
+void print_matrix (const FullMatrix<double> &m)
+{
+ for (unsigned int i=0; i<m.m(); ++i)
+ {
+ for (unsigned int j=0; j<m.n(); ++j)
+ deallog << m(i,j) << ' ';
+ deallog << std::endl;
+ }
+}
+
+
+template<int dim>
+void refine_mesh (Triangulation<dim> &triangulation)
+{
+ bool cell_refined = false;
+ for (typename Triangulation<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ {
+ const Point<dim> 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<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ cell->set_refine_flag();
+ triangulation.execute_coarsening_and_refinement ();
+}
+
+
+
+template <int dim>
+void check (const FiniteElement<dim>& fe)
+{
+ deallog << fe.get_name() << std::endl;
+
+ Triangulation<dim> tr;
+
+ std::vector<unsigned int> subdivisions (dim, 1);
+ subdivisions[0] = 2;
+
+ const Point<dim> bottom_left = (dim == 2 ?
+ Point<dim>(-1,-1) : Point<dim>(-1,-1,-1));
+ const Point<dim> top_right = (dim == 2 ?
+ Point<dim>(1,1) : Point<dim>(1,1,1));
+ GridGenerator::subdivided_hyper_rectangle (tr,
+ subdivisions, bottom_left, top_right, true);
+ refine_mesh(tr);
+
+ MGDoFHandler<dim> mg_dof_handler(tr);
+ mg_dof_handler.distribute_dofs(fe);
+
+ std::vector<unsigned int> block_selected(3,0);
+ block_selected[2] = 1;
+
+ deallog << "Global dofs: " << mg_dof_handler.n_dofs() << std::endl;
+ for(unsigned int l=0; l<tr.n_levels(); ++l)
+ {
+ deallog << "Level " << l << " dofs:";
+ deallog << ' ' << mg_dof_handler.n_dofs(l);
+ deallog << std::endl;
+ }
+
+ DoFRenumbering::component_wise (mg_dof_handler,
+ block_selected);
+ for (unsigned int level=0; level<tr.n_levels(); ++level)
+ DoFRenumbering::component_wise (mg_dof_handler,
+ level, block_selected);
+
+ MGTransferSelect<double> transfer;
+ transfer.build_matrices(mg_dof_handler, mg_dof_handler,
+ 0, 0, block_selected, block_selected);
+
+ std::vector<std::vector<unsigned int> >
+ dofs_per_block(tr.n_levels(), std::vector<unsigned int>(2));
+ MGTools::count_dofs_per_block(mg_dof_handler,
+ dofs_per_block, block_selected);
+
+ FullMatrix<double> 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));
+}
--- /dev/null
+//----------------------------------------------------------------------------
+// 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 <base/function.h>
+#include <base/logstream.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+#include <grid/tria.h>
+#include <grid/tria_accessor.h>
+#include <grid/tria_iterator.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_renumbering.h>
+#include <dofs/dof_tools.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+#include <multigrid/mg_dof_handler.h>
+#include <multigrid/mg_transfer.h>
+#include <multigrid/mg_transfer_component.h>
+#include <multigrid/mg_tools.h>
+#include <multigrid/mg_level_object.h>
+
+#include <fstream>
+#include <iomanip>
+#include <iomanip>
+#include <algorithm>
+
+using namespace std;
+
+template <int dim, typename number, int spacedim>
+void
+reinit_vector (const dealii::MGDoFHandler<dim,spacedim> &mg_dof,
+ MGLevelObject<dealii::Vector<number> > &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 <typename Transfer>
+void
+make_matrix (const Transfer &transfer,
+ const unsigned int high_level,
+ FullMatrix<double> &matrix)
+{
+ Vector<double> src (matrix.n());
+ Vector<double> dst (matrix.m());
+ for (unsigned int i=0; i<src.size(); ++i)
+ {
+ src = 0;
+ src(i) = 1;
+ transfer.prolongate (high_level, dst, src);
+ for (unsigned int j=0; j<dst.size(); ++j)
+ matrix(j,i) = dst(j);
+ }
+}
+
+
+
+void print_matrix (const FullMatrix<double> &m)
+{
+ for (unsigned int i=0; i<m.m(); ++i)
+ {
+ for (unsigned int j=0; j<m.n(); ++j)
+ deallog << m(i,j) << ' ';
+ deallog << std::endl;
+ }
+}
+
+
+template<int dim>
+void refine_mesh (Triangulation<dim> &triangulation)
+{
+ bool cell_refined = false;
+ for (typename Triangulation<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ {
+ const Point<dim> 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<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ cell->set_refine_flag();
+ triangulation.execute_coarsening_and_refinement ();
+}
+
+
+
+template <int dim>
+void check (const FiniteElement<dim>& fe)
+{
+ deallog << fe.get_name() << std::endl;
+
+ Triangulation<dim> tr;
+
+ std::vector<unsigned int> subdivisions (dim, 1);
+ subdivisions[0] = 2;
+
+ const Point<dim> bottom_left = (dim == 2 ?
+ Point<dim>(-1,-1) : Point<dim>(-1,-1,-1));
+ const Point<dim> top_right = (dim == 2 ?
+ Point<dim>(1,1) : Point<dim>(1,1,1));
+ GridGenerator::subdivided_hyper_rectangle (tr,
+ subdivisions, bottom_left, top_right, true);
+ refine_mesh(tr);
+
+ MGDoFHandler<dim> mg_dof_handler(tr);
+ mg_dof_handler.distribute_dofs(fe);
+
+ std::vector<unsigned int> block_selected(3,0);
+ block_selected[2] = 1;
+
+ deallog << "Global dofs: " << mg_dof_handler.n_dofs() << std::endl;
+ for(unsigned int l=0; l<tr.n_levels(); ++l)
+ {
+ deallog << "Level " << l << " dofs:";
+ deallog << ' ' << mg_dof_handler.n_dofs(l);
+ deallog << std::endl;
+ }
+
+ DoFRenumbering::component_wise (mg_dof_handler,
+ block_selected);
+ for (unsigned int level=0; level<tr.n_levels(); ++level)
+ DoFRenumbering::component_wise (mg_dof_handler,
+ level, block_selected);
+
+ std::vector<std::set<unsigned int> > boundary_indices(tr.n_levels());
+ typename FunctionMap<dim>::type dirichlet_boundary;
+ ZeroFunction<dim> dirichlet_bc(fe.n_components());
+ dirichlet_boundary[3] = &dirichlet_bc;
+
+ MGTools::make_boundary_list (mg_dof_handler, dirichlet_boundary,
+ boundary_indices);
+
+ MGTransferSelect<double> transfer;
+ transfer.build_matrices(mg_dof_handler, mg_dof_handler,
+ 0, 0, block_selected, block_selected, boundary_indices);
+
+ std::vector<std::vector<unsigned int> >
+ dofs_per_block(tr.n_levels(), std::vector<unsigned int>(2));
+ MGTools::count_dofs_per_block(mg_dof_handler,
+ dofs_per_block, block_selected);
+
+ FullMatrix<double> 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));
+}
--- /dev/null
+//----------------------------------------------------------------------------
+// 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 <base/logstream.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+#include <grid/tria.h>
+#include <grid/grid_generator.h>
+#include <grid/tria_accessor.h>
+#include <grid/tria_iterator.h>
+#include <grid/grid_out.h>
+#include <dofs/dof_renumbering.h>
+#include <dofs/dof_tools.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+#include <multigrid/mg_dof_handler.h>
+#include <multigrid/mg_transfer.h>
+#include <multigrid/mg_transfer_component.h>
+#include <multigrid/mg_tools.h>
+#include <multigrid/mg_level_object.h>
+
+#include <fstream>
+#include <iomanip>
+#include <iomanip>
+#include <algorithm>
+
+using namespace std;
+
+
+template<int dim>
+void refine_mesh (Triangulation<dim> &triangulation)
+{
+ bool cell_refined = false;
+ for (typename Triangulation<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ {
+ const Point<dim> 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<dim>::active_cell_iterator
+ cell = triangulation.begin_active();
+ cell != triangulation.end(); ++cell)
+ cell->set_refine_flag();
+ triangulation.execute_coarsening_and_refinement ();
+}
+
+template <int dim>
+void check (const FiniteElement<dim>& fe, const unsigned int selected_block)
+{
+ deallog << fe.get_name() << std::endl;
+
+ Triangulation<dim> tr;
+ std::vector<unsigned int> subdivisions (dim, 1);
+ subdivisions[0] = 2;
+
+ const Point<dim> bottom_left = (dim == 2 ?
+ Point<dim>(-1,-1) : Point<dim>(-1,-1,-1));
+ const Point<dim> top_right = (dim == 2 ?
+ Point<dim>(1,1) : Point<dim>(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<dim> mg_dof_handler(tr);
+ mg_dof_handler.distribute_dofs(fe);
+
+ std::vector<unsigned int> 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<tr.n_levels(); ++level)
+ DoFRenumbering::component_wise (mg_dof_handler, level, block_component);
+
+
+ MGTransferSelect<double> transfer;
+
+ transfer.build_matrices(mg_dof_handler, mg_dof_handler,
+ selected_block, selected_block,
+ block_component, block_component);
+
+ std::vector<unsigned int> dofs_per_block(3);
+ DoFTools::count_dofs_per_block(mg_dof_handler, dofs_per_block, block_component);
+ std::vector<std::vector<unsigned int> > mg_dofs_per_block(tr.n_levels(), std::vector<unsigned int>(3));
+ MGTools::count_dofs_per_block(mg_dof_handler, mg_dofs_per_block, block_component);
+
+ deallog << "Global dofs:";
+ for (unsigned int i=0;i<dofs_per_block.size();++i)
+ deallog << ' ' << dofs_per_block[i];
+ deallog << std::endl;
+ for (unsigned int l=0;l<mg_dofs_per_block.size();++l)
+ {
+ deallog << "Level " << l << " dofs:";
+ for (unsigned int i=0;i<mg_dofs_per_block[l].size();++i)
+ deallog << ' ' << mg_dofs_per_block[l][i];
+ deallog << std::endl;
+ }
+
+ BlockVector<double> u;
+ u.reinit (dofs_per_block);
+ for (unsigned int i=0;i<u.size();++i)
+ u(i) = i;
+
+ MGLevelObject<Vector<double> > v(0,tr.n_levels()-1);
+ for(unsigned int l=0; l<tr.n_levels()-1; ++l)
+ v[l].reinit(mg_dofs_per_block[l][2]);
+
+
+ transfer.copy_to_mg(mg_dof_handler, v, u);
+ for(unsigned int l=0; l<tr.n_levels(); ++l)
+ {
+ deallog << "Level " << l << std::endl;
+ for (unsigned int i=0; i<v[l].size();++i)
+ deallog << ' ' << (int) v[l](i);
+ deallog << std::endl;
+ }
+
+ for(unsigned int l=0; l<tr.n_levels(); ++l)
+ for (unsigned int i=0;i<v[l].size();++i)
+ v[l](i) = i;
+
+ u=0;
+ transfer.copy_from_mg(mg_dof_handler, u, v);
+ deallog << "Global" << std::endl;
+ for (unsigned int i=0; i<u.block(selected_block).size();++i)
+ deallog << ' ' << (int) u.block(selected_block)(i);
+ deallog << std::endl;
+ for (unsigned int i=0; i<u.size();++i)
+ deallog << ' ' << (int) u(i);
+ deallog << std::endl;
+}
+
+
+int main()
+{
+ std::ofstream logfile("transfer_system_adaptive_09/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),5),0);
+ check (FESystem<2>(FE_Q<2>(1),5),1);
+ check (FESystem<2>(FE_Q<2>(1),5),2);
+}