From 38d1ad1f06aedf85e3f2b0abe5ad9857580107b8 Mon Sep 17 00:00:00 2001 From: Jason Ong Date: Wed, 3 May 2023 12:21:40 +0800 Subject: [PATCH] Added MAD_H300 and code edits for SingleStageRocet.m --- .gitignore | 1 + Code/DragInterpolations_MAD_H300.m | 40 +++++++++++++++ Code/ICANSAT/V0/ICANSAT.m | 2 +- Code/ICANSAT/V1/ICANSAT_V1.m | 2 +- Code/ICANSAT/V2/ICANSAT_V2.m | 2 +- Code/MAD/MAD_Validation.m | 2 +- Code/MAD_H300/MAD_H300.m | 12 +++++ Code/MAD_H300/MAD_H300_DragData.txt | 15 ++++++ Code/MAD_H300/MAD_H300_v1_VacT_v_Time.txt | 26 ++++++++++ Code/SingleStageRocket.m | 62 +++++++++++++++++++---- 10 files changed, 150 insertions(+), 14 deletions(-) create mode 100644 Code/DragInterpolations_MAD_H300.m create mode 100644 Code/MAD_H300/MAD_H300.m create mode 100644 Code/MAD_H300/MAD_H300_DragData.txt create mode 100644 Code/MAD_H300/MAD_H300_v1_VacT_v_Time.txt diff --git a/.gitignore b/.gitignore index a0f7549..ec14369 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ Code/ICANSAT/V0/Result Code/ICANSAT/V1/Result Code/ICANSAT/V2/Result Code/MAD/Result +Code/MAD_H300/Result diff --git a/Code/DragInterpolations_MAD_H300.m b/Code/DragInterpolations_MAD_H300.m new file mode 100644 index 0000000..58da210 --- /dev/null +++ b/Code/DragInterpolations_MAD_H300.m @@ -0,0 +1,40 @@ +function [coeffdrag] = DragInterpolations_MAD_H300(velocity, altitude, time, tb) + +drag_data = dlmread("MAD_H300/MAD_H300_DragData.txt", "\t",1,0); + +% Mach No +mach_no = drag_data(:,1); + +% Altitude 0m, full base drag +cdfull_0 = drag_data(:,3); + +% Altitude 30000m, full base drag +cdfull_30000 = drag_data(:,4); + +% Altitude 0m, no base drag +cdzero_0 = drag_data(:,2); + +% Interpolate for Cd values at two stated altitudes, then interpolate for +% Cd value at a specific altitude + +R = 8.3145; +gamma = 1.4; +M_air = 0.0289645; + +[T,p,rho] = CalcAtmosQuantities(altitude); +sound_speed = sqrt(gamma*R*T/M_air); +mach_speed = velocity/sound_speed; + +% Check if propellant is still available +if (time > tb) % Propellant is not available + if (altitude > 30000) + coeffdrag = interp1(mach_no, cdfull_30000, mach_speed); + else + coeffdrag = interp1(mach_no, cdfull_0, mach_speed); + end +else % Propellant still burning + coeffdrag = interp1(mach_no, cdzero_0, mach_speed); +end + +end + diff --git a/Code/ICANSAT/V0/ICANSAT.m b/Code/ICANSAT/V0/ICANSAT.m index a57b576..b8baecc 100644 --- a/Code/ICANSAT/V0/ICANSAT.m +++ b/Code/ICANSAT/V0/ICANSAT.m @@ -3,7 +3,7 @@ addpath('../') addpath('../..') % Df, Lr, Ls, ms, mp, tb -icansat = SingleStageRocket(0.1567, 2.391, 4, 14, 1.92, 8.0); +icansat = SingleStageRocket(0.1567, 2.391, 4, 14, 1.92, 8.0, 0); % Timestep, no. of timesteps, launch angle icansat.SetSimulationParams(0.01, 10000, 88); diff --git a/Code/ICANSAT/V1/ICANSAT_V1.m b/Code/ICANSAT/V1/ICANSAT_V1.m index 443b243..6bb7bee 100644 --- a/Code/ICANSAT/V1/ICANSAT_V1.m +++ b/Code/ICANSAT/V1/ICANSAT_V1.m @@ -3,7 +3,7 @@ addpath('../') addpath('../..') % Df, Lr, Ls, ms, mp, tb -icansat = SingleStageRocket(0.1567, 2.391, 4, 14, 1.160534, 4.0); +icansat = SingleStageRocket(0.1567, 2.391, 4, 14, 1.160534, 4.0, 0); RunTrajectorySim(icansat, 88); RunTrajectorySim(icansat, 86); diff --git a/Code/ICANSAT/V2/ICANSAT_V2.m b/Code/ICANSAT/V2/ICANSAT_V2.m index d2ca3e1..9855112 100644 --- a/Code/ICANSAT/V2/ICANSAT_V2.m +++ b/Code/ICANSAT/V2/ICANSAT_V2.m @@ -3,7 +3,7 @@ addpath('../') addpath('../..') % Df, Lr, Ls, ms, mp, tb -icansat = SingleStageRocket(0.1567, 2.391, 4, 14, 1.160534, 3.6325); +icansat = SingleStageRocket(0.1567, 2.391, 4, 14, 1.160534, 3.6325, 0); RunTrajectorySim(icansat, 88); RunTrajectorySim(icansat, 86); diff --git a/Code/MAD/MAD_Validation.m b/Code/MAD/MAD_Validation.m index 0e44806..fe12388 100644 --- a/Code/MAD/MAD_Validation.m +++ b/Code/MAD/MAD_Validation.m @@ -1,7 +1,7 @@ clc addpath('../') -mad = SingleStageRocket(0.205, 4.96, 10, 68, 78, 20.1); +mad = SingleStageRocket(0.205, 4.96, 10, 68, 78, 20.1, 0); mad.SetSimulationParams(0.05, 10000, 85); mad.SetRocketID("MAD"); mad.InitializeVars(); diff --git a/Code/MAD_H300/MAD_H300.m b/Code/MAD_H300/MAD_H300.m new file mode 100644 index 0000000..a590024 --- /dev/null +++ b/Code/MAD_H300/MAD_H300.m @@ -0,0 +1,12 @@ +clc +addpath('../') + +mad_H300 = SingleStageRocket(0.31, 5.712, 1, 148, 158, 15.77, 0.0283); +mad_H300.SetSimulationParams(0.05, 20000, 85); +mad_H300.SetRocketID("MAD_H300"); +mad_H300.InitializeVars(); +mad_H300.SetThrustCorrection(); + +mad_H300.CalculateThrust('MAD_H300_v1_VacT_v_Time.txt'); +mad_H300.CalculateTrajectory(); +mad_H300.WriteCompactDataFile(20); \ No newline at end of file diff --git a/Code/MAD_H300/MAD_H300_DragData.txt b/Code/MAD_H300/MAD_H300_DragData.txt new file mode 100644 index 0000000..54f3e05 --- /dev/null +++ b/Code/MAD_H300/MAD_H300_DragData.txt @@ -0,0 +1,15 @@ +Mach NBD_0K FBD_0K FBD_30K +0 0.44 0.493 0.733 +0.3 0.432 0.484 0.653 +0.5 0.427 0.478 0.6 +0.7 0.42 0.47 0.565 +0.8 0.417 0.467 0.553 +0.9 0.443 0.492 0.572 +0.99 0.517 0.583 0.657 +1.01 0.532 0.602 0.696 +1.1 0.556 0.632 0.632 +1.2 0.553 0.625 0.683 +1.5 0.543 0.61 0.66 +2 0.458 0.513 0.56 +3 0.33 0.369 0.417 +4 0.244 0.269 0.331- diff --git a/Code/MAD_H300/MAD_H300_v1_VacT_v_Time.txt b/Code/MAD_H300/MAD_H300_v1_VacT_v_Time.txt new file mode 100644 index 0000000..5c45c3a --- /dev/null +++ b/Code/MAD_H300/MAD_H300_v1_VacT_v_Time.txt @@ -0,0 +1,26 @@ +0 0 +0.01 12970 +0.2 29125 +0.4 28002 +0.6 27233 +0.8 26677 +1 25804 +1.2 25526 +1.4 25306 +1.6 25123 +2 24829 +3 24312 +3.4 24130 +4 23947 +5 23649 +6 23385 +7 23134 +8 22893 +9 22654 +10 22411 +11 22163 +12 21909 +13 21641 +14 21366 +15 21086 +15.77 0 diff --git a/Code/SingleStageRocket.m b/Code/SingleStageRocket.m index 53c5236..969e44e 100644 --- a/Code/SingleStageRocket.m +++ b/Code/SingleStageRocket.m @@ -41,6 +41,7 @@ classdef SingleStageRocket < handle area % Cross sectional area q % Dynamic pressure launch_angle + exit_area % Nozzle exit_area % Rocket identifier (MAD, ICANSAT, Spark etc.) % For purposes of drag identification @@ -52,7 +53,7 @@ classdef SingleStageRocket < handle methods % Initialization - function self = SingleStageRocket(Df, Ls, Lr, ms, mp, tb) + function self = SingleStageRocket(Df, Ls, Lr, ms, mp, tb, ae) % Set rocket parameters self.Df = Df; self.Ls = Ls; @@ -67,6 +68,10 @@ classdef SingleStageRocket < handle % Derived parameters self.mt = self.ms + self.mp; + + % Nozzle exit area + % If ae == 0, then thrust correction using exit area is ignored. + self.exit_area = ae; end % Set rocket ID @@ -166,11 +171,16 @@ classdef SingleStageRocket < handle end % Thrust correction based on ASTOS manual - function T = ThrustCorrection(obj, h, thrust) + function T = AstosThrustCorrection(obj, h, thrust) [t,p,rho] = CalcAtmosQuantities(h); T = thrust*1.095 - 0.014 * p; end + function T = VacThrustCorrection(obj, h, thrust) + [t,p,rho] = CalcAtmosQuantities(h); + T = thrust - 0; + end + % Calculate mass at each iteration function CalculateMassFlow(obj,n_tb) g0 = 9.8066; @@ -228,7 +238,10 @@ classdef SingleStageRocket < handle case "MAD" Cd = DragInterpolations_MAD(V, y, t, obj.tb); - + + case "MAD_H300" + Cd = DragInterpolations_MAD_H300(V, y, t, obj.tb); + % Spark data not validated case "Spark" Cd = DragInterpolations_Spark(V, y); @@ -256,9 +269,16 @@ classdef SingleStageRocket < handle else % Thrust correction if boolean true if obj.thrust_correction == true - obj.thrust(i) = obj.ThrustCorrection(obj.y(i-1), obj.thrust(i)); - if obj.thrust(i) < 0 - obj.thrust(i) = 0; + if obj.ID == "MAD" + obj.thrust(i) = obj.AstosThrustCorrection(obj.y(i-1), obj.thrust(i)); + if obj.thrust(i) < 0 + obj.thrust(i) = 0; + end + else + obj.thrust(i) = obj.VacThrustCorrection(obj.y(i-1), obj.thrust(i)); + if obj.thrust(i) < 0 + obj.thrust(i) = 0; + end end end thrust_i = obj.thrust(i); @@ -330,8 +350,11 @@ classdef SingleStageRocket < handle end + % Flight path angle in ° obj.theta = obj.theta*(180/pi); - obj.q = obj.q./1000; + + % Dynamic pressure in kPa + obj.q = obj.q./1000; %% PREDICTED PERFORMANCE Vx = max(obj.V); Mx = max(obj.M); @@ -360,13 +383,32 @@ classdef SingleStageRocket < handle text = "VariableMassFlow"; result_dat_file = 'Result/' + obj.ID + "_Result_" + obj.launch_angle + "_deg_" + text + ".txt"; end - result_matrix = [obj.t obj.x/1000 obj.y/1000 obj.M obj.thrust obj.DvDt obj.m obj.mdot obj.isp]; - result_data = reshape(result_matrix, [], 9); - dlmwrite(result_dat_file, 'Time(s),x(km),y(km),Mach,Thrust(N),Acceleration(m/s2),Mass(kg),mdot(kg/s),Isp (s)','delimiter','') + result_matrix = [obj.t obj.x/1000 obj.y/1000 obj.V obj.M obj.thrust obj.DvDt obj.m obj.mdot obj.isp obj.Cd obj.q]; + result_data = reshape(result_matrix, [], 12); + dlmwrite(result_dat_file, 'Time(s),x(km),y(km),Velocity(m/s),Mach,Thrust(N),Acceleration(m/s2),Mass(kg),mdot(kg/s),Isp(s),Cd,DynPres(kPa)','delimiter','') dlmwrite(result_dat_file, result_data, '-append', 'delimiter', ','); notify_text = 'Results written for ' + obj.ID + ' at ' + obj.launch_angle + " degrees.\n "; fprintf(notify_text); fprintf("-----------------------------------------------------------------------------------\n"); end + + % Reduce data by n times + function WriteCompactDataFile(obj, n) + if obj.mdot_constant == true + result_dat_file = 'Result/' + obj.ID + "_Result_" + obj.launch_angle + "deg (Compact).txt"; + else + text = "VariableMassFlow"; + result_dat_file = 'Result/' + obj.ID + "_Result_" + obj.launch_angle + "_deg_" + text + ".txt"; + end + result_matrix = [obj.t(1:n:obj.NStepEnd) obj.x(1:n:obj.NStepEnd)/1000 obj.y(1:n:obj.NStepEnd)/1000 obj.V(1:n:obj.NStepEnd) obj.M(1:n:obj.NStepEnd) ... + obj.thrust(1:n:obj.NStepEnd) obj.DvDt(1:n:obj.NStepEnd) obj.m(1:n:obj.NStepEnd) obj.mdot(1:n:obj.NStepEnd) obj.isp(1:n:obj.NStepEnd) obj.Cd(1:n:obj.NStepEnd) ... + obj.q(1:n:obj.NStepEnd)]; + result_data = reshape(result_matrix, [], 12); + dlmwrite(result_dat_file, 'Time(s),x(km),y(km),Velocity(m/s),Mach,Thrust(N),Acceleration(m/s2),Mass(kg),mdot(kg/s),Isp(s),Cd,DynPres(kPa)','delimiter','') + dlmwrite(result_dat_file, result_data, '-append', 'delimiter', ','); + notify_text = 'Compact results written for ' + obj.ID + ' at ' + obj.launch_angle + " degrees.\n "; + fprintf(notify_text); + fprintf("-----------------------------------------------------------------------------------\n"); + end end end \ No newline at end of file