From a4a9f46ccdb7517ba0d2735f46fc4d85a859cbca Mon Sep 17 00:00:00 2001 From: Alberto Cuadra Lara Date: Mon, 6 Mar 2023 17:12:05 +0100 Subject: [PATCH] Update: reorganize CT-ROCKET module --- .../{compute_chamber_FAC.m => compute_FAC.m} | 36 ++++++----------- modules/ct_rocket/compute_chamber_IAC.m | 2 +- .../ct_rocket/compute_chemical_equilibria.m | 20 ---------- modules/ct_rocket/compute_exit.m | 2 +- modules/ct_rocket/compute_throat_IAC.m | 2 +- ...ocket_parameters.m => rocket_parameters.m} | 2 +- modules/ct_rocket/rocket_performance.m | 39 ++++++++++--------- modules/ct_rocket/solve_model_rocket.m | 10 ++--- 8 files changed, 40 insertions(+), 73 deletions(-) rename modules/ct_rocket/{compute_chamber_FAC.m => compute_FAC.m} (82%) delete mode 100644 modules/ct_rocket/compute_chemical_equilibria.m rename modules/ct_rocket/{compute_rocket_parameters.m => rocket_parameters.m} (94%) diff --git a/modules/ct_rocket/compute_chamber_FAC.m b/modules/ct_rocket/compute_FAC.m similarity index 82% rename from modules/ct_rocket/compute_chamber_FAC.m rename to modules/ct_rocket/compute_FAC.m index 539b7936..9c96625b 100644 --- a/modules/ct_rocket/compute_chamber_FAC.m +++ b/modules/ct_rocket/compute_FAC.m @@ -1,5 +1,5 @@ -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. @@ -7,23 +7,19 @@ % 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) @@ -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; @@ -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) diff --git a/modules/ct_rocket/compute_chamber_IAC.m b/modules/ct_rocket/compute_chamber_IAC.m index a130e99a..2bce124b 100644 --- a/modules/ct_rocket/compute_chamber_IAC.m +++ b/modules/ct_rocket/compute_chamber_IAC.m @@ -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 diff --git a/modules/ct_rocket/compute_chemical_equilibria.m b/modules/ct_rocket/compute_chemical_equilibria.m deleted file mode 100644 index aa66a4f1..00000000 --- a/modules/ct_rocket/compute_chemical_equilibria.m +++ /dev/null @@ -1,20 +0,0 @@ -function mix2 = compute_chemical_equilibria(self, mix1, pP, mix2) - % Compute chemical equilibria for the 2 given thermodynamic states, - % e.g., enthalpy-pressure (HP) - % - % Args: - % self (struct): Data of the mixture, conditions, and databases - % mix1 (struct): Properties of the initial mixture - % pP (float): Pressure [bar] - % mix2 (struct): Properties of the final mixture (previous calculation) - % - % Returns: - % mix2 (struct): Properties of the final mixture - - if isempty(mix2) - mix2 = equilibrate(self, mix1, pP); - else - mix2 = equilibrate(self, mix1, pP, mix2); - end - -end diff --git a/modules/ct_rocket/compute_exit.m b/modules/ct_rocket/compute_exit.m index be040dc4..58e970b5 100644 --- a/modules/ct_rocket/compute_exit.m +++ b/modules/ct_rocket/compute_exit.m @@ -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 diff --git a/modules/ct_rocket/compute_throat_IAC.m b/modules/ct_rocket/compute_throat_IAC.m index 4b18b9be..6bcc25cf 100644 --- a/modules/ct_rocket/compute_throat_IAC.m +++ b/modules/ct_rocket/compute_throat_IAC.m @@ -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); diff --git a/modules/ct_rocket/compute_rocket_parameters.m b/modules/ct_rocket/rocket_parameters.m similarity index 94% rename from modules/ct_rocket/compute_rocket_parameters.m rename to modules/ct_rocket/rocket_parameters.m index 8fb6c14a..1501eb65 100644 --- a/modules/ct_rocket/compute_rocket_parameters.m +++ b/modules/ct_rocket/rocket_parameters.m @@ -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, diff --git a/modules/ct_rocket/rocket_performance.m b/modules/ct_rocket/rocket_performance.m index 1fcff9b5..6e93a864 100644 --- a/modules/ct_rocket/rocket_performance.m +++ b/modules/ct_rocket/rocket_performance.m @@ -1,9 +1,9 @@ -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. @@ -11,25 +11,26 @@ % 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); @@ -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 \ No newline at end of file diff --git a/modules/ct_rocket/solve_model_rocket.m b/modules/ct_rocket/solve_model_rocket.m index 0b95650b..55fd4a66 100644 --- a/modules/ct_rocket/solve_model_rocket.m +++ b/modules/ct_rocket/solve_model_rocket.m @@ -21,10 +21,10 @@ % 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 = []; @@ -32,7 +32,7 @@ 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