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]);
145 switch_bounds =
false;
151 switch_bounds =
true;
158 const unsigned int i1 =
159 x1 <=
_x[n - 1] ? std::distance(
_x.begin(), std::upper_bound(
_x.begin(),
_x.end(), x1)) : n;
160 const unsigned int i2 =
161 x2 <=
_x[n - 1] ? std::distance(
_x.begin(), std::upper_bound(
_x.begin(),
_x.end(), x2)) : n;
168 Real integral1, integral2;
172 const Real y1 =
_y[0] + dydx * (x1 -
_x[0]);
173 integral1 = 0.5 * (y1 +
_y[0]) * (
_x[0] - x1);
176 const Real y2 =
_y[0] + dydx * (x2 -
_x[0]);
177 integral2 = 0.5 * (y2 +
_y[0]) * (
_x[0] - x2);
184 integral1 =
_y[0] * (
_x[0] - x1);
186 integral2 =
_y[0] * (
_x[0] - x2);
191 integral += integral1 - integral2;
196 Real integral1, integral2;
199 const Real dydx = (
_y[n - 1] -
_y[n - 2]) / (
_x[n - 1] -
_x[n - 2]);
200 const Real y2 =
_y[n - 1] + dydx * (x2 -
_x[n - 1]);
201 integral2 = 0.5 * (y2 +
_y[n - 1]) * (x2 -
_x[n - 1]);
204 const Real y1 =
_y[n - 1] + dydx * (x1 -
_x[n - 1]);
205 integral1 = 0.5 * (y1 +
_y[n - 1]) * (x1 -
_x[n - 1]);
212 integral2 =
_y[n - 1] * (x2 -
_x[n - 1]);
214 integral1 =
_y[n - 1] * (x1 -
_x[n - 1]);
219 integral += integral2 - integral1;
226 const Real dydx = (
_y[i] -
_y[i - 1]) / (
_x[i] -
_x[i - 1]);
227 const Real y1 =
_y[i - 1] + dydx * (x1 -
_x[i - 1]);
228 integral1 = 0.5 * (y1 +
_y[i - 1]) * (x1 -
_x[i - 1]);
236 const Real dydx = (
_y[i] -
_y[i - 1]) / (
_x[i] -
_x[i - 1]);
237 const Real y2 =
_y[i - 1] + dydx * (x2 -
_x[i - 1]);
238 integral2 = 0.5 * (y2 +
_y[i - 1]) * (x2 -
_x[i - 1]);
241 integral2 = 0.5 * (
_y[i] +
_y[i - 1]) * (
_x[i] -
_x[i - 1]);
243 integral += integral2 - integral1;
251 return -1.0 * integral;
Real integratePartial(Real x1, Real x2) const
Returns the integral of the function over a specified domain.
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
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 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