LCOV - code coverage report
Current view: top level - ext/amrex/2d-coverage-g++-24.08/include - AMReX_BoxList.H (source / functions) Hit Total Coverage
Test: coverage_merged.info Lines: 3 3 100.0 %
Date: 2024-11-18 05:28:54 Functions: 3 3 100.0 %

          Line data    Source code
       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             : 
      19             :     //! Returns a BoxList defining the complement of BoxList bl in Box b.
      20             :     BoxList complementIn (const Box& b, const BoxList& bl);
      21             : 
      22             :     //! Returns BoxList defining the compliment of b2 in b1in.
      23             :     BoxList boxDiff (const Box& b1in, const Box& b2);
      24             : 
      25             :     void boxDiff (BoxList& bl_diff, const Box& b1in, const Box& b2);
      26             : 
      27             :     //! Returns a new BoxList in which each Box is refined by the given ratio.
      28             :     BoxList refine (const BoxList&  bl, int ratio);
      29             : 
      30             :     //! Returns a new BoxList in which each Box is coarsened by the given ratio.
      31             :     BoxList coarsen (const BoxList& bl, int ratio);
      32             : 
      33             :     //! Returns a BoxList defining the intersection of bl with b.
      34             :     BoxList intersect (const BoxList& bl, const Box& b);
      35             : 
      36             :     //! Returns a new BoxList in which each Box is grown by the given size.
      37             :     BoxList accrete (const BoxList& bl, int sz);
      38             : 
      39             :     //! Return BoxList which covers the same area but has no overlapping boxes.
      40             :     BoxList removeOverlap (const BoxList& bl);
      41             : 
      42             : 
      43             :     //! Output a BoxList to an ostream in ASCII format.
      44             :     std::ostream& operator<< (std::ostream&  os, const BoxList& blist);
      45             : 
      46             : 
      47             : /** \brief A class for managing a List of Boxes that share a common
      48             : * IndexType.  This class implements operations for sets of Boxes.
      49             : * This is a concrete class, not a polymorphic one.
      50             : */
      51             : class BoxList
      52             : {
      53             : public:
      54             : 
      55             :     friend class BoxDomain;
      56             : 
      57             :     using       iterator = Vector<Box>::iterator;
      58             :     using const_iterator = Vector<Box>::const_iterator;
      59             : 
      60             :     //! Construct an empty BoxList with IndexType::TheCellType().
      61             :     BoxList ();
      62             : 
      63             :     //! Make a boxList consisting of a single Box
      64             :     explicit BoxList (const Box& bx);
      65             : 
      66             :     //! Construct an empty BoxList with IndexType _btype
      67             :     explicit BoxList (IndexType _btype);
      68             : 
      69             :     //!  Construct a BoxList from a BoxArray.
      70             :     explicit BoxList (const BoxArray& ba);
      71             : 
      72             :     //! Construct a boxlist from a rvalue Vector<Box>.
      73             :     explicit BoxList (Vector<Box>&& bxs);
      74             : 
      75             :     //! Make a boxList consisting of non-overlapping tile box from a single Box
      76             :     BoxList (const Box& bx, const IntVect& tilesize);
      77             : 
      78             :     //! Make a BoxList consisting of nboxes Boxes from a single Box
      79             :     BoxList (const Box& bx, int nboxes);
      80             : 
      81             :     //! Make a BoxList consisting of nboxes Boxes chopped in dir-direction from a single Box
      82             :     BoxList (const Box& bx, int nboxes, Direction dir);
      83             : 
      84      345562 :     ~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             : 
      92             :     //! Append a Box to this BoxList.
      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             : 
     103             :     //! Join the BoxList to ourselves.
     104             :     void join (const BoxList& blist);
     105             :     //! Join the Array of Boxes to ourselves.
     106             :     void join (const Vector<Box>& barr);
     107             :     //! Catenate the BoxList to ourselves. Removes entries from blist.
     108             :     void catenate (BoxList& blist);
     109             : 
     110             :     //! Remove all Boxes from this BoxList.
     111             :     void clear ();
     112             :     //! The number of Boxes in this BoxList.
     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      345562 :     [[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      345562 :     [[nodiscard]] const_iterator end () const noexcept { return m_lbox.cend(); }
     123             :     [[nodiscard]] const_iterator cend () const noexcept { return m_lbox.cend(); }
     124             :     /**
     125             :     * \brief True if this BoxList is valid; i.e. all the Boxes are
     126             :     * valid and they all have the same IndexType.  Also returns
     127             :     * true if the BoxList is empty.
     128             :     */
     129             :     [[nodiscard]] bool ok () const noexcept;
     130             :     //! Is this BoxList equal to rhs?
     131             :     bool operator== (const BoxList& rhs) const;
     132             :     //! Is this BoxList notequal to rhs?
     133             :     bool operator!= (const BoxList& rhs) const;
     134             :     //! Is this BoxList empty?
     135             :     [[nodiscard]] bool isEmpty () const noexcept { return m_lbox.empty(); }
     136             :     //! Is this BoxList not empty?
     137             :     [[nodiscard]] bool isNotEmpty () const noexcept { return !m_lbox.empty(); }
     138             :     //! True if the set of intersecting Boxes is empty.
     139             :     [[nodiscard]] bool isDisjoint () const;
     140             :     //! True if all Boxes in bl are contained in this BoxList.
     141             :     [[nodiscard]] bool contains (const BoxList& bl) const;
     142             :     //! Modify this BoxList to contain only its intersection with Box b.
     143             :     BoxList& intersect (const Box& b);
     144             :     //! Modify this BoxList to contain only its intersection with BoxList bl.
     145             :     BoxList& intersect (const BoxList& bl);
     146             :     //! Remove empty Boxes from this BoxList.
     147             :     BoxList& removeEmpty();
     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);
     153             :     BoxList& parallelComplementIn (const Box& b, BoxList&& bl);
     154             :     BoxList& parallelComplementIn (const Box& b, const BoxArray& ba);
     155             : 
     156             :     //! Refine each Box in the BoxList by the ratio.
     157             :     BoxList& refine (int ratio);
     158             :     //! Refine each Box in the BoxList by the ratio.
     159             :     BoxList& refine (const IntVect& ratio);
     160             :     //! Coarsen each Box in the BoxList by the ratio.
     161             :     BoxList& coarsen (int ratio);
     162             :     //! Coarsen each Box in the BoxList by the ratio.
     163             :     BoxList& coarsen (const IntVect& ratio);
     164             :     //! Grow each Box in the BoxList by size sz.
     165             :     BoxList& accrete  (int sz);
     166             :     BoxList& accrete  (const IntVect& sz);
     167             :     //! Applies Box::shift(int,int) to each Box in the BoxList.
     168             :     BoxList& shift (int dir,
     169             :                     int nzones);
     170             :     //! Applies Box::shiftHalf(int,int) to each Box in the BoxList.
     171             :     BoxList& shiftHalf (int dir,
     172             :                         int num_halfs);
     173             :     //! Applies Box::shiftHalf(IntVect) to each Box in BoxList.
     174             :     BoxList& shiftHalf (const IntVect& iv);
     175             :     /**
     176             :     * \brief Merge adjacent Boxes in this BoxList. Return the number
     177             :     * of Boxes merged.  If "best" is specified we do a single
     178             :     * bruteforce pass over the list checking each Box against
     179             :     * all Boxes after it in the list to see if they can be
     180             :     * merged.  If "best" is not specified we limit how fair
     181             :     * afield we look for possible matches.  The "best" algorithm
     182             :     * is O(N-squared) while the other algorithm is O(N).
     183             :     */
     184             :     int simplify (bool best = false);
     185             :     //! Assuming the boxes are nicely ordered
     186             :     int ordered_simplify ();
     187             :     //! Forces each Box in the BoxList to have sides of length <= chunk.
     188             :     BoxList& maxSize (int chunk);
     189             :     //! Forces each Box in the BoxList to have dimth side of length <= chunk[dim].
     190             :     BoxList& maxSize (const IntVect& chunk);
     191             :     //! Returns smallest Box that contains all Boxes in this BoxList.
     192             :     [[nodiscard]] Box minimalBox () const;
     193             :     //! Returns the IndexType of Boxes in this BoxList.
     194             :     [[nodiscard]] IndexType ixType () const noexcept { return btype; }
     195             :     //! Set the type of the BoxList.  It's an error if the BoxList isn't empty.
     196             :     void set (IndexType ixtyp) noexcept { BL_ASSERT(m_lbox.empty()); btype = ixtyp; }
     197             :     /**
     198             :     * \brief Applies surroundingNodes(Box) to each Box in BoxArray.
     199             :     * See the documentation of Box for details.
     200             :     */
     201             :     BoxList& surroundingNodes () noexcept;
     202             :     /**
     203             :     * \brief Applies surroundingNodes(Box,int) to each Box in
     204             :     * BoxList.  See the documentation of Box for details.
     205             :     */
     206             :     BoxList& surroundingNodes (int dir) noexcept;
     207             :     //! Applies Box::enclosedCells() to each Box in the BoxList.
     208             :     BoxList& enclosedCells () noexcept;
     209             :     //! Applies Box::enclosedCells(int) to each Box in the BoxList.
     210             :     BoxList& enclosedCells  (int dir) noexcept;
     211             :     //! Applies Box::convert(IndexType) to each Box in the BoxList.
     212             :     BoxList& convert (IndexType typ) noexcept;
     213             : 
     214             :     //! Returns a reference to the Vector<Box>.
     215             :     [[nodiscard]] Vector<Box>& data () noexcept { return m_lbox; }
     216             :     //! Returns a constant reference to the Vector<Box>.
     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:
     227             :     //! Core simplify routine.
     228             :     int simplify_doit (int depth);
     229             : 
     230             :     //! The list of Boxes.
     231             :     Vector<Box> m_lbox;
     232             :     //! The IndexType of Boxes in the BoxList.
     233             :     IndexType btype;
     234             : 
     235             : };
     236             : 
     237             : }
     238             : 
     239             : #endif /*BL_BOXLIST_H*/

Generated by: LCOV version 1.14