Skip to content

Commit

Permalink
Merge pull request #773 from AlbertoCuadra/develop
Browse files Browse the repository at this point in the history
Update: reorganize CT-ROCKET module
  • Loading branch information
AlbertoCuadra committed Mar 6, 2023
2 parents d2cd8d5 + 8d1ac04 commit 6f9dc3d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
function [mix2_inj, mix2_c, mix3] = compute_chamber_FAC(self, mix1, varargin)
% Compute chemical equilibria at the injector, outlet of the chamber,
function [mix2_inj, mix2_c, mix3] = compute_FAC(self, mix1, mix2_inj, mix2_c, mix3)
% Compute chemical equilibria at the injector, outlet of the chamber and at the throat
% using the Finite-Area-Chamber (FAC) model
%
% This method is based on Gordon, S., & McBride, B. J. (1994). NASA reference publication, 1311.
%
% Args:
% self (struct): Data of the mixture, conditions, and databases
% mix1 (struct): Properties of the initial mixture
%
% Optional Args:
% * mix2_inj (struct): Properties of the mixture at the injector of the chamber (previous calculation)
% * mix2_c (struct): Properties of the mixture at the outlet of the chamber (previous calculation)
% * mix3 (struct): Properties of the mixture at the throat (previous calculation)
% mix2_inj (struct): Properties of the mixture at the injector of the chamber (previous calculation)
% mix2_c (struct): Properties of the mixture at the outlet of the chamber (previous calculation)
% mix3 (struct): Properties of the mixture at the throat (previous calculation)
%
% Returns:
% mix2_inj (struct): Properties of the mixture at the injector of the chamber
% mix2_c (struct): Properties of the mixture at the outlet of the chamber
% mix3 (struct): Properties of the mixture at the throat
% Tuple containing
%
% * mix2_inj (struct): Properties of the mixture at the injector of the chamber
% * mix2_c (struct): Properties of the mixture at the outlet of the chamber
% * mix3 (struct): Properties of the mixture at the throat

% Abbreviations
TN = self.TN;
% Unpack
if nargin > 3, mix2_inj = get_struct(varargin{1}); else, mix2_inj = []; end
if nargin > 4, mix2_c = get_struct(varargin{2}); else, mix2_c = []; end
if nargin > 5, mix3 = get_struct(varargin{3}); else, mix3 = []; end
% Definitions
Aratio_chamber = self.PD.Aratio_c.value;
% Obtain mixture compostion and properties at the injector of the chamber (equivalent to the outlet of the chamber using IAC model)
Expand Down Expand Up @@ -53,7 +49,7 @@
% Compute pressuse_inj_a
pressure_inj_a = (pressure_c + density_c * velocity_c^2); % [Pa]
% Check convergence
STOP = abs(pressure_inj - pressure_inj_a) / pressure_inj;
STOP = abs(pressure_inj_a - pressure_inj) / pressure_inj_a;
% Update guess
pressure_inf = pressure_inf * pressure_inj / pressure_inj_a; % [bar]
mix2_inf.p = pressure_inf;
Expand All @@ -68,16 +64,6 @@
end

% SUB-PASS FUNCTIONS
function str = get_struct(var)

try
str = var{1, 1};
catch
str = var;
end

end

function pressure_inf = compute_initial_guess_pressure(pressure_inj, Aratio_chamber)
% Compute initial guess of the pressure assuming an Infinite-Area-Chamber
% (IAC) for the Finite-Area-Chamber model (FAC)
Expand Down
2 changes: 1 addition & 1 deletion modules/ct_rocket/compute_chamber_IAC.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
% Definitions
self.PD.ProblemType = 'HP';
% Compute chemical equilibria at the exit of the chamber (HP)
mix2 = compute_chemical_equilibria(self, mix1, mix1.p, mix2);
mix2 = equilibrate(self, mix1, mix1.p, mix2);
% Set A_chamber/A_throat
mix2.Aratio = Inf;
end
20 changes: 0 additions & 20 deletions modules/ct_rocket/compute_chemical_equilibria.m

This file was deleted.

2 changes: 1 addition & 1 deletion modules/ct_rocket/compute_exit.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
% Extract pressure [bar]
pressure = extract_pressure(logP, mix2.p);
% Solve chemical equilibrium (SP)
mix4 = compute_chemical_equilibria(self, mix2, pressure, mix4);
mix4 = equilibrate(self, mix2, pressure, mix4);
% Compute velocity at the exit point
mix4.u = compute_velocity(mix2_in, mix4);
% Compute new estimate
Expand Down
2 changes: 1 addition & 1 deletion modules/ct_rocket/compute_throat_IAC.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
% Loop
while STOP > self.TN.tol_rocket && it < self.TN.it_rocket
it = it + 1;
mix3 = compute_chemical_equilibria(self, mix2, pressure, mix3);
mix3 = equilibrate(self, mix2, pressure, mix3);
mix3.u = compute_velocity(mix2, mix3);
pressure = compute_pressure(mix3);
STOP = compute_STOP(mix3);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [mix3, varargout] = compute_rocket_parameters(mix2, mix3, gravity, varargin)
function [mix3, varargout] = rocket_parameters(mix2, mix3, gravity, varargin)
% Compute Rocket performance parameters at the throat
%
% This method is based on Gordon, S., & McBride, B. J. (1994). NASA reference publication,
Expand Down
39 changes: 20 additions & 19 deletions modules/ct_rocket/rocket_performance.m
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
function [mix1, mix2_inj, mix2_c, mix3, mix4] = rocket_performance(self, mix1, Aratio, varargin)
function [mix1, mix2_inj, mix2_c, mix3, mix4] = rocket_performance(self, mix1, varargin)
% Routine that computes the propellant rocket performance
%
% Methods implemented:
% * Infinite-Area-Chamber (IAC)
% * Finite-Area-Chamber (FAC) - NOT YET
% * Finite-Area-Chamber (FAC)
%
% This method is based on Gordon, S., & McBride, B. J. (1994). NASA reference publication,
% 1311.
%
% Args:
% self (struct): Data of the mixture, conditions, and databases
% mix1 (struct): Properties of the initial mixture
% Aratio (struct): Ratio area_exit / area_throat
%
% Optional Args:
% - mix2 (struct): Properties of the mixture at the outlet of the chamber (previous calculation)
% - mix3 (struct): Properties of the mixture at the throat (previous calculation)
% * Aratio (struct): Ratio area_exit / area_throat
% * mix2 (struct): Properties of the mixture at the outlet of the chamber (previous calculation)
% * mix3 (struct): Properties of the mixture at the throat (previous calculation)
%
% Returns:
% Tuple containing
%
% - mix1 (struct): Properties of the initial mixture
% - mix2 (struct): Properties of the mixture at the outlet of the chamber
% - mix3 (struct): Properties of the mixture at the throat
% - mix4 (struct): Properties of the mixture at the given exit points

% Assign values
if nargin > 3, mix2_inj = get_struct(varargin{1}); else, mix2_inj = []; end
if nargin > 4, mix2_c = get_struct(varargin{2}); else, mix2_c = []; end
if nargin > 5, mix3 = get_struct(varargin{3}); else, mix3 = []; end
if nargin > 6, mix4 = get_struct(varargin{4}); else, mix4 = []; end
% * mix1 (struct): Properties of the initial mixture
% * mix2 (struct): Properties of the mixture at the outlet of the chamber
% * mix3 (struct): Properties of the mixture at the throat
% * mix4 (struct): Properties of the mixture at the given exit points

% Unpack additional input parameters
if nargin > 2, Aratio = varargin{1}; else, Aratio = []; end
if nargin > 3, mix2_inj = get_struct(varargin{2}); else, mix2_inj = []; end
if nargin > 4, mix2_c = get_struct(varargin{3}); else, mix2_c = []; end
if nargin > 5, mix3 = get_struct(varargin{4}); else, mix3 = []; end
if nargin > 6, mix4 = get_struct(varargin{5}); else, mix4 = []; end
% Compute chemical equilibria at different points of the rocket
% depending of the model selected
[mix2_inj, mix2_c, mix3, mix4] = solve_model_rocket(self, mix1, mix2_inj, mix2_c, mix3, mix4, Aratio);
Expand All @@ -39,22 +40,22 @@
if self.PD.FLAG_IAC
% Velocity at the outlet of the chamber
mix2_c.u = 0; mix2_c.v_shock = 0;
[mix3, mix4] = compute_rocket_parameters(mix2_c, mix3, self.C.gravity, mix4);
[mix3, mix4] = rocket_parameters(mix2_c, mix3, self.C.gravity, mix4);
else
% Velocity at the injector
mix2_inj.u = 0; mix2_inj.v_shock = 0;
[mix3, mix2_c, mix4] = compute_rocket_parameters(mix2_inj, mix3, self.C.gravity, mix2_c, mix4);
[mix3, mix2_c, mix4] = rocket_parameters(mix2_inj, mix3, self.C.gravity, mix2_c, mix4);
end

end

% SUB-PASS FUNCTIONS
function str = get_struct(var)

% Get struct
try
str = var{1, 1};
catch
str = var;
end

end
end
10 changes: 5 additions & 5 deletions modules/ct_rocket/solve_model_rocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
% Returns:
% Tuple containing
%
% - mix2_1 (struct): Properties of the mixture at injector of the chamber (only FAC)
% - mix2 (struct): Properties of the mixture at the outlet of the chamber
% - mix3 (struct): Properties of the mixture at the throat
% - mix4 (struct): Properties of the mixture at the given exit points
% * mix2_1 (struct): Properties of the mixture at injector of the chamber (only FAC)
% * mix2 (struct): Properties of the mixture at the outlet of the chamber
% * mix3 (struct): Properties of the mixture at the throat
% * mix4 (struct): Properties of the mixture at the given exit points

if self.PD.FLAG_IAC
mix2_inj = [];
mix2_c = compute_chamber_IAC(self, mix1, mix2_c);
mix3 = compute_throat_IAC(self, mix2_c, mix3);
mix4 = compute_exit(self, mix2_c, mix3, mix4, Aratio);
else
[mix2_inj, mix2_c, mix3] = compute_chamber_FAC(self, mix1, mix2_inj, mix2_c, mix3);
[mix2_inj, mix2_c, mix3] = compute_FAC(self, mix1, mix2_inj, mix2_c, mix3);
mix4 = compute_exit(self, mix2_c, mix3, mix4, Aratio, mix2_inj);
end

Expand Down

0 comments on commit 6f9dc3d

Please sign in to comment.