Chombo + EB + MF  3.2
MultiBlockCoordSys.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 _MULTIBLOCKCOORDSYS_H_
12 #define _MULTIBLOCKCOORDSYS_H_
13 
14 #include "NewCoordSys.H"
15 #include "Vector.H"
16 #include "BlockBoundary.H"
17 #include "Tuple.H"
18 #include "IndicesTransformation.H"
19 #include "VectorTransformation.H"
21 #include "LevelData.H"
22 #include "FluxBox.H"
23 #include "NamespaceHeader.H"
24 
25 /// virtual interface class encapsulating multi-block mapping API
26 /**
27  The MultiBlockCoordSys is designed to represent multiblock mappings.
28  Each mapping is represented by a separate NewCoordSys which has an
29  associated valid region defined by a Box in index space.
30 
31  Implementations of specific multiblock coordinate systems will be
32  provided by derived classes.
33 */
35 {
36 
37 public:
38 
39  /// default constructor
41 
42  /// destructor (should this delete the members of coordSysVect?
43  virtual ~MultiBlockCoordSys();
44 
45  /// returns block number in which a_box is contained in the global index space
46  /** returns -1 if a_box isn't fully contained in the valid region of
47  any block
48  */
49  virtual int whichBlock(const Box& a_box) const;
50 
51  /// returns block number in which a_iv is contained in the global index space
52  /** returns -1 if a_iv isn't fully contained in the valid region of
53  any block
54  */
55  virtual int whichBlock(const IntVect& a_iv) const;
56 
57  /// returns block number that overlaps a_box in the global index space
58  /** returns -1 if either
59  a_box doesn't overlap the valid region of any block, or
60  a_box overlaps the valid region of more than one block.
61  */
62  virtual int whichBlockOverlap(const Box& a_box) const;
63 
64  /// returns block number in which a_iv is contained within buffer of a_bufferSize
65  /** returns -1 if a_iv isn't fully contained in the buffered region of
66  any block
67  */
68  virtual int whichBlockBuffered(const IntVect& a_iv,
69  int a_bufferSize) const;
70 
71  /// block mapping conversion function
72  /** given a_xiSrc in block a_nSrc, returns which block (a_n_valid)
73  contains that location in its valid region and its
74  location a_xi_valid in that block's computational coordinate space.
75  */
76  virtual void blockRemapping(RealVect& a_xi_valid,
77  int& a_n_valid,
78  const RealVect& a_xiSrc,
79  int a_nSrc) const = 0;
80 
81  // Purpose of this function is that, relative to calling
82  // blockRemapping one point at a time, things will run
83  // faster if you start by assuming each point is in the same
84  // block as the previous point.
85  // virtual void blockRemapping(FArrayBox& a_xi_valid,
86  // BaseFab<int>& a_n_valid,
87  // const FArrayBox& a_xiSrc,
88  // int a_nSrc) const;
89 
90  /// general block mapping conversion function
91  /** Given a_xiSrc in mapped space of block a_nSrc,
92  and block index a_nDst,
93  returns coordinates in mapped space of block a_nDst.
94 
95  Default implementation goes through real space.
96  */
97  virtual RealVect blockRemappingGeneral(int a_nDst,
98  const RealVect& a_xiSrc,
99  int a_nSrc) const;
100 
101  /// return a cell that is far enough away from external boundaries
102  /** Given a_cell in block a_blockNum, return another cell that
103  is a_cell shifted as necessary away from the external boundaries
104  so as to leave distance of at least a_radius to all external boundaries.
105  */
106  virtual IntVect cellAvoidingBoundaries(const IntVect& a_cell,
107  int a_blockNum,
108  int a_radius) const;
109 
110  /// modify a_bx so that it lies entirely within the physical domain
111  /** Modify a_bx by removing parts of it that lie off edges of
112  block a_blockNum that correspond to physical boundaries.
113  Cells lying off the block in other directions are retained.
114  */
115  virtual void keepInDomain(Box& a_bx,
116  int a_blockNum) const;
117 
118  /// return ProblemDomain within block, with box and ghost cells
119  /** Return non-periodic ProblemDomain with base box
120  grow(a_baseBox, a_numGhost), cropped at the physical boundaries.
121  Cells lying off the block in other directions are retained.
122  */
123  //**FIXME This returns a problem domain customized for each box
124  //** and the name itself is kind of misleading. I would prefer
125  //** it sized to the block itself and if there is only one block,
126  //** then returning the actual problem domain with proper
127  //** periodicity. In the meantime, LevelGridMetrics has routines
128  //** that provide similar functionality.
129  virtual ProblemDomain problemDomain(const Box& a_baseBox,
130  int a_numGhost) const;
131 
132  /// return ProblemDomain of block containing a box
133  /** Return non-periodic ProblemDomain consisting of the whole block box
134  that contains a_baseBox.
135  */
136  virtual ProblemDomain blockDomainOfBox(const Box& a_baseBox) const;
137 
138  /// return vector transformation from one block to another at a point.
139  /** Return object that transforms the components of a vector
140  situated at a_xiSrc from basis of block a_nSrc
141  to components in basis in block a_nDst.
142 
143  Default implementation goes through real space.
144  */
146  const RealVect& a_xiSrc,
147  int a_nSrc) const;
148 
149  /// return vector transformation from one block to another at center of a cell.
150  /** Return object that transforms the components of a vector
151  situated at center of cell a_ivSrc from basis of block a_nSrc
152  to components in basis in block a_nDst.
153 
154  Calls vectorBlockTransformation.
155  */
157  const IntVect& a_ivSrc,
158  int a_nSrc) const;
159 
161  int a_nDst,
162  const Box& a_srcBox,
163  int a_nSrc) const;
164 
165  /// return average vector transformation from one block to another at a cell
166  /** Return average of object that transforms the components of a vector
167  on the cell a_ivSrc from basis of block a_nSrc
168  to components in basis in block a_nDst.
169 
170  Calls vectorBlockTransformationCenter.
171  */
173  const IntVect& a_ivSrc,
174  int a_nSrc) const;
175 
176  /// return average vector transformation from one block to another at a cell, with averaging over specified dimensions only
177  /** Return average of object that transforms the components of a vector
178  on the cells of a_srcBox from basis of block a_nSrc
179  to components in basis in block a_nDst,
180  where averaging is done in all dimensions that are NOT in a_fixedDims.
181 
182  This is returned in a_vtFab(a_srcBox, 0).
183 
184  Calls vectorBlockTransformationCenter.
185  */
187  int a_nDst,
188  const Box& a_srcBox,
189  int a_nSrc,
190  Interval a_fixedDims = Interval() ) const;
191 
192  /// return gradient of vector transformation from one block to another at a cell
193  /** Return gradient (or more precisely, difference, or gradient multiplied
194  by mesh spacing) of object that transforms the components of a vector
195  at center of cell a_ivSrc from basis of block a_nSrc
196  to components in basis in block a_nDst.
197 
198  Calls vectorBlockTransformationCenter.
199  */
201  const IntVect& a_ivSrc,
202  int a_nSrc) const;
203 
204  /// return gradient of vector transformation from one block to another at a cell, over specified dimensions only
205  /** Return gradient (or more precisely, difference, or gradient multiplied
206  by mesh spacing) of object that transforms the components of a vector
207  at center of cells in a_srcBox from basis of block a_nSrc
208  to components in basis in block a_nDst,
209  on all dimensions that are NOT in a_fixedDims.
210 
211  This is returned in a_vtFab(a_srcBox, 0:a_interpDimsVect.size()-1).
212 
213  Calls vectorBlockTransformationCenter.
214  */
216  int a_nDst,
217  const Box& a_srcBox,
218  int a_nSrc,
219  Interval a_fixedDims = Interval() ) const;
220 
222  int a_nDst,
223  const Box& a_srcBox,
224  int a_nSrc,
225  Interval a_fixedDims = Interval() ) const;
226 
227  /// return displacements
228  /**
229  Return a Vector of same length as a_dstCoords and a_dstBlocks,
230  with component i of this Vector being the displacement
231  from point a_srcCoords in mapped coordinates of block a_srcBlock
232  to point a_dstCoords[i] in mapped coordinates of block a_dstBlocks[i].
233 
234  If this method is not overwritten, then component i of the returned
235  Vector is simply the displacement in physical coordinates from
236  a_srcCoords to a_dstCoords[i].
237  */
238  virtual Vector<RealVect> displacements(const Vector<RealVect>& a_dstCoords,
239  const Vector<int>& a_dstBlocks,
240  const RealVect& a_srcCoords,
241  int a_srcBlock) const;
242 
243  /// return distance between two points
244  virtual Real distance(const RealVect& a_srcCoords,
245  int a_srcBlock,
246  const RealVect& a_dstCoords,
247  int a_dstBlock) const;
248 
249  /// Return the mapping which corresponds to the block with the given index.
250  virtual const NewCoordSys* getCoordSys(int a_n) const
251  {
252  return m_coordSysVect[a_n];
253  }
254 
255  /// Return the mapping which corresponds to the given box.
256  /// \param a_box The Box for which the coordinate system is retrieved. This
257  /// Box must be contained completely within a block or this
258  /// method will fail.
259  virtual const NewCoordSys* getCoordSys(const Box& a_box) const
260  { return m_coordSysVect[whichBlock(a_box)]; }
261 
262  /// const access to the mapping blocks
263  const Vector<Box>& mappingBlocks() const
264  {return m_mappingBlocks;}
265 
266  /// number of blocks
267  int numBlocks() const
268  {return m_mappingBlocks.size();}
269 
270  /// const access to the block boundaries
272  {return m_boundaries; }
273 
274  /// const access to m_validNum[a_block]
275  const BaseFab<int>& validNum(int a_block) const
276  {return *(m_validNum[a_block]); }
277 
278  /// const access to m_validBlocks[a_block]
279  const BaseFab<int>& validBlocks(int a_block) const
280  {return *(m_validBlocks[a_block]); }
281 
282  /// const access to m_validTransformations[a_block]
284  {return *(m_validTransformations[a_block]); }
285 
286  /// const access to m_allBlockTransformations[blockSrc][blockDst]
288  int a_blockDst) const
289  {return m_allBlockTransformations[a_blockSrc][a_blockDst]; }
290 
291  /// Need to have m_boundaries for this.
293 
294  /// Return list of valid blocks and cells corresponding to a_cell in a_block.
295  void validBlocksCells(Vector<int>& a_validBlocks,
296  Vector<IntVect>& a_validCells,
297  int a_origBlock,
298  const IntVect& a_origCell);
299 
300  /// Have separate volume flux on each block. Normally does nothing, but cubed-sphere coordinate system needs it.
301  virtual void separateVolFlux(LevelData<FluxBox>& a_flux) const;
302 
303  int realDim() const
304  {
305  return m_realDim;
306  }
307 
308  RealVect dxVect() const
309  {
310  return m_dxVect;
311  }
312 
313  bool gotBoundaries() const
314  {
315  return m_gotBoundaries;
316  }
317 
319  {
321  }
322 
323  bool gotMappingBlocks() const
324  {
325  return m_gotMappingBlocks;
326  }
327 
328  bool gotCoordSysVect() const
329  {
330  return m_gotCoordSysVect;
331  }
332 
333  bool useScriptN() const
334  {
335  return m_useScriptN;
336  }
337 
338  bool isDefined() const;
339 
340 protected:
341 
342  void permute(Vector<int>& a_vec,
343  int a_start,
344  int a_length,
345  Vector< Vector<int> >& a_allPathsDir,
346  const Vector<int>& a_changedDirs);
347 
349 
350  void setBoundaryFromFaces(int a_srcBlock,
351  int a_srcFaceID,
352  int a_dstBlock,
353  int a_dstFaceID,
354  IntVect a_sign = IntVect::Unit);
355 
356  /// Do we have m_coordSysVect?
358 
359  /// Vector of NewCoordSys -- one for each mapping block
361 
362  /// Do we have m_mappingBlocks?
364 
365  /// Associated regions in index space over which each mapping is valid
367 
368  /// Have we filled in m_boundaries?
369  /// covers m_boundaries
371 
372  /// The grid spacing, must be the same across all mapping blocks
374 
375  /// Number of dimensions in real space; default SpaceDim
377 
378  /// Description of each boundary face of each block; set these in derived class and then set m_gotBoundaries true
380 
381  /// have we filled in transformations in initializeBlockTransformations()?
382  /// covers m_allBlockTransformations, m_validNum, m_validBlocks, m_validTransformations
384 
385  /// [blockSrc][blockDst] gives transformation from blockSrc to blockDst
387 
388  /// number of valid blocks containing ghost cells of each block in each direction:
389  /// this is the number of components in m_validBlocks and m_validTransformations.
390  /// m_validNum lives on [-1:1]^SpaceDim and has 1 component.
392 
393  /// for each block, block numbers of valid blocks containing its ghost cells in each direction.
394  /// m_validBlocks[iblock] lives on [-1:1]^SpaceDim and has SpaceDim! components, of which we use m_validNum[iblock](offset, 0) for each offset in [-1:1]^SpaceDim.
396 
397  /// for each block, transformation from each block to valid blocks containing its ghost cells in each direction.
398  /// m_validTransformation[iblock] lives on [-1:1]^SpaceDim and has SpaceDim! components, of which we use m_validNum[iblock](offset, 0) for each offset in [-1:1]^SpaceDim.
400 
401  /// Whether scriptN is used in calculating N
402  // By default, this is set to true. If it should be set to false, do so
403  // in the constructors of derived classes
405 };
406 
407 
408 /// pure-virtual base class defining factory interface for MultiBlockCoordSys
409 class
411 {
412 public:
413 
415  {
416  }
417 
419  {
420  }
421 
422  virtual MultiBlockCoordSys* getCoordSys(const ProblemDomain& levelDomain,
423  const RealVect& a_dx) const = 0;
424 };
425 
426 #include "NamespaceFooter.H"
427 #endif
virtual int whichBlock(const Box &a_box) const
returns block number in which a_box is contained in the global index space
virtual Tuple< VectorTransformation, SpaceDim > vectorBlockTransformationGrad(int a_nDst, const IntVect &a_ivSrc, int a_nSrc) const
return gradient of vector transformation from one block to another at a cell
virtual void blockRemapping(RealVect &a_xi_valid, int &a_n_valid, const RealVect &a_xiSrc, int a_nSrc) const =0
block mapping conversion function
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
bool m_useScriptN
Whether scriptN is used in calculating N.
Definition: MultiBlockCoordSys.H:404
virtual ProblemDomain blockDomainOfBox(const Box &a_baseBox) const
return ProblemDomain of block containing a box
Vector< BaseFab< int > *> m_validNum
Definition: MultiBlockCoordSys.H:391
virtual ~MultiBlockCoordSysFactory()
Definition: MultiBlockCoordSys.H:418
virtual VectorTransformation vectorBlockTransformationCenter(int a_nDst, const IntVect &a_ivSrc, int a_nSrc) const
return vector transformation from one block to another at center of a cell.
bool m_gotCoordSysVect
Do we have m_coordSysVect?
Definition: MultiBlockCoordSys.H:357
bool gotCoordSysVect() const
Definition: MultiBlockCoordSys.H:328
MultiBlockCoordSysFactory()
Definition: MultiBlockCoordSys.H:414
Vector< BaseFab< IndicesTransformation > *> m_validTransformations
Definition: MultiBlockCoordSys.H:399
void setAllBoundaries(BlockBoundary::btype a_btype)
bool gotMappingBlocks() const
Definition: MultiBlockCoordSys.H:323
virtual void keepInDomain(Box &a_bx, int a_blockNum) const
modify a_bx so that it lies entirely within the physical domain
const Vector< Box > & mappingBlocks() const
const access to the mapping blocks
Definition: MultiBlockCoordSys.H:263
Class to describe transformation of SpaceDim-vectors, typically from one block to another...
Definition: VectorTransformation.H:23
void validBlocksCells(Vector< int > &a_validBlocks, Vector< IntVect > &a_validCells, int a_origBlock, const IntVect &a_origCell)
Return list of valid blocks and cells corresponding to a_cell in a_block.
virtual Vector< RealVect > displacements(const Vector< RealVect > &a_dstCoords, const Vector< int > &a_dstBlocks, const RealVect &a_srcCoords, int a_srcBlock) const
return displacements
void setBoundaryFromFaces(int a_srcBlock, int a_srcFaceID, int a_dstBlock, int a_dstFaceID, IntVect a_sign=IntVect::Unit)
const BaseFab< IndicesTransformation > & validTransformations(int a_block) const
const access to m_validTransformations[a_block]
Definition: MultiBlockCoordSys.H:283
btype
Definition: BlockBoundary.H:136
bool gotBoundaries() const
Definition: MultiBlockCoordSys.H:313
void initializeBlockTransformations()
Need to have m_boundaries for this.
int realDim() const
Definition: MultiBlockCoordSys.H:303
virtual const NewCoordSys * getCoordSys(const Box &a_box) const
Definition: MultiBlockCoordSys.H:259
const BaseFab< int > & validNum(int a_block) const
const access to m_validNum[a_block]
Definition: MultiBlockCoordSys.H:275
Structure for passing component ranges in code.
Definition: Interval.H:23
static const IntVect Unit
Definition: IntVect.H:663
bool m_gotMappingBlocks
Do we have m_mappingBlocks?
Definition: MultiBlockCoordSys.H:363
double Real
Definition: REAL.H:33
RealVect dxVect() const
Definition: MultiBlockCoordSys.H:308
Vector< NewCoordSys * > m_coordSysVect
Vector of NewCoordSys – one for each mapping block.
Definition: MultiBlockCoordSys.H:360
Ordered Tuples for Types T.
Definition: Tuple.H:30
bool gotBlockTransformations() const
Definition: MultiBlockCoordSys.H:318
Vector< Vector< IndicesTransformation > > m_allBlockTransformations
[blockSrc][blockDst] gives transformation from blockSrc to blockDst
Definition: MultiBlockCoordSys.H:386
const BaseFab< int > & validBlocks(int a_block) const
const access to m_validBlocks[a_block]
Definition: MultiBlockCoordSys.H:279
int numBlocks() const
number of blocks
Definition: MultiBlockCoordSys.H:267
size_t size() const
Definition: Vector.H:192
virtual RealVect blockRemappingGeneral(int a_nDst, const RealVect &a_xiSrc, int a_nSrc) const
general block mapping conversion function
Vector< Box > m_mappingBlocks
Associated regions in index space over which each mapping is valid.
Definition: MultiBlockCoordSys.H:366
const Vector< Tuple< BlockBoundary, 2 *SpaceDim > > & boundaries() const
const access to the block boundaries
Definition: MultiBlockCoordSys.H:271
virtual const NewCoordSys * getCoordSys(int a_n) const
Return the mapping which corresponds to the block with the given index.
Definition: MultiBlockCoordSys.H:250
virtual interface class encapsulating multi-block mapping API
Definition: MultiBlockCoordSys.H:34
virtual VectorTransformation vectorBlockTransformation(int a_nDst, const RealVect &a_xiSrc, int a_nSrc) const
return vector transformation from one block to another at a point.
virtual ~MultiBlockCoordSys()
destructor (should this delete the members of coordSysVect?
void permute(Vector< int > &a_vec, int a_start, int a_length, Vector< Vector< int > > &a_allPathsDir, const Vector< int > &a_changedDirs)
virtual void separateVolFlux(LevelData< FluxBox > &a_flux) const
Have separate volume flux on each block. Normally does nothing, but cubed-sphere coordinate system ne...
RealVect m_dxVect
The grid spacing, must be the same across all mapping blocks.
Definition: MultiBlockCoordSys.H:373
virtual void vectorBlockAvgTransformation(BaseFab< VectorAvgTransformation > &a_vtAvgFab, int a_nDst, const Box &a_srcBox, int a_nSrc, Interval a_fixedDims=Interval()) const
virtual int whichBlockOverlap(const Box &a_box) const
returns block number that overlaps a_box in the global index space
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
virtual ProblemDomain problemDomain(const Box &a_baseBox, int a_numGhost) const
return ProblemDomain within block, with box and ghost cells
virtual VectorTransformation vectorBlockTransformationAvg(int a_nDst, const IntVect &a_ivSrc, int a_nSrc) const
return average vector transformation from one block to another at a cell
virtual Real distance(const RealVect &a_srcCoords, int a_srcBlock, const RealVect &a_dstCoords, int a_dstBlock) const
return distance between two points
virtual int whichBlockBuffered(const IntVect &a_iv, int a_bufferSize) const
returns block number in which a_iv is contained within buffer of a_bufferSize
int m_realDim
Number of dimensions in real space; default SpaceDim.
Definition: MultiBlockCoordSys.H:376
const IndicesTransformation & blockTransformation(int a_blockSrc, int a_blockDst) const
const access to m_allBlockTransformations[blockSrc][blockDst]
Definition: MultiBlockCoordSys.H:287
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
pure-virtual base class defining factory interface for MultiBlockCoordSys
Definition: MultiBlockCoordSys.H:409
bool useScriptN() const
Definition: MultiBlockCoordSys.H:333
Vector< BaseFab< int > *> m_validBlocks
Definition: MultiBlockCoordSys.H:395
Class to describe transformation of indices from one block to another.
Definition: IndicesTransformation.H:25
Vector< Tuple< BlockBoundary, 2 *SpaceDim > > m_boundaries
Description of each boundary face of each block; set these in derived class and then set m_gotBoundar...
Definition: MultiBlockCoordSys.H:379
MultiBlockCoordSys()
default constructor
virtual IntVect cellAvoidingBoundaries(const IntVect &a_cell, int a_blockNum, int a_radius) const
return a cell that is far enough away from external boundaries
bool isDefined() const
bool m_gotBlockTransformations
Definition: MultiBlockCoordSys.H:383
Virtual base class encapsulating mapped-grid coordinate systems.
Definition: NewCoordSys.H:30
bool m_gotBoundaries
Definition: MultiBlockCoordSys.H:370