00001 #ifdef CH_LANG_CC 00002 /* 00003 * _______ __ 00004 * / ___/ / ___ __ _ / / ___ 00005 * / /__/ _ \/ _ \/ V \/ _ \/ _ \ 00006 * \___/_//_/\___/_/_/_/_.__/\___/ 00007 * Please refer to Copyright.txt, in Chombo's root directory. 00008 */ 00009 #endif 00010 00011 // NodeQuadCFInterp2.H 00012 // original NodeQuadCFInterp by petermc, Mon, Apr 23, 2001 00013 // petermc, 31 Oct 2001 00014 #ifndef _NODEQUADCFINTERP2_H_ 00015 #define _NODEQUADCFINTERP2_H_ 00016 00017 #include <cmath> 00018 #include <cstdlib> 00019 #include "BaseFab.H" 00020 #include "NodeFArrayBox.H" 00021 #include "LevelData.H" 00022 #include "NodeCFIVS.H" 00023 #include "NodeBC.H" 00024 #include "NamespaceHeader.H" 00025 00026 00027 /// Class to interpolate quadratically at coarse/fine interface when refinement ratio is 2 00028 class NodeQuadCFInterp2 00029 /** Class to interpolate quadratically at interface between this level 00030 and next coarser level, when the refinement ratio is 2. 00031 This class should be considered internal to NodeQuadCFInterp. 00032 00033 <b>Long Description:</b> 00034 00035 The interface has codimension one.<br> 00036 If a fine node coincides with a coarse node, then we merely project 00037 from the coarse node to the fine node.<br> 00038 Otherwise, we take the mean of the neighboring coarse nodes 00039 and subtract 1/8 * dx^2 times the sum of the second derivatives 00040 in the appropriate directions. 00041 00042 The interpolation is performed in function coarseFineInterp(). 00043 The constructor computes <i>m_loCFIVS</i> and <i>m_hiCFIVS</i> to 00044 determine the fine nodes at the interface with the coarse level. 00045 00046 The constructor also takes <i>m_loCFIVS</i> and <i>m_hiCFIVS</i> to 00047 determine the fine nodes at the interface with the coarse level. 00048 Calling getFineIVS() on <i>m_loCFIVS</i>[idir][dit()] gives us the 00049 IntVectSet of nodes of <i>m_grids</i>[dit()] on the face in the low 00050 direction in dimension idir, that lie on the interface with the 00051 coarser level. Similarly with <i>m_hiCFIVS</i>[idir][dit()] for the 00052 opposite face, in the high direction in dimension idir. 00053 00054 <b>2-D Description:</b> 00055 00056 In the 2-D problem, the interface is 1-D. Between coarse nodes 00057 at 0 and 1, we approximate the value at the fine node by<br> 00058 f(1/2) ~ (f(0) + f(1))/2 - 1/8 * f''(1/2)<br> 00059 where we estimate the second derivative f''(1/2) from the 00060 coarse values f(0), f(1), and either f(-1) or f(2) or both. 00061 00062 If the points -1 and 2 are both on the grid: 00063 <pre> 00064 o---o-x-o---o 00065 -1 0 1 2 00066 </pre> 00067 then we use<br> 00068 f''(1/2) ~ (f(-1) - f(0) - f(1) + f(2))/2. 00069 00070 If the point -1 is on the grid but 2 is not: 00071 <pre> 00072 o---o-x-o o 00073 -1 0 1 2 00074 </pre> 00075 then we approximate f''(1/2) by f''(0) and use<br> 00076 f''(0) ~ (f(-1) - 2 * f(0) + f(1)). 00077 00078 If the point 2 is on the grid but -1 is not: 00079 <pre> 00080 o o-x-o---o 00081 -1 0 1 2 00082 </pre> 00083 then we approximate f''(1/2) by f''(1) and use<br> 00084 f''(1) ~ (f(0) - 2 * f(1) + f(2)). 00085 00086 <b>3-D Description:</b> 00087 00088 In the 3-D problem, the interface is 2-D. For any given fine node 00089 along the interface, look at its three coordinates. At least one 00090 of the coordinates is divisible by 2, meaning that it lies on a 00091 plane of coarse nodes. If all of the coordinates are even, then 00092 the fine node coincides with a coarse node, and we project the 00093 value. If only one coordinate is odd, then this reduces to the 00094 problem of a 1-D interface described above in the 2-D case. 00095 00096 We are left with the problem of interpolating f(1/2, 1/2). 00097 <pre> 00098 (0,1) (1,1) 00099 o-------o 00100 | | 00101 | x | 00102 | | 00103 o-------o 00104 (0,0) (1,0) 00105 </pre> 00106 We use<br> 00107 f(1/2,1/2) ~ (f(0,0) + f(0,1) + f(1,0) + f(1,1))/4 - 00108 1/8 * ( d^2 f/dx^2 (1/2,1/2) + d^2 f/dy^2 (1/2,1/2))<br> 00109 where the second derivatives are estimated from the four 00110 neighboring coarse nodes and their neighbors. 00111 00112 In particular, d^2 f/dx^2 (1/2,1/2) is approximated by the 00113 mean of d^2 f/dx^2 (1/2, 0) and d^2 f/dx^2 (1/2, 1).<br> 00114 These second derivatives are estimated in the same way as 00115 described above for the 1-D interface in the 2-D case. 00116 */ 00117 { 00118 public: 00119 00120 /** 00121 \name Constructors, destructor and defines 00122 */ 00123 /*@{*/ 00124 00125 /// 00126 /** Default constructor. User must subsequently call define(). 00127 */ 00128 NodeQuadCFInterp2(); 00129 00130 /// 00131 /** Constructor calls setDefaultValues() and then calls 00132 define() with the same arguments. 00133 */ 00134 NodeQuadCFInterp2(const DisjointBoxLayout& a_grids, 00135 const Box& a_domain, 00136 const LayoutData<NodeCFIVS>* const a_loCFIVS, 00137 const LayoutData<NodeCFIVS>* const a_hiCFIVS, 00138 bool a_interfaceOnly, 00139 int a_interpolationDegree, 00140 int a_ncomp = 1, 00141 bool a_verbose = false); 00142 00143 /// 00144 /** Constructor calls setDefaultValues() and then calls 00145 define() with the same arguments. 00146 */ 00147 NodeQuadCFInterp2(const DisjointBoxLayout& a_grids, 00148 const ProblemDomain& a_domain, 00149 const LayoutData<NodeCFIVS>* const a_loCFIVS, 00150 const LayoutData<NodeCFIVS>* const a_hiCFIVS, 00151 bool a_interfaceOnly, 00152 int a_interpolationDegree, 00153 int a_ncomp = 1, 00154 bool a_verbose = false); 00155 00156 /// 00157 /** Destructor. 00158 */ 00159 ~NodeQuadCFInterp2(); 00160 00161 /// 00162 /** Full define function. Makes all coarse-fine 00163 information and sets internal variables. The current level 00164 is taken to be the fine level. 00165 */ 00166 void define(/// CELL-centered grids at this level 00167 const DisjointBoxLayout& a_grids, 00168 /// CELL-centered physical domain at this level 00169 const ProblemDomain& a_domain, 00170 /// pointer to object storing coarse/fine interface nodes 00171 const LayoutData<NodeCFIVS>* const a_loCFIVS, 00172 /// pointer to object storing coarse/fine interface nodes 00173 const LayoutData<NodeCFIVS>* const a_hiCFIVS, 00174 /// whether interpolation is from interface only, meaning that off-interface data should not be used 00175 bool a_interfaceOnly, 00176 /// degree of interpolation; 1 for (bi)linear, 2 for (bi)quadratic 00177 int a_interpolationDegree, 00178 /// number of components of data 00179 int a_ncomp = 1, 00180 /// verbose output flag 00181 bool a_verbose = false); 00182 00183 /// 00184 /** Full define function. Makes all coarse-fine 00185 information and sets internal variables. The current level 00186 is taken to be the fine level. 00187 */ 00188 void define(/// CELL-centered grids at this level 00189 const DisjointBoxLayout& a_grids, 00190 /// CELL-centered physical domain at this level 00191 const Box& a_domain, 00192 /// pointer to object storing coarse/fine interface nodes 00193 const LayoutData<NodeCFIVS>* const a_loCFIVS, 00194 /// pointer to object storing coarse/fine interface nodes 00195 const LayoutData<NodeCFIVS>* const a_hiCFIVS, 00196 /// whether interpolation is from interface only, meaning that off-interface data should not be used 00197 bool a_interfaceOnly, 00198 /// degree of interpolation; 1 for (bi)linear, 2 for (bi)quadratic 00199 int a_interpolationDegree, 00200 /// number of components of data 00201 int a_ncomp = 1, 00202 /// verbose output flag 00203 bool a_verbose = false); 00204 00205 00206 /*@}*/ 00207 00208 /** 00209 \name Access functions 00210 */ 00211 /*@{*/ 00212 00213 /// 00214 /** Returns <tt>true</tt> if this object was created with the defining 00215 constructor or if define() has been called. 00216 */ 00217 bool isDefined() const; 00218 00219 /*@}*/ 00220 00221 /** 00222 \name Parameter-setting functions 00223 */ 00224 /*@{*/ 00225 00226 /// 00227 /** Set whether to give output. Default is <tt>false</tt>. 00228 */ 00229 void setVerbose( bool a_verbose ); 00230 00231 /*@}*/ 00232 00233 /** 00234 \name Data modification functions 00235 */ 00236 /*@{*/ 00237 00238 /// 00239 /** Coarse / Fine (inhomogeneous) interpolation operator. 00240 Fill the nodes of <i>a_phi</i> on the coarse/fine interface with 00241 interpolated data from <i>a_phiCoarse</i>. 00242 */ 00243 void coarseFineInterp(/// data at this level 00244 LevelData<NodeFArrayBox>& a_phi, 00245 /// data at the next coarser level 00246 const LevelData<NodeFArrayBox>& a_phiCoarse); 00247 00248 /*@}*/ 00249 00250 protected: 00251 00252 /** CELL-centered grids at the current level (the finer level) 00253 */ 00254 DisjointBoxLayout m_grids; 00255 00256 /** CELL-centered physical domain of this level 00257 */ 00258 ProblemDomain m_domain; 00259 00260 /** NODE-centered box of nodes at physical domain at the coarser level 00261 */ 00262 Box m_domainCoarseNodes; 00263 00264 /** CELL-centered <i>m_grids</i> coarsened by 2 00265 */ 00266 DisjointBoxLayout m_coarsenedGrids; 00267 00268 /** copy of coarse phi, used in CFInterp(). 00269 */ 00270 LevelData<NodeFArrayBox> m_coarseCopy; 00271 00272 /** interpolating from interface only? 00273 */ 00274 bool m_interfaceOnly; 00275 00276 /** degree of interpolation: 1 for (bi)linear, 2 for (bi)quadratic 00277 */ 00278 int m_interpolationDegree; 00279 00280 /** number of components of data, needed for setting size of work array 00281 */ 00282 int m_ncomp; 00283 00284 /** has full define function been called? 00285 */ 00286 bool m_isDefined; 00287 00288 /** pointer to object storing coarse/fine interface nodes 00289 between this level and next coarser level 00290 */ 00291 const LayoutData<NodeCFIVS>* m_loCFIVS; 00292 00293 /** pointer to object storing coarse/fine interface nodes 00294 between this level and next coarser level 00295 */ 00296 const LayoutData<NodeCFIVS>* m_hiCFIVS; 00297 // LayoutData<NodeCFIVS> m_loCFIVS[SpaceDim]; 00298 // LayoutData<NodeCFIVS> m_hiCFIVS[SpaceDim]; 00299 00300 // weights for coarse/fine interpolation 00301 // Tuple<FArrayBox*, SpaceDim> m_wtLo, m_wtHi, m_wtC; 00302 00303 /** if <tt>true</tt>, print out extra information 00304 */ 00305 bool m_verbose; 00306 00307 private: 00308 //internally useful functions 00309 00310 void clearMemory(); 00311 00312 void setDefaultValues(); 00313 00314 /** Interpolate from <i>a_psiFab</i> to <i>a_fineFab</i> 00315 at <i>a_iv</i> along a line. 00316 */ 00317 void interpLine(/// fine data on NODE-centered FAB 00318 FArrayBox& a_fineFab, 00319 /// coarse data on NODE-centered FAB 00320 const FArrayBox& a_psiFab, 00321 /// nodes of <i>a_psiFab</i> from which data can be used 00322 const IntVectSet& a_psiFabNodes, 00323 /// point at which to interpolate 00324 const IntVect& a_iv, 00325 /// direction (0 to SpaceDim-1) along which to interpolate 00326 int a_idirOther); 00327 00328 }; 00329 00330 #include "NamespaceFooter.H" 00331 #endif