Chombo + EB  3.0
DenseIntVectSet.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 _DENSEINTVECTSET_H_
12 #define _DENSEINTVECTSET_H_
13 
14 #include "BitSet.H"
15 #include "IntVect.H"
16 #include "Box.H"
17 #include "Vector.H"
18 #include "ProblemDomain.H"
19 #include "NamespaceHeader.H"
20 
21 class ProblemDomain;
23 /// Dense representation implementation of IntVectSet class
24 
25 /** Performance-oriented class that reproduces most of the
26  functionality of IntVectSet. This object stores a dense
27  representation of an IntVectSet over the box of definition
28 
29  Storage is performed with a BitSet. This stores 0 or 1 on
30  a per-bit basis for each location in the IntVectSet.
31 
32  For an explanation of undocumented functions look at IntVectSet
33 
34 @see IntVectSet
35 
36 */
38 {
39 public:
40  ///
42  {}
43 
44  ///
45  /** you can either have the domain begin all true, or all false */
46  DenseIntVectSet(const Box& a_domain, bool init = true);
47  // copy, and operator= should be fine
48 
49  ///
50  /**
51  make this set the complement of itself and the input
52  */
54 
55  ///
56  /**
57  make this set the complement of itself and the input
58  */
59  DenseIntVectSet& operator-=(const IntVect& intvect);
60 
61  ///
62  /**
63  make this set the complement of itself and the input
64  */
66 
67  ///
68  /**
69  make this set the intersection of itself and the input
70  */
72 
73  ///
74  /**
75  make this set the intersection of itself and the input
76  */
78 
79  ///
80  /**
81  make this set the union of itself and the input. intvect MUST
82  be within the domain of of the DenseIntVectSet or this will throw
83  an error
84  */
85  DenseIntVectSet& operator|=(const IntVect& intvect);
86 
87  ///
88  /**
89  make this set the union of itself and the input. b MUST
90  be within the domain of of the DenseIntVectSet or this will throw
91  an error
92  */
93  DenseIntVectSet& operator|=(const Box& b);
94 
95  ///
96  /**
97  make this set the union of itself and the input. resulting
98  DenseIntVectSet has domain of the minBox holding both oeprator
99  and operand
100  */
102 
103  ///
104  /**
105  make this set the intersection of itself and the input
106  */
108 
109  ///Shift every cell in the set by the input. Fast
110  /**
111  Shift every cell in the set by the input.
112  */
113  void shift(const IntVect& iv);
114 
115  /// O(1) time inquiry of containment
116  /* slower, constant time pointwise access.
117  You should not build a BoxIterator, then access this
118  method if you intend to iterate over the objects true
119  or false terms. you should build a DenseIntVectSetIterator */
120  bool operator[](const IntVect& index) const;
121 
122  /// O(1) time inquiry of containment
123  /** returns 'true' if the entire set of points specified
124  by the box 'b' is a member of the IntvectSet */
125  bool contains(const Box& box) const;
126 
127  ///
128  /**
129  coarsen the set by the input
130  */
131  void coarsen(int iref);
132 
133  ///
134  /**
135  refine the set by the input
136  */
137  void refine(int iref);
138 
139  ///
140  /**
141  grow the set by the input
142  */
143  void grow(int igrow);
144 
145  ///
146  /**
147  grow the set by the input
148  */
149  void grow(int idir, int igrow);
150 
151  ///
152  /**
153  @see IntVectSet::growHi
154  */
155  void growHi();
156 
157  ///
158  /**
159  @see IntVectSet::growHi(int)
160  */
161  void growHi(const int a_dir);
162 
163  ///
164  /**
165  Make empty by setting all bits to false
166  */
167  void makeEmptyBits();
168 
169  ///
170  /** Chop the DenseIntVectSet at the chop_pnt in the dir direction
171  Returns one DenseIntVectSet and modifies the object DenseIntVectSet.
172  The union of the two is the original IntVectSet.
173  The modified DenseIntVectSet is the low end, the returned DenseIntvectSet
174  is the high end. @see IntVectSet::chop */
175  DenseIntVectSet chop(int dir, int chop_pnt);
176 
177  inline const Box& box() const;
178 
179  ///
180  /** @see IntVectSet::nestingRegion
181  */
182  void nestingRegion(int a_radius, const Box& a_domain);
183 
184  ///
185 
186  void nestingRegion(int a_radius, const ProblemDomain& a_domain);
187 
188  ///cheaper than numPts()==0 by wide margin
189  /**
190  return true if the set has no points
191  */
192  bool isEmpty() const; //cheaper than numPts by wide margin
193 
194  ///cheaper than numPts()==box().numPts(), by significant margin
195  /**
196  return true if the set consists of a set of a full box
197  */
198  bool isFull() const; // cheaper than numPts, bu significant margin
199 
200  ///
201  /**
202  Return true if all bits on the high hyperfaces are zero
203  */
204  bool isHighEmpty() const;
205 
206  ///
207  /**
208  Return true if all bits on the high hyperface are zero
209  */
210  bool isHighEmpty(const int a_dir) const;
211 
212  ///
213  /**
214  return the number of points in the set
215  */
216  int numPts() const;
217 
218  ///
219  bool operator==(const DenseIntVectSet& a_lhs) const;
220 
221 
222  /**
223  Primary sorting criterion: Box::operator<() applied to m_domain.
224  Secondary sorting criterion: BitSet::operator<() applied to m_bits.
225  */
226  bool operator<(const DenseIntVectSet& a_ivs) const;
227 
228  ///
229  /**
230  turn DenseIntVectSet into a Vector of Boxes
231  */
232  Vector<Box> createBoxes() const;
233  ///
234  /**
235  set object to its minimum representation. changes data, but
236  is a logically const operation
237  */
238  void compact() const ;
239 
240  void recalcMinBox() const;
241 
242  const Box& mBox() const
243  {
244  return m_minBox;
245  }
246 
247  /** \name Linearization routines */
248  /*@{*/
249  int linearSize() const;
250 
251  void linearIn(const void* const inBuf);
252 
253  void linearOut(void* const a_outBuf) const;
254 
255  /*@}*/
256 private:
257 
258  void grow(const IntVect& iv);
259  // version without checking intersect or empty
261  bool isHighEmpty(const int a_dirS, const int a_dirE) const;
262 
267 };
268 
269 /// Iterate over all the 'true' members of a DenseIntVectSet set
270 /** This class is used by IVSIterator to implement its iterator when IntVectSet
271  * is stored as a DenseIntVectSet.
272  */
274 {
275 public:
276 
277  ///
279 
280  ///
282 
283  //default null, assignment, copy and destructor should work fine.
284 
285  ///
286  void define(const DenseIntVectSet& ivs);
287 
288  ///
289  const IntVect& operator()() const;
290 
291  ///
292  bool ok() const;
293 
294  ///
295  void operator++();
296 
297  ///
298  void begin();
299 
300  ///
301  void end();
302 
304 
305 private:
306 
307  ///
308  void thisIntVect(const int a_linearPos);
309 
310  ///
311  void setStride();
312 
318 };
319 
320 //===================================================================
321 
322 // inline functions
323 
324 inline
325 const Box& DenseIntVectSet::box() const
326 {
327  return m_domain;
328 }
329 
330 inline
332 {
333  if (m_domain.contains(intvect))
334  m_bits.setFalse(m_domain.index(intvect));
335  return *this;
336 }
337 
338 inline void DenseIntVectSet::shift(const IntVect& iv)
339 {
340  m_domain.shift(iv);
341  m_minBox.shift(iv);
342 }
343 
344 /** After default construction, ok() is false so it looks like an empty bitset
345  * but if operator++() is called, it will fail.
346  */
347 inline
349  :
350  m_ivsPtr(0),
351 // m_current(IntVect::Zero), // Leave uninitialized if empty bitset
352  m_stride(IntVect::Unit), // Avoid /0 if op++ called on empty bitset (if
353  m_prevLinearPos(-2) // defined later)
354 {
355 }
356 
357 /** Never really used. Normal construction by IntVectSet is default then
358  * define().
359  */
360 inline
362  :
363  m_iterator(ivs.m_bits), // Finds first linear position
364  m_ivsPtr(&ivs),
365 // m_current(IntVect::Zero), // Leave uninitialized if empty bitset
366  m_stride(IntVect::Unit), // Avoid /0 if op++ called on empty bitset
367  m_prevLinearPos(-2)
368 {
369  if (ok())
370  {
371  setStride();
373  }
374 }
375 
376 inline void
378 {
379  m_iterator.define(ivs.m_bits); // Finds first linear position
380  m_ivsPtr = &ivs;
381  m_prevLinearPos = -2;
382  if (ok())
383  {
384  setStride();
386  }
387 }
388 
389 inline const IntVect&
391 {
392  return m_current;
393 }
394 
395 inline bool
397 {
398  return m_iterator.ok();
399 }
400 
401 inline void
403 {
404  CH_assert(m_ivsPtr != 0); // Catch the case where op++ is used on a
405  ++m_iterator; // default construction
407 }
408 
409 inline void
411 {
412  m_iterator.begin();
413  m_prevLinearPos = -2;
414  if (ok())
415  {
417  }
418 }
419 
420 inline void
422 {
423  m_iterator.end();
424 }
425 
426 inline void
428 {
429  D_TERM6(
430  m_stride[0] = 1;,
431  m_stride[1] = std::max(1, m_stride[0]*m_ivsPtr->m_domain.size(0));,
432  m_stride[2] = std::max(1, m_stride[1]*m_ivsPtr->m_domain.size(1));,
433  m_stride[3] = std::max(1, m_stride[2]*m_ivsPtr->m_domain.size(2));,
434  m_stride[4] = std::max(1, m_stride[3]*m_ivsPtr->m_domain.size(3));,
435  m_stride[5] = std::max(1, m_stride[4]*m_ivsPtr->m_domain.size(4));)
436 }
437 
438 #include "NamespaceFooter.H"
439 #endif
Definition: BitSet.H:317
void recalcMinBox() const
DenseIntVectSet chop(int dir, int chop_pnt)
void refine(int iref)
void shift(const IntVect &iv)
Shift every cell in the set by the input. Fast.
Definition: DenseIntVectSet.H:338
void end()
Definition: BitSet.H:461
void grow(int igrow)
static DenseIntVectSet emptyDenseIntVectSet
Definition: DenseIntVectSet.H:303
void makeEmptyBits()
Box m_minBox
Definition: DenseIntVectSet.H:266
void thisIntVect(const int a_linearPos)
#define D_TERM6(a, b, c, d, e, f)
Definition: CHArray.H:40
#define CH_assert(cond)
Definition: CHArray.H:37
void end()
Definition: DenseIntVectSet.H:421
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:130
void begin()
Definition: BitSet.H:453
bool operator<(const DenseIntVectSet &a_ivs) const
Dense representation implementation of IntVectSet class.
Definition: DenseIntVectSet.H:37
DenseIntVectSet & operator&=(const Box &box)
DenseIntVectSet()
Definition: DenseIntVectSet.H:41
void linearIn(const void *const inBuf)
int m_prevLinearPos
Definition: DenseIntVectSet.H:317
void linearOut(void *const a_outBuf) const
DenseIntVectSet & intersect(const DenseIntVectSet &rhs)
bool ok() const
Definition: BitSet.H:415
IntVect size() const
size functions
Definition: Box.H:1814
DenseIntVectSet & operator-=(const Box &box)
void define(const BitSet &a_bitset)
Definition: BitSet.H:389
bool operator[](const IntVect &index) const
O(1) time inquiry of containment.
IntVect m_current
Definition: DenseIntVectSet.H:315
void compact() const
Definition: EBInterface.H:45
void nestingRegion(int a_radius, const Box &a_domain)
void coarsen(int iref)
DenseIntVectSet & operator|=(const IntVect &intvect)
void operator++()
Definition: DenseIntVectSet.H:402
bool contains(const Box &box) const
O(1) time inquiry of containment.
Iterate over all the 'true' members of a DenseIntVectSet set.
Definition: DenseIntVectSet.H:273
long index(const IntVect &v) const
Definition: Box.H:1954
bool ok() const
Definition: DenseIntVectSet.H:396
void begin()
Definition: DenseIntVectSet.H:410
Box m_domain
Definition: DenseIntVectSet.H:263
IndexTM< T, N > max(const IndexTM< T, N > &a_p1, const IndexTM< T, N > &a_p2)
Definition: IndexTMI.H:403
BitSetTrueIterator m_iterator
Definition: DenseIntVectSet.H:313
bool operator==(const DenseIntVectSet &a_lhs) const
Definition: BitSet.H:64
DenseIntVectSetIterator()
Definition: DenseIntVectSet.H:348
void setFalse(int i)
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
bool isHighEmpty() const
Vector< Box > createBoxes() const
bool contains(const IntVect &p) const
Definition: Box.H:1888
const DenseIntVectSet * m_ivsPtr
Definition: DenseIntVectSet.H:314
void setStride()
Definition: DenseIntVectSet.H:427
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Box & shift(int dir, int nzones)
shift functions
Definition: Box.H:2088
int linearSize() const
void define(const DenseIntVectSet &ivs)
Definition: DenseIntVectSet.H:377
int numPts() const
const Box & mBox() const
Definition: DenseIntVectSet.H:242
const IntVect & operator()() const
Definition: DenseIntVectSet.H:390
IntVect m_stride
Definition: DenseIntVectSet.H:316
BitSet m_bits
Definition: DenseIntVectSet.H:264
const Box & box() const
Definition: DenseIntVectSet.H:325
bool isFull() const
cheaper than numPts()==box().numPts(), by significant margin
bool isEmpty() const
cheaper than numPts()==0 by wide margin