Chombo + EB + MF  3.2
BlockBaseRegister.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 // jafh, 5 Jan 2011
12 
13 #ifndef _BLOCKBASEREGISTER_H_
14 #define _BLOCKBASEREGISTER_H_
15 
16 #include <map>
17 
18 #include "MultiBlockCoordSys.H"
19 #include "BaseFab.H"
20 #include "LevelData.H"
21 #include "LoHiSide.H"
22 
23 #include "NamespaceHeader.H"
24 
25 /// Class to implement a single data register a mapped multiblock domain block boundary.
26 
27 template <class T> class BlockBaseRegister
28 {
29 public:
30 
31  /**
32  \name Constructor, destructor, and defines.
33  */
34  /*@{*/
35 
36  /// Empty constructor.
37  /**
38  */
40  : m_ghost(0), m_verbosity(0), m_isDefined(false), m_hasData(false), m_hasDefinedDataLayouts(false)
41  {}
42 
43  /// Constructor.
44  /**
45  – a_mblock: Pointer to multiblock coordinate system.
46  – a_grids: DisjointBoxLayout over which multiblock grid is defined.
47  – a_ghost: Extension of register domain for auxiliary data.
48  */
49  BlockBaseRegister(const MultiBlockCoordSys* a_mblock,
50  /// CELL-centered grids
51  const DisjointBoxLayout& a_grids,
52  /// ghost width for state variables
53  const int& a_ghost = 0 );
54 
55  /// virtual destructor
56  virtual ~BlockBaseRegister();
57 
58  /// Define function that matches constructor
59  /**
60  – a_mblock: Pointer to multiblock coordinate system.
61  – a_grids: DisjointBoxLayout over which multiblock grid is defined.
62  – a_ghost: Extension of register domain for auxiliary data.
63  */
64  void define(const MultiBlockCoordSys* a_mblock,
65  /// CELL-centered grids
66  const DisjointBoxLayout& a_grids,
67  /// ghost width for state variables
68  const int& a_ghost = 0 );
69 
70  /// Returns true if class has been defined, false otherwise.
71  bool isDefined() const
72  {
73  return m_isDefined;
74  }
75 
76  /// Set verbosity.
77  /**
78  Default is 0. Positive values output increasing amounts of information.
79  */
80  virtual void setVerbose(int a_verbose)
81  {
82  m_verbosity = a_verbose;
83  }
84 
85  /// Store data on block-boundary faces.
86  /**
87  – a_flux: Face-centered data to be stored.
88  – a_dataIndex: Index of box where flux has been computed.
89  – a_dir: Direction of the face.
90  – a_side: Low or high side of the box where the block-boundary
91  face lies.
92  */
93  void store(const T& a_data,
94  const DataIndex& a_dataIndex,
95  int a_dir,
96  Side::LoHiSide a_side);
97 
98  /// Increment data on block-boundary faces.
99  /**
100  – a_flux: Face-centered flux to be stored.
101  – a_dataIndex: Index of box where flux has been computed.
102  – a_dir: Direction of the face.
103  – a_side: Low or high side of the box where the block-boundary
104  face lies.
105  */
106  void increment(const T& a_flux,
107  const DataIndex& a_dataIndex,
108  int a_dir,
109  Side::LoHiSide a_side);
110 
111  /// Exchange data to fill exterior register regions.
112  /**
113  Perform data manipulation so that both interior and exterior register
114  data is current.
115  */
116  void exchange();
117 
118  ///
119  /**
120  Sets the contents of the register to zero.
121  */
122  void zeroRegister( const int a_n_comp=-1 );
123 
124  /// Returns whether or not a box has a block-boundary interface on one of its faces.
125  /**
126  – a_dataIndex: Index of box.
127  – a_dir: Direction of the face of the box.
128  – a_side: Low or high side of the box.
129  */
130  bool hasInterface(const DataIndex& a_dataIndex,
131  int a_dir,
132  Side::LoHiSide a_side) const;
133 
134  /// Return data on a block-boundary interface of a box, if hasInterface(a_dataIndex, a_dir, a_side) is true.
135  /**
136  – a_data: Face-centered data returned.
137  – a_dataIndex: Index of box.
138  – a_dir: Direction of the face.
139  – a_side: Low or high side of the box.
140  – a_sideData: Low or high side of the block-boundary interface,
141  from which data will be taken.
142  */
143  void fill(T& a_data,
144  const DataIndex& a_dataIndex,
145  int a_dir,
146  Side::LoHiSide a_side,
147  Side::LoHiSide a_sideData) const;
148 
149  /// Set the name of the register.
150  /**
151  String identifier for this register, useful for debugging output.
152  Default is UNDEFINED.
153  */
154  virtual void setName(const std::string& a_name)
155  {
156  m_name = a_name;
157  }
158 
159 protected:
160 
161  /// Returns true if the block-boundary in this direction on this side is an interface between blocks, false otherwise.
162  /**
163  – a_block: Index of the block.
164  – a_dir: Direction of the face.
165  – a_side: Low or high side of the box.
166  */
167  inline bool isInterface( const int& a_block,
168  const int& a_dir,
169  const Side::LoHiSide& a_side ) const;
170 
171  /// Returns true if data has been stored in the register, false otherwise.
172  inline bool hasData() const
173  {
174  return m_hasData;
175  }
176 
177  /// Returns the integer index of the block in which the box corresponding to the DataIndex resides.
178  /**
179  – a_dataIndex: Index of box.
180  */
181  inline int getBlockID( const DataIndex& a_dataIndex ) const;
182 
183  /// Returns the box corresponding to the block specified by the block integer index.
184  /**
185  – a_block: Index of the block.
186  */
187  inline const Box& getBlockBox( const int& a_block ) const;
188 
189  /// Returns the box corresponding to the block opposite to the block specified by the block integer index through the block-boundary specified by the integer index.
190  /**
191  – a_block: Index of the block.
192  – a_block: Index of the block boundary.
193  */
194  inline const Box& getNeighborBlockBox( const int& a_block,
195  const int& a_blockBdryIndex ) const;
196 
197  /// Returns the index transformation box corresponding to the Blockboundary specified by the block integer index and the block-boundary index.
198  /**
199  – a_block: Index of the block.
200  – a_block: Index of the block boundary.
201  */
203  const int& a_block,
204  const int& a_blockBdryIndex ) const;
205 
206  /// Returns the index of the neighboring block opposite the block in the direction and side spceified.
207  /**
208  – a_block: Index of the block.
209  – a_dir: Direction of the face.
210  – a_side: Low or high side of the box.
211  */
212  inline int getSrcBlockBdryIndex( const int& a_block,
213  const int& a_dir,
214  const Side::LoHiSide& a_side );
215 
216  /// Builds an array of vectors of boxes, one for each direction-side combination, that corresponds to either the full register, the src for external register regions, or the image of the src external regions.
217  /**
218  – a_boxes: Array of vector of boxes.
219  – a_boxProcMap: Array of vector of processor mappings.
220  – a_dataIndex: Array of vector of DataIndices that relate each box to a box in the underlying DisjointBoxLayout.
221  – a_type: Type of register box to build [DST, SRC, or EXC].
222  */
223  enum UseType
224  {
226  DST=0,
230  };
231 
232  void buildBoxVectors( Vector<Box> a_boxes[2*CH_SPACEDIM],
233  Vector<int> a_boxProcMap[2*CH_SPACEDIM],
234  Vector<DataIndex> a_dataIndex[2*CH_SPACEDIM],
235  const UseType a_type );
236 
237  /// Builds a mapping from the block-boundary index of neighboring block to the local block-boundary index.
238  /**
239  – a_map: Array of vector relating block-boundary indices.
240  */
242 
243  /// Build all box layouts for the data register
244  void buildRegisterLayout();
245 
246  /// Build all box layouts for the source boxes
247  void buildSrcRegisterLayout();
248 
249  /// Build all disjoint box layouts for the data exchange
251 
252  /// Define each of the three internally used data layouts
253  void defineDataLayouts( const int a_ncomp );
254 
255  /// Undefine each of the three internally used data layouts
256  void clearDataLayouts();
257 
258  /// Build a box layout for the data register given a vector of boxes with processor mappings and related DataIndices from the underlying disjoint box layout.
259  /**
260  – a_layout: Resulting box layout.
261  – a_map: Mapping between DataIndexes of the underlying disjoint box layout and DataIndexes of the resulting box layout.
262  – a_boxes: Vector of boxes.
263  – a_boxProcMap: Vector of processor mappings.
264  – a_indices: Vector of DataIndices that relate each box to a box in the underlying DisjointBoxLayout.
265  */
266  inline void createDstBoxLayout( DisjointBoxLayout& a_layout,
267  LayoutData<DataIndex>& a_map,
268  const Vector<Box>& a_boxes,
269  const Vector<int>& a_procs,
270  const Vector<DataIndex>& a_indices );
271 
272  /// Build the box layout and associated box mappings for the source boxes
273  /**
274  – a_layout: Resulting box layout.
275  – a_dstToSrcMap: Array of mappings between DataIndexes of the destination box layout and DataIndexes of the resulting box layout.
276  – a_boxes: Vector of boxes.
277  – a_boxProcMap: Vector of processor mappings.
278  – a_indices: Vector of DataIndices that relate each box to a box in the underlying DisjointBoxLayout.
279  – a_dstBlockBdryIndices: Vector of DataIndices that relate each box to a block boundry of the destination block.
280  – a_grdToDstMap: Array of vector of DataIndices that relate each in the underlying DisjointBoxLayout to a box in the destination register.
281  */
282  inline void createSrcBoxLayout(
283  DisjointBoxLayout& a_layout,
284  LayoutData<DataIndex> a_dstToSrcMap[2*CH_SPACEDIM],
285  const Vector<Box>& a_boxes,
286  const Vector<int>& a_procs,
287  const Vector<DataIndex>& a_indices,
288  const Vector<int>& a_dstBlockBdryIndices,
289  const LayoutData<DataIndex> a_grdToDstMap[2*CH_SPACEDIM] );
290 
291  /// Build the box layout and associated box mappings for the data exchange
292  /**
293  – a_layout: Resulting box layout.
294  – a_dstToExcMap: Array of mappings between DataIndexes of the destination box layout and DataIndexes of the resulting box layout.
295  – a_boxes: Vector of boxes.
296  – a_boxProcMap: Vector of processor mappings.
297  – a_indices: Vector of DataIndices that relate each box to a box in the underlying DisjointBoxLayout.
298  – a_grdToDstMap: Array of vector of DataIndices that relate each in the underlying DisjointBoxLayout to a box in the destination register.
299  */
300  inline void createExchangeBoxLayout(
301  DisjointBoxLayout& a_layout,
302  LayoutData<DataIndex>& a_dstToExcMap,
303  const Vector<Box>& a_boxes,
304  const Vector<int>& a_procs,
305  const Vector<DataIndex>& a_indices,
306  const LayoutData<DataIndex>& a_grdToDstMap );
307 
308  /// Copy, including parallel exchange, of data from interior exchange registers to exterior source registers.
309  inline void copyToSrcRegister();
310 
311  /// Local copy of data from exterior source registers to exterior full register.
312  inline void copyToDstRegister();
313 
314  /// Print all registers to pout().
315  void printRegisters() const;
316 
317  /// Print the specified register.
318  /**
319  – a_register: Array of registers to print.
320  */
321  inline void print(
322  const LevelData<T> a_register[2*CH_SPACEDIM] ) const;
323  inline void print(
324  const BoxLayoutData<T> a_register[2*CH_SPACEDIM] ) const;
325 
326  inline bool hasStorage() const { return m_hasDefinedDataLayouts; }
327 
331  int m_ghost;
334  bool m_hasData;
336  std::string m_name;
338 
339  typedef std::map<int,int> BlockBdryIndexMap;
341 
342  // Data register
343 // BoxLayout m_registerLayout[2*CH_SPACEDIM];
344 // BoxLayoutData<T> m_register[2*CH_SPACEDIM];
347 
350 
353 // BoxLayout m_srcRegisterLayout[2*CH_SPACEDIM];
354 // BoxLayoutData<T> m_srcRegister[2*CH_SPACEDIM];
355 
359 };
360 
361 #include "NamespaceFooter.H"
362 
363 #include "BlockBaseRegisterImplem.H"
364 
365 #endif // include guard
int m_ghost
Definition: BlockBaseRegister.H:331
void buildSrcRegisterLayout()
Build all box layouts for the source boxes.
Definition: BlockBaseRegisterImplem.H:666
IntVect m_ghostVect
Definition: BlockBaseRegister.H:337
bool isDefined() const
Returns true if class has been defined, false otherwise.
Definition: BlockBaseRegister.H:71
int getBlockID(const DataIndex &a_dataIndex) const
Returns the integer index of the block in which the box corresponding to the DataIndex resides...
Definition: BlockBaseRegisterImplem.H:404
std::map< int, int > BlockBdryIndexMap
Definition: BlockBaseRegister.H:339
#define CH_SPACEDIM
Definition: SPACE.H:51
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
void copyToDstRegister()
Local copy of data from exterior source registers to exterior full register.
Definition: BlockBaseRegisterImplem.H:889
DisjointBoxLayout m_srcRegisterLayout[2 *CH_SPACEDIM]
Definition: BlockBaseRegister.H:351
bool m_isDefined
Definition: BlockBaseRegister.H:333
const Box & getNeighborBlockBox(const int &a_block, const int &a_blockBdryIndex) const
Returns the box corresponding to the block opposite to the block specified by the block integer index...
Definition: BlockBaseRegisterImplem.H:422
LevelData< T > m_register[2 *CH_SPACEDIM]
Definition: BlockBaseRegister.H:346
int m_verbosity
Definition: BlockBaseRegister.H:332
Class to implement a single data register a mapped multiblock domain block boundary.
Definition: BlockBaseRegister.H:27
LevelData< T > m_excRegister[2 *CH_SPACEDIM]
Definition: BlockBaseRegister.H:349
void createExchangeBoxLayout(DisjointBoxLayout &a_layout, LayoutData< DataIndex > &a_dstToExcMap, const Vector< Box > &a_boxes, const Vector< int > &a_procs, const Vector< DataIndex > &a_indices, const LayoutData< DataIndex > &a_grdToDstMap)
Build the box layout and associated box mappings for the data exchange.
Definition: BlockBaseRegisterImplem.H:599
void defineDataLayouts(const int a_ncomp)
Define each of the three internally used data layouts.
Definition: BlockBaseRegisterImplem.H:78
BlockBaseRegister()
Empty constructor.
Definition: BlockBaseRegister.H:39
LayoutData< DataIndex > m_grdToDstMap[2 *CH_SPACEDIM]
Definition: BlockBaseRegister.H:356
bool m_hasData
Definition: BlockBaseRegister.H:334
Definition: BlockBaseRegister.H:228
void clearDataLayouts()
Undefine each of the three internally used data layouts.
Definition: BlockBaseRegisterImplem.H:97
void buildExchangeRegisterLayout()
Build all disjoint box layouts for the data exchange.
Definition: BlockBaseRegisterImplem.H:697
void store(const T &a_data, const DataIndex &a_dataIndex, int a_dir, Side::LoHiSide a_side)
Store data on block-boundary faces.
Definition: BlockBaseRegisterImplem.H:110
Definition: BlockBaseRegister.H:226
void zeroRegister(const int a_n_comp=-1)
Definition: BlockBaseRegisterImplem.H:278
DisjointBoxLayout m_grids
Definition: BlockBaseRegister.H:328
void buildBoxVectors(Vector< Box > a_boxes[2 *CH_SPACEDIM], Vector< int > a_boxProcMap[2 *CH_SPACEDIM], Vector< DataIndex > a_dataIndex[2 *CH_SPACEDIM], const UseType a_type)
Definition: BlockBaseRegisterImplem.H:724
virtual ~BlockBaseRegister()
virtual destructor
Definition: BlockBaseRegisterImplem.H:39
Vector< BlockBdryIndexMap > m_blockBdryIndexMap
Definition: BlockBaseRegister.H:340
bool isInterface(const int &a_block, const int &a_dir, const Side::LoHiSide &a_side) const
Returns true if the block-boundary in this direction on this side is an interface between blocks...
Definition: BlockBaseRegisterImplem.H:487
std::string m_name
Definition: BlockBaseRegister.H:336
void print(const LevelData< T > a_register[2 *CH_SPACEDIM]) const
Print the specified register.
Definition: BlockBaseRegisterImplem.H:993
new code
Definition: BoxLayoutData.H:170
void createSrcBoxLayout(DisjointBoxLayout &a_layout, LayoutData< DataIndex > a_dstToSrcMap[2 *CH_SPACEDIM], const Vector< Box > &a_boxes, const Vector< int > &a_procs, const Vector< DataIndex > &a_indices, const Vector< int > &a_dstBlockBdryIndices, const LayoutData< DataIndex > a_grdToDstMap[2 *CH_SPACEDIM])
Build the box layout and associated box mappings for the source boxes.
Definition: BlockBaseRegisterImplem.H:558
Data on a BoxLayout.
Definition: BoxLayoutData.H:97
bool hasStorage() const
Definition: BlockBaseRegister.H:326
DisjointBoxLayout m_excRegisterLayout[2 *CH_SPACEDIM]
Definition: BlockBaseRegister.H:348
Definition: BlockBaseRegister.H:227
ProblemDomain m_domain
Definition: BlockBaseRegister.H:329
LayoutData< DataIndex > m_dstToExcMap[2 *CH_SPACEDIM]
Definition: BlockBaseRegister.H:357
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:30
LoHiSide
Definition: LoHiSide.H:27
bool hasInterface(const DataIndex &a_dataIndex, int a_dir, Side::LoHiSide a_side) const
Returns whether or not a box has a block-boundary interface on one of its faces.
Definition: BlockBaseRegisterImplem.H:315
virtual interface class encapsulating multi-block mapping API
Definition: MultiBlockCoordSys.H:34
int getSrcBlockBdryIndex(const int &a_block, const int &a_dir, const Side::LoHiSide &a_side)
Returns the index of the neighboring block opposite the block in the direction and side spceified...
Definition: BlockBaseRegisterImplem.H:453
void fill(T &a_data, const DataIndex &a_dataIndex, int a_dir, Side::LoHiSide a_side, Side::LoHiSide a_sideData) const
Return data on a block-boundary interface of a box, if hasInterface(a_dataIndex, a_dir, a_side) is true.
Definition: BlockBaseRegisterImplem.H:344
bool m_hasDefinedDataLayouts
Definition: BlockBaseRegister.H:335
IndicesTransformation getTransformation(const int &a_block, const int &a_blockBdryIndex) const
Returns the index transformation box corresponding to the Blockboundary specified by the block intege...
Definition: BlockBaseRegisterImplem.H:441
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
DisjointBoxLayout m_registerLayout[2 *CH_SPACEDIM]
Definition: BlockBaseRegister.H:345
Definition: DataIndex.H:114
void buildRegisterLayout()
Build all box layouts for the data register.
Definition: BlockBaseRegisterImplem.H:637
void copyToSrcRegister()
Copy, including parallel exchange, of data from interior exchange registers to exterior source regist...
Definition: BlockBaseRegisterImplem.H:842
void printRegisters() const
Print all registers to pout().
Definition: BlockBaseRegisterImplem.H:1031
void increment(const T &a_flux, const DataIndex &a_dataIndex, int a_dir, Side::LoHiSide a_side)
Increment data on block-boundary faces.
Definition: BlockBaseRegisterImplem.H:179
void createDstBoxLayout(DisjointBoxLayout &a_layout, LayoutData< DataIndex > &a_map, const Vector< Box > &a_boxes, const Vector< int > &a_procs, const Vector< DataIndex > &a_indices)
Build a box layout for the data register given a vector of boxes with processor mappings and related ...
Definition: BlockBaseRegisterImplem.H:520
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
void exchange()
Exchange data to fill exterior register regions.
Definition: BlockBaseRegisterImplem.H:247
void define(const MultiBlockCoordSys *a_mblock, const DisjointBoxLayout &a_grids, const int &a_ghost=0)
Define function that matches constructor.
Definition: BlockBaseRegisterImplem.H:46
Class to describe transformation of indices from one block to another.
Definition: IndicesTransformation.H:25
UseType
Builds an array of vectors of boxes, one for each direction-side combination, that corresponds to eit...
Definition: BlockBaseRegister.H:223
virtual void setVerbose(int a_verbose)
Set verbosity.
Definition: BlockBaseRegister.H:80
LevelData< T > m_srcRegister[2 *CH_SPACEDIM]
Definition: BlockBaseRegister.H:352
Definition: BlockBaseRegister.H:225
const Box & getBlockBox(const int &a_block) const
Returns the box corresponding to the block specified by the block integer index.
Definition: BlockBaseRegisterImplem.H:413
LayoutData< DataIndex > m_dstToSrcMap[2 *CH_SPACEDIM]
Definition: BlockBaseRegister.H:358
MultiBlockCoordSys * m_coordsys
Definition: BlockBaseRegister.H:330
void buildInverseBlockBdryIndexMap(Vector< int > a_map[2 *CH_SPACEDIM])
Builds a mapping from the block-boundary index of neighboring block to the local block-boundary index...
Definition: BlockBaseRegisterImplem.H:816
Definition: BlockBaseRegister.H:229
virtual void setName(const std::string &a_name)
Set the name of the register.
Definition: BlockBaseRegister.H:154
bool hasData() const
Returns true if data has been stored in the register, false otherwise.
Definition: BlockBaseRegister.H:172