Proto  3.2
Proto_MBInterpOp.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_MB_INTERP_OP_
3 #define _PROTO_MB_INTERP_OP_
4 
5 #include "Proto.H"
6 #include "Proto_MBLevelBoxData.H" //for MBDataPoint definition
8 #include "Proto_Matrix.H"
9 #include "Proto_Operator.H"
10 #include "Proto_MBPointInterpOp.H"
11 #include <unordered_set>
12 #include <algorithm>
13 
14 namespace Proto
15 {
16  // used for the hash table
17  class MBPointID
18  {
19  public:
20 
21  inline MBPointID(Point a_pt, int a_index) : m_point(a_pt), m_index(a_index) {}
22 
23  inline MBPointID(const MBPointID& a_rhs) : m_point(a_rhs.m_point), m_index(a_rhs.m_index) {}
24  inline bool operator<(const MBPointID& a_rhs) const
25  {
26  if (m_index != a_rhs.m_index) { return m_index < a_rhs.m_index; }
27  if (m_point != a_rhs.m_point) { return m_point < a_rhs.m_point; }
28  return false;
29  }
30 
31  inline bool operator==(const MBPointID& a_rhs) const
32  {
33  return ((m_index == a_rhs.m_index) && (m_point == a_rhs.m_point));
34  }
35 
36  inline Point point() const { return m_point; }
37  inline BlockIndex index() const {return m_index; }
38 
39  struct Hash {
40  std::size_t operator()(const MBPointID& a_pt) const {
41  std::size_t hashValue = 0;
42  hash_combine(hashValue, a_pt.index());
43  for (int ii = 0; ii < DIM; ii++)
44  {
45  hash_combine(hashValue, a_pt.point()[ii]);
46  }
47  return hashValue;
48  }
49 
50  void hash_combine(std::size_t& seed, int value) const {
51  seed ^= std::hash<int>{}(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
52  }
53  };
54 
55  private:
56 
57  const Point m_point;
58  const int m_index;
59  };
60 
61  /// Mapped Multiblock Block Boundary Interpolation Operator
62  /** MBInterpOp interpolates data to all block boundary ghost cells in a
63  * MBLevelBoxData. Ghost cells associated with domain boundaries are not
64  * affected. */
65  class MBInterpOp
66  {
67  public:
68 
69  inline MBInterpOp();
70 
71  /// Initialize
72  /** This function does not create any operators. The user must call define separately */
73  inline MBInterpOp(Point a_ghost, unsigned int a_order = 4);
74 
75  template<typename MAP, MemType MEM>
76  inline MBInterpOp(
77  const MBLevelMap<MAP, MEM>& a_map,
78  int a_order = 4);
79 
80  /// Define Block
81  /** Builds the necessary MBPointInterpOp objects for each block boundary ghost cell
82  * implied by the input MBLevelMap and the number of ghost cells this was initialized
83  * with (see constructor). This function only defines the operators used to interpolate
84  * into the specified block. A user may choose to specify a different version of
85  * physical space when building the operators for each block */
86  template<typename MAP, MemType MEM>
87  inline void define(
88  const MBLevelMap<MAP, MEM>& a_map,
89  int a_order = 4);
90 
91  /// Define Block
92  /** Builds the necessary MBPointInterpOp objects for each block boundary ghost cell
93  * implied by the input MBLevelMap and the number of ghost cells this was initialized
94  * with (see constructor). This function only defines the operators used to interpolate
95  * into the specified block. A user may choose to specify a different version of
96  * physical space when building the operators for each block */
97  template<typename MAP, MemType MEM>
98  inline void define(
99  const MBLevelMap<MAP, MEM>& a_map,
100  MBInterpLayout a_interpLayout,
101  int a_order = 4);
102 
103  template<typename MAP, MemType MEM>
104  inline void define(
105  const std::vector<std::shared_ptr<MBLevelMap<MAP, MEM>>>& a_maps,
106  MBInterpLayout a_interpLayout,
107  int a_order = 4);
108 
109  /// Manual Operator Insertion
110  /** Allows a user to build an MBInterpOp by manually constructing the point ops
111  */
112  inline void insert(std::shared_ptr<MBPointInterpOp> a_op);
114  /// Apply
115  /** Interpolates from source data to all block boundary ghost cells in the destination.
116  * It is assumed that MBLevelBoxData::fillBoundaries() has been called on the source
117  * data beforehand. */
118  template<typename T, unsigned int C, MemType MEM>
119  inline void apply(
122 
123  /// Coefficients
124  /** Writes the first P coefficients of the interpolating polynomial to a specified
125  * component of a specified source data array. Useful for debugging */
126  /*
127  template<typename T, unsigned int C, unsigned int P, MemType MEM>
128  inline void coefs(
129  MBLevelBoxData<T, P, MEM>& a_coefs,
130  MBLevelBoxData<T, C, MEM>& a_src,
131  int a_srcComponent = 0);
132  */
133 
134  /// Get Point Operator
135  /** Returns the MBPointInterpOp associated with a specified target cell. */
136  inline MBPointInterpOp& operator()(const MBDataPoint& a_target)
137  {
138  for (auto& op : m_ops)
139  {
140  if (a_target == op->target()) {return *op;}
141  }
142  MayDay<void>::Abort("Failed to find op at target");
143  }
144  void print() const;
145  void writeFootprint(std::string filename) const;
146  template<typename MAP, MemType MEM>
147  void writeLevelFootprint(const MBLevelMap<MAP, MEM>& map, std::string filename) const;
148  template<typename T, unsigned int C, MemType MEM>
149  void printErrorPoints(
151  T a_eps = 0);
152 
153  private:
154 
155  template<typename MAP, MemType MEM>
156  void addPointOps(const MBIndex& index, Point dir, const MBLevelMap<MAP,MEM>& map);
157  bool containsOp(Point dataPoint, const MBIndex& index) const;
158  template<typename MAP, MemType MEM>
159  void addPointOp(
160  Point dataPoint,
161  const MBIndex& index,
162  const MBLevelMap<MAP,MEM>& map);
163  void addShiftedOp(
164  const MBPointInterpOp& baseOp,
165  Point shift);
166  void copyAlongSymmetryAxes(const MBPointInterpOp& pointOp);
167 
170  int m_order;
171  std::vector<std::shared_ptr<MBPointInterpOp>> m_ops;
172  std::unordered_set<MBPointID, MBPointID::Hash> m_points;
173  };
174 
175  // Interpolate Block Boundaries
176  template<typename MAP, typename T, unsigned int C, MemType MEM, Centering CTR>
177  inline void interpBoundaries(
178  MBLevelBoxData<T, C, MEM, CTR>& a_data, unsigned int a_order = 4);
179 
180  // Interpolate Block Boundaries
181  template<typename MAP, typename T, unsigned int C, MemType MEM, Centering CTR>
182  inline void interpBoundaries(
184  MBLevelMap<MAP, MEM>& a_map,
185  unsigned int a_order = 4);
186 
187 #include "implem/Proto_MBInterpOpImplem.H"
188 } //end namespace Proto
189 #endif // end include guard
static void Abort(const char *const a_msg=m_nullString)
Print out message to cerr and exit via abort() (if serial) or MPI_Abort() (if parallel).
const int m_index
Definition: Proto_MBInterpOp.H:58
void copyAlongSymmetryAxes(const MBPointInterpOp &pointOp)
Definition: Proto_MBInterpOp.H:141
MBInterpLayout m_interpLayout
Definition: Proto_MBInterpOp.H:168
Definition: Proto_MBInterpLayout.H:11
int BlockIndex
Defines what type is used for indexing block entities.
Definition: Proto_MBGraph.H:9
Mapped Multiblock Block Boundary Interpolation Operator.
Definition: Proto_MBInterpOp.H:65
Single Level Mapped Multiblock Map.
Definition: Proto_MBLevelBoxData.H:19
void interpBoundaries(LevelBoxData< T, C, MEM, CTR > &a_crse, LevelBoxData< T, C, MEM, CTR > &a_fine, InterpStencil< T > &a_interp)
Interpolate Boundaries.
Definition: Proto_LevelBoxData.H:955
MBPointInterpOp & operator()(const MBDataPoint &a_target)
Coefficients.
Definition: Proto_MBInterpOp.H:136
Definition: Proto_MBInterpOp.H:39
MBPointID(Point a_pt, int a_index)
Definition: Proto_MBInterpOp.H:21
Multiblock Level Box Data.
Definition: Proto_MBLevelBoxData.H:17
std::vector< std::shared_ptr< MBPointInterpOp > > m_ops
Definition: Proto_MBInterpOp.H:171
Definition: Proto_MBInterpOp.H:17
Point point() const
Definition: Proto_MBInterpOp.H:36
const Point m_point
Definition: Proto_MBInterpOp.H:57
bool operator==(const MBPointID &a_rhs) const
Definition: Proto_MBInterpOp.H:31
MBPointID(const MBPointID &a_rhs)
Definition: Proto_MBInterpOp.H:23
void hash_combine(std::size_t &seed, int value) const
Definition: Proto_MBInterpOp.H:50
std::unordered_set< MBPointID, MBPointID::Hash > m_points
Definition: Proto_MBInterpOp.H:172
bool operator<(const MBPointID &a_rhs) const
Definition: Proto_MBInterpOp.H:24
BlockIndex index() const
Definition: Proto_MBInterpOp.H:37
Definition: Proto_Array.H:17
Integer Valued Vector.
Definition: Proto_Point.H:24
Mapped Multiblock Block Boundary Interpolation Operator.
Definition: Proto_MBPointInterpOp.H:12
int m_order
Definition: Proto_MBInterpOp.H:170
Point dir
Definition: Proto_MBBoxPartition.H:16
Point m_ghost
Definition: Proto_MBInterpOp.H:169
std::size_t operator()(const MBPointID &a_pt) const
Definition: Proto_MBInterpOp.H:40
Definition: Proto_MBDataPoint.H:10