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 _AMRLEVEL_H_ 00012 #define _AMRLEVEL_H_ 00013 00014 #include "Vector.H" 00015 #include "REAL.H" 00016 #include "Box.H" 00017 #include "ProblemDomain.H" 00018 #include "DataIterator.H" 00019 #include "Vector.H" 00020 #include "IntVectSet.H" 00021 #include "CH_HDF5.H" 00022 #include "NamespaceHeader.H" 00023 00024 //class HDF5Handle; 00025 //class IntVectSet; 00026 //template <class TTYPE> class Vector; 00027 00028 /// Abstract base class for time-dependent data at a level of refinement. 00029 /** 00030 This is an abstract base class for data at the same level of 00031 refinement within a hierarchy of levels. The concrete class 00032 derived from AMRLevel is called a physics class. The domain 00033 of a level is a disjoint union of rectangles in a logically 00034 rectangular index space. Data is defined within this domain. 00035 There is also a problem domain, which may be larger, within which 00036 data can, in theory, be interpolated from some coarser level. 00037 00038 AMRLevel is intimately entangled with the AMR class. 00039 The AMR contains a collection of AMRLevel objects which 00040 represent a hierarchy of levels of refinement. The class AMR 00041 is responsible for calling the correct member functions of 00042 AMRLevel. The user is responsible for implementing the physics 00043 class, and might never call any AMRLevel functions described 00044 here. 00045 */ 00046 00047 class AMRLevel 00048 { 00049 public: 00050 /// 00051 /** 00052 Default constructor. 00053 */ 00054 AMRLevel(); 00055 00056 /// 00057 /** 00058 Destructor. 00059 */ 00060 virtual 00061 ~AMRLevel(); 00062 00063 /// 00064 /** 00065 Defines this AMRLevel. 00066 00067 <ul> 00068 <li>a_coarser_level_ptr (not modified): pointer to next coarser level 00069 object. 00070 <li>a_problem_domain (not modified): problem domain of this level. 00071 <li>a_level (not modified): index of this level. The base level is 00072 zero. 00073 <li>a_ref_ratio (not modified): the refinement ratio between this level 00074 and the next finer level. 00075 </ul> 00076 */ 00077 virtual 00078 void define(AMRLevel* a_coarser_level_ptr, 00079 const Box& a_problem_domain, 00080 int a_level, 00081 int a_ref_ratio); 00082 00083 /// 00084 /** 00085 Defines this AMRLevel. 00086 00087 <ul> 00088 <li>a_coarser_level_ptr (not modified): pointer to next coarser level 00089 object. 00090 <li>a_problem_domain (not modified): problem domain of this level. 00091 <li>a_level (not modified): index of this level. The base level is 00092 zero. 00093 <li>a_ref_ratio (not modified): the refinement ratio between this level 00094 and the next finer level. 00095 </ul> 00096 */ 00097 virtual 00098 void define(AMRLevel* a_coarser_level_ptr, 00099 const ProblemDomain& a_problem_domain, 00100 int a_level, 00101 int a_ref_ratio); 00102 00103 /// 00104 /** 00105 Advances this level by one time step. Returns an estimate of the 00106 new time step. 00107 00108 This is a pure virtual function and MUST be defined in the derived 00109 class. 00110 00111 */ 00112 virtual 00113 Real advance() = 0; 00114 00115 /// 00116 /** 00117 Return true if the solution has converged to a steady state for this level. 00118 Default version always returns false. 00119 */ 00120 virtual 00121 bool convergedToSteadyState() 00122 { 00123 return false; 00124 } 00125 00126 /// 00127 /** 00128 Things to do after advancing this level by one time step. 00129 00130 This is a pure virtual function and MUST be defined in the derived 00131 class. 00132 00133 */ 00134 virtual 00135 void postTimeStep() = 0; 00136 00137 /// 00138 /** 00139 Creates tagged cells for dynamic mesh refinement. 00140 00141 This is a pure virtual function and MUST be defined in the derived 00142 class. 00143 00144 */ 00145 virtual 00146 void tagCells(IntVectSet& a_tags) = 0; 00147 00148 /// 00149 /** 00150 Creates tagged cells for mesh refinement at initialization. 00151 00152 This is a pure virtual function and MUST be defined in the derived 00153 class. 00154 00155 */ 00156 virtual 00157 void tagCellsInit(IntVectSet& a_tags) = 0; 00158 00159 /// 00160 /** 00161 Performs any pre-regridding operations which are necessary. 00162 00163 This is not a pure virtual function to preserve compatibility 00164 with earlier versions of AMRLevel. The AMRLevel::preRegrid() 00165 instantiation is a no-op. 00166 */ 00167 virtual 00168 void preRegrid(int a_base_level, const Vector<Vector<Box> >& a_new_grids); 00169 00170 /// 00171 /** 00172 Redefines this level to have the specified domain a_new_grids. 00173 00174 This is a pure virtual function and MUST be defined in the derived 00175 class. 00176 00177 */ 00178 virtual 00179 void regrid(const Vector<Box>& a_new_grids) = 0; 00180 00181 /// 00182 /** 00183 Performs any post-regridding operations which are necessary. 00184 00185 This is not a pure virtual function to preserve compatibility 00186 with earlier versions of AMRLevel. The AMRLevel::postRegrid() 00187 instantiation is a no-op. 00188 */ 00189 virtual 00190 void postRegrid(int a_base_level); 00191 00192 /// 00193 /** 00194 Initializes this level to have the specified domain a_new_grids. 00195 00196 This is a pure virtual function and MUST be defined in the derived 00197 class. 00198 00199 */ 00200 virtual 00201 void initialGrid(const Vector<Box>& a_new_grids) = 0; 00202 00203 /// 00204 /** 00205 Performs operations required after the grid has been defined but 00206 before data initialization. This will also be called after 00207 readCheckpointLevel during a restart procedure with argument 00208 a_restart set to true. 00209 00210 Levels are accessed from finest to coarsest. The 00211 AMRLevel::postInitialGrid() instantiation is a no-op. 00212 00213 */ 00214 virtual 00215 void postInitialGrid(const bool a_restart); 00216 00217 /// 00218 /** 00219 Initializes data. 00220 00221 This is a pure virtual function and MUST be defined in the derived 00222 class. 00223 00224 */ 00225 virtual 00226 void initialData() = 0; 00227 00228 /// 00229 /** 00230 Things to do after initialization. 00231 00232 This is a pure virtual function and MUST be defined in the derived 00233 class. 00234 00235 */ 00236 virtual 00237 void postInitialize() = 0; 00238 00239 //! Override this method to have an AMRLevel subclass perform some 00240 //! operation upon the conclusion of a simulation. This is called 00241 //! when AMR::conclude() is called. The final step is passed to the 00242 //! method. 00243 //! \param a_step The last step in the simulation. 00244 virtual void conclude(int a_step) const; 00245 00246 /** 00247 \name I/O functions 00248 */ 00249 /**@{*/ 00250 00251 #ifdef CH_USE_HDF5 00252 /// 00253 /** 00254 Writes checkpoint header. 00255 00256 This is a pure virtual function and MUST be defined in the derived 00257 class. 00258 00259 */ 00260 virtual 00261 void writeCheckpointHeader (HDF5Handle& a_handle) const = 0; 00262 00263 /// 00264 /** 00265 Write checkpoint data for this level. 00266 00267 This is a pure virtual function and MUST be defined in the derived 00268 class. 00269 00270 */ 00271 virtual 00272 void writeCheckpointLevel (HDF5Handle& a_handle) const = 0; 00273 00274 /// 00275 /** 00276 Reads checkpoint header. 00277 00278 This is a pure virtual function and MUST be defined in the derived 00279 class. 00280 00281 */ 00282 virtual 00283 void readCheckpointHeader (HDF5Handle& a_handle) = 0; 00284 00285 /// 00286 /** 00287 Reads checkpoint data for this level. 00288 00289 This is a pure virtual function and MUST be defined in the derived 00290 class. 00291 00292 */ 00293 virtual 00294 void readCheckpointLevel (HDF5Handle& a_handle) = 0; 00295 00296 /// 00297 /** 00298 Writes plot header. 00299 00300 This is a pure virtual function and MUST be defined in the derived 00301 class. 00302 00303 */ 00304 virtual 00305 void writePlotHeader (HDF5Handle& a_handle) const = 0; 00306 00307 /// 00308 /** 00309 Write plot file for this level. 00310 00311 This is a pure virtual function and MUST be defined in the derived 00312 class. 00313 00314 */ 00315 virtual 00316 void writePlotLevel (HDF5Handle& a_handle) const = 0; 00317 #endif 00318 00319 //! This allows one to write a plot file in a non-HDF5 format. It is called only at 00320 //! refinement level 0, so AMR data will have to be handled by the implementer. 00321 //! \param a_prefix A prefix for the custom plot file name. 00322 //! \param a_step The current time step. 00323 virtual void writeCustomPlotFile(const std::string& a_prefix, 00324 int a_step) const; 00325 00326 /**@}*/ 00327 00328 /** 00329 \name Parameter-setting functions 00330 */ 00331 /**@{*/ 00332 00333 /// 00334 /** 00335 Sets the pointer-to-finer-level member to a_finer_level_ptr. 00336 */ 00337 virtual 00338 void finerLevelPtr(AMRLevel* a_finer_level_ptr); 00339 00340 /// 00341 /** 00342 Sets the time step to a_dt. 00343 */ 00344 virtual 00345 void dt(Real a_dt); 00346 00347 /// 00348 /** 00349 Sets the time to a_time. 00350 00351 */ 00352 virtual 00353 void time(Real a_time); 00354 00355 /// 00356 /** 00357 Sets the initial dt multiplier to a_initial_dt_multiplier. 00358 */ 00359 virtual 00360 void initialDtMultiplier(Real a_initial_dt_multiplier); 00361 00362 /**@}*/ 00363 00364 /** 00365 \name Access functions 00366 */ 00367 /**@{*/ 00368 00369 /// 00370 /** 00371 Returns the current value of the time step. 00372 00373 */ 00374 virtual 00375 Real dt() const; 00376 00377 /// 00378 /** 00379 Returns the current value of the time on this level. 00380 */ 00381 virtual 00382 Real time() const; 00383 00384 /// 00385 /** 00386 Returns the initial dt multiplier. 00387 */ 00388 virtual 00389 Real initialDtMultiplier() const; 00390 00391 /// 00392 /** 00393 Returns the problem domain of this level. 00394 00395 */ 00396 virtual 00397 const ProblemDomain& problemDomain() const; 00398 00399 /// 00400 /** 00401 Returns the domain of this level. 00402 00403 */ 00404 virtual 00405 Vector<Box> boxes() const; 00406 00407 /// 00408 /** 00409 Returns true if any AMRLevel::define function has been called, 00410 false otherwise. 00411 */ 00412 bool isDefined() const; 00413 00414 /// 00415 /** 00416 Returns true if a coarser level exists, is defined, and has a grid. 00417 */ 00418 bool hasCoarserLevel() const; 00419 00420 /// 00421 /** 00422 Returns true if a finer level exists, is defined, and has a grid. 00423 */ 00424 bool hasFinerLevel() const; 00425 00426 /// 00427 /** 00428 Returns the index of this level 00429 */ 00430 virtual 00431 int level() const; 00432 00433 /// 00434 /** 00435 Returns the refinement ratio between this level and the next finer level. 00436 00437 */ 00438 virtual 00439 int refRatio() const; 00440 00441 /// 00442 /** 00443 Returns maximum stable time step for this level. 00444 00445 This is a pure virtual function and MUST be defined in the derived 00446 class. 00447 00448 */ 00449 virtual 00450 Real computeDt() = 0; 00451 00452 /// 00453 /** 00454 Returns maximum stable time step for this level with initial data. 00455 00456 This is a pure virtual function and MUST be defined in the derived 00457 class. 00458 00459 */ 00460 virtual 00461 Real computeInitialDt() = 0; 00462 00463 //! Retrieve an array of all of the AMRLevel objects in the entire hierarchy. 00464 Vector<AMRLevel*> getAMRLevelHierarchy(); 00465 00466 /**@}*/ 00467 00468 /// 00469 /** 00470 Returns current verbosity level. Minimum verbosity is 0, for 00471 which nothing is printed. 00472 00473 */ 00474 static 00475 int verbosity(); 00476 00477 /// 00478 /** 00479 Sets verbosity level to a_verbosity. Minimum verbosity is 0, for 00480 which nothing is printed. 00481 */ 00482 static 00483 void verbosity(int a_verbosity); 00484 00485 protected: 00486 00487 // verbosity level 00488 static int s_verbosity; 00489 00490 // the problem domain 00491 ProblemDomain m_problem_domain; 00492 00493 // 00494 Vector<Box> m_level_grids; 00495 00496 // the level 00497 int m_level; 00498 00499 // refinement ratio between this level and the next finer 00500 int m_ref_ratio; 00501 00502 // initial time step multipier 00503 Real m_initial_dt_multiplier; 00504 00505 // time step 00506 Real m_dt; 00507 00508 // time 00509 Real m_time; 00510 00511 // pointer to next coarser level 00512 AMRLevel* m_coarser_level_ptr; 00513 00514 // pointer to next finer level 00515 AMRLevel* m_finer_level_ptr; 00516 00517 bool m_isDefined; 00518 }; 00519 00520 #include "NamespaceFooter.H" 00521 #endif