20 const std::vector<Real> & y,
22 : _x(x), _y(y), _extrap(extrap)
30 if (
_x.size() !=
_y.size())
31 throw std::domain_error(
"Vectors are not the same length");
33 for (
unsigned int i = 0; i + 1 <
_x.size(); ++i)
34 if (
_x[i] >=
_x[i + 1])
36 std::ostringstream oss;
37 oss <<
"x-values are not strictly increasing: x[" << i <<
"]: " <<
_x[i] <<
" x[" << i + 1
38 <<
"]: " <<
_x[i + 1];
39 throw std::domain_error(oss.str());
49 mooseError(
"Trying to evaluate an empty LinearInterpolation");
59 return _y[0] + (x -
_x[0]) / (
_x[1] -
_x[0]) * (
_y[1] -
_y[0]);
62 (x -
_x.back()) / (
_x[
_x.size() - 2] -
_x.back()) * (
_y[
_y.size() - 2] -
_y.back());
72 auto upper = std::upper_bound(
_x.begin(),
_x.end(), x);
73 const auto i = cast_int<std::size_t>(std::distance(
_x.begin(), upper) - 1);
74 if (i == cast_int<std::size_t>(
_x.size() - 1))
80 return _y[i] + (
_y[i + 1] -
_y[i]) * (x -
_x[i]) / (
_x[i + 1] -
_x[i]);
83 template Real LinearInterpolation::sample<Real>(
const Real &)
const;
84 template ADReal LinearInterpolation::sample<ADReal>(
const ADReal &)
const;
95 return (
_y[1] -
_y[0]) / (
_x[1] -
_x[0]);
97 return (
_y[
_y.size() - 2] -
_y.back()) / (
_x[
_x.size() - 2] -
_x.back());
107 auto upper = std::upper_bound(
_x.begin(),
_x.end(), x);
108 const auto i = cast_int<std::size_t>(std::distance(
_x.begin(), upper) - 1);
109 if (i == cast_int<std::size_t>(
_x.size() - 1))
115 return (
_y[i + 1] -
_y[i]) / (
_x[i + 1] -
_x[i]);
118 template Real LinearInterpolation::sampleDerivative<Real>(
const Real &)
const;
119 template ADReal LinearInterpolation::sampleDerivative<ADReal>(
const ADReal &)
const;
126 for (
unsigned int i = 1; i <
_x.size(); ++i)
127 answer += 0.5 * (
_y[i] +
_y[i - 1]) * (
_x[i] -
_x[i - 1]);
132 template <
typename T>
138 const T *x1_ptr, *x2_ptr;
142 if (MooseUtils::absoluteFuzzyEqual(rawA, rawB))
144 else if (rawB > rawA)
150 switch_bounds =
false;
158 switch_bounds =
true;
160 const auto & x1 = *x1_ptr;
161 const auto & x2 = *x2_ptr;
166 const auto n =
_x.size();
167 const unsigned int i1 =
168 raw1 <=
_x[n - 1] ? std::distance(
_x.begin(), std::upper_bound(
_x.begin(),
_x.end(), raw1))
170 const unsigned int i2 =
171 raw2 <=
_x[n - 1] ? std::distance(
_x.begin(), std::upper_bound(
_x.begin(),
_x.end(), raw2))
179 T integral1, integral2;
182 const auto dydx = (
_y[1] -
_y[0]) / (
_x[1] -
_x[0]);
183 const auto y1 =
_y[0] + dydx * (x1 -
_x[0]);
184 integral1 = 0.5 * (y1 +
_y[0]) * (
_x[0] - x1);
187 const auto y2 =
_y[0] + dydx * (x2 -
_x[0]);
188 integral2 = 0.5 * (y2 +
_y[0]) * (
_x[0] - x2);
195 integral1 =
_y[0] * (
_x[0] - x1);
197 integral2 =
_y[0] * (
_x[0] - x2);
202 integral += integral1 - integral2;
207 T integral1, integral2;
210 const auto dydx = (
_y[n - 1] -
_y[n - 2]) / (
_x[n - 1] -
_x[n - 2]);
211 const auto y2 =
_y[n - 1] + dydx * (x2 -
_x[n - 1]);
212 integral2 = 0.5 * (y2 +
_y[n - 1]) * (x2 -
_x[n - 1]);
215 const auto y1 =
_y[n - 1] + dydx * (x1 -
_x[n - 1]);
216 integral1 = 0.5 * (y1 +
_y[n - 1]) * (x1 -
_x[n - 1]);
223 integral2 =
_y[n - 1] * (x2 -
_x[n - 1]);
225 integral1 =
_y[n - 1] * (x1 -
_x[n - 1]);
230 integral += integral2 - integral1;
237 const auto dydx = (
_y[i] -
_y[i - 1]) / (
_x[i] -
_x[i - 1]);
238 const auto y1 =
_y[i - 1] + dydx * (x1 -
_x[i - 1]);
239 integral1 = 0.5 * (y1 +
_y[i - 1]) * (x1 -
_x[i - 1]);
247 const auto dydx = (
_y[i] -
_y[i - 1]) / (
_x[i] -
_x[i - 1]);
248 const auto y2 =
_y[i - 1] + dydx * (x2 -
_x[i - 1]);
249 integral2 = 0.5 * (y2 +
_y[i - 1]) * (x2 -
_x[i - 1]);
252 integral2 = 0.5 * (
_y[i] +
_y[i - 1]) * (
_x[i] -
_x[i - 1]);
254 integral += integral2 - integral1;
262 return -1.0 * integral;
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
DualNumber< Real, Real > ChainedReal
Real integrate()
This function returns the integral of the function over the whole domain.
T sample(const T &x) const
This function will take an independent variable input and will return the dependent variable based on...
unsigned int getSampleSize() const
This function returns the size of the array holding the points, i.e.
DualNumber< Real, DNDerivativeType, true > ADReal
T integratePartial(const T &x1, const T &x2) const
Returns the integral of the function over a specified domain.
T sampleDerivative(const T &x) const
This function will take an independent variable input and will return the derivative of the dependent...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real