Chombo + EB + MF  3.2
ListBox.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 // ANAG, LBNL
12 
13 #ifndef _LISTBOX_H_
14 #define _LISTBOX_H_
15 
16 #include "Arena.H"
17 #include "Interval.H"
18 #include "RealVect.H"
19 #include "List.H"
20 #include "Box.H"
21 #include "NamespaceHeader.H"
22 
23 /** A class for storing and sorting particle items. Particles are held in a List
24  and belong to this ListBox if their position is within the domain represented
25  by the object Box.. Class <T> must have a \p RealVect \b <T>::position() const
26  function which is used to assign the item to the ListBox. See class \p BinItem
27  for a base class for particles.
28 */
29 
30 template<class T>
31 class ListBox
32 {
33 public:
34 
35  /// Null constructor.
36  ListBox();
37 
38  /// Constructs an empty \p ListBox on \a a_box. a_meshSpacing is the cell size in
39  /// each direction, and a_origin is the location in physical coordinates of the
40  /// lower left corner of the problem domain.
41  ListBox(const Box& a_box,
42  const RealVect& a_meshSpacing,
43  const RealVect& a_origin);
44 
45  /// Destructor.
46  virtual ~ListBox();
47 
48  /// Same as the constructor.
49  virtual void define(const Box& a_box,
50  const RealVect& a_meshSpacing,
51  const RealVect& a_origin);
52 
53  /// Free the memory associated with this ListBox.
54  virtual void undefine();
55 
56  /// Returns the list of items contained in this ListBox.
57  inline List<T>& listItems();
58 
59  /// Returns the list of items contained in this ListBox, const version.
60  inline const List<T>& listItems() const;
61 
62  /// Copy items from this ListBox into a_list only if they are contained in a_valid.
63  /// This operation does not remove the items from this ListBox.
64  virtual void getItems(List<T>& a_list, const Box& a_valid) const;
65 
66  /// Transfer items from this ListBox into a_list only if they are contained in a_valid.
67  /// This operation removes the items from this ListBox.
68  virtual void getItemsDestructive(List<T>& a_list, const Box& a_valid);
69 
70  /// Copy items from this ListBox into a_list if they are NOT contained in a_valid.
71  /// Does not remove the items from this ListBox.
72  virtual void getInvalid(List<T>& a_list, const Box& a_valid) const;
73 
74  /// Transfer items from this ListBox into a_list if they are NOT contained in a_valid.
75  /// This removes the items from this ListBox.
76  virtual void getInvalidDestructive(List<T>& a_list, const Box& a_valid);
77 
78  /// Add a_item to this ListBox if it is contained within m_box.
79  virtual void addItem(const T& a_item);
80 
81  /// Add each item in a_list into this ListBox if they are contained within m_box.
82  /// Does not remove the items from a_list.
83  virtual void addItems(const List<T>& a_list);
84 
85  /// Transfer each item in a_list into this ListBox if it is contained within m_box.
86  /// This removes the items from a_list.
87  virtual void addItemsDestructive(List<T>& a_list);
88 
89  /// Transfer each item in a_list into this ListBox if it is contained within a_valid.
90  /// This removes the items from a_list.
91  virtual void addItemsDestructive(List<T>& a_list, const Box& a_valid);
92 
93  /// Performs transfer of the items from src to dest. Notice that as
94  /// a result both *this and a_src are modified.
95  virtual void transfer(ListBox<T>& a_src,
96  const Box& a_srcBox,
97  const Box& a_destBox,
98  const int a_srcComp =0,
99  const int a_destComp=0,
100  const int a_numComp =1);
101 
102  /// Remove all the items from this ListBox that are within a_RegionTo, and add
103  /// all the particles from the ListBox a_src that are within a_RegionFrom.
104  virtual void copy(const Box& a_RegionFrom,
105  const Interval& a_Cdest,
106  const Box& a_RegionTo,
107  const ListBox<T>& a_src,
108  const Interval& a_Csrc);
109 
110  /// Return the number of items in this ListBox.
111  virtual size_t numItems() const;
112 
113  // Return the number of items in this ListBox that are inside a_box; this one is slow.
114  virtual size_t numItems(const Box& a_box, const bool a_in=true) const;
115 
116  // Linearization functions
117 
118  /// The number of bytes used by \b linearIn()/linearOut().
119  /** Returns the size, in number of bytes, of a flat linear
120  representation of the items in the specified \p Box.
121  */
122  virtual int size(const Box& a_box,
123  const Interval& a_comps = Interval()) const;
124 
125  /// Write a serialized (packed) representation into \a a_buf.
126  /** Write a linear representation of the items in the specified \p Box.
127  Assumes that sufficient memory for the buffer has already been
128  allocated by the caller.
129  */
130  virtual void linearOut(void* a_buf,
131  const Box& a_box,
132  const Interval& a_comps = Interval()) const;
133 
134  ///
135  virtual void linearOutDestructive(void* buf,
136  const Box& a_box,
137  const Interval& a_comps = Interval());
138 
139  /// Extract a serialized (packed) representation from \a a_buf.
140  /** Given a linear representation of the class data previously made
141  using linearIn() in \a a_buf, set the data for this class on the
142  specified \p Box.
143  */
144  virtual void linearIn(void* a_buf,
145  const Box& a_box,
146  const Interval& a_comps = Interval());
147 
148  /// Retrieve the mesh size.
149  virtual const RealVect& meshSpacing() const;
150 
151  /// Retrieve the box.
152  const Box& box() const;
153 
154  /// Delete all items in this ListBox and reset it to the null Box.
155  virtual void clear();
156 
157  /// Lists are not pre-allocatable. This function is needed so that ListBox
158  /** can be stored inside LevelData<T> containers
159  */
160  static int preAllocatable() { return 2; }
161 
162  /// as in BaseFab; needed for loop-unroll macro
163  IntVect size() const
164  {
165  return this->m_box.size();
166  }
167 
168 protected:
169 
170  static Arena* s_Arena;
171 
172  static std::string name();
173 
174  /// The Box that defines the valid region of this ListBox
176 
177  /// Pointer to the List that stores our items
179 
180  /// The cell size in physical space
182 
183  /// The center of our coordinate system. Used for binning our items.
185 
186  /// Determines whether a_item is enclosed in a_box
187  inline virtual bool isEnclosed(const T& a_item, const Box& a_box) const;
188 
189 private:
190  ///
191  /// These functions are made private to prevent use of the default
192  /// functions provided by the C++ compiler.
193  ///
195  ListBox(const ListBox<T>&);
196 
197 };
198 
199 #include "NamespaceFooter.H"
200 
201 // Implementation
202 #include "ListBoxI.H"
203 
204 #endif
RealVect m_mesh_spacing
The cell size in physical space.
Definition: ListBox.H:181
List< T > & listItems()
Returns the list of items contained in this ListBox.
Definition: ListBoxI.H:121
virtual void transfer(ListBox< T > &a_src, const Box &a_srcBox, const Box &a_destBox, const int a_srcComp=0, const int a_destComp=0, const int a_numComp=1)
Definition: ListBoxI.H:279
virtual void addItems(const List< T > &a_list)
Definition: ListBoxI.H:235
Definition: ListBox.H:31
Box m_box
The Box that defines the valid region of this ListBox.
Definition: ListBox.H:175
IntVect size() const
size functions
Definition: Box.H:1819
IntVect size() const
as in BaseFab; needed for loop-unroll macro
Definition: ListBox.H:163
RealVect m_origin
The center of our coordinate system. Used for binning our items.
Definition: ListBox.H:184
virtual void linearOut(void *a_buf, const Box &a_box, const Interval &a_comps=Interval()) const
Write a serialized (packed) representation into a_buf.
Definition: ListBoxI.H:371
static int preAllocatable()
Lists are not pre-allocatable. This function is needed so that ListBox.
Definition: ListBox.H:160
virtual void define(const Box &a_box, const RealVect &a_meshSpacing, const RealVect &a_origin)
Same as the constructor.
Definition: ListBoxI.H:55
virtual ~ListBox()
Destructor.
Definition: ListBoxI.H:49
virtual void undefine()
Free the memory associated with this ListBox.
Definition: ListBoxI.H:99
Structure for passing component ranges in code.
Definition: Interval.H:23
A Doubly-Linked List Class.
Definition: List.H:21
A Virtual Base Class for Dynamic Memory Managemen.
Definition: Arena.H:40
virtual void getInvalid(List< T > &a_list, const Box &a_valid) const
Definition: ListBoxI.H:189
virtual void getItemsDestructive(List< T > &a_list, const Box &a_valid)
Definition: ListBoxI.H:159
ListBox()
Null constructor.
Definition: ListBoxI.H:27
virtual void getItems(List< T > &a_list, const Box &a_valid) const
Definition: ListBoxI.H:137
ListBox< T > & operator=(const ListBox< T > &)
virtual void clear()
Delete all items in this ListBox and reset it to the null Box.
Definition: ListBoxI.H:468
static Arena * s_Arena
Definition: ListBox.H:170
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
virtual void getInvalidDestructive(List< T > &a_list, const Box &a_valid)
Definition: ListBoxI.H:204
static std::string name()
Definition: ListBoxI.H:478
virtual size_t numItems() const
Return the number of items in this ListBox.
Definition: ListBoxI.H:314
virtual void addItem(const T &a_item)
Add a_item to this ListBox if it is contained within m_box.
Definition: ListBoxI.H:226
virtual void addItemsDestructive(List< T > &a_list)
Definition: ListBoxI.H:252
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
virtual void linearOutDestructive(void *buf, const Box &a_box, const Interval &a_comps=Interval())
Definition: ListBoxI.H:399
virtual const RealVect & meshSpacing() const
Retrieve the mesh size.
Definition: ListBoxI.H:456
virtual bool isEnclosed(const T &a_item, const Box &a_box) const
Determines whether a_item is enclosed in a_box.
Definition: ListBoxI.H:486
List< T > * m_dptr
Pointer to the List that stores our items.
Definition: ListBox.H:178
virtual void copy(const Box &a_RegionFrom, const Interval &a_Cdest, const Box &a_RegionTo, const ListBox< T > &a_src, const Interval &a_Csrc)
Definition: ListBoxI.H:300
virtual void linearIn(void *a_buf, const Box &a_box, const Interval &a_comps=Interval())
Extract a serialized (packed) representation from a_buf.
Definition: ListBoxI.H:427
const Box & box() const
Retrieve the box.
Definition: ListBoxI.H:462