diff --git a/apogeeAnalysis/src/engineCutApogee.m b/apogeeAnalysis/src/engineCutApogee.m index 41c240004abe5b91026f7174ba775a0d3966f9ed..9b5ba9015cf331e39675c8e0cdac12fda9109de4 100644 --- a/apogeeAnalysis/src/engineCutApogee.m +++ b/apogeeAnalysis/src/engineCutApogee.m @@ -63,8 +63,6 @@ for i = 1:2 % highest and lowest apogee cases for l = 1:nCutOffTime rocket.motor.cutoffTime = timeEngineCutVect(l); - rocket.coefficients.state.xcgTime = linspace(0, rocket.motor.cutoffTime, ... - length(rocket.coefficients.state.xcgTime)); % Apogee apogee(l,k,i) = quickApogeeOnly(rocket, environment, wind, settings, wrapper); end diff --git a/apogeeAnalysis/src/standardApogee.m b/apogeeAnalysis/src/standardApogee.m index efd81950458311a7127d7267796682437cd3cf34..6fab302db49f3285ef0f8995fcb3f53b6348f365 100644 --- a/apogeeAnalysis/src/standardApogee.m +++ b/apogeeAnalysis/src/standardApogee.m @@ -50,8 +50,6 @@ for i = 1:2 % highest and lowest apogee cases tempMotor.name = selectedMotors(k).MotorName; rocket.mass = []; % Disables any ovverrides rocket.motor = tempMotor; - rocket.coefficients.state.xcgTime = linspace(0, tempMotor.cutoffTime, ... - length(rocket.coefficients.state.xcgTime)); rocket.motor.thrust = rocket.motor.thrust * ... (1 + settings.cases(i).thrustUncertSign * settings.uncert.sigma * ... settings.uncert.totalImpulse / selectedMotors(k).Itot); diff --git a/autoMatricesProtub/autoMatProtubConfig.m b/autoMatricesProtub/autoMatProtubConfig.m index 3dc509dc8daa5bcd3cf1cc20702d3a8d776edd0d..84797c278c5cec39ac673f6c494c6bbac6bf6c9b 100644 --- a/autoMatricesProtub/autoMatProtubConfig.m +++ b/autoMatricesProtub/autoMatProtubConfig.m @@ -22,11 +22,15 @@ set(groot,'defaultAxesTickLabelInterpreter','latex'); set(groot,'defaulttextinterpreter','latex'); set(groot,'defaultLegendInterpreter','latex'); +flags.saveVars = true; +flags.computeHighAOA = false; + %% STATES % State values in which the aerodynamic coefficients will be computed vars.mach = 0.05:0.05:1; -vars.alpha = [-22 -15 -10 -7.5 -5 -2.5 -1 -0.5 -0.1 0 0.1 0.5 1 2.5 5 7.5 10 15 22]; -vars.beta = [-13 -8 -5 -2.5 -0.1 0 0.1 2.5 5 8 13]; +vars.alpha = [0 0.1 0.5 1 2.5 5 7.5 10 15 22 35 60 90.1 115 130 170]; +vars.beta = []; +vars.phi = [0:12:120]; vars.alt = (0:400:4000); % above local ground (env.z0 will be added in main) % xcg discretization @@ -36,6 +40,7 @@ vars.Nxcg = 3; % Number of wanted xcgs in order to generate N varsHighAOA.mach = 0.05:0.05:0.7; varsHighAOA.alpha = [-170 -130 -115 -90.1 -60 -35 -10 -5 -1 0 1 5 10 35 60 90.1 115 130 170]; varsHighAOA.beta = [-170 -130 -115 -90.1 -60 -35 -10 -5 -1 0 1 5 10 35 60 90.1 115 130 170]; +varsHighAOA.phi = []; varsHighAOA.alt = (0:400:4000); % above local ground (env.z0 will be added in main) %% FINS CN partial output diff --git a/autoMatricesProtub/mainAutoMatProtub.m b/autoMatricesProtub/mainAutoMatProtub.m index 07e6db7ecabb3341c8768c08e0226fa1aec69001..e248f56e6cc5955ec450afe9bca883b1360bae7f 100644 --- a/autoMatricesProtub/mainAutoMatProtub.m +++ b/autoMatricesProtub/mainAutoMatProtub.m @@ -1,9 +1,10 @@ function [coeffsOut, coeffsOutHighAOA] = mainAutoMatProtub(rocket, environment, settings, options) arguments rocket = []; % Empty by default - environment Environment = Environment.empty - settings Settings = Settings.empty - options.saveVars logical = true + environment Environment = Environment.empty + settings Settings = Settings.empty + options.saveVars logical = [] + options.computeHighAOA = [] end %% PATH currentPath = fileparts(mfilename("fullpath")); @@ -19,6 +20,8 @@ if isempty(rocket), rocket = Rocket(mission, [], "loadCoefficients", false); end if isempty(environment), environment = Environment(mission, rocket.motor); end if isempty(settings), autoMatSettings = Settings('autoMatProtub'); end +Settings.read(autoMatSettings, options, 'flags'); + %% FINALIZE CONFIG (with data not directly editable) % correcting altitudes autoMatSettings.vars.alt = autoMatSettings.vars.alt + environment.z0; @@ -75,18 +78,7 @@ else end tic -%% COMPUTE HIGH AOA AERODYNAMIC COEFFICIENTS -fprintf('Generating new coefficients: High AoA...\n'); -autoMatSettings.varsHighAOA.xcg = rocket.xcg(end); -if length(autoMatSettings.varsHighAOA.alpha) > 20 || ... - length(autoMatSettings.varsHighAOA.mach) > 20 - error("automatrices with Dissile and alpha/mach" + ... - "> 20 cases is not yet compatible"); -end -inputHighAOA = createDissileInput(rocket, autoMatSettings.varsHighAOA); -[coeffsTotHighAOA, finsCNHighAOA] = dissileMatcom(inputHighAOA); - -%% COMPUTE AERODYNAMIC COEFFICIENTS +%% COMPUTE AND EXPORT AERODYNAMIC COEFFICIENTS fprintf('Generating new coefficients: Refined envelope...\n'); autoMatSettings.vars.xcg = chosenXcg; if length(autoMatSettings.vars.alpha) > 20 || ... @@ -97,14 +89,28 @@ end input = createDissileInput(rocket, autoMatSettings.vars); [coeffsTot, finsCN] = dissileMatcom(input); -%% SAVE DATA - coeffsOut = exportVars( ... - autoMatSettings.varsHighAOA, rocket, mission, coeffsTotHighAOA, finsCNHighAOA, chosenXcg, ... - autoMatSettings.saveFinsCN, options.saveVars, 'aeroCoefficientsHighAOA.mat'); -coeffsOutHighAOA = exportVars( ... autoMatSettings.vars, rocket, mission, coeffsTot, finsCN, chosenXcg, ... - autoMatSettings.saveFinsCN, options.saveVars, 'aeroCoefficients.mat'); + autoMatSettings.saveFinsCN, autoMatSettings.flags.saveVars, 'aeroCoefficients.mat'); + +%% COMPUTE AND EXPORT HIGH AOA AERODYNAMIC COEFFICIENTS +coeffsOutHighAOA = Coefficient(); +if autoMatSettings.flags.computeHighAOA + fprintf('Generating new coefficients: High AoA...\n'); + autoMatSettings.varsHighAOA.xcg = rocket.xcg(end); + if length(autoMatSettings.varsHighAOA.alpha) > 20 || ... + length(autoMatSettings.varsHighAOA.mach) > 20 + error("automatrices with Dissile and alpha/mach" + ... + "> 20 cases is not yet compatible"); + end + inputHighAOA = createDissileInput(rocket, autoMatSettings.varsHighAOA); + [coeffsTotHighAOA, finsCNHighAOA] = dissileMatcom(inputHighAOA); + + + coeffsOutHighAOA = exportVars( ... + autoMatSettings.varsHighAOA, rocket, mission, coeffsTotHighAOA, finsCNHighAOA, chosenXcg, ... + autoMatSettings.saveFinsCN, autoMatSettings.flags.saveVars, 'aeroCoefficientsHighAOA.mat'); +end AMtime = toc; fprintf('Aerodynamics Prediction completed \n') diff --git a/autoMatricesProtub/src/exportVars.m b/autoMatricesProtub/src/exportVars.m index 9a388e39af36eaa106709329b5b434d95291e60e..f0f87fd6014dbb8cbe7d14dce16837d754836d80 100644 --- a/autoMatricesProtub/src/exportVars.m +++ b/autoMatricesProtub/src/exportVars.m @@ -17,6 +17,7 @@ end state.alphas = vars.alpha; state.altitudes = vars.alt; state.betas = vars.beta; +state.phis = vars.phi; state.machs = vars.mach; state.hprot = vars.hprot; diff --git a/common b/common index bc61b5b9265bde0f30dfc53db0bf5820e3c69b04..01ad37374e485282e37e3e35917d233f22e6bc53 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit bc61b5b9265bde0f30dfc53db0bf5820e3c69b04 +Subproject commit 01ad37374e485282e37e3e35917d233f22e6bc53 diff --git a/utils/tests/alphaPhi/coeffs.mat b/utils/tests/alphaPhi/coeffs.mat new file mode 100644 index 0000000000000000000000000000000000000000..d7c6d523d2b281bb07c20bdb6c2651243ca2e99e --- /dev/null +++ b/utils/tests/alphaPhi/coeffs.mat @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e106d1b2e75105acddf1ef9290b13cb469c4332e25492b33f1e9ef75bf991aa +size 472473 diff --git a/utils/tests/alphaPhi/coeffsPhi.mat b/utils/tests/alphaPhi/coeffsPhi.mat new file mode 100644 index 0000000000000000000000000000000000000000..6bc5c935efe568e136096a205aa3a377de19690e --- /dev/null +++ b/utils/tests/alphaPhi/coeffsPhi.mat @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39d9a040d0569838c0d1f0e7a0b0683a527e6a7de4b1c6469f7c5a211e7fa7f3 +size 203464 diff --git a/utils/tests/alphaPhi/computeCoeffs.m b/utils/tests/alphaPhi/computeCoeffs.m new file mode 100644 index 0000000000000000000000000000000000000000..4ee579ec273dc6d338b546f66220ec005781071b --- /dev/null +++ b/utils/tests/alphaPhi/computeCoeffs.m @@ -0,0 +1,20 @@ +function [coeffsR, coeffs] = computeCoeffs(sections, alpha, mach, phi, abk, interpolant) +angle = 360 / sections; +n = floor(phi / angle); +deltaPhi = n*angle; +psi = phi - deltaPhi; + +coeffsR = zeros(6, 1); +coeffsR(:, 1) = interpolant(alpha, mach, psi, abk); % Get coeffs in limited range +coeffs(:, 1) = interpolant(alpha, mach, phi, abk); % Get coeffs in full range + +R = @(phi) [ + cos(phi), -sin(phi); + sin(phi), cos(phi)]; + +Rot = R(deltaPhi * pi/180); + +coeffsR([2, 3]) = Rot * coeffsR([2, 3]); +coeffsR([5, 6]) = Rot' * coeffsR([5, 6]); +end + diff --git a/utils/tests/alphaPhi/testAlphaPhi.m b/utils/tests/alphaPhi/testAlphaPhi.m new file mode 100644 index 0000000000000000000000000000000000000000..c9ffe138f748badc4aa09b03d42cab9a278dae54 --- /dev/null +++ b/utils/tests/alphaPhi/testAlphaPhi.m @@ -0,0 +1,54 @@ +% Workflow: +% - Converti alpha-beta in alphaTot-phi +% - Sia il razzo diviso in n settori: m = 360/n +% - Considera phi1 = phi % m +% - Interpola coefficientin in alphaTot-phi1 +% - Ruota in alphaTot-phi +% +% Cosa succede alle derivate dinamiche? + +%% aTot-phi -> a-b conversion to get sample points +% alpha = [-10 -5 -2.5 -1 -0.5 -0.1 0 0.1 0.5 1 2.5 5 10]; +% beta = [-10 -5 -2.5 -1 -0.5 -0.1 0 0.1 0.5 1 2.5 5 10]; + +% considero casi allineati con assi principali (non sono particolari, data la geometria): +% alphaTot = [0 0.1 0.5 1 2.5 5 10]; +% phi = [0, 90, 180, 270] + +%% Coefficients creation and validation +data = load("coeffs.mat"); +ab = data.coeffsAB; +ap = data.coeffsAP; + +alpha = ab.state.alphas; +beta = ab.state.betas; + +alphaT = ap.state.alphas; +phi = ap.state.phis; + +coeffIdx = [1 3 5 6 9 13]; + +% permute coefficients (to have mach after alpha phi) +coeffsAB = permute(ab.total(coeffIdx, :, :, :, :, :), ... + [1, 2, 4, 3, 5, 6]); % coeffs, alpha, phi, mach, abk +coeffsAP = permute(ap.total(coeffIdx, :, :, :, :, :), ... + [1, 2, 4, 3, 5, 6]); + +% Get sample points +sz = size(coeffsAP, [1, 2, 4, 5, 6]); +sz(2) = sz(2) * 4; % consider four cases (0, 90, 180, 270) +cAB = NaN(sz); +cAP = NaN(sz); + +cAB(:, 1:7, :, :) = squeeze(coeffsAB(:, 7:end, 7, :, 1, :)); % a > 0, b = 0 +cAB(:, 8:14, :, :) = squeeze(coeffsAB(:, 7, 7:end, :, 1, :)); % a = 0, b > 0 +cAB(:, 15:21, :, :) = squeeze(coeffsAB(:, 7:-1:1, 7, :, 1, :)); % a < 0, b = 0 +cAB(:, 22:28, :, :) = squeeze(coeffsAB(:, 7, 7:-1:1, :, 1, :)); % a = 0, b < 0 + +cAP(:, 1:7, :, :) = squeeze(coeffsAP(:, :, 1, :, 1, :)); % a > 0, b = 0 +cAP(:, 8:14, :, :) = squeeze(coeffsAP(:, :, 2, :, 1, :)); % a = 0, b > 0 +cAP(:, 15:21, :, :) = squeeze(coeffsAP(:, :, 3, :, 1, :)); % a < 0, b = 0 +cAP(:, 22:28, :, :) = squeeze(coeffsAP(:, :, 4, :, 1, :)); % a = 0, b < 0 + +error = cAB - cAP; +errMax = max(error, [], "all"); \ No newline at end of file diff --git a/utils/tests/alphaPhi/testRotation.m b/utils/tests/alphaPhi/testRotation.m new file mode 100644 index 0000000000000000000000000000000000000000..98597289a4d964ea1040907e5c0d85171e8508c5 --- /dev/null +++ b/utils/tests/alphaPhi/testRotation.m @@ -0,0 +1,69 @@ +%% rotating the frame +% alphaTot = [0 0.1 0.5 1 2.5 5 10 20]; +% phi = [0:30:360] + +clear; clc; close all + +% Consider a generic touple (alpha-tot, phi) +ap = load("coeffsPhi.mat").coeffsPhi; + +coeffIdx = [1 3 5 6 9 13]; + +coeffsAP = squeeze(permute(ap.total(coeffIdx, :, :, :, :, :), ... + [2, 3, 4, 5, 6, 1])); + +%% Interpolate coefficients on psi +alpha = ap.state.alphas; +mach = ap.state.machs; +phi = ap.state.phis; +abk = ap.state.hprot / ap.state.hprot(end); +interpolant = griddedInterpolant(... + {alpha, mach, phi, abk}, ... + coeffsAP, 'linear', 'nearest'); + +%% Validate in multiple cases coefficients by n*section + +% uncomment * if manually outputting err from Coefficient + +n = 100; + +mach = rand(n, 1); +abk = rand(n, 1); +sections = ap.geometry.nPanel; + +% Generic alpha-phi +alpha = rand(n, 1)*20; +phi = rand(n, 1)*360; +beta = rand(n, 1)*20 - 10; +err1 = nan(6, n); +altitude = rand(n, 1)*3000; + +for i = 1:n + [coeffsR, coeffs] = computeCoeffs(sections, alpha(i), mach(i), phi(i), abk(i), interpolant); + err1(:, i) = abs(coeffs - coeffsR); + + % uncomment if error calculation manually added internally + % [~, err1(:, i)] = ap.get(alpha(i)*pi/180, mach(i), beta(i)*pi/180, altitude(i), abk(i), 1.7); +end + +% Extrapolation (best near) +mach = 1.2; +alpha = 30; +phi = 247; +abk = 1.3; % This should actually never happen + +[coeffsR, coeffs] = computeCoeffs(sections, alpha, mach, phi, abk, interpolant); + +err2 = abs(coeffs - coeffsR); + +% Edge cases (phi = 120*n) +mach = 0.3; +alpha = 10; +phi = [0, 120, 240, 360]; +abk = 0.5; % This should actually never happen +err3 = nan(6, 4); + +for i = 1:4 + [coeffsR, coeffs] = computeCoeffs(sections, alpha, mach, phi(i), abk, interpolant); + err3(:, i) = abs(coeffs - coeffsR); +end \ No newline at end of file