Block-Structured AMR Software Framework
AMReX_BoxList.H
Go to the documentation of this file.
1 
2 #ifndef BL_BOXLIST_H
3 #define BL_BOXLIST_H
4 #include <AMReX_Config.H>
5 
6 #include <AMReX_IntVect.H>
7 #include <AMReX_IndexType.H>
8 #include <AMReX_Box.H>
9 #include <AMReX_Array.H>
10 #include <AMReX_Vector.H>
11 
12 #include <iosfwd>
13 
14 namespace amrex
15 {
16  class BoxArray;
17  class BoxList;
18 
20  BoxList complementIn (const Box& b, const BoxList& bl);
21 
23  BoxList boxDiff (const Box& b1in, const Box& b2);
24 
25  void boxDiff (BoxList& bl_diff, const Box& b1in, const Box& b2);
26 
28  BoxList refine (const BoxList& bl, int ratio);
29 
31  BoxList coarsen (const BoxList& bl, int ratio);
32 
34  BoxList intersect (const BoxList& bl, const Box& b);
35 
37  BoxList accrete (const BoxList& bl, int sz);
38 
41 
42 
44  std::ostream& operator<< (std::ostream& os, const BoxList& blist);
45 
46 
51 class BoxList
52 {
53 public:
54 
55  friend class BoxDomain;
56 
59 
61  BoxList ();
62 
64  explicit BoxList (const Box& bx);
65 
67  explicit BoxList (IndexType _btype);
68 
70  explicit BoxList (const BoxArray& ba);
71 
73  explicit BoxList (Vector<Box>&& bxs);
74 
76  BoxList (const Box& bx, const IntVect& tilesize);
77 
79  BoxList (const Box& bx, int nboxes);
80 
82  BoxList (const Box& bx, int nboxes, Direction dir);
83 
84  ~BoxList () = default;
85  BoxList (const BoxList& rhs) = default;
86  BoxList (BoxList&& rhs) = default;
87  BoxList& operator= (const BoxList& rhs) = default;
88  BoxList& operator= (BoxList&& rhs) = default;
89 
90  void reserve (std::size_t n) { m_lbox.reserve(n); }
91 
93  void push_back (const Box& bn) {
94  if (m_lbox.empty()) { btype = bn.ixType(); }
95  BL_ASSERT(ixType() == bn.ixType());
96  m_lbox.push_back(bn);
97  }
98 
99  [[nodiscard]] Box& front () noexcept { BL_ASSERT(!m_lbox.empty()); return m_lbox.front(); }
100 
101  [[nodiscard]] const Box& front () const noexcept { BL_ASSERT(!m_lbox.empty()); return m_lbox.front(); }
102 
104  void join (const BoxList& blist);
106  void join (const Vector<Box>& barr);
108  void catenate (BoxList& blist);
109 
111  void clear ();
113  [[nodiscard]] Long size () const noexcept { return m_lbox.size(); }
114 
115  [[nodiscard]] std::size_t capacity () const noexcept { return m_lbox.capacity(); }
116 
117  [[nodiscard]] iterator begin () noexcept { return m_lbox.begin(); }
118  [[nodiscard]] const_iterator begin () const noexcept { return m_lbox.cbegin(); }
119  [[nodiscard]] const_iterator cbegin () const noexcept { return m_lbox.cbegin(); }
120 
121  [[nodiscard]] iterator end () noexcept { return m_lbox.end(); }
122  [[nodiscard]] const_iterator end () const noexcept { return m_lbox.cend(); }
123  [[nodiscard]] const_iterator cend () const noexcept { return m_lbox.cend(); }
129  [[nodiscard]] bool ok () const noexcept;
131  bool operator== (const BoxList& rhs) const;
133  bool operator!= (const BoxList& rhs) const;
135  [[nodiscard]] bool isEmpty () const noexcept { return m_lbox.empty(); }
137  [[nodiscard]] bool isNotEmpty () const noexcept { return !m_lbox.empty(); }
139  [[nodiscard]] bool isDisjoint () const;
141  [[nodiscard]] bool contains (const BoxList& bl) const;
143  BoxList& intersect (const Box& b);
145  BoxList& intersect (const BoxList& bl);
148 
149  BoxList& complementIn (const Box& b, const BoxList& bl);
150  BoxList& complementIn (const Box& b, BoxList&& bl);
151  BoxList& complementIn (const Box& b, const BoxArray& ba);
152  BoxList& parallelComplementIn (const Box& b, const BoxList& bl);
154  BoxList& parallelComplementIn (const Box& b, const BoxArray& ba);
155 
157  BoxList& refine (int ratio);
159  BoxList& refine (const IntVect& ratio);
161  BoxList& coarsen (int ratio);
163  BoxList& coarsen (const IntVect& ratio);
165  BoxList& accrete (int sz);
166  BoxList& accrete (const IntVect& sz);
168  BoxList& shift (int dir,
169  int nzones);
171  BoxList& shiftHalf (int dir,
172  int num_halfs);
174  BoxList& shiftHalf (const IntVect& iv);
184  int simplify (bool best = false);
188  BoxList& maxSize (int chunk);
190  BoxList& maxSize (const IntVect& chunk);
192  [[nodiscard]] Box minimalBox () const;
194  [[nodiscard]] IndexType ixType () const noexcept { return btype; }
196  void set (IndexType ixtyp) noexcept { BL_ASSERT(m_lbox.empty()); btype = ixtyp; }
201  BoxList& surroundingNodes () noexcept;
206  BoxList& surroundingNodes (int dir) noexcept;
208  BoxList& enclosedCells () noexcept;
210  BoxList& enclosedCells (int dir) noexcept;
212  BoxList& convert (IndexType typ) noexcept;
213 
215  [[nodiscard]] Vector<Box>& data () noexcept { return m_lbox; }
217  [[nodiscard]] const Vector<Box>& data () const noexcept { return m_lbox; }
218 
219  void swap (BoxList& rhs) noexcept {
220  std::swap(m_lbox, rhs.m_lbox);
221  std::swap(btype, rhs.btype);
222  }
223 
224  void Bcast ();
225 
226 private:
228  int simplify_doit (int depth);
229 
234 
235 };
236 
237 }
238 
239 #endif /*BL_BOXLIST_H*/
#define BL_ASSERT(EX)
Definition: AMReX_BLassert.H:39
A collection of Boxes stored in an Array.
Definition: AMReX_BoxArray.H:550
A List of Disjoint Boxes.
Definition: AMReX_BoxDomain.H:67
A class for managing a List of Boxes that share a common IndexType. This class implements operations ...
Definition: AMReX_BoxList.H:52
BoxList & shiftHalf(const IntVect &iv)
Applies Box::shiftHalf(IntVect) to each Box in BoxList.
bool ok() const noexcept
True if this BoxList is valid; i.e. all the Boxes are valid and they all have the same IndexType....
BoxList(const Box &bx)
Make a boxList consisting of a single Box.
bool contains(const BoxList &bl) const
True if all Boxes in bl are contained in this BoxList.
BoxList & surroundingNodes() noexcept
Applies surroundingNodes(Box) to each Box in BoxArray. See the documentation of Box for details.
const_iterator cend() const noexcept
Definition: AMReX_BoxList.H:123
bool isDisjoint() const
True if the set of intersecting Boxes is empty.
void clear()
Remove all Boxes from this BoxList.
BoxList(IndexType _btype)
Construct an empty BoxList with IndexType _btype.
BoxList & complementIn(const Box &b, const BoxArray &ba)
BoxList & intersect(const Box &b)
Modify this BoxList to contain only its intersection with Box b.
IndexType ixType() const noexcept
Returns the IndexType of Boxes in this BoxList.
Definition: AMReX_BoxList.H:194
const_iterator cbegin() const noexcept
Definition: AMReX_BoxList.H:119
BoxList(const Box &bx, const IntVect &tilesize)
Make a boxList consisting of non-overlapping tile box from a single Box.
BoxList()
Construct an empty BoxList with IndexType::TheCellType().
const_iterator end() const noexcept
Definition: AMReX_BoxList.H:122
Vector< Box > & data() noexcept
Returns a reference to the Vector<Box>.
Definition: AMReX_BoxList.H:215
BoxList & coarsen(int ratio)
Coarsen each Box in the BoxList by the ratio.
BoxList & accrete(int sz)
Grow each Box in the BoxList by size sz.
BoxList(Vector< Box > &&bxs)
Construct a boxlist from a rvalue Vector<Box>.
iterator end() noexcept
Definition: AMReX_BoxList.H:121
BoxList & removeEmpty()
Remove empty Boxes from this BoxList.
BoxList & convert(IndexType typ) noexcept
Applies Box::convert(IndexType) to each Box in the BoxList.
BoxList & parallelComplementIn(const Box &b, BoxList &&bl)
void catenate(BoxList &blist)
Catenate the BoxList to ourselves. Removes entries from blist.
BoxList(const Box &bx, int nboxes)
Make a BoxList consisting of nboxes Boxes from a single Box.
bool isEmpty() const noexcept
Is this BoxList empty?
Definition: AMReX_BoxList.H:135
void set(IndexType ixtyp) noexcept
Set the type of the BoxList. It's an error if the BoxList isn't empty.
Definition: AMReX_BoxList.H:196
BoxList & refine(const IntVect &ratio)
Refine each Box in the BoxList by the ratio.
BoxList(const BoxList &rhs)=default
std::size_t capacity() const noexcept
Definition: AMReX_BoxList.H:115
~BoxList()=default
const Box & front() const noexcept
Definition: AMReX_BoxList.H:101
BoxList(BoxList &&rhs)=default
bool isNotEmpty() const noexcept
Is this BoxList not empty?
Definition: AMReX_BoxList.H:137
BoxList & operator=(const BoxList &rhs)=default
IndexType btype
The IndexType of Boxes in the BoxList.
Definition: AMReX_BoxList.H:233
BoxList & shift(int dir, int nzones)
Applies Box::shift(int,int) to each Box in the BoxList.
BoxList & complementIn(const Box &b, const BoxList &bl)
void reserve(std::size_t n)
Definition: AMReX_BoxList.H:90
BoxList & parallelComplementIn(const Box &b, const BoxArray &ba)
int simplify(bool best=false)
Merge adjacent Boxes in this BoxList. Return the number of Boxes merged. If "best" is specified we do...
const_iterator begin() const noexcept
Definition: AMReX_BoxList.H:118
BoxList & refine(int ratio)
Refine each Box in the BoxList by the ratio.
BoxList & maxSize(int chunk)
Forces each Box in the BoxList to have sides of length <= chunk.
BoxList & complementIn(const Box &b, BoxList &&bl)
void swap(BoxList &rhs) noexcept
Definition: AMReX_BoxList.H:219
BoxList & enclosedCells() noexcept
Applies Box::enclosedCells() to each Box in the BoxList.
BoxList & intersect(const BoxList &bl)
Modify this BoxList to contain only its intersection with BoxList bl.
BoxList & coarsen(const IntVect &ratio)
Coarsen each Box in the BoxList by the ratio.
BoxList(const BoxArray &ba)
Construct a BoxList from a BoxArray.
int simplify_doit(int depth)
Core simplify routine.
void push_back(const Box &bn)
Append a Box to this BoxList.
Definition: AMReX_BoxList.H:93
Box & front() noexcept
Definition: AMReX_BoxList.H:99
const Vector< Box > & data() const noexcept
Returns a constant reference to the Vector<Box>.
Definition: AMReX_BoxList.H:217
int ordered_simplify()
Assuming the boxes are nicely ordered.
iterator begin() noexcept
Definition: AMReX_BoxList.H:117
BoxList & shiftHalf(int dir, int num_halfs)
Applies Box::shiftHalf(int,int) to each Box in the BoxList.
Long size() const noexcept
The number of Boxes in this BoxList.
Definition: AMReX_BoxList.H:113
BoxList & maxSize(const IntVect &chunk)
Forces each Box in the BoxList to have dimth side of length <= chunk[dim].
Box minimalBox() const
Returns smallest Box that contains all Boxes in this BoxList.
Vector< Box >::iterator iterator
Definition: AMReX_BoxList.H:57
BoxList & parallelComplementIn(const Box &b, const BoxList &bl)
Vector< Box > m_lbox
The list of Boxes.
Definition: AMReX_BoxList.H:231
Vector< Box >::const_iterator const_iterator
Definition: AMReX_BoxList.H:58
BoxList & accrete(const IntVect &sz)
void join(const Vector< Box > &barr)
Join the Array of Boxes to ourselves.
void join(const BoxList &blist)
Join the BoxList to ourselves.
BoxList(const Box &bx, int nboxes, Direction dir)
Make a BoxList consisting of nboxes Boxes chopped in dir-direction from a single Box.
AMREX_GPU_HOST_DEVICE IndexTypeND< dim > ixType() const noexcept
Returns the indexing type.
Definition: AMReX_Box.H:127
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition: AMReX_Vector.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void swap(T &a, T &b) noexcept
Definition: AMReX_algoim_K.H:113
Definition: AMReX_Amr.cpp:49
void accrete(BoxDomain &dest, const BoxDomain &fin, int sz)
Grow each Box in BoxDomain fin by size sz and place the result into BoxDomain dest.
Definition: AMReX_BoxDomain.cpp:45
BoxArray intersect(const BoxArray &ba, const Box &b, int ng=0)
Make a BoxArray from the intersection of Box b and BoxArray(+ghostcells).
BoxList boxDiff(const Box &b1in, const Box &b2)
Returns BoxList defining the compliment of b2 in b1in.
BoxArray complementIn(const Box &b, const BoxArray &ba)
Make a BoxArray from the complement of BoxArray ba in Box b.
Direction
Definition: AMReX_Orientation.H:14
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE BoxND< dim > refine(const BoxND< dim > &b, int ref_ratio) noexcept
Definition: AMReX_Box.H:1342
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Coarsen BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo/rati...
Definition: AMReX_Box.H:1304
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition: AMReX_AmrMesh.cpp:1236
BoxList removeOverlap(const BoxList &bl)
Return BoxList which covers the same area but has no overlapping boxes.