mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: added interpolateSplineXY templated function, and updated tabulated6DoFMotion
This commit is contained in:
@ -0,0 +1,126 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "interpolateSplineXY.H"
|
||||
#include "primitiveFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::Field<Type> Foam::interpolateSplineXY
|
||||
(
|
||||
const scalarField& xNew,
|
||||
const scalarField& xOld,
|
||||
const Field<Type>& yOld
|
||||
)
|
||||
{
|
||||
Field<Type> yNew(xNew.size());
|
||||
|
||||
forAll(xNew, i)
|
||||
{
|
||||
yNew[i] = interpolateSmoothXY(xNew[i], xOld, yOld);
|
||||
}
|
||||
|
||||
return yNew;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::interpolateSplineXY
|
||||
(
|
||||
const scalar x,
|
||||
const scalarField& xOld,
|
||||
const Field<Type>& yOld
|
||||
)
|
||||
{
|
||||
label n = xOld.size();
|
||||
|
||||
// early exit if out of bounds or only one value
|
||||
if (n == 1 || x < xOld[0])
|
||||
{
|
||||
return yOld[0];
|
||||
}
|
||||
if (x > xOld[n - 1])
|
||||
{
|
||||
return yOld[n - 1];
|
||||
}
|
||||
|
||||
// linear interpolation if only two values
|
||||
if (n == 2)
|
||||
{
|
||||
return (x - xOld[0])/(xOld[1] - xOld[0])*(yOld[1] - yOld[0]) + yOld[0];
|
||||
}
|
||||
|
||||
// find bounding knots
|
||||
label hi = 0;
|
||||
while (hi < n && xOld[hi] < x)
|
||||
{
|
||||
hi++;
|
||||
}
|
||||
|
||||
label lo = hi - 1;
|
||||
|
||||
const Type& y1 = yOld[lo];
|
||||
const Type& y2 = yOld[hi];
|
||||
|
||||
Type y0;
|
||||
if (lo == 0)
|
||||
{
|
||||
y0 = 2*y1 - y2;
|
||||
}
|
||||
else
|
||||
{
|
||||
y0 = yOld[lo - 1];
|
||||
}
|
||||
|
||||
Type y3;
|
||||
if (hi + 1 == n)
|
||||
{
|
||||
y3 = 2*y2 - y1;
|
||||
}
|
||||
else
|
||||
{
|
||||
y3 = yOld[hi + 1];
|
||||
}
|
||||
|
||||
// weighting
|
||||
scalar mu = (x - xOld[lo])/(xOld[hi] - xOld[lo]);
|
||||
|
||||
// interpolate
|
||||
return
|
||||
0.5
|
||||
*(
|
||||
2*y1
|
||||
+ mu
|
||||
*(
|
||||
-y0 + y2
|
||||
+ mu*((2*y0 - 5*y1 + 4*y2 - y3) + mu*(-y0 + 3*y1 - 3*y2 + y3))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,84 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
InNamespace
|
||||
Foam
|
||||
|
||||
Description
|
||||
Interpolates y values from one curve to another with a different x
|
||||
distribution.
|
||||
|
||||
Uses Catmull-Rom spline interpolation between points.
|
||||
|
||||
SourceFiles
|
||||
interpolateSplineXY.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef interpolateSplineXY_H
|
||||
#define interpolateSplineXY_H
|
||||
|
||||
#include "scalar.H"
|
||||
#include "primitiveFieldsFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Field<Type> interpolateSplineXY
|
||||
(
|
||||
const scalarField& xNew,
|
||||
const scalarField& xOld,
|
||||
const Field<Type>& yOld
|
||||
);
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type interpolateSplineXY
|
||||
(
|
||||
const scalar x,
|
||||
const scalarField& xOld,
|
||||
const Field<Type>& yOld
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "interpolateSplineXY.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -27,7 +27,7 @@ License
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "Tuple2.H"
|
||||
#include "IFstream.H"
|
||||
#include "interpolateXY.H"
|
||||
#include "interpolateSplineXY.H"
|
||||
#include "mathematicalConstants.H"
|
||||
|
||||
using namespace Foam::constant::mathematical;
|
||||
@ -98,7 +98,7 @@ Foam::solidBodyMotionFunctions::tabulated6DoFMotion::transformation() const
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
translationRotationVectors TRV = interpolateXY
|
||||
translationRotationVectors TRV = interpolateSplineXY
|
||||
(
|
||||
t,
|
||||
times_,
|
||||
|
||||
Reference in New Issue
Block a user