Chombo + EB  3.0
NodeQuadCFInterp2.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 // NodeQuadCFInterp2.H
12 // original NodeQuadCFInterp by petermc, Mon, Apr 23, 2001
13 // petermc, 31 Oct 2001
14 #ifndef _NODEQUADCFINTERP2_H_
15 #define _NODEQUADCFINTERP2_H_
16 
17 #include <cmath>
18 #include <cstdlib>
19 #include "BaseFab.H"
20 #include "NodeFArrayBox.H"
21 #include "LevelData.H"
22 #include "NodeCFIVS.H"
23 #include "NodeBC.H"
24 #include "NamespaceHeader.H"
25 
26 
27 /// Class to interpolate quadratically at coarse/fine interface when refinement ratio is 2
29 /** Class to interpolate quadratically at interface between this level
30  and next coarser level, when the refinement ratio is 2.
31  This class should be considered internal to NodeQuadCFInterp.
32 
33  <b>Long Description:</b>
34 
35  The interface has codimension one.<br>
36  If a fine node coincides with a coarse node, then we merely project
37  from the coarse node to the fine node.<br>
38  Otherwise, we take the mean of the neighboring coarse nodes
39  and subtract 1/8 * dx^2 times the sum of the second derivatives
40  in the appropriate directions.
41 
42  The interpolation is performed in function coarseFineInterp().
43  The constructor computes <i>m_loCFIVS</i> and <i>m_hiCFIVS</i> to
44  determine the fine nodes at the interface with the coarse level.
45 
46  The constructor also takes <i>m_loCFIVS</i> and <i>m_hiCFIVS</i> to
47  determine the fine nodes at the interface with the coarse level.
48  Calling getFineIVS() on <i>m_loCFIVS</i>[idir][dit()] gives us the
49  IntVectSet of nodes of <i>m_grids</i>[dit()] on the face in the low
50  direction in dimension idir, that lie on the interface with the
51  coarser level. Similarly with <i>m_hiCFIVS</i>[idir][dit()] for the
52  opposite face, in the high direction in dimension idir.
53 
54  <b>2-D Description:</b>
55 
56  In the 2-D problem, the interface is 1-D. Between coarse nodes
57  at 0 and 1, we approximate the value at the fine node by<br>
58  f(1/2) ~ (f(0) + f(1))/2 - 1/8 * f''(1/2)<br>
59  where we estimate the second derivative f''(1/2) from the
60  coarse values f(0), f(1), and either f(-1) or f(2) or both.
61 
62  If the points -1 and 2 are both on the grid:
63 <pre>
64  o---o-x-o---o
65  -1 0 1 2
66 </pre>
67  then we use<br>
68  f''(1/2) ~ (f(-1) - f(0) - f(1) + f(2))/2.
69 
70  If the point -1 is on the grid but 2 is not:
71 <pre>
72  o---o-x-o o
73  -1 0 1 2
74 </pre>
75  then we approximate f''(1/2) by f''(0) and use<br>
76  f''(0) ~ (f(-1) - 2 * f(0) + f(1)).
77 
78  If the point 2 is on the grid but -1 is not:
79 <pre>
80  o o-x-o---o
81  -1 0 1 2
82 </pre>
83  then we approximate f''(1/2) by f''(1) and use<br>
84  f''(1) ~ (f(0) - 2 * f(1) + f(2)).
85 
86  <b>3-D Description:</b>
87 
88  In the 3-D problem, the interface is 2-D. For any given fine node
89  along the interface, look at its three coordinates. At least one
90  of the coordinates is divisible by 2, meaning that it lies on a
91  plane of coarse nodes. If all of the coordinates are even, then
92  the fine node coincides with a coarse node, and we project the
93  value. If only one coordinate is odd, then this reduces to the
94  problem of a 1-D interface described above in the 2-D case.
95 
96  We are left with the problem of interpolating f(1/2, 1/2).
97 <pre>
98  (0,1) (1,1)
99  o-------o
100  | |
101  | x |
102  | |
103  o-------o
104  (0,0) (1,0)
105 </pre>
106  We use<br>
107  f(1/2,1/2) ~ (f(0,0) + f(0,1) + f(1,0) + f(1,1))/4 -
108  1/8 * ( d^2 f/dx^2 (1/2,1/2) + d^2 f/dy^2 (1/2,1/2))<br>
109  where the second derivatives are estimated from the four
110  neighboring coarse nodes and their neighbors.
111 
112  In particular, d^2 f/dx^2 (1/2,1/2) is approximated by the
113  mean of d^2 f/dx^2 (1/2, 0) and d^2 f/dx^2 (1/2, 1).<br>
114  These second derivatives are estimated in the same way as
115  described above for the 1-D interface in the 2-D case.
116 */
117 {
118 public:
119 
120  /**
121  \name Constructors, destructor and defines
122  */
123  /*@{*/
124 
125  ///
126  /** Default constructor. User must subsequently call define().
127  */
129 
130  ///
131  /** Constructor calls setDefaultValues() and then calls
132  define() with the same arguments.
133  */
134  NodeQuadCFInterp2(const DisjointBoxLayout& a_grids,
135  const Box& a_domain,
136  const LayoutData<NodeCFIVS>* const a_loCFIVS,
137  const LayoutData<NodeCFIVS>* const a_hiCFIVS,
138  bool a_interfaceOnly,
139  int a_interpolationDegree,
140  int a_ncomp = 1,
141  bool a_verbose = false);
142 
143  ///
144  /** Constructor calls setDefaultValues() and then calls
145  define() with the same arguments.
146  */
147  NodeQuadCFInterp2(const DisjointBoxLayout& a_grids,
148  const ProblemDomain& a_domain,
149  const LayoutData<NodeCFIVS>* const a_loCFIVS,
150  const LayoutData<NodeCFIVS>* const a_hiCFIVS,
151  bool a_interfaceOnly,
152  int a_interpolationDegree,
153  int a_ncomp = 1,
154  bool a_verbose = false);
155 
156  ///
157  /** Destructor.
158  */
160 
161  ///
162  /** Full define function. Makes all coarse-fine
163  information and sets internal variables. The current level
164  is taken to be the fine level.
165  */
166  void define(/// CELL-centered grids at this level
167  const DisjointBoxLayout& a_grids,
168  /// CELL-centered physical domain at this level
169  const ProblemDomain& a_domain,
170  /// pointer to object storing coarse/fine interface nodes
171  const LayoutData<NodeCFIVS>* const a_loCFIVS,
172  /// pointer to object storing coarse/fine interface nodes
173  const LayoutData<NodeCFIVS>* const a_hiCFIVS,
174  /// whether interpolation is from interface only, meaning that off-interface data should not be used
175  bool a_interfaceOnly,
176  /// degree of interpolation; 1 for (bi)linear, 2 for (bi)quadratic
177  int a_interpolationDegree,
178  /// number of components of data
179  int a_ncomp = 1,
180  /// verbose output flag
181  bool a_verbose = false);
182 
183  ///
184  /** Full define function. Makes all coarse-fine
185  information and sets internal variables. The current level
186  is taken to be the fine level.
187  */
188  void define(/// CELL-centered grids at this level
189  const DisjointBoxLayout& a_grids,
190  /// CELL-centered physical domain at this level
191  const Box& a_domain,
192  /// pointer to object storing coarse/fine interface nodes
193  const LayoutData<NodeCFIVS>* const a_loCFIVS,
194  /// pointer to object storing coarse/fine interface nodes
195  const LayoutData<NodeCFIVS>* const a_hiCFIVS,
196  /// whether interpolation is from interface only, meaning that off-interface data should not be used
197  bool a_interfaceOnly,
198  /// degree of interpolation; 1 for (bi)linear, 2 for (bi)quadratic
199  int a_interpolationDegree,
200  /// number of components of data
201  int a_ncomp = 1,
202  /// verbose output flag
203  bool a_verbose = false);
204 
205 
206  /*@}*/
207 
208  /**
209  \name Access functions
210  */
211  /*@{*/
212 
213  ///
214  /** Returns <tt>true</tt> if this object was created with the defining
215  constructor or if define() has been called.
216  */
217  bool isDefined() const;
218 
219  /*@}*/
220 
221  /**
222  \name Parameter-setting functions
223  */
224  /*@{*/
225 
226  ///
227  /** Set whether to give output. Default is <tt>false</tt>.
228  */
229  void setVerbose( bool a_verbose );
230 
231  /*@}*/
232 
233  /**
234  \name Data modification functions
235  */
236  /*@{*/
237 
238  ///
239  /** Coarse / Fine (inhomogeneous) interpolation operator.
240  Fill the nodes of <i>a_phi</i> on the coarse/fine interface with
241  interpolated data from <i>a_phiCoarse</i>.
242  */
243  void coarseFineInterp(/// data at this level
245  /// data at the next coarser level
246  const LevelData<NodeFArrayBox>& a_phiCoarse);
247 
248  /*@}*/
249 
250 protected:
251 
252  /** CELL-centered grids at the current level (the finer level)
253  */
255 
256  /** CELL-centered physical domain of this level
257  */
259 
260  /** NODE-centered box of nodes at physical domain at the coarser level
261  */
263 
264  /** CELL-centered <i>m_grids</i> coarsened by 2
265  */
267 
268  /** copy of coarse phi, used in CFInterp().
269  */
271 
272  /** interpolating from interface only?
273  */
275 
276  /** degree of interpolation: 1 for (bi)linear, 2 for (bi)quadratic
277  */
279 
280  /** number of components of data, needed for setting size of work array
281  */
282  int m_ncomp;
283 
284  /** has full define function been called?
285  */
287 
288  /** pointer to object storing coarse/fine interface nodes
289  between this level and next coarser level
290  */
292 
293  /** pointer to object storing coarse/fine interface nodes
294  between this level and next coarser level
295  */
297  // LayoutData<NodeCFIVS> m_loCFIVS[SpaceDim];
298  // LayoutData<NodeCFIVS> m_hiCFIVS[SpaceDim];
299 
300  // weights for coarse/fine interpolation
301  // Tuple<FArrayBox*, SpaceDim> m_wtLo, m_wtHi, m_wtC;
302 
303  /** if <tt>true</tt>, print out extra information
304  */
305  bool m_verbose;
306 
307 private:
308  //internally useful functions
309 
310  void clearMemory();
311 
312  void setDefaultValues();
313 
314  /** Interpolate from <i>a_psiFab</i> to <i>a_fineFab</i>
315  at <i>a_iv</i> along a line.
316  */
317  void interpLine(/// fine data on NODE-centered FAB
318  FArrayBox& a_fineFab,
319  /// coarse data on NODE-centered FAB
320  const FArrayBox& a_psiFab,
321  /// nodes of <i>a_psiFab</i> from which data can be used
322  const IntVectSet& a_psiFabNodes,
323  /// point at which to interpolate
324  const IntVect& a_iv,
325  /// direction (0 to SpaceDim-1) along which to interpolate
326  int a_idirOther);
327 
328 };
329 
330 #include "NamespaceFooter.H"
331 #endif
bool isDefined() const
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:130
ProblemDomain m_domain
Definition: NodeQuadCFInterp2.H:258
int m_ncomp
Definition: NodeQuadCFInterp2.H:282
int m_interpolationDegree
Definition: NodeQuadCFInterp2.H:278
bool m_isDefined
Definition: NodeQuadCFInterp2.H:286
void setVerbose(bool a_verbose)
DisjointBoxLayout m_grids
Definition: NodeQuadCFInterp2.H:254
const LayoutData< NodeCFIVS > * m_hiCFIVS
Definition: NodeQuadCFInterp2.H:296
void interpLine(FArrayBox &a_fineFab, const FArrayBox &a_psiFab, const IntVectSet &a_psiFabNodes, const IntVect &a_iv, int a_idirOther)
void coarseFineInterp(LevelData< NodeFArrayBox > &a_phi, const LevelData< NodeFArrayBox > &a_phiCoarse)
LevelData< NodeFArrayBox > m_coarseCopy
Definition: NodeQuadCFInterp2.H:270
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:31
void define(const DisjointBoxLayout &a_grids, const ProblemDomain &a_domain, const LayoutData< NodeCFIVS > *const a_loCFIVS, const LayoutData< NodeCFIVS > *const a_hiCFIVS, bool a_interfaceOnly, int a_interpolationDegree, int a_ncomp=1, bool a_verbose=false)
Box m_domainCoarseNodes
Definition: NodeQuadCFInterp2.H:262
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
const LayoutData< NodeCFIVS > * m_loCFIVS
Definition: NodeQuadCFInterp2.H:291
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Definition: FArrayBox.H:44
bool m_verbose
Definition: NodeQuadCFInterp2.H:305
bool m_interfaceOnly
Definition: NodeQuadCFInterp2.H:274
DisjointBoxLayout m_coarsenedGrids
Definition: NodeQuadCFInterp2.H:266
Class to interpolate quadratically at coarse/fine interface when refinement ratio is 2...
Definition: NodeQuadCFInterp2.H:28