--- /dev/null
+New: The convert_active_cell_iterator() function can be used to convert from a
+Triangulation active cell iterator to a DoFHandler active cell iterator, or
+from an active cell iterator of one DoFHandler to that of another DoFHandler.
+<br>
+(Jean-Paul Pelteret, 2022/07/15)
#endif
};
+
+/**
+ * A function that converts a Triangulation active cell iterator to a
+ * DoFHandler active cell iterator. The triangulation @p iterator must be
+ * associated with the triangulation of the @p dof_handler.
+ *
+ * @param iterator The input iterator to be converted.
+ * @param dof_handler The DoFHandler for the output active cell iterator.
+ * @return An active cell iterator for the @p dof_handler, matching the cell
+ * referenced by the input triangulation @p iterator.
+ */
+template <int dim, int spacedim>
+typename DoFHandler<dim, spacedim>::active_cell_iterator
+convert_active_cell_iterator(
+ const typename Triangulation<dim, spacedim>::active_cell_iterator &iterator,
+ const DoFHandler<dim, spacedim> &dof_handler)
+{
+ Assert(
+ &iterator->get_triangulation() == &dof_handler.get_triangulation(),
+ ExcMessage(
+ "The triangulation associated with the iterator does not match that of the dof_handler."));
+
+ return typename DoFHandler<dim, spacedim>::active_cell_iterator(
+ &dof_handler.get_triangulation(),
+ iterator->level(),
+ iterator->index(),
+ &dof_handler);
+}
+
+
+/**
+ * A function that converts a DoFHandler active cell iterator to an active
+ * cell iterator of another DoFHandler. The degree-of-freedom handler to which
+ * @p iterator is associated must have the same triangulation as the
+ * second @p dof_handler.
+ *
+ * @param iterator The input iterator to be converted.
+ * @param dof_handler The DoFHandler for the output active cell iterator.
+ * @return An active cell iterator for the @p dof_handler, matching the cell
+ * referenced by the input @p iterator for another DoFHandler.
+ */
+template <int dim, int spacedim>
+typename DoFHandler<dim, spacedim>::active_cell_iterator
+convert_active_cell_iterator(
+ const typename DoFHandler<dim, spacedim>::active_cell_iterator &iterator,
+ const DoFHandler<dim, spacedim> & dof_handler)
+{
+ Assert(
+ &iterator->get_triangulation() == &dof_handler.get_triangulation(),
+ ExcMessage(
+ "The triangulation associated with the iterator does not match that of the dof_handler."));
+
+ return typename DoFHandler<dim, spacedim>::active_cell_iterator(
+ &dof_handler.get_triangulation(),
+ iterator->level(),
+ iterator->index(),
+ &dof_handler);
+}
+
+
namespace internal
{
namespace hp
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2022 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check that conversion between Triangulation iterator and DoFHandler iterator
+// works
+
+
+#include <deal.II/dofs/dof_handler.h>
+
+#include <deal.II/fe/fe_q.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+
+#include "../tests.h"
+
+template <int dim, int spacedim>
+void
+test()
+{
+ Triangulation<dim, spacedim> triangulation;
+ GridGenerator::hyper_cube(triangulation);
+ triangulation.refine_global(2);
+ FE_Q<dim, spacedim> fe(2);
+ DoFHandler<dim, spacedim> dof_handler(triangulation);
+ dof_handler.distribute_dofs(fe);
+
+ for (const auto &it_tria : triangulation.active_cell_iterators())
+ {
+ const auto it_dh = convert_active_cell_iterator(it_tria, dof_handler);
+ Assert(it_tria->level() == it_dh->level(),
+ ExcMessage("Iterator conversion failed: Level."));
+ Assert(it_tria->index() == it_dh->index(),
+ ExcMessage("Iterator conversion failed: Index."));
+ Assert(it_tria->id() == it_dh->id(),
+ ExcMessage("Iterator conversion failed: Id."));
+ }
+}
+
+
+
+int
+main()
+{
+ initlog();
+
+ test<1, 1>();
+ test<1, 2>();
+ test<2, 2>();
+ test<2, 3>();
+ test<3, 3>();
+
+ deallog << "OK" << std::endl;
+
+ return 0;
+}
--- /dev/null
+
+DEAL::OK
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2022 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check that conversion DoFHandler iterator to another DoFHandler iterator
+// works
+
+
+#include <deal.II/dofs/dof_handler.h>
+
+#include <deal.II/fe/fe_q.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+
+#include "../tests.h"
+
+template <int dim, int spacedim>
+void
+test()
+{
+ Triangulation<dim, spacedim> triangulation;
+ GridGenerator::hyper_cube(triangulation);
+ triangulation.refine_global(2);
+ FE_Q<dim, spacedim> fe_1(2);
+ FE_Q<dim, spacedim> fe_2(3);
+ DoFHandler<dim, spacedim> dof_handler_1(triangulation);
+ DoFHandler<dim, spacedim> dof_handler_2(triangulation);
+ dof_handler_1.distribute_dofs(fe_1);
+ dof_handler_2.distribute_dofs(fe_2);
+
+ for (const auto &it_dh_1 : dof_handler_1.active_cell_iterators())
+ {
+ const auto it_dh_2 = convert_active_cell_iterator(it_dh_1, dof_handler_2);
+ Assert(it_dh_1->level() == it_dh_2->level(),
+ ExcMessage("Iterator conversion failed: Level."));
+ Assert(it_dh_1->index() == it_dh_2->index(),
+ ExcMessage("Iterator conversion failed: Index."));
+ Assert(it_dh_1->id() == it_dh_2->id(),
+ ExcMessage("Iterator conversion failed: Id."));
+ }
+}
+
+
+
+int
+main()
+{
+ initlog();
+
+ test<1, 1>();
+ test<1, 2>();
+ test<2, 2>();
+ test<2, 3>();
+ test<3, 3>();
+
+ deallog << "OK" << std::endl;
+
+ return 0;
+}
--- /dev/null
+
+DEAL::OK