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