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 #ifndef _TIMEINTERPOLATORRK4_H_ 00012 #define _TIMEINTERPOLATORRK4_H_ 00013 00014 #include "FArrayBox.H" 00015 #include "DisjointBoxLayout.H" 00016 #include "LevelData.H" 00017 #include "ProblemDomain.H" 00018 #include "NamespaceHeader.H" 00019 00020 /// Time interpolator class using 4th-order Runge-Kutta 00021 00022 /** 00023 */ 00024 class TimeInterpolatorRK4 00025 { 00026 public: 00027 /// Default constructor 00028 /** 00029 Object requires define() to be called before all other functions. 00030 */ 00031 TimeInterpolatorRK4(); 00032 00033 /// Destructor 00034 /** 00035 Destroys all objects created by define(). Passed in data references 00036 of define() are left alone. 00037 */ 00038 ~TimeInterpolatorRK4(); 00039 00040 /// Actual constructor. 00041 /** 00042 Set up object. 00043 */ 00044 void define(/// layout at this level 00045 const DisjointBoxLayout& a_thisDisjointBoxLayout, 00046 /// layout at next coarser level 00047 const DisjointBoxLayout& a_coarserDisjointBoxLayout, 00048 /// problem domain on this level 00049 const ProblemDomain& a_domain, 00050 /// refinement ratio between this level and next coarser level 00051 const int& a_refineCoarse, 00052 /// number of variables 00053 const int& a_numStates, 00054 /// layers of ghost cells to be filled in on the coarsened layout at this level 00055 const int& a_ghosts); 00056 00057 /// Set coarse timestep. 00058 void setDt(const Real& a_dt); 00059 00060 /// Update Taylor polynomial coefficients with the coarse solution. 00061 /** 00062 Update Taylor polynomial coefficients with coarse solution a_soln. 00063 Ghost cells, too. 00064 00065 This function must be called after setDt() and before saveRHS(). 00066 */ 00067 void saveInitialSoln(const LevelData<FArrayBox>& a_soln); 00068 00069 /// Update Taylor polynomial coefficients with coarse right-hand side. 00070 /** 00071 Update Taylor polynomial coefficients with coarse right-hand side. 00072 Ghost cells, too. 00073 00074 This function must be called exactly four times, after saveInitialSoln() 00075 and before any calls to interpolate(). 00076 00077 The counter m_countRHS keeps track of how many times this is called. 00078 */ 00079 void saveRHS(const LevelData<FArrayBox>& a_rhs); 00080 00081 /// Interpolate in time using the Taylor polynomial. 00082 /** 00083 Interpolate in time to a_U on interval a_intvl using the Taylor polynomial. 00084 Ghost cells, too. 00085 */ 00086 void interpolate(/// interpolated solution on this level coarsened 00087 LevelData<FArrayBox>& a_U, 00088 /// time interpolation coefficient in range [0:1] 00089 const Real& a_timeInterpCoeff, 00090 /// interval of a_U to fill in 00091 const Interval& a_intvl); 00092 00093 /// Set RK4 intermediate values in time using the Taylor polynomial. 00094 /** 00095 Set RK4 intermediate values to a_U on interval a_intvl 00096 using the Taylor polynomial. 00097 Ghost cells, too. 00098 */ 00099 void intermediate(/// interpolated solution on this level coarsened 00100 LevelData<FArrayBox>& a_U, 00101 /// time interpolation coefficient in range [0:1] 00102 const Real& a_timeInterpCoeff, 00103 /// which RK4 stage: 0, 1, 2, 3 00104 const int& a_stage, 00105 /// interval of a_U to fill in 00106 const Interval& a_intvl) const; 00107 00108 protected: 00109 00110 /// Reset this object to use with new data 00111 void resetData(); 00112 00113 /// Set a_vec = m_dt * (a_c0, a_c1, a_c2, a_c3). 00114 void setVectorDt(Vector<Real>& a_vec, Real a_c0, Real a_c1, Real a_c2, Real a_c3); 00115 00116 Vector< Vector<Real> > m_coeffs; 00117 00118 /// layout for this level, coarsened by m_refToCoarse 00119 DisjointBoxLayout m_thisCoarsenedLayout; 00120 00121 /// layout for the coarse level 00122 DisjointBoxLayout m_coarseLayout; 00123 00124 /// For copying from rhs on m_coarseLayout to m_rhsCopy on m_thisCoarsenedLayout 00125 Copier m_copier; 00126 00127 /// layers of ghost cells around m_thisCoarsenedLayout for m_rhsCopy and m_taylorCoeffs 00128 int m_ghosts; 00129 00130 /// number of coefficients in Taylor polynomial: this is 4 00131 int m_numCoeffs; 00132 00133 /// ghost vector around m_thisCoarsenedLayout for m_rhsCopy and m_taylorCoeffs 00134 IntVect m_ghostVect; 00135 00136 /// coarse timestep 00137 Real m_dt; 00138 00139 /// Copy of rhs on m_thisCoarsenedLayout, to be used within saveRHS 00140 LevelData<FArrayBox> m_rhsCopy; 00141 00142 /// coefficients of the third-degree Taylor polynomial on m_thisCoarsenedLayout with ghost vector m_ghostVect; m_numCoeffs*m_numStates components 00143 LevelData<FArrayBox> m_taylorCoeffs; 00144 00145 /// difference between f(U1) and f(U2), used for intermediate-value calculations, on m_thisCoarsenedLayout with ghost vector m_ghostVect; m_numCoeffs*m_numStates components 00146 LevelData<FArrayBox> m_diff12; 00147 00148 /// whether m_dt has been set 00149 bool m_gotDt; 00150 00151 /// whether initial solution has been saved 00152 bool m_gotInitialSoln; 00153 00154 /// whether we have the full Taylor polynomial 00155 bool m_gotFullTaylorPoly; 00156 00157 /// number of times saveRHS function has been called 00158 int m_countRHS; 00159 00160 /// Problem domain - index space for next coarser level 00161 ProblemDomain m_coarseDomain; 00162 00163 /// Refinement ratio between this level and the next coarser 00164 int m_refineCoarse; 00165 00166 /// Number of variables 00167 int m_numStates; 00168 00169 /// define() has been called 00170 bool m_defined; 00171 00172 private: 00173 00174 // Disallowed for all the usual reasons 00175 void operator=(const TimeInterpolatorRK4&); 00176 TimeInterpolatorRK4(const TimeInterpolatorRK4&); 00177 }; 00178 00179 #include "NamespaceFooter.H" 00180 #endif