From: Rene Gassmoeller Date: Wed, 17 Aug 2016 21:15:32 +0000 (-0600) Subject: Add a way to get a cell_iterator from a CellId X-Git-Tag: v8.5.0-rc1~757^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76af7c0c5edb823cbbbd4d71917d8ed7ab3c79c9;p=dealii.git Add a way to get a cell_iterator from a CellId --- diff --git a/include/deal.II/grid/cell_id.h b/include/deal.II/grid/cell_id.h index a40b0923a2..347cf5cf8a 100644 --- a/include/deal.II/grid/cell_id.h +++ b/include/deal.II/grid/cell_id.h @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 1998 - 2015 by the deal.II authors +// Copyright (C) 1998 - 2016 by the deal.II authors // // This file is part of the deal.II library. // @@ -25,6 +25,7 @@ DEAL_II_NAMESPACE_OPEN +template class Triangulation; /** * A class to represent a unique ID for a cell in a Triangulation. This class @@ -74,6 +75,13 @@ public: */ std::string to_string() const; + /** + * Return a cell_iterator to the cell represented by this CellId. + */ + template + typename Triangulation::cell_iterator + to_cell(const Triangulation &tria) const; + /** * compare two CellIds */ diff --git a/source/grid/CMakeLists.txt b/source/grid/CMakeLists.txt index 8279350bf2..89f29b7603 100644 --- a/source/grid/CMakeLists.txt +++ b/source/grid/CMakeLists.txt @@ -37,6 +37,7 @@ SET(_src ) SET(_inst + cell_id.inst.in grid_generator.inst.in grid_in.inst.in grid_out.inst.in diff --git a/source/grid/cell_id.cc b/source/grid/cell_id.cc index 57bd2764af..880be816ed 100644 --- a/source/grid/cell_id.cc +++ b/source/grid/cell_id.cc @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 2015 by the deal.II authors +// Copyright (C) 2015,2016 by the deal.II authors // // This file is part of the deal.II library. // @@ -15,6 +15,8 @@ #include +#include + #include DEAL_II_NAMESPACE_OPEN @@ -27,4 +29,19 @@ CellId::to_string() const return ss.str(); } +template +typename Triangulation::cell_iterator +CellId::to_cell(const Triangulation &tria) const +{ + typename Triangulation::cell_iterator cell (&tria,0,coarse_cell_id); + + for (unsigned int i = 0; i < id.size(); ++i) + cell = cell->child(static_cast (id[i])); + + return cell; +} + +// explicit instantiations +#include "cell_id.inst" + DEAL_II_NAMESPACE_CLOSE diff --git a/source/grid/cell_id.inst.in b/source/grid/cell_id.inst.in new file mode 100644 index 0000000000..f601a0809b --- /dev/null +++ b/source/grid/cell_id.inst.in @@ -0,0 +1,23 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS) +{ +#if deal_II_dimension <= deal_II_space_dimension + template typename Triangulation::cell_iterator CellId::to_cell(const Triangulation &tria) const; +#endif +} diff --git a/tests/grid/cell_id_03.cc b/tests/grid/cell_id_03.cc new file mode 100644 index 0000000000..1c4fc27cb7 --- /dev/null +++ b/tests/grid/cell_id_03.cc @@ -0,0 +1,76 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check CellId + +#include "../tests.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +template +void check (TRIA &tr) +{ + typename TRIA::cell_iterator cell = tr.begin(), + endc = tr.end(); + + + for (; cell!=endc; ++cell) + { + deallog << cell->level() << " " << cell->index() << std::endl; + + // Store the CellId and create a cell iterator pointing to the same cell + + const CellId cid = cell->id(); + + typename TRIA::cell_iterator cell2 = cid.to_cell(tr); + + deallog << cell2->level() << " " << cell2->index() << std::endl; + } + + deallog << "OK" << std::endl; +} + + +int main (int argc, char *argv[]) +{ + // Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads()); + + initlog(); + deal_II_exceptions::disable_abort_on_exception(); + + Triangulation<2> tria; + GridGenerator::hyper_cube (tria); + tria.refine_global (2); + tria.begin_active()->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + check(tria); +} + + + diff --git a/tests/grid/cell_id_03.output b/tests/grid/cell_id_03.output new file mode 100644 index 0000000000..42bf5a9b06 --- /dev/null +++ b/tests/grid/cell_id_03.output @@ -0,0 +1,52 @@ + +DEAL::0 0 +DEAL::0 0 +DEAL::1 0 +DEAL::1 0 +DEAL::1 1 +DEAL::1 1 +DEAL::1 2 +DEAL::1 2 +DEAL::1 3 +DEAL::1 3 +DEAL::2 0 +DEAL::2 0 +DEAL::2 1 +DEAL::2 1 +DEAL::2 2 +DEAL::2 2 +DEAL::2 3 +DEAL::2 3 +DEAL::2 4 +DEAL::2 4 +DEAL::2 5 +DEAL::2 5 +DEAL::2 6 +DEAL::2 6 +DEAL::2 7 +DEAL::2 7 +DEAL::2 8 +DEAL::2 8 +DEAL::2 9 +DEAL::2 9 +DEAL::2 10 +DEAL::2 10 +DEAL::2 11 +DEAL::2 11 +DEAL::2 12 +DEAL::2 12 +DEAL::2 13 +DEAL::2 13 +DEAL::2 14 +DEAL::2 14 +DEAL::2 15 +DEAL::2 15 +DEAL::3 0 +DEAL::3 0 +DEAL::3 1 +DEAL::3 1 +DEAL::3 2 +DEAL::3 2 +DEAL::3 3 +DEAL::3 3 +DEAL::OK