Chombo + EB + MF  3.2
LevelGridMetrics.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 _LEVELGRIDMETRICS_H_
12 #define _LEVELGRIDMETRICS_H_
13 
14 
15 /******************************************************************************/
16 /**
17  * \file
18  *
19  * \brief Grid metrics on and between levels.
20  *
21  *//*+*************************************************************************/
22 
23 #include "AMRLevel.H"
24 #include "CodimBox.H"
25 #include "CoarseAverageFace.H"
26 #include "CoarseAverageCodim.H"
27 #include "MultiBlockCoordSys.H"
28 #include "NewFourthOrderCoordSys.H"
30 #include "MultiBlockLevelGeom.H"
32 #include "MultiBlockFaceRegister.H"
33 
34 #include "NamespaceHeader.H"
35 
36 //--Forward declarations
37 
38 class TimeInterpolatorRK4; // (part of timeIntermediate hack)
39 
40 // //--Debug support
41 
42 // extern int LGMDebug;
43 
44 
45 /*******************************************************************************
46  */
47 /// Average from fine intersections
48 /**
49  * The objective of this class is to average down information from A^(l+1)
50  * to C^(l) but only on the intersection of A^(l+1) and B^(l+1). This class
51  * is designed to support class 'LevelGridMetrics' where A is the snapback
52  * flux on the old fine mesh, B is the new mesh, and C (= A^l) is the snapback
53  * flux on the old coarse mesh. These are the steps (Cr is coarsen operator):
54  * <ol>
55  * <li> Average A^(l+1) to D^(l) on boxes of Cr(A^(l+1)). This step is
56  * performed at level 'l+1'. D and the coarsened box layout of A are
57  * saved.
58  * <li> Now at level 'l', copy to E^(l) on boxes of C^(l). These first two
59  * steps are done in the averager
60  * <li> Compute mask for each box of C^(l). The mask is the
61  * intersection of Cr(A^(l+1)), Cr(B^(l+1)), and C^(l)
62  * <li> Copy from E^(l) to C^(l) using the mask.
63  * </ol>
64  *
65  ******************************************************************************/
66 
68 {
69 public:
70 
71  /// Constructor
73  const int a_nRef);
74 
75  // Use synthesized destructor
76 
77  /// Copy the average using a mask
78  void copyTo(LevelData<FluxBox>& a_C,
79  const DisjointBoxLayout& a_dblB);
80 
81 private:
82 
83  // Copy and assignment not allowed
86 
87 protected:
88 
89  const int m_nComp; ///< Number of components in A (same as C)
90  const int m_nRef; ///< Refinement between A & C
91  DisjointBoxLayout m_crDblA; ///< Coarsened layout for A
92  CoarseAverageFace m_averager; ///< The averager itself stores the
93  ///< averaged data between averaging and
94  ///< copying
95 };
96 
97 
98 /*******************************************************************************
99  */
100 /// Grid metrics for a level
101 /**
102  * This class adds infrastructure for mapped grids to the fourth-order
103  * Cartesian AMRLevel class. The interface closely follows that of
104  * AMRLevel. Typically this class is a member of the user's derived
105  * AMRLevel and the member functions of LevelGridData should be called
106  * from member functions of the derived AMRLevel that have the same name.
107  *
108  * <p> This class provides m_N, the metric terms \f$\mathbf(N)\f$ on each
109  * face, and m_J, the determinant (physical cell volume divided by
110  * computational cell volume). These quantities are appropriately maintained
111  * during all aspects of an AMR solution.
112  *
113  * <p> GHOSTS --- The determinants, (J), are defined on all ghost cells at
114  * the domain interior and 1 layer of ghost cells outside a non-periodic
115  * domain. Hence, gradients of J are available everywhere an application may
116  * store data. To achieve this, it is assumed that the metrics can be
117  * evaluated everywhere in \f$\mathcal(G)(\Gamma,2)\f$.
118  * HOWEVER, metrics that are consistent between levels are only maintained in
119  * the valid region of the finer level. A valid cell on a coarse level will
120  * have metrics computed separately from any overlapping ghost cells from a
121  * finer level (i.e., the volumes of the fine ghost cells may not sum to the
122  * volume of the valid coarse cell). Consistency between levels everywhere
123  * could be achieved by treating all ghost cells as part of the valid region
124  * --- this would simply (probably simply) require some modifications to the
125  * "averagers". However we do not do this because:
126  * <ul>
127  * <li> it breaks a consistent definition of valid/invalid
128  * <li> there is no requirement for conservation in ghost cells since they
129  * are only used for gradient reconstruction, limiting, etc.
130  * </ul>
131  * Any ghost cell that is covered by a valid cell on that level is consistent
132  * with the metrics from any finer level by means of the copiers (used in
133  * the averagers) copying to both the invalid and valid regions of a
134  * destination.
135  * <p>
136  * Transverse terms in N are determined only on the faces of grow(N.box(), -1)
137  * if obtained by averaging, i.e., on one less layer than where the normal
138  * components are known. If obtained by analytic methods, they are available
139  * everywhere.
140  *
141  * <p> Normally, N is calculated using script N to ensure freestream
142  * preservation. But in some cases, e.g., a 2-D solution on the surface of
143  * a sphere, there is no definition of script N. In those cases,
144  * m_useScriptN should be set to false and N will be calculated and averaged
145  * directly. The averaging ensures conservation but freestream-preservation
146  * is sacrificed. The value of m_useScriptN is obtained from the
147  * MultiBlockCoordSys and should be set to 'false' in the constructor of
148  * coordinate systems derived from class MultiBlockCoordSys. Otherwise, by
149  * default, it is set to true.
150  *
151  * <p>
152  * The following routines should be called from the corresponding routines
153  * with the same name derived AMRLevel:
154  * <ul>
155  * <li> initialGrid
156  * <li> postInitialGrid
157  * <li> postTimeStep
158  * <li> preRegrid
159  * <li> regrid
160  * </ul>
161  *
162  * <p> Setup for the class is as follows:
163  * <ol>
164  * <li> Call define to setup the class members -- metrics are still
165  * undefined.
166  * <li> Optionally call initialGrid to set the new box layout on a level.
167  * This can be deferred until postInitialGrid if desired.
168  * <li> Call postInitialGrid to set the new box layout (if not done in
169  * previous step) and define the metrics.
170  * </ol>
171  *
172  * <p> During a run, be sure to:
173  * <ol>
174  * <li> Call postTimeStep to average down the metric terms from finer
175  * levels. This only has an effect if they changed on the finer
176  * level
177  * </ol>
178  *
179  * <p> For a regrid do the following:
180  * <ol>
181  * <li> Call preRegrid to compute the new metrics and correct the solution
182  * on the old mesh to the metrics of the new mesh (snapback).
183  * <li> Optionally call regrid to interpolate from the coarse mesh to
184  * the new fine mesh. This can be done is user code but must
185  * use FourthOrderMappedFineInterp to ensure a conservative and
186  * free-stream preserving interpolation on the mapped grid.
187  * </ol>
188  *
189  * \note
190  * <ul>
191  * <li> To facilitate products that involve gradients, the metrics (N) are
192  * determined on the faces of boxes with size ghostBox+2. This is
193  * labeled an 'NReqGhostBox' herein. At domain boundaries, the boxes
194  * for 'N' extend by 2 cells outside the physical domain and it is
195  * assumed that the mappings exist there. The determinants (J) are
196  * determined on the cells of boxes with size ghostBox+1. This is
197  * labeled a 'JReqGhostBox' herein. At domain boundaries, the boxes
198  * for 'J' extends by 1 cell outside the physical domain
199  * <li> Averages of fluxes. Most of the fluxes, <F>\ are stored as average
200  * quantities to be applied to a face and do not include area
201  * information. I.e., the actual flux across a 2-D face is
202  * \f$\langle F\rangle h^2\f$ Hence when correcting from fine to
203  * coarse, you want to average the fine <F> and then muliply by the
204  * area of the coarse face (although in most equations, the area
205  * cancels out with another term). However, the \f$\mathcal(N)^s\f$,
206  * which are a type of flux, are stored differently in that they have
207  * already been multiplied by the length term (equivalent to
208  * \f$\langle F\rangle h^2\f$ in the example above). Hence, these
209  * fluxes needed to be summed when correcting from coarse to fine.
210  * <li> WARNING! If transverse components of <N> are computed analytically,
211  * they are only averaged down when finer levels have changed before
212  * entering a postTimeStep (along with normal components).
213  * Consequently, it is currently difficult to know if they have been
214  * computed or averaged from a finer level at any given point. But
215  * note that if transverse components of <N> are computed by averaging
216  * from normal components, then they should always be consistent.
217  * **FIXME -- probably the best fix is to only average the normal
218  * components if transverse are computed analytically.
219  * </ul>
220  *
221  *//*+*************************************************************************/
222 
224 {
225 
226 public:
227 
228  /// Age of metric terms during a regrid
229  enum AgeType
230  {
231  AgeOld = 0,
232  AgeNew = 1,
233  AgeNum = 2
234  };
235 
236  /// Type of operation for computing transverse terms in N
238  {
240  TransverseNOpAnalytic, // Analytic calculation
241  TransverseNOpAverage // Average from normals on nearby
242  // transverse faces
243  };
244 
245 
246 /*==============================================================================
247  * Constructors and destructors
248  *============================================================================*/
249 
250 public:
251 
252  /// Constructor
253  LevelGridMetrics(const int a_nComp,
254  const int a_spaceOrder);
255 
256  /// Destructor
257  virtual ~LevelGridMetrics();
258 
259 private:
260 
261  // Copy and assignment not allowed
264 
265 
266 /*==============================================================================
267  * Member functions
268  *============================================================================*/
269 
270 public:
271 
272  /// Free memory
273  void clear();
274 
275  /// Does a finer level exist?
276  bool hasFiner() const;
277 
278  /// Does a coarser level exist?
279  bool hasCoarser() const;
280 
281  /// Define the class. No metrics terms are yet available.
282  void define(
283  AMRLevel *const a_AMRLevel,
284  MultiBlockCoordSysFactory *const a_coordSysFact,
285  LevelGridMetrics *const a_coarserLevelGridMetrics,
286  const RealVect& a_dxVect,
287  const IntVect& a_ghostVect,
288  const TransverseNOpType a_transverseNOpType = TransverseNOpNone,
289  const bool a_haveMultiBlockVectorData = true,
290 //**FIXME do we need this?
291  const int a_numBlocks = 1);
292 
293  /// Define the class. No metrics terms are yet available.
294  void define(
295  AMRLevel *const a_AMRLevel,
296  MultiBlockCoordSys *const a_coordSys,
297  LevelGridMetrics *const a_coarserLevelGridMetrics,
298  const RealVect& a_dxVect,
299  const IntVect& a_ghostVect,
300  const TransverseNOpType a_transverseNOpType = TransverseNOpNone,
301  const bool a_haveMultiBlockVectorData = true,
302 //**FIXME do we need this?
303  const int a_numBlocks = 1);
304 
305  /// Are the metrics defined on this level?
306  bool metricsDefined() const;
307 
308  /// Did the metrics change on the finer mesh?
309  bool didFinerChange() const;
310 
311  /// Retrieve the multi-block coordinate system.
312  const MultiBlockCoordSys& getCoordSys() const;
313 
314  /// Get the coordinate system
315  /* Are we ever going to use a second-order system? If so, I assume the
316  * CoordSys routines will be virtualized such that getCoordSys2 can be
317  * changed to getCoordSys and the cast will be unnecessary.
318  */
319  const NewCoordSys* getCoordSys2(const Box& box) const;
320 
321  ///
322  const NewFourthOrderCoordSys* getCoordSys(const Box& box) const;
323 
324  /// Get the block index
325  int getBlock(const Box& a_box) const;
326 
327  /// Get a problem domain representing a block
328  const ProblemDomain& blockDomain(const Box& a_box, const int a_numGhost = 0);
329 
330  /// Get the computational mesh spacing
331  const RealVect& dxVect() const;
332 
333 //--AMRLevel extensions
334 
335  /// After a time step, average down \f$N\f$ and \f$J\f$
336  void postTimeStep();
337 
338  /// Set up initial grid
339  virtual void initialGrid(const DisjointBoxLayout *const a_newGrid);
340 
341  /// Set up the initial metric terms.
342  void postInitialGrid(const DisjointBoxLayout *const a_newGrid);
343 
344  /// Compute new metrics and correct the solution on the coarser meshes
345  void preRegrid(const int a_baseLevel,
346  const DisjointBoxLayout& a_newGrid,
347  const LevelData<FArrayBox> *const a_coarseUOldPtr,
348  LevelData<FArrayBox>& a_UOld,
349  LevelData<FArrayBox>& a_JUOld);
350 
351  /// Regrid operations -- performs a coarse to fine interpolation
352  virtual void regrid(LevelData<FArrayBox>& a_JU,
353  const LevelData<FArrayBox>& a_CrU,
354  const LevelData<FArrayBox>& a_CrJU,
355  const Interval& a_vectorIntv);
356 
357 // /// Post regrid operations -- currently unused.
358 // void postRegrid(int a_base_level);
359 
360 //--Convenience
361 
362  /// Fill invalid fine ghost cells (with preset CrFnU)
363  virtual void fillFineGhostCells(LevelData<FArrayBox>& a_U,
364  LevelData<FArrayBox>& a_JU,
365  Real a_time = -1);
366 
367  /// Computes <U> in valid cells
368  void computeValidU(LevelData<FArrayBox>& a_U,
369  const LevelData<FArrayBox>& a_JU);
370 
371  /// Compute the minimum grid buffer size for a fourth-order interpolation
372  static int bufferSize4thO(const std::vector<int>& a_refRatio,
373  const int a_maxLevel,
374  const int a_numGhost);
375 
376  /// Exchange <U> across multiblock boundaries
377  void multiblockExchangeU(LevelData<FArrayBox>& a_U,
378  const Interval& a_vectorIntv) const;
379 
380  /// Supports a call to TimeInterpolatorRK4::intermediate for multi-block grids
381  void timeIntermediate(const TimeInterpolatorRK4& a_timeInterpolator,
382  const Real& a_timeInterpCoeff,
383  const int& a_stage,
384  const Interval& a_vectorIntv);
385 
386 //--Consistent access to structural boxes
387 
388  /// Get the boxes
389  const DisjointBoxLayout& getBoxes() const;
390 
391  /// Get a level iterator
392  DataIterator getDataIterator() const;
393 
394  /// Resize a box to include the ghost cells
395  Box resizeWithGhosts(const Box& box) const;
396 
397  /// Determine the ghost vector required for \f$J\f$.
398  virtual IntVect getJReqGhostVect() const;
399 
400  /// Determine the ghost vector required for \f$N\f$.
401  virtual IntVect getNReqGhostVect() const;
402 
403  /// Resize a box to the size required for \f$J\f$
404  Box resizeWithJReqGhosts(const Box& box) const;
405 
406  /// Resize a box to the size required for \f$N\f$
407  Box resizeWithNReqGhosts(const Box& box) const;
408 
409 //--Access to the interpolator's temporary structures
410 
411  /*
412  * The following return a coarsened representation of 'this' level, i.e.,
413  * 'this' is the fine level.
414  */
415 
416  /// Set the coarsened-fine <U> used by the interpolator (CrFn access)
417  LevelData<FArrayBox>& presetCr2ThisInterpolatorCrFnLevU();
418 
419  /// Set the coarsened-fine <JU> used by the interpolator (CrFn access)
420  LevelData<FArrayBox>& presetCr2ThisInterpolatorCrFnLevJU();
421 
422 // Obsolete
423  // /// Get the coarsened-fine <U> used by the interpolator
424  // const LevelData<FArrayBox>& getCr2ThisInterpolatorCrFnLevU() const;
425 
426  // /// Get the coarsened-fine <JU> used by the interpolator
427  // const LevelData<FArrayBox>& getCr2ThisInterpolatorCrFnLevJU() const;
428 
429  /*
430  * The following make use of the coarse data on 'this' level, i.e., 'this' is
431  * the coarse level.
432  */
433 
434  /// Set the coarsened-fine <U> used by the interpolator
435  void presetThis2FnInterpolatorCrFnLevU(
436  const LevelData<FArrayBox>& a_CrLevU,
437  const Interval& a_vectorIntv);
438 
439 // Should not be used
440  // /// Set the coarsened-fine <JU> used by the interpolator
441  // void presetThis2FnInterpolatorCrFnLevJU(
442  // const LevelData<FArrayBox>& a_CrLevJU);
443 
444  /// Invalidate the CrFn data, both <U> and <JU>\, used by the interpolator
445  void invalidateCr2ThisInterpolatorCrFnLevData();
446 
447  /// Invalidate the CrFn data, both <U> and <JU>\, used by the interpolator
448  void invalidateThis2FnInterpolatorCrFnLevData();
449 
450  /// Number of ghosts used to build the coarsened-fine data in the interpolator
451  const IntVect& interpolatorCrFnNumGhost(const bool a_force = false) const;
452 
453  /// Is this a multiblock grid
454  bool isMultiblock() const;
455 
456  ///
457  const ProblemDomain& problemDomain() const;
458 
459 protected:
460 
461 //--Easier access to AMRLevel data (these are also defined in AMRLevel.H).
462 
463  ///
464  int level() const;
465 
466  ///
467  int refRatio() const;
468 
469  ///
470  static int verbosity();
471 
472 //--Internal
473 
474  /// Completely define the metrics for this level
475  void defineMetrics();
476 
477  /// Label this and all finer levels as having undefined metrics
478  void undefineMetrics();
479 
480  /// Compute \f$N\f$ on the hyperfaces from \f$\mathcal{N}^s\f$
481  // Only used if m_useScriptN == true
482  void faceNormalN(LevelData<FluxBox>& a_N,
483  const LevelData<CodimBox <FArrayBox> >& a_scrN);
484 
485  /// Compute \f$N\f$ on the hyperfaces from \f$\mathcal{N}^s\f$
486  // Only used if m_useScriptN == false
487  void getN(LevelData<FluxBox>& a_N);
488 
489  /// Add transverse components to \f$N\f$
490  void faceTransverseN(LevelData<FluxBox>& a_N);
491 
492  /// Integrate \f$\mathcal{N}^s\f$ on each hyperedge
493  void getScriptN(LevelData<CodimBox<FArrayBox> >& a_scrN);
494 
495  /// Average \f$\mathcal{N}^s\f$
496  // Only used if m_useScriptN == true
497  void averageScriptN(const bool a_isBase,
498  LevelData<CodimBox<FArrayBox> >& a_scrN);
499 
500  /// Average \f$N\f$ directly if \f$\mathcal{N}^s\f$ doesn't exist.
501  // Only used if m_useScriptN == false
502  void averageN(const bool a_isBase,
503  LevelData<FluxBox>& a_N);
504 
505  /// Compute the volume flux
506  void getVolFlux(LevelData<FluxBox>& a_NtX,
507  const LevelData<FluxBox>& a_N);
508 
509  /// Take divergence of \f$N^T X\f$ to set m_J.
510  virtual void setAvgJfromNtX(LevelData<FluxBox>& a_NtX);
511 
512  /// Average the volume flux \f$N^T X\f$.
513  void averageVolFlux(const bool a_isBase,
514  LevelData<FluxBox>& a_NtX,
515  const AgeType a_age);
516 
517  /// Compute \f$N^T X\f$ on all finer levels and average down
518  void volFluxCascade();
519 
520  /// Average the snapback solution flux, \f$N^T F\f$.
521  void averageSnapbackSolFlux(const bool a_isBase,
522  LevelData<FluxBox>& a_NtFDiff);
523 
524  /// Store the DisjointBoxLayout and define multiblock structures
525  virtual void defineGrids(const DisjointBoxLayout& a_grids);
526 
527  /// Create a non-periodic DisjointBoxLayout
528  void defineGridsNP(const DisjointBoxLayout& a_grids);
529 
530 
531 /*==============================================================================
532  * Data members
533  *============================================================================*/
534 
535 public:
536 
537  LevelData<FluxBox> m_N; ///< \f$\mathbf(N)\f$ on each face
538  LevelData<FArrayBox> m_J; ///< Physical cell volume divided by
539  ///< computational cell volume
540 
541 protected:
542 
543 //--Single-block
544 
545  // The following averagers are not defined on the finest level
546  CoarseAverageCodim* m_scrNAverager; ///< Averager for \f$\mathcal(N)^s\f$.
547  ///< Only used if m_useScriptN == true
548  CoarseAverageFace* m_NAverager; ///< Averager for \f$N\f$
549  ///< Only used if m_useScriptN == false
550  CoarseAverageFace* m_NtXAverager[AgeNum];
551  ///< This averages the volume flux from a
552  ///< finer level. Averagers exist for old
553  ///< "AgeOld" and new "AgeNew" meshes
554  ///< during a regrid
556  ///< Averager for the snapback solution
557  ///< flux. This averager only operates
558  ///< on the intersections of three
559  ///< layouts.
560 
561  MultiBlockCoordSys* m_coordSys; ///< The multi-block coordinate system.
562 
564  ///< Grid metrics on the next finer level
566  ///< Grid metrics on the next coarser
567  ///< level
568 
569  AMRLevel* m_parentAMRLevel; ///< The AMR level we are attached to
570 
571  IntVect m_ghostVect; ///< Ghost cell vector
572  DisjointBoxLayout m_grids; ///< Grid layout
573  DisjointBoxLayout m_gridsNP; ///< Non-periodic grid layout. This is a
574  ///< shallow copy of m_grids, with a non-
575  ///< periodic problem domain and a new
576  ///< neighbor iterator if problemDomain()
577  ///< is periodic.
578  RealVect m_dxVect; ///< Mesh spacing in each direction
579  const int m_spaceOrder; ///< Spatial-order of accuracy - must be 4
580 
581 //--AMR tools
582 
584  ///< Constrained least-squares
585  ///< interpolator for interpolating <JU>
586  ///< from coarse to fine meshes. 'This'
587  ///< mesh is the coarse mesh.
588 
589 //--Multiblock tools
590 
591  ProblemDomain m_cachedBlockDomain; ///< Representing only the block (it is
592  ///< assumed periodic boundaries are not
593  ///< used for multiblock)
594  int m_cachedBlockIdx; ///< Index of the cached block
595  int m_cachedBlockNG; ///< Number of ghosts that the cached
596  ///< block was grown by.
597  MultiBlockLevelGeom m_mbgeo; ///< Topology of the multiblock layout
599  ///< To exchange information across
600  ///< multiblock boundaries
601  MultiBlockFaceRegister* m_Nmbreg; ///< Flux-like register for resolving
602  ///< \f$\mathbf{N}\f$ on faces at coarse-
603  ///< fine interfaces that overlap
604  ///< multiblock boundaries
605  MultiBlockFaceRegister* m_NtXmbreg[AgeNum];
606  ///< Flux-like register for resolving
607  ///< \f$\mathbf{N}^T\mathbf{X}\f$ on faces
608  ///< at coarse-fine interfaces that
609  ///< overlap multiblock boundaries
610 
611 //--Miscellaneous/flags
612 
614  ///< Type of operatation for computing
615  ///< transverse terms in N
616  bool m_metricsChanged; ///< T - The metrics on this level have
617  ///< changed
618  bool m_metricsDefined; ///< T - The metrics have been defined for
619  ///< this level
620  bool m_useScriptN; ///< For some mappings, it is not possible
621  ///< to define scriptN. In those cases,
622  ///< N is calculated and averaged
623  ///< directly. The solution is
624  ///< conservative but freestream-
625  ///< preservation is lost across coarse-
626  ///< fine interfaces.
627  ///< T - Script N is used (default).
628  ///< F - Script N is not used. N is
629  ///< calculated directly and
630  ///< freestream preservation is lost
631  bool m_isMultiblock; ///< T - A multiblock coordinates system
632  bool m_haveMultiBlockVectorData; ///< T - Space vector data will be
633  ///< exchanged across multiblock
634  ///< boundaries
635 
636  static int s_verbosity;
637 };
638 
639 
640 /*******************************************************************************
641  *
642  * Class LevelGridMetrics: inline member definitions
643  *
644  ******************************************************************************/
645 
646 /*--------------------------------------------------------------------*/
647 // Are the metrics defined on this level?
648 /** After preRegrid, this also indicates if a level is used.
649  * \return T - yes.
650  *//*-----------------------------------------------------------------*/
651 
652 inline bool
654 {
655  return m_metricsDefined;
656 }
657 
658 /*--------------------------------------------------------------------*/
659 // Did the metrics change on the finer mesh?
660 /** \return T - yes.
661  *//*-----------------------------------------------------------------*/
662 
663 inline bool
665 {
666  return m_finerLevelGridMetrics->m_metricsChanged;
667 }
668 
669 /*--------------------------------------------------------------------*/
670 // Get the coordinate system
671 /** \param[in] box Assigned to this box
672  *//*-----------------------------------------------------------------*/
673 
674 inline const NewCoordSys*
676 {
677  return m_coordSys->getCoordSys(box);
678 }
679 
680 inline const MultiBlockCoordSys&
682 {
683  return *m_coordSys;
684 }
685 
686 #if 0
687 /*--------------------------------------------------------------------*/
688 // Get the coordinate system
689 /** \param[in] dit Assigned to this data iterator
690  *//*-----------------------------------------------------------------*/
691 
692 inline const NewCoordSys*
694 {
695  return m_coordSys->getCoordSys(m_grids[dit()]);
696 }
697 #endif
698 
699 /*--------------------------------------------------------------------*/
700 // Get the "fourth-order" coordinate system
701 /** \param[in] box Assigned to this box
702  *//*-----------------------------------------------------------------*/
703 
704 inline const NewFourthOrderCoordSys*
706 {
707  return static_cast<const NewFourthOrderCoordSys*>(m_coordSys->getCoordSys(box));
708 }
709 
710 #if 0
711 /*--------------------------------------------------------------------*/
712 // Get the "fourth-order" coordinate system
713 /** \param[in] dit Assigned to this data iterator
714  *//*-----------------------------------------------------------------*/
715 
716 inline const NewFourthOrderCoordSys*
718 {
719  return static_cast<const NewFourthOrderCoordSys*>(m_coordSys->getCoordSys(m_grids[dit()]));
720 }
721 #endif
722 
723 /*--------------------------------------------------------------------*/
724 // Get the block index
725 /** \param[in] a_box Assigned to this interior box
726  * \return Block index
727  *//*-----------------------------------------------------------------*/
728 
729 inline int
730 LevelGridMetrics::getBlock(const Box& a_box) const
731 {
732  return m_coordSys->whichBlock(a_box);
733 }
734 
735 /*--------------------------------------------------------------------*/
736 // Get a problem domain representing a block
737 /** \param[in] a_box Assigned to this interior box
738  * \param[in] a_numGhost
739  * The number of ghosts that the box representing
740  * the block should be grown by before cropping.
741  * Cropping *only* occurs at boundaries defined
742  * by the physical domain
743  * \return If singleblock, the problem domain. If
744  * multiblock, non-periodic problem domain
745  * representing the block
746  * \note
747  * <ul>
748  * <li> If single block, the problem domain must be cached when
749  * the coordSys is defined
750  * </ul>
751  *//*-----------------------------------------------------------------*/
752 
753 inline const ProblemDomain&
754 LevelGridMetrics::blockDomain(const Box& a_box, const int a_numGhost)
755 {
756  if (isMultiblock())
757  {
758  CH_assert(a_numGhost >= 0);
759  const int iBlock = getBlock(a_box);
760  CH_assert(iBlock >= 0);
761  if (iBlock != m_cachedBlockIdx || a_numGhost != m_cachedBlockNG)
762  {
763  m_cachedBlockIdx = iBlock;
764  m_cachedBlockNG = a_numGhost;
765  // Find the problem domain representing the block
766  Box grownBlock =
767  grow(m_coordSys->mappingBlocks()[iBlock], a_numGhost);
768  if (a_numGhost > 0)
769  {
770  m_coordSys->keepInDomain(grownBlock, iBlock);
771  }
772  m_cachedBlockDomain.define(grownBlock);
773  }
774  }
775  return m_cachedBlockDomain;
776 }
777 
778 /*--------------------------------------------------------------------*/
779 // Get the computational mesh spacing
780 /** \return Mesh spacing in each direction
781  *//*-----------------------------------------------------------------*/
782 
783 inline const RealVect&
785 {
786  return m_dxVect;
787 }
788 
789 
790 /*====================================================================*/
791 /** \name Consistent access to structural boxes
792  *
793  * There are several places to get the boxes and interators from but
794  * all should be the same. These functions provide consistent
795  * access with sizes relevant to the metrics.
796  *//*=================================================================*/
797 //@{
798 
799 // Get the boxes
800 inline const DisjointBoxLayout&
802 {
803  return m_grids;
804 }
805 
806 // Get a level iterator
807 inline DataIterator
809 {
810  return getBoxes().dataIterator();
811 }
812 
813 // Resize a box to include the ghost cells (defines J)
814 inline Box
816 {
817  return grow(box, m_ghostVect);
818 }
819 
820 // Determine the ghost vector required for \f$J\f$.
821 /** This is +1 over the ghost box to allow for derivatives needed
822  * to manipulate products
823  */
824 inline IntVect
826 {
827  return IntVect::Unit;
828 }
829 
830 // Determine the ghost vector required for \f$N\f$.
831 /** This is +2 over the ghost box to allow for tangential derivatives needed
832  * to compute the volume flux
833  */
834 inline IntVect
836 {
837  return 2*IntVect::Unit;
838 }
839 
840 // Resize a box to the size required for \f$J\f$
841 inline Box
843 {
844  return grow(box, getJReqGhostVect());
845 }
846 
847 // Resize a box to the size required for \f$N\f$
848 inline Box
850 {
851  return grow(box, getNReqGhostVect());
852 }
853 //@}
854 
855 
856 /*====================================================================*/
857 /** \name Easier access to AMRLevel data
858  *//*=================================================================*/
859 //@{
860 
861 inline int
863 {
864  return m_parentAMRLevel->level();
865 }
866 
867 inline int
869 {
870  return m_parentAMRLevel->refRatio();
871 }
872 
873 inline const ProblemDomain&
875 {
876  return m_parentAMRLevel->problemDomain();
877 }
878 //@}
879 
880 /*--------------------------------------------------------------------*/
881 // Set the coarsened-fine <U> used by the interpolator (CrFn access)
882 /** Grids must have been defined for the interpolator. Returns a
883  * coarsening of 'this' level to be filled externally using a copyTo.
884  * 'this' is the fine level. I.e., 'this' is the fine level.
885  *//*-----------------------------------------------------------------*/
886 
887 inline LevelData<FArrayBox>&
889 {
890  CH_assert(hasCoarser());
891  return m_coarserLevelGridMetrics->m_interpolator->presetCrFnLevU();
892 }
893 
894 /*--------------------------------------------------------------------*/
895 // Set the coarsened-fine <JU> used by the interpolator (CrFn access)
896 /** Grids must have been defined for the interpolator. Returns a
897  * coarsening of 'this' level to be filled externally using a copyTo.
898  * 'this' is the fine level. I.e., 'this' is the fine level.
899  *//*-----------------------------------------------------------------*/
900 
901 inline LevelData<FArrayBox>&
903 {
904  CH_assert(hasCoarser());
905  return m_coarserLevelGridMetrics->m_interpolator->presetCrFnLevJU();
906 }
907 
908 // Obsolete
909 // /*--------------------------------------------------------------------*/
910 // // Get the coarsened-fine <U> used by the interpolator
911 // /** Grids must have been defined for the interpolator. Returns a
912 // * coarsening of 'this' level. I.e., 'this' is the fine level.
913 // *//*-----------------------------------------------------------------*/
914 
915 // inline const LevelData<FArrayBox>&
916 // LevelGridMetrics::getCr2ThisInterpolatorCrFnLevU() const
917 // {
918 // CH_assert(hasCoarser());
919 // return m_coarserLevelGridMetrics->m_interpolator.getCrFnLevU();
920 // }
921 
922 // /*--------------------------------------------------------------------*/
923 // // Get the coarsened-fine <JU> used by the interpolator
924 // /** Grids must have been defined for the interpolator. Returns a
925 // * coarsening of 'this' level. I.e., 'this' is the fine level.
926 // *//*-----------------------------------------------------------------*/
927 
928 // inline const LevelData<FArrayBox>&
929 // LevelGridMetrics::getCr2ThisInterpolatorCrFnLevJU() const
930 // {
931 // CH_assert(hasCoarser());
932 // return m_coarserLevelGridMetrics->m_interpolator.getCrFnLevJU();
933 // }
934 
935 /*--------------------------------------------------------------------*/
936 // Set the coarsened-fine <U> used by the interpolator
937 /** Grids must have been defined for the interpolator. Copies the
938  * coarse data from 'this' level to the coarsened-fine representation
939  * in the interpolator. 'this' is the coarse level.
940  * \param[in] a_CrU <U> on the coarse level
941  * \param[in] a_vectorIntv
942  * An interval in components of U consisting of
943  * vector data
944  *//*-----------------------------------------------------------------*/
945 
946 inline void
948  const LevelData<FArrayBox>& a_CrLevU,
949  const Interval& a_vectorIntv)
950 {
951  CH_assert(hasFiner());
952  m_interpolator->presetCrFnLevU(a_CrLevU, a_vectorIntv);
953 }
954 
955 // Should not be used
956 // /*--------------------------------------------------------------------*/
957 // // Set the coarsened-fine <JU> used by the interpolator
958 // /** Grids must have been defined for the interpolator. Copies the
959 // * coarse data from 'this' level to the coarsened-fine representation
960 // * in the interpolator. 'this' is the coarse level.
961 // *//*-----------------------------------------------------------------*/
962 
963 // inline void
964 // LevelGridMetrics::presetThis2FnInterpolatorCrFnLevJU(
965 // const LevelData<FArrayBox>& a_CrLevJU)
966 // {
967 // CH_assert(hasFiner());
968 // m_interpolator.presetCrFnLevJU(a_CrLevJU);
969 // }
970 
971 /*--------------------------------------------------------------------*/
972 // Invalidate the CrFn data, both <U> and <JU>, used by the
973 // interpolator
974 /** 'this' is the fine level. If data goes out-of-date on the coarser
975  * level, then the interpolator, for interpolating to 'this' level,
976  * has out-of-date coarsened-fine data. There must be a coarser
977  * level
978  *//*-----------------------------------------------------------------*/
979 
980 inline void
982 {
983  CH_assert(hasCoarser());
984  m_coarserLevelGridMetrics->m_interpolator->invalidateCrFnLevData();
985 }
986 
987 /*--------------------------------------------------------------------*/
988 // Invalidate the CrFn data, both <U> and <JU>, used by the
989 // interpolator
990 /** 'this' is the coarse level. If data goes out-of-date on 'this'
991  * level, then the interpolator, for interpolating to the next finer
992  * level, has out-of-date coarsened-fine data. You can invalidate
993  * even if there is no finer level.
994  *//*-----------------------------------------------------------------*/
995 
996 inline void
998 {
999  m_interpolator->invalidateCrFnLevData();
1000 }
1001 
1002 /*--------------------------------------------------------------------*/
1003 // Number of ghosts used to build the coarsened-fine data in the
1004 // interpolator
1005 /** \param[in] a_force T - avoid assertion checking.
1006  * F - (default)
1007  * \note
1008  * <ul>
1009  * <li> The caller should ensure that a finer level exists if the
1010  * assertion is disabled. Commonly, the return value is
1011  * required inbetween initialGrid() and postInitialGrid()
1012  * where the metrics have not yet been defined (so the
1013  * assertion would fail) but the grid has been defined (so
1014  * this value is known).
1015  * </ul>
1016  *//*-----------------------------------------------------------------*/
1017 
1018 inline const IntVect&
1020 {
1021  if (!a_force)
1022  {
1023  CH_assert(hasFiner());
1024  }
1025  return m_interpolator->CrFnNumGhost();
1026 }
1027 
1028 /*--------------------------------------------------------------------*/
1029 // Is this a multiblock grid?
1030 /** \return T - Yes
1031  *//*-----------------------------------------------------------------*/
1032 
1033 inline bool
1035 {
1036  return m_isMultiblock;
1037 }
1038 
1039 #include "NamespaceFooter.H"
1040 #endif
IntersectionAverageFace(const LevelData< FluxBox > &a_A, const int a_nRef)
Constructor.
The class MultiBlockLevelGeom stores topological and geometric information.
Definition: MultiBlockLevelGeom.H:29
LevelData< FArrayBox > & presetCr2ThisInterpolatorCrFnLevU()
Set the coarsened-fine <U> used by the interpolator (CrFn access)
Definition: LevelGridMetrics.H:888
void presetThis2FnInterpolatorCrFnLevU(const LevelData< FArrayBox > &a_CrLevU, const Interval &a_vectorIntv)
Set the coarsened-fine <U> used by the interpolator.
Definition: LevelGridMetrics.H:947
Class to interpolate from coarse to valid fine cells on mapped grids.
void invalidateThis2FnInterpolatorCrFnLevData()
Invalidate the CrFn data, both <U> and <JU>\, used by the interpolator.
Definition: LevelGridMetrics.H:997
MultiBlockLevelExchangeAverage m_mbex
Definition: LevelGridMetrics.H:598
bool m_isMultiblock
T - A multiblock coordinates system.
Definition: LevelGridMetrics.H:631
const int m_spaceOrder
Spatial-order of accuracy - must be 4.
Definition: LevelGridMetrics.H:579
#define CH_assert(cond)
Definition: CHArray.H:37
FourthOrderMappedFineInterp * m_interpolator
Definition: LevelGridMetrics.H:583
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
const ProblemDomain & blockDomain(const Box &a_box, const int a_numGhost=0)
Get a problem domain representing a block.
Definition: LevelGridMetrics.H:754
IntVect m_ghostVect
Ghost cell vector.
Definition: LevelGridMetrics.H:571
Box resizeWithJReqGhosts(const Box &box) const
Resize a box to the size required for .
Definition: LevelGridMetrics.H:842
const ProblemDomain & problemDomain() const
Definition: LevelGridMetrics.H:874
Definition: MultiBlockFaceRegister.H:21
DisjointBoxLayout m_grids
Grid layout.
Definition: LevelGridMetrics.H:572
Definition: LevelGridMetrics.H:240
Virtual base class encapsulating mapped-grid coordinate systems.
Definition: NewFourthOrderCoordSys.H:77
Abstract base class for time-dependent data at a level of refinement.
Definition: AMRLevel.H:47
IntersectionAverageFace * m_NtFDiffAverager
Definition: LevelGridMetrics.H:555
bool m_useScriptN
Definition: LevelGridMetrics.H:620
AgeType
Age of metric terms during a regrid.
Definition: LevelGridMetrics.H:229
Definition: DataIterator.H:190
bool metricsDefined() const
Are the metrics defined on this level?
Definition: LevelGridMetrics.H:653
CoarseAverageFace m_averager
Definition: LevelGridMetrics.H:92
void define(const IntVect &small, const IntVect &big)
CoarseAverageFace * m_NAverager
Definition: LevelGridMetrics.H:548
TransverseNOpType
Type of operation for computing transverse terms in N.
Definition: LevelGridMetrics.H:237
static int s_verbosity
Definition: LevelGridMetrics.H:636
IntersectionAverageFace & operator=(const IntersectionAverageFace &)
Box resizeWithNReqGhosts(const Box &box) const
Resize a box to the size required for .
Definition: LevelGridMetrics.H:849
Definition: EBInterface.H:45
bool didFinerChange() const
Did the metrics change on the finer mesh?
Definition: LevelGridMetrics.H:664
virtual IntVect getJReqGhostVect() const
Determine the ghost vector required for .
Definition: LevelGridMetrics.H:825
DisjointBoxLayout m_gridsNP
Definition: LevelGridMetrics.H:573
void getBoxes(Vector< Vector< Box > > &a_boxes, Vector< int > &a_refRat, const Box &a_domain)
Definition: CoarseAverageCodim.H:27
const DisjointBoxLayout & getBoxes() const
Get the boxes.
Definition: LevelGridMetrics.H:801
Structure for passing component ranges in code.
Definition: Interval.H:23
static const IntVect Unit
Definition: IntVect.H:663
DataIterator getDataIterator() const
Get a level iterator.
Definition: LevelGridMetrics.H:808
Average from fine intersections.
Definition: LevelGridMetrics.H:67
double Real
Definition: REAL.H:33
Grid metrics for a level.
Definition: LevelGridMetrics.H:223
const int m_nComp
Number of components in A (same as C)
Definition: LevelGridMetrics.H:89
int getBlock(const Box &a_box) const
Get the block index.
Definition: LevelGridMetrics.H:730
bool m_metricsDefined
Definition: LevelGridMetrics.H:618
Box grow(const Box &b, int i)
Definition: Box.H:2277
Box resizeWithGhosts(const Box &box) const
Resize a box to include the ghost cells.
Definition: LevelGridMetrics.H:815
void invalidateCr2ThisInterpolatorCrFnLevData()
Invalidate the CrFn data, both <U> and <JU>\, used by the interpolator.
Definition: LevelGridMetrics.H:981
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:30
Time interpolator class using 4th-order Runge-Kutta.
Definition: TimeInterpolatorRK4.H:24
int m_cachedBlockNG
Definition: LevelGridMetrics.H:595
replaces face-centered coarse-level data w/ averaged fine-level data
Definition: CoarseAverageFace.H:24
int m_cachedBlockIdx
Index of the cached block.
Definition: LevelGridMetrics.H:594
LevelData< FArrayBox > & presetCr2ThisInterpolatorCrFnLevJU()
Set the coarsened-fine <JU> used by the interpolator (CrFn access)
Definition: LevelGridMetrics.H:902
ProblemDomain m_cachedBlockDomain
Definition: LevelGridMetrics.H:591
virtual interface class encapsulating multi-block mapping API
Definition: MultiBlockCoordSys.H:34
CoarseAverageCodim * m_scrNAverager
Definition: LevelGridMetrics.H:546
bool m_metricsChanged
Definition: LevelGridMetrics.H:616
int refRatio() const
Definition: LevelGridMetrics.H:868
LevelData< FluxBox > m_N
on each face
Definition: LevelGridMetrics.H:537
bool m_haveMultiBlockVectorData
Definition: LevelGridMetrics.H:632
Definition: LevelGridMetrics.H:239
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
bool isMultiblock() const
Is this a multiblock grid.
Definition: LevelGridMetrics.H:1034
An FArrayBox container for storage on the codimensions of a box.
Definition: CodimBox.H:65
LevelGridMetrics * m_finerLevelGridMetrics
Grid metrics on the next finer level.
Definition: LevelGridMetrics.H:563
MultiBlockCoordSys * m_coordSys
The multi-block coordinate system.
Definition: LevelGridMetrics.H:561
void copyTo(LevelData< FluxBox > &a_C, const DisjointBoxLayout &a_dblB)
Copy the average using a mask.
virtual IntVect getNReqGhostVect() const
Determine the ghost vector required for .
Definition: LevelGridMetrics.H:835
const int m_nRef
Refinement between A & C.
Definition: LevelGridMetrics.H:90
int level() const
Definition: LevelGridMetrics.H:862
const NewCoordSys * getCoordSys2(const Box &box) const
Get the coordinate system.
Definition: LevelGridMetrics.H:675
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
pure-virtual base class defining factory interface for MultiBlockCoordSys
Definition: MultiBlockCoordSys.H:409
LevelGridMetrics * m_coarserLevelGridMetrics
Definition: LevelGridMetrics.H:565
TransverseNOpType m_transverseNOpType
Definition: LevelGridMetrics.H:613
const RealVect & dxVect() const
Get the computational mesh spacing.
Definition: LevelGridMetrics.H:784
Interpolate from coarse cells to valid fine cells on mapped grids.
Definition: FourthOrderMappedFineInterp.H:153
const IntVect & interpolatorCrFnNumGhost(const bool a_force=false) const
Number of ghosts used to build the coarsened-fine data in the interpolator.
Definition: LevelGridMetrics.H:1019
The class MultiBlockLevelExchangeAverage stores topological and geometric information for cell-averag...
Definition: MultiBlockLevelExchangeAverage.H:25
const MultiBlockCoordSys & getCoordSys() const
Retrieve the multi-block coordinate system.
Definition: LevelGridMetrics.H:681
MultiBlockLevelGeom m_mbgeo
Topology of the multiblock layout.
Definition: LevelGridMetrics.H:597
MultiBlockFaceRegister * m_Nmbreg
Definition: LevelGridMetrics.H:601
DisjointBoxLayout m_crDblA
Coarsened layout for A.
Definition: LevelGridMetrics.H:91
RealVect m_dxVect
Mesh spacing in each direction.
Definition: LevelGridMetrics.H:578
Virtual base class encapsulating mapped-grid coordinate systems.
Definition: NewCoordSys.H:30
AMRLevel * m_parentAMRLevel
The AMR level we are attached to.
Definition: LevelGridMetrics.H:569
LevelData< FArrayBox > m_J
Definition: LevelGridMetrics.H:538