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 _MESHREFINE_H_ 00012 #define _MESHREFINE_H_ 00013 00014 #include <climits> 00015 00016 #include "Vector.H" 00017 #include "Box.H" 00018 #include "IntVectSet.H" 00019 #include "REAL.H" 00020 #include "ProblemDomain.H" 00021 #include "NamespaceHeader.H" 00022 00023 // Constants: 00024 00025 /// Class which manages grid generation 00026 class MeshRefine 00027 /** 00028 This class manages grid generation from sets of tagged cells. It is 00029 designed to be a pure virtual base class from which another class 00030 may be derived with a specific grid-generation algorithm (for example, 00031 the BRMeshRefine class). 00032 00033 There are two ways grids can be defined based on tagged cells. 00034 one takes a single IntVectSet of tags defined on the BaseLevel 00035 mesh and uses that set of tags for every level to be refined; 00036 the other takes a Vector<IntVectSet> of tags defined on all the 00037 mesh levels to be refined and uses those. 00038 00039 <b> Long Description: </b> 00040 00041 Create new meshes based on tagged cells on a range of levels of a mesh 00042 hierarchy. Each level of tagged cells is used to generate a new mesh at 00043 the next finer level. The finest level in the output mesh will be one 00044 level higher than the top of the range of levels given as input. As a 00045 special case, use the same tags (appropriately refined) for all levels. 00046 00047 \b Usage: 00048 00049 Call the regrid functions after computing error estimates and tagging cells. 00050 To add a new mesh level, set TopLevel to the index of the finest level 00051 in the existing mesh and define tags on the finest level. To keep the 00052 existing number of mesh levels, set TopLevel to one less than the 00053 index of the finest level and don't define any tags on the finest level. 00054 If a single IntVectSet of tags is passed (instead of a 00055 Vector<IntVectSet>) then the same tags (properly refined) will be used 00056 for all the new meshes up to level TopLevel+1. In any case, the 00057 meshes at levels BaseLevel and below are not modified. The output 00058 argument newmeshes will be reallocated to the necessary size before 00059 being used. When this function returns, the elements of the 00060 newmeshes vector corresponding to the unchanged levels will be 00061 filled in with copies of the levels from the old mesh vector. The 00062 variable tags is modified in an undefined way, so its contents 00063 should not be relied upon. The variable BlockFactor specifies the 00064 amount by which each box will be coarsenable. Every grid box will 00065 have an integral multiple of BlockFactor cells in each dimension and 00066 also lower index values that are integral multiples. As a side effect, 00067 the minimum box size will be BlockFactor. 00068 00069 Expensive validations are done only when debugging is enabled 00070 (i.e. the DEBUG make variable is "TRUE"). 00071 00072 <b> Usage Notes: </b> 00073 00074 All the input vectors should be defined with max index >= TopLevel. 00075 They should have values for indices [BaseLevel:TopLevel]. 00076 (except for OldMeshes, which must be defined for all indices). The 00077 new mesh vector newmeshes will be redefined up to index 00078 TopLevel+1. RefRatios should be defined such that 00079 RefRatios[L] is the value to use to refine the level L mesh to 00080 produce the level L+1 mesh. The tags vector is modified in an 00081 undefined manner. The output variable newmeshes may not be 00082 completely defined if an exception occurs. 00083 The BlockFactor can be used to force a minimum box size. 00084 */ 00085 { 00086 public: 00087 /// default constructor -- leaves object in an unusable state 00088 MeshRefine(); 00089 00090 /// full constructor -- leaves object in usable state 00091 MeshRefine(/// level 0 domain 00092 const Box& a_baseDomain, 00093 /// refinement ratios -- refRatio[0] is btwn levels 0 and 1 00094 const Vector<int>& a_refRatios, 00095 /// measure of how efficiently tagged cells will be covered 00096 const Real a_fillRatio, 00097 /// amount by which grids are guaranteed to be coarsenable 00098 const int a_blockFactor, 00099 /// proper nesting buffer amount 00100 const int a_bufferSize, 00101 /// maximum grid length in any direction -- 0 means no limit. 00102 const int a_maxSize); 00103 00104 /// full constructor -- leaves object in usable state 00105 MeshRefine(/// level 0 domain 00106 const ProblemDomain& a_baseDomain, 00107 /// refinement ratios -- refRatio[0] is btwn levels 0 and 1 00108 const Vector<int>& a_refRatios, 00109 /// measure of how efficiently tagged cells will be covered 00110 const Real a_fillRatio, 00111 /// amount by which grids are guaranteed to be coarsenable 00112 const int a_blockFactor, 00113 /// proper nesting buffer amount 00114 const int a_bufferSize, 00115 /// maximum grid length in any direction -- 0 means no limit. 00116 const int a_maxSize); 00117 00118 /// destructor 00119 virtual ~MeshRefine(); 00120 00121 /// define function -- size of RefRatios will define maximum number of levels 00122 void define(/// level 0 domain 00123 const Box& a_baseDomain, 00124 /// refinement ratios -- refRatio[0] is btwn levels 0 and 1 00125 const Vector<int>& a_refRatios, 00126 /// measure of how efficiently tagged cells will be covered 00127 const Real a_fillRatio, 00128 /// amount by which grids are guaranteed to be coarsenable 00129 const int a_blockFactor, 00130 /// proper nesting buffer amount 00131 const int a_bufferSize, 00132 /// maximum grid length in any direction -- 0 means no limit 00133 const int a_maxSize); 00134 00135 /// define function -- size of RefRatios will define maximum number of levels 00136 void define(/// level 0 domain 00137 const ProblemDomain& a_baseDomain, 00138 /// refinement ratios -- refRatio[0] is btwn levels 0 and 1 00139 const Vector<int>& a_refRatios, 00140 /// measure of how efficiently tagged cells will be covered 00141 const Real a_fillRatio, 00142 /// amount by which grids are guaranteed to be coarsenable 00143 const int a_blockFactor, 00144 /// proper nesting buffer amount 00145 const int a_bufferSize, 00146 /// maximum grid length in any direction -- 0 means no limit 00147 const int a_maxSize); 00148 00149 ///create hierarchy of grids from a single level of tags 00150 /** This function creates a hierarchy of grids from a single level of 00151 tags on BaseLevel. If tags exist, then all levels will have grids. 00152 Returns the new finest level of grids. 00153 */ 00154 virtual int regrid(/// new set of grids at every level 00155 Vector<Vector<Box> >& a_newmeshes, 00156 /// tagged cells on baseLevel 00157 const IntVectSet& a_tags, 00158 /// index of base mesh level (finest unchanged level) 00159 const int a_baseLevel, 00160 /// top level to refine (one less than finest possible level) 00161 const int a_topLevel, 00162 /// existing grids (if no previous grids, set to domains) 00163 const Vector<Vector<Box> >& a_oldMeshes); 00164 00165 /// create hierarchy of grids from tags at all levels 00166 /** This function creates a hierarchy of grids from tags at all 00167 refinement levels. It is possible that not all levels will 00168 return with grids, since there may not be tags at all levels. 00169 Returns the new finest level of grids. 00170 */ 00171 virtual int regrid(/// new set of grids at every level 00172 Vector<Vector<Box> >& a_newmeshes, 00173 /// tagged cells on each existing level 00174 Vector<IntVectSet>& a_tags, 00175 /// index of base mesh level (finest unchanged level) 00176 const int a_baseLevel, 00177 /// top level to refine (one less than finest possible level) 00178 const int a_topLevel, 00179 /// existing grids (if no previous grids, set to domains) 00180 const Vector<Vector<Box> >& a_oldMeshes); 00181 00182 // Access functions 00183 00184 /// returns vector of refinement ratios 00185 const Vector<int>& refRatios() const; 00186 00187 /// returns fillRatio 00188 Real fillRatio() const; 00189 00190 /// returns blocking factor 00191 int blockFactor() const; 00192 00193 /// returns proper nesting buffer size 00194 int bufferSize() const; 00195 00196 /// returns maximum box size in any dimension -- 0 means no limit 00197 int maxSize() const; 00198 00199 /// sets vector of refinement ratios 00200 void refRatios(const Vector<int>& a_nRefVect); 00201 00202 /// sets fillRatio 00203 void fillRatio(const Real a_fill_ratio); 00204 00205 /// sets blocking factor 00206 void blockFactor(const int a_block_factor); 00207 00208 /// sets proper nesting buffer size 00209 void bufferSize(const int a_buffer_size); 00210 00211 /// sets maximum box size in any dimension -- 0 means no limit 00212 void maxSize(const int a_max_size); 00213 00214 /// has this object been defined properly? 00215 bool isDefined() const; 00216 00217 /// sets proper nesting region granularity. 00218 void granularity(int a_granularity); 00219 00220 /// constructs a set of boxes which covers a set of tagged cells 00221 /** constructs a set of boxes which covers a set of tagged cells 00222 by using the algorithm of choice. Everything should 00223 be on the same level, and blocking factor is not applied. 00224 Boxes will be on the same refinement level as the tags. 00225 This would normally be a protected function, but it can be useful 00226 to call it on its own, so it has been left public. 00227 */ 00228 virtual void 00229 makeBoxes(/// output: refined boxes at each new level 00230 Vector<Box>& a_mesh, 00231 /// input: set of tagged cells to cover 00232 const IntVectSet& a_tags, 00233 /// input: proper nesting domain in which mesh boxes must live 00234 const IntVectSet& a_pnd, 00235 /// input: physical domain 00236 const ProblemDomain& a_domain, 00237 ///input: largest number of cells in any dimension for any box 00238 const int a_maxSize, 00239 const int a_totalBufferSize) const = 0; 00240 00241 00242 void setPNDMode(int a_mode); 00243 protected: 00244 00245 /// computes local blockFactors used internally to enforce the BlockFactor 00246 /** This function computes values for m_local_blockfactors array, which 00247 is the amount that tags on a level are coarsened in order to guarantee 00248 that the grids on the next finer level are coarsenable by the 00249 BlockFactor. */ 00250 virtual void 00251 computeLocalBlockFactors(); 00252 00253 bool properlyNested(const Box& a_box, 00254 const ProblemDomain& a_domain, 00255 const IntVectSet& a_pnd, 00256 int a_totalBuffer) const; 00257 00258 /// Computes proper nesting domains. 00259 /** 00260 This should only be 00261 called by refine. it assumes that everything has already been 00262 coarsened by the local blocking factor 00263 */ 00264 virtual void 00265 makePNDs(///output: proper nesting domains at each level 00266 Vector<IntVectSet>& a_pnds, 00267 Vector<int>& a_totalBufferSize, 00268 /// input: index of highest AMR level not to be refined 00269 const int a_baseLevel, 00270 /// input: index of highest AMR level in output 00271 const int a_topLevel, 00272 /// input: (same as in \em meshRefine) 00273 const Vector<ProblemDomain>& a_domains, 00274 /// input: boxes at mesh level \em BaseLevel 00275 const IntVectSet& a_baseMesh, 00276 ///input: (similar to \em meshRefine; but with level-dependent coarsening factors) 00277 const Vector<int>& a_bufferSize ) const; 00278 00279 virtual void 00280 makePNDs(///output: proper nesting domains at each level 00281 Vector<IntVectSet>& a_pnds, 00282 Vector<int>& a_totalBufferSize, 00283 /// input: index of highest AMR level not to be refined 00284 const int a_baseLevel, 00285 /// input: index of highest AMR level in output 00286 const int a_topLevel, 00287 /// input: (same as in \em meshRefine) 00288 const Vector<ProblemDomain>& a_domains, 00289 /// input: boxes at mesh level \em BaseLevel 00290 const Vector<Box>& a_baseMesh, 00291 ///input: (similar to \em meshRefine; but with level-dependent coarsening factors) 00292 const Vector<int>& a_bufferSize ) const; 00293 00294 00295 // local data members 00296 00297 bool m_isDefined; 00298 00299 Vector<ProblemDomain> m_vectDomains; 00300 00301 Vector<IntVectSet> m_pnds; 00302 int m_lastBase; 00303 int m_lastTop; 00304 int m_lastBuffer; 00305 00306 Vector<int> m_nRefVect; 00307 00308 Real m_fillRatio; 00309 00310 int m_blockFactor; 00311 00312 Vector<int> m_level_blockfactors; 00313 00314 int m_bufferSize; 00315 00316 int m_maxSize; 00317 00318 int m_granularity; 00319 00320 int m_PNDMode; 00321 00322 }; 00323 00324 #include "NamespaceFooter.H" 00325 #endif
1.5.5