// ---------------------------------------------------------------------
-// Test GridTools::map_dof_to_support_patch ()
+// Test GridTools::map_dof_to_support_patch () using a quadratic FE_Q<dim>
+// space. We output the barycenter of each cell in the patch around the dof
+// for a few dofs in the triangulation. We have three layers of refinement in
+// the triangulation which represents the various patches that could arise in
+// practice.
#include <deal.II/grid/tria_iterator.h>
#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/grid_tools.h>
-
#include <deal.II/dofs/dof_handler.h>
#include <fstream>
triangulation.refine_global (2);
{
+ // choose barycenters of cells to refine or coarsen to end up with
+ // a three level triangulation.
std::vector<Point<dim> > refine_centers;
std::vector<Point<dim> > coarsen_centers;
- if(dim==1)
- {
- refine_centers.push_back(Point<dim> (1./8.));
+ if (dim==1)
+ {
+ refine_centers.push_back(Point<dim> (1./8.));
- coarsen_centers.push_back(Point<dim> (5./8.));
- coarsen_centers.push_back(Point<dim> (7./8.));
- }
+ coarsen_centers.push_back(Point<dim> (5./8.));
+ coarsen_centers.push_back(Point<dim> (7./8.));
+ }
else if (dim==2)
- {
- refine_centers.push_back(Point<dim> (1./8., 7./8.));
+ {
+ refine_centers.push_back(Point<dim> (1./8., 7./8.));
- coarsen_centers.push_back(Point<dim> (5./8., 5./8.));
- coarsen_centers.push_back(Point<dim> (5./8., 7./8.));
- coarsen_centers.push_back(Point<dim> (7./8., 5./8.));
- coarsen_centers.push_back(Point<dim> (7./8., 7./8.));
+ coarsen_centers.push_back(Point<dim> (5./8., 5./8.));
+ coarsen_centers.push_back(Point<dim> (5./8., 7./8.));
+ coarsen_centers.push_back(Point<dim> (7./8., 5./8.));
+ coarsen_centers.push_back(Point<dim> (7./8., 7./8.));
- }
+ }
else if (dim==3)
- {
- refine_centers.push_back(Point<dim> (1./8., 7./8., 1./8.));
-
- coarsen_centers.push_back(Point<dim> (7./8., 7./8., 7./8.));
- coarsen_centers.push_back(Point<dim> (5./8., 7./8., 7./8.));
- coarsen_centers.push_back(Point<dim> (7./8., 5./8., 7./8.));
- coarsen_centers.push_back(Point<dim> (5./8., 5./8., 7./8.));
- coarsen_centers.push_back(Point<dim> (7./8., 7./8., 5./8.));
- coarsen_centers.push_back(Point<dim> (5./8., 7./8., 5./8.));
- coarsen_centers.push_back(Point<dim> (7./8., 5./8., 5./8.));
- coarsen_centers.push_back(Point<dim> (5./8., 5./8., 5./8.));
- }
+ {
+ refine_centers.push_back(Point<dim> (1./8., 7./8., 1./8.));
+
+ coarsen_centers.push_back(Point<dim> (7./8., 7./8., 7./8.));
+ coarsen_centers.push_back(Point<dim> (5./8., 7./8., 7./8.));
+ coarsen_centers.push_back(Point<dim> (7./8., 5./8., 7./8.));
+ coarsen_centers.push_back(Point<dim> (5./8., 5./8., 7./8.));
+ coarsen_centers.push_back(Point<dim> (7./8., 7./8., 5./8.));
+ coarsen_centers.push_back(Point<dim> (5./8., 7./8., 5./8.));
+ coarsen_centers.push_back(Point<dim> (7./8., 5./8., 5./8.));
+ coarsen_centers.push_back(Point<dim> (5./8., 5./8., 5./8.));
+ }
else
Assert(false, ExcNotImplemented() );
cell = triangulation.begin_active();
cell != triangulation.end(); ++cell, ++index)
- {
- Point<dim> cell_bary = cell->barycenter();
-
- // refine cells
- for (unsigned int i=0; i<refine_centers.size(); ++i)
- {
- double diff = 0;
- for (unsigned int d=0; d<dim; ++d)
- diff += pow(cell_bary[d] - refine_centers[i][d], 2.);
- diff = std::sqrt(diff);
-
- if (diff < 1e-14)
- {
- cell->set_refine_flag ();
- break;
- }
- }
- // coarsen cells
- for (unsigned int i=0; i<coarsen_centers.size(); ++i)
{
- double diff = 0;
- for (unsigned int d=0; d<dim; ++d)
- diff += pow(cell_bary[d] - coarsen_centers[i][d], 2.);
- diff = std::sqrt(diff);
-
- if (diff < 1e-14)
- {
- cell->set_coarsen_flag ();
- break;
- }
+ Point<dim> cell_bary = cell->barycenter();
+
+ // refine cells
+ for (unsigned int i=0; i<refine_centers.size(); ++i)
+ {
+ double diff = 0;
+ for (unsigned int d=0; d<dim; ++d)
+ diff += pow(cell_bary[d] - refine_centers[i][d], 2.);
+ diff = std::sqrt(diff);
+
+ if (diff < 1e-14)
+ {
+ cell->set_refine_flag ();
+ break;
+ }
+ }
+ // coarsen cells
+ for (unsigned int i=0; i<coarsen_centers.size(); ++i)
+ {
+ double diff = 0;
+ for (unsigned int d=0; d<dim; ++d)
+ diff += pow(cell_bary[d] - coarsen_centers[i][d], 2.);
+ diff = std::sqrt(diff);
+
+ if (diff < 1e-14)
+ {
+ cell->set_coarsen_flag ();
+ break;
+ }
+ }
}
- }
triangulation.execute_coarsening_and_refinement ();
}
dof_to_cell_map = GridTools::get_dof_to_support_patch_map(dof_handler);
for (unsigned int i=0; i<dof_handler.n_dofs(); ++i)
- {
- // loop through and print out barycenter of cells in patch of certain dofs
- // in system
- if (i % (dim == 1 ? 1 : (dim == 2 ? 5 : 25 )) == 0)
{
- deallog << "Patch around dof " << i << ": ";
- typename std::vector<typename dealii::DoFHandler<dim>::active_cell_iterator>::iterator
- patch_iter = dof_to_cell_map[i].begin(),
- patch_iter_end = dof_to_cell_map[i].end();
- for (; patch_iter != patch_iter_end ; ++patch_iter )
- {
- typename dealii::DoFHandler<dim>::active_cell_iterator patch_cell = *(patch_iter);
- Point<dim> cell_bary = patch_cell->barycenter();
- deallog << "(" ;
- for (unsigned int d=0; d<dim-1; ++d)
- deallog << cell_bary[d] << ", ";
- deallog << cell_bary[dim-1] << ") ";
- }
- deallog << std::endl;
- }
+ // loop through and print out barycenter of cells in patch of certain dofs
+ // in system
+ if (i % (dim == 1 ? 1 : (dim == 2 ? 5 : 25 )) == 0)
+ {
+ deallog << "Patch around dof " << i << ": ";
+ typename std::vector<typename dealii::DoFHandler<dim>::active_cell_iterator>::iterator
+ patch_iter = dof_to_cell_map[i].begin(),
+ patch_iter_end = dof_to_cell_map[i].end();
+ for (; patch_iter != patch_iter_end ; ++patch_iter )
+ {
+ typename dealii::DoFHandler<dim>::active_cell_iterator patch_cell = *(patch_iter);
+ Point<dim> cell_bary = patch_cell->barycenter();
+ deallog << "(" ;
+ for (unsigned int d=0; d<dim-1; ++d)
+ deallog << cell_bary[d] << ", ";
+ deallog << cell_bary[dim-1] << ") ";
+ }
+ deallog << std::endl;
+ }
- }
+ }
// clean up data