-
Notifications
You must be signed in to change notification settings - Fork 1k
/
SplineInterpolation.C
101 lines (84 loc) · 2.17 KB
/
SplineInterpolation.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
#include "SplineInterpolation.h"
// MOOSE includes
#include "MooseError.h"
// C++ includes
#include <fstream>
int SplineInterpolation::_file_number = 0;
SplineInterpolation::SplineInterpolation() {}
SplineInterpolation::SplineInterpolation(const std::vector<Real> & x,
const std::vector<Real> & y,
Real yp1 /* = _deriv_bound*/,
Real ypn /* = _deriv_bound*/)
: SplineInterpolationBase(), _x(x), _y(y), _yp1(yp1), _ypn(ypn)
{
errorCheck();
solve();
}
void
SplineInterpolation::setData(const std::vector<Real> & x,
const std::vector<Real> & y,
Real yp1 /* = _deriv_bound*/,
Real ypn /* = _deriv_bound*/)
{
_x = x;
_y = y;
_yp1 = yp1;
_ypn = ypn;
errorCheck();
solve();
}
void
SplineInterpolation::errorCheck()
{
if (_x.size() != _y.size())
mooseError("SplineInterpolation: vectors are not the same length");
bool error = false;
for (unsigned i = 0; !error && i + 1 < _x.size(); ++i)
if (_x[i] >= _x[i + 1])
error = true;
if (error)
mooseError("x-values are not strictly increasing");
}
void
SplineInterpolation::solve()
{
spline(_x, _y, _y2, _yp1, _ypn);
}
Real
SplineInterpolation::sample(Real x) const
{
return SplineInterpolationBase::sample(_x, _y, _y2, x);
}
Real
SplineInterpolation::sampleDerivative(Real x) const
{
return SplineInterpolationBase::sampleDerivative(_x, _y, _y2, x);
}
Real
SplineInterpolation::sample2ndDerivative(Real x) const
{
return SplineInterpolationBase::sample2ndDerivative(_x, _y, _y2, x);
}
Real
SplineInterpolation::domain(int i) const
{
return _x[i];
}
Real
SplineInterpolation::range(int i) const
{
return _y[i];
}
unsigned int
SplineInterpolation::getSampleSize()
{
return _x.size();
}