Chombo + EB + MF  3.2
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  virtual 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  If m_refineDirs != IntVect::Unit, then a_tags and a_oldMeshes must have
155  ranges restricted to 0 in all dimensions d with m_refineDirs[d] == 0,
156  and the output a_newmeshes will have this same restriction.
157  */
158  virtual int regrid(/// new set of grids at every level
159  Vector<Vector<Box> >& a_newmeshes,
160  /// tagged cells on baseLevel
161  const IntVectSet& a_tags,
162  /// index of base mesh level (finest unchanged level)
163  const int a_baseLevel,
164  /// top level to refine (one less than finest possible level)
165  const int a_topLevel,
166  /// existing grids (if no previous grids, set to domains)
167  const Vector<Vector<Box> >& a_oldMeshes);
168 
169  /// create hierarchy of grids from tags at all levels
170  /** This function creates a hierarchy of grids from tags at all
171  refinement levels. It is possible that not all levels will
172  return with grids, since there may not be tags at all levels.
173  Returns the new finest level of grids.
174 
175  If m_refineDirs != IntVect::Unit, then a_tags and a_oldMeshes must have
176  ranges restricted to 0 in all dimensions d with m_refineDirs[d] == 0,
177  and the output a_newmeshes will have this same restriction.
178  */
179  virtual int regrid(/// new set of grids at every level
180  Vector<Vector<Box> >& a_newmeshes,
181  /// tagged cells on each existing level
182  Vector<IntVectSet>& a_tags,
183  /// index of base mesh level (finest unchanged level)
184  const int a_baseLevel,
185  /// top level to refine (one less than finest possible level)
186  const int a_topLevel,
187  /// existing grids (if no previous grids, set to domains)
188  const Vector<Vector<Box> >& a_oldMeshes);
189 
190  // Access functions
191 
192  /// returns vector of refinement ratios
193  const Vector<int>& refRatios() const;
194 
195  /// returns fillRatio
196  Real fillRatio() const;
197 
198  /// returns blocking factor
199  int blockFactor() const;
200 
201  /// returns proper nesting buffer size
202  int bufferSize() const;
203 
204  /// returns maximum box size in any dimension -- 0 means no limit
205  int maxSize() const;
206 
207  /// sets vector of refinement ratios
208  void refRatios(const Vector<int>& a_nRefVect);
209 
210  /// sets fillRatio
211  virtual void fillRatio(const Real a_fill_ratio);
212 
213  /// sets blocking factor
214  virtual void blockFactor(const int a_block_factor);
215 
216  /// sets proper nesting buffer size
217  virtual void bufferSize(const int a_buffer_size);
218 
219  /// sets maximum box size in any dimension -- 0 means no limit
220  virtual void maxSize(const int a_max_size);
221 
222  /// has this object been defined properly?
223  bool isDefined() const;
224 
225  /// sets proper nesting region granularity.
226  void granularity(int a_granularity);
227 
228  /// constructs a set of boxes which covers a set of tagged cells
229  /** constructs a set of boxes which covers a set of tagged cells
230  by using the algorithm of choice. Everything should
231  be on the same level, and blocking factor is not applied.
232  Boxes will be on the same refinement level as the tags.
233  This would normally be a protected function, but it can be useful
234  to call it on its own, so it has been left public.
235  */
236  virtual void
237  makeBoxes(/// output: refined boxes at each new level
238  Vector<Box>& a_mesh,
239  /// input: set of tagged cells to cover
240  const IntVectSet& a_tags,
241  /// input: proper nesting domain in which mesh boxes must live
242  const IntVectSet& a_pnd,
243  /// input: physical domain
244  const ProblemDomain& a_domain,
245  ///input: largest number of cells in any dimension for any box
246  const int a_maxSize,
247  const int a_totalBufferSize) const = 0;
248 
249  void setPNDMode(int a_mode);
250 
251  /// set each component to 1 or 0 according to whether or not we refine in that direction. Default IntVect::Unit.
252  void setRefineDirs(const IntVect& a_refineDirs);
253 
254  /// returns IntVect with component d set to a_val if m_refineDirs[d] == 1; else 1.
255  IntVect inRefineDirs(int a_val) const;
256 
257  // intersects the Box with the hyperplane of 0 in dimensions where m_refineDirs == 0
258  void restrictUnrefined(Box& a_box) const;
259 
260  // intersects the IntVectSet with the hyperplane of 0 in dimensions where m_refineDirs == 0
261  void restrictUnrefined(IntVectSet& a_ivs) const;
262 
263 protected:
264 
265  /// computes local blockFactors used internally to enforce the BlockFactor
266  /** This function computes values for m_local_blockfactors array, which
267  is the amount that tags on a level are coarsened in order to guarantee
268  that the grids on the next finer level are coarsenable by the
269  BlockFactor. */
270  virtual void
272 
273  virtual bool properlyNested(const Box& a_box,
274  const ProblemDomain& a_domain,
275  const IntVectSet& a_pnd,
276  int a_totalBuffer) const;
277 
278  /// Computes proper nesting domains.
279  /**
280  This should only be
281  called by refine. it assumes that everything has already been
282  coarsened by the local blocking factor
283  */
284  virtual void
285  makePNDs(///output: proper nesting domains at each level
286  Vector<IntVectSet>& a_pnds,
287  Vector<int>& a_totalBufferSize,
288  /// input: index of highest AMR level not to be refined
289  const int a_baseLevel,
290  /// input: index of highest AMR level in output
291  const int a_topLevel,
292  /// input: (same as in \em meshRefine)
293  const Vector<ProblemDomain>& a_domains,
294  /// input: boxes at mesh level \em BaseLevel
295  const IntVectSet& a_baseMesh,
296  ///input: (similar to \em meshRefine; but with level-dependent coarsening factors)
297  const Vector<int>& a_bufferSize ) const;
298 
299  virtual void
300  makePNDs(///output: proper nesting domains at each level
301  Vector<IntVectSet>& a_pnds,
302  Vector<int>& a_totalBufferSize,
303  /// input: index of highest AMR level not to be refined
304  const int a_baseLevel,
305  /// input: index of highest AMR level in output
306  const int a_topLevel,
307  /// input: (same as in \em meshRefine)
308  const Vector<ProblemDomain>& a_domains,
309  /// input: boxes at mesh level \em BaseLevel
310  const Vector<Box>& a_baseMesh,
311  ///input: (similar to \em meshRefine; but with level-dependent coarsening factors)
312  const Vector<int>& a_bufferSize ) const;
313 
314  virtual void buildSupport(const ProblemDomain& lvldomain, Vector<Box>& lvlboxes, IntVectSet& modifiedTags);
315 
316  virtual void clipBox(Box& a_box, const ProblemDomain& a_domain) const ;
317  // local data members
318 
320 
322 
327 
329 
331 
333 
335 
337 
339 
341 
343 
344  // component 1 if refining in this dimension, 0 if not. Default IntVect::Unit.
346 
347  // Lowest d such that m_refineDirs[d] == 1. Default 0.
349 };
350 
351 #include "NamespaceFooter.H"
352 #endif
Vector< ProblemDomain > m_vectDomains
Definition: MeshRefine.H:321
virtual void clipBox(Box &a_box, const ProblemDomain &a_domain) const
Vector< IntVectSet > m_pnds
Definition: MeshRefine.H:323
int bufferSize() const
returns proper nesting buffer size
int m_lowestRefineDir
Definition: MeshRefine.H:348
virtual void buildSupport(const ProblemDomain &lvldomain, Vector< Box > &lvlboxes, IntVectSet &modifiedTags)
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:141
int maxSize() const
returns maximum box size in any dimension – 0 means no limit
Real fillRatio() const
returns fillRatio
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:332
Real m_fillRatio
Definition: MeshRefine.H:330
int m_lastBase
Definition: MeshRefine.H:324
void granularity(int a_granularity)
sets proper nesting region granularity.
void setPNDMode(int a_mode)
int m_lastBuffer
Definition: MeshRefine.H:326
void setRefineDirs(const IntVect &a_refineDirs)
set each component to 1 or 0 according to whether or not we refine in that direction. Default IntVect::Unit.
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.
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 bool properlyNested(const Box &a_box, const ProblemDomain &a_domain, const IntVectSet &a_pnd, int a_totalBuffer) const
IntVect m_refineDirs
Definition: MeshRefine.H:345
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
Vector< int > m_nRefVect
Definition: MeshRefine.H:328
IntVect inRefineDirs(int a_val) const
returns IntVect with component d set to a_val if m_refineDirs[d] == 1; else 1.
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
void restrictUnrefined(Box &a_box) const
int m_maxSize
Definition: MeshRefine.H:338
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
const Vector< int > & refRatios() const
returns vector of refinement ratios
int m_lastTop
Definition: MeshRefine.H:325
bool isDefined() const
has this object been defined properly?
virtual void computeLocalBlockFactors()
computes local blockFactors used internally to enforce the BlockFactor
bool m_isDefined
Definition: MeshRefine.H:319
Class which manages grid generation.
Definition: MeshRefine.H:26
int m_PNDMode
Definition: MeshRefine.H:342
int blockFactor() const
returns blocking factor
int m_granularity
Definition: MeshRefine.H:340
Vector< int > m_level_blockfactors
Definition: MeshRefine.H:334
int m_bufferSize
Definition: MeshRefine.H:336