Chombo + EB  3.0
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  Things to do after advancing this level by one time step.
118 
119  This is a pure virtual function and MUST be defined in the derived
120  class.
121 
122  */
123  virtual
124  void postTimeStep() = 0;
125 
126  ///
127  /**
128  Creates tagged cells for dynamic mesh refinement.
129 
130  This is a pure virtual function and MUST be defined in the derived
131  class.
132 
133  */
134  virtual
135  void tagCells(IntVectSet& a_tags) = 0;
136 
137  ///
138  /**
139  Creates tagged cells for mesh refinement at initialization.
140 
141  This is a pure virtual function and MUST be defined in the derived
142  class.
143 
144  */
145  virtual
146  void tagCellsInit(IntVectSet& a_tags) = 0;
147 
148  ///
149  /**
150  Performs any pre-regridding operations which are necessary.
151 
152  This is not a pure virtual function to preserve compatibility
153  with earlier versions of AMRLevel. The AMRLevel::preRegrid()
154  instantiation is a no-op.
155  */
156  virtual
157  void preRegrid(int a_base_level, const Vector<Vector<Box> >& a_new_grids);
158 
159  ///
160  /**
161  Redefines this level to have the specified domain a_new_grids.
162 
163  This is a pure virtual function and MUST be defined in the derived
164  class.
165 
166  */
167  virtual
168  void regrid(const Vector<Box>& a_new_grids) = 0;
169 
170  ///
171  /**
172  Performs any post-regridding operations which are necessary.
173 
174  This is not a pure virtual function to preserve compatibility
175  with earlier versions of AMRLevel. The AMRLevel::postRegrid()
176  instantiation is a no-op.
177  */
178  virtual
179  void postRegrid(int a_base_level);
180 
181  ///
182  /**
183  Initializes this level to have the specified domain a_new_grids.
184 
185  This is a pure virtual function and MUST be defined in the derived
186  class.
187 
188  */
189  virtual
190  void initialGrid(const Vector<Box>& a_new_grids) = 0;
191 
192  ///
193  /**
194  Performs operations required after the grid has been defined but
195  before data initialization. This will also be called after
196  readCheckpointLevel during a restart procedure with argument
197  a_restart set to true.
198 
199  Levels are accessed from finest to coarsest. The
200  AMRLevel::postInitialGrid() instantiation is a no-op.
201 
202  */
203  virtual
204  void postInitialGrid(const bool a_restart);
205 
206  ///
207  /**
208  Initializes data.
209 
210  This is a pure virtual function and MUST be defined in the derived
211  class.
212 
213  */
214  virtual
215  void initialData() = 0;
216 
217  ///
218  /**
219  Things to do after initialization.
220 
221  This is a pure virtual function and MUST be defined in the derived
222  class.
223 
224  */
225  virtual
226  void postInitialize() = 0;
227 
228  //! Override this method to have an AMRLevel subclass perform some
229  //! operation upon the conclusion of a simulation. This is called
230  //! when AMR::conclude() is called. The final step is passed to the
231  //! method.
232  //! \param a_step The last step in the simulation.
233  virtual void conclude(int a_step) const;
234 
235  /**
236  \name I/O functions
237  */
238  /**@{*/
239 
240 #ifdef CH_USE_HDF5
241  ///
242  /**
243  Writes checkpoint header.
244 
245  This is a pure virtual function and MUST be defined in the derived
246  class.
247 
248  */
249  virtual
250  void writeCheckpointHeader (HDF5Handle& a_handle) const = 0;
251 
252  ///
253  /**
254  Write checkpoint data for this level.
255 
256  This is a pure virtual function and MUST be defined in the derived
257  class.
258 
259  */
260  virtual
261  void writeCheckpointLevel (HDF5Handle& a_handle) const = 0;
262 
263  ///
264  /**
265  Reads checkpoint header.
266 
267  This is a pure virtual function and MUST be defined in the derived
268  class.
269 
270  */
271  virtual
272  void readCheckpointHeader (HDF5Handle& a_handle) = 0;
273 
274  ///
275  /**
276  Reads checkpoint data for this level.
277 
278  This is a pure virtual function and MUST be defined in the derived
279  class.
280 
281  */
282  virtual
283  void readCheckpointLevel (HDF5Handle& a_handle) = 0;
284 
285  ///
286  /**
287  Writes plot header.
288 
289  This is a pure virtual function and MUST be defined in the derived
290  class.
291 
292  */
293  virtual
294  void writePlotHeader (HDF5Handle& a_handle) const = 0;
295 
296  ///
297  /**
298  Write plot file for this level.
299 
300  This is a pure virtual function and MUST be defined in the derived
301  class.
302 
303  */
304  virtual
305  void writePlotLevel (HDF5Handle& a_handle) const = 0;
306 #endif
307 
308  //! This allows one to write a plot file in a non-HDF5 format. It is called only at
309  //! refinement level 0, so AMR data will have to be handled by the implementer.
310  //! \param a_prefix A prefix for the custom plot file name.
311  //! \param a_step The current time step.
312  virtual void writeCustomPlotFile(const std::string& a_prefix,
313  int a_step) const;
314 
315  /**@}*/
316 
317  /**
318  \name Parameter-setting functions
319  */
320  /**@{*/
321 
322  ///
323  /**
324  Sets the pointer-to-finer-level member to a_finer_level_ptr.
325  */
326  virtual
327  void finerLevelPtr(AMRLevel* a_finer_level_ptr);
328 
329  ///
330  /**
331  Sets the time step to a_dt.
332  */
333  virtual
334  void dt(Real a_dt);
335 
336  ///
337  /**
338  Sets the time to a_time.
339 
340  */
341  virtual
342  void time(Real a_time);
343 
344  ///
345  /**
346  Sets the initial dt multiplier to a_initial_dt_multiplier.
347  */
348  virtual
349  void initialDtMultiplier(Real a_initial_dt_multiplier);
350 
351  /**@}*/
352 
353  /**
354  \name Access functions
355  */
356  /**@{*/
357 
358  ///
359  /**
360  Returns the current value of the time step.
361 
362  */
363  virtual
364  Real dt() const;
365 
366  ///
367  /**
368  Returns the current value of the time on this level.
369  */
370  virtual
371  Real time() const;
372 
373  ///
374  /**
375  Returns the initial dt multiplier.
376  */
377  virtual
378  Real initialDtMultiplier() const;
379 
380  ///
381  /**
382  Returns the problem domain of this level.
383 
384  */
385  virtual
386  const ProblemDomain& problemDomain() const;
387 
388  ///
389  /**
390  Returns the domain of this level.
391 
392  */
393  virtual
394  Vector<Box> boxes() const;
395 
396  ///
397  /**
398  Returns true if any AMRLevel::define function has been called,
399  false otherwise.
400  */
401  bool isDefined() const;
402 
403  ///
404  /**
405  Returns true if a coarser level exists, is defined, and has a grid.
406  */
407  bool hasCoarserLevel() const;
408 
409  ///
410  /**
411  Returns true if a finer level exists, is defined, and has a grid.
412  */
413  bool hasFinerLevel() const;
414 
415  ///
416  /**
417  Returns the index of this level
418  */
419  virtual
420  int level() const;
421 
422  ///
423  /**
424  Returns the refinement ratio between this level and the next finer level.
425 
426  */
427  virtual
428  int refRatio() const;
429 
430  ///
431  /**
432  Returns maximum stable time step for this level.
433 
434  This is a pure virtual function and MUST be defined in the derived
435  class.
436 
437  */
438  virtual
439  Real computeDt() = 0;
440 
441  ///
442  /**
443  Returns maximum stable time step for this level with initial data.
444 
445  This is a pure virtual function and MUST be defined in the derived
446  class.
447 
448  */
449  virtual
450  Real computeInitialDt() = 0;
451 
452  //! Retrieve an array of all of the AMRLevel objects in the entire hierarchy.
454 
455  /**@}*/
456 
457  ///
458  /**
459  Returns current verbosity level. Minimum verbosity is 0, for
460  which nothing is printed.
461 
462  */
463  static
464  int verbosity();
465 
466  ///
467  /**
468  Sets verbosity level to a_verbosity. Minimum verbosity is 0, for
469  which nothing is printed.
470  */
471  static
472  void verbosity(int a_verbosity);
473 
474 protected:
475 
476  // verbosity level
477  static int s_verbosity;
478 
479  // the problem domain
481 
482  //
484 
485  // the level
486  int m_level;
487 
488  // refinement ratio between this level and the next finer
490 
491  // initial time step multipier
493 
494  // time step
496 
497  // time
499 
500  // pointer to next coarser level
502 
503  // pointer to next finer level
505 
507 };
508 
509 #include "NamespaceFooter.H"
510 #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:506
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:477
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:130
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:52
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:498
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:480
Real m_initial_dt_multiplier
Definition: AMRLevel.H:492
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:483
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:489
virtual void writeCheckpointLevel(HDF5Handle &a_handle) const =0
AMRLevel * m_coarser_level_ptr
Definition: AMRLevel.H:501
AMRLevel * m_finer_level_ptr
Definition: AMRLevel.H:504
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:495
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:267
int m_level
Definition: AMRLevel.H:486
virtual void postRegrid(int a_base_level)
virtual void postInitialize()=0
bool hasFinerLevel() const
virtual void initialData()=0