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
*/
}
+
+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
{
// ---------------------------------------------------------------------
-// testing parent and child relationship of CellIds
+// testing parent/ancestor and child relationship of CellIds
#include <deal.II/grid/cell_id.h>
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;
}