Chombo + EB + MF  3.2
DisjointBoxLayout.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 _DISJOINTBOXLAYOUT_H_
12 #define _DISJOINTBOXLAYOUT_H_
13 
14 #include "Vector.H"
15 #include "BoxLayout.H"
16 #include "ProblemDomain.H"
17 #include "NamespaceHeader.H"
18 
19 struct SliceSpec;
20 
21 ///A BoxLayout that has a concept of disjointedness
22 /**
23  DisjointBoxLayout is-a BoxLayout that has a concept of disjointedness
24  of the boxes. DisjointBoxLayout is only different from BoxLayout in
25  that it has a method isDisjoint(). DisjointBoxLayouts also have
26  a ProblemDomain member to ensure disjointness in the case of periodic
27  boundary conditions, among other things.
28 */
29 
31 {
32 
33 public:
34 
35  friend class Copier;
36 
37  /**
38  \name Constructors, destructors, defines
39  */
40  /*@{*/
41 
42  ///
43  /**
44  Construct BoxLayout with no boxes.
45  */
47 
48  ///
49  /** Construct from a Vector of Boxes and optionally a Vector of
50  processor assignments. If the processor assignment Vector
51  is present, it must be either zero-length or the same length
52  as the Box Vector. On exit, the DisjointBoxLayout will be closed.
53  */
54  DisjointBoxLayout(const Vector<Box>& a_boxes,
55  const Vector<int>& a_procIDs);
56 
57  ///
58  /** Construct from a Vector of Boxes and optionally a Vector of
59  processor assignments. If the processor assignment Vector
60  is present, it must be either zero-length or the same length
61  as the Box Vector. On exit, the DisjointBoxLayout will be closed.
62  */
63  DisjointBoxLayout(const Vector<Box>& a_boxes,
64  const Vector<int>& a_procIDs,
65  const ProblemDomain& a_physDomain);
66 
67  ///
68  /** Construct from a LayoutData<Box>.
69  On exit, the BoxLayout will be closed.
70  */
71  DisjointBoxLayout(const LayoutData<Box>& a_newLayout);
72 
73  ///
74  /**
75  Ref-counted destruction. Once the last reference to the
76  implementation of this class is destroyed, the data members
77  are cleaned up.
78  */
79  virtual
81  {}
82 
83  // for flop counts
84  unsigned long long int numPointsThisProc() const;
85 
86  ///
87  /** Define this DisjointBoxLayout from a Vector of Boxes. This is a
88  wrapper for a call to BoxLayout::define, required because
89  DisjointBoxLayout::define is overloaded and the compiler will not
90  look into the base class for name resolution.
91  */
92  virtual void
93  define(const Vector<Box>& a_boxes,
94  const Vector<int>& a_procIDs);
95 
96  ///
97  /**
98  Like the define() that takes the same two arguments, except this one
99  also initializes a_procIDs if it's not NULL. In that case, the passed-in
100  a_procIDs should point to a Vector of size 0.
101  */
102  void
103  defineAndLoadBalance(const Vector<Box>& a_boxes,
104  Vector<int>* a_procIDs);
105 
106  ///
107  /**
108  Like the define() that takes the same two arguments, except this one
109  also initializes a_procIDs if it's not NULL. In that case, the passed-in
110  a_procIDs should point to a Vector of size 0.
111  */
112  void
113  defineAndLoadBalance(const Vector<Box>& a_boxes,
114  Vector<int>* a_procIDs,
115  const ProblemDomain& a_physDomain);
116 
117  ///
118  /** Shallow define. Only way to promote a BoxLayout. If BoxLayout
119  has been closed, then this method checks isDisjoint and throws an
120  error if not disjoint. If <i>a_layout</i> is disjoint, then this object
121  becomes a closed DisjointBoxLayout object.
122  */
123  virtual void
124  define(const BoxLayout& a_layout);
125 
126  ///
127  /** Shallow define. Only way to promote a BoxLayout. If BoxLayout
128  has been closed, then this method checks isDisjoint and throws an
129  error if not disjoint. If <i>a_layout</i> is disjoint, then this object
130  becomes a closed DisjointBoxLayout object. If BoxLayout has been closed,
131  and is sorted, the neighbour iterator is rebuilt (now with knowledge of
132  the problem domain).
133  */
134  virtual void
135  define(const BoxLayout& a_layout, const ProblemDomain& a_physDomain);
136 
137  ///
138  /** Define this DisjointBoxLayout from a Vector of Boxes. This is a
139  wrapper for a call to BoxLayout::define, required because
140  DisjointBoxLayout::define is overloaded and the compiler will not
141  look into the base class for name resolution.
142  */
143  virtual void
144  define(const Vector<Box>& a_boxes,
145  const Vector<int>& a_procIDs,
146  const ProblemDomain& a_physDomain);
147 
148  ///
149  /** Define this DisjointBoxLayout from a Vector of Boxes.
150  Same as define.
151  */
152  virtual void
153  define_pd(const Vector<Box>& a_boxes,
154  const Vector<int>& a_procIDs,
155  const ProblemDomain& a_physDomain)
156  {define(a_boxes, a_procIDs, a_physDomain);}
157 
158  /*@}*/
159 
160  /**
161  \name Checks
162  */
163  /*@{*/
164 
165  ///
166  /** Returns <tt>true</tt> if this object contains a disjoint
167  union of Boxes.
168 
169  The Disjoint testing algorithm assumes that the
170  boxes are CELL-Centered boxes. We can expand the algorithm
171  when someone needs it. bvs
172  */
173  bool
174  isDisjoint() const;
175 
176  ///
177  /** Checks to see that problem domains are compatible.
178  To be compatible:
179  - <i>a_domain</i> and the ProblemDomain in
180  this DisjointBoxLayout must have the same periodicity.
181  - The ProblemDomains must be periodic in the same dimensions.
182  - In all periodic directions, the period must be the same.
183 
184  There are no checks in non-periodic directions, since
185  DisjointBoxLayouts don't care about physical domains
186  except in the periodic case.
187  */
188  bool checkPeriodic(const ProblemDomain& a_domain) const;
189 
190  /** Performs problem domain check when we don't have direct
191  access to a problemDomain.
192 
193  Returns <tt>true</tt> if this and <i>a_dbl</i>
194  have compatible ProblemDomains.
195  */
196  bool checkDomains(const DisjointBoxLayout& a_dbl) const;
197 
198  /*@}*/
199 
200  /**
201  \name Modification functions
202  */
203  /*@{*/
204 
205  ///
206  /** Mark this DisjointBoxLayout as complete and unchangeable.
207  */
208  virtual void
209  close();
210 
211  ///
212  /** Set ProblemDomain. Useful when using addBox() and trying to use closeNoSort()
213  */
214  void setDomain(const ProblemDomain& a_domain)
215  {
216  //if (*m_closed)
217  // {
218  // MayDay::Error("attempt to setDomain on closed DisjointBoxLayout");
219  // }
220  m_physDomain = a_domain;
221  }
222 
223  ///
224  /** Create new open DisjointBoxLayout with copied data.
225 
226  Doesn't check for disjointness, since <i>a_source</i> is already
227  guaranteed to be disjoint. Also copies problem domain
228  info. */
229  virtual void
230  deepCopy(const DisjointBoxLayout& a_source);
231 
232  ///
233  /** Create new open DisjointBoxLayout with copied data.
234 
235  Checks that the source BoxLayout isDisjoint, throws an error
236  if it is not. Otherwise, same as BoxLayout::deepCopy. */
237  virtual void
238  deepCopy(const BoxLayout& a_source);
239 
240  ///
241  /** Create new open DisjointBoxLayout with copied data.
242 
243  Checks that the source BoxLayout isDisjoint, throws an error
244  if it is not. Otherwise, same as BoxLayout::deepCopy. */
245  virtual void
246  deepCopy(const BoxLayout& a_source, const ProblemDomain& a_physDomain);
247 
248  /**
249  Makes a_to a one-cell-thick version of *this -- sliced at a_ss.position
250  along the a_ss.direction'th axis.
251  If a_ss.position is outside the range of *this, that's a fatal error.
252  If a_maintainProcAssign = true, maintain processor assignments in the
253  process (even if it breaks load balancing)
254  */
255  void degenerate( DisjointBoxLayout& a_to, const SliceSpec& a_ss,
256  bool a_maintainProcAssign = false) const;
257 
258  ///
259  /**
260 
261  Coarsen a DisjointBoxLayout:
262  - <i>output</i> must be open
263  - <i>input</i> must be closed
264  - <i>refinement</i> must be a positive non-zero integer
265  - <i>output</i> and <i>input</i> do not share an
266  implementation.
267 
268  <i>output</i> is first deepCopy'ed from <i>input</i>,
269  then coarsen(refinement) is called on each box of <i>output</i>.
270 
271  <i>output</i> returns from this function closed.
272 
273  LayoutIterators and DataIterators from <i>input</i> and <i>output</i>
274  can be used interchangeably.
275  */
276  friend void coarsen(DisjointBoxLayout& output,
277  const DisjointBoxLayout& input,
278  int refinement);
279 
280  ///
281  /**
282  Refine a DisjointBoxLayout:
283  - <i>output</i> must be open
284  - <i>input</i> must be closed
285  - <i>refinement</i> must be a positive non-zero integer
286  - <i>output</i> and <i>input</i> do not share an
287  implementation.
288 
289  <i>output</i> is first deepCopy'ed from <i>input</i>,
290  then refine(refinement) is called on each box of <i>output</i>.
291 
292  <i>output</i> returns from this function closed.
293 
294  LayoutIterators and DataIterators from <i>input</i> and <i>output</i>
295  can be used interchangeably.
296  */
297  friend void refine(DisjointBoxLayout& output,
298  const DisjointBoxLayout& input,
299  int refinement);
300 
301  /*@}*/
302 
303  /**
304  \name Neighbor functions
305  */
306  /*@{*/
307 
308  ///
309  /** Returns the set of boxes which you get from calling Box::adjCellLo
310  on each box in input. Output must be open, is closed upon exit from
311  this function. A negative length results in the set of boxes
312  of width a_len on the low side of, but _inside_ the original boxes.
313  */
314  friend void adjCellLo(DisjointBoxLayout& a_output,
315  const DisjointBoxLayout& a_input,
316  int a_dir, int a_len);
317 
318  ///
319  /** Returns the set of boxes which result from calling Box::adjCellHi
320  on each box in input. Output must be open, will be closed upon
321  exiting this function. A negative length results in the set of boxes
322  of width a_len on the low side of, but _inside_ the original boxes.
323  */
324  friend void adjCellHi(DisjointBoxLayout& a_output,
325  const DisjointBoxLayout& a_input,
326  int a_dir, int a_len);
327 
328  /*@}*/
329 
330  const ProblemDomain& physDomain() const;
331 
332  virtual void closeNoSort(); // close without sorting; used by AdjCellHi, etc.
333 
334 protected:
335  ///
336  friend class NeighborIterator;
338 
339  // The "pair" here : the first int is the index of the periodic shift iterator, the second unsigned int is
340  // the box index. an unshifted box is stored with a -1 shift index.
342 
343  void computeNeighbors();
344  virtual void closeN( RefCountedPtr<Vector<Vector<std::pair<int, LayoutIndex> > > > neighbors);
345  virtual void closeNO(); // close, but don't bother building neighbors
346 
347 };
348 void adjCellLo_dbl(DisjointBoxLayout& a_output,
349  const DisjointBoxLayout& a_input,
350  int a_dir, int a_len);
351 void adjCellHi_dbl(DisjointBoxLayout& a_output,
352  const DisjointBoxLayout& a_input,
353  int a_dir, int a_len);
354 void coarsen_dbl(DisjointBoxLayout& output,
355  const DisjointBoxLayout& input,
356  int refinement);
357 void refine_dbl(DisjointBoxLayout& output,
358  const DisjointBoxLayout& input,
359  int refinement);
360 
361 inline
363  const DisjointBoxLayout& a_input,
364  int a_dir, int a_len)
365 {
366  adjCellLo(a_output,a_input,a_dir,a_len);
367 }
368 inline
370  const DisjointBoxLayout& a_input,
371  int a_dir, int a_len)
372 {
373  adjCellHi(a_output,a_input,a_dir,a_len);
374 }
375 inline
377  const DisjointBoxLayout& input,
378  int refinement)
379 {
380  coarsen(output, input, refinement);
381 }
382 inline
384  const DisjointBoxLayout& input,
385  int refinement)
386 {
387  refine(output, input, refinement);
388 }
389 
390 ///
391 /** Returns the set of boxes which you get from calling Box::adjCellLo
392  on each box in input. Output must be open, is closed upon exit from
393  this function. A negative length results in the set of boxes
394  of width a_len on the low side of, but _inside_ the original boxes.
395  */
396 void adjCellLo(DisjointBoxLayout& a_output,
397  const DisjointBoxLayout& a_input,
398  int a_dir, int a_len=1);
399 
400 ///
401 /** Returns the set of boxes which result from calling Box::adjCellHi
402  on each box in input. Output must be open, will be closed upon
403  exiting this function. A negative length results in the set of boxes
404  of width a_len on the low side of, but _inside_ the original boxes.
405  */
406 void adjCellHi(DisjointBoxLayout& a_output,
407  const DisjointBoxLayout& a_input,
408  int a_dir, int a_len=1);
409 
410  /*@}*/
411 
412 #include "NamespaceFooter.H"
413 #endif
bool checkDomains(const DisjointBoxLayout &a_dbl) const
virtual void closeN(RefCountedPtr< Vector< Vector< std::pair< int, LayoutIndex > > > > neighbors)
bool isDisjoint() const
void adjCellHi_dbl(DisjointBoxLayout &a_output, const DisjointBoxLayout &a_input, int a_dir, int a_len)
Definition: DisjointBoxLayout.H:369
A reference-counting handle class.
Definition: RefCountedPtr.H:173
Box refine(const Box &b, const IntVect &refinement_ratio)
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
friend void adjCellLo(DisjointBoxLayout &a_output, const DisjointBoxLayout &a_input, int a_dir, int a_len)
friend void adjCellHi(DisjointBoxLayout &a_output, const DisjointBoxLayout &a_input, int a_dir, int a_len)
virtual void closeNoSort()
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:145
Data that maintains a one-to-one mapping of T to the boxes in a BoxLayout.
Definition: BoxLayout.H:26
A strange but true thing to make copying from one boxlayoutdata to another fast.
Definition: Copier.H:152
void defineAndLoadBalance(const Vector< Box > &a_boxes, Vector< int > *a_procIDs)
Definition: SliceSpec.H:41
void adjCellLo_dbl(DisjointBoxLayout &a_output, const DisjointBoxLayout &a_input, int a_dir, int a_len)
Definition: DisjointBoxLayout.H:362
virtual void define_pd(const Vector< Box > &a_boxes, const Vector< int > &a_procIDs, const ProblemDomain &a_physDomain)
Definition: DisjointBoxLayout.H:153
const ProblemDomain & physDomain() const
void setDomain(const ProblemDomain &a_domain)
Definition: DisjointBoxLayout.H:214
void coarsen_dbl(DisjointBoxLayout &output, const DisjointBoxLayout &input, int refinement)
Definition: DisjointBoxLayout.H:376
virtual void closeNO()
void adjCellHi(DisjointBoxLayout &a_output, const DisjointBoxLayout &a_input, int a_dir, int a_len=1)
virtual void deepCopy(const DisjointBoxLayout &a_source)
IndexTM< T, N > coarsen(const IndexTM< T, N > &a_p, T a_s)
Definition: IndexTMI.H:430
virtual void close()
ProblemDomain m_physDomain
Definition: DisjointBoxLayout.H:337
void adjCellLo(DisjointBoxLayout &a_output, const DisjointBoxLayout &a_input, int a_dir, int a_len=1)
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:30
virtual ~DisjointBoxLayout()
Definition: DisjointBoxLayout.H:80
friend void coarsen(DisjointBoxLayout &output, const DisjointBoxLayout &input, int refinement)
RefCountedPtr< Vector< Vector< std::pair< int, LayoutIndex > > > > m_neighbors
Definition: DisjointBoxLayout.H:341
void refine_dbl(DisjointBoxLayout &output, const DisjointBoxLayout &input, int refinement)
Definition: DisjointBoxLayout.H:383
bool checkPeriodic(const ProblemDomain &a_domain) const
void degenerate(DisjointBoxLayout &a_to, const SliceSpec &a_ss, bool a_maintainProcAssign=false) const
unsigned long long int numPointsThisProc() const
virtual void define(const Vector< Box > &a_boxes, const Vector< int > &a_procIDs)
An Iterator based on a DisjointBoxLayout object for neighboring boxes.
Definition: NeighborIterator.H:23
friend void refine(DisjointBoxLayout &output, const DisjointBoxLayout &input, int refinement)