Chombo + EB  3.0
MeshRefine.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 _MESHREFINE_H_
12 #define _MESHREFINE_H_
13 
14 #include <climits>
15 
16 #include "Vector.H"
17 #include "Box.H"
18 #include "IntVectSet.H"
19 #include "REAL.H"
20 #include "ProblemDomain.H"
21 #include "NamespaceHeader.H"
22 
23 // Constants:
24 
25 /// Class which manages grid generation
27 /**
28  This class manages grid generation from sets of tagged cells. It is
29  designed to be a pure virtual base class from which another class
30  may be derived with a specific grid-generation algorithm (for example,
31  the BRMeshRefine class).
32 
33  There are two ways grids can be defined based on tagged cells.
34  one takes a single IntVectSet of tags defined on the BaseLevel
35  mesh and uses that set of tags for every level to be refined;
36  the other takes a Vector<IntVectSet> of tags defined on all the
37  mesh levels to be refined and uses those.
38 
39  <b> Long Description: </b>
40 
41  Create new meshes based on tagged cells on a range of levels of a mesh
42  hierarchy. Each level of tagged cells is used to generate a new mesh at
43  the next finer level. The finest level in the output mesh will be one
44  level higher than the top of the range of levels given as input. As a
45  special case, use the same tags (appropriately refined) for all levels.
46 
47  \b Usage:
48 
49  Call the regrid functions after computing error estimates and tagging cells.
50  To add a new mesh level, set TopLevel to the index of the finest level
51  in the existing mesh and define tags on the finest level. To keep the
52  existing number of mesh levels, set TopLevel to one less than the
53  index of the finest level and don't define any tags on the finest level.
54  If a single IntVectSet of tags is passed (instead of a
55  Vector<IntVectSet>) then the same tags (properly refined) will be used
56  for all the new meshes up to level TopLevel+1. In any case, the
57  meshes at levels BaseLevel and below are not modified. The output
58  argument newmeshes will be reallocated to the necessary size before
59  being used. When this function returns, the elements of the
60  newmeshes vector corresponding to the unchanged levels will be
61  filled in with copies of the levels from the old mesh vector. The
62  variable tags is modified in an undefined way, so its contents
63  should not be relied upon. The variable BlockFactor specifies the
64  amount by which each box will be coarsenable. Every grid box will
65  have an integral multiple of BlockFactor cells in each dimension and
66  also lower index values that are integral multiples. As a side effect,
67  the minimum box size will be BlockFactor.
68 
69  Expensive validations are done only when debugging is enabled
70  (i.e. the DEBUG make variable is "TRUE").
71 
72  <b> Usage Notes: </b>
73 
74  All the input vectors should be defined with max index >= TopLevel.
75  They should have values for indices [BaseLevel:TopLevel].
76  (except for OldMeshes, which must be defined for all indices). The
77  new mesh vector newmeshes will be redefined up to index
78  TopLevel+1. RefRatios should be defined such that
79  RefRatios[L] is the value to use to refine the level L mesh to
80  produce the level L+1 mesh. The tags vector is modified in an
81  undefined manner. The output variable newmeshes may not be
82  completely defined if an exception occurs.
83  The BlockFactor can be used to force a minimum box size.
84 */
85 {
86 public:
87  /// default constructor -- leaves object in an unusable state
88  MeshRefine();
89 
90  /// full constructor -- leaves object in usable state
91  MeshRefine(/// level 0 domain
92  const Box& a_baseDomain,
93  /// refinement ratios -- refRatio[0] is btwn levels 0 and 1
94  const Vector<int>& a_refRatios,
95  /// measure of how efficiently tagged cells will be covered
96  const Real a_fillRatio,
97  /// amount by which grids are guaranteed to be coarsenable
98  const int a_blockFactor,
99  /// proper nesting buffer amount
100  const int a_bufferSize,
101  /// maximum grid length in any direction -- 0 means no limit.
102  const int a_maxSize);
103 
104  /// full constructor -- leaves object in usable state
105  MeshRefine(/// level 0 domain
106  const ProblemDomain& a_baseDomain,
107  /// refinement ratios -- refRatio[0] is btwn levels 0 and 1
108  const Vector<int>& a_refRatios,
109  /// measure of how efficiently tagged cells will be covered
110  const Real a_fillRatio,
111  /// amount by which grids are guaranteed to be coarsenable
112  const int a_blockFactor,
113  /// proper nesting buffer amount
114  const int a_bufferSize,
115  /// maximum grid length in any direction -- 0 means no limit.
116  const int a_maxSize);
117 
118  /// destructor
119  virtual ~MeshRefine();
120 
121  /// define function -- size of RefRatios will define maximum number of levels
122  void define(/// level 0 domain
123  const Box& a_baseDomain,
124  /// refinement ratios -- refRatio[0] is btwn levels 0 and 1
125  const Vector<int>& a_refRatios,
126  /// measure of how efficiently tagged cells will be covered
127  const Real a_fillRatio,
128  /// amount by which grids are guaranteed to be coarsenable
129  const int a_blockFactor,
130  /// proper nesting buffer amount
131  const int a_bufferSize,
132  /// maximum grid length in any direction -- 0 means no limit
133  const int a_maxSize);
134 
135  /// define function -- size of RefRatios will define maximum number of levels
136  void define(/// level 0 domain
137  const ProblemDomain& a_baseDomain,
138  /// refinement ratios -- refRatio[0] is btwn levels 0 and 1
139  const Vector<int>& a_refRatios,
140  /// measure of how efficiently tagged cells will be covered
141  const Real a_fillRatio,
142  /// amount by which grids are guaranteed to be coarsenable
143  const int a_blockFactor,
144  /// proper nesting buffer amount
145  const int a_bufferSize,
146  /// maximum grid length in any direction -- 0 means no limit
147  const int a_maxSize);
148 
149  ///create hierarchy of grids from a single level of tags
150  /** This function creates a hierarchy of grids from a single level of
151  tags on BaseLevel. If tags exist, then all levels will have grids.
152  Returns the new finest level of grids.
153  */
154  virtual int regrid(/// new set of grids at every level
155  Vector<Vector<Box> >& a_newmeshes,
156  /// tagged cells on baseLevel
157  const IntVectSet& a_tags,
158  /// index of base mesh level (finest unchanged level)
159  const int a_baseLevel,
160  /// top level to refine (one less than finest possible level)
161  const int a_topLevel,
162  /// existing grids (if no previous grids, set to domains)
163  const Vector<Vector<Box> >& a_oldMeshes);
164 
165  /// create hierarchy of grids from tags at all levels
166  /** This function creates a hierarchy of grids from tags at all
167  refinement levels. It is possible that not all levels will
168  return with grids, since there may not be tags at all levels.
169  Returns the new finest level of grids.
170  */
171  virtual int regrid(/// new set of grids at every level
172  Vector<Vector<Box> >& a_newmeshes,
173  /// tagged cells on each existing level
174  Vector<IntVectSet>& a_tags,
175  /// index of base mesh level (finest unchanged level)
176  const int a_baseLevel,
177  /// top level to refine (one less than finest possible level)
178  const int a_topLevel,
179  /// existing grids (if no previous grids, set to domains)
180  const Vector<Vector<Box> >& a_oldMeshes);
181 
182  // Access functions
183 
184  /// returns vector of refinement ratios
185  const Vector<int>& refRatios() const;
186 
187  /// returns fillRatio
188  Real fillRatio() const;
189 
190  /// returns blocking factor
191  int blockFactor() const;
192 
193  /// returns proper nesting buffer size
194  int bufferSize() const;
195 
196  /// returns maximum box size in any dimension -- 0 means no limit
197  int maxSize() const;
198 
199  /// sets vector of refinement ratios
200  void refRatios(const Vector<int>& a_nRefVect);
201 
202  /// sets fillRatio
203  void fillRatio(const Real a_fill_ratio);
204 
205  /// sets blocking factor
206  void blockFactor(const int a_block_factor);
207 
208  /// sets proper nesting buffer size
209  void bufferSize(const int a_buffer_size);
210 
211  /// sets maximum box size in any dimension -- 0 means no limit
212  void maxSize(const int a_max_size);
213 
214  /// has this object been defined properly?
215  bool isDefined() const;
216 
217  /// sets proper nesting region granularity.
218  void granularity(int a_granularity);
219 
220  /// constructs a set of boxes which covers a set of tagged cells
221  /** constructs a set of boxes which covers a set of tagged cells
222  by using the algorithm of choice. Everything should
223  be on the same level, and blocking factor is not applied.
224  Boxes will be on the same refinement level as the tags.
225  This would normally be a protected function, but it can be useful
226  to call it on its own, so it has been left public.
227  */
228  virtual void
229  makeBoxes(/// output: refined boxes at each new level
230  Vector<Box>& a_mesh,
231  /// input: set of tagged cells to cover
232  const IntVectSet& a_tags,
233  /// input: proper nesting domain in which mesh boxes must live
234  const IntVectSet& a_pnd,
235  /// input: physical domain
236  const ProblemDomain& a_domain,
237  ///input: largest number of cells in any dimension for any box
238  const int a_maxSize,
239  const int a_totalBufferSize) const = 0;
240 
241 
242  void setPNDMode(int a_mode);
243 protected:
244 
245  /// computes local blockFactors used internally to enforce the BlockFactor
246  /** This function computes values for m_local_blockfactors array, which
247  is the amount that tags on a level are coarsened in order to guarantee
248  that the grids on the next finer level are coarsenable by the
249  BlockFactor. */
250  virtual void
252 
253  bool properlyNested(const Box& a_box,
254  const ProblemDomain& a_domain,
255  const IntVectSet& a_pnd,
256  int a_totalBuffer) const;
257 
258  /// Computes proper nesting domains.
259  /**
260  This should only be
261  called by refine. it assumes that everything has already been
262  coarsened by the local blocking factor
263  */
264  virtual void
265  makePNDs(///output: proper nesting domains at each level
266  Vector<IntVectSet>& a_pnds,
267  Vector<int>& a_totalBufferSize,
268  /// input: index of highest AMR level not to be refined
269  const int a_baseLevel,
270  /// input: index of highest AMR level in output
271  const int a_topLevel,
272  /// input: (same as in \em meshRefine)
273  const Vector<ProblemDomain>& a_domains,
274  /// input: boxes at mesh level \em BaseLevel
275  const IntVectSet& a_baseMesh,
276  ///input: (similar to \em meshRefine; but with level-dependent coarsening factors)
277  const Vector<int>& a_bufferSize ) const;
278 
279  virtual void
280  makePNDs(///output: proper nesting domains at each level
281  Vector<IntVectSet>& a_pnds,
282  Vector<int>& a_totalBufferSize,
283  /// input: index of highest AMR level not to be refined
284  const int a_baseLevel,
285  /// input: index of highest AMR level in output
286  const int a_topLevel,
287  /// input: (same as in \em meshRefine)
288  const Vector<ProblemDomain>& a_domains,
289  /// input: boxes at mesh level \em BaseLevel
290  const Vector<Box>& a_baseMesh,
291  ///input: (similar to \em meshRefine; but with level-dependent coarsening factors)
292  const Vector<int>& a_bufferSize ) const;
293 
294 
295  // local data members
296 
298 
300 
305 
307 
309 
311 
313 
315 
317 
319 
321 
322 };
323 
324 #include "NamespaceFooter.H"
325 #endif
Vector< ProblemDomain > m_vectDomains
Definition: MeshRefine.H:299
Vector< IntVectSet > m_pnds
Definition: MeshRefine.H:301
MeshRefine()
default constructor – leaves object in an unusable state
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:130
bool properlyNested(const Box &a_box, const ProblemDomain &a_domain, const IntVectSet &a_pnd, int a_totalBuffer) const
virtual ~MeshRefine()
destructor
virtual void makeBoxes(Vector< Box > &a_mesh, const IntVectSet &a_tags, const IntVectSet &a_pnd, const ProblemDomain &a_domain, const int a_maxSize, const int a_totalBufferSize) const =0
constructs a set of boxes which covers a set of tagged cells
int m_blockFactor
Definition: MeshRefine.H:310
Real m_fillRatio
Definition: MeshRefine.H:308
Real fillRatio() const
returns fillRatio
int maxSize() const
returns maximum box size in any dimension – 0 means no limit
int m_lastBase
Definition: MeshRefine.H:302
void granularity(int a_granularity)
sets proper nesting region granularity.
void setPNDMode(int a_mode)
int m_lastBuffer
Definition: MeshRefine.H:304
double Real
Definition: REAL.H:33
void define(const Box &a_baseDomain, const Vector< int > &a_refRatios, const Real a_fillRatio, const int a_blockFactor, const int a_bufferSize, const int a_maxSize)
define function – size of RefRatios will define maximum number of levels
virtual int regrid(Vector< Vector< Box > > &a_newmeshes, const IntVectSet &a_tags, const int a_baseLevel, const int a_topLevel, const Vector< Vector< Box > > &a_oldMeshes)
create hierarchy of grids from a single level of tags
const Vector< int > & refRatios() const
returns vector of refinement ratios
Vector< int > m_nRefVect
Definition: MeshRefine.H:306
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
bool isDefined() const
has this object been defined properly?
int bufferSize() const
returns proper nesting buffer size
int m_maxSize
Definition: MeshRefine.H:316
int m_lastTop
Definition: MeshRefine.H:303
virtual void computeLocalBlockFactors()
computes local blockFactors used internally to enforce the BlockFactor
int blockFactor() const
returns blocking factor
bool m_isDefined
Definition: MeshRefine.H:297
Class which manages grid generation.
Definition: MeshRefine.H:26
int m_PNDMode
Definition: MeshRefine.H:320
int m_granularity
Definition: MeshRefine.H:318
Vector< int > m_level_blockfactors
Definition: MeshRefine.H:312
int m_bufferSize
Definition: MeshRefine.H:314
virtual void makePNDs(Vector< IntVectSet > &a_pnds, Vector< int > &a_totalBufferSize, const int a_baseLevel, const int a_topLevel, const Vector< ProblemDomain > &a_domains, const IntVectSet &a_baseMesh, const Vector< int > &a_bufferSize) const
Computes proper nesting domains.