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