Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
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
11#include <AMReX_IntVect.H>
12#include <AMReX_IndexType.H>
13#include <AMReX_Box.H>
14#include <AMReX_Array.H>
15#include <AMReX_Vector.H>
16
17#include <iosfwd>
18
19namespace amrex
20{
21 class BoxArray;
22 class BoxList;
23
31 BoxList complementIn (const Box& b, const BoxList& bl);
32
39 BoxList boxDiff (const Box& b1in, const Box& b2);
40
48 void boxDiff (BoxList& bl_diff, const Box& b1in, const Box& b2);
49
56 BoxList refine (const BoxList& bl, int ratio);
57
64 BoxList coarsen (const BoxList& bl, int ratio);
65
72 BoxList intersect (const BoxList& bl, const Box& b);
73
80 BoxList accrete (const BoxList& bl, int sz);
81
87 BoxList removeOverlap (const BoxList& bl);
88
89
97 std::ostream& operator<< (std::ostream& os, const BoxList& blist);
98
99
109{
110public:
111
112 friend class BoxDomain;
113
116
118 BoxList ();
119
121 explicit BoxList (const Box& bx);
122
124 explicit BoxList (IndexType _btype);
125
127 explicit BoxList (const BoxArray& ba);
128
130 explicit BoxList (Vector<Box>&& bxs);
131
133 BoxList (const Box& bx, const IntVect& tilesize);
134
136 BoxList (const Box& bx, int nboxes);
137
139 BoxList (const Box& bx, int nboxes, Direction dir);
140
141 ~BoxList () = default;
142 BoxList (const BoxList& rhs) = default;
143 BoxList (BoxList&& rhs) = default;
144 BoxList& operator= (const BoxList& rhs) = default;
145 BoxList& operator= (BoxList&& rhs) = default;
146
148 void reserve (std::size_t n) { m_lbox.reserve(n); }
149
151 void push_back (const Box& bn) {
152 if (m_lbox.empty()) { btype = bn.ixType(); }
153 BL_ASSERT(ixType() == bn.ixType());
154 m_lbox.push_back(bn);
155 }
156
158 [[nodiscard]] Box& front () noexcept { BL_ASSERT(!m_lbox.empty()); return m_lbox.front(); }
159
161 [[nodiscard]] const Box& front () const noexcept { BL_ASSERT(!m_lbox.empty()); return m_lbox.front(); }
162
164 void join (const BoxList& blist);
166 void join (const Vector<Box>& barr);
168 void catenate (BoxList& blist);
169
171 void clear ();
173 [[nodiscard]] Long size () const noexcept { return m_lbox.size(); }
174
176 [[nodiscard]] std::size_t capacity () const noexcept { return m_lbox.capacity(); }
177
179 [[nodiscard]] iterator begin () noexcept { return m_lbox.begin(); }
181 [[nodiscard]] const_iterator begin () const noexcept { return m_lbox.cbegin(); }
183 [[nodiscard]] const_iterator cbegin () const noexcept { return m_lbox.cbegin(); }
184
186 [[nodiscard]] iterator end () noexcept { return m_lbox.end(); }
188 [[nodiscard]] const_iterator end () const noexcept { return m_lbox.cend(); }
190 [[nodiscard]] const_iterator cend () const noexcept { return m_lbox.cend(); }
196 [[nodiscard]] bool ok () const noexcept;
198 bool operator== (const BoxList& rhs) const;
200 bool operator!= (const BoxList& rhs) const;
202 [[nodiscard]] bool isEmpty () const noexcept { return m_lbox.empty(); }
204 [[nodiscard]] bool isNotEmpty () const noexcept { return !m_lbox.empty(); }
206 [[nodiscard]] bool isDisjoint () const;
208 [[nodiscard]] bool contains (const BoxList& bl) const;
210 BoxList& intersect (const Box& b);
212 BoxList& intersect (const BoxList& bl);
215
223 BoxList& complementIn (const Box& b, const BoxList& bl);
231 BoxList& complementIn (const Box& b, BoxList&& bl);
239 BoxList& complementIn (const Box& b, const BoxArray& ba);
247 BoxList& parallelComplementIn (const Box& b, const BoxList& bl);
255 BoxList& parallelComplementIn (const Box& b, BoxList&& bl);
263 BoxList& parallelComplementIn (const Box& b, const BoxArray& ba);
264
270 BoxList& refine (int ratio);
276 BoxList& refine (const IntVect& ratio);
282 BoxList& coarsen (int ratio);
288 BoxList& coarsen (const IntVect& ratio);
294 BoxList& accrete (int sz);
300 BoxList& accrete (const IntVect& sz);
307 BoxList& shift (int dir,
308 int nzones);
315 BoxList& shiftHalf (int dir,
316 int num_halfs);
322 BoxList& shiftHalf (const IntVect& iv);
332 int simplify (bool best = false);
334 int ordered_simplify ();
336 BoxList& maxSize (int chunk);
338 BoxList& maxSize (const IntVect& chunk);
340 [[nodiscard]] Box minimalBox () const;
342 [[nodiscard]] IndexType ixType () const noexcept { return btype; }
344 void set (IndexType ixtyp) noexcept { BL_ASSERT(m_lbox.empty()); btype = ixtyp; }
349 BoxList& surroundingNodes () noexcept;
354 BoxList& surroundingNodes (int dir) noexcept;
356 BoxList& enclosedCells () noexcept;
358 BoxList& enclosedCells (int dir) noexcept;
360 BoxList& convert (IndexType typ) noexcept;
361
363 [[nodiscard]] Vector<Box>& data () noexcept { return m_lbox; }
365 [[nodiscard]] const Vector<Box>& data () const noexcept { return m_lbox; }
366
368 void swap (BoxList& rhs) noexcept {
369 std::swap(m_lbox, rhs.m_lbox);
370 std::swap(btype, rhs.btype);
371 }
372
374 void Bcast ();
375
376private:
378 int simplify_doit (int depth);
379
381 Vector<Box> m_lbox;
383 IndexType btype;
384
385};
386
387}
388
389#endif /*BL_BOXLIST_H*/
Fixed-size array types for use on GPU and CPU.
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
Integer-lattice boxes and helpers for defining index-space regions.
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:676
A list of disjoint boxes built on top of BoxList.
Definition AMReX_BoxDomain.H:95
A list of Boxes sharing a common IndexType.
Definition AMReX_BoxList.H:109
bool ok() const noexcept
True if this BoxList is valid; i.e. all the Boxes are valid and they all have the same IndexType....
Definition AMReX_BoxList.cpp:235
bool contains(const BoxList &bl) const
True if all Boxes in bl are contained in this BoxList.
Definition AMReX_BoxList.cpp:252
const_iterator cend() const noexcept
Return a const iterator past the last Box.
Definition AMReX_BoxList.H:190
bool isDisjoint() const
True if the set of intersecting Boxes is empty.
Definition AMReX_BoxList.cpp:242
BoxList & convert(IndexType typ) noexcept
Applies Box::convert(IndexType) to each Box in the BoxList.
Definition AMReX_BoxList.cpp:865
BoxList & refine(int ratio)
Refine each Box in the BoxList by a uniform ratio.
Definition AMReX_BoxList.cpp:503
void clear()
Remove all Boxes from this BoxList.
Definition AMReX_BoxList.cpp:65
BoxList & shiftHalf(int dir, int num_halfs)
Apply Box::shiftHalf(dir, num_halfs) to every Box in the list.
Definition AMReX_BoxList.cpp:573
BoxList & coarsen(int ratio)
Coarsen each Box in the BoxList by a uniform ratio.
Definition AMReX_BoxList.cpp:523
const Box & front() const noexcept
Return a const reference to the first Box in the list.
Definition AMReX_BoxList.H:161
IndexType ixType() const noexcept
Returns the IndexType of Boxes in this BoxList.
Definition AMReX_BoxList.H:342
const_iterator cbegin() const noexcept
Return a const iterator to the first Box.
Definition AMReX_BoxList.H:183
BoxList()
Construct an empty BoxList with IndexType::TheCellType().
Definition AMReX_BoxList.cpp:146
const_iterator end() const noexcept
Return a const iterator past the last Box.
Definition AMReX_BoxList.H:188
BoxList & intersect(const Box &b)
Modify this BoxList to contain only its intersection with Box b.
Definition AMReX_BoxList.cpp:265
iterator end() noexcept
Return an iterator past the last Box.
Definition AMReX_BoxList.H:186
Vector< Box > & data() noexcept
Returns a reference to the Vector<Box>.
Definition AMReX_BoxList.H:363
const Vector< Box > & data() const noexcept
Returns a constant reference to the Vector<Box>.
Definition AMReX_BoxList.H:365
void catenate(BoxList &blist)
Catenate the BoxList to ourselves. Removes entries from blist.
Definition AMReX_BoxList.cpp:85
bool isEmpty() const noexcept
Is this BoxList empty?
Definition AMReX_BoxList.H:202
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:344
BoxList(const BoxList &rhs)=default
std::size_t capacity() const noexcept
Return the current allocated capacity.
Definition AMReX_BoxList.H:176
void Bcast()
Broadcast this BoxList from the I/O processor to all other processors.
Definition AMReX_BoxList.cpp:908
~BoxList()=default
BoxList(BoxList &&rhs)=default
bool isNotEmpty() const noexcept
Is this BoxList not empty?
Definition AMReX_BoxList.H:204
void reserve(std::size_t n)
Reserve storage for at least n Boxes.
Definition AMReX_BoxList.H:148
int simplify(bool best=false)
Merge adjacent Boxes in this BoxList. Return the number of Boxes merged. If "best" is specified we do...
Definition AMReX_BoxList.cpp:652
const_iterator begin() const noexcept
Return a const iterator to the first Box.
Definition AMReX_BoxList.H:181
BoxList & surroundingNodes() noexcept
Applies surroundingNodes(Box) to each Box in BoxArray. See the documentation of Box for details.
Definition AMReX_BoxList.cpp:825
BoxList & enclosedCells() noexcept
Applies Box::enclosedCells() to each Box in the BoxList.
Definition AMReX_BoxList.cpp:845
Box & front() noexcept
Return a reference to the first Box in the list.
Definition AMReX_BoxList.H:158
void swap(BoxList &rhs) noexcept
Swap contents with another BoxList.
Definition AMReX_BoxList.H:368
BoxList & accrete(int sz)
Grow each Box in the BoxList by sz cells in every direction.
Definition AMReX_BoxList.cpp:543
BoxList & parallelComplementIn(const Box &b, const BoxList &bl)
Parallel version of complementIn using BoxList.
Definition AMReX_BoxList.cpp:397
BoxList & maxSize(int chunk)
Forces each Box in the BoxList to have sides of length <= chunk.
Definition AMReX_BoxList.cpp:819
void push_back(const Box &bn)
Append a Box to this BoxList.
Definition AMReX_BoxList.H:151
int ordered_simplify()
Merge adjacent Boxes assuming the list is already sorted/ordered.
Definition AMReX_BoxList.cpp:668
iterator begin() noexcept
Return an iterator to the first Box.
Definition AMReX_BoxList.H:179
BoxList & removeEmpty()
Remove empty Boxes from this BoxList.
Definition AMReX_BoxList.cpp:93
Long size() const noexcept
The number of Boxes in this BoxList.
Definition AMReX_BoxList.H:173
Box minimalBox() const
Returns smallest Box that contains all Boxes in this BoxList.
Definition AMReX_BoxList.cpp:747
Vector< Box >::iterator iterator
Definition AMReX_BoxList.H:114
BoxList & complementIn(const Box &b, const BoxList &bl)
Set this BoxList to the complement of BoxList bl in Box b.
Definition AMReX_BoxList.cpp:305
Vector< Box >::const_iterator const_iterator
Definition AMReX_BoxList.H:115
BoxList & shift(int dir, int nzones)
Apply Box::shift(dir, nzones) to every Box in the list.
Definition AMReX_BoxList.cpp:563
BoxList & operator=(const BoxList &rhs)=default
void join(const BoxList &blist)
Join the BoxList to ourselves.
Definition AMReX_BoxList.cpp:71
__host__ __device__ IndexTypeND< dim > ixType() const noexcept
Return the indexing type.
Definition AMReX_Box.H:148
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Return a copy of b coarsened by the isotropic ratio ref_ratio.
Definition AMReX_Box.H:1469
__host__ __device__ BoxND< dim > refine(const BoxND< dim > &b, int ref_ratio) noexcept
Return a copy of b refined by the isotropic ratio ref_ratio.
Definition AMReX_Box.H:1510
Definition AMReX_Amr.cpp:50
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Stream helper; forwards to the friend declared inside AmrMesh.
Definition AMReX_AmrMesh.cpp:1306
void accrete(BoxDomain &dest, const BoxDomain &fin, int sz)
Grow each Box in BoxDomain fin by size sz.
Definition AMReX_BoxDomain.cpp:45
BoxArray intersect(const BoxArray &ba, const Box &b, int ng)
Make a BoxArray from the intersection of Box b and BoxArray(+ghostcells).
Definition AMReX_BoxArray.cpp:1717
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
BoxList boxDiff(const Box &b1in, const Box &b2)
Returns a BoxList defining the complement of b2 in b1in.
Definition AMReX_BoxList.cpp:597
BoxArray complementIn(const Box &b, const BoxArray &ba)
Make a BoxArray from the complement of ba within the Box b.
Definition AMReX_BoxArray.cpp:1710
Direction
Definition AMReX_Orientation.H:14
BoxList removeOverlap(const BoxList &bl)
Return BoxList which covers the same area but has no overlapping boxes.
Definition AMReX_BoxList.cpp:133