https://mooseframework.inl.gov
Loading...
Searching...
No Matches
BicubicInterpolation.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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
12#include "MooseTypes.h"
14
30{
31public:
32 BicubicInterpolation(const std::vector<Real> & x1,
33 const std::vector<Real> & x2,
34 const std::vector<std::vector<Real>> & y);
35
36 virtual ~BicubicInterpolation() = default;
37
41 void errorCheck();
42
46 Real sample(const Real x1, const Real x2) const override;
47 ADReal sample(const ADReal & x1, const ADReal & x2) const override;
48 ChainedReal sample(const ChainedReal & x1, const ChainedReal & x2) const override;
49
57 virtual void
58 sampleValueAndDerivatives(Real x1, Real x2, Real & y, Real & dy1, Real & dy2) const override;
59 virtual void sampleValueAndDerivatives(
60 const ADReal & x1, const ADReal & x2, ADReal & y, ADReal & dy1, ADReal & dy2) const override;
61 virtual void sampleValueAndDerivatives(const ChainedReal & x1,
62 const ChainedReal & x2,
63 ChainedReal & y,
64 ChainedReal & dy1,
65 ChainedReal & dy2) const override;
66
71 Real sampleDerivative(Real x1, Real x2, unsigned int deriv_var) const override;
72
76 Real sample2ndDerivative(Real x1, Real x2, unsigned int deriv_var) const override;
77
83
84protected:
88 template <typename T>
89 void findInterval(const std::vector<Real> & x,
90 const T & xi,
91 unsigned int & klo,
92 unsigned int & khi,
93 T & xs) const;
94
95 template <typename T>
96 T sampleInternal(const T & x1, const T & x2) const;
97
98 template <typename T>
99 void sampleValueAndDerivativesInternal(T x1, T x2, T & y, T & dy1, T & dy2) const;
100
107 void tableDerivatives(std::vector<std::vector<Real>> & dy_dx1,
108 std::vector<std::vector<Real>> & dy_dx2,
109 std::vector<std::vector<Real>> & d2y_dx1x2);
110
112 std::vector<std::vector<Real>> _y;
113
116 std::vector<std::vector<std::vector<std::vector<Real>>>> _bicubic_coeffs;
117
120 const std::vector<std::vector<int>> _wt{
121 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
122 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
123 {-3, 0, 0, 3, 0, 0, 0, 0, -2, 0, 0, -1, 0, 0, 0, 0},
124 {2, 0, 0, -2, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0},
125 {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
126 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
127 {0, 0, 0, 0, -3, 0, 0, 3, 0, 0, 0, 0, -2, 0, 0, -1},
128 {0, 0, 0, 0, 2, 0, 0, -2, 0, 0, 0, 0, 1, 0, 0, 1},
129 {-3, 3, 0, 0, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
130 {0, 0, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, -2, -1, 0, 0},
131 {9, -9, 9, -9, 6, 3, -3, -6, 6, -6, -3, 3, 4, 2, 1, 2},
132 {-6, 6, -6, 6, -4, -2, 2, 4, -3, 3, 3, -3, -2, -1, -1, -2},
133 {2, -2, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
134 {0, 0, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, 1, 1, 0, 0},
135 {-6, 6, -6, 6, -3, -3, 3, 3, -4, 4, 2, -2, -2, -2, -1, -1},
136 {4, -4, 4, -4, 2, 2, -2, -2, 2, -2, -2, 2, 1, 1, 1, 1}};
137};
DualNumber< Real, DNDerivativeType, true > ADReal
DualNumber< Real, Real > ChainedReal
Definition ChainedReal.h:30
Point xi
Definition MortarUtils.C:59
This class interpolates tabulated data with a bicubic function.
std::vector< std::vector< std::vector< std::vector< Real > > > > _bicubic_coeffs
Matrix of precomputed coefficients There are four coefficients in each direction at each dependent va...
void tableDerivatives(std::vector< std::vector< Real > > &dy_dx1, std::vector< std::vector< Real > > &dy_dx2, std::vector< std::vector< Real > > &d2y_dx1x2)
Provides the values of the first derivatives in each direction at all points in the table of data,...
Real sample(const Real x1, const Real x2) const override
Samples value at point (x1, x2)
Real sample2ndDerivative(Real x1, Real x2, unsigned int deriv_var) const override
Samples second derivative at point (x1, x2)
T sampleInternal(const T &x1, const T &x2) const
virtual ~BicubicInterpolation()=default
void findInterval(const std::vector< Real > &x, const T &xi, unsigned int &klo, unsigned int &khi, T &xs) const
Find the indices of the dependent values axis which bracket the point xi.
const std::vector< std::vector< int > > _wt
Matrix used to calculate bicubic interpolation coefficients (from Numerical Recipes)
std::vector< std::vector< Real > > _y
The dependent values at (x1, x2) points.
void sampleValueAndDerivativesInternal(T x1, T x2, T &y, T &dy1, T &dy2) const
Real sampleDerivative(Real x1, Real x2, unsigned int deriv_var) const override
Samples first derivative at point (x1, x2)
virtual void sampleValueAndDerivatives(Real x1, Real x2, Real &y, Real &dy1, Real &dy2) const override
Samples value and first derivatives at point (x1, x2) Use this function for speed when computing both...
void errorCheck()
Sanity checks on input data.
void precomputeCoefficients()
Precompute all of the coefficients for the bicubic interpolation to avoid calculating them repeatedly...
This class interpolates tabulated data with a Bidimension function (either bicubic or bilinear).
virtual Real sampleDerivative(const Real, const Real, unsigned int) const
Samples first derivative at point (x1, x2)
virtual void sampleValueAndDerivatives(Real, Real, Real &, Real &, Real &) const
Samples value and first derivatives at point (x1, x2) Use this function for speed when computing both...