]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement BB::create_extended_relative() 15102/head
authorMaximilian Bergbauer <maximilian.bergbauer@tum.de>
Fri, 14 Apr 2023 13:15:55 +0000 (15:15 +0200)
committerMaximilian Bergbauer <maximilian.bergbauer@tum.de>
Fri, 14 Apr 2023 13:18:51 +0000 (15:18 +0200)
include/deal.II/base/bounding_box.h
source/grid/grid_tools.cc

index 610776612290a3b388df7e0fa037f5fa6c6268b2..7d9313554c43e5153780430f05a1e5325f6ce882 100644 (file)
@@ -256,6 +256,22 @@ public:
   BoundingBox<spacedim, Number>
   create_extended(const Number amount) const;
 
+  /**
+   * Increase (or decrease) each side of the bounding box by the given
+   * @p relative_amount.
+   *
+   * After calling this method, the lower left corner of the bounding box will
+   * have each coordinate decreased by @p relative_amount * side_length(direction),
+   * and the upper right corner of the bounding box will have each coordinate
+   * increased by @p relative_amount * side_length(direction).
+   *
+   * If you call this method with a negative number, and one of the axes of the
+   * original bounding box is smaller than relative_amount *
+   * side_length(direction) / 2, the method will trigger an assertion.
+   */
+  BoundingBox<spacedim, Number>
+  create_extended_relative(const Number relative_amount) const;
+
   /**
    * Compute the volume (i.e. the dim-dimensional measure) of the BoundingBox.
    */
@@ -574,6 +590,29 @@ BoundingBox<spacedim, Number>::create_extended(const Number amount) const
 }
 
 
+
+template <int spacedim, typename Number>
+inline BoundingBox<spacedim, Number>
+BoundingBox<spacedim, Number>::create_extended_relative(
+  const Number relative_amount) const
+{
+  // create and modify copy
+  auto bb = *this;
+
+  for (unsigned int d = 0; d < spacedim; ++d)
+    {
+      bb.boundary_points.first[d] -= relative_amount * side_length(d);
+      bb.boundary_points.second[d] += relative_amount * side_length(d);
+      Assert(bb.boundary_points.first[d] <= bb.boundary_points.second[d],
+             ExcMessage("Bounding Box can't be shrunk this much: the points' "
+                        "order should remain bottom left, top right."));
+    }
+
+  return bb;
+}
+
+
+
 template <int spacedim, typename Number>
 template <class Archive>
 void
index f7fddacd9b39955fb78ec4b51fc8f5911783bf92..b6ee97f2b33d880e597b0d8a2bc041733370bee5 100644 (file)
@@ -5830,8 +5830,8 @@ namespace GridTools
     // Check all points within a given pair of box and cell
     const auto check_all_points_within_box = [&](const auto &leaf) {
       const double                relative_tolerance = 1e-12;
-      const BoundingBox<spacedim> box = leaf.first.create_extended(
-        relative_tolerance * leaf.first.side_length(0));
+      const BoundingBox<spacedim> box =
+        leaf.first.create_extended_relative(relative_tolerance);
       const auto &cell_hint = leaf.second;
 
       for (const auto &point_and_id :

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.