diff options
author | Erik Schnetter <schnetter@cct.lsu.edu> | 2010-04-27 10:20:03 -0500 |
---|---|---|
committer | Barry Wardell <barry.wardell@gmail.com> | 2011-12-14 16:45:48 +0000 |
commit | f69747c422faeed04848bf1a485238a927c33304 (patch) | |
tree | 100c83aebdd28f0b2ebf1b93c77e0ffc9c007a8b /Carpet | |
parent | 298d4af50f5abcd3c0d1655349d960f87f54f658 (diff) |
Carpet: Introduce bbox and bboxset loop iterators
Introduce LOOP_OVER_BBOX and LOOP_OVER_BSET iterators.
Introduce ibbox2iminimax function.
Diffstat (limited to 'Carpet')
-rw-r--r-- | Carpet/Carpet/src/modes.cc | 24 | ||||
-rw-r--r-- | Carpet/Carpet/src/modes.hh | 42 |
2 files changed, 66 insertions, 0 deletions
diff --git a/Carpet/Carpet/src/modes.cc b/Carpet/Carpet/src/modes.cc index f426b73f6..d101a509b 100644 --- a/Carpet/Carpet/src/modes.cc +++ b/Carpet/Carpet/src/modes.cc @@ -1352,6 +1352,30 @@ namespace Carpet { // + // Loop over a bounding box + // + + void ibbox2iminimax (ibbox const& ext, // component extent + ibbox const& box, // this bbox + ivect& imin, ivect& imax) + { + ivect const izero = ivect(0); + + assert (all ((box.lower() - ext.lower() ) >= 0)); + assert (all ((box.upper() - ext.lower() + ext.stride()) >= 0)); + assert (all ((box.lower() - ext.lower() ) % ext.stride() == 0)); + assert (all ((box.upper() - ext.lower() + ext.stride()) % ext.stride() == 0)); + + imin = (box.lower() - ext.lower() ) / ext.stride(); + imax = (box.upper() - ext.lower() + ext.stride()) / ext.stride(); + + assert (all (0 <= imin)); + assert (box.empty() xor all (imin <= imax)); + } + + + + // // Call a scheduling group // diff --git a/Carpet/Carpet/src/modes.hh b/Carpet/Carpet/src/modes.hh index 868c54172..37d3ec646 100644 --- a/Carpet/Carpet/src/modes.hh +++ b/Carpet/Carpet/src/modes.hh @@ -434,6 +434,48 @@ namespace Carpet { + // Loop over a bounding box + + void ibbox2iminimax (ibbox const& ext, // component extent + ibbox const& box, // this bbox + ivect& imin, ivect& imax); + +#define LOOP_OVER_BBOX(cctkGH, box_, box, imin, imax) \ + do { \ + bool bbox_loop_ = true; \ + assert (Carpet::is_local_mode()); \ + dh::light_mboxes const& light_boxes_ = \ + Carpet::vdd.AT(Carpet::map)->light_boxes; \ + ibbox const& ext_ = \ + light_boxes_.AT(mglevel).AT(reflevel).AT(component).exterior; \ + ibbox const box = (box_) & ext_; \ + if (not box.empty()) { \ + ivect imin; \ + ivect imax; \ + Carpet::ibbox2iminimax (ext_, box, imin, imax); \ + { +#define END_LOOP_OVER_BBOX \ + } \ + } /* if not empty */ \ + assert (bbox_loop_); \ + bbox_loop_ = false; \ + } while (false) + +#define LOOP_OVER_BSET(cctkGH, set_, box, imin, imax) \ + do { \ + bool bset_loop_ = true; \ + ibset const& set1_ (set_); \ + for (ibset::const_iterator bi = set1_.begin(); bi != set1_.end(); ++bi) { \ + LOOP_OVER_BBOX(cctkGH, *bi, box, imin, imax) { +#define END_LOOP_OVER_BSET \ + } END_LOOP_OVER_BBOX; \ + } /* for */ \ + assert (bset_loop_); \ + bset_loop_ = false; \ + } while (false) + + + } // namespace Carpet #endif // #ifndef MODES_HH |