www.mooseframework.org
BicubicSplineInterpolation.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
13 
23 {
24 public:
31  BicubicSplineInterpolation(const std::vector<Real> & x1,
32  const std::vector<Real> & x2,
33  const std::vector<std::vector<Real>> & y,
34  const std::vector<Real> & yx11 = std::vector<Real>(),
35  const std::vector<Real> & yx1n = std::vector<Real>(),
36  const std::vector<Real> & yx21 = std::vector<Real>(),
37  const std::vector<Real> & yx2n = std::vector<Real>());
38 
39  virtual ~BicubicSplineInterpolation() = default;
40 
44  void setData(const std::vector<Real> & x1,
45  const std::vector<Real> & x2,
46  const std::vector<std::vector<Real>> & y,
47  const std::vector<Real> & yx11 = std::vector<Real>(),
48  const std::vector<Real> & yx1n = std::vector<Real>(),
49  const std::vector<Real> & yx21 = std::vector<Real>(),
50  const std::vector<Real> & yx2n = std::vector<Real>());
51 
55  void errorCheck();
56 
60  Real sample(Real x1, Real x2, Real yx11 = _deriv_bound, Real yx1n = _deriv_bound);
61 
68  Real x2,
69  Real & y,
70  Real & dy1,
71  Real & dy2,
72  Real yx11 = _deriv_bound,
73  Real yx1n = _deriv_bound,
74  Real yx21 = _deriv_bound,
75  Real yx2n = _deriv_bound);
76 
81  Real x1, Real x2, unsigned int deriv_var, Real yp1 = _deriv_bound, Real ypn = _deriv_bound);
82 
87  Real x1, Real x2, unsigned int deriv_var, Real yp1 = _deriv_bound, Real ypn = _deriv_bound);
88 
89 protected:
91  std::vector<Real> _x1;
93  std::vector<Real> _x2;
95  std::vector<std::vector<Real>> _y;
97  std::vector<std::vector<Real>> _y_trans;
98 
105  std::vector<Real> _yx11;
106  std::vector<Real> _yx1n;
107  std::vector<Real> _yx21;
108  std::vector<Real> _yx2n;
109 
111  std::vector<std::vector<Real>> _y2_rows;
112  std::vector<std::vector<Real>> _y2_columns;
113 
115  std::vector<Real> _row_spline_second_derivs;
116  std::vector<Real> _row_spline_eval;
117  std::vector<Real> _column_spline_second_derivs;
118  std::vector<Real> _column_spline_eval;
119 
126 
130  void solve();
131 
136  void constructRowSpline(Real x1,
137  std::vector<Real> & spline_eval,
138  std::vector<Real> & spline_second_derivs,
139  Real yx11 = _deriv_bound,
140  Real yx1n = _deriv_bound);
141 
146  void constructColumnSpline(Real x2,
147  std::vector<Real> & spline_eval,
148  std::vector<Real> & spline_second_derivs,
149  Real yx21 = _deriv_bound,
150  Real yx2n = _deriv_bound);
151 
153  static int _file_number;
154 };
Real sample(Real x1, Real x2, Real yx11=_deriv_bound, Real yx1n=_deriv_bound)
Samples value at point (x1, x2)
std::vector< Real > _x1
Independent values in the x1 direction.
virtual ~BicubicSplineInterpolation()=default
std::vector< std::vector< Real > > _y_trans
Transpose of _y.
void errorCheck()
Sanity checks on input data.
std::vector< std::vector< Real > > _y
The dependent values at (x1, x2) points.
Real sampleDerivative(Real x1, Real x2, unsigned int deriv_var, Real yp1=_deriv_bound, Real ypn=_deriv_bound)
Samples first derivative at point (x1, x2)
std::vector< Real > _x2
Independent values in the x2 direction.
std::vector< Real > _yx11
Boundary conditions.
std::vector< std::vector< Real > > _y2_rows
Second derivatives.
void constructColumnSpline(Real x2, std::vector< Real > &spline_eval, std::vector< Real > &spline_second_derivs, Real yx21=_deriv_bound, Real yx2n=_deriv_bound)
Helper functions to evaluate row splines and construct column spline for the given point...
void constructRowSplineSecondDerivativeTable()
Precompute tables of row (column) spline second derivatives and store them to reduce computational de...
This class interpolates tabulated functions with a bi-cubic spline.
void solve()
Calculates the tables of second derivatives.
std::vector< Real > _row_spline_second_derivs
Vectors used during sampling.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static int _file_number
File number for data dump.
void constructRowSpline(Real x1, std::vector< Real > &spline_eval, std::vector< Real > &spline_second_derivs, Real yx11=_deriv_bound, Real yx1n=_deriv_bound)
Helper functions to evaluate column splines and construct row spline for the given point...
Real sample2ndDerivative(Real x1, Real x2, unsigned int deriv_var, Real yp1=_deriv_bound, Real ypn=_deriv_bound)
Samples second derivative at point (x1, x2)
void sampleValueAndDerivatives(Real x1, Real x2, Real &y, Real &dy1, Real &dy2, Real yx11=_deriv_bound, Real yx1n=_deriv_bound, Real yx21=_deriv_bound, Real yx2n=_deriv_bound)
Samples value and first derivatives at point (x1, x2) Use this function for speed when computing both...
std::vector< std::vector< Real > > _y2_columns
std::vector< Real > _column_spline_second_derivs
void setData(const std::vector< Real > &x1, const std::vector< Real > &x2, const std::vector< std::vector< Real >> &y, const std::vector< Real > &yx11=std::vector< Real >(), const std::vector< Real > &yx1n=std::vector< Real >(), const std::vector< Real > &yx21=std::vector< Real >(), const std::vector< Real > &yx2n=std::vector< Real >())
Set the x1, x2 and y values, and first derivatives at the edges.