Chombo + EB  3.2
FluxBox.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 _FLUXBOX_H_
12 #define _FLUXBOX_H_
13 
14 #include "Box.H"
15 #include "Vector.H"
16 #include "FArrayBox.H"
17 #include "NamespaceHeader.H"
18 
19 /// A FArrayBox-like container for face-centered fluxes
20 /** This is a class to contain face-centered fluxes on a box.
21  */
22 class FluxBox
23 {
24 
25 public:
26  /// Default constructor
27  FluxBox();
28 
29  /// Constructs FluxBox on cell-centered box with n components
30  FluxBox(const Box& bx, int n=1);
31 
32  /// Constructs FluxBox aliasing SpaceDim memory pointers for the FArrayBox
33  FluxBox(const Box& a_bx, const int a_nComp, D_DECL6(Real *const a_alias0,
34  Real *const a_alias1,
35  Real *const a_alias2,
36  Real *const a_alias3,
37  Real *const a_alias4,
38  Real *const a_alias5));
39 
40 
41  /// aliasing constructor
42  /** This behaves like the BaseFab(Interval, BaseFab) constructor, by creating
43  aliased versions of each FArrayBox
44  */
45  FluxBox(const Interval& a_comps, FluxBox& a_original);
46 
47  /// Destructor
48  ~FluxBox();
49 
50  /// Resize FluxBox similar to BaseFab::resize()
51  //void resize(const Box& bx, int n=1);
52 
53  /// Define function
54  void define(const Box& bx, int n=1);
55 
56  void define(const FluxBox& a_fb)
57  {
58  define(a_fb.box(), a_fb.nComp());
59  }
60 
61  /// Returns the FluxBox to the undefined state
62  void clear();
63 
64  // access functions
65 
66  /// Number of components
67  int nComp() const;
68 
69  /// Returns cell-centered box which defines fluxBox
70  const Box& box() const;
71 
72  /// Returns face-centered flux in direction \em dir
73  FArrayBox& getFlux(const int dir);
74 
75  /// Returns const reference to face-centered flux in direction \em dir
76  const FArrayBox& getFlux(const int dir) const;
77 
78  /// Returns FArrayBox in direction dir
79  FArrayBox& operator[] (const int dir);
80 
81  /// Constant version
82  const FArrayBox& operator[] (const int dir) const;
83 
84  // data modification functions
85 
86  /// Set all fluxes to val
87  void setVal(const Real val);
88 
89  /// Set fluxes in direction dir to val
90  void setVal(const Real val, const int dir);
91 
92  /// More specific setVal
93  void setVal(const Real val, const int dir, const int startComp,
94  const int nComp);
95 
96  /// Sets fluxes on faces surrounding cell-centered box bx
97  void setVal(const Real val, const Box& bx);
98 
99  /// Most specific setVal
100  /**
101  Sets fluxes on faces surrounding cell-centered box bx
102  */
103  void setVal(const Real val, const Box& bx, const int dir,
104  const int startComp, const int nComp);
105 
106  /// Copy from src to this FluxBox -- sizes must be identical
107  void copy(const FluxBox& src);
108 
109  /// Copy on overlap, for all directions
110  void copy(const FluxBox& src, const int srcComp,
111  const int destComp, const int numComp);
112 
113  /// Copy on overlap of FluxBoxes, in direction dir
114  void copy(const FluxBox& src, const int dir, const int srcComp,
115  const int destComp, const int numComp);
116 
117  /**
118  Modifies this FluxBox by copying the contents of the argument src
119  into it. A copy within the intersecting region of the domains of the
120  two FluxBoxes and the specified Box a_destbox is performed. All
121  components are copied.
122  */
123  void copy(const FluxBox& a_src,
124  const Box& a_destbox);
125 
126  /// Copies from a subsection of one box into another.
127  /**
128  Assumes the boxes are both in the same index space, and that
129  box R is completely contained in both the src and destination
130  boxes. This function required by BoxLayoutData
131  */
132  void copy(const Box& R, const Interval& Cdest, const FluxBox& src,
133  const Interval& Csrc);
134 
135  /// Modifies this FluxBox by copying the contents of \em src into it.
136  /**
137  This, the most general form
138  of copy, specifies the contents of any sub-box srcbox
139  in `FluxBox' src may be copied into a (possibly
140  different) destbox in the destination `FluxBox'. Note
141  that although the srcbox and the destbox may be
142  disjoint, they must be the same size and shape. If the
143  sizes differ, the copy is undefined and a runtime error
144  results. This copy function is the only one of the
145  copy functions to allow a copy between differing
146  boxes. The user also specifies how many components are
147  copied, starting at component srccomp in src and stored
148  starting at component destcomp. The results are
149  UNDEFINED if the src and dest FluxBoxes are the same and
150  the srcbox and destbox overlap.
151  */
152  void copy (const Box& srcbox,
153  const Interval& destcomps,
154  const Box& destbox,
155  const FluxBox& src,
156  const Interval& srccomps);
157 
158  /// Modifies this FluxBox to its additive inverse.
159  /**
160  Modifies this FluxBox by replacing each value with its additive
161  inverse, for the given range of components and within the given subbox.
162  Returns *this.
163  */
164  FluxBox& negate (const Box& subbox,
165  int comp=0,
166  int numcomp=1);
167 
168  /// Modifies this FluxBox to its additive inverse.
169  /**
170  Modifies this FluxBox by replacing each value with its additive
171  inverse, for the given range of components over the whole domain of
172  the FluxBox. Returns *this.
173  */
174  FluxBox& negate (int comp,
175  int numcomp=1);
176 
177  /// Modifies this FluxBox to its additive inverse.
178  /**
179  Modifies this FluxBox by replacing each value with its additive
180  inverse for all components over the whole domain of the FluxBox.
181  Returns *this.
182  */
183  FluxBox& negate ();
184 
185  /// Modifies this FluxBox by adding src in the CELL-CENTERED sub-box
186  /**
187  Modifies this FluxBox by pointwise addition of values in the argument
188  FluxBox. Adds src's components (a_srccomp : a_srccomp+a_numcomp-1)
189  to this FluxBox's components (a_destcomp : a_destcomp+numcomp-1)
190  where the domain of this FluxBox intersects the a_subbox. The actual
191  directionally-dependent subbox is a_subbox.surroundingNodes(dir);
192  NOTE:
193  a_subbox must be contained in the cell-centered Box of this FluxBox.
194  Returns *this
195  */
196  FluxBox& plus(const FluxBox& a_src,
197  const Box& a_subbox,
198  int a_srccomp,
199  int a_destcomp,
200  int a_numcomp = 1);
201 
202  // plus operator with calling sequence similar to matching copy (for use in additive exchange operations)
203  void plus (const Box& srcbox,
204  const Interval& destcomps,
205  const Box& destbox,
206  const FluxBox& src,
207  const Interval& srccomps);
208 
209 
210 
211  /// Modifies this FluxBox by subtracting src in the CELL-CENTERED sub-box
212  /**
213  Modifies this FluxBox by pointwise addition of values in the argument
214  FArrayBox. Subtracts src's components (a_srccomp : a_srccomp+a_numcomp-1)
215  from this FluxBox's components (a_destcomp : a_destcomp+numcomp-1)
216  where the domain of this FluxBox intersects the a_subbox. The actual
217  directionally-dependent subbox is a_subbox.surroundingNodes(dir);
218  NOTE:
219  a_subbox must be contained in the cell-centered Box of this FluxBox.
220  Returns *this
221  */
222  FluxBox& minus(const FluxBox& a_src,
223  const Box& a_subbox,
224  int a_srccomp,
225  int a_destcomp,
226  int a_numcomp = 1);
227 
228  /// Modifies this FluxBox by multiplying src in the CELL-CENTERED sub-box
229  /**
230  Modifies this FluxBox by pointwise multiplication of values in the
231  argument FArrayBox. Multiplies src's components
232  (a_srccomp : a_srccomp+a_numcomp-1) with this FluxBox's components
233  (a_destcomp : a_destcomp+numcomp-1) where the domain of this FluxBox
234  intersects the a_subbox. The actual directionally-dependent subbox
235  is a_subbox.surroundingNodes(dir);
236  NOTE:
237  a_subbox must be contained in the cell-centered Box of this FluxBox.
238  Returns *this
239  */
240  FluxBox& mult(const FluxBox& a_src,
241  const Box& a_subbox,
242  int a_srccomp,
243  int a_destcomp,
244  int a_numcomp = 1);
245 
246  /// Modifies this FluxBox by dividing src in the CELL-CENTERED sub-box
247  /**
248  Modifies this FluxBox by pointwise division of values in the argument
249  FArrayBox. Divides src's components (a_srccomp : a_srccomp+a_numcomp-1)
250  into this FluxBox's components (a_destcomp : a_destcomp+numcomp-1)
251  where the domain of this FluxBox intersects the a_subbox. The actual
252  directionally-dependent subbox is a_subbox.surroundingNodes(dir);
253  NOTE:
254  a_subbox must be contained in the cell-centered Box of this FluxBox.
255  Returns *this
256  */
257  FluxBox& divide(const FluxBox& a_src,
258  const Box& a_subbox,
259  int a_srccomp,
260  int a_destcomp,
261  int a_numcomp = 1);
262 
263  /// Modifies this FluxBox by adding the scalar Real r to all values.
265 
266  /// Modifies this FluxBox by incrementing with the argument FluxBox.
267  /**
268  Modifies this FluxBox by pointwise addition of the values of the
269  argument FluxBox. You might come to grief if the domains of the
270  FArrayBoxes don't match, just as in FArrayBox::plus().
271  */
272  FluxBox& operator+= (const FluxBox& f);
273 
274  /// Modifies this FluxBox by subtracting the scalar Real r to all values.
276 
277  /// Modifies this FluxBox by decrementing with the argument FluxBox.
278  /**
279  Modifies this FluxBox by pointwise subtraction of the values of the
280  argument FluxBox. You might come to grief if the domains of the
281  FluxBoxes don't match, just as in FArrayBox::minus().
282  */
283  FluxBox& operator-= (const FluxBox& f);
284 
285  /// Modifies this FluxBox by multiplying all values by the scalar Real r.
287 
288  /// Modifies this FluxBox by multiplying by the argument FluxBox.
289  /**
290  Modifies this FluxBox by pointwise multiplication of the values by the
291  argument FluxBox. You might come to grief if the domains of the
292  FluxBoxes don't match, just as in FArrayBox::mult().
293  */
294  FluxBox& operator*= (const FluxBox& f);
295 
296  /// Modifies this FluxBox by shifting its domain box.
297  FluxBox& shift (const IntVect& v);
298 
299  // Linearization Functions
300 
301  /// Returns size of linearized data over \em bx.
302  /**
303  Returns size, in number of bytes, of a flat linear
304  representation of data in components comps in faces around
305  cell-centered box R
306  */
307  int size(const Box& bx, const Interval& comps) const;
308 
309  /// Writes a linear representation of this FluxBox
310  /**
311  Write a linear representaion of the internal data for
312  the faces surrounding cell-centered box R. Assumes that sufficient
313  memory for the buffer has already been allocated by the caller
314  */
315  void linearOut(void*buf, const Box& R, const Interval& comps) const;
316 
317  /// like linearOut, but returns current position in the buffer
318  void* linearOut2(void*buf, const Box& R, const Interval& comps) const;
319 
320  /// Read a linear representation of the data over the Box \rm R
321  /**
322  Reads in the output of linearOut
323  */
324  void linearIn(void*buf, const Box& R, const Interval& comps);
325 
326  /// like linearInt, but returns current position in the buffer
327  void* linearIn2(void*buf, const Box& R, const Interval& comps);
328 
329  /// Helper function for linearization
330  static int preAllocatable()
331  {
332  return 0;
333  }
334 
335 
336 protected:
337  /**
338  Cell-centered Box over which this FluxBox is defined
339  */
341 
342  /**
343  Number of variables on each face
344  */
345  int m_nvar;
346 
347  /**
348  CH_SPACEDIM FArrayBoxes which hold fluxes
349  */
351 
352 
353 private:
354  // these are disallowed
355 
356  /// Disallowed
357  FluxBox (const FluxBox&);
358  /// Disallowed
359  FluxBox& operator = (const FluxBox&);
360 
361 };
362 
363 #include "NamespaceFooter.H"
364 #endif
#define D_DECL6(a, b, c, d, e, f)
Definition: CHArray.H:39
FluxBox & minus(const FluxBox &a_src, const Box &a_subbox, int a_srccomp, int a_destcomp, int a_numcomp=1)
Modifies this FluxBox by subtracting src in the CELL-CENTERED sub-box.
int m_nvar
Definition: FluxBox.H:345
FluxBox & divide(const FluxBox &a_src, const Box &a_subbox, int a_srccomp, int a_destcomp, int a_numcomp=1)
Modifies this FluxBox by dividing src in the CELL-CENTERED sub-box.
FluxBox & plus(const FluxBox &a_src, const Box &a_subbox, int a_srccomp, int a_destcomp, int a_numcomp=1)
Modifies this FluxBox by adding src in the CELL-CENTERED sub-box.
FArrayBox & operator[](const int dir)
Returns FArrayBox in direction dir.
one dimensional dynamic array
Definition: Vector.H:53
FluxBox & operator+=(Real r)
Modifies this FluxBox by adding the scalar Real r to all values.
FluxBox & operator=(const FluxBox &)
Disallowed.
void setVal(const Real val)
Set all fluxes to val.
static int preAllocatable()
Helper function for linearization.
Definition: FluxBox.H:330
A FArrayBox-like container for face-centered fluxes.
Definition: FluxBox.H:22
Structure for passing component ranges in code.
Definition: Interval.H:23
Box m_bx
Definition: FluxBox.H:340
~FluxBox()
Destructor.
FluxBox & shift(const IntVect &v)
Modifies this FluxBox by shifting its domain box.
double Real
Definition: REAL.H:33
void copy(const FluxBox &src)
Copy from src to this FluxBox – sizes must be identical.
FluxBox & operator*=(Real r)
Modifies this FluxBox by multiplying all values by the scalar Real r.
int size(const Box &bx, const Interval &comps) const
Returns size of linearized data over bx.
void * linearIn2(void *buf, const Box &R, const Interval &comps)
like linearInt, but returns current position in the buffer
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
void linearOut(void *buf, const Box &R, const Interval &comps) const
Writes a linear representation of this FluxBox.
Vector< FArrayBox * > m_fluxes
Definition: FluxBox.H:350
FluxBox & operator-=(Real r)
Modifies this FluxBox by subtracting the scalar Real r to all values.
void clear()
Returns the FluxBox to the undefined state.
FArrayBox & getFlux(const int dir)
Returns face-centered flux in direction dir.
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
const Box & box() const
Returns cell-centered box which defines fluxBox.
Definition: FArrayBox.H:45
void define(const FluxBox &a_fb)
Definition: FluxBox.H:56
FluxBox()
Default constructor.
void define(const Box &bx, int n=1)
Resize FluxBox similar to BaseFab::resize()
int nComp() const
Number of components.
void * linearOut2(void *buf, const Box &R, const Interval &comps) const
like linearOut, but returns current position in the buffer
void linearIn(void *buf, const Box &R, const Interval &comps)
Read a linear representation of the data over the Box R.
FluxBox & negate()
Modifies this FluxBox to its additive inverse.
FluxBox & mult(const FluxBox &a_src, const Box &a_subbox, int a_srccomp, int a_destcomp, int a_numcomp=1)
Modifies this FluxBox by multiplying src in the CELL-CENTERED sub-box.