From ed99546b8a493cf5553686d712d890838d7d4877 Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Wed, 18 Dec 2024 15:00:57 +0000 Subject: [PATCH] ENH: tabulated6DoFMotion: add optional linear interpolation scheme --- .../tabulated6DoFMotion/tabulated6DoFMotion.C | 48 ++++++++++++++++--- .../tabulated6DoFMotion/tabulated6DoFMotion.H | 18 ++++++- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/meshTools/solidBodyMotionFunctions/tabulated6DoFMotion/tabulated6DoFMotion.C b/src/meshTools/solidBodyMotionFunctions/tabulated6DoFMotion/tabulated6DoFMotion.C index e9668c8044..5e880c5be1 100644 --- a/src/meshTools/solidBodyMotionFunctions/tabulated6DoFMotion/tabulated6DoFMotion.C +++ b/src/meshTools/solidBodyMotionFunctions/tabulated6DoFMotion/tabulated6DoFMotion.C @@ -31,6 +31,7 @@ License #include "Tuple2.H" #include "IFstream.H" #include "interpolateSplineXY.H" +#include "interpolateXY.H" #include "unitConversion.H" @@ -51,6 +52,17 @@ namespace solidBodyMotionFunctions } +const Foam::Enum +< + Foam::solidBodyMotionFunctions::tabulated6DoFMotion::interpolationType +> +Foam::solidBodyMotionFunctions::tabulated6DoFMotion::interpolationTypeNames +({ + { interpolationType::SPLINE, "spline" }, + { interpolationType::LINEAR, "linear" } +}); + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::solidBodyMotionFunctions::tabulated6DoFMotion::tabulated6DoFMotion @@ -90,12 +102,28 @@ Foam::solidBodyMotionFunctions::tabulated6DoFMotion::transformation() const << exit(FatalError); } - translationRotationVectors TRV = interpolateSplineXY - ( - t, - times_, - values_ - ); + translationRotationVectors TRV; + switch (interpolator_) + { + case interpolationType::SPLINE: + { + TRV = interpolateSplineXY(t, times_, values_); + break; + } + case interpolationType::LINEAR: + { + TRV = interpolateXY(t, times_, values_); + break; + } + default: + { + FatalErrorInFunction + << "Unrecognised 'interpolationScheme' option: " + << interpolationTypeNames[interpolator_] + << exit(FatalError); + break; + } + } // Convert the rotational motion from deg to rad TRV[1] *= degToRad(); @@ -155,6 +183,14 @@ bool Foam::solidBodyMotionFunctions::tabulated6DoFMotion::read SBMFCoeffs_.readEntry("CofG", CofG_); + interpolator_ = + interpolationTypeNames.getOrDefault + ( + "interpolationScheme", + SBMFCoeffs_, + interpolationType::SPLINE + ); + return true; } diff --git a/src/meshTools/solidBodyMotionFunctions/tabulated6DoFMotion/tabulated6DoFMotion.H b/src/meshTools/solidBodyMotionFunctions/tabulated6DoFMotion/tabulated6DoFMotion.H index cd583521a1..50fbe81de0 100644 --- a/src/meshTools/solidBodyMotionFunctions/tabulated6DoFMotion/tabulated6DoFMotion.H +++ b/src/meshTools/solidBodyMotionFunctions/tabulated6DoFMotion/tabulated6DoFMotion.H @@ -61,7 +61,23 @@ class tabulated6DoFMotion : public solidBodyMotionFunction { - // Private data + // Private Enumerations + + //- Options for the interpolation algorithm + enum class interpolationType : char + { + SPLINE = 0, //!< "Spline interpolation method" + LINEAR //!< "Linear interpolation method" + }; + + //- Names for interpolationType + static const Enum interpolationTypeNames; + + + // Private Data + + //- Interpolation algorithm + interpolationType interpolator_; //- Time data file name read from dictionary fileName timeDataFileName_;