From 606c70ba30488ae8b5bf9384bbe85dc94e0cc522 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Sun, 26 May 2013 16:22:04 -0400 Subject: CarpetLib: New function bbox::anti_contracted_for anti_contracted_for is the exact opposite of contracted for. It is similar to expanded_for, but may return different results in corner cases. --- Carpet/CarpetLib/src/bbox.cc | 20 ++++++++++++++++++++ Carpet/CarpetLib/src/bbox.hh | 3 +++ 2 files changed, 23 insertions(+) diff --git a/Carpet/CarpetLib/src/bbox.cc b/Carpet/CarpetLib/src/bbox.cc index 5c561c498..63f2040e2 100644 --- a/Carpet/CarpetLib/src/bbox.cc +++ b/Carpet/CarpetLib/src/bbox.cc @@ -222,6 +222,26 @@ bbox bbox::contracted_for (const bbox& b) const { return bbox(lo,up,str); } +// Find the smallest open b-compatible box around *this: +// This routine is similar to expanded_for. However, it returns a box +// that is possibly larger than the box returned by expanded_for. +template +bbox bbox::anti_contracted_for (const bbox& b) const { + if (empty()) return bbox(b.lower(), b.lower()-b.stride(), b.stride()); + return expand(1, 1).expanded_for(b).expand(-1, -1); + // if (all(stride() <= b.stride())) { + // // New stride is larger or equal to current stride: forward call + // // to expanded_for + // return expanded_for(b); + // } + // if (all(stride() > b.stride())) { + // // New stride is smaller than current stride: expand box by one + // // stride, call expanded_for, and shrink box by on stride again + // return expand(1, 1).expanded_for(b).expand(-1, -1); + // } + // __builtin_unreachable(); +} + // Smallest bbox containing both boxes template bbox bbox::expanded_containing (const bbox& b) const { diff --git a/Carpet/CarpetLib/src/bbox.hh b/Carpet/CarpetLib/src/bbox.hh index d65928e02..5dea7f9d3 100644 --- a/Carpet/CarpetLib/src/bbox.hh +++ b/Carpet/CarpetLib/src/bbox.hh @@ -184,6 +184,9 @@ public: /** Find the largest b-compatible box inside this bbox. */ bbox contracted_for (const bbox& b) const CCTK_MEMBER_ATTRIBUTE_PURE; + /** Find the smallest open b-compatible box around *this */ + bbox anti_contracted_for (const bbox& b) const CCTK_MEMBER_ATTRIBUTE_PURE; + /** Find the smallest bbox containing both boxes. */ bbox expanded_containing (const bbox& b) const CCTK_MEMBER_ATTRIBUTE_PURE; -- cgit v1.2.3