Chombo + EB + MF  3.2
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  */
71  DenseIntVectSet& operator&=(const Box& box);
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  Primary sorting criterion: Box::operator<() applied to m_domain.
223  Secondary sorting criterion: BitSet::operator<() applied to m_bits.
224  */
225  bool operator<(const DenseIntVectSet& a_ivs) const;
226 
227  ///
228  /**
229  turn DenseIntVectSet into a Vector of Boxes
230  */
231  Vector<Box> createBoxes() const;
232  ///
233  /**
234  set object to its minimum representation. changes data, but
235  is a logically const operation
236  */
237  void compact() const ;
238 
239  void recalcMinBox() const;
240 
241  const Box& mBox() const
242  {
243  return m_minBox;
244  }
245 
246  /** \name Linearization routines */
247  /*@{*/
248  int linearSize() const;
249 
250  void linearIn(const void* const inBuf);
251 
252  void linearOut(void* const a_outBuf) const;
253 
254  /*@}*/
255 private:
256 
257  void grow(const IntVect& iv);
258  // version without checking intersect or empty
260  bool isHighEmpty(const int a_dirS, const int a_dirE) const;
261 
266 };
267 
268 /// Iterate over all the 'true' members of a DenseIntVectSet set
269 /** This class is used by IVSIterator to implement its iterator when IntVectSet
270  * is stored as a DenseIntVectSet.
271  */
273 {
274 public:
275 
276  ///
278 
279  ///
281 
282  //default null, assignment, copy and destructor should work fine.
283 
284  ///
285  void define(const DenseIntVectSet& ivs);
286 
287  ///
288  const IntVect& operator()() const;
289 
290  ///
291  bool ok() const;
292 
293  ///
294  void operator++();
295 
296  ///
297  void begin();
298 
299  ///
300  void end();
301 
303 
304 private:
305 
306  ///
307  void thisIntVect(const int a_linearPos);
308 
309  ///
310  void setStride();
311 
317 };
318 
319 //===================================================================
320 
321 // inline functions
322 
323 inline
324 const Box& DenseIntVectSet::box() const
325 {
326  return m_domain;
327 }
328 
329 inline
331 {
332  if (m_domain.contains(intvect))
333  m_bits.setFalse(m_domain.index(intvect));
334  return *this;
335 }
336 
337 inline void DenseIntVectSet::shift(const IntVect& iv)
338 {
339  m_domain.shift(iv);
340  m_minBox.shift(iv);
341 }
342 
343 /** After default construction, ok() is false so it looks like an empty bitset
344  * but if operator++() is called, it will fail.
345  */
346 inline
348  :
349  m_ivsPtr(0),
350 // m_current(IntVect::Zero), // Leave uninitialized if empty bitset
351  m_stride(IntVect::Unit), // Avoid /0 if op++ called on empty bitset (if
352  m_prevLinearPos(-2) // defined later)
353 {
354 }
355 
356 /** Never really used. Normal construction by IntVectSet is default then
357  * define().
358  */
359 inline
361  :
362  m_iterator(ivs.m_bits), // Finds first linear position
363  m_ivsPtr(&ivs),
364 // m_current(IntVect::Zero), // Leave uninitialized if empty bitset
365  m_stride(IntVect::Unit), // Avoid /0 if op++ called on empty bitset
366  m_prevLinearPos(-2)
367 {
368  if (ok())
369  {
370  setStride();
372  }
373 }
374 
375 inline void
377 {
378  m_iterator.define(ivs.m_bits); // Finds first linear position
379  m_ivsPtr = &ivs;
380  m_prevLinearPos = -2;
381  if (ok())
382  {
383  setStride();
385  }
386 }
387 
388 inline const IntVect&
390 {
391  return m_current;
392 }
393 
394 inline bool
396 {
397  return m_iterator.ok();
398 }
399 
400 inline void
402 {
403  CH_assert(m_ivsPtr != 0); // Catch the case where op++ is used on a
404  ++m_iterator; // default construction
406 }
407 
408 inline void
410 {
411  m_iterator.begin();
412  m_prevLinearPos = -2;
413  if (ok())
414  {
416  }
417 }
418 
419 inline void
421 {
422  m_iterator.end();
423 }
424 
425 inline void
427 {
428  D_TERM6(
429  m_stride[0] = 1;,
430  m_stride[1] = std::max(1, m_stride[0]*m_ivsPtr->m_domain.size(0));,
431  m_stride[2] = std::max(1, m_stride[1]*m_ivsPtr->m_domain.size(1));,
432  m_stride[3] = std::max(1, m_stride[2]*m_ivsPtr->m_domain.size(2));,
433  m_stride[4] = std::max(1, m_stride[3]*m_ivsPtr->m_domain.size(3));,
434  m_stride[5] = std::max(1, m_stride[4]*m_ivsPtr->m_domain.size(4));)
435 }
436 
437 #include "NamespaceFooter.H"
438 #endif
Definition: BitSet.H:317
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:337
void end()
Definition: BitSet.H:461
void compact() const
bool isEmpty() const
cheaper than numPts()==0 by wide margin
void grow(int igrow)
static DenseIntVectSet emptyDenseIntVectSet
Definition: DenseIntVectSet.H:302
void makeEmptyBits()
Box m_minBox
Definition: DenseIntVectSet.H:265
IntVect size() const
size functions
Definition: Box.H:1819
void thisIntVect(const int a_linearPos)
bool operator[](const IntVect &index) const
O(1) time inquiry of containment.
#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:420
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
void begin()
Definition: BitSet.H:453
Dense representation implementation of IntVectSet class.
Definition: DenseIntVectSet.H:37
DenseIntVectSet()
Definition: DenseIntVectSet.H:41
void linearIn(const void *const inBuf)
int m_prevLinearPos
Definition: DenseIntVectSet.H:316
void recalcMinBox() const
DenseIntVectSet & intersect(const DenseIntVectSet &rhs)
const Box & mBox() const
Definition: DenseIntVectSet.H:241
DenseIntVectSet & operator-=(const Box &box)
bool contains(const IntVect &p) const
Definition: Box.H:1887
void linearOut(void *const a_outBuf) const
void define(const BitSet &a_bitset)
Definition: BitSet.H:389
bool isHighEmpty() const
IntVect m_current
Definition: DenseIntVectSet.H:314
Definition: EBInterface.H:45
void nestingRegion(int a_radius, const Box &a_domain)
bool operator==(const DenseIntVectSet &a_lhs) const
void coarsen(int iref)
DenseIntVectSet & operator|=(const IntVect &intvect)
void operator++()
Definition: DenseIntVectSet.H:401
const Box & box() const
Definition: DenseIntVectSet.H:324
const IntVect & operator()() const
Definition: DenseIntVectSet.H:389
Iterate over all the &#39;true&#39; members of a DenseIntVectSet set.
Definition: DenseIntVectSet.H:272
void begin()
Definition: DenseIntVectSet.H:409
Box m_domain
Definition: DenseIntVectSet.H:262
Vector< Box > createBoxes() const
DenseIntVectSet & operator &=(const Box &box)
IndexTM< T, N > max(const IndexTM< T, N > &a_p1, const IndexTM< T, N > &a_p2)
Definition: IndexTMI.H:401
BitSetTrueIterator m_iterator
Definition: DenseIntVectSet.H:312
Definition: BitSet.H:64
DenseIntVectSetIterator()
Definition: DenseIntVectSet.H:347
friend class DenseIntVectSetIterator
Definition: DenseIntVectSet.H:264
void setFalse(int i)
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
long index(const IntVect &v) const
Definition: Box.H:1947
const DenseIntVectSet * m_ivsPtr
Definition: DenseIntVectSet.H:313
void setStride()
Definition: DenseIntVectSet.H:426
bool contains(const Box &box) const
O(1) time inquiry of containment.
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Box & shift(int dir, int nzones)
shift functions
Definition: Box.H:2083
bool ok() const
Definition: BitSet.H:415
bool operator<(const DenseIntVectSet &a_ivs) const
void define(const DenseIntVectSet &ivs)
Definition: DenseIntVectSet.H:376
int linearSize() const
IntVect m_stride
Definition: DenseIntVectSet.H:315
BitSet m_bits
Definition: DenseIntVectSet.H:263
bool isFull() const
cheaper than numPts()==box().numPts(), by significant margin
bool ok() const
Definition: DenseIntVectSet.H:395
int numPts() const