I am writing a space-time adaptive algorithm (dG in time, cG in space) for a blowup problem and have an a posteriori error estimator computed on a union grid of up to three different grids. I then need to transfer this error estimator to my current triangulation. I can match the cells across the grids up to one level just fine using the following code
const std::list<std::pair<typename Triangulation<dim>::cell_iterator, typename Triangulation<dim>::cell_iterator>> cell_list = GridTools::get_finest_common_cells (triangulation_space, union_triangulation);
auto cell_iter = cell_list.begin();
for (; cell_iter != cell_list.end(); ++cell_iter)
{
if (cell_iter->second->has_children () == false)
{
refinement_vector(cell_iter->first->active_cell_index()) = refinement_union_vector(cell_iter->second->active_cell_index());
}
else
{
const unsigned int no_of_subcells = cell_iter->second->n_children();
for (unsigned int subcell = 0; subcell < no_of_subcells; ++subcell)
{
refinement_vector(cell_iter->first->active_cell_index()) = fmax(refinement_vector(cell_iter->first->active_cell_index()), refinement_union_vector(cell_iter->second->child(subcell)->active_cell_index()));
}
}
}
but this only works under the assumption that the current grid differs from the union grid by one level which may not necessarily be the case. Obviously I could add "n" inner loops to this in order to take care of up to n different levels between the triangulations but this makes the code more unreadable and is not very "elegant". Does anybody have a better suggestion? Thanks!