www.mooseframework.org
SplineInterpolation.C
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 #include "SplineInterpolation.h"
11 
12 // MOOSE includes
13 #include "MooseError.h"
14 
15 // C++ includes
16 #include <fstream>
17 
19 
21 
22 SplineInterpolation::SplineInterpolation(const std::vector<Real> & x,
23  const std::vector<Real> & y,
24  Real yp1 /* = _deriv_bound*/,
25  Real ypn /* = _deriv_bound*/)
26  : SplineInterpolationBase(), _x(x), _y(y), _yp1(yp1), _ypn(ypn)
27 {
28  errorCheck();
29  solve();
30 }
31 
32 void
33 SplineInterpolation::setData(const std::vector<Real> & x,
34  const std::vector<Real> & y,
35  Real yp1 /* = _deriv_bound*/,
36  Real ypn /* = _deriv_bound*/)
37 {
38  _x = x;
39  _y = y;
40  _yp1 = yp1;
41  _ypn = ypn;
42  errorCheck();
43  solve();
44 }
45 
46 void
48 {
49  if (_x.size() != _y.size())
50  mooseError("SplineInterpolation: vectors are not the same length");
51 
52  bool error = false;
53  for (unsigned i = 0; !error && i + 1 < _x.size(); ++i)
54  if (_x[i] >= _x[i + 1])
55  error = true;
56 
57  if (error)
58  mooseError("x-values are not strictly increasing");
59 }
60 
61 void
63 {
64  spline(_x, _y, _y2, _yp1, _ypn);
65 }
66 
67 Real
69 {
71 }
72 
73 ADReal
75 {
77 }
78 
79 Real
81 {
83 }
84 
85 Real
87 {
89 }
90 
91 Real
93 {
94  return _x[i];
95 }
96 
97 Real
99 {
100  return _y[i];
101 }
102 
103 unsigned int
105 {
106  return _x.size();
107 }
Real sample(Real x) const
This function will take an independent variable input and will return the dependent variable based on...
Real _yp1
boundary conditions
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
Real sample2ndDerivative(const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const
Real sample(const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const
Real sampleDerivative(const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const
void setData(const std::vector< Real > &x, const std::vector< Real > &y, Real yp1=_deriv_bound, Real ypn=_deriv_bound)
Set the x-, y- values and first derivatives.
Real domain(int i) const
unsigned int getSampleSize()
This function returns the size of the array holding the points, i.e.
std::vector< Real > _y2
Second derivatives.
DualReal ADReal
Definition: ADRealForward.h:14
std::vector< Real > _x
std::vector< Real > _y
Real sample2ndDerivative(Real x) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real sampleDerivative(Real x) const
Real range(int i) const
void spline(const std::vector< Real > &x, const std::vector< Real > &y, std::vector< Real > &y2, Real yp1=_deriv_bound, Real ypn=_deriv_bound)
This function calculates the second derivatives based on supplied x and y-vectors.