From: Marc Fehling Date: Sun, 13 Dec 2020 02:41:12 +0000 (-0700) Subject: Added Triangulation::create_cell_iterator(). X-Git-Tag: v9.3.0-rc1~734^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F11365%2Fhead;p=dealii.git Added Triangulation::create_cell_iterator(). --- diff --git a/doc/news/changes/incompatibilities/20201212Fehling b/doc/news/changes/incompatibilities/20201212Fehling new file mode 100644 index 0000000000..e90b30f7bf --- /dev/null +++ b/doc/news/changes/incompatibilities/20201212Fehling @@ -0,0 +1,4 @@ +Deprecated: The function CellId::to_cell() has been replaced by +Triangulation::create_cell_iterator(). +
+(Marc Fehling, 2020/12/12) diff --git a/include/deal.II/grid/cell_id.h b/include/deal.II/grid/cell_id.h index 4b23bb3716..d1716bb6a4 100644 --- a/include/deal.II/grid/cell_id.h +++ b/include/deal.II/grid/cell_id.h @@ -148,9 +148,11 @@ public: /** * Return a cell_iterator to the cell represented by this CellId. + * + * @deprecated Use Triangulation::create_cell_iterator() instead. */ template - typename Triangulation::cell_iterator + DEAL_II_DEPRECATED typename Triangulation::cell_iterator to_cell(const Triangulation &tria) const; /** diff --git a/include/deal.II/grid/tria.h b/include/deal.II/grid/tria.h index bca79fbf5f..d98377b26e 100644 --- a/include/deal.II/grid/tria.h +++ b/include/deal.II/grid/tria.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -2743,6 +2744,21 @@ public: active_cell_iterator last_active() const; + /** + * Return an iterator to a cell of this Triangulation object constructed from + * an independent CellId object. + * + * If the given argument corresponds to a valid cell in this triangulation, + * this operation will always succeed for sequential triangulations where the + * current processor stores all cells that are part of the triangulation. On + * the other hand, if this is a parallel triangulation, then the current + * processor may not actually know about this cell. In this case, this + * operation will succeed for locally relevant cells, but may not for + * artificial cells that are less refined on the current processor. + */ + cell_iterator + create_cell_iterator(const CellId &cell_id) const; + /** * @name Cell iterator functions returning ranges of iterators */ @@ -4029,8 +4045,6 @@ private: friend class dealii::internal::TriangulationImplementation::TriaObjects; - friend class CellId; - // explicitly check for sensible template arguments, but not on windows // because MSVC creates bogus warnings during normal compilation #ifndef DEAL_II_MSVC diff --git a/source/grid/cell_id.cc b/source/grid/cell_id.cc index 81ba05cdb6..2dbe9567e0 100644 --- a/source/grid/cell_id.cc +++ b/source/grid/cell_id.cc @@ -166,15 +166,10 @@ template typename Triangulation::cell_iterator CellId::to_cell(const Triangulation &tria) const { - typename Triangulation::cell_iterator cell( - &tria, 0, tria.coarse_cell_id_to_coarse_cell_index(coarse_cell_id)); - - for (unsigned int i = 0; i < n_child_indices; ++i) - cell = cell->child(static_cast(child_indices[i])); - - return cell; + return tria.create_cell_iterator(*this); } + // explicit instantiations #include "cell_id.inst" diff --git a/source/grid/tria.cc b/source/grid/tria.cc index d9d2b7737a..1feb29179c 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -11985,6 +11985,31 @@ Triangulation::last_active() const +template +typename Triangulation::cell_iterator +Triangulation::create_cell_iterator(const CellId &cell_id) const +{ + cell_iterator cell( + this, 0, coarse_cell_id_to_coarse_cell_index(cell_id.get_coarse_cell_id())); + + for (const auto &child_index : cell_id.get_child_indices()) + { + Assert( + cell->has_children(), + ExcMessage( + "CellId is invalid for this triangulation.\n" + "Either the provided CellId does not correspond to a cell in this " + "triangulation object, or, in case you are using a parallel " + "triangulation, may correspond to an artificial cell that is less " + "refined on this processor.")); + cell = cell->child(static_cast(child_index)); + } + + return cell; +} + + + template typename Triangulation::cell_iterator Triangulation::end() const diff --git a/tests/fe/fe_subface_values_01.cc b/tests/fe/fe_subface_values_01.cc index 195062eac0..fc9cc8f641 100644 --- a/tests/fe/fe_subface_values_01.cc +++ b/tests/fe/fe_subface_values_01.cc @@ -74,12 +74,12 @@ run(unsigned int degree, unsigned int n_q_points) UpdateFlags flags = update_quadrature_points; // dummy FESubfaceValues sub_face(fe, quad, flags); - sub_face.reinit(CellId(0, {1}).to_cell(tria), 0, 0); + sub_face.reinit(tria.create_cell_iterator(CellId(0, {1})), 0, 0); for (auto p : sub_face.get_quadrature_points()) deallog << p << std::endl; deallog << std::endl; - sub_face.reinit(CellId(0, {1}).to_cell(tria), 1, 0); + sub_face.reinit(tria.create_cell_iterator(CellId(0, {1})), 1, 0); for (auto p : sub_face.get_quadrature_points()) deallog << p << std::endl; deallog << std::endl; diff --git a/tests/fullydistributed_grids/copy_distributed_tria_03.cc b/tests/fullydistributed_grids/copy_distributed_tria_03.cc index 30c067f4f8..b420846261 100644 --- a/tests/fullydistributed_grids/copy_distributed_tria_03.cc +++ b/tests/fullydistributed_grids/copy_distributed_tria_03.cc @@ -63,7 +63,7 @@ test(int n_refinements, const int n_subdivisions, MPI_Comm comm) for (auto &cell : tria_pft.active_cell_iterators()) { CellId id = cell->id(); - auto cell_base = id.to_cell(tria_pdt); + auto cell_base = tria_pdt.create_cell_iterator(id); for (unsigned int d = 0; d < dim; d++) Assert(std::abs(cell->center()[d] - cell_base->center()[d]) < 1e-9, ExcMessage("Cells do not match")); diff --git a/tests/fullydistributed_grids/copy_serial_tria_08.cc b/tests/fullydistributed_grids/copy_serial_tria_08.cc index a83aa5ee74..d0d68e5464 100644 --- a/tests/fullydistributed_grids/copy_serial_tria_08.cc +++ b/tests/fullydistributed_grids/copy_serial_tria_08.cc @@ -65,7 +65,7 @@ test(int n_refinements, MPI_Comm comm) for (auto &cell : tria_pft.active_cell_iterators()) { CellId id = cell->id(); - auto cell_base = id.to_cell(basetria); + auto cell_base = basetria.create_cell_iterator(id); // Assert(cell->center() == cell_base->center(), // ExcMessage("Cells do not match")); for (unsigned int d = 0; d < dim; d++) diff --git a/tests/fullydistributed_grids/copy_serial_tria_09.cc b/tests/fullydistributed_grids/copy_serial_tria_09.cc index 118e2e3b7e..5bc44455ff 100644 --- a/tests/fullydistributed_grids/copy_serial_tria_09.cc +++ b/tests/fullydistributed_grids/copy_serial_tria_09.cc @@ -79,7 +79,7 @@ test(int n_refinements, for (auto &cell : tria_pft.active_cell_iterators()) { CellId id = cell->id(); - auto cell_base = id.to_cell(basetria); + auto cell_base = basetria.create_cell_iterator(id); for (unsigned int d = 0; d < dim; d++) Assert(std::abs(cell->center()[d] - cell_base->center()[d]) < 1e-9, ExcMessage("Cells do not match")); diff --git a/tests/grid/cell_id_03.cc b/tests/grid/cell_id_03.cc index 4d719abef0..8defc8c542 100644 --- a/tests/grid/cell_id_03.cc +++ b/tests/grid/cell_id_03.cc @@ -49,7 +49,7 @@ check(TRIA &tr) const CellId cid = cell->id(); - typename TRIA::cell_iterator cell2 = cid.to_cell(tr); + typename TRIA::cell_iterator cell2 = tr.create_cell_iterator(cid); deallog << cell2->level() << " " << cell2->index() << std::endl; } diff --git a/tests/grid/cell_id_04.cc b/tests/grid/cell_id_04.cc index 55d79dc461..d66c42ccad 100644 --- a/tests/grid/cell_id_04.cc +++ b/tests/grid/cell_id_04.cc @@ -56,7 +56,8 @@ check(Triangulation &tr) const CellId cid2(cids); - typename Triangulation::cell_iterator cell2 = cid2.to_cell(tr); + typename Triangulation::cell_iterator cell2 = + tr.create_cell_iterator(cid2); Assert(cid2 == cid, ExcInternalError()); Assert(cell2 == cell, ExcInternalError()); diff --git a/tests/sharedtria/mg_dof_01.cc b/tests/sharedtria/mg_dof_01.cc index 9918d477c2..3fd2c10f23 100644 --- a/tests/sharedtria/mg_dof_01.cc +++ b/tests/sharedtria/mg_dof_01.cc @@ -75,7 +75,8 @@ compare_meshes(DoFHandler &shared_dof_handler, continue; typename Triangulation::cell_iterator tria_shared_cell = - cell->id().to_cell(shared_dof_handler.get_triangulation()); + shared_dof_handler.get_triangulation().create_cell_iterator( + cell->id()); typename DoFHandler::cell_iterator dof_shared_cell( &shared_dof_handler.get_triangulation(), tria_shared_cell->level(),