]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add CellId::is_ancestor_of 9214/head
authorPeter Munch <peterrmuench@gmail.com>
Thu, 2 Jan 2020 17:16:18 +0000 (18:16 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Thu, 2 Jan 2020 17:16:18 +0000 (18:16 +0100)
doc/news/changes/minor/20200102PeterMunch [new file with mode: 0644]
include/deal.II/grid/cell_id.h
tests/grid/cell_id_06.cc
tests/grid/cell_id_06.output

diff --git a/doc/news/changes/minor/20200102PeterMunch b/doc/news/changes/minor/20200102PeterMunch
new file mode 100644 (file)
index 0000000..e2997f3
--- /dev/null
@@ -0,0 +1,3 @@
+New: Add method is_ancestor_of to CellId.
+<br>
+(Peter Munch, 2020/01/02)
index 721e51b416a75dd78d25b2bd16d8975fb052b31f..f628f0b92035670d6dc3202a0da71adbe0b39098 100644 (file)
@@ -171,6 +171,12 @@ public:
   bool
   is_parent_of(const CellId &other) const;
 
+  /**
+   * Determine if this cell id is the ancestor of the input cell id.
+   */
+  bool
+  is_ancestor_of(const CellId &other) const;
+
   /**
    * Boost serialization function
    */
@@ -350,6 +356,24 @@ CellId::is_parent_of(const CellId &other) const
 }
 
 
+
+inline bool
+CellId::is_ancestor_of(const CellId &other) const
+{
+  if (this->coarse_cell_id != other.coarse_cell_id)
+    return false;
+
+  if (n_child_indices >= 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
 {
index f1b5354770975c8e28f4c15431b65f182522a403..091563cad031c568ee1768818a37469e302bab14 100644 (file)
@@ -14,7 +14,7 @@
 // ---------------------------------------------------------------------
 
 
-// testing parent and child relationship of CellIds
+// testing parent/ancestor and child relationship of CellIds
 
 #include <deal.II/grid/cell_id.h>
 
@@ -32,19 +32,16 @@ main()
   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;
+  for (const auto &pair :
+       std::vector<std::pair<CellId, CellId>>{
+         {id0, id0}, // same cell (expected: false, false)
+         {id0, id1}, // same level (false, false)
+         {id0, id2}, // child (true, true)
+         {id0, id3}, // grand child (false, true)
+         {id0, id4}} // cell with different coarse-cell id (false, false)
+  )
+    deallog << pair.first.is_parent_of(pair.second) << " "
+            << pair.first.is_ancestor_of(pair.second) << std::endl;
 }
index 3c5613acaaf4e602a066069bcc2f722379e11854..99b001189b01231bda3a713329c5ce41dc4c87ca 100644 (file)
@@ -1,6 +1,6 @@
 
-DEAL::false
-DEAL::false
-DEAL::true
-DEAL::false
-DEAL::false
+DEAL::false false
+DEAL::false false
+DEAL::true true
+DEAL::false true
+DEAL::false 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.