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 _COARSEAVERAGE_H_ 00012 #define _COARSEAVERAGE_H_ 00013 00014 #include "REAL.H" 00015 #include "BaseFab.H" 00016 #include "FArrayBox.H" 00017 #include "LevelData.H" 00018 #include "NamespaceHeader.H" 00019 00020 class DisjointBoxLayout; 00021 00022 /// replaces coarse level data with an average of fine level data. 00023 /** 00024 This class replaces data at a coarse level of refinement with an 00025 average of data at a finer level of refinement, in areas where fine 00026 data is present. Coarse level data is not modified where fine 00027 level data is not present. 00028 00029 */ 00030 class CoarseAverage 00031 { 00032 public: 00033 00034 /// 00035 /** 00036 Default constructor. User must subsequently call define(). 00037 */ 00038 CoarseAverage(); 00039 00040 /// 00041 /** 00042 Destructor. 00043 */ 00044 virtual ~CoarseAverage(); 00045 00046 /// 00047 /** 00048 Defining constructor. Constructs a valid object. 00049 Equivalent to default construction followed by define(). 00050 00051 {\bf Arguments:}\\ 00052 a_fine_domain (not modified): the fine level domain.\\ 00053 a_numcomps (not modified): the number of components.\\ 00054 a_ref_ratio (not modified): the refinement ratio. \\ 00055 00056 */ 00057 CoarseAverage(const DisjointBoxLayout& a_fine_domain, 00058 int a_numcomps, 00059 int a_ref_ratio); 00060 00061 /// 00062 /** 00063 Defining constructor. Constructs a valid object. 00064 Equivalent to default construction followed by define(). 00065 This version takes the coarser level as well, results in 00066 a faster averaging operation, since Copier can be pre-constructed. 00067 00068 {\bf Arguments:}\\ 00069 a_fine_domain (not modified): the fine level domain.\\ 00070 a_crse_domain (not modified): the crse level domain.\\ 00071 a_numcomps (not modified): the number of components.\\ 00072 a_ref_ratio (not modified): the refinement ratio.\\ 00073 a_ghostVect (not modified): radius of ghost cells around coarse grids to be filled (normally none)\ 00074 00075 00076 */ 00077 CoarseAverage(const DisjointBoxLayout& a_fine_domain, 00078 const DisjointBoxLayout& a_crse_domain, 00079 int a_numcomps, 00080 int a_ref_ratio, 00081 IntVect a_ghostVect = IntVect::Zero); 00082 00083 /// 00084 /** 00085 Defines this object. Existing information is overriden. 00086 00087 {\bf Arguments:}\\ 00088 a_fine_domain (not modified): the fine level domain.\\ 00089 a_numcomps (not modified): the number of components.\\ 00090 a_ref_ratio (not modified): the refinement ratio.\\ 00091 00092 {\bf This:}\\ 00093 ---This object is modified.--- 00094 00095 */ 00096 void 00097 define(const DisjointBoxLayout& a_fine_domain, // the fine level domain 00098 int a_numcomps, // the number of components 00099 int a_ref_ratio); // the refinement ratio 00100 00101 00102 /// 00103 /** 00104 Defines this object. Existing information is overriden. 00105 This version takes the coarser-level grids as well, which 00106 allows for a faster averaging operation, since the Copier 00107 can be pre-defined 00108 00109 {\bf Arguments:}\\ 00110 a_fine_domain (not modified): the fine level domain.\\ 00111 a_crse_domain (not modified): the coarse level domain.\\ 00112 a_numcomps (not modified): the number of components.\\ 00113 a_ref_ratio (not modified): the refinement ratio.\\ 00114 a_ghostVect (not modified): radius of ghost cells around coarse grids to be filled (normally none)\ 00115 00116 {\bf This:}\\ 00117 ---This object is modified.--- 00118 00119 */ 00120 void 00121 define(const DisjointBoxLayout& a_fine_domain, // the fine level domain 00122 const DisjointBoxLayout& a_crse_domain, // the crse level domain 00123 int a_numcomps, // the number of components 00124 int a_ref_ratio, // the refinement ratio 00125 IntVect a_ghostVect = IntVect::Zero); // coarse-level ghost cells to be filled. 00126 00127 /// 00128 /** 00129 Returns true if this object was created with the defining 00130 constructor or if define() has been called. 00131 00132 {\bf This:}\\ 00133 This object is not modified. 00134 */ 00135 bool 00136 isDefined() const; 00137 00138 /// 00139 /** 00140 Replaces a_coarse_data with the average of a_fine_data within the 00141 coarsening of the domain of the fine level. Elsewhere, the 00142 coarse data is unchanged. It is an error to call if not 00143 this->isDefined(). The domain of a_fine_data should be 00144 the same as the fine domain specified in the most recent call to 00145 define(). It is expected that the coarse and fine level's 00146 domains are properly nested. Both a_coarse_data and a_fine_data 00147 should have the same number of components specified in the most 00148 recent call to define(). 00149 00150 {\bf Arguments:}\\ 00151 a_coarse_data (modified): coarse data. \\ 00152 a_fine_data (not modified): fine data. \\ 00153 00154 {\bf This:}\\ 00155 Well, it's complicated. As far as the user is concerned, this object 00156 is not modified. See the design document if you care for details. 00157 00158 */ 00159 // this method would like to be const, but the work array is changed. 00160 // this suggests that the work array should not be persistent. 00161 virtual void 00162 averageToCoarse(LevelData<FArrayBox>& a_coarse_data, 00163 const LevelData<FArrayBox>& a_fine_data); 00164 00165 00166 /// similar to averageToCoarse, except does a harmonic average 00167 void 00168 averageToCoarseHarmonic(LevelData<FArrayBox>& a_coarse_data, 00169 const LevelData<FArrayBox>& a_fine_data); 00170 00171 00172 /// 00173 enum averageType 00174 { 00175 arithmetic = 0, 00176 harmonic, 00177 NUM_AVERAGE_TYPES 00178 }; 00179 00180 00181 protected: 00182 00183 00184 /** utility function called by both averageToCoarse 00185 and averageToCoarseHarmonic (to avoid code duplication) 00186 */ 00187 void 00188 computeAverages(LevelData<FArrayBox>& a_coarse_data, 00189 const LevelData<FArrayBox>& a_fine_data, 00190 int a_averageType); 00191 00192 void 00193 averageGridData(BaseFab<Real>& a_coarse, 00194 const BaseFab<Real>& a_fine, 00195 int a_ref_ratio, 00196 int a_averageType) 00197 const; 00198 00199 protected: 00200 bool is_defined; 00201 00202 // the refinement ratio 00203 int m_ref_ratio; 00204 // work array for the coarsening of the fine data, of the same "shape" 00205 // as the fine data. 00206 LevelData<FArrayBox> m_coarsened_fine_data; 00207 00208 // has a copier been defined to transfer data to coarse-grid layout? 00209 bool m_is_copier_defined; 00210 00211 // cached copier to handle transfer to coarse-grid layout. 00212 Copier m_copier; 00213 }; 00214 00215 #include "NamespaceFooter.H" 00216 #endif