Proto  3.2
Proto_MBLevelMap.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_MB_LEVEL_MAP_
3 #define _PROTO_MB_LEVEL_MAP_
4 
5 #include <optional>
6 
8 #include "Proto_MBLevelBoxData.H"
9 #include "Proto_MBMapOp.H"
10 #include "Proto_Operator.H"
11 //#include "Proto_CubedSphereKernels.H"
12 
13 namespace Proto
14 {
15 
16 /// Single Level Mapped Multiblock Map
17 /** This class provides an interface for constructing maps for use in single level
18  * mapped multiblock applications.
19  *
20  * When a map is constructed, coordinate and Jacobian data are cached for all valid
21  * regions of the supplied MBDisjointBoxLayout as well as proscribed ghost regions.
22  * However, the map's apply function can be used to compute these quantities on any
23  * domain where the associated functions are defined.
24  *
25  * USAGE:
26  * To use this interface, create a class which
27  * inherits from MBLevelMap. The map itself is implemented by defining the one
28  * of the virtual "apply" functions (the user may supply either one or both
29  * depending on whether or not they need and/or would like to define how the metric
30  * tensor is computed). The user may also implement the virtual init function which will be
31  * called during construction of the Map. The init function is useful for caching constant
32  * data such as operators, stencils, or metrics in order to prevent computing these
33  * quantities each time apply is called.
34  */
35 template<typename MAP, MemType MEM = MEMTYPE_DEFAULT>
36 class MBLevelMap
37 {
38  public:
39 
40  /// Trivial Constructor
41  inline MBLevelMap(){}
42 
43  /// Non-Trivial Constructor
44  inline MBLevelMap(
45  const MBDisjointBoxLayout& a_layout,
46  const Array<Point, DIM+1>& a_ghost,
47  unsigned int a_focalBlock = 0);
48 
49  /// Non-Trivial Constructor
50  inline MBLevelMap(
51  const MBDisjointBoxLayout& a_layout,
52  Point a_ghost,
53  unsigned int a_focalBlock = 0);
54 
55  /// Define
56  /** Delayed construction.
57  *
58  * \param a_layout A mapped multiblock layout defining the domain
59  * \param a_ghost An array of ghost data sizes. This ghost array is used
60  * To define how much ghost data should be allocated for
61  * cached arrays of the coordinates and Jacobian.
62  * \param a_focalBlock The "focus" block id associated with this map. Often unused.
63  */
64  inline void define(
65  const MBDisjointBoxLayout& a_layout,
66  const Array<Point, DIM+1>& a_ghost,
67  unsigned int a_focalBlock = 0);
68 
69  inline void define(
70  const MBDisjointBoxLayout& a_layout,
71  Point a_ghost,
72  unsigned int a_focalBlock = 0);
73 
74  inline void initialize() const;
75 
76  /// Access Cached Coordinate Values
77  /** Returns an MBLevelBoxData containing the cached coordinate data.
78  * The returned data has NODE centering.
79  */
81 
82  inline std::shared_ptr<MBLevelBoxData<double, DIM, MEM, PR_NODE>> mapData() {return m_X; }
83 
84  /// Access Cached Coordinate Values (Const Overload)
86 
87  /// Jacobian Access
88  /** Returns an MBLevelBoxData containing the cached Jacobian data.
89  * The returned data has CELL centering and is assumed to be cell averaged.
90  */
92 
93  inline std::shared_ptr<MBLevelBoxData<double, 1, MEM, PR_CELL>> jacobianData() {return m_J; }
94  /// Jacobian Access (Const Overload)
96 
97  /// Compute Map
98  /** Users should override this function when defining their map if they do not want
99  * to explicitly define the metric tensor (NT). The domains of the coordinate and
100  * Jacobian quantities are assumed to be defined before they are input to this function.
101  * Note that the ghost values used to define the map during construction have absolutely
102  * no bearing on the valid domains for this function, so long as the relevant analytic
103  * functions are defined.
104  *
105  * \param a_X: Coordinates at nodes [input/output]
106  * \param a_J: Cell averaged jacobian [input/output]
107  * \param a_index: MBIndex corresponding to the patch where the operator is being applied
108  */
109  inline void apply(
112  unsigned int a_block) const;
113 
114  /// Compute Map (With Metrics)
115  /** Users should override this function when defining their map if they want
116  * to explicitly define the metric tensor (NT). The domains of the coordinate and
117  * Jacobian quantities are assumed to be defined before they are input to this function.
118  * Note that the ghost values used to define the map during construction have absolutely
119  * no bearing on the valid domains for this function, so long as the relevant analytic
120  * functions are defined.
121  *
122  * \param a_X: Coordinates at nodes [input/output]
123  * \param a_J: Cell averaged jacobian [input/output]
124  * \param a_NT: Face averaged metric terms in each coordinate direction [output]
125  * \param a_index: MBIndex corresponding to the patch where the operator is being applied
126  */
127  inline void apply(
131  unsigned int a_block) const;
132 
133  /// Compute Map With Rotation
134  /**
135  * Used internally for the case where X and J are defined on domains in
136  * a different coordinate system from the block of the map computation (defined by a_index).
137  * This function creates a temporary version of X and J with domains in the block associated
138  * with a_index, computes X and J, and copies the result with rotation into the outputs.
139  *
140  * Not recommended for public use.
141  */
142  inline void doApply(
145  unsigned int a_computeBlock,
146  unsigned int a_outBlock) const;
147 
148  /// Compute Cell Centered Coordinates
149  /** Returns the cell-centered coordinates on a specified range.
150  *
151  * \param a_box Output range
152  * \param a_computeBlock Block index associated with the coordinates being computed
153  * \param a_outBlock Block index associated with the input range
154  */
156  const Box& a_box,
157  unsigned int a_computeBlock,
158  unsigned int a_outBlock) const;
159 
161  /// Compute Cell Centered Coordinates
162  /** Returns the cell-averaged coordinates on a specified range.
163  *
164  * \param a_box Output range
165  * \param a_computeBlock Block index associated with the coordinates being computed
166  * \param a_outBlock Block index associated with the input range
167  */
169  const Box& a_box,
170  unsigned int a_computeBlock,
171  unsigned int a_outBlock) const;
172 
174  const Point& point,
175  const BlockIndex& block) const;
176 
178  const Point& point,
179  const BlockIndex& block,
180  const Array<double, DIM>& offset) const;
181  /// Compute Mapped Coordinates
182  /** Returns coordinates in mapped space of a given data point. The Coordinates
183  * are of the cell center of the point plus the offset which is in units of the grid spacing.
184  */
185 // inline Array<double, DIM> mappedCoords(
186 // const MBDataPoint& a_point,
187 // const Array<double, DIM>& a_offset) const;
188 
189 // /// Compute Mapped Coordinates (No Offset)
190 // inline Array<double, DIM> mappedCoords(const MBDataPoint& a_point) const;
191 
192  /// Analytic Map (DataPoint Cell Center)
193  inline Array<double, DIM> apply(const MBDataPoint& a_point) const;
194 
195  /// Analytic Map (DataPoint With Offset)
196  inline Array<double, DIM> apply(
197  const MBDataPoint& a_point,
198  const Array<double, DIM>& a_offset) const;
199 
200  /// Compute Cell Centered Coordinates
201  /** Computes the cell-centered coodinate values at a specified MBDataPoint */
202  inline Array<double, DIM> cellCentered(const MBDataPoint& a_point) const;
203 
204  /// Compute Cell Centered Coordinates, analytic case.
205  /** Computes the cell-centered coodinate valuesas a specified analytic function, */
206  inline Array<double, DIM> analyticCellCentered(const MBDataPoint& a_point) const;
207 
208  /// Compute Cell Averaged Coordinates
209  /** Computes the cell-averaged coodinate values at a specified MBDataPoint */
210  inline Array<double, DIM> cellAveraged(const MBDataPoint& a_point) const;
211 
212  /// Get Layout
213  inline const MBDisjointBoxLayout& layout() const;
214 
215  /// Get Mapped Grid Spacing
216  inline const Array<double, DIM> dx(BlockIndex a_block) const;
217 
218  /// Get Operator
219  inline MAP& op(BlockIndex a_block) const;
220 
221  /// Get Ghost Sizes
222  inline Array<Point, DIM+1> ghost() const { return m_ghost; }
224  /// Get Mapped Coordinate Values
225  /** Given a node-centered box and grid spacing, generate the node centered mapped
226  * coordinates. This assumes that the origin corresponds to the point (0,0,...,0) and
227  * that the input box already accounts for node centering (e.g. Box::grow(PR_NODE) is
228  * assumed to already have been called.)
229  *
230  * /param a_box A box that already accounts for node centering
231  * /param a_dx Grid spacing
232  */
233  inline BoxData<double, DIM, MEM> X(const Box& a_box, const Array<double, DIM>& a_dx) const;
234 
235  inline MAP& operator[](BlockIndex block);
236 
237  /// @brief Convert a Point from one block's index space to another by using forward / inverse mapping
238  /// @param srcPoint Point in the source block's index space
239  /// @param srcBlock Source block
240  /// @param dstBlock Destination block
241  /// @return
242  inline Point convertPoint(Point srcPoint, BlockIndex srcBlock, BlockIndex dstBlock) const;
244  inline std::optional<std::pair<MBIndex, Point>> whichNeighborContains(const MBIndex& localIndex, const Point& localPoint, bool checkLocalInteriorGhostCells = true) const;
245 
246  private:
248  unsigned int m_focalBlock;
250  mutable std::vector<std::shared_ptr<MAP>> m_ops; ///< Map operators
251  std::vector<Array<double, DIM>> m_dx; ///< Mapped space grid spacing
253  mutable bool m_initialized;
254  mutable std::shared_ptr<MBLevelBoxData<double, DIM, MEM, PR_NODE>> m_X; ///< Cached coodinate values
255  mutable std::shared_ptr<MBLevelBoxData<double, 1, MEM, PR_CELL>> m_J; ///< Cached Jacobian values
256  //mutable std::vector<std::unordered_map<MBPoint, MBPoint>> m_pointMap; ///< Cached Point conversions
257 };
258 
259 #include "implem/Proto_MBLevelMapImplem.H"
260 } // end namespace Proto
261 #endif // end include guard
const MBDisjointBoxLayout & layout() const
Get Layout.
Definition: Proto_MBLevelMap.H:262
Array< double, DIM > analyticCellCentered(const MBDataPoint &a_point) const
Compute Cell Centered Coordinates, analytic case.
Definition: Proto_MBLevelMap.H:243
Point convertPoint(Point srcPoint, BlockIndex srcBlock, BlockIndex dstBlock) const
Convert a Point from one block&#39;s index space to another by using forward / inverse mapping...
Definition: Proto_MBLevelMap.H:325
Multidimensional Rectangular Array.
Definition: Proto_BoxData.H:314
int BlockIndex
Defines what type is used for indexing block entities.
Definition: Proto_MBGraph.H:9
std::optional< std::pair< MBIndex, Point > > whichNeighborContains(const MBIndex &localIndex, const Point &localPoint, bool checkLocalInteriorGhostCells=true) const
Definition: Proto_MBLevelMap.H:338
Single Level Mapped Multiblock Map.
Definition: Proto_MBLevelBoxData.H:19
bool m_initialized
Definition: Proto_MBLevelMap.H:253
std::vector< Array< double, DIM > > m_dx
Mapped space grid spacing.
Definition: Proto_MBLevelMap.H:251
MBLevelBoxData< double, 1, MEM, PR_CELL > & jacobian()
Jacobian Access.
Definition: Proto_MBLevelMap.H:310
void apply(BoxData< double, DIM, MEM > &a_X, BoxData< double, 1, MEM > &a_J, unsigned int a_block) const
Compute Map.
Definition: Proto_MBLevelMap.H:91
std::shared_ptr< MBLevelBoxData< double, 1, MEM, PR_CELL > > m_J
Cached Jacobian values.
Definition: Proto_MBLevelMap.H:255
Multiblock Level Box Data.
Definition: Proto_MBLevelBoxData.H:17
void doApply(BoxData< double, DIM, MEM > &a_X, BoxData< double, 1, MEM > &a_J, unsigned int a_computeBlock, unsigned int a_outBlock) const
Compute Map With Rotation.
Definition: Proto_MBLevelMap.H:112
BoxData< double, DIM, MEM > cellCentered(const Box &a_box, unsigned int a_computeBlock, unsigned int a_outBlock) const
Compute Cell Centered Coordinates.
Definition: Proto_MBLevelMap.H:149
std::shared_ptr< MBLevelBoxData< double, DIM, MEM, PR_NODE > > m_X
Cached coodinate values.
Definition: Proto_MBLevelMap.H:254
An interval in DIM dimensional space.
Definition: Proto_Box.H:29
Array< double, DIM > mappedCoords(const Point &point, const BlockIndex &block) const
Definition: Proto_MBLevelMap.H:182
MBDisjointBoxLayout m_layout
Definition: Proto_MBLevelMap.H:252
const Array< double, DIM > dx(BlockIndex a_block) const
Get Mapped Grid Spacing.
Definition: Proto_MBLevelMap.H:265
MAP & op(BlockIndex a_block) const
Get Operator.
Definition: Proto_MBLevelMap.H:272
std::shared_ptr< MBLevelBoxData< double, DIM, MEM, PR_NODE > > mapData()
Definition: Proto_MBLevelMap.H:82
MBLevelMap()
Trivial Constructor.
Definition: Proto_MBLevelMap.H:41
unsigned int m_focalBlock
Definition: Proto_MBLevelMap.H:248
Definition: Proto_Array.H:17
Stencil< double > m_c2c
Definition: Proto_MBLevelMap.H:249
std::vector< std::shared_ptr< MAP > > m_ops
Map operators.
Definition: Proto_MBLevelMap.H:250
std::shared_ptr< MBLevelBoxData< double, 1, MEM, PR_CELL > > jacobianData()
Definition: Proto_MBLevelMap.H:93
A templated constant size array object similar to std::array, but with the ability to be used inside ...
Definition: Proto_Array.H:28
BoxData< double, DIM, MEM > X(const Box &a_box, const Array< double, DIM > &a_dx) const
Get Mapped Coordinate Values.
Definition: Proto_MBLevelMap.H:278
void initialize() const
Definition: Proto_MBLevelMap.H:64
Integer Valued Vector.
Definition: Proto_Point.H:24
Definition: Proto_MBDisjointBoxLayout.H:14
Array< Point, DIM+1 > m_ghost
Definition: Proto_MBLevelMap.H:247
MAP & operator[](BlockIndex block)
Definition: Proto_MBLevelMap.H:85
BoxData< double, DIM, MEM > cellAveraged(const Box &a_box, unsigned int a_computeBlock, unsigned int a_outBlock) const
Compute Cell Centered Coordinates.
Definition: Proto_MBLevelMap.H:135
MBLevelBoxData< double, DIM, MEM, PR_NODE > & map()
Access Cached Coordinate Values.
Definition: Proto_MBLevelMap.H:296
Definition: Proto_MBDataPoint.H:10
Array< Point, DIM+1 > ghost() const
Get Ghost Sizes.
Definition: Proto_MBLevelMap.H:222
void define(const MBDisjointBoxLayout &a_layout, const Array< Point, DIM+1 > &a_ghost, unsigned int a_focalBlock=0)
Define.
Definition: Proto_MBLevelMap.H:42
Definition: Proto_BoxData.H:1436