Line data Source code
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 : #include "SplineInterpolation.h"
11 :
12 : // MOOSE includes
13 : #include "MooseError.h"
14 :
15 : // C++ includes
16 : #include <fstream>
17 :
18 : int SplineInterpolation::_file_number = 0;
19 :
20 0 : SplineInterpolation::SplineInterpolation() {}
21 :
22 286 : SplineInterpolation::SplineInterpolation(const std::vector<Real> & x,
23 : const std::vector<Real> & y,
24 : Real yp1 /* = _deriv_bound*/,
25 286 : Real ypn /* = _deriv_bound*/)
26 286 : : SplineInterpolationBase(), _x(x), _y(y), _yp1(yp1), _ypn(ypn)
27 : {
28 286 : errorCheck();
29 286 : solve();
30 286 : }
31 :
32 : void
33 0 : 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 0 : _x = x;
39 0 : _y = y;
40 0 : _yp1 = yp1;
41 0 : _ypn = ypn;
42 0 : errorCheck();
43 0 : solve();
44 0 : }
45 :
46 : void
47 286 : SplineInterpolation::errorCheck()
48 : {
49 286 : if (_x.size() != _y.size())
50 0 : mooseError("SplineInterpolation: vectors are not the same length");
51 :
52 286 : bool error = false;
53 2139 : for (unsigned i = 0; !error && i + 1 < _x.size(); ++i)
54 1853 : if (_x[i] >= _x[i + 1])
55 0 : error = true;
56 :
57 286 : if (error)
58 0 : mooseError("x-values are not strictly increasing");
59 286 : }
60 :
61 : void
62 286 : SplineInterpolation::solve()
63 : {
64 286 : spline(_x, _y, _y2, _yp1, _ypn);
65 286 : }
66 :
67 : Real
68 3160 : SplineInterpolation::sample(Real x) const
69 : {
70 3160 : return SplineInterpolationBase::sample(_x, _y, _y2, x);
71 : }
72 :
73 : ADReal
74 0 : SplineInterpolation::sample(const ADReal & x) const
75 : {
76 0 : return SplineInterpolationBase::sample(_x, _y, _y2, x);
77 : }
78 :
79 : Real
80 1680 : SplineInterpolation::sampleDerivative(Real x) const
81 : {
82 1680 : return SplineInterpolationBase::sampleDerivative(_x, _y, _y2, x);
83 : }
84 :
85 : Real
86 1024 : SplineInterpolation::sample2ndDerivative(Real x) const
87 : {
88 1024 : return SplineInterpolationBase::sample2ndDerivative(_x, _y, _y2, x);
89 : }
90 :
91 : Real
92 0 : SplineInterpolation::domain(int i) const
93 : {
94 0 : return _x[i];
95 : }
96 :
97 : Real
98 0 : SplineInterpolation::range(int i) const
99 : {
100 0 : return _y[i];
101 : }
102 :
103 : unsigned int
104 0 : SplineInterpolation::getSampleSize()
105 : {
106 0 : return _x.size();
107 : }
|