From bbe1d29750a8019c24df76494bca572c600c0700 Mon Sep 17 00:00:00 2001 From: Mauco03 <marco.gaibotti@skywarder.eu> Date: Sun, 20 Apr 2025 21:40:45 +0200 Subject: [PATCH] [coeff-transport][utils] Added test to find best interpolation strategy --- utils/tests/griddedInterpolant/data.mat | 3 ++ .../griddedInterpolant/testPerformance.m | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 utils/tests/griddedInterpolant/data.mat create mode 100644 utils/tests/griddedInterpolant/testPerformance.m diff --git a/utils/tests/griddedInterpolant/data.mat b/utils/tests/griddedInterpolant/data.mat new file mode 100644 index 00000000..f66a8279 --- /dev/null +++ b/utils/tests/griddedInterpolant/data.mat @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f8bc82e162d2e571dd73f75a00e7870ad5b56c66bf422b0709a366e6ea49a0a +size 9120699 diff --git a/utils/tests/griddedInterpolant/testPerformance.m b/utils/tests/griddedInterpolant/testPerformance.m new file mode 100644 index 00000000..5cbba49e --- /dev/null +++ b/utils/tests/griddedInterpolant/testPerformance.m @@ -0,0 +1,36 @@ +load("data.mat"); + +% Case with empty airbrakes dimension + +coeffs = staticCoeffs(:, :, :, :, 1, :); airbakes = 0; % Emulate singleton condition +nodes = {alpha, mach, beta, altitude, airbakes}; +singletonDims = [cellfun(@(x) isscalar(x) || isempty(x), nodes), 0]; + +%% 'Dumb' strategy: duplicate array for singleton dimensions + +selctedDims = singletonDims + 1; % if dimension is not singleon, repeat once, twice otherwise +coeffsDumb = repmat(coeffs, selctedDims); + +airbakesDumb = [0, 1]; % Create fake abk nodes (coeffs will be duplicated) +nodesDumb = {alpha, mach, beta, altitude, airbakesDumb}; + +% This works well when extrapolation is best near +intDumb = griddedInterpolant(nodesDumb, coeffsDumb, "linear", "nearest"); + +%% Check strategy: index only valid inputs + +intCheck = griddedInterpolant(nodes(~singletonDims(1:end-1)), coeffs, "linear", "nearest"); + +tCheck = timeit(@() intrpCheck(intCheck, ~singletonDims(1:end-1), 0, 0.5, 0.3, 100, 0.4)); +tDumb = timeit(@() intrpDumb(intDumb, 0, 0.5, 0.3, 100, 0.4)); + +% Vince metodo stupido + +function value = intrpDumb(interpolant, alpha, mach, beta, altitude, airbakes) + value = interpolant(alpha, mach, beta, altitude, airbakes); +end + +function intrpCheck(interpolant, valid, alpha, mach, beta, altitude, airbakes) + inputs = {alpha, mach, beta, altitude, airbakes}; + value = squeeze(interpolant(inputs{valid})); +end -- GitLab