Skip to content
Snippets Groups Projects
Commit 7381b22c authored by Lucrezia Roncelli's avatar Lucrezia Roncelli
Browse files

Aggiunto file coefficientToCsv

parent 344104d2
Branches
No related tags found
No related merge requests found
close; clear; clc;
%% Imposta il razzo e importa i coefficienti aerodinamici
r = Rocket(Mission(true));
coefficient = r.coefficients;
% Dati geometrici fissi
airbrakeI = 1; % [-]
xcgI = 1; % [m]
lRef = (coefficient.geometry.chord1 + coefficient.geometry.chord2) / 2; % Corda media [m]
P = [0 1 0;
0 0 -1;
-1 0 0];
% Preallocazione lunghezze
numAlphas = length(coefficient.state.alphas);
numMachs = length(coefficient.state.machs);
numBetas = length(coefficient.state.betas);
numAltitudes = length(coefficient.state.altitudes);
N = numAlphas * numMachs * numBetas * numAltitudes; % 45980
% Preallocazione tabelle per salvare i risultati: [alpha, beta, mach, Re, coefficiente]
dataCQ = zeros(N, 5);
dataCL = zeros(N, 5);
dataCD = zeros(N, 5);
dataCm = zeros(N, 5);
dataCn = zeros(N, 5);
dataCr = zeros(N, 5);
% Ciclo annidato su tutti gli stati aerodinamici
idx = 1;
tic;
for i = 1 : numAlphas
alpha = coefficient.state.alphas(i) * pi/180; % [rad]
M1 = [ 1 0 0;
0 cos(alpha) sin(alpha);
0 -sin(alpha) cos(alpha)];
for j = 1 : numMachs
mach = coefficient.state.machs(j); % [-]
for k = 1 : numBetas
beta = coefficient.state.betas(k) * pi/180; % [rad]
M2 = [cos(beta) 0 sin(beta);
0 1 0;
-sin(beta) 0 cos(beta)];
for h = 1 : numAltitudes
alt = coefficient.state.altitudes(h); % [m]
% Estrae i coefficienti aerodinamici in quella configurazione
coefficientForce = coefficient.static(1:3, i, j, k, h, airbrakeI, xcgI);
coefficientMoment = coefficient.static(4:6, i, j, k, h, airbrakeI, xcgI);
% Forze trasformate nel sistema corpo
L = ((M1*M2)\eye(3)) * P * coefficientForce;
L([2,3]) = - L([2,3]);
% Momenti trasformati nel sistema corpo
M = ((M1*M2)\eye(3))*P*coefficientMoment;
M([2,3]) = - M([2,3]);
% Coefficenti finali
cQ = L(1); % Side force coefficient
cL = L(2); % Lift coefficient
cD = L(3); % Drag coefficient
cm = M(1); % Pitching moment coefficient
cn = M(2); % Yawing moment coefficient
cr = M(3); % Rolling moment coefficient
% Calcolo Reynolds
[~, a, ~, ~, nu, ~] = atmosisa(alt);
Re = (mach * a * lRef) / nu;
% Salvataggio righe nei dataset
dataCQ(idx,:) = [alpha, beta, mach, Re, cQ];
dataCL(idx,:) = [alpha, beta, mach, Re, cL];
dataCD(idx,:) = [alpha, beta, mach, Re, cD];
dataCm(idx,:) = [alpha, beta, mach, Re, cm];
dataCn(idx,:) = [alpha, beta, mach, Re, cn];
dataCr(idx,:) = [alpha, beta, mach, Re, cr];
idx = idx + 1;
end
end
end
end
tempoCicloFor = toc;
% Esportazione su file CSV
filenames = {'cQ.csv', 'cL.csv', 'cD.csv', 'cm.csv', 'cn.csv', 'cr.csv'}; % ATTENZIONE cr andrà rinominata manualmente in cl affinchè sia accettata da RocketPy
datasets = {dataCQ, dataCL, dataCD, dataCm, dataCn, dataCr};
header = {'alpha', 'beta', 'mach', 'Reynolds', 'coefficient'};
for idx = 1:numel(filenames)
T = array2table(datasets{idx}, 'VariableNames', header);
writetable(T, filenames{idx});
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment