Chombo + EB  3.2
AMRLevel.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _AMRLEVEL_H_
12 #define _AMRLEVEL_H_
13 
14 #include "Vector.H"
15 #include "REAL.H"
16 #include "Box.H"
17 #include "ProblemDomain.H"
18 #include "DataIterator.H"
19 #include "Vector.H"
20 #include "IntVectSet.H"
21 #include "CH_HDF5.H"
22 #include "NamespaceHeader.H"
23 
24 //class HDF5Handle;
25 //class IntVectSet;
26 //template <class TTYPE> class Vector;
27 
28 /// Abstract base class for time-dependent data at a level of refinement.
29 /**
30  This is an abstract base class for data at the same level of
31  refinement within a hierarchy of levels. The concrete class
32  derived from AMRLevel is called a physics class. The domain
33  of a level is a disjoint union of rectangles in a logically
34  rectangular index space. Data is defined within this domain.
35  There is also a problem domain, which may be larger, within which
36  data can, in theory, be interpolated from some coarser level.
37 
38  AMRLevel is intimately entangled with the AMR class.
39  The AMR contains a collection of AMRLevel objects which
40  represent a hierarchy of levels of refinement. The class AMR
41  is responsible for calling the correct member functions of
42  AMRLevel. The user is responsible for implementing the physics
43  class, and might never call any AMRLevel functions described
44  here.
45 */
46 
47 class AMRLevel
48 {
49 public:
50  ///
51  /**
52  Default constructor.
53  */
54  AMRLevel();
55 
56  ///
57  /**
58  Destructor.
59  */
60  virtual
61  ~AMRLevel();
62 
63  ///
64  /**
65  Defines this AMRLevel.
66 
67  <ul>
68  <li>a_coarser_level_ptr (not modified): pointer to next coarser level
69  object.
70  <li>a_problem_domain (not modified): problem domain of this level.
71  <li>a_level (not modified): index of this level. The base level is
72  zero.
73  <li>a_ref_ratio (not modified): the refinement ratio between this level
74  and the next finer level.
75  </ul>
76  */
77  virtual
78  void define(AMRLevel* a_coarser_level_ptr,
79  const Box& a_problem_domain,
80  int a_level,
81  int a_ref_ratio);
82 
83  ///
84  /**
85  Defines this AMRLevel.
86 
87  <ul>
88  <li>a_coarser_level_ptr (not modified): pointer to next coarser level
89  object.
90  <li>a_problem_domain (not modified): problem domain of this level.
91  <li>a_level (not modified): index of this level. The base level is
92  zero.
93  <li>a_ref_ratio (not modified): the refinement ratio between this level
94  and the next finer level.
95  </ul>
96  */
97  virtual
98  void define(AMRLevel* a_coarser_level_ptr,
99  const ProblemDomain& a_problem_domain,
100  int a_level,
101  int a_ref_ratio);
102 
103  ///
104  /**
105  Advances this level by one time step. Returns an estimate of the
106  new time step.
107 
108  This is a pure virtual function and MUST be defined in the derived
109  class.
110 
111  */
112  virtual
113  Real advance() = 0;
114 
115  ///
116  /**
117  Return true if the solution has converged to a steady state for this level.
118  Default version always returns false.
119  */
120  virtual
122  {
123  return false;
124  }
125 
126  ///
127  /**
128  Things to do after advancing this level by one time step.
129 
130  This is a pure virtual function and MUST be defined in the derived
131  class.
132 
133  */
134  virtual
135  void postTimeStep() = 0;
136 
137  ///
138  /**
139  Creates tagged cells for dynamic mesh refinement.
140 
141  This is a pure virtual function and MUST be defined in the derived
142  class.
143 
144  */
145  virtual
146  void tagCells(IntVectSet& a_tags) = 0;
147 
148  ///
149  /**
150  Creates tagged cells for mesh refinement at initialization.
151 
152  This is a pure virtual function and MUST be defined in the derived
153  class.
154 
155  */
156  virtual
157  void tagCellsInit(IntVectSet& a_tags) = 0;
158 
159  ///
160  /**
161  Performs any pre-regridding operations which are necessary.
162 
163  This is not a pure virtual function to preserve compatibility
164  with earlier versions of AMRLevel. The AMRLevel::preRegrid()
165  instantiation is a no-op.
166  */
167  virtual
168  void preRegrid(int a_base_level, const Vector<Vector<Box> >& a_new_grids);
169 
170  ///
171  /**
172  Redefines this level to have the specified domain a_new_grids.
173 
174  This is a pure virtual function and MUST be defined in the derived
175  class.
176 
177  */
178  virtual
179  void regrid(const Vector<Box>& a_new_grids) = 0;
180 
181  ///
182  /**
183  Performs any post-regridding operations which are necessary.
184 
185  This is not a pure virtual function to preserve compatibility
186  with earlier versions of AMRLevel. The AMRLevel::postRegrid()
187  instantiation is a no-op.
188  */
189  virtual
190  void postRegrid(int a_base_level);
191 
192  ///
193  /**
194  Initializes this level to have the specified domain a_new_grids.
195 
196  This is a pure virtual function and MUST be defined in the derived
197  class.
198 
199  */
200  virtual
201  void initialGrid(const Vector<Box>& a_new_grids) = 0;
202 
203  ///
204  /**
205  Performs operations required after the grid has been defined but
206  before data initialization. This will also be called after
207  readCheckpointLevel during a restart procedure with argument
208  a_restart set to true.
209 
210  Levels are accessed from finest to coarsest. The
211  AMRLevel::postInitialGrid() instantiation is a no-op.
212 
213  */
214  virtual
215  void postInitialGrid(const bool a_restart);
216 
217  ///
218  /**
219  Initializes data.
220 
221  This is a pure virtual function and MUST be defined in the derived
222  class.
223 
224  */
225  virtual
226  void initialData() = 0;
227 
228  ///
229  /**
230  Things to do after initialization.
231 
232  This is a pure virtual function and MUST be defined in the derived
233  class.
234 
235  */
236  virtual
237  void postInitialize() = 0;
238 
239  //! Override this method to have an AMRLevel subclass perform some
240  //! operation upon the conclusion of a simulation. This is called
241  //! when AMR::conclude() is called. The final step is passed to the
242  //! method.
243  //! \param a_step The last step in the simulation.
244  virtual void conclude(int a_step) const;
245 
246  /**
247  \name I/O functions
248  */
249  /**@{*/
250 
251 #ifdef CH_USE_HDF5
252  ///
253  /**
254  Writes checkpoint header.
255 
256  This is a pure virtual function and MUST be defined in the derived
257  class.
258 
259  */
260  virtual
261  void writeCheckpointHeader (HDF5Handle& a_handle) const = 0;
262 
263  ///
264  /**
265  Write checkpoint data for this level.
266 
267  This is a pure virtual function and MUST be defined in the derived
268  class.
269 
270  */
271  virtual
272  void writeCheckpointLevel (HDF5Handle& a_handle) const = 0;
273 
274  ///
275  /**
276  Reads checkpoint header.
277 
278  This is a pure virtual function and MUST be defined in the derived
279  class.
280 
281  */
282  virtual
283  void readCheckpointHeader (HDF5Handle& a_handle) = 0;
284 
285  ///
286  /**
287  Reads checkpoint data for this level.
288 
289  This is a pure virtual function and MUST be defined in the derived
290  class.
291 
292  */
293  virtual
294  void readCheckpointLevel (HDF5Handle& a_handle) = 0;
295 
296  ///
297  /**
298  Writes plot header.
299 
300  This is a pure virtual function and MUST be defined in the derived
301  class.
302 
303  */
304  virtual
305  void writePlotHeader (HDF5Handle& a_handle) const = 0;
306 
307  ///
308  /**
309  Write plot file for this level.
310 
311  This is a pure virtual function and MUST be defined in the derived
312  class.
313 
314  */
315  virtual
316  void writePlotLevel (HDF5Handle& a_handle) const = 0;
317 #endif
318 
319  //! This allows one to write a plot file in a non-HDF5 format. It is called only at
320  //! refinement level 0, so AMR data will have to be handled by the implementer.
321  //! \param a_prefix A prefix for the custom plot file name.
322  //! \param a_step The current time step.
323  virtual void writeCustomPlotFile(const std::string& a_prefix,
324  int a_step) const;
325 
326  /**@}*/
327 
328  /**
329  \name Parameter-setting functions
330  */
331  /**@{*/
332 
333  ///
334  /**
335  Sets the pointer-to-finer-level member to a_finer_level_ptr.
336  */
337  virtual
338  void finerLevelPtr(AMRLevel* a_finer_level_ptr);
339 
340  ///
341  /**
342  Sets the time step to a_dt.
343  */
344  virtual
345  void dt(Real a_dt);
346 
347  ///
348  /**
349  Sets the time to a_time.
350 
351  */
352  virtual
353  void time(Real a_time);
354 
355  ///
356  /**
357  Sets the initial dt multiplier to a_initial_dt_multiplier.
358  */
359  virtual
360  void initialDtMultiplier(Real a_initial_dt_multiplier);
361 
362  /**@}*/
363 
364  /**
365  \name Access functions
366  */
367  /**@{*/
368 
369  ///
370  /**
371  Returns the current value of the time step.
372 
373  */
374  virtual
375  Real dt() const;
376 
377  ///
378  /**
379  Returns the current value of the time on this level.
380  */
381  virtual
382  Real time() const;
383 
384  ///
385  /**
386  Returns the initial dt multiplier.
387  */
388  virtual
389  Real initialDtMultiplier() const;
390 
391  ///
392  /**
393  Returns the problem domain of this level.
394 
395  */
396  virtual
397  const ProblemDomain& problemDomain() const;
398 
399  ///
400  /**
401  Returns the domain of this level.
402 
403  */
404  virtual
405  Vector<Box> boxes() const;
406 
407  ///
408  /**
409  Returns true if any AMRLevel::define function has been called,
410  false otherwise.
411  */
412  bool isDefined() const;
413 
414  ///
415  /**
416  Returns true if a coarser level exists, is defined, and has a grid.
417  */
418  bool hasCoarserLevel() const;
419 
420  ///
421  /**
422  Returns true if a finer level exists, is defined, and has a grid.
423  */
424  bool hasFinerLevel() const;
425 
426  ///
427  /**
428  Returns the index of this level
429  */
430  virtual
431  int level() const;
432 
433  ///
434  /**
435  Returns the refinement ratio between this level and the next finer level.
436 
437  */
438  virtual
439  int refRatio() const;
440 
441  ///
442  /**
443  Returns maximum stable time step for this level.
444 
445  This is a pure virtual function and MUST be defined in the derived
446  class.
447 
448  */
449  virtual
450  Real computeDt() = 0;
451 
452  ///
453  /**
454  Returns maximum stable time step for this level with initial data.
455 
456  This is a pure virtual function and MUST be defined in the derived
457  class.
458 
459  */
460  virtual
461  Real computeInitialDt() = 0;
462 
463  //! Retrieve an array of all of the AMRLevel objects in the entire hierarchy.
465 
466  /**@}*/
467 
468  ///
469  /**
470  Returns current verbosity level. Minimum verbosity is 0, for
471  which nothing is printed.
472 
473  */
474  static
475  int verbosity();
476 
477  ///
478  /**
479  Sets verbosity level to a_verbosity. Minimum verbosity is 0, for
480  which nothing is printed.
481  */
482  static
483  void verbosity(int a_verbosity);
484 
485 protected:
486 
487  // verbosity level
488  static int s_verbosity;
489 
490  // the problem domain
492 
493  //
495 
496  // the level
497  int m_level;
498 
499  // refinement ratio between this level and the next finer
501 
502  // initial time step multipier
504 
505  // time step
507 
508  // time
510 
511  // pointer to next coarser level
513 
514  // pointer to next finer level
516 
518 };
519 
520 #include "NamespaceFooter.H"
521 #endif
virtual Real computeDt()=0
Vector< AMRLevel * > getAMRLevelHierarchy()
Retrieve an array of all of the AMRLevel objects in the entire hierarchy.
virtual ~AMRLevel()
bool m_isDefined
Definition: AMRLevel.H:517
virtual void tagCells(IntVectSet &a_tags)=0
virtual void writePlotLevel(HDF5Handle &a_handle) const =0
virtual Real computeInitialDt()=0
static int s_verbosity
Definition: AMRLevel.H:488
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
virtual void tagCellsInit(IntVectSet &a_tags)=0
virtual void postInitialGrid(const bool a_restart)
virtual int refRatio() const
one dimensional dynamic array
Definition: Vector.H:53
virtual Real dt() const
Abstract base class for time-dependent data at a level of refinement.
Definition: AMRLevel.H:47
bool isDefined() const
virtual void define(AMRLevel *a_coarser_level_ptr, const Box &a_problem_domain, int a_level, int a_ref_ratio)
virtual Vector< Box > boxes() const
virtual void postTimeStep()=0
Real m_time
Definition: AMRLevel.H:509
virtual void preRegrid(int a_base_level, const Vector< Vector< Box > > &a_new_grids)
virtual void writeCheckpointHeader(HDF5Handle &a_handle) const =0
virtual Real time() const
virtual void conclude(int a_step) const
virtual const ProblemDomain & problemDomain() const
ProblemDomain m_problem_domain
Definition: AMRLevel.H:491
Real m_initial_dt_multiplier
Definition: AMRLevel.H:503
virtual void initialGrid(const Vector< Box > &a_new_grids)=0
virtual Real initialDtMultiplier() const
virtual Real advance()=0
double Real
Definition: REAL.H:33
virtual void regrid(const Vector< Box > &a_new_grids)=0
Vector< Box > m_level_grids
Definition: AMRLevel.H:494
virtual void writePlotHeader(HDF5Handle &a_handle) const =0
bool hasCoarserLevel() const
static int verbosity()
virtual void finerLevelPtr(AMRLevel *a_finer_level_ptr)
virtual int level() const
int m_ref_ratio
Definition: AMRLevel.H:500
virtual void writeCheckpointLevel(HDF5Handle &a_handle) const =0
AMRLevel * m_coarser_level_ptr
Definition: AMRLevel.H:512
virtual bool convergedToSteadyState()
Definition: AMRLevel.H:121
AMRLevel * m_finer_level_ptr
Definition: AMRLevel.H:515
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
virtual void readCheckpointLevel(HDF5Handle &a_handle)=0
virtual void readCheckpointHeader(HDF5Handle &a_handle)=0
Real m_dt
Definition: AMRLevel.H:506
virtual void writeCustomPlotFile(const std::string &a_prefix, int a_step) const
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:292
int m_level
Definition: AMRLevel.H:497
virtual void postRegrid(int a_base_level)
virtual void postInitialize()=0
bool hasFinerLevel() const
virtual void initialData()=0