Chombo + EB + MF  3.2
BinFab.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 #ifndef _BINFAB_H_
12 #define _BINFAB_H_
13 
14 #include "BaseFab.H"
15 #include "RealVect.H"
16 #include "FluxBox.H"
17 #include "List.H"
18 #include "Box.H"
19 #include "NamespaceHeader.H"
20 
21 
22 /// Base class for particle data on a \p Box
23 /** This is a class for holding and sorting particle items. Class <T>
24  must have a \p RealVect \b <T>::position() const function which is used
25  to place the item in an appropriate bin. See class \p BinItem for a base
26  class for particles. All BinFabs are assumed to have 1 component.
27 */
28 
29 template<class T>
30 class BinFab : public BaseFab<List<T> >
31 {
32 public:
33  /// Null constructor, copy constructor and operator= can be compiler defined.
34  BinFab();
35 
36  /// Constructs an empty \p BinFab on \a a_domain.
37  BinFab(const Box& a_domain,
38  const RealVect& a_mesh_spacing,
39  const RealVect& a_origin);
40 
41  /// Copy constructor
42  BinFab(const BinFab& a_binfab);
43 
44 #ifdef __IBMCPP__
45  //[NOTE: this is here only because the IBM xlC compiler tries to compile
46  // DefaultDataFactory<BinFab<BinItem>> in particleTest.cpp, even
47  // though it isn't used anywhere. Stupid compiler. <dbs> July2005]
48  BinFab(const Box& a_domain, int a_ncomps);
49 #endif
50 
51  /// Destructor
52  virtual ~BinFab();
53 
54  /// Same as the constructor
55  virtual void define(const Box& a_domain,
56  const RealVect& a_mesh_spacing,
57  const RealVect& a_origin);
58 
59  /// Sort all the items into the appropriate bins, losing items not in the FAB's domain.
60  /** This is used after "pushing" particles (i.e. updating physical positions).
61  */
62  virtual void reBin();
63 
64  /// Sort all the items into the appropriate bins and return items in (or not in) the \p Box
65  /** This is used after "pushing" particles, to find which have left the domain of the \b BinFab.
66  */
67  virtual void reBin(List<T>& a_lost, const Box & a_valid = Box(), bool a_in = true);
68 
69  /// Copy one item into the appropriate bin.
70  virtual void addItem(const T& a_item);
71 
72  /// Copy one item into the specified bin.
73  virtual void addItem(const T& a_item, const IntVect& a_bin);
74 
75  /// Copy items into the appropriate bins.
76  virtual void addItems(const List<T>& a_list);
77 
78  /// Copy items into the appropriate bins and remove them from the \p List.
79  virtual void addItemsDestructive(List<T>& a_list);
80 
81  /// Copy items into the appropriate bins. Remove items that are in (or not in) the \p Box from the \p List.
82  virtual void addItemsDestructive(List<T>& a_list, const Box& a_valid, bool a_in = true);
83 
84  /// Move particles from a \p BinFab to the overlapping cells in this one.
85  /** Performs a point-wise transfer of the whole \p List<T> in src cells
86  to the corresponding cells in *this. Notice that as a result both
87  *this and a_src are modified.
88  */
89  virtual void transfer(BinFab<T>& a_src,
90  const Box& a_srcBox,
91  const Box& a_destBox);
92 
93 //XXX //XXX testing if copy() can be overloaded to handle transfer() <dbs>
94 //XXX BinFab<T> & copy(BinFab<T>& a_src,
95 //XXX const Box& a_srcBox,
96 //XXX const Box& a_destBox);
97 //XXX
98 
99  /// Delete all the items in this \p BinFab and reset it to the null \p Box.
100  virtual void clear();
101 
102  /// Count the number of items in this \p BinFab in the specified \p Box.
103  /** The default is to do the whole FAB.
104  This is slow, so use it sparingly.
105  */
106  virtual int numItems(const Box& a_box = Box()) const;
107 
108  /// Retrieve the mesh cell size, in physical coordinates.
109  virtual RealVect meshSpacing() const;
110 
111  /// Set the mesh cell size, in physical coordinates.
112  virtual void meshSpacing(const RealVect& a_mesh_spacing) ;
113 
114  /// Retrieve the physical coordinates of the lower corner of cell zero.
115  RealVect origin() const;
116 
117  /// Set the physical coordinates of the lower corner of cell zero.
118  void origin(const RealVect& a_origin);
119 
120  // Linearization functions
121 
122  /// The number of bytes used by \b linearIn()/linearOut().
123  /** Returns the size, in number of bytes, of a flat linear
124  representation of the items in the specified \p Box.
125  */
126  virtual size_t size(const Box& a_box, const Interval& a_comps = Interval(0,0)) const;
127 
128  /// Write a serialized (packed) representation into \a a_buf.
129  /** Write a linear representation of the items in the specified \p Box.
130  Assumes that sufficient memory for the buffer has already been
131  allocated by the caller.
132  */
133  virtual void linearOut(void* a_buf, const Box& a_box,
134  const Interval& a_comps) const;
135 
136  /// Write a serialized (packed) representation into \a a_buf and remove from *this.
137  /** Write a linear representation of the items in the specified \p Box and
138  removes them from this \p BinFab. Assumes that sufficient memory for
139  the buffer has already been allocated by the caller.
140  */
141  virtual void linearOutDestructive(void* buf, const Box& a_box,
142  const Interval& a_comps = Interval(0,0));
143 
144  /// Extract a serialized (packed) representation from \a a_buf.
145  /** Given a linear representation of the class data previously made
146  using linearIn() in \a a_buf, set the data for this class on the
147  specified \p Box.
148  */
149  virtual void linearIn(void* a_buf, const Box& a_box,
150  const Interval& a_comps = Interval(0,0));
151 
152  ///
153  static int preAllocatable()
154  {
155  return 2;
156  }
157 
158  /// Should be inherited from BaseFab but it isn't, sigh; code is the same.
159  /** needed for loop-unroll macro */
160  IntVect size () const
161  {
162  return this->m_domain.size();
163  }
164 
165 protected:
166  /// location in physical space of the 0 index
168 
169  /// cell size in physical space
171 
172  /// compute the cell index containing the physical position of the item
173  inline virtual IntVect locateBin(const T& a_item) const;
174 };
175 
176 // Implementation
177 
178 #include "NamespaceFooter.H"
179 #include "BinFabImplem.H"
180 
181 #endif
virtual void addItem(const T &a_item)
Copy one item into the appropriate bin.
Definition: BinFabImplem.H:107
IntVect size() const
size functions
Definition: Box.H:1819
virtual void linearOut(void *a_buf, const Box &a_box, const Interval &a_comps) const
Write a serialized (packed) representation into a_buf.
Definition: BinFabImplem.H:470
virtual int numItems(const Box &a_box=Box()) const
Count the number of items in this BinFab in the specified Box.
Definition: BinFabImplem.H:412
IntVect size() const
Should be inherited from BaseFab but it isn&#39;t, sigh; code is the same.
Definition: BinFab.H:160
Box m_domain
Definition: BaseFab.H:632
virtual RealVect meshSpacing() const
Retrieve the mesh cell size, in physical coordinates.
Definition: BinFabImplem.H:83
virtual void reBin()
Sort all the items into the appropriate bins, losing items not in the FAB&#39;s domain.
Definition: BinFabImplem.H:259
virtual void linearIn(void *a_buf, const Box &a_box, const Interval &a_comps=Interval(0, 0))
Extract a serialized (packed) representation from a_buf.
Definition: BinFabImplem.H:527
Structure for passing component ranges in code.
Definition: Interval.H:23
A Doubly-Linked List Class.
Definition: List.H:21
RealVect origin() const
Retrieve the physical coordinates of the lower corner of cell zero.
Definition: BinFabImplem.H:98
void define()
Definition: BaseFabImplem.H:672
virtual ~BinFab()
Destructor.
Definition: BinFabImplem.H:53
virtual IntVect locateBin(const T &a_item) const
compute the cell index containing the physical position of the item
Definition: BinFabImplem.H:582
Definition: BaseFab.H:81
RealVect m_origin
location in physical space of the 0 index
Definition: BinFab.H:167
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
virtual void linearOutDestructive(void *buf, const Box &a_box, const Interval &a_comps=Interval(0, 0))
Write a serialized (packed) representation into a_buf and remove from *this.
Definition: BinFabImplem.H:501
virtual void clear()
Delete all the items in this BinFab and reset it to the null Box.
Definition: BinFabImplem.H:398
BinFab()
Null constructor, copy constructor and operator= can be compiler defined.
Definition: BinFabImplem.H:25
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
RealVect m_mesh_spacing
cell size in physical space
Definition: BinFab.H:170
static int preAllocatable()
Definition: BinFab.H:153
Base class for particle data on a Box.
Definition: BinFab.H:30
virtual void addItemsDestructive(List< T > &a_list)
Copy items into the appropriate bins and remove them from the List.
Definition: BinFabImplem.H:157
virtual void transfer(BinFab< T > &a_src, const Box &a_srcBox, const Box &a_destBox)
Move particles from a BinFab to the overlapping cells in this one.
Definition: BinFabImplem.H:369
virtual void addItems(const List< T > &a_list)
Copy items into the appropriate bins.
Definition: BinFabImplem.H:130