From: Maximilian Bergbauer Date: Fri, 14 Apr 2023 13:15:55 +0000 (+0200) Subject: Implement BB::create_extended_relative() X-Git-Tag: v9.5.0-rc1~324^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F15102%2Fhead;p=dealii.git Implement BB::create_extended_relative() --- diff --git a/include/deal.II/base/bounding_box.h b/include/deal.II/base/bounding_box.h index 6107766122..7d9313554c 100644 --- a/include/deal.II/base/bounding_box.h +++ b/include/deal.II/base/bounding_box.h @@ -256,6 +256,22 @@ public: BoundingBox 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 + 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::create_extended(const Number amount) const } + +template +inline BoundingBox +BoundingBox::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 template void diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index f7fddacd9b..b6ee97f2b3 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -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 box = leaf.first.create_extended( - relative_tolerance * leaf.first.side_length(0)); + const BoundingBox box = + leaf.first.create_extended_relative(relative_tolerance); const auto &cell_hint = leaf.second; for (const auto &point_and_id :