Proto  3.2
Proto_AMRGrid.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_AMR_GRID_
3 #define _PROTO_AMR_GRID_
4 
5 #include "Proto_FinitePointSet.H"
7 #include "Proto_LevelBoxData.H"
8 #include "Proto_InterpStencil.H"
9 
10 //#define PR_AMR_REFRATIO 2
11 
12 namespace Proto
13 {
14  // NB: Tags are encoded using short instead of bool so that Stencils can be used to
15  // manipulate them (e.g. for buffering). -CLG
20 
21  /// AMR Grid
22  /**
23  AMRGrid is a collection of DisjointBoxLayout objects that define
24  properly nested unions of logically rectangular space.
25  */
26  class AMRGrid
27  {
28  public:
29 
30  /// Compute Tags
31  /**
32  Populate tags using the magnitude of the undivided difference of the a specified component of a dataset.
33 
34  \param tags The tag data to be populated. Must have compatible layout with the level being checked.
35  \param data The level of data to compute tags on
36  \param comp Component of data to use
37  \param bufferSize Distance to buffer the computed tags by
38  \param threshold Threshold above whcih a tag is generated
39  */
40  template<typename T, unsigned int C=1, MemType MEM = MEMTYPE_DEFAULT, Centering CTR = PR_CELL>
41  inline static void computeTags(
42  LevelTagData& a_tags,
44  Point a_bufferSize,
45  T a_threshold,
46  unsigned int a_comp = 0);
47 
48  /// Compute Tags (Isotropic)
49  /**
50  Computes tags with an isotropic buffer radius.
51  */
52  template<typename T, unsigned int C=1,
54  inline static void computeTags(
55  LevelTagData& a_tags,
57  int a_bufferSize,
58  T a_threshold,
59  unsigned int a_comp = 0);
60 
61  /// Buffer Tags
62  /**
63  Grows a level of tag data by bufferSize.
64  */
65  inline static void buffer(LevelTagData& a_tags, Point a_bufferSize);
66 
67  /// Buffer Tags (Isotropic)
68  /**
69  Grows a level of tag data by bufferSize.
70  */
71  inline static void buffer(LevelTagData& a_tags, int a_bufferSize);
72 
73  /// Trivial Constructor
74  AMRGrid() {m_defined = false;}
75 
76  /// Multi-Level Constructor
77  /**
78  Create an AMRGrid using a vector of DisjointBoxLayouts.
79  TODO: What to do if the DBLs are not properly nested?
80 
81  \param layouts A vector of DisjointBoxLayouts.
82  \param refRatios Refinement ratios for each *coarse* level.
83  \param maxLevels The maximum number of levels allowable in this grid.
84  */
85  inline AMRGrid(
86  const std::vector<DisjointBoxLayout>& a_layouts,
87  const std::vector<Point>& a_refRatios,
88  int a_maxLevels);
89 
90  /// Single-Level Constructor
91  /**
92  Create an AMRGrid by initializing only the coarsest level.
93 
94  \param layout Layout of the coarsest level.
95  \param refRatios Refinement ratios for each *coarse* level.
96  \param maxLevels The maximum number of levels allowable in this grid.
97  */
98  inline AMRGrid(
99  const DisjointBoxLayout& a_layout,
100  const std::vector<Point>& a_refRatios,
101  int a_maxLevels);
102 
103  /// Multi-Level Define
104  /**
105  Lazy multi-level construction
106 
107  \param layouts A vector of DisjointBoxLayouts.
108  \param refRatios Refinement ratios for each *coarse* level.
109  \param maxLevels The maximum number of levels allowable in this grid.
110  */
111  inline void
112  define(
113  const std::vector<DisjointBoxLayout>& a_layouts,
114  const std::vector<Point>& a_refRatios,
115  int a_maxLevels);
116 
117  /// Single-Level Define
118  /**
119  Lazy single-level construction
120 
121  \param layout Layout of the coarsest level.
122  \param refRatios Refinement ratios for each *coarse* level.
123  \param maxLevels The maximum number of levels allowable in this grid.
124  */
125  inline void
126  define(
127  const DisjointBoxLayout& a_layout,
128  const std::vector<Point>& a_refRatios,
129  int a_maxLevels);
130 
131  /// Layout Access (Const)
132  inline const DisjointBoxLayout&
133  operator[](unsigned int a_level) const;
134 
135  /// Layout Access (Non-Const)
136  inline DisjointBoxLayout&
137  operator[](unsigned int a_level);
138 
139  /// Regrid
140  /**
141  Given tag data on a level, modify or generate a grid on the next finer level.
142  Input level must correspond to the grid on which input tags are defined.
143  Input level must be coarser than the finest permissible level in the grid.
144  For grids with fewer than their predefined max number of levels, this
145  function can add at most one level of grid.
146  Proper nesting is NOT enforced by this function (see enforceNesting).
147  */
148  inline void regrid(LevelTagData& a_tags, unsigned int a_level, Point a_boxSize);
149  inline void regrid(LevelTagData& a_tags, unsigned int a_level);
150 
151  /// Enforce Nesting
152  /**
153  Enforce the proper nesting criteria on a given level.
154  Input level must be an "internal" level. That is to say, greater than 0
155  and finer than the finest level in the grid.
156  */
157  inline void enforceNesting(unsigned int a_level, int a_nestingDistance = 1);
158 
159  /// Trim a_level grids so that they properly nest in a_level-1 grids.
160  inline void enforceNesting2(unsigned int a_level, int a_nestingDistance = 1);
161 
162  /// Query Number of Levels
163  inline int numLevels() const { return m_layouts.size(); }
164 
165  /// Query Max Number of Levels
166  inline int maxLevels() const { return m_maxLevels; }
167 
168  /// Query Refinement Ratio
169  inline Point refRatio(int a_level) const;
170 
171  /// Query Compatibility
172  /**
173  Determines if the layouts are compatible in a data iterator sence on
174  each level of this and another grid. If the two grids have different
175  numbers of levels, this check is only performed for levels that
176  are defined for both grids.
177 
178  \param grid Another AMRGrid
179  */
180  inline bool compatible(const AMRGrid& a_grid) const;
181 
182  /// Augments set of a_level tags by set intersecting a_level+2 grids.
183  inline void addFinerGrids(LevelTagData& a_tags,int a_level);
184  inline void addFinerTags(LevelTagData& a_tags, unsigned int a_level);
185 
186  inline void print() const;
187 
188  private:
189 
190  bool m_defined;
191  std::vector<DisjointBoxLayout> m_layouts;
192  std::vector<Point> m_refRatios;
193  //int m_nestingDistance;
195  };
196 
197 #include "implem/Proto_AMRGridImplem.H"
198 } // end namespace Proto
199 #endif //end include guard
LevelBoxData< short, 1, MEMTYPE_DEFAULT, PR_CELL > LevelTagData
Definition: Proto_AMRGrid.H:16
static void computeTags(LevelTagData &a_tags, LevelBoxData< T, C, MEM, CTR > &a_data, Point a_bufferSize, T a_threshold, unsigned int a_comp=0)
Compute Tags.
Definition: Proto_AMRGrid.H:12
AMRGrid()
Trivial Constructor.
Definition: Proto_AMRGrid.H:74
BoxData< short, 1, MemType::HOST > TagDataHost
Definition: Proto_AMRGrid.H:19
Multidimensional Rectangular Array.
Definition: Proto_BoxData.H:314
bool compatible(const AMRGrid &a_grid) const
Query Compatibility.
Definition: Proto_AMRGrid.H:261
Disjoint Box Layout.
Definition: Proto_DisjointBoxLayout.H:30
void enforceNesting2(unsigned int a_level, int a_nestingDistance=1)
Trim a_level grids so that they properly nest in a_level-1 grids.
Definition: Proto_AMRGrid.H:377
void enforceNesting(unsigned int a_level, int a_nestingDistance=1)
Enforce Nesting.
Definition: Proto_AMRGrid.H:272
int m_maxLevels
Definition: Proto_AMRGrid.H:194
MemType
Definition: Proto_MemType.H:7
int numLevels() const
Query Number of Levels.
Definition: Proto_AMRGrid.H:163
Level Box Data.
Definition: Proto_HDF5.H:17
int maxLevels() const
Query Max Number of Levels.
Definition: Proto_AMRGrid.H:166
std::vector< DisjointBoxLayout > m_layouts
Definition: Proto_AMRGrid.H:191
AMR Grid.
Definition: Proto_AMRGrid.H:26
void addFinerGrids(LevelTagData &a_tags, int a_level)
Augments set of a_level tags by set intersecting a_level+2 grids.
Definition: Proto_AMRGrid.H:332
void addFinerTags(LevelTagData &a_tags, unsigned int a_level)
Definition: Proto_AMRGrid.H:404
void print() const
Definition: Proto_AMRGrid.H:451
LevelBoxData< short, 1, MemType::HOST, PR_CELL > LevelTagDataHost
Definition: Proto_AMRGrid.H:17
BoxData< short, 1, MEMTYPE_DEFAULT > TagData
Definition: Proto_AMRGrid.H:18
void regrid(LevelTagData &a_tags, unsigned int a_level, Point a_boxSize)
Regrid.
Definition: Proto_AMRGrid.H:205
Definition: Proto_Array.H:17
void define(const std::vector< DisjointBoxLayout > &a_layouts, const std::vector< Point > &a_refRatios, int a_maxLevels)
Multi-Level Define.
Definition: Proto_AMRGrid.H:123
const DisjointBoxLayout & operator[](unsigned int a_level) const
Layout Access (Const)
Definition: Proto_AMRGrid.H:173
std::vector< Point > m_refRatios
Definition: Proto_AMRGrid.H:192
static void buffer(LevelTagData &a_tags, Point a_bufferSize)
Buffer Tags.
Definition: Proto_AMRGrid.H:80
Integer Valued Vector.
Definition: Proto_Point.H:24
bool m_defined
Definition: Proto_AMRGrid.H:190
Definition: Proto_Centering.H:9
#define MEMTYPE_DEFAULT
Definition: Proto_MemType.H:24
Centering
Definition: Proto_Centering.H:7
Point refRatio(int a_level) const
Query Refinement Ratio.
Definition: Proto_AMRGrid.H:252