]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a way to get a cell_iterator from a CellId
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Wed, 17 Aug 2016 21:15:32 +0000 (15:15 -0600)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Wed, 17 Aug 2016 23:54:00 +0000 (17:54 -0600)
include/deal.II/grid/cell_id.h
source/grid/CMakeLists.txt
source/grid/cell_id.cc
source/grid/cell_id.inst.in [new file with mode: 0644]
tests/grid/cell_id_03.cc [new file with mode: 0644]
tests/grid/cell_id_03.output [new file with mode: 0644]

index a40b0923a2390a496a67f8a6fef9680f20d6f06c..347cf5cf8aaa3d7aea8abe5b28bd5da700bd1d03 100644 (file)
@@ -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 <int, int> 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<int dim, int spacedim>
+  typename Triangulation<dim,spacedim>::cell_iterator
+  to_cell(const Triangulation<dim,spacedim> &tria) const;
+
   /**
    * compare two CellIds
    */
index 8279350bf27ab47b9fd7994a23b8f81f983d743e..89f29b7603c2d8bf81e6f237c4d511b433939b5c 100644 (file)
@@ -37,6 +37,7 @@ SET(_src
   )
 
 SET(_inst
+  cell_id.inst.in
   grid_generator.inst.in
   grid_in.inst.in
   grid_out.inst.in
index 57bd2764afa418ac21ca2bb9660db57181ef2b62..880be816ed7e597cc67284bb351b83287062b21a 100644 (file)
@@ -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 <deal.II/grid/cell_id.h>
 
+#include <deal.II/grid/tria.h>
+
 #include <sstream>
 
 DEAL_II_NAMESPACE_OPEN
@@ -27,4 +29,19 @@ CellId::to_string() const
   return ss.str();
 }
 
+template<int dim, int spacedim>
+typename Triangulation<dim,spacedim>::cell_iterator
+CellId::to_cell(const Triangulation<dim,spacedim> &tria) const
+{
+  typename Triangulation<dim,spacedim>::cell_iterator cell (&tria,0,coarse_cell_id);
+
+  for (unsigned int i = 0; i < id.size(); ++i)
+    cell = cell->child(static_cast<unsigned int> (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 (file)
index 0000000..f601a08
--- /dev/null
@@ -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<deal_II_dimension,deal_II_space_dimension>::cell_iterator CellId::to_cell(const Triangulation<deal_II_dimension,deal_II_space_dimension> &tria) const;
+#endif
+}
diff --git a/tests/grid/cell_id_03.cc b/tests/grid/cell_id_03.cc
new file mode 100644 (file)
index 0000000..1c4fc27
--- /dev/null
@@ -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 <deal.II/base/geometry_info.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/distributed/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_refinement.h>
+
+#include <fstream>
+#include <sstream>
+
+template <class TRIA>
+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 (file)
index 0000000..42bf5a9
--- /dev/null
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.