Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_BoxArray.H
Go to the documentation of this file.
1
2#ifndef BL_BOXARRAY_H
3#define BL_BOXARRAY_H
4#include <AMReX_Config.H>
5
6#include <AMReX_IndexType.H>
7#include <AMReX_BoxList.H>
8#include <AMReX_Array.H>
9#include <AMReX_Periodicity.H>
10#include <AMReX_Vector.H>
11
12#include <iosfwd>
13#include <cstddef>
14#include <cstdint>
15#include <map>
16#include <memory>
17#include <unordered_map>
18
19namespace amrex
20{
21 class BoxArray;
22
24 [[nodiscard]] BoxArray boxComplement (const Box& b1in, const Box& b2);
25
27 [[nodiscard]] BoxArray complementIn (const Box& b, const BoxArray& ba);
28
30 [[nodiscard]] BoxArray intersect (const BoxArray& ba, const Box& b, int ng = 0);
31
32 [[nodiscard]] BoxArray intersect (const BoxArray& ba, const Box& b, const IntVect& ng);
33
35 [[nodiscard]] BoxArray intersect (const BoxArray& lhs, const BoxArray& rhs);
36
38 [[nodiscard]] BoxList intersect (const BoxArray& ba, const BoxList& bl);
39
40 [[nodiscard]] BoxArray convert (const BoxArray& ba, IndexType typ);
41 [[nodiscard]] BoxArray convert (const BoxArray& ba, const IntVect& typ);
42
43 [[nodiscard]] BoxArray coarsen (const BoxArray& ba, int ratio);
44 [[nodiscard]] BoxArray coarsen (const BoxArray& ba, const IntVect& ratio);
45
46 [[nodiscard]] BoxArray refine (const BoxArray& ba, int ratio);
47 [[nodiscard]] BoxArray refine (const BoxArray& ba, const IntVect& ratio);
48
50 [[nodiscard]] BoxList GetBndryCells (const BoxArray& ba, int ngrow);
51
53 void readBoxArray (BoxArray& ba, std::istream& s, bool b = false);
54
56 [[nodiscard]] bool match (const BoxArray& x, const BoxArray& y);
57
73 [[nodiscard]] BoxArray decompose (Box const& domain, int nboxes,
74 Array<bool,AMREX_SPACEDIM> const& decomp
75 = {AMREX_D_DECL(true,true,true)},
76 bool no_overlap = false);
77
79struct BARef
80{
81 BARef ();
82 explicit BARef (size_t size);
83 explicit BARef (const Box& b);
84 explicit BARef (const BoxList& bl);
85 explicit BARef (BoxList&& bl) noexcept;
86 explicit BARef (std::istream& is);
87 BARef (const BARef& rhs);
88 BARef (BARef&& rhs) = delete;
89 BARef& operator= (const BARef& rhs) = delete;
90 BARef& operator= (BARef&& rhs) = delete;
91
92 ~BARef ();
93
94 void define (const Box& bx);
95 void define (const BoxList& bl);
96 void define (BoxList&& bl) noexcept;
97 void define (std::istream& is, int& ndims);
99 void resize (Long n);
100#ifdef AMREX_MEM_PROFILING
101 void updateMemoryUsage_box (int s);
102 void updateMemoryUsage_hash (int s);
103#endif
104
105 [[nodiscard]] bool HasHashMap () const {
106 bool r;
107#ifdef AMREX_USE_OMP
108#pragma omp atomic read
109#endif
110 r = has_hashmap;
111 return r;
112 }
113
114 //
116 Vector<Box> m_abox;
117 //
119 mutable Box bbox;
120
121 mutable IntVect crsn;
122
123 using HashType = std::unordered_map< IntVect, std::vector<int>, IntVect::shift_hasher > ;
124 //using HashType = std::map< IntVect,std::vector<int> >;
125
126 mutable HashType hash;
127
128 mutable bool has_hashmap = false;
129
130 static int numboxarrays;
131 static int numboxarrays_hwm;
132 static Long total_box_bytes;
133 static Long total_box_bytes_hwm;
134 static Long total_hash_bytes;
135 static Long total_hash_bytes_hwm;
136
137 static void Initialize ();
138 static void Finalize ();
139 static bool initialized;
140};
142
144struct BATnull
145{
146 [[nodiscard]] Box operator() (const Box& bx) const noexcept { return bx; }
147 [[nodiscard]] static constexpr Box coarsen (Box const& a_box) { return a_box; }
148 [[nodiscard]] static constexpr IntVect doiLo () { return IntVect::TheZeroVector(); }
149 [[nodiscard]] static constexpr IntVect doiHi () { return IntVect::TheZeroVector(); }
150 [[nodiscard]] static constexpr IndexType index_type () { return IndexType(); }
151 [[nodiscard]] static constexpr IntVect coarsen_ratio () { return IntVect::TheUnitVector(); }
152};
154
156struct BATindexType
157{
158 explicit BATindexType (IndexType a_typ) : m_typ(a_typ) {}
159 [[nodiscard]] Box operator() (const Box& bx) const noexcept { return amrex::convert(bx,m_typ); }
160 [[nodiscard]] static Box coarsen (Box const& a_box) noexcept { return a_box; }
161 [[nodiscard]] static constexpr IntVect doiLo () { return IntVect::TheZeroVector(); }
162 [[nodiscard]] IntVect doiHi () const noexcept { return m_typ.ixType(); }
163 [[nodiscard]] IndexType index_type () const noexcept { return m_typ; }
164 [[nodiscard]] static constexpr IntVect coarsen_ratio () { return IntVect::TheUnitVector(); }
165 IndexType m_typ;
166};
168
170struct BATcoarsenRatio
171{
172 explicit BATcoarsenRatio (IntVect const& a_crse_ratio) : m_crse_ratio(a_crse_ratio) {}
173 [[nodiscard]] Box operator() (const Box& bx) const noexcept { return amrex::coarsen(bx,m_crse_ratio); }
174 [[nodiscard]] Box coarsen (Box const& a_box) const noexcept { return amrex::coarsen(a_box,m_crse_ratio); }
175 [[nodiscard]] static constexpr IntVect doiLo () { return IntVect::TheZeroVector(); }
176 [[nodiscard]] static constexpr IntVect doiHi () { return IntVect::TheZeroVector(); }
177 [[nodiscard]] static constexpr IndexType index_type () { return IndexType(); }
178 [[nodiscard]] IntVect coarsen_ratio () const noexcept { return m_crse_ratio; }
179 IntVect m_crse_ratio;
180};
182
184struct BATindexType_coarsenRatio
185{
186 BATindexType_coarsenRatio (IndexType a_typ, IntVect const& a_crse_ratio)
187 : m_typ(a_typ), m_crse_ratio(a_crse_ratio) {}
188
189 [[nodiscard]] Box operator() (const Box& bx) const noexcept {
190 return amrex::convert(amrex::coarsen(bx,m_crse_ratio),m_typ);
191 }
192
193 [[nodiscard]] Box coarsen (Box const& a_box) const noexcept { return amrex::coarsen(a_box,m_crse_ratio); }
194
195 [[nodiscard]] static constexpr IntVect doiLo () { return IntVect::TheZeroVector(); }
196 [[nodiscard]] IntVect doiHi () const noexcept { return m_typ.ixType(); }
197
198 [[nodiscard]] IndexType index_type () const noexcept { return m_typ; }
199 [[nodiscard]] IntVect coarsen_ratio () const noexcept { return m_crse_ratio; }
200
201 IndexType m_typ;
202 IntVect m_crse_ratio;
203};
205
207struct BATbndryReg
208{
209 BATbndryReg (Orientation a_face, IndexType a_typ,
210 int a_in_rad, int a_out_rad, int a_extent_rad)
211 : m_face(a_face), m_typ(a_typ), m_crse_ratio(1)
212 {
213 m_loshft = IntVect(-a_extent_rad);
214 m_hishft = IntVect( a_extent_rad);
215 IntVect nodal = a_typ.ixType();
216 m_hishft += nodal;
217 const int d = a_face.coordDir();
218 if (nodal[d]) {
219 // InterpFaceRegister & SyncRegister in IAMR
220 if (m_face.isLow()) {
221 m_loshft[d] = 0;
222 m_hishft[d] = 0;
223 } else {
224 m_loshft[d] = 1;
225 m_hishft[d] = 1;
226 }
227 m_doilo = IntVect(0);
228 m_doihi = nodal;
229 } else {
230 // BndryRegister
231 if (m_face.isLow()) {
232 m_loshft[d] = nodal[d] - a_out_rad;
233 m_hishft[d] = nodal[d] + a_in_rad - 1;
234 } else {
235 m_loshft[d] = 1 - a_in_rad;
236 m_hishft[d] = a_out_rad;
237 }
238 m_doilo = IntVect(a_extent_rad);
239 m_doihi = IntVect(a_extent_rad);
240 m_doihi += nodal;
241 if (m_face.isLow()) { // domain of influence in index space
242 m_doilo[d] = a_out_rad;
243 m_doihi[d] = 0;
244 } else {
245 m_doilo[d] = 0;
246 m_doihi[d] = a_out_rad;
247 }
248 }
249 }
250
251 [[nodiscard]] Box operator() (const Box& a_bx) const noexcept {
252 IntVect lo = amrex::coarsen(a_bx.smallEnd(), m_crse_ratio);
253 IntVect hi = amrex::coarsen(a_bx.bigEnd(), m_crse_ratio);
254 const int d = m_face.coordDir();
255 if (m_face.isLow()) {
256 hi[d] = lo[d];
257 } else {
258 lo[d] = hi[d];
259 }
260 lo += m_loshft;
261 hi += m_hishft;
262 return Box(lo,hi,m_typ);
263 }
264
265 [[nodiscard]] Box coarsen (Box const& a_box) const noexcept { return amrex::coarsen(a_box,m_crse_ratio); }
266
267 [[nodiscard]] IntVect doiLo () const noexcept { return m_doilo; }
268 [[nodiscard]] IntVect doiHi () const noexcept { return m_doihi; }
269
270 [[nodiscard]] IndexType index_type () const noexcept { return m_typ; }
271 [[nodiscard]] IntVect coarsen_ratio () const noexcept { return m_crse_ratio; }
272
273 friend bool operator== (BATbndryReg const& a, BATbndryReg const& b) noexcept {
274 return a.m_face == b.m_face && a.m_typ == b.m_typ && a.m_crse_ratio == b.m_crse_ratio
275 && a.m_loshft == b.m_loshft && a.m_hishft == b.m_hishft
276 && a.m_doilo == b.m_doilo && a.m_doihi == b.m_doihi;
277 }
278
279 Orientation m_face;
280 IndexType m_typ;
281 IntVect m_crse_ratio;
282 IntVect m_loshft;
283 IntVect m_hishft;
284 IntVect m_doilo;
285 IntVect m_doihi;
286};
288
290struct BATransformer
291{
292 enum struct BATType : std::int8_t { null, indexType, coarsenRatio, indexType_coarsenRatio, bndryReg};
293
294 union BATOp {
295 BATOp () noexcept
296 : m_null() {}
297 BATOp (IndexType t) noexcept
298 : m_indexType(t) {}
299 BATOp (IntVect const& r) noexcept
300 : m_coarsenRatio(r) {}
301 BATOp (IndexType t, IntVect const& r) noexcept
302 : m_indexType_coarsenRatio(t,r) {}
303 BATOp (Orientation f, IndexType t, int in_rad, int out_rad, int extent_rad) noexcept
304 : m_bndryReg(f,t,in_rad,out_rad,extent_rad) {}
305 BATnull m_null;
306 BATindexType m_indexType;
307 BATcoarsenRatio m_coarsenRatio;
308 BATindexType_coarsenRatio m_indexType_coarsenRatio;
309 BATbndryReg m_bndryReg;
310 };
311
312 BATransformer () = default;
313
314 BATransformer (IndexType t)
315 : m_bat_type(t.cellCentered() ? BATType::null : BATType::indexType),
316 m_op (t.cellCentered() ? BATOp() : BATOp(t)) {}
317
318 BATransformer (Orientation f, IndexType t, int in_rad, int out_rad, int extent_rad)
319 : m_bat_type(BATType::bndryReg),
320 m_op(f,t,in_rad,out_rad,extent_rad) {}
321
322 [[nodiscard]] Box operator() (Box const& ab) const noexcept {
323 switch (m_bat_type)
324 {
325 case BATType::null:
326 return m_op.m_null(ab);
327 case BATType::indexType:
328 return m_op.m_indexType(ab);
329 case BATType::coarsenRatio:
330 return m_op.m_coarsenRatio(ab);
331 case BATType::indexType_coarsenRatio:
332 return m_op.m_indexType_coarsenRatio(ab);
333 default:
334 return m_op.m_bndryReg(ab);
335 }
336 }
337
338 [[nodiscard]] Box coarsen (Box const& a_box) const noexcept {
339 switch (m_bat_type)
340 {
341 case BATType::null:
342 return amrex::BATnull::coarsen(a_box);
343 case BATType::indexType:
344 return amrex::BATindexType::coarsen(a_box);
345 case BATType::coarsenRatio:
346 return m_op.m_coarsenRatio.coarsen(a_box);
347 case BATType::indexType_coarsenRatio:
348 return m_op.m_indexType_coarsenRatio.coarsen(a_box);
349 default:
350 return m_op.m_bndryReg.coarsen(a_box);
351 }
352 }
353
354 [[nodiscard]] IntVect doiLo () const noexcept {
355 switch (m_bat_type)
356 {
357 case BATType::null:
358 return amrex::BATnull::doiLo();
359 case BATType::indexType:
360 return amrex::BATindexType::doiLo();
361 case BATType::coarsenRatio:
362 return amrex::BATcoarsenRatio::doiLo();
363 case BATType::indexType_coarsenRatio:
364 return amrex::BATindexType_coarsenRatio::doiLo();
365 default:
366 return m_op.m_bndryReg.doiLo();
367 }
368 }
369
370 [[nodiscard]] IntVect doiHi () const noexcept {
371 switch (m_bat_type)
372 {
373 case BATType::null:
374 return amrex::BATnull::doiHi();
375 case BATType::indexType:
376 return m_op.m_indexType.doiHi();
377 case BATType::coarsenRatio:
378 return amrex::BATcoarsenRatio::doiHi();
379 case BATType::indexType_coarsenRatio:
380 return m_op.m_indexType_coarsenRatio.doiHi();
381 default:
382 return m_op.m_bndryReg.doiHi();
383 }
384 }
385
386 [[nodiscard]] IndexType index_type () const noexcept {
387 switch (m_bat_type)
388 {
389 case BATType::null:
390 return amrex::BATnull::index_type();
391 case BATType::indexType:
392 return m_op.m_indexType.index_type();
393 case BATType::coarsenRatio:
394 return amrex::BATcoarsenRatio::index_type();
395 case BATType::indexType_coarsenRatio:
396 return m_op.m_indexType_coarsenRatio.index_type();
397 default:
398 return m_op.m_bndryReg.index_type();
399 }
400 }
401
402 [[nodiscard]] IntVect coarsen_ratio () const noexcept {
403 switch (m_bat_type)
404 {
405 case BATType::null:
406 return amrex::BATnull::coarsen_ratio();
407 case BATType::indexType:
408 return amrex::BATindexType::coarsen_ratio();
409 case BATType::coarsenRatio:
410 return m_op.m_coarsenRatio.coarsen_ratio();
411 case BATType::indexType_coarsenRatio:
412 return m_op.m_indexType_coarsenRatio.coarsen_ratio();
413 default:
414 return m_op.m_bndryReg.coarsen_ratio();
415 }
416 }
417
418 [[nodiscard]] bool is_null () const noexcept {
419 return m_bat_type == BATType::null;
420 }
421
422 [[nodiscard]] bool is_simple () const noexcept {
423 return m_bat_type != BATType::bndryReg;
424 }
425
426 void set_coarsen_ratio (IntVect const& a_ratio) noexcept {
427 switch (m_bat_type)
428 {
429 case BATType::null:
430 {
431 if (a_ratio == IntVect::TheUnitVector()) {
432 return;
433 } else {
434 m_bat_type = BATType::coarsenRatio;
435 m_op.m_coarsenRatio.m_crse_ratio = a_ratio;
436 return;
437 }
438 }
439 case BATType::indexType:
440 {
441 if (a_ratio == IntVect::TheUnitVector()) {
442 return;
443 } else {
444 m_bat_type = BATType::indexType_coarsenRatio;
445 auto t = m_op.m_indexType.m_typ;
446 m_op.m_indexType_coarsenRatio.m_typ = t;
447 m_op.m_indexType_coarsenRatio.m_crse_ratio = a_ratio;
448 return;
449 }
450 }
451 case BATType::coarsenRatio:
452 {
453 if (a_ratio == IntVect::TheUnitVector()) {
454 m_bat_type = BATType::null;
455 return;
456 } else {
457 m_op.m_coarsenRatio.m_crse_ratio = a_ratio;
458 return;
459 }
460 }
461 case BATType::indexType_coarsenRatio:
462 {
463 if (a_ratio == IntVect::TheUnitVector()) {
464 m_bat_type = BATType::indexType;
465 auto t = m_op.m_indexType_coarsenRatio.m_typ;
466 m_op.m_indexType.m_typ = t;
467 return;
468 } else {
469 m_op.m_indexType_coarsenRatio.m_crse_ratio = a_ratio;
470 return;
471 }
472 }
473 default:
474 {
475 m_op.m_bndryReg.m_crse_ratio = a_ratio;
476 return;
477 }
478 }
479 }
480
481 void set_index_type (IndexType typ) noexcept {
482 switch (m_bat_type)
483 {
484 case BATType::null:
485 {
486 if (typ.cellCentered()) {
487 return;
488 } else {
489 m_bat_type = BATType::indexType;
490 m_op.m_indexType.m_typ = typ;
491 return;
492 }
493 }
494 case BATType::indexType:
495 {
496 if (typ.cellCentered()) {
497 m_bat_type = BATType::null;
498 return;
499 } else {
500 m_op.m_indexType.m_typ = typ;
501 return;
502 }
503 }
504 case BATType::coarsenRatio:
505 {
506 if (typ.cellCentered()) {
507 return;
508 } else {
509 m_bat_type = BATType::indexType_coarsenRatio;
510 auto r = m_op.m_coarsenRatio.m_crse_ratio;
511 m_op.m_indexType_coarsenRatio.m_typ = typ;
512 m_op.m_indexType_coarsenRatio.m_crse_ratio = r;
513 return;
514 }
515 }
516 case BATType::indexType_coarsenRatio:
517 {
518 if (typ.cellCentered()) {
519 m_bat_type = BATType::coarsenRatio;
520 auto r = m_op.m_indexType_coarsenRatio.m_crse_ratio;
521 m_op.m_coarsenRatio.m_crse_ratio = r;
522 return;
523 } else {
524 m_op.m_indexType_coarsenRatio.m_typ = typ;
525 return;
526 }
527 }
528 default:
529 {
530 m_op.m_bndryReg.m_typ = typ;
531 return;
532 }
533 }
534 }
535
536 friend bool operator== (BATransformer const& a, BATransformer const& b) noexcept {
537 if (a.m_bat_type != BATType::bndryReg && b.m_bat_type != BATType::bndryReg) {
538 return a.index_type() == b.index_type()
539 && a.coarsen_ratio() == b.coarsen_ratio();
540 } else if (a.m_bat_type == BATType::bndryReg && b.m_bat_type == BATType::bndryReg) {
541 return a.m_op.m_bndryReg == b.m_op.m_bndryReg;
542 } else {
543 return false;
544 }
545 }
546
547 BATType m_bat_type{BATType::null};
548 BATOp m_op;
549};
551
552// for backward compatibility
553using BndryBATransformer = BATransformer;
554
555class MFIter;
556class AmrMesh;
557class FabArrayBase;
558
568{
569public:
570
571 BoxArray () noexcept;
572 BoxArray (const BoxArray& rhs) = default;
573 BoxArray (BoxArray&& rhs) noexcept = default;
574 BoxArray& operator= (BoxArray const& rhs) = default;
575 BoxArray& operator= (BoxArray&& rhs) noexcept = default;
576 ~BoxArray() noexcept = default;
577
579 explicit BoxArray (const Box& bx);
580
582 explicit BoxArray (size_t n);
583
585 BoxArray (const Box* bxvec,
586 int nbox);
587
589 explicit BoxArray (const BoxList& bl);
590 explicit BoxArray (BoxList&& bl) noexcept;
591
592 BoxArray (const BoxArray& rhs, const BATransformer& trans);
593
594 BoxArray (BoxList&& bl, IntVect const& max_grid_size);
595
600 void define (const Box& bx);
605 void define (const BoxList& bl);
606 void define (BoxList&& bl) noexcept;
607
609 void clear ();
610
612 void resize (Long len);
613
615 [[nodiscard]] Long size () const noexcept { return m_ref->m_abox.size(); }
616
618 [[nodiscard]] Long capacity () const noexcept { return static_cast<Long>(m_ref->m_abox.capacity()); }
619
621 [[nodiscard]] bool empty () const noexcept { return m_ref->m_abox.empty(); }
622
624 [[nodiscard]] Long numPts() const noexcept;
625
627 [[nodiscard]] double d_numPts () const noexcept;
634 int readFrom (std::istream& is);
635
637 std::ostream& writeOn (std::ostream&) const;
638
640 [[nodiscard]] bool operator== (const BoxArray& rhs) const noexcept;
641
643 [[nodiscard]] bool operator!= (const BoxArray& rhs) const noexcept;
644
645 [[nodiscard]] bool operator== (const Vector<Box>& bv) const noexcept;
646 [[nodiscard]] bool operator!= (const Vector<Box>& bv) const noexcept;
647
649 [[nodiscard]] bool CellEqual (const BoxArray& rhs) const noexcept;
650
652 BoxArray& maxSize (int block_size);
653
654 BoxArray& maxSize (const IntVect& block_size);
655
659 BoxArray& minmaxSize (const IntVect& min_size, const IntVect& max_size);
660
662 BoxArray& refine (int refinement_ratio);
663
665 BoxArray& refine (const IntVect& iv);
666
668 BoxArray& coarsen (int refinement_ratio);
669
671 [[nodiscard]] bool coarsenable (int refinement_ratio, int min_width=1) const;
672 [[nodiscard]] bool coarsenable (const IntVect& refinement_ratio, int min_width=1) const;
673 [[nodiscard]] bool coarsenable (const IntVect& refinement_ratio, const IntVect& min_width) const;
674
676 BoxArray& coarsen (const IntVect& iv);
677
679 BoxArray& growcoarsen (int n, const IntVect& iv);
680 BoxArray& growcoarsen (IntVect const& ngrow, const IntVect& iv);
681
683 BoxArray& grow (int n);
684
686 BoxArray& grow (const IntVect& iv);
691 BoxArray& grow (int idir, int n_cell);
696 BoxArray& growLo (int idir, int n_cell);
701 BoxArray& growHi (int idir, int n_cell);
711 BoxArray& surroundingNodes (int dir);
712
715
717 BoxArray& enclosedCells (int dir);
718
721
722 BoxArray& convert (const IntVect& iv);
723
725 BoxArray& convert (Box (*fp)(const Box&));
726
728 BoxArray& shift (int dir, int nzones);
729
731 BoxArray& shift (const IntVect &iv);
732
734 void set (int i, const Box& ibox);
735
737 [[nodiscard]] Box operator[] (int index) const noexcept {
738 return m_bat(m_ref->m_abox[index]);
739 }
740
742 [[nodiscard]] Box operator[] (const MFIter& mfi) const noexcept;
743
745 [[nodiscard]] Box get (int index) const noexcept { return operator[](index); }
746
748 [[nodiscard]] Box getCellCenteredBox (int index) const noexcept {
749 return m_bat.coarsen(m_ref->m_abox[index]);
750 }
751
756 [[nodiscard]] bool ok () const;
757
759 [[nodiscard]] bool isDisjoint () const;
760
762 [[nodiscard]] BoxList boxList () const;
763
765 [[nodiscard]] bool contains (const IntVect& v) const;
766
771 [[nodiscard]]
772 bool contains (const Box& b, bool assume_disjoint_ba = false,
773 const IntVect& ng = IntVect(0)) const;
774
778 [[nodiscard]]
779 bool contains (const BoxArray& ba, bool assume_disjoint_ba = false,
780 const IntVect& ng = IntVect(0)) const;
781
789 [[nodiscard]]
790 bool contains (const BoxArray& ba, Periodicity const& period) const;
791
793 [[nodiscard]] Box minimalBox () const;
794 [[nodiscard]] Box minimalBox (Long& npts_avg_box) const;
795
800 [[nodiscard]]
801 bool intersects (const Box& b, int ng = 0) const;
802
803 [[nodiscard]]
804 bool intersects (const Box& b, const IntVect& ng) const;
805
807 [[nodiscard]]
808 std::vector< std::pair<int,Box> > intersections (const Box& bx) const;
809
811 [[nodiscard]]
812 std::vector< std::pair<int,Box> > intersections (const Box& bx, bool first_only, int ng) const;
813
814 [[nodiscard]]
815 std::vector< std::pair<int,Box> > intersections (const Box& bx, bool first_only, const IntVect& ng) const;
816
818 void intersections (const Box& bx, std::vector< std::pair<int,Box> >& isects) const;
819
821 void intersections (const Box& bx, std::vector< std::pair<int,Box> >& isects,
822 bool first_only, int ng) const;
823
824 void intersections (const Box& bx, std::vector< std::pair<int,Box> >& isects,
825 bool first_only, const IntVect& ng) const;
826
828 [[nodiscard]] BoxList complementIn (const Box& b) const;
829 void complementIn (BoxList& bl, const Box& b) const;
830
832 [[nodiscard]] BoxList complementIn (const Box& b, const Periodicity& period) const;
833
835 void clear_hash_bin () const;
836
838 void removeOverlap (bool simplify=true);
839
841 [[nodiscard]] static bool SameRefs (const BoxArray& lhs, const BoxArray& rhs) { return lhs.m_ref == rhs.m_ref; }
842
843 struct RefID {
844 RefID () noexcept = default;
845 explicit RefID (BARef* data_) noexcept : data(data_) {}
846 bool operator< (const RefID& rhs) const noexcept { return std::less<>()(data,rhs.data); }
847 bool operator== (const RefID& rhs) const noexcept { return data == rhs.data; }
848 bool operator!= (const RefID& rhs) const noexcept { return data != rhs.data; }
849 friend std::ostream& operator<< (std::ostream& os, const RefID& id);
850 private:
851 BARef* data{nullptr};
852 };
853
855 [[nodiscard]] RefID getRefID () const noexcept { return RefID { m_ref.get() }; }
856
858 [[nodiscard]] IndexType ixType () const noexcept { return m_bat.index_type(); }
859
861 [[nodiscard]] IntVect crseRatio () const noexcept { return m_bat.coarsen_ratio(); }
862
863 static void Initialize ();
864 static void Finalize ();
865 static bool initialized;
866
868 void uniqify ();
869
870 [[nodiscard]] BoxList const& simplified_list () const; // For regular AMR grids only!!!
871 [[nodiscard]] BoxArray simplified () const; // For regular AMR grids only!!!
872
873 [[nodiscard]] BATransformer const& transformer () const;
874
875 [[nodiscard]] std::weak_ptr<BARef> getWeakRef () const;
876 [[nodiscard]] std::shared_ptr<BARef> const& getSharedRef () const;
877 std::shared_ptr<BARef>& getSharedRef ();
878
879 friend class AmrMesh;
880 friend class FabArrayBase;
881
882private:
884 void type_update ();
885
886 [[nodiscard]] BARef::HashType& getHashMap () const;
887
888 [[nodiscard]] IntVect getDoiLo () const noexcept;
889 [[nodiscard]] IntVect getDoiHi () const noexcept;
890
891 BATransformer m_bat;
893 std::shared_ptr<BARef> m_ref;
894 mutable std::shared_ptr<BoxList> m_simplified_list;
895};
896
898std::ostream& operator<< (std::ostream& os, const BoxArray& ba);
899
900std::ostream& operator<< (std::ostream& os, const BoxArray::RefID& id);
901
902}
903
904#endif /*BL_BOXARRAY_H*/
int idir
Definition AMReX_HypreMLABecLap.cpp:1093
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Definition AMReX_AmrMesh.H:64
A collection of Boxes stored in an Array.
Definition AMReX_BoxArray.H:568
IndexType ixType() const noexcept
Return index type of this BoxArray.
Definition AMReX_BoxArray.H:858
Box operator[](int index) const noexcept
Return element index of this BoxArray.
Definition AMReX_BoxArray.H:737
Long capacity() const noexcept
Return the number of boxes that can be held in the current allocated storage.
Definition AMReX_BoxArray.H:618
RefID getRefID() const noexcept
Return a unique ID of the reference.
Definition AMReX_BoxArray.H:855
bool intersects(const Box &b, int ng=0) const
True if the Box intersects with this BoxArray(+ghostcells). The Box must have the same IndexType as t...
Definition AMReX_BoxArray.cpp:1169
BoxArray & grow(int n)
Grow each Box in the BoxArray by the specified amount.
Definition AMReX_BoxArray.cpp:706
static void Finalize()
Definition AMReX_BoxArray.cpp:282
BoxArray() noexcept
Definition AMReX_BoxArray.cpp:287
std::vector< std::pair< int, Box > > intersections(const Box &bx) const
Return intersections of Box and BoxArray.
Definition AMReX_BoxArray.cpp:1186
std::ostream & writeOn(std::ostream &) const
Output this BoxArray to a checkpoint file.
Definition AMReX_BoxArray.cpp:482
bool contains(const IntVect &v) const
True if the IntVect is within any of the Boxes in this BoxArray.
Definition AMReX_BoxArray.cpp:977
static void Initialize()
Definition AMReX_BoxArray.cpp:271
BoxList const & simplified_list() const
Definition AMReX_BoxArray.cpp:1640
BoxList boxList() const
Create a BoxList from this BoxArray.
Definition AMReX_BoxArray.cpp:949
BoxArray simplified() const
Definition AMReX_BoxArray.cpp:1651
IntVect crseRatio() const noexcept
Return crse ratio of this BoxArray.
Definition AMReX_BoxArray.H:861
int readFrom(std::istream &is)
Initialize the BoxArray from the supplied istream. It is an error if the BoxArray has already been in...
Definition AMReX_BoxArray.cpp:468
void define(const Box &bx)
Initialize the BoxArray from a single box. It is an error if the BoxArray has already been initialize...
Definition AMReX_BoxArray.cpp:352
Long numPts() const noexcept
Returns the total number of cells contained in all boxes in the BoxArray.
Definition AMReX_BoxArray.cpp:394
void clear_hash_bin() const
Clear out the internal hash table used by intersections.
Definition AMReX_BoxArray.cpp:1440
Box minimalBox() const
Return smallest Box that contains all Boxes in this BoxArray.
Definition AMReX_BoxArray.cpp:1067
BoxArray & minmaxSize(const IntVect &min_size, const IntVect &max_size)
Definition AMReX_BoxArray.cpp:577
BoxArray & refine(int refinement_ratio)
Refine each Box in the BoxArray to the specified ratio.
Definition AMReX_BoxArray.cpp:593
std::weak_ptr< BARef > getWeakRef() const
Definition AMReX_BoxArray.cpp:1663
bool coarsenable(int refinement_ratio, int min_width=1) const
Coarsen each Box in the BoxArray to the specified ratio.
Definition AMReX_BoxArray.cpp:615
BoxArray & growLo(int idir, int n_cell)
Grow each Box in the BoxArray on the low end by n_cell cells in the idir direction.
Definition AMReX_BoxArray.cpp:752
void resize(Long len)
Resize the BoxArray. See Vector<T>::resize() for the gory details.
Definition AMReX_BoxArray.cpp:387
BoxArray & enclosedCells()
Apply Box::enclosedCells() to each Box in the BoxArray.
Definition AMReX_BoxArray.cpp:799
std::shared_ptr< BARef > const & getSharedRef() const
Definition AMReX_BoxArray.cpp:1669
Box getCellCenteredBox(int index) const noexcept
Return cell-centered box at element index of this BoxArray.
Definition AMReX_BoxArray.H:748
double d_numPts() const noexcept
Returns the total number of cells (in double type) contained in all boxes in the BoxArray.
Definition AMReX_BoxArray.cpp:431
BATransformer const & transformer() const
Definition AMReX_BoxArray.cpp:1657
static bool initialized
Definition AMReX_BoxArray.H:865
static bool SameRefs(const BoxArray &lhs, const BoxArray &rhs)
whether two BoxArrays share the same data
Definition AMReX_BoxArray.H:841
BoxArray & growHi(int idir, int n_cell)
Grow each Box in the BoxArray on the high end by n_cell cells in the idir direction.
Definition AMReX_BoxArray.cpp:768
BoxList complementIn(const Box &b) const
Return box - boxarray.
Definition AMReX_BoxArray.cpp:1314
void removeOverlap(bool simplify=true)
Change the BoxArray to one with no overlap and then simplify it (see the simplify function in BoxList...
Definition AMReX_BoxArray.cpp:1456
BoxArray & coarsen(int refinement_ratio)
Coarsen each Box in the BoxArray to the specified ratio.
Definition AMReX_BoxArray.cpp:672
BoxArray & shift(int dir, int nzones)
Apply Box::shift(int,int) to each Box in the BoxArray.
Definition AMReX_BoxArray.cpp:847
BoxArray & surroundingNodes()
Apply surroundingNodes(Box) to each Box in BoxArray. See the documentation of Box for details.
Definition AMReX_BoxArray.cpp:784
BoxArray(BoxArray &&rhs) noexcept=default
Long size() const noexcept
Return the number of boxes in the BoxArray.
Definition AMReX_BoxArray.H:615
Box get(int index) const noexcept
Return element index of this BoxArray.
Definition AMReX_BoxArray.H:745
~BoxArray() noexcept=default
bool CellEqual(const BoxArray &rhs) const noexcept
Are the BoxArrays equal after conversion to cell-centered.
Definition AMReX_BoxArray.cpp:546
void set(int i, const Box &ibox)
Set element i in this BoxArray to Box ibox.
Definition AMReX_BoxArray.cpp:878
BoxArray & growcoarsen(int n, const IntVect &iv)
Grow and then coarsen each Box in the BoxArray.
Definition AMReX_BoxArray.cpp:685
BoxArray & convert(IndexType typ)
Apply Box::convert(IndexType) to each Box in the BoxArray.
Definition AMReX_BoxArray.cpp:813
bool ok() const
Return true if Box is valid and they all have the same IndexType. Is true by default if the BoxArray ...
Definition AMReX_BoxArray.cpp:894
BoxArray & operator=(BoxArray const &rhs)=default
void uniqify()
Make ourselves unique.
Definition AMReX_BoxArray.cpp:1617
BoxArray(const BoxArray &rhs)=default
bool empty() const noexcept
Return whether the BoxArray is empty.
Definition AMReX_BoxArray.H:621
bool isDisjoint() const
Return true if set of intersecting Boxes in BoxArray is null.
Definition AMReX_BoxArray.cpp:920
BoxArray & maxSize(int block_size)
Forces each Box in BoxArray to have sides <= block_size.
Definition AMReX_BoxArray.cpp:553
void clear()
Remove all Boxes from the BoxArray.
Definition AMReX_BoxArray.cpp:379
A class for managing a List of Boxes that share a common IndexType. This class implements operations ...
Definition AMReX_BoxList.H:52
Base class for FabArray.
Definition AMReX_FabArrayBase.H:42
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:85
This provides length of period for periodic domains. 0 means it is not periodic in that direction....
Definition AMReX_Periodicity.H:17
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Coarsen BoxND by given (positive) coarsening ratio.
Definition AMReX_Box.H:1409
__host__ __device__ BoxND< dim > refine(const BoxND< dim > &b, int ref_ratio) noexcept
Definition AMReX_Box.H:1459
Definition AMReX_Amr.cpp:49
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a BoxND with different type.
Definition AMReX_Box.H:1558
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:1721
AMReX * Initialize(MPI_Comm mpi_comm, std::ostream &a_osout=std::cout, std::ostream &a_oserr=std::cerr, ErrorHandler a_errhandler=nullptr, int a_device_id=-1)
Definition AMReX.cpp:332
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:30
BoxList GetBndryCells(const BoxArray &ba, int ngrow)
Find the ghost cells of a given BoxArray.
Definition AMReX_BoxArray.cpp:1846
IndexTypeND< 3 > IndexType
IndexType is an alias for amrex::IndexTypeND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:36
void Finalize(AMReX *pamrex)
Definition AMReX.cpp:792
BoxArray decompose(Box const &domain, int nboxes, Array< bool, 3 > const &decomp, bool no_overlap)
Decompose domain box into BoxArray.
Definition AMReX_BoxArray.cpp:1947
bool match(const BoxArray &x, const BoxArray &y)
Note that two BoxArrays that match are not necessarily equal.
Definition AMReX_BoxArray.cpp:1934
BoxArray complementIn(const Box &b, const BoxArray &ba)
Make a BoxArray from the complement of BoxArray ba in Box b.
Definition AMReX_BoxArray.cpp:1714
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:33
void readBoxArray(BoxArray &ba, std::istream &is, bool bReadSpecial)
Read a BoxArray from a stream. If b is true, read in a special way.
Definition AMReX_BoxArray.cpp:1904
BATransformer BndryBATransformer
Definition AMReX_BoxArray.H:553
BoxArray boxComplement(const Box &b1in, const Box &b2)
Make a BoxArray from the the complement of b2 in b1in.
Definition AMReX_BoxArray.cpp:1707
Definition AMReX_BoxArray.H:843
friend std::ostream & operator<<(std::ostream &os, const RefID &id)
Definition AMReX_BoxArray.cpp:2130
RefID() noexcept=default
bool operator<(const RefID &rhs) const noexcept
Definition AMReX_BoxArray.H:846
bool operator!=(const RefID &rhs) const noexcept
Definition AMReX_BoxArray.H:848
bool operator==(const RefID &rhs) const noexcept
Definition AMReX_BoxArray.H:847