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 <atomic>
14#include <cstddef>
15#include <cstdint>
16#include <map>
17#include <memory>
18#include <unordered_map>
19
25namespace amrex
26{
27 class BoxArray;
28
36 [[nodiscard]] BoxArray boxComplement (const Box& b1in, const Box& b2);
37
45 [[nodiscard]] BoxArray complementIn (const Box& b, const BoxArray& ba);
46
54 [[nodiscard]] BoxArray intersect (const BoxArray& ba, const Box& b, int ng = 0);
55
63 [[nodiscard]] BoxArray intersect (const BoxArray& ba, const Box& b, const IntVect& ng);
64
66 [[nodiscard]] BoxArray intersect (const BoxArray& lhs, const BoxArray& rhs);
67
69 [[nodiscard]] BoxList intersect (const BoxArray& ba, const BoxList& bl);
70
80 [[nodiscard]] BoxArray convert (const BoxArray& ba, IndexType typ);
90 [[nodiscard]] BoxArray convert (const BoxArray& ba, const IntVect& typ);
91
101 [[nodiscard]] BoxArray coarsen (const BoxArray& ba, int ratio);
111 [[nodiscard]] BoxArray coarsen (const BoxArray& ba, const IntVect& ratio);
112
122 [[nodiscard]] BoxArray refine (const BoxArray& ba, int ratio);
132 [[nodiscard]] BoxArray refine (const BoxArray& ba, const IntVect& ratio);
133
146 [[nodiscard]] BoxList GetBndryCells (const BoxArray& ba, int ngrow);
147
155 void readBoxArray (BoxArray& ba, std::istream& s, bool b = false);
156
167 [[nodiscard]] bool match (const BoxArray& x, const BoxArray& y);
168
184 [[nodiscard]] BoxArray decompose (Box const& domain, int nboxes,
185 Array<bool,AMREX_SPACEDIM> const& decomp
186 = {AMREX_D_DECL(true,true,true)},
187 bool no_overlap = false);
188
190struct BARef
191{
192 BARef ();
193 explicit BARef (size_t size);
194 explicit BARef (const Box& b);
195 explicit BARef (const BoxList& bl);
196 explicit BARef (BoxList&& bl) noexcept;
197 explicit BARef (std::istream& is);
198 BARef (const BARef& rhs);
199 BARef (BARef&& rhs) = delete;
200 BARef& operator= (const BARef& rhs) = delete;
201 BARef& operator= (BARef&& rhs) = delete;
202
203 ~BARef ();
204
205 void define (const Box& bx);
206 void define (const BoxList& bl);
207 void define (BoxList&& bl) noexcept;
208 void define (std::istream& is, int& ndims);
210 void resize (Long n);
211#ifdef AMREX_MEM_PROFILING
212 void updateMemoryUsage_box (int s);
213 void updateMemoryUsage_hash (int s);
214#endif
215
216 [[nodiscard]] bool HasHashMap () const noexcept {
217 return has_hashmap.load(std::memory_order_acquire);
218 }
219
220 //
222 Vector<Box> m_abox;
223 //
225 mutable Box bbox;
226
227 mutable IntVect crsn;
228
229 using HashType = std::unordered_map< IntVect, std::vector<int>, IntVect::shift_hasher > ;
230 //using HashType = std::map< IntVect,std::vector<int> >;
231
232 mutable HashType hash;
233
234 mutable std::atomic<bool> has_hashmap = false;
235
236 static int numboxarrays;
237 static int numboxarrays_hwm;
238 static Long total_box_bytes;
239 static Long total_box_bytes_hwm;
240 static Long total_hash_bytes;
241 static Long total_hash_bytes_hwm;
242
243 static void Initialize ();
244 static void Finalize ();
245 static bool initialized;
246};
248
250struct BATnull
251{
252 [[nodiscard]] Box operator() (const Box& bx) const noexcept { return bx; }
253 [[nodiscard]] static constexpr Box coarsen (Box const& a_box) { return a_box; }
254 [[nodiscard]] static constexpr IntVect doiLo () { return IntVect::TheZeroVector(); }
255 [[nodiscard]] static constexpr IntVect doiHi () { return IntVect::TheZeroVector(); }
256 [[nodiscard]] static constexpr IndexType index_type () { return IndexType(); }
257 [[nodiscard]] static constexpr IntVect coarsen_ratio () { return IntVect::TheUnitVector(); }
258};
260
262struct BATindexType
263{
264 explicit BATindexType (IndexType a_typ) : m_typ(a_typ) {}
265 [[nodiscard]] Box operator() (const Box& bx) const noexcept { return amrex::convert(bx,m_typ); }
266 [[nodiscard]] static Box coarsen (Box const& a_box) noexcept { return a_box; }
267 [[nodiscard]] static constexpr IntVect doiLo () { return IntVect::TheZeroVector(); }
268 [[nodiscard]] IntVect doiHi () const noexcept { return m_typ.ixType(); }
269 [[nodiscard]] IndexType index_type () const noexcept { return m_typ; }
270 [[nodiscard]] static constexpr IntVect coarsen_ratio () { return IntVect::TheUnitVector(); }
271 IndexType m_typ;
272};
274
276struct BATcoarsenRatio
277{
278 explicit BATcoarsenRatio (IntVect const& a_crse_ratio) : m_crse_ratio(a_crse_ratio) {}
279 [[nodiscard]] Box operator() (const Box& bx) const noexcept { return amrex::coarsen(bx,m_crse_ratio); }
280 [[nodiscard]] Box coarsen (Box const& a_box) const noexcept { return amrex::coarsen(a_box,m_crse_ratio); }
281 [[nodiscard]] static constexpr IntVect doiLo () { return IntVect::TheZeroVector(); }
282 [[nodiscard]] static constexpr IntVect doiHi () { return IntVect::TheZeroVector(); }
283 [[nodiscard]] static constexpr IndexType index_type () { return IndexType(); }
284 [[nodiscard]] IntVect coarsen_ratio () const noexcept { return m_crse_ratio; }
285 IntVect m_crse_ratio;
286};
288
290struct BATindexType_coarsenRatio
291{
292 BATindexType_coarsenRatio (IndexType a_typ, IntVect const& a_crse_ratio)
293 : m_typ(a_typ), m_crse_ratio(a_crse_ratio) {}
294
295 [[nodiscard]] Box operator() (const Box& bx) const noexcept {
296 return amrex::convert(amrex::coarsen(bx,m_crse_ratio),m_typ);
297 }
298
299 [[nodiscard]] Box coarsen (Box const& a_box) const noexcept { return amrex::coarsen(a_box,m_crse_ratio); }
300
301 [[nodiscard]] static constexpr IntVect doiLo () { return IntVect::TheZeroVector(); }
302 [[nodiscard]] IntVect doiHi () const noexcept { return m_typ.ixType(); }
303
304 [[nodiscard]] IndexType index_type () const noexcept { return m_typ; }
305 [[nodiscard]] IntVect coarsen_ratio () const noexcept { return m_crse_ratio; }
306
307 IndexType m_typ;
308 IntVect m_crse_ratio;
309};
311
313struct BATbndryReg
314{
315 BATbndryReg (Orientation a_face, IndexType a_typ,
316 int a_in_rad, int a_out_rad, int a_extent_rad)
317 : m_face(a_face), m_typ(a_typ), m_crse_ratio(1)
318 {
319 m_loshft = IntVect(-a_extent_rad);
320 m_hishft = IntVect( a_extent_rad);
321 IntVect nodal = a_typ.ixType();
322 m_hishft += nodal;
323 const int d = a_face.coordDir();
324 if (nodal[d]) {
325 // InterpFaceRegister & SyncRegister in IAMR
326 if (m_face.isLow()) {
327 m_loshft[d] = 0;
328 m_hishft[d] = 0;
329 } else {
330 m_loshft[d] = 1;
331 m_hishft[d] = 1;
332 }
333 m_doilo = IntVect(a_extent_rad);
334 m_doihi = IntVect(a_extent_rad);
335 m_doihi += nodal;
336 m_doilo[d] = 0;
337 m_doihi[d] = nodal[d];
338 } else {
339 // BndryRegister
340 if (m_face.isLow()) {
341 m_loshft[d] = nodal[d] - a_out_rad;
342 m_hishft[d] = nodal[d] + a_in_rad - 1;
343 } else {
344 m_loshft[d] = 1 - a_in_rad;
345 m_hishft[d] = a_out_rad;
346 }
347 m_doilo = IntVect(a_extent_rad);
348 m_doihi = IntVect(a_extent_rad);
349 m_doihi += nodal;
350 // domain of influence in index space, the inverse of the shifts
351 int const in_doi = (a_in_rad > 1) ? a_in_rad-1 : 0;
352 if (m_face.isLow()) {
353 m_doilo[d] = a_out_rad;
354 m_doihi[d] = in_doi;
355 } else {
356 m_doilo[d] = in_doi;
357 m_doihi[d] = a_out_rad;
358 }
359 }
360 }
361
362 [[nodiscard]] Box operator() (const Box& a_bx) const noexcept {
363 IntVect lo = amrex::coarsen(a_bx.smallEnd(), m_crse_ratio);
364 IntVect hi = amrex::coarsen(a_bx.bigEnd(), m_crse_ratio);
365 const int d = m_face.coordDir();
366 if (m_face.isLow()) {
367 hi[d] = lo[d];
368 } else {
369 lo[d] = hi[d];
370 }
371 lo += m_loshft;
372 hi += m_hishft;
373 return Box(lo,hi,m_typ);
374 }
375
376 [[nodiscard]] Box coarsen (Box const& a_box) const noexcept { return amrex::coarsen(a_box,m_crse_ratio); }
377
378 [[nodiscard]] IntVect doiLo () const noexcept { return m_doilo; }
379 [[nodiscard]] IntVect doiHi () const noexcept { return m_doihi; }
380
381 [[nodiscard]] IndexType index_type () const noexcept { return m_typ; }
382 [[nodiscard]] IntVect coarsen_ratio () const noexcept { return m_crse_ratio; }
383
384 friend bool operator== (BATbndryReg const& a, BATbndryReg const& b) noexcept {
385 return a.m_face == b.m_face && a.m_typ == b.m_typ && a.m_crse_ratio == b.m_crse_ratio
386 && a.m_loshft == b.m_loshft && a.m_hishft == b.m_hishft
387 && a.m_doilo == b.m_doilo && a.m_doihi == b.m_doihi;
388 }
389
390 Orientation m_face;
391 IndexType m_typ;
392 IntVect m_crse_ratio;
393 IntVect m_loshft;
394 IntVect m_hishft;
395 IntVect m_doilo;
396 IntVect m_doihi;
397};
399
401struct BATransformer
402{
403 enum struct BATType : std::int8_t { null, indexType, coarsenRatio, indexType_coarsenRatio, bndryReg};
404
405 union BATOp {
406 BATOp () noexcept
407 : m_null() {}
408 BATOp (IndexType t) noexcept
409 : m_indexType(t) {}
410 BATOp (IntVect const& r) noexcept
411 : m_coarsenRatio(r) {}
412 BATOp (IndexType t, IntVect const& r) noexcept
413 : m_indexType_coarsenRatio(t,r) {}
414 BATOp (Orientation f, IndexType t, int in_rad, int out_rad, int extent_rad) noexcept
415 : m_bndryReg(f,t,in_rad,out_rad,extent_rad) {}
416 BATnull m_null;
417 BATindexType m_indexType;
418 BATcoarsenRatio m_coarsenRatio;
419 BATindexType_coarsenRatio m_indexType_coarsenRatio;
420 BATbndryReg m_bndryReg;
421 };
422
423 BATransformer () = default;
424
425 BATransformer (IndexType t)
426 : m_bat_type(t.cellCentered() ? BATType::null : BATType::indexType),
427 m_op (t.cellCentered() ? BATOp() : BATOp(t)) {}
428
429 BATransformer (Orientation f, IndexType t, int in_rad, int out_rad, int extent_rad)
430 : m_bat_type(BATType::bndryReg),
431 m_op(f,t,in_rad,out_rad,extent_rad) {}
432
433 [[nodiscard]] Box operator() (Box const& ab) const noexcept {
434 switch (m_bat_type)
435 {
436 case BATType::null:
437 return m_op.m_null(ab);
438 case BATType::indexType:
439 return m_op.m_indexType(ab);
440 case BATType::coarsenRatio:
441 return m_op.m_coarsenRatio(ab);
442 case BATType::indexType_coarsenRatio:
443 return m_op.m_indexType_coarsenRatio(ab);
444 default:
445 return m_op.m_bndryReg(ab);
446 }
447 }
448
449 [[nodiscard]] Box coarsen (Box const& a_box) const noexcept {
450 switch (m_bat_type)
451 {
452 case BATType::null:
453 return amrex::BATnull::coarsen(a_box);
454 case BATType::indexType:
455 return amrex::BATindexType::coarsen(a_box);
456 case BATType::coarsenRatio:
457 return m_op.m_coarsenRatio.coarsen(a_box);
458 case BATType::indexType_coarsenRatio:
459 return m_op.m_indexType_coarsenRatio.coarsen(a_box);
460 default:
461 return m_op.m_bndryReg.coarsen(a_box);
462 }
463 }
464
465 [[nodiscard]] IntVect doiLo () const noexcept {
466 switch (m_bat_type)
467 {
468 case BATType::null:
469 return amrex::BATnull::doiLo();
470 case BATType::indexType:
471 return amrex::BATindexType::doiLo();
472 case BATType::coarsenRatio:
473 return amrex::BATcoarsenRatio::doiLo();
474 case BATType::indexType_coarsenRatio:
475 return amrex::BATindexType_coarsenRatio::doiLo();
476 default:
477 return m_op.m_bndryReg.doiLo();
478 }
479 }
480
481 [[nodiscard]] IntVect doiHi () const noexcept {
482 switch (m_bat_type)
483 {
484 case BATType::null:
485 return amrex::BATnull::doiHi();
486 case BATType::indexType:
487 return m_op.m_indexType.doiHi();
488 case BATType::coarsenRatio:
489 return amrex::BATcoarsenRatio::doiHi();
490 case BATType::indexType_coarsenRatio:
491 return m_op.m_indexType_coarsenRatio.doiHi();
492 default:
493 return m_op.m_bndryReg.doiHi();
494 }
495 }
496
497 [[nodiscard]] IndexType index_type () const noexcept {
498 switch (m_bat_type)
499 {
500 case BATType::null:
501 return amrex::BATnull::index_type();
502 case BATType::indexType:
503 return m_op.m_indexType.index_type();
504 case BATType::coarsenRatio:
505 return amrex::BATcoarsenRatio::index_type();
506 case BATType::indexType_coarsenRatio:
507 return m_op.m_indexType_coarsenRatio.index_type();
508 default:
509 return m_op.m_bndryReg.index_type();
510 }
511 }
512
513 [[nodiscard]] IntVect coarsen_ratio () const noexcept {
514 switch (m_bat_type)
515 {
516 case BATType::null:
517 return amrex::BATnull::coarsen_ratio();
518 case BATType::indexType:
519 return amrex::BATindexType::coarsen_ratio();
520 case BATType::coarsenRatio:
521 return m_op.m_coarsenRatio.coarsen_ratio();
522 case BATType::indexType_coarsenRatio:
523 return m_op.m_indexType_coarsenRatio.coarsen_ratio();
524 default:
525 return m_op.m_bndryReg.coarsen_ratio();
526 }
527 }
528
529 [[nodiscard]] bool is_null () const noexcept {
530 return m_bat_type == BATType::null;
531 }
532
533 [[nodiscard]] bool is_simple () const noexcept {
534 return m_bat_type != BATType::bndryReg;
535 }
536
537 void set_coarsen_ratio (IntVect const& a_ratio) noexcept {
538 switch (m_bat_type)
539 {
540 case BATType::null:
541 {
542 if (a_ratio == IntVect::TheUnitVector()) {
543 return;
544 } else {
545 m_bat_type = BATType::coarsenRatio;
546 m_op.m_coarsenRatio.m_crse_ratio = a_ratio;
547 return;
548 }
549 }
550 case BATType::indexType:
551 {
552 if (a_ratio == IntVect::TheUnitVector()) {
553 return;
554 } else {
555 m_bat_type = BATType::indexType_coarsenRatio;
556 auto t = m_op.m_indexType.m_typ;
557 m_op.m_indexType_coarsenRatio.m_typ = t;
558 m_op.m_indexType_coarsenRatio.m_crse_ratio = a_ratio;
559 return;
560 }
561 }
562 case BATType::coarsenRatio:
563 {
564 if (a_ratio == IntVect::TheUnitVector()) {
565 m_bat_type = BATType::null;
566 return;
567 } else {
568 m_op.m_coarsenRatio.m_crse_ratio = a_ratio;
569 return;
570 }
571 }
572 case BATType::indexType_coarsenRatio:
573 {
574 if (a_ratio == IntVect::TheUnitVector()) {
575 m_bat_type = BATType::indexType;
576 auto t = m_op.m_indexType_coarsenRatio.m_typ;
577 m_op.m_indexType.m_typ = t;
578 return;
579 } else {
580 m_op.m_indexType_coarsenRatio.m_crse_ratio = a_ratio;
581 return;
582 }
583 }
584 default:
585 {
586 m_op.m_bndryReg.m_crse_ratio = a_ratio;
587 return;
588 }
589 }
590 }
591
592 void set_index_type (IndexType typ) noexcept {
593 switch (m_bat_type)
594 {
595 case BATType::null:
596 {
597 if (typ.cellCentered()) {
598 return;
599 } else {
600 m_bat_type = BATType::indexType;
601 m_op.m_indexType.m_typ = typ;
602 return;
603 }
604 }
605 case BATType::indexType:
606 {
607 if (typ.cellCentered()) {
608 m_bat_type = BATType::null;
609 return;
610 } else {
611 m_op.m_indexType.m_typ = typ;
612 return;
613 }
614 }
615 case BATType::coarsenRatio:
616 {
617 if (typ.cellCentered()) {
618 return;
619 } else {
620 m_bat_type = BATType::indexType_coarsenRatio;
621 auto r = m_op.m_coarsenRatio.m_crse_ratio;
622 m_op.m_indexType_coarsenRatio.m_typ = typ;
623 m_op.m_indexType_coarsenRatio.m_crse_ratio = r;
624 return;
625 }
626 }
627 case BATType::indexType_coarsenRatio:
628 {
629 if (typ.cellCentered()) {
630 m_bat_type = BATType::coarsenRatio;
631 auto r = m_op.m_indexType_coarsenRatio.m_crse_ratio;
632 m_op.m_coarsenRatio.m_crse_ratio = r;
633 return;
634 } else {
635 m_op.m_indexType_coarsenRatio.m_typ = typ;
636 return;
637 }
638 }
639 default:
640 {
641 m_op.m_bndryReg.m_typ = typ;
642 return;
643 }
644 }
645 }
646
647 friend bool operator== (BATransformer const& a, BATransformer const& b) noexcept {
648 if (a.m_bat_type != BATType::bndryReg && b.m_bat_type != BATType::bndryReg) {
649 return a.index_type() == b.index_type()
650 && a.coarsen_ratio() == b.coarsen_ratio();
651 } else if (a.m_bat_type == BATType::bndryReg && b.m_bat_type == BATType::bndryReg) {
652 return a.m_op.m_bndryReg == b.m_op.m_bndryReg;
653 } else {
654 return false;
655 }
656 }
657
658 BATType m_bat_type{BATType::null};
659 BATOp m_op;
660};
662
663// for backward compatibility
664using BndryBATransformer = BATransformer;
665
666class MFIter;
667class AmrMesh;
668class FabArrayBase;
669
681{
682public:
683
685 BoxArray () noexcept;
686 BoxArray (const BoxArray& rhs) = default;
687 BoxArray (BoxArray&& rhs) noexcept = default;
688 BoxArray& operator= (BoxArray const& rhs) = default;
689 BoxArray& operator= (BoxArray&& rhs) noexcept = default;
690 ~BoxArray() noexcept = default;
691
697 explicit BoxArray (const Box& bx);
698
702 explicit BoxArray (size_t n);
703
710 BoxArray (const Box* bxvec,
711 int nbox);
712
714 explicit BoxArray (const BoxList& bl);
715 explicit BoxArray (BoxList&& bl) noexcept;
716
723 BoxArray (const BoxArray& rhs, const BATransformer& trans);
724
731 BoxArray (BoxList&& bl, IntVect const& max_grid_size);
732
740 void define (const Box& bx);
748 void define (const BoxList& bl);
749 void define (BoxList&& bl) noexcept;
750
752 void clear ();
753
755 void resize (Long len);
756
758 [[nodiscard]] Long size () const noexcept { return m_ref->m_abox.size(); }
759
761 [[nodiscard]] Long capacity () const noexcept { return static_cast<Long>(m_ref->m_abox.capacity()); }
762
764 [[nodiscard]] bool empty () const noexcept { return m_ref->m_abox.empty(); }
765
767 [[nodiscard]] Long numPts() const noexcept;
768
770 [[nodiscard]] double d_numPts () const noexcept;
781 int readFrom (std::istream& is);
782
784 std::ostream& writeOn (std::ostream&) const;
785
787 [[nodiscard]] bool operator== (const BoxArray& rhs) const noexcept;
788
790 [[nodiscard]] bool operator!= (const BoxArray& rhs) const noexcept;
791
792 [[nodiscard]] bool operator== (const Vector<Box>& bv) const noexcept;
793 [[nodiscard]] bool operator!= (const Vector<Box>& bv) const noexcept;
794
796 [[nodiscard]] bool CellEqual (const BoxArray& rhs) const noexcept;
797
806 BoxArray& maxSize (int block_size);
807
817 BoxArray& maxSize (const IntVect& block_size);
818
829 BoxArray& minmaxSize (const IntVect& min_size, const IntVect& max_size);
830
840 void repartition (BoxList&& bl);
841
850 BoxArray& refine (int refinement_ratio);
851
860 BoxArray& refine (const IntVect& iv);
861
870 BoxArray& coarsen (int refinement_ratio);
871
884 [[nodiscard]] bool coarsenable (int refinement_ratio, int min_width=1) const;
897 [[nodiscard]] bool coarsenable (const IntVect& refinement_ratio, int min_width=1) const;
910 [[nodiscard]] bool coarsenable (const IntVect& refinement_ratio, const IntVect& min_width) const;
911
920 BoxArray& coarsen (const IntVect& iv);
921
932 BoxArray& growcoarsen (int n, const IntVect& iv);
943 BoxArray& growcoarsen (IntVect const& ngrow, const IntVect& iv);
944
953 BoxArray& grow (int n);
954
963 BoxArray& grow (const IntVect& iv);
973 BoxArray& grow (int idir, int n_cell);
983 BoxArray& growLo (int idir, int n_cell);
993 BoxArray& growHi (int idir, int n_cell);
1009 BoxArray& surroundingNodes (int dir);
1010
1017
1025 BoxArray& enclosedCells (int dir);
1026
1034 BoxArray& convert (IndexType typ);
1035
1043 BoxArray& convert (const IntVect& iv);
1044
1053 BoxArray& convert (Box (*fp)(const Box&));
1054
1064 BoxArray& shift (int dir, int nzones);
1065
1074 BoxArray& shift (const IntVect &iv);
1075
1085 void set (int i, const Box& ibox);
1086
1088 [[nodiscard]] Box operator[] (int index) const noexcept {
1089 return m_bat(m_ref->m_abox[index]);
1090 }
1091
1093 [[nodiscard]] Box operator[] (const MFIter& mfi) const noexcept;
1094
1096 [[nodiscard]] Box get (int index) const noexcept { return operator[](index); }
1097
1099 [[nodiscard]] Box getCellCenteredBox (int index) const noexcept {
1100 return m_bat.coarsen(m_ref->m_abox[index]);
1101 }
1102
1109 [[nodiscard]] bool ok () const;
1110
1112 [[nodiscard]] bool isDisjoint () const;
1113
1115 [[nodiscard]] BoxList boxList () const;
1116
1121 [[nodiscard]] bool contains (const IntVect& v) const;
1122
1132 [[nodiscard]]
1133 bool contains (const Box& b, bool assume_disjoint_ba = false,
1134 const IntVect& ng = IntVect(0)) const;
1135
1143 [[nodiscard]]
1144 bool contains (const BoxArray& ba, bool assume_disjoint_ba = false,
1145 const IntVect& ng = IntVect(0)) const;
1146
1156 [[nodiscard]]
1157 bool contains (const BoxArray& ba, Periodicity const& period) const;
1158
1160 [[nodiscard]] Box minimalBox () const;
1165 [[nodiscard]] Box minimalBox (Long& npts_avg_box) const;
1166
1172 [[nodiscard]]
1173 bool intersects (const Box& b, int ng = 0) const;
1174
1180 [[nodiscard]]
1181 bool intersects (const Box& b, const IntVect& ng) const;
1182
1189 [[nodiscard]]
1190 std::vector< std::pair<int,Box> > intersections (const Box& bx) const;
1191
1198 [[nodiscard]]
1199 std::vector< std::pair<int,Box> > intersections (const Box& bx, bool first_only, int ng) const;
1200
1207 [[nodiscard]]
1208 std::vector< std::pair<int,Box> > intersections (const Box& bx, bool first_only, const IntVect& ng) const;
1209
1215 void intersections (const Box& bx, std::vector< std::pair<int,Box> >& isects) const;
1216
1224 void intersections (const Box& bx, std::vector< std::pair<int,Box> >& isects,
1225 bool first_only, int ng) const;
1226
1234 void intersections (const Box& bx, std::vector< std::pair<int,Box> >& isects,
1235 bool first_only, const IntVect& ng) const;
1236
1238 [[nodiscard]] BoxList complementIn (const Box& b) const;
1239 void complementIn (BoxList& bl, const Box& b) const;
1240
1242 [[nodiscard]] BoxList complementIn (const Box& b, const Periodicity& period) const;
1243
1245 void clear_hash_bin () const;
1246
1248 void removeOverlap (bool simplify=true);
1249
1251 [[nodiscard]] static bool SameRefs (const BoxArray& lhs, const BoxArray& rhs) { return lhs.m_ref == rhs.m_ref; }
1252
1253 struct RefID {
1254 RefID () noexcept = default;
1255 explicit RefID (BARef* data_) noexcept : data(data_) {}
1256 bool operator< (const RefID& rhs) const noexcept { return std::less<>()(data,rhs.data); }
1257 bool operator== (const RefID& rhs) const noexcept { return data == rhs.data; }
1258 bool operator!= (const RefID& rhs) const noexcept { return data != rhs.data; }
1259 friend std::ostream& operator<< (std::ostream& os, const RefID& id);
1260 private:
1261 BARef* data{nullptr};
1262 };
1263
1265 [[nodiscard]] RefID getRefID () const noexcept { return RefID { m_ref.get() }; }
1266
1268 [[nodiscard]] IndexType ixType () const noexcept { return m_bat.index_type(); }
1269
1271 [[nodiscard]] IntVect crseRatio () const noexcept { return m_bat.coarsen_ratio(); }
1272
1273 static void Initialize ();
1274 static void Finalize ();
1275 static bool initialized;
1276
1278 void uniqify ();
1279
1281 [[nodiscard]] BoxList const& simplified_list () const;
1283 [[nodiscard]] BoxArray simplified () const;
1284
1286 [[nodiscard]] BATransformer const& transformer () const;
1287
1289 [[nodiscard]] std::weak_ptr<BARef> getWeakRef () const;
1291 [[nodiscard]] std::shared_ptr<BARef> const& getSharedRef () const;
1293 std::shared_ptr<BARef>& getSharedRef ();
1294
1295 friend class AmrMesh;
1296 friend class FabArrayBase;
1297
1298private:
1300 void type_update ();
1301
1302 [[nodiscard]] BARef::HashType& getHashMap () const;
1303
1304 [[nodiscard]] IntVect getDoiLo () const noexcept;
1305 [[nodiscard]] IntVect getDoiHi () const noexcept;
1306
1307 BATransformer m_bat;
1309 std::shared_ptr<BARef> m_ref;
1310 mutable std::shared_ptr<BoxList> m_simplified_list;
1311};
1312
1314std::ostream& operator<< (std::ostream& os, const BoxArray& ba);
1315
1316std::ostream& operator<< (std::ostream& os, const BoxArray::RefID& id);
1317
1318}
1319
1320#endif /*BL_BOXARRAY_H*/
Fixed-size array types for use on GPU and CPU.
A list of Boxes sharing a common IndexType.
int idir
Definition AMReX_HypreMLABecLap.cpp:1135
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Definition AMReX_AmrMesh.H:84
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:681
IndexType ixType() const noexcept
Return index type of this BoxArray.
Definition AMReX_BoxArray.H:1268
Box operator[](int index) const noexcept
Return element index of this BoxArray.
Definition AMReX_BoxArray.H:1088
Long capacity() const noexcept
Return the number of boxes that can be held in the current allocated storage.
Definition AMReX_BoxArray.H:761
RefID getRefID() const noexcept
Return a unique ID of the reference.
Definition AMReX_BoxArray.H:1265
bool intersects(const Box &b, int ng=0) const
True if b intersects this BoxArray(+ng).
Definition AMReX_BoxArray.cpp:1185
BoxArray & grow(int n)
Grow each Box by n cells in every direction.
Definition AMReX_BoxArray.cpp:722
static void Finalize()
Definition AMReX_BoxArray.cpp:282
BoxArray() noexcept
Construct an empty BoxArray.
Definition AMReX_BoxArray.cpp:287
std::vector< std::pair< int, Box > > intersections(const Box &bx) const
Return all intersections of bx with this BoxArray.
Definition AMReX_BoxArray.cpp:1202
std::ostream & writeOn(std::ostream &) const
Output this BoxArray to a checkpoint file.
Definition AMReX_BoxArray.cpp:482
bool contains(const IntVect &v) const
Return true if the cell v is within any box in the array.
Definition AMReX_BoxArray.cpp:993
static void Initialize()
Definition AMReX_BoxArray.cpp:271
BoxList const & simplified_list() const
Return (and cache) a simplified BoxList representation; regular AMR grids only.
Definition AMReX_BoxArray.cpp:1654
BoxList boxList() const
Create a BoxList from this BoxArray.
Definition AMReX_BoxArray.cpp:965
BoxArray simplified() const
Return a simplified BoxArray; regular AMR grids only.
Definition AMReX_BoxArray.cpp:1665
IntVect crseRatio() const noexcept
Return crse ratio of this BoxArray.
Definition AMReX_BoxArray.H:1271
int readFrom(std::istream &is)
Initialize the BoxArray from the supplied istream.
Definition AMReX_BoxArray.cpp:468
void define(const Box &bx)
Initialize the BoxArray from a single box.
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:1458
Box minimalBox() const
Return smallest Box that contains all Boxes in this BoxArray.
Definition AMReX_BoxArray.cpp:1083
BoxArray & minmaxSize(const IntVect &min_size, const IntVect &max_size)
Constrain Box sizes between min_size and max_size.
Definition AMReX_BoxArray.cpp:577
BoxArray & refine(int refinement_ratio)
Refine each Box in the BoxArray by refinement_ratio.
Definition AMReX_BoxArray.cpp:606
std::weak_ptr< BARef > getWeakRef() const
Return a weak pointer to the shared Box storage.
Definition AMReX_BoxArray.cpp:1677
bool coarsenable(int refinement_ratio, int min_width=1) const
Check whether every Box is coarsenable by refinement_ratio.
Definition AMReX_BoxArray.cpp:628
BoxArray & growLo(int idir, int n_cell)
Grow each Box on the lower side of dimension idir.
Definition AMReX_BoxArray.cpp:768
void repartition(BoxList &&bl)
Replace the Boxes with a different partition of the same cells.
Definition AMReX_BoxArray.cpp:593
void resize(Long len)
Resize the BoxArray. See Vector<T>::resize() for the gory details.
Definition AMReX_BoxArray.cpp:387
BoxArray & enclosedCells()
Convert the BoxArray to cell-centered type in all directions.
Definition AMReX_BoxArray.cpp:815
std::shared_ptr< BARef > const & getSharedRef() const
Return the shared pointer to the Box storage.
Definition AMReX_BoxArray.cpp:1683
Box getCellCenteredBox(int index) const noexcept
Return cell-centered box at element index of this BoxArray.
Definition AMReX_BoxArray.H:1099
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
Return the transformer describing index-type/coarsening metadata.
Definition AMReX_BoxArray.cpp:1671
static bool initialized
Definition AMReX_BoxArray.H:1275
static bool SameRefs(const BoxArray &lhs, const BoxArray &rhs)
whether two BoxArrays share the same data
Definition AMReX_BoxArray.H:1251
BoxArray & growHi(int idir, int n_cell)
Grow each Box on the upper side of dimension idir.
Definition AMReX_BoxArray.cpp:784
BoxList complementIn(const Box &b) const
Return box - boxarray.
Definition AMReX_BoxArray.cpp:1331
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:1474
BoxArray & coarsen(int refinement_ratio)
Coarsen each Box in the BoxArray by refinement_ratio.
Definition AMReX_BoxArray.cpp:685
BoxArray & shift(int dir, int nzones)
Shift each Box in the BoxArray by nzones cells in direction dir.
Definition AMReX_BoxArray.cpp:863
BoxArray & surroundingNodes()
Convert the BoxArray to nodal type in all directions.
Definition AMReX_BoxArray.cpp:800
BoxArray(BoxArray &&rhs) noexcept=default
Long size() const noexcept
Return the number of boxes in the BoxArray.
Definition AMReX_BoxArray.H:758
Box get(int index) const noexcept
Return element index of this BoxArray.
Definition AMReX_BoxArray.H:1096
~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 to ibox if no coarsening transformer is active.
Definition AMReX_BoxArray.cpp:894
BoxArray & growcoarsen(int n, const IntVect &iv)
Expand boxes by n cells in every direction, then coarsen by iv.
Definition AMReX_BoxArray.cpp:701
BoxArray & convert(IndexType typ)
Set the IndexType of the BoxArray.
Definition AMReX_BoxArray.cpp:829
bool ok() const
Return true if the BoxArray is empty or every Box reports ok().
Definition AMReX_BoxArray.cpp:910
BoxArray & operator=(BoxArray const &rhs)=default
void uniqify()
Make ourselves unique.
Definition AMReX_BoxArray.cpp:1631
BoxArray(const BoxArray &rhs)=default
bool empty() const noexcept
Return whether the BoxArray is empty.
Definition AMReX_BoxArray.H:764
bool isDisjoint() const
Return true if set of intersecting Boxes in BoxArray is null.
Definition AMReX_BoxArray.cpp:936
BoxArray & maxSize(int block_size)
Split any Box whose side length exceeds block_size.
Definition AMReX_BoxArray.cpp:553
void clear()
Remove all Boxes from the BoxArray.
Definition AMReX_BoxArray.cpp:379
A list of Boxes sharing a common IndexType.
Definition AMReX_BoxList.H:109
Base class for FabArray.
Definition AMReX_FabArrayBase.H:47
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:88
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:29
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a copy of b converted to the nodal flags typ.
Definition AMReX_Box.H:1630
__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
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:1735
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)
Initialize AMReX using an existing MPI communicator.
Definition AMReX.cpp:344
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
BoxList GetBndryCells(const BoxArray &ba, int ngrow)
Find the boundary/ghost region around a BoxArray.
Definition AMReX_BoxArray.cpp:1860
IndexTypeND< 3 > IndexType
IndexType is an alias for amrex::IndexTypeND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:41
void Finalize(AMReX *pamrex)
Finalize AMReX state associated with the supplied instance pointer.
Definition AMReX.cpp:827
BoxArray decompose(Box const &domain, int nboxes, Array< bool, 3 > const &decomp, bool no_overlap)
Decompose domain box into BoxArray.
Definition AMReX_BoxArray.cpp:1961
bool match(const BoxArray &x, const BoxArray &y)
Return true if two BoxArrays cover the same index space.
Definition AMReX_BoxArray.cpp:1948
BoxArray complementIn(const Box &b, const BoxArray &ba)
Make a BoxArray from the complement of ba within the Box b.
Definition AMReX_BoxArray.cpp:1728
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
void readBoxArray(BoxArray &ba, std::istream &is, bool bReadSpecial)
Read a BoxArray from a stream.
Definition AMReX_BoxArray.cpp:1918
BATransformer BndryBATransformer
Definition AMReX_BoxArray.H:664
BoxArray boxComplement(const Box &b1in, const Box &b2)
Make a BoxArray from the complement of b2 in b1in.
Definition AMReX_BoxArray.cpp:1721
Definition AMReX_BoxArray.H:1253
friend std::ostream & operator<<(std::ostream &os, const RefID &id)
Definition AMReX_BoxArray.cpp:2144
RefID() noexcept=default
bool operator<(const RefID &rhs) const noexcept
Definition AMReX_BoxArray.H:1256
bool operator!=(const RefID &rhs) const noexcept
Definition AMReX_BoxArray.H:1258
bool operator==(const RefID &rhs) const noexcept
Definition AMReX_BoxArray.H:1257