template <int dim>
void
add_periodic_refinement_signals(Triangulation<dim> &triangulation)
{
// Before refining we ensure that periodic face pairs have the same
// refinement flag.
{
auto signal_periodic_faces_symmetric_marking = [&triangulation]() -> void {
for (typename Triangulation<dim>::active_cell_iterator cell = triangulation.begin_active(); cell != triangulation.end(); ++cell)
{
for (unsigned int face = 0; face < GeometryInfo<dim>::faces_per_cell; ++face)
{
if (cell->has_periodic_neighbor(face))
{
if (cell->refine_flag_set())
{
cell->periodic_neighbor(face)->clear_coarsen_flag();
cell->periodic_neighbor(face)->set_refine_flag();
}
else if (cell->periodic_neighbor(face)->refine_flag_set())
{
cell->clear_coarsen_flag();
cell->set_refine_flag();
}
else if (cell->coarsen_flag_set())
{
cell->periodic_neighbor(face)->clear_refine_flag();
cell->periodic_neighbor(face)->set_coarsen_flag();
}
else if (cell->periodic_neighbor(face)->coarsen_flag_set())
{
cell->clear_refine_flag();
cell->set_coarsen_flag();
}
}
}
}
// Its quite possible that, after all of this, we violate some
// of the 2:1 cell level ratio expectations... Thats this error:
// An error occurred in line <12816> of file <.../dealii/source/grid/tria.cc> in function // virtual bool dealii::Triangulation<2, 2>::prepare_coarsening_and_refinement() [dim = 2, spacedim = 2]
// The violated condition was:
// cell_is_patch_level_1(cell)
// To fix this, we make the following call:
triangulation.prepare_coarsening_and_refinement();
};
// Add signals
triangulation.signals.pre_refinement.connect(signal_periodic_faces_symmetric_marking);
}
}