Proto  3.2
Proto_InterpStencil1D.H
Go to the documentation of this file.
1 #ifndef _PROTO_INTERP_STENCIL_1D_H_
2 #define _PROTO_INTERP_STENCIL_1D_H_
3 #include "Proto_Stencil.H"
4 
5 namespace Proto {
6 
7 /// Interpolation Stencil
8 /**
9  \ingroup stencil_operations
10  InterpStencil1D is a convenient abstraction which encapsulates the functionality of an operation in which
11  the destination refinement is non-trivial. This kind of operation can be done with normal Stencil objects,
12  however for a destination refinement of R, an array of R^DIM Stencils will be needed in general.
13 */
14 template <class T>
16 {
17 public:
18  /// Default Constructor
19  inline InterpStencil1D() {}
20  inline InterpStencil1D(unsigned int a_dir, unsigned int a_ratio) { }
21  inline void define(unsigned int a_dir, unsigned int a_ratio);
22 
23  inline const Stencil<T>& get(unsigned int a_shift) const;
24  inline void set(Stencil<T> a_S, unsigned int a_shift);
25 
26  /// Span
27  /** \ingroup stencil_operations
28  Computes the composite span of all Stencils in the InterpStencil1D
29  */
30  inline Box span() const;
31 
32  /// Ghost Size
33  /**
34  \ingroup stencil_operations
35  Conservatively computes the amount of ghost data needed to apply this InterpStencil1D.
36  May overestimate in the case of assymmetric InterpStencil1D footprints.
37  */
38  inline Point ghost() const;
39 
40  /// Lazy Apply
41  /**
42  \ingroup stencil_operations
43  Gathers inputs for the composite Stencil operation and stores them in an intermediate
44  LazyStencil to be consumed by a left hand side operator ("=", "|=", or "+=").
45  The syntax is identical to that used by Stencil.
46 
47  \param a_src Source data
48  \param a_scale (Optional) value to scale the output of *this by.
49  */
50  template<unsigned int C, MemType MEMTYPE, unsigned int D, unsigned int E>
51  inline LazyStencil<T,C,MEMTYPE,D,E> operator()(
52  const BoxData<T,C,MEMTYPE,D,E>& a_src,
53  T a_scale = 1) const;
54 
55  /// Lazy Apply
56  /**
57  \ingroup stencil_operations
58  Gathers inputs for the composite Stencil operation and stores them in an intermediate
59  LazyStencil to be consumed by a left hand side operator ("=", "|=", or "+=").
60  The syntax is identical to that used by Stencil.
61  Explicitly defining a Box input is not recommended unless absolutely necessary.
62 
63  \param a_src Source data
64  \param a_box Iteration box
65  \param a_scale (Optional) value to scale the output of *this by.
66  */
67  template<unsigned int C, MemType MEMTYPE, unsigned int D, unsigned int E>
68  inline LazyStencil<T,C,MEMTYPE,D,E> operator()(
70  Box a_box,
71  T a_scale = 1) const;
72 
73  /// Return Destination Refinement Ratio
74  /**
75  \ingroup stencil_operations
76  */
77  inline unsigned int ratio() const {return m_r;}
78  /// Iterate Over Stencil Components
79  /**
80  \ingroup stencil_operations
81  */
82  inline typename std::vector<Stencil<T>>::iterator begin(){return m_s.begin();}
83  /// Iterate Over Stencil Components
84  /**
85  \ingroup stencil_operations
86  */
87  inline typename std::vector<Stencil<T>>::iterator end(){return m_s.end();}
88 
89  inline void print() const;
90 
91 #ifdef PR_LAPACK
92 //=======================================================================================
93 // InterpStencil1D Library ||
94 //=======================++
95  #if 0
96  /// Piecewise Constant Interpolation
97  /**
98  \ingroup stencil_library
99  \param a_ratio Anisotropic destination refinement
100  */
101  static inline InterpStencil1D<T> PiecewiseConstant(Point a_ratio);
102  /// Piecewise Linear Interpolation
103  /**
104  \ingroup stencil_library
105  \param a_ratio Anisotropic destination refinement
106  */
107  static inline InterpStencil1D<T> PiecewiseLinear(Point a_ratio);
108  /// Piecewise Linear Interpolation
109  /**
110  Computed based on tensor products of 1 dimensional interpolations.
111  \ingroup stencil_library
112  \param a_ratio Isotropic destination refinement
113  */
114  static inline InterpStencil1D<T> Quadratic(int a_ratio);
115 
116  /// Build High-Order Interpolation Stencil (Simple)
117  /**
118  Builds a symmetric, <code>a_order</code> order accurate interpolation operator
119  with an isotropic refinement ratio.
120 
121  \param a_order Order of accuracy
122  \param a_refRatio Isotropic refinement ratio
123  */
124  static inline InterpStencil1D<T> Build(int a_order, int a_refRatio);
125 
126  /// Build High-Order Interpolation Stencil (Simple, Anisotropic)
127  /**
128  Builds a symmetric, <code>a_order</code> order accurate interpolation operator
129  with an isotropic refinement ratio.
130 
131  \param a_order Order of accuracy
132  \param a_refRatio Isotropic refinement ratio
133  */
134  static inline InterpStencil1D<T> Build(int a_order, Point a_refRatio);
135 
136  /// Build General High-Order Interpolation Stencil (General)
137  /**
138  Builds an InterpStencil1D with a custom footprint using a Least-Squares solve.
139 
140  \ingroup stencil_library
141  \param a_shiftMax Maximum Manhattan distance from the Stencil center
142  \param a_shiftKernel Maximum span of the InterpStencil1D
143  \param a_order Order of polynomial fit (e.g. 2 for quadratic)
144  \param a_refRatio Desired ratio of interpolation. Must be a power of 2
145  */
146  static inline InterpStencil1D<T> Build(
147  int a_shiftMax,
148  Box a_shiftKernel,
149  int a_order,
150  int a_refRatio);
151 
152  /// Build General High-Order Interpolation Stencil (General, Anisotropic)
153  /**
154  Builds an InterpStencil1D with a custom footprint using a Least-Squares solve.
155 
156  \ingroup stencil_library
157  \param a_shiftMax Maximum Manhattan distance from the Stencil center
158  \param a_shiftKernel Maximum span of the InterpStencil1D
159  \param a_order Order of polynomial fit (e.g. 2 for quadratic)
160  \param a_refRatio Desired ratio of interpolation. Must be a power of 2
161  */
162  static inline InterpStencil1D<T> Build(
163  int a_shiftMax,
164  Box a_shiftKernel,
165  int a_order,
166  Point a_refRatio);
167 
168  /// Build General High-Order Interpolation Stencil
169  /**
170  Builds an InterpStencil1D with a custom footprint using a Least-Squares solve.
171 
172  \ingroup stencil_library
173  \param a_shifts Desired shifts of the stencil.
174  \param a_maxOrder Highest desired order of Polynomial interpolant.
175  \param a_refRatio Desired ratio of interpolation. Must be a power of 2.
176  */
177  static inline InterpStencil1D<T> Build(
178  std::vector<Point>& a_shifts,
179  int a_maxOrder,
180  Point a_refRatio);
181 
182  /// Build General High-Order Interpolation Stencil
183  /**
184  Builds an InterpStencil1D with a custom footprint using a Least-Squares solve.
185  Orders are specified as Point such that (1,2,3) is equivalent to x*y^2*z^3.
186 
187  \ingroup stencil_library
188  \param a_shifts Desired shifts of the stencil.
189  \param a_orders Polynomial exponents in vector form.
190  \param a_refRatio Desired ratio of interpolation. Must be a power of 2
191  */
192  static inline InterpStencil1D<T> Build(
193  std::vector<Point>& a_shifts,
194  const std::vector<Point>& a_orders,
195  Point a_refRatio);
196 #endif // end ifdef PR_LAPACK
197 #endif
198 private:
199  unsigned int m_r; ///< Destination refinement ratio
200  unsigned int m_dir; ///< Coordinate
201  std::vector<Stencil<T>> m_s; ///< Array of Stencils
202 };
203 
204 #include "implem/Proto_InterpStencil1DImplem.H"
205 } // end namespace Proto
206 #endif // End Include Guard
unsigned int ratio() const
Return Destination Refinement Ratio.
Definition: Proto_InterpStencil1D.H:77
Multidimensional Rectangular Array.
Definition: Proto_BoxData.H:314
A Linear Stencil Operation.
Definition: Proto_BoxData.H:76
std::vector< Stencil< T > > m_s
Array of Stencils.
Definition: Proto_InterpStencil1D.H:201
LazyStencil< T, C, MEMTYPE, D, E > operator()(const BoxData< T, C, MEMTYPE, D, E > &a_src, T a_scale=1) const
Lazy Apply.
Definition: Proto_InterpStencil1D.H:91
Point ghost() const
Ghost Size.
Definition: Proto_InterpStencil1D.H:49
An interval in DIM dimensional space.
Definition: Proto_Box.H:29
Box span() const
Span.
Definition: Proto_InterpStencil1D.H:37
void define(unsigned int a_dir, unsigned int a_ratio)
Definition: Proto_InterpStencil1D.H:3
InterpStencil1D()
Default Constructor.
Definition: Proto_InterpStencil1D.H:19
InterpStencil1D(unsigned int a_dir, unsigned int a_ratio)
Definition: Proto_InterpStencil1D.H:20
void print() const
Definition: Proto_InterpStencil1D.H:61
Definition: Proto_Array.H:17
Integer Valued Vector.
Definition: Proto_Point.H:24
unsigned int m_r
Destination refinement ratio.
Definition: Proto_InterpStencil1D.H:199
unsigned int m_dir
Coordinate.
Definition: Proto_InterpStencil1D.H:200
std::vector< Stencil< T > >::iterator begin()
Iterate Over Stencil Components.
Definition: Proto_InterpStencil1D.H:82
Interpolation Stencil.
Definition: Proto_InterpStencil1D.H:15
std::vector< Stencil< T > >::iterator end()
Iterate Over Stencil Components.
Definition: Proto_InterpStencil1D.H:87