1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "interpolateSplineXY.H"
27 #include "primitiveFields.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 Foam::Field<Type> Foam::interpolateSplineXY
34 const scalarField& xNew,
35 const scalarField& xOld,
36 const Field<Type>& yOld
39 Field<Type> yNew(xNew.size());
43 yNew[i] = interpolateSmoothXY(xNew[i], xOld, yOld);
51 Type Foam::interpolateSplineXY
54 const scalarField& xOld,
55 const Field<Type>& yOld
58 label n = xOld.size();
60 // early exit if out of bounds or only one value
61 if (n == 1 || x < xOld[0])
70 // linear interpolation if only two values
73 return (x - xOld[0])/(xOld[1] - xOld[0])*(yOld[1] - yOld[0]) + yOld[0];
76 // find bounding knots
78 while (hi < n && xOld[hi] < x)
85 const Type& y1 = yOld[lo];
86 const Type& y2 = yOld[hi];
109 scalar mu = (x - xOld[lo])/(xOld[hi] - xOld[lo]);
119 + mu*((2*y0 - 5*y1 + 4*y2 - y3) + mu*(-y0 + 3*y1 - 3*y2 + y3))
125 // ************************************************************************* //