Chombo + EB + MF  3.2
MultiBlockUtil.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 _MULTIBLOCKUTIL_H_
12 #define _MULTIBLOCKUTIL_H_
13 
14 #include "MultiBlockCoordSys.H"
15 #include "IndicesTransformation.H"
16 #include "IVSFAB.H"
17 #include "MBStencil.H"
18 #include "MBVectorStencil.H"
19 
20 #include "NamespaceHeader.H"
21 
22 /// The class MultiBlockUtil contains some functions used by MultiBlockLevelGeom, MultiBlockLevelExchange, and MultiBlockLevelCopier. It does NOT store any layouts.
24 {
25 public:
26 
27  /// default constructor
29 
30  /// destructor
31  virtual ~MultiBlockUtil();
32 
33  /// full constructor
34  MultiBlockUtil(const MultiBlockCoordSys* a_coordSysPtr,
35  Interval a_fixedDims = Interval(),
36  Vector<int> a_fixedPt = Vector<int>() );
37 
38  virtual void undefine();
39 
40  virtual void define(const MultiBlockCoordSys* a_coordSysPtr,
41  Interval a_fixedDims = Interval(),
42  Vector<int> a_fixedPt = Vector<int>() );
43 
44  /// the offset in [-1:1]^D of cell a_cell from the box of block a_block.
45  IntVect whichOffset(int a_block,
46  const IntVect& a_cell) const;
47 
48  /// the transformation from block a_dstBlock to a_srcBlock, taking offset a_offset from a_dstBlock
49  const IndicesTransformation& blockTransform(int a_srcBlock,
50  int a_dstBlock,
51  const IntVect& a_offset) const;
52 
53  /// transformations to block a_srcBlock, taking offset a_offset from all destination blocks
54  const Vector<IndicesTransformation>& transformsSrcOff(int a_srcBlock,
55  const IntVect& a_offset) const;
56 
57  /// add IntVects to an IntVectSet in all directions, even across block boundaries.
58  void growIVS(IntVectSet& a_ivs,
59  int a_bufferSize) const;
60 
61  /// return list of all cells that share a vertex with a given cell
62  /** Given a_baseCell in block a_baseBlock, return a Vector of cells
63  with indices a_neighborCells in corresponding blocks a_neighborBlocks.
64  */
65  void commonVertexCells(Vector<IntVect>& a_neighborCells,
66  Vector<int>& a_neighborBlocks,
67  const IntVect& a_baseCell,
68  int a_baseBlock) const;
69 
71  const MBStencilElement& a_base) const;
72 
73  /// return shifted cell
74  /**
75  Starting with valid cell with indices a_origCell in block a_origBlock;
76  shift in direction a_dir by a_shift;
77  end up in valid cell with indices a_shiftedCell in block a_shiftedBlock.
78  Return false if go beyond physical boundary.
79  */
80  bool validCellShift(IntVect& a_shiftedCell,
81  int& a_shiftedBlock,
82  const IntVect& a_origCell,
83  int a_origBlock,
84  int a_dir,
85  int a_shift) const;
86 
87  bool validCellShift(MBStencilElement& a_shiftedElt,
88  const MBStencilElement& a_origElt,
89  int a_dir,
90  int a_shift) const;
91 
92  /// return index, block, and center in mapped coordinates of valid cell containing each ghost cell
93  /**
94  For each IntVect thisGhostCell in a_ghostCellsIVS, which is
95  an extra-block ghost cell of block a_baseBlockNum,
96  find the valid cell that contains its center.
97  Then set a_validIndices(thisGhostCell, 0) to its indices,
98  set a_validBlock(thisGhostCell, 0) to its block number,
99  and set a_validMappedCenter(thisGhostCell, 0) to the center of
100  thisGhostCell in the mapped coordinates of its valid block.
101  */
102  void getValid(IVSFAB<IntVect>& a_validIndices,
103  IVSFAB<int>& a_validBlock,
104  IVSFAB<RealVect>& a_validMappedCenter,
105  const IntVectSet& a_ghostCellsIVS,
106  int a_baseBlockNum) const;
107 
108  void getValid(BaseFab<IntVect>& a_validIndices,
109  BaseFab<int>& a_validBlock,
110  BaseFab<RealVect>& a_validMappedCenter,
111  const Box& a_bx,
112  int a_baseBlockNum) const;
113 
114  /// find the stencil cells and source blocks for all cells in a_ghostCellsIVS, and also the minimum Box covering all such cells for each source block
115  /**
116  In a_stencil, return the valid cells and source block numbers of the
117  stencil of radius a_radius for every ghost cell in a_ghostCellsIVS.
118  In a_minBox[srcBlock], return the minimum Box that covers all
119  the cells of a_stencils that are in block srcBlock.
120 
121  For each ghost cell thisGhostCell in a_ghostCellsIVS,
122  the center of thisGhostCell lies in block a_validBlock(thisGhost, 0)
123  within the valid cell with indices a_validIndices(thisGhostCell, 0)
124  and within that block, the ghost cell center has mapped coordinates
125  a_validMappedCenter(thisGhostCell, 0).
126  */
127  void getStencilCells(IVSFAB<MBStencil>& a_stencils,
128  Vector<Box>& a_minBox,
129  const IntVectSet& a_ghostCellsIVS,
130  const IVSFAB<IntVect>& a_validIndices,
131  const IVSFAB<int>& a_validBlock,
132  const IVSFAB<RealVect>& a_validMappedCenter,
133  int a_order,
134  int a_radius) const;
135 
136  void getVectorStencilCells(IVSFAB<MBVectorStencil>& a_vectorstencils,
137  const IVSFAB<MBStencil>& a_stencils,
138  const IntVectSet& a_ghostCellsIVS) const;
139 
140  void getVectorTransformations(Vector< BaseFab<VectorTransformation>* >& a_vectorTransformations,
141  const IVSFAB<MBVectorStencil>& a_vectorstencilsFab,
142  const IndexType& a_type,
143  const IntVectSet& a_ghostCellsIVS,
144  int a_ghostBlockNum) const;
145 
146  void getWeights(IVSFAB<MBStencil>& a_stencilsFab,
147  const IndexType& a_type,
148  const IntVectSet& a_ghostCellsIVS,
149  const IVSFAB<IntVect>& a_validIndices,
150  const IVSFAB<int>& a_validBlock,
151  const IVSFAB<RealVect>& a_validMappedCenter,
152  const Vector<IntVect>& a_exponents,
153  int a_ghostBlockNum) const;
154 
155  void getVectorWeights(IVSFAB<MBVectorStencil>& a_vectorstencilsFab,
156  const Vector< BaseFab<VectorTransformation>* >& a_vectorStencilTransformations,
157  const IndexType& a_type,
158  const IntVectSet& a_ghostCellsIVS,
159  const IVSFAB<IntVect>& a_validIndices,
160  const IVSFAB<int>& a_validBlock,
161  const IVSFAB<RealVect>& a_validMappedCenter,
162  const Vector<IntVect>& a_exponents,
163  int a_ghostBlockNum) const;
164 
165  /// copy from a_blockStencilsFab to a_stencilsFab on a_ghostCellsIVS, where the cells in the stencil of a_blockStencilsFab are m_fixedPt in m_fixedDimsVect.
166  void copyStencilsFromBlock(IVSFAB<MBStencil>& a_stencilsFab,
167  const IntVectSet& a_ghostCellsIVS,
168  const IVSFAB<MBStencil>& a_blockStencilsFab) const;
169 
170  void copyVectorStencilsFromBlock(IVSFAB<MBVectorStencil>& a_vectorstencilsFab,
171  const IntVectSet& a_ghostCellsIVS,
172  const IVSFAB<MBVectorStencil>& a_blockVectorStencilsFab) const;
173 
174  Box boxFixed(const Box& a_bx);
175 
177  const Box& a_baseBox,
178  int a_ghostLayer,
179  int a_baseBlockNum) const;
180 
181  bool allGridsHaveFixedPt(const BoxLayout& a_layout);
182 
183  void getCollapsedLayout(BoxLayout& a_layoutCollapsed,
184  const BoxLayout& a_layoutFull);
185 
186  void getCollapsedLayout(DisjointBoxLayout& a_layoutCollapsed,
187  const DisjointBoxLayout& a_layoutFull);
188 
189  void getFixedOffLayout(BoxLayout& a_layoutFixedOff,
190  const BoxLayout& a_layoutFull);
191 
192  /// returns a_gradData = gradient(a_data) on valid cells, taking 1-sided differences next to block boundaries
193  void order2grad(LevelData<FArrayBox>& a_gradData,
194  const LevelData<FArrayBox>& a_data);
195 
196 protected:
197 
198  /// return list of all aliases of a vertex
199  /** Given a_baseVertex, a vertex of block a_baseBlock,
200  return a Vector of vertices with indices a_aliasVertices
201  in corresponding blocks a_aliasBlocks.
202  */
203  void vertexAliases(Vector<IntVect>& a_aliasVertices,
204  Vector<int>& a_aliasBlocks,
205  const IntVect& a_baseVertex,
206  int a_baseBlock) const;
207 
209  const MBStencilElement& a_base) const;
210 
211  /// return the set of all valid cells adjacent to a given set of vertices
212  /** Given list of vertices a_vertexIndices in blocks a_vertexBlocks,
213  return a Vector of cell indices a_cellIndices
214  in corresponding blocks a_cellBlocks.
215  */
216  void validCellsFromVertices(Vector<IntVect>& a_cellIndices,
217  Vector<int>& a_cellBlocks,
218  const Vector<IntVect>& a_vertexIndices,
219  const Vector<int>& a_vertexBlocks) const;
220 
222  const Vector<MBStencilElement>& a_vertices) const;
223 
224  /// return <((Xvec() - Xvec(a_commonMappedBasePoint))/a_avgDistance)^pvec>_(a_cell), for all pvec
225  /**
226  Sets a_powers[pvec] = <((Xvec() - Xvec(a_commonMappedBasePoint)/a_avgDistance))^pvec>_(a_cell)
227  for each pvec such that sum(|pvec|) <= m_degree
228  where
229  a_cell is in index space of a_thisBlockNum (may or may not be valid here),
230  XVec() is in mapped space of a_commonBlockNum and varies over a_cell,
231  a_commonMappedBasePoint is a point in mapped space of a_commonBlockNum .
232 
233  Example in 2D with order 4, in this sequence:
234  0: 0 0
235  1: 1 0
236  2: 2 0
237  3: 3 0
238  4: 0 1
239  5: 1 1
240  6: 2 1
241  7: 0 2
242  8: 1 2
243  9: 0 3
244  */
245  void displacementPowers(Vector<Real>& a_powers,
246  const IntVect& a_cell,
247  const RealVect& a_commonMappedBasePoint,
248  Real a_avgDistance,
249  int a_thisBlockNum,
250  int a_commonBlockNum,
251  const Vector<IntVect>& a_exponents) const;
252 
254  const BaseFab<VectorTransformation>& a_vectorStencilTransformations,
255  const IntVect& a_cell,
256  const RealVect& a_commonMappedBasePoint,
257  Real a_avgDistance,
258  int a_thisBlockNum,
259  int a_commonBlockNum,
260  int a_ghostBlockNum,
261  const Vector<IntVect>& a_exponents) const;
262 
263  void getStencilCells(MBStencil& a_stencil,
264  Vector<Box>& a_minBox,
265  const IntVect& a_iv,
266  const IntVect& a_validIndices,
267  int a_validBlockNum,
268  const RealVect& a_validMappedCenter,
269  int a_order,
270  int a_radius) const;
271 
272  void getWeights(MBStencil& a_stencil,
273  const IndexType& a_type,
274  const IntVect& a_iv,
275  const IntVect& a_validIndices,
276  int a_validBlockNum,
277  const RealVect& a_validMappedCenter,
278  const Vector<IntVect>& a_exponents,
279  int a_ghostBlockNum) const;
280 
281  void getVectorWeights(MBVectorStencil& a_vectorstencil,
282  const Vector< BaseFab<VectorTransformation>* >& a_vectorStencilTransformations,
283  const IndexType& a_type,
284  const IntVect& a_iv,
285  const IntVect& a_validIndices,
286  int a_validBlockNum,
287  const RealVect& a_validMappedCenter,
288  const Vector<IntVect>& a_exponents,
289  int a_ghostBlockNum) const;
290 
291  void copyStencilsFromBlock(MBStencil& a_stencil,
292  const IntVect& a_iv,
293  const MBStencil& a_blockStencil) const;
294 
295  void copyVectorStencilsFromBlock(MBVectorStencil& a_vectorstencil,
296  const IntVect& a_iv,
297  const MBVectorStencil& a_blockVectorStencil) const;
298 
299  /// is defined?
301 
302  /// contains coordinate system
304 
305  /// all mapping blocks, from m_coordSysPtr
307 
308  /// Number of mapping blocks
310 
311  /// all block boundaries; from m_coordSysPtr
313 
315 
316  /// transformations from destination blocks to source blocks. Has m_nblocks components and lives on m_offsetAllBox.
317  /**
318  IndicesTransformation (*m_transformsAll(ivOff, srcBlock)[dstBlock]
319  is the transformation from dstBlock to srcBlock
320  in the chunk of the halo offset by IntVect ivOff from dstBlock.
321  */
322  // Vector< BaseFab<IndicesTransformation>* > m_transformsAll;
324 
325  /// dimensions that are fixed. Default is empty.
327 
328  /// dimensions that are fixed. Default is empty.
330 
331  /// coordinates in dimensions of m_fixedDims. Default is empty.
333 
334  /// dimensions that will be interpolated, which is all dimensions that are not in m_fixedDims. Default is 0:SpaceDim-1.
336 
337  /// 1 in interpolated dimensions, 0 in fixed dimensions
339 
340  /// these are used in the the (2*SpaceDim+1)-point 4th-order convolution stencil
344 };
345 
346 #include "NamespaceFooter.H"
347 
348 #endif // include guard
void getWeights(IVSFAB< MBStencil > &a_stencilsFab, const IndexType &a_type, const IntVectSet &a_ghostCellsIVS, const IVSFAB< IntVect > &a_validIndices, const IVSFAB< int > &a_validBlock, const IVSFAB< RealVect > &a_validMappedCenter, const Vector< IntVect > &a_exponents, int a_ghostBlockNum) const
Vector< int > m_interpDimsVect
dimensions that will be interpolated, which is all dimensions that are not in m_fixedDims. Default is 0:SpaceDim-1.
Definition: MultiBlockUtil.H:335
void getCollapsedLayout(BoxLayout &a_layoutCollapsed, const BoxLayout &a_layoutFull)
Class to describe a single element of a multi-block interpolation stencil.
Definition: MBStencilElement.H:20
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
Vector< IntVect > m_convBaseCells
Definition: MultiBlockUtil.H:342
IntVect m_interpUnit
1 in interpolated dimensions, 0 in fixed dimensions
Definition: MultiBlockUtil.H:338
Vector< int > m_fixedDimsVect
dimensions that are fixed. Default is empty.
Definition: MultiBlockUtil.H:329
void getFixedOffLayout(BoxLayout &a_layoutFixedOff, const BoxLayout &a_layoutFull)
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:145
Class to describe a multi-block interpolation stencil.
Definition: MBVectorStencil.H:21
Vector< Tuple< BlockBoundary, 2 *SpaceDim > > m_boundaries
all block boundaries; from m_coordSysPtr
Definition: MultiBlockUtil.H:312
void displacementPowers(Vector< Real > &a_powers, const IntVect &a_cell, const RealVect &a_commonMappedBasePoint, Real a_avgDistance, int a_thisBlockNum, int a_commonBlockNum, const Vector< IntVect > &a_exponents) const
return <((Xvec() - Xvec(a_commonMappedBasePoint))/a_avgDistance)^pvec>_(a_cell), for all pvec ...
void commonVertexStencilElements(Vector< MBStencilElement > &a_neighbors, const MBStencilElement &a_base) const
int m_nblocks
Number of mapping blocks.
Definition: MultiBlockUtil.H:309
IntVectSet extraBlockGhosts(const Box &a_baseBox, int a_ghostLayer, int a_baseBlockNum) const
MultiBlockCoordSys * m_coordSysPtr
contains coordinate system
Definition: MultiBlockUtil.H:303
const IndicesTransformation & blockTransform(int a_srcBlock, int a_dstBlock, const IntVect &a_offset) const
the transformation from block a_dstBlock to a_srcBlock, taking offset a_offset from a_dstBlock ...
Definition: IVSFAB.H:31
bool validCellShift(IntVect &a_shiftedCell, int &a_shiftedBlock, const IntVect &a_origCell, int a_origBlock, int a_dir, int a_shift) const
return shifted cell
Interval m_fixedDims
dimensions that are fixed. Default is empty.
Definition: MultiBlockUtil.H:326
int m_convSize
these are used in the the (2*SpaceDim+1)-point 4th-order convolution stencil
Definition: MultiBlockUtil.H:341
bool m_isDefined
is defined?
Definition: MultiBlockUtil.H:300
void vertexStencilElementAliases(Vector< MBStencilElement > &a_aliases, const MBStencilElement &a_base) const
IntVect whichOffset(int a_block, const IntVect &a_cell) const
the offset in [-1:1]^D of cell a_cell from the box of block a_block.
MultiBlockUtil()
default constructor
void validCellsFromVertices(Vector< IntVect > &a_cellIndices, Vector< int > &a_cellBlocks, const Vector< IntVect > &a_vertexIndices, const Vector< int > &a_vertexBlocks) const
return the set of all valid cells adjacent to a given set of vertices
Structure for passing component ranges in code.
Definition: Interval.H:23
const Vector< IndicesTransformation > & transformsSrcOff(int a_srcBlock, const IntVect &a_offset) const
transformations to block a_srcBlock, taking offset a_offset from all destination blocks ...
double Real
Definition: REAL.H:33
bool allGridsHaveFixedPt(const BoxLayout &a_layout)
void growIVS(IntVectSet &a_ivs, int a_bufferSize) const
add IntVects to an IntVectSet in all directions, even across block boundaries.
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:30
void getValid(IVSFAB< IntVect > &a_validIndices, IVSFAB< int > &a_validBlock, IVSFAB< RealVect > &a_validMappedCenter, const IntVectSet &a_ghostCellsIVS, int a_baseBlockNum) const
return index, block, and center in mapped coordinates of valid cell containing each ghost cell ...
void validStencilElementsFromVertices(Vector< MBStencilElement > &a_stencilElements, const Vector< MBStencilElement > &a_vertices) const
void getStencilCells(IVSFAB< MBStencil > &a_stencils, Vector< Box > &a_minBox, const IntVectSet &a_ghostCellsIVS, const IVSFAB< IntVect > &a_validIndices, const IVSFAB< int > &a_validBlock, const IVSFAB< RealVect > &a_validMappedCenter, int a_order, int a_radius) const
find the stencil cells and source blocks for all cells in a_ghostCellsIVS, and also the minimum Box c...
virtual interface class encapsulating multi-block mapping API
Definition: MultiBlockCoordSys.H:34
virtual ~MultiBlockUtil()
destructor
Vector< Real > m_convWeight
Definition: MultiBlockUtil.H:343
virtual void define(const MultiBlockCoordSys *a_coordSysPtr, Interval a_fixedDims=Interval(), Vector< int > a_fixedPt=Vector< int >())
void vertexAliases(Vector< IntVect > &a_aliasVertices, Vector< int > &a_aliasBlocks, const IntVect &a_baseVertex, int a_baseBlock) const
return list of all aliases of a vertex
The class MultiBlockUtil contains some functions used by MultiBlockLevelGeom, MultiBlockLevelExchange...
Definition: MultiBlockUtil.H:23
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
void displacementPowersTransformed(Vector< Real > &a_powers, const BaseFab< VectorTransformation > &a_vectorStencilTransformations, const IntVect &a_cell, const RealVect &a_commonMappedBasePoint, Real a_avgDistance, int a_thisBlockNum, int a_commonBlockNum, int a_ghostBlockNum, const Vector< IntVect > &a_exponents) const
void getVectorStencilCells(IVSFAB< MBVectorStencil > &a_vectorstencils, const IVSFAB< MBStencil > &a_stencils, const IntVectSet &a_ghostCellsIVS) const
Box m_offsetAllBox
Definition: MultiBlockUtil.H:314
BaseFab< Vector< IndicesTransformation > * > m_transformsAll
transformations from destination blocks to source blocks. Has m_nblocks components and lives on m_off...
Definition: MultiBlockUtil.H:323
virtual void undefine()
Box boxFixed(const Box &a_bx)
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Cell-Based or Node-Based Indices.
Definition: Box.H:45
Class to describe transformation of indices from one block to another.
Definition: IndicesTransformation.H:25
void getVectorWeights(IVSFAB< MBVectorStencil > &a_vectorstencilsFab, const Vector< BaseFab< VectorTransformation > * > &a_vectorStencilTransformations, const IndexType &a_type, const IntVectSet &a_ghostCellsIVS, const IVSFAB< IntVect > &a_validIndices, const IVSFAB< int > &a_validBlock, const IVSFAB< RealVect > &a_validMappedCenter, const Vector< IntVect > &a_exponents, int a_ghostBlockNum) const
void order2grad(LevelData< FArrayBox > &a_gradData, const LevelData< FArrayBox > &a_data)
returns a_gradData = gradient(a_data) on valid cells, taking 1-sided differences next to block bounda...
Vector< int > m_fixedPt
coordinates in dimensions of m_fixedDims. Default is empty.
Definition: MultiBlockUtil.H:332
Class to describe a multi-block interpolation stencil.
Definition: MBStencil.H:21
void copyVectorStencilsFromBlock(IVSFAB< MBVectorStencil > &a_vectorstencilsFab, const IntVectSet &a_ghostCellsIVS, const IVSFAB< MBVectorStencil > &a_blockVectorStencilsFab) const
void commonVertexCells(Vector< IntVect > &a_neighborCells, Vector< int > &a_neighborBlocks, const IntVect &a_baseCell, int a_baseBlock) const
return list of all cells that share a vertex with a given cell
void copyStencilsFromBlock(IVSFAB< MBStencil > &a_stencilsFab, const IntVectSet &a_ghostCellsIVS, const IVSFAB< MBStencil > &a_blockStencilsFab) const
copy from a_blockStencilsFab to a_stencilsFab on a_ghostCellsIVS, where the cells in the stencil of a...
void getVectorTransformations(Vector< BaseFab< VectorTransformation > * > &a_vectorTransformations, const IVSFAB< MBVectorStencil > &a_vectorstencilsFab, const IndexType &a_type, const IntVectSet &a_ghostCellsIVS, int a_ghostBlockNum) const
Vector< Box > m_mappingBlocks
all mapping blocks, from m_coordSysPtr
Definition: MultiBlockUtil.H:306