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