]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add CellId::is_parent_of 8737/head
authorPeter Munch <peterrmuench@gmail.com>
Wed, 11 Sep 2019 19:00:27 +0000 (21:00 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Wed, 11 Sep 2019 20:37:21 +0000 (22:37 +0200)
doc/news/changes/minor/20190911PeterMunch [new file with mode: 0644]
include/deal.II/grid/cell_id.h
tests/grid/cell_id_06.cc [new file with mode: 0644]
tests/grid/cell_id_06.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20190911PeterMunch b/doc/news/changes/minor/20190911PeterMunch
new file mode 100644 (file)
index 0000000..d06245d
--- /dev/null
@@ -0,0 +1,3 @@
+New: Add method is_parent_of to CellId.
+<br>
+(Peter Munch, 2019/09/11)
index 169295818c3cd0724e886885090192b70f8383ed..3787b97801f90b374176e427fbe8eead6e226a5f 100644 (file)
@@ -156,6 +156,12 @@ public:
   bool
   operator<(const CellId &other) const;
 
+  /**
+   * Determine if this cell id is the direct parent of the input cell id.
+   */
+  bool
+  is_parent_of(const CellId &other) const;
+
   /**
    * Boost serialization function
    */
@@ -317,6 +323,24 @@ CellId::operator<(const CellId &other) const
 }
 
 
+
+inline bool
+CellId::is_parent_of(const CellId &other) const
+{
+  if (this->coarse_cell_id != other.coarse_cell_id)
+    return false;
+
+  if (n_child_indices + 1 != other.n_child_indices)
+    return false;
+
+  for (unsigned int idx = 0; idx < n_child_indices; ++idx)
+    if (child_indices[idx] != other.child_indices[idx])
+      return false;
+
+  return true; // other.id is longer
+}
+
+
 inline types::coarse_cell_id
 CellId::get_coarse_cell_id() const
 {
diff --git a/tests/grid/cell_id_06.cc b/tests/grid/cell_id_06.cc
new file mode 100644 (file)
index 0000000..f1b5354
--- /dev/null
@@ -0,0 +1,50 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2019 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.
+//
+// ---------------------------------------------------------------------
+
+
+// testing parent and child relationship of CellIds
+
+#include <deal.II/grid/cell_id.h>
+
+#include "../tests.h"
+
+int
+main()
+{
+  initlog();
+
+  // create some arbitrary CellIds
+  CellId id0(0, {0});
+  CellId id1(0, {1});
+  CellId id2(0, {0, 0});
+  CellId id3(0, {0, 0, 0});
+  CellId id4(1, {0});
+
+  // same cell (expected: false)
+  deallog << std::boolalpha;
+  deallog << id0.is_parent_of(id0) << std::endl;
+
+  // same level (false)
+  deallog << id0.is_parent_of(id1) << std::endl;
+
+  // child (true)
+  deallog << id0.is_parent_of(id2) << std::endl;
+
+  // grand child (false)
+  deallog << id0.is_parent_of(id3) << std::endl;
+
+  // cell with different coarse-cell id (false)
+  deallog << id0.is_parent_of(id4) << std::endl;
+}
diff --git a/tests/grid/cell_id_06.output b/tests/grid/cell_id_06.output
new file mode 100644 (file)
index 0000000..3c5613a
--- /dev/null
@@ -0,0 +1,6 @@
+
+DEAL::false
+DEAL::false
+DEAL::true
+DEAL::false
+DEAL::false

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.