Chombo + EB  3.0
PiecewiseLinearFillPatch.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 _PIECEWISELINEARFILLPATCH_H_
12 #define _PIECEWISELINEARFILLPATCH_H_
13 
14 #include <iostream>
15 #include <fstream>
16 #include "REAL.H"
17 #include "Box.H"
18 #include "FArrayBox.H"
19 #include "LevelData.H"
20 #include "IntVectSet.H"
21 #include "ProblemDomain.H"
22 #include "NamespaceHeader.H"
23 
24 /// Fills ghost cells by linear interpolation in space and time
25 
26 /**
27 Fills some fine level ghost cells by piecewise linear interpolation
28 from the coarse level.
29 
30 This class also presents an interface for performing piecewise
31 constant interpolation in space. If this is all that is required,
32 define with 'a_pwconst_interp_only = true' to save memory and
33 expense.
34 
35 This class fills the first a_interp_radius layers of fine level
36 ghost cells that are not part of other fine level grids. It uses
37 piecewise linear interpolation from the coarse level. The slopes
38 are computed using van leer limiting if there is enough room for
39 the stencil. It drops order and uses first-order one-sided
40 differences otherwise.
41 
42 Below is a picture of a fine level, with a_interp_radius = 1. The
43 ghost cells of grid 1 are shown. Cells marked X are interpolated
44 to from the coarse level. Cells marked ^ are not interpolated to
45 because they are in the valid domain of another fine grid. Cells
46 marked . are not interpolated to because they are outside the
47 problem domain. All of this changes in the presence of periodic
48 boundary conditions -- in periodic directions, all cells are considered
49 to be within the domain.
50 
51 <PRE>
52  +=======================================+
53  | |
54  | |
55  | |
56  | |
57  | + - - - - - - - - - - - - - - | +
58  | X X X X X X X X X X X X X X X|.
59  | | +===========================+ |
60  | X| |.
61  | | | | |
62  | X| grid 1 |.
63  | | | | |
64  | X| |.
65  | | | | |
66  | X| |.
67  | +=======+===+===============+=======+ |
68  | | ^ ^ ^|X X X X X X X X|^ ^ ^ ^|.
69  | | + - - | - - - - - - - | - - - | +
70  | | | |grid 2 |
71  | | grid 0 | +=======+
72  | | | |
73  | | | |
74  | | | |
75  | +===========+ |
76  | |
77  | |
78  | problem domain |
79  +=======================================+
80 </PRE>
81 
82  the picture below shows the locations of the types of slopes. The
83  coarse grid is shown, and the projection of the fine grid onto the
84  coarse index space (on which slopes are computed). Coarse cells
85  marked ^ and . do not need slopes. Van Leer slopes in both
86  directions are used at coarse cells marked X. Coarse cells marked
87  V and < have one-sided differencing: cells marked V have low-sided
88  differencing in the y-direction (in this example, because the
89  coarse grid doesn't exist on the high side of these cells), and
90  cells marked < have low-sided differencing in the x-direction
91  (because the problem domain doesn't exist on the high side of
92  these cells). There can also be cells that have one-sided
93  differences in both directions.
94 
95 <PRE>
96  +-----------------------+===============+
97  | | coarse grid 1 |
98  | | |
99  | | |
100  +=======================+ - - - - - - - | - +
101  | \ / \ / \ / \ /|\ / \ / \ / \ /|
102  | | V V V V | X X X < | . |
103  | / \ / \ / \ / \|/ \ / \ / \ / \|
104  | | +---------------------------+ |
105  | \ /| | |
106  | | X | | | . |
107  | / \| | |
108  | | | | | |
109  | \ /| | |
110  | | X | | | . |
111  | / \| | |
112  | +-------+---+---------------+-------+ |
113  | | |\ / \ /|\ / \ /| |
114  | | | ^ ^ | X X | X X | ^ ^ | . |
115  | | |/ \ / \|/ \ / \| |
116  | | + - - - | - - - - - - - +-------+ - +
117  | | | | |
118  | | | | |
119  | | | | |
120  | +-----------+ +===============+
121  | | |
122  | | |
123  | coarse grid 0 | |
124  +=======================+---------------+
125 </PRE>
126 */
127 
129 {
130 public:
131  ///
132  /**
133  Default constructor. User must subsequently call define().
134  */
136 
137  ///
138  /**
139  Destructor.
140  */
141 virtual ~PiecewiseLinearFillPatch();
142 
143  ///
144  /**
145  Defining constructor.
146 
147  {\bf Arguments:}\\
148  a_fine_domain (not modified): domain of fine level. \\
149  a_coarse_domain (not modified): domain of coarse level. \\
150  a_num_comps (not modified): number of components of state vector. \\
151  a_problem_domain (not modified): problem domain on the coarse level. \\
152  a_ref_ratio (not modified): refinement ratio. \\
153  a_interp_radius (not modified): number of layers of fine ghost cells to fill by interpolation. \\
154  a_constInterpOnly (not modified): if true, only set up for piecewise-constant interpolation in space. \\
155  */
156  PiecewiseLinearFillPatch(const DisjointBoxLayout& a_fine_domain,
157  const DisjointBoxLayout& a_coarse_domain,
158  int a_num_comps,
159  const Box& a_crse_problem_domain,
160  int a_ref_ratio,
161  int a_interp_radius,
162  bool a_pwconst_interp_only = false
163  );
164 
165  ///
166  /**
167  Defining constructor.
168 
169  {\bf Arguments:}\\
170  a_fine_domain (not modified): domain of fine level. \\
171  a_coarse_domain (not modified): domain of coarse level. \\
172  a_num_comps (not modified): number of components of state vector. \\
173  a_problem_domain (not modified): problem domain on the coarse level. \\
174  a_ref_ratio (not modified): refinement ratio. \\
175  a_interp_radius (not modified): number of layers of fine ghost cells to fill by interpolation. \\
176  a_constInterpOnly (not modified): if true, only set up for piecewise-constant interpolation in space. \\
177  */
178  PiecewiseLinearFillPatch(const DisjointBoxLayout& a_fine_domain,
179  const DisjointBoxLayout& a_coarse_domain,
180  int a_num_comps,
181  const ProblemDomain& a_crse_problem_domain,
182  int a_ref_ratio,
183  int a_interp_radius,
184  bool a_pwconst_interp_only = false
185  );
186 
187  ///
188  /**
189  Defines this object. The user may call define() once and call
190  fillInterp() multiple times with different valid data sets.
191 
192  {\bf Arguments:}\\
193  a_fine_domain (not modified): domain of fine level. \\
194  a_coarse_domain (not modified): domain of coarse level. \\
195  a_num_comps (not modified): number of components of state vector. \\
196  a_problem_domain (not modified): problem domain on the coarse level. \\
197  a_ref_ratio (not modified): refinement ratio. \\
198  a_interp_radius (not modified): number of layers of fine ghost cells to fill by interpolation. \\
199  a_constInterpOnly (not modified): if true, only set up for piecewise-constant interpolation in space. \\
200 
201  {\bf This:}\\
202  ---This object is modified.---
203 
204  */
205  void
206  define(const DisjointBoxLayout& a_fine_domain,
207  const DisjointBoxLayout& a_coarse_domain,
208  int a_num_comps,
209  const Box& a_crse_problem_domain,
210  int a_ref_ratio,
211  int a_interp_radius,
212  bool a_pwconst_interp_only = false
213  );
214 
215  ///
216  /**
217  Defines this object. The user may call define() once and call
218  fillInterp() multiple times with different valid data sets.
219 
220  {\bf Arguments:}\\
221  a_fine_domain (not modified): domain of fine level. \\
222  a_coarse_domain (not modified): domain of coarse level. \\
223  a_num_comps (not modified): number of components of state vector. \\
224  a_problem_domain (not modified): problem domain on the coarse level. \\
225  a_ref_ratio (not modified): refinement ratio. \\
226  a_interp_radius (not modified): number of layers of fine ghost cells to fill by interpolation. \\
227  a_constInterpOnly (not modified): if true, only set up for piecewise-constant interpolation in space. \\
228 
229  {\bf This:}\\
230  ---This object is modified.---
231 
232  */
233  void
234  define(const DisjointBoxLayout& a_fine_domain,
235  const DisjointBoxLayout& a_coarse_domain,
236  int a_num_comps,
237  const ProblemDomain& a_crse_problem_domain,
238  int a_ref_ratio,
239  int a_interp_radius,
240  bool a_pwconst_interp_only = false
241  );
242 
243  ///
244  /**
245  Returns true if this object was created with the defining
246  constructor or if define() has been called.
247 
248  {\bf This:}\\
249  This object is not modified.
250  */
251  bool
252  isDefined() const;
253 
254  ///
255  /**
256  Fills the first m_interp_radius layers of fine ghost cells by
257  interpolation from the coarse level. It is an error to call if not
258  this->isDefined(). The range components to interpolate must be
259  specified. The corresponding components on the coarse and fine
260  levels may be different. It is required that a_fine_data's domain
261  is the same as was specified in the most recent call to define().
262  It is expected that the coarse and fine level's domains are
263  properly nested.
264 
265  {\bf Arguments:}\\
266  a_fine_data (modified): fine-level data being interpolated to.\\
267  a_old_coarse_data (not modified): coarse level source data at the old time.\\
268  a_new_coarse_data (not modified): coarse level source data at the new time.\\
269  a_time_interp_coef (not modified): time interpolation coefficient, in the range [0:1]. 0=old time, 1=new time.\\
270  a_src_comp (not modifed): starting coarse data component.\\
271  a_dest_comp (not modifed): starting fine data component.\\
272  a_num_comp (not modified): number of data components to be
273  interpolated.
274 
275  {\bf This:}\\
276  Well, it's complicated. As far as the user is concerned, this object
277  is not modified. See the design document if you care for details.
278 
279  */
280  void
281  fillInterp(LevelData<FArrayBox>& a_fine_data,
282  const LevelData<FArrayBox>& a_old_coarse_data,
283  const LevelData<FArrayBox>& a_new_coarse_data,
284  Real a_time_interp_coef,
285  int a_src_comp,
286  int a_dest_comp,
287  int a_num_comp
288  );
289 
290  ///
291  /**
292  Fills the first m_interp_radius layers of fine ghost cells by
293  piece-wise constant interpolation (only in space) from a coarse level
294  {\bf Arguments:}\\
295  a_fine_data (modified): fine-level data being interpolated to.\\
296  a_coarse_data (not modified): coarse level source data.\\
297  a_src_comp (not modifed): starting coarse data component.\\
298  a_dest_comp (not modifed): starting fine data component.\\
299  a_num_comp (not modified): number of data components to be
300  */
301  void
303  const LevelData<FArrayBox>& a_coarse_data,
304  int a_src_comp,
305  int a_dest_comp,
306  int a_num_comp
307  );
308 
309  // debugging utilities
310  void
311  printIntVectSets() const;
312 
313 
314 protected:
315  // copy coarse data to coarsened fine work array and interpolate to
316  // fine time level
317  void
318  timeInterp(const LevelData<FArrayBox>& a_old_coarse_data,
319  const LevelData<FArrayBox>& a_new_coarse_data,
320  Real a_time_interp_coef,
321  int a_src_comp,
322  int a_dest_comp,
323  int a_num_comp
324  );
325 
326  // fill the fine interpolation sites piecewise-constantly
327 virtual void
329  int a_src_comp,
330  int a_dest_comp,
331  int a_num_comp
332  )
333  const;
334 
335  // compute slopes in specified direction
336 virtual void computeSlopes(int a_src_comp,
337  int a_num_comp);
338 
339  void computeSimpleSlopesFab(FArrayBox & a_slopeFab,
340  const int & a_src_comp,
341  const int & a_num_comp,
342  const int & a_dir,
343  const FArrayBox & a_dataFab,
344  const IntVectSet& a_local_centered_interp,
345  const IntVectSet& a_local_lo_interp,
346  const IntVectSet& a_local_hi_interp);
347 
348  void computeMultiDimSlopes(FArrayBox & a_slopes0,
349  FArrayBox & a_slopes1,
350  FArrayBox & a_slopes2,
351  const FArrayBox& a_dataFab,
352  const int & a_src_comp,
353  const int & a_num_comp,
354  const Box & a_slopeBox);
355 
356  // increment the fine interpolation sites with linear term for the
357  // specified coordinate direction
358 virtual void
360  int a_src_comp,
361  int a_dest_comp,
362  int a_num_comp)
363  const;
364 
365 
366 protected:
368  // the radius of the interpolation stencil. e.g. a stencil using
369  // (i-1,j), (i,j) and (i+1,j) has a radius of 1.
370  static const int s_stencil_radius;
371  // refinement ratio
373  // number of layers of fine ghost cells to fill by interpolation.
375  // work array for coarse data in grids shaped like the fine level.
377  // work array for slopes
379  // problem domain on the coarse level.
381  // per-grid fine locations that you interpolate to.
383  // per-grid coarse locations that you interpolate from, by type of
384  // interpolation in the specified coordinate direction.
388  // cached Copier
390 };
391 
392 #include "NamespaceFooter.H"
393 #endif
virtual void fillConstantInterp(LevelData< FArrayBox > &a_fine_data, int a_src_comp, int a_dest_comp, int a_num_comp) const
virtual void computeSlopes(int a_src_comp, int a_num_comp)
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:130
void define(const DisjointBoxLayout &a_fine_domain, const DisjointBoxLayout &a_coarse_domain, int a_num_comps, const Box &a_crse_problem_domain, int a_ref_ratio, int a_interp_radius, bool a_pwconst_interp_only=false)
Fills ghost cells by linear interpolation in space and time.
Definition: PiecewiseLinearFillPatch.H:128
LayoutData< IntVectSet > m_coarse_centered_interp[SpaceDim]
Definition: PiecewiseLinearFillPatch.H:385
Copier m_coarsenCopier
Definition: PiecewiseLinearFillPatch.H:389
A strange but true thing to make copying from one boxlayoutdata to another fast.
Definition: Copier.H:137
virtual void incrementLinearInterp(LevelData< FArrayBox > &a_fine_data, int a_src_comp, int a_dest_comp, int a_num_comp) const
LevelData< FArrayBox > m_coarsened_fine_data
Definition: PiecewiseLinearFillPatch.H:376
LayoutData< IntVectSet > m_coarse_lo_interp[SpaceDim]
Definition: PiecewiseLinearFillPatch.H:386
const int SpaceDim
Definition: SPACE.H:39
void computeSimpleSlopesFab(FArrayBox &a_slopeFab, const int &a_src_comp, const int &a_num_comp, const int &a_dir, const FArrayBox &a_dataFab, const IntVectSet &a_local_centered_interp, const IntVectSet &a_local_lo_interp, const IntVectSet &a_local_hi_interp)
LevelData< FArrayBox > m_slopes[3]
Definition: PiecewiseLinearFillPatch.H:378
int m_interp_radius
Definition: PiecewiseLinearFillPatch.H:374
bool m_is_defined
Definition: PiecewiseLinearFillPatch.H:367
double Real
Definition: REAL.H:33
int m_ref_ratio
Definition: PiecewiseLinearFillPatch.H:372
LayoutData< IntVectSet > m_fine_interp
Definition: PiecewiseLinearFillPatch.H:382
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:31
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
static const int s_stencil_radius
Definition: PiecewiseLinearFillPatch.H:370
Definition: FArrayBox.H:44
LayoutData< IntVectSet > m_coarse_hi_interp[SpaceDim]
Definition: PiecewiseLinearFillPatch.H:387
ProblemDomain m_crse_problem_domain
Definition: PiecewiseLinearFillPatch.H:380
void timeInterp(const LevelData< FArrayBox > &a_old_coarse_data, const LevelData< FArrayBox > &a_new_coarse_data, Real a_time_interp_coef, int a_src_comp, int a_dest_comp, int a_num_comp)
void computeMultiDimSlopes(FArrayBox &a_slopes0, FArrayBox &a_slopes1, FArrayBox &a_slopes2, const FArrayBox &a_dataFab, const int &a_src_comp, const int &a_num_comp, const Box &a_slopeBox)
void fillInterp(LevelData< FArrayBox > &a_fine_data, const LevelData< FArrayBox > &a_old_coarse_data, const LevelData< FArrayBox > &a_new_coarse_data, Real a_time_interp_coef, int a_src_comp, int a_dest_comp, int a_num_comp)
virtual ~PiecewiseLinearFillPatch()
void fillInterpPWConstSpace(LevelData< FArrayBox > &a_fine_data, const LevelData< FArrayBox > &a_coarse_data, int a_src_comp, int a_dest_comp, int a_num_comp)
void printIntVectSets() const