Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #116

Merged
merged 33 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
447baaf
Solve: error range equivalence ratio
AlbertoCuadra Dec 6, 2021
4a423d5
Add: update GUI last results
AlbertoCuadra Dec 6, 2021
abba953
Add: gui_add_children (draft)
AlbertoCuadra Dec 6, 2021
5656a7b
Update
AlbertoCuadra Dec 6, 2021
1b340fb
Update: rename and improve performance
AlbertoCuadra Dec 7, 2021
4e6139f
Update: rename
AlbertoCuadra Dec 7, 2021
7b5e5ad
Add: update UITree (save data)
AlbertoCuadra Dec 7, 2021
b40f6fe
Add: UITree and rename some functions
AlbertoCuadra Dec 7, 2021
a95f811
Add: composition results and read data from uitree
AlbertoCuadra Dec 7, 2021
3b7dc88
Add: compute phi soot and fuel/oxidizer ratios
AlbertoCuadra Dec 7, 2021
f35535e
Add: compatibility for complete reaction
AlbertoCuadra Dec 7, 2021
3c41aeb
Update: set phi soot to inf in case no fuel
AlbertoCuadra Dec 7, 2021
37ebe00
Add: compute equilibrium with complete reaction
AlbertoCuadra Dec 7, 2021
1a25e6c
Update: save data UITree
AlbertoCuadra Dec 7, 2021
1f76d43
Add: compute percentage Fuel, Oxidizer/Fuel ...
AlbertoCuadra Dec 7, 2021
3b05e41
Add: recompute in case nan in equilibrium
AlbertoCuadra Dec 7, 2021
3debece
Solve: error ListProducts
AlbertoCuadra Dec 7, 2021
422c2de
Update: comments
AlbertoCuadra Dec 7, 2021
114cdce
Add: temporaly app for preliminary computations
AlbertoCuadra Dec 8, 2021
45a63a4
Add: compute Mach for a given velocity, viceversa
AlbertoCuadra Dec 8, 2021
ac85703
Update: unnecesary
AlbertoCuadra Dec 8, 2021
9d5ac3d
Solve: typo phi = 45 (char space)
AlbertoCuadra Dec 8, 2021
bec665d
Add: compute range of Mach or velocity (GUI)
AlbertoCuadra Dec 8, 2021
df26ee7
Update: less decimals
AlbertoCuadra Dec 8, 2021
99eed5d
Solve: minor bug when computing sound velocity
AlbertoCuadra Dec 8, 2021
a6f221a
Solve: error check condensed
AlbertoCuadra Dec 14, 2021
dd1b14c
Add: example seminar UMA 2021
AlbertoCuadra Dec 14, 2021
95cc7b8
Update: typo
AlbertoCuadra Dec 14, 2021
c692ded
Solve: error write results
AlbertoCuadra Dec 14, 2021
3b0382f
Solve: wrong value post-shock velocity
AlbertoCuadra Dec 14, 2021
d790038
Update
AlbertoCuadra Dec 14, 2021
f6886dd
Add: function to compute a vector of gibbs energy
AlbertoCuadra Dec 14, 2021
f0a88df
Merge branch 'master' into develop
AlbertoCuadra Dec 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Databases/Functions/set_g0.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function g0 = set_g0(ls, TP, DB)
% Function that computes the vector of gibbs free energy for the given
% set of species [J/mol]
for i=length(ls):-1:1
species = ls{i};
g0(i, 1) = species_g0(species, TP, DB) * 1e3;
end
end
30 changes: 30 additions & 0 deletions Examples/Example_TP_seminar.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
% -------------------------------------------------------------------------
% EXAMPLE: TP_seminar
%
% Compute equilibrium composition at defined temperature (e.g., 1500 K) and
% pressure (e.g., 1.01325 bar) for a lean H2-Br2 mixture at
% standard conditions, and a set of 3 species considered.
%
% species == {'H2', 'Br2', 'HBr'}
%
% See wiki or ListSpecies() for more predefined sets of species
%
% @author: Alberto Cuadra Lara
% PhD Candidate - Group Fluid Mechanics
% Universidad Carlos III de Madrid
%
% Last update Dec 10 2021
% -------------------------------------------------------------------------

%% INITIALIZE
self = App({'H2', 'Br2', 'HBr'});
%% INITIAL CONDITIONS
self = set_prop(self, 'TR', 300, 'pR', 1 * 1.01325);
self.PD.S_Fuel = {'H2', 'Br2'};
self.PD.N_Fuel = [0.75, 0.25];
%% ADDITIONAL INPUTS (DEPENDS OF THE PROBLEM SELECTED)
self = set_prop(self, 'pP', self.PD.pR.value, 'TP', 1500);
%% SOLVE PROBLEM
self = SolveProblem(self, 'TP');
%% DISPLAY RESULTS (PLOTS)
postResults(self);
39 changes: 26 additions & 13 deletions GUI/Functions/gui_CalculateButtonPushed.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
% Save results
results = save_results(obj, app);
% Update GUI with the last results of the set
obj = update_results_gui(obj, results);
obj = gui_update_results(obj, results);
% Display results (plots)
postResults(app);
% Set lamp to Done color
Expand All @@ -34,27 +34,40 @@
end

% SUB-PASS FUNCTIONS
function obj = update_results_gui(obj, app)
% Update GUI with the results computed
function obj = gui_update_results(obj, results)
% Update:
% 1. GUI with the last results computed
% 2. GUI-UITree with all the results

% Update GUI with the last result computed
gui_write_results(obj, results, 1);
% Update UITree with all the results
gui_add_nodes(obj.Node_Results, results)
end

function obj = get_listSpecies_gui(obj)
obj.LS = obj.listbox_Products.Items;
if isempty(obj.LS)
% Get default value
obj.LS = 'Soot Formation';
obj.LS = ListSpecies([], 'Soot Formation');
end
end
function results = save_results(obj, app)
% Save results in the UITree
% 1. Save data
results.mix1 = app.PS.strR;
results.mix2 = app.PS.strP;
results.ProblemType = obj.ProblemType.Value;
results.reaction = obj.Reaction.Value;
results.LS = obj.LS;
results.LS_products = obj.LS_products;
% 2. Save results in the UITree
% Save results
N = length(app.PS.strR);
for i = N:-1:1
results(i).mix1 = app.PS.strR{i};
results(i).mix2 = app.PS.strP{i};
results(i).ProblemType = obj.ProblemType.Value;
results(i).Reactants = obj.Reactants.Items{sscanf(obj.Reactants.Value, '%d')};
results(i).Products = obj.Products.Value;
if isempty(results(i).Products)
results(i).Products = 'Default';
end
results(i).LS = app.S.LS;
results(i).LS_products = obj.LS;
results(i).UITable_R_Data = obj.UITable_R.Data;
end
end

function app = get_input_constrains(obj, app)
Expand Down
10 changes: 5 additions & 5 deletions GUI/Functions/gui_ProblemTypeValueChanged.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ function gui_ProblemTypeValueChanged(obj)
% Set default input values
obj.PR1.Value = '300';
obj.PR2.Value = '1';
obj.PR3.Value = '0';
obj.PR4.Value = '0';
obj.PR4.Value = '2';
gui_compute_mach_or_velocity(obj, 'Mach');
% Set visible item volume ratio
obj.text_vP_vR.Visible = 'off';
obj.text_vP_vR.Visible = 'off';
% Set invisible shocks/detonation items
gui_visible_shocks(obj, true);
case 'SHOCK_R' % * SHOCK_R: CALCULATE PLANAR POST-REFLECTED SHOCK STATE
Expand All @@ -144,8 +144,8 @@ function gui_ProblemTypeValueChanged(obj)
% Set default input values
obj.PR1.Value = '300';
obj.PR2.Value = '1';
obj.PR3.Value = '0';
obj.PR4.Value = '0';
obj.PR4.Value = '2';
gui_compute_mach_or_velocity(obj, 'Mach');
% Set visible item volume ratio
obj.text_vP_vR.Visible = 'off';
% Set invisible shocks/detonation items
Expand Down
19 changes: 19 additions & 0 deletions GUI/Functions/gui_ProductsValueChanged.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function gui_ProductsValueChanged(obj)
% Update List of species considered as Products
try
if isempty(obj.Products.Value)
temp_app = ListSpecies(obj);
obj.listbox_Products.Items = temp_app.S.LS;
else
% Update List of Products depending of the value of the equivalence ratio
if strcmpi(obj.Products.Value, 'Complete Reaction')
gui_edit_phiValueChanged(obj, []);
else
temp_app = ListSpecies(obj, obj.Products.Value);
obj.listbox_Products.Items = temp_app.S.LS;
end
end
catch
obj.listbox_Products.Items = {};
end
end
9 changes: 0 additions & 9 deletions GUI/Functions/gui_ReactionValueChanged.m

This file was deleted.

48 changes: 48 additions & 0 deletions GUI/Functions/gui_add_nodes.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function gui_add_nodes(obj_parent, results)
% Function that generate nodes in a UITree and save data on them.
% 1. Generate Nodes (childrens)
% * Category 1: new children node: Results -> ProblemType
match_text = strcat('Problem Type: ', results(1).ProblemType);
category1 = set_node(obj_parent, match_text);
% * Category 2: new children node: ProblemType -> Reactants
match_text = strcat('Reactants: ', results(1).Reactants);
category2 = set_node(category1, match_text);
% * Category 3: new children node: Reactants -> ListProducts
match_text = strcat('List Products: ', results(1).Products);
category3 = set_node(category2, match_text);
% * Category 4: new children node: ListProducts -> cases
for i = 1:length(results)
match_text = sprintf('Case %d', category3.UserData);
set_node(category3, match_text, 'NodeData', results(i));
category3.UserData = category3.UserData + 1;
end
end

function category_children = set_node(category_parent, match_text, varargin)
% Default values
NodeData = [];
% Check varargin inputs
for i = 1:nargin - 3
switch lower(varargin{i})
case 'nodedata'
NodeData = varargin{i + 1};
end
end
% Set node
j = 0;
if ~isempty(category_parent.Children)
i = 1;
while i <= length(category_parent.Children)
if strcmpi(category_parent.Children(i).Text, match_text)
category_children = category_parent.Children(i);
j = 1;
break;
end
i = i + 1;
end
end
if j == 0
category_children = uitreenode(category_parent, 'Text', match_text, 'NodeData', NodeData, 'UserData', 1);
end
expand(category_parent,'all');
end
31 changes: 31 additions & 0 deletions GUI/Functions/gui_compute_mach_or_velocity.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function gui_compute_mach_or_velocity(obj, inputname)
% Function that computes the pre-shock Mach number of the mixture from
% a given pre-shock velocity or viceversa.
if any(contains(obj.ProblemType.Value, 'SHOCK', 'IgnoreCase', true))
if ~isempty(obj.UITable_R.Data)
temp_app = gui_create_temp_app(obj, [], false);
mix1 = temp_app.PS.strR{1};

if strcmpi(inputname, 'Mach')
[M1, FLAG] = gui_get_prop(obj, 'M1', obj.PR4.Value);
u1 = M1 * soundspeed(mix1);
obj.PR3.Value = compute_vector_or_scalar(u1, FLAG);
else
[u1, FLAG] = gui_get_prop(obj, 'u1', obj.PR3.Value);
M1 = u1 / soundspeed(mix1);
obj.PR4.Value = compute_vector_or_scalar(M1, FLAG);
end
else
obj.PR3.Value = '-';
end
end
end

% SUB-PASS FUNCTIONS
function value_char = compute_vector_or_scalar(value, FLAG)
if FLAG
value_char = sprintf('[%.2f:%.2f:%.2f]', value(1), value(2) - value(1), value(end));
else
value_char = sprintf('%.2f', value);
end
end
14 changes: 0 additions & 14 deletions GUI/Functions/gui_compute_propReactants.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,4 @@
app = get_FLAG_N(app);
% Compute stoichiometric matrix and properties of the mixture
app = Define_FOI(app, 1);
if ~isempty(app.PD.S_Fuel) && ~isempty(app.PD.S_Oxidizer)
% Compute percentage Fuel, Oxidizer/Fuel ratio and equivalence ratio
R = app.PD.R_Fuel + app.PD.R_Oxidizer + app.PD.R_Inert;
app.PS.strR{1}.percentage_Fuel = sum(app.PD.R_Fuel(:, 1)) / sum(R(:, 1)) * 100;
app.PS.strR{1}.FO = sum(app.PD.R_Fuel(:, 1)) / sum(app.PD.R_Oxidizer(:, 1));
app.PS.strR{1}.FO_st = sum(app.PD.R_Fuel(:, 1)) / (app.PS.strR_Fuel.x + app.PS.strR_Fuel.y/4 - app.PS.strR_Fuel.z/2);
app.PS.strR{1}.OF = 1/app.PS.strR{1}.FO;
app.PS.strR{1}.phi = app.PS.strR{1}.FO / app.PS.strR{1}.FO_st;
else
app.PS.strR{1}.percentage_Fuel = 0;
app.PS.strR{1}.FO = inf;
app.PS.strR{1}.OF = 0;
app.PS.strR{1}.phi = '-';
end
end
10 changes: 10 additions & 0 deletions GUI/Functions/gui_create_temp_app.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function app = gui_create_temp_app(obj, event, FLAG_COMPUTE_FROM_PHI)
% Function that creates an app required for preliminary calculations

% Initialize app (fast: transfer DB)
app = App('fast', obj.DB_master, obj.DB);
% Get reactant species
app = gui_get_reactants(obj, event, app, FLAG_COMPUTE_FROM_PHI);
% Compute properties of the mixture
app = gui_compute_propReactants(obj, app);
end
35 changes: 26 additions & 9 deletions GUI/Functions/gui_edit_phiValueChanged.m
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
function gui_edit_phiValueChanged(obj, event)
function [obj, temp_app] = gui_edit_phiValueChanged(obj, event)
% Update moles and mole fractions of the reactant UITables for the
% given equivalence ratio
try
% If UITable_R is empty the equivalence can not change
if isempty(obj.UITable_R.Data)
return
end
% Initialize app (fast: transfer DB)
app = App('fast', obj.DB_master, obj.DB);
% Set FLAG compute moles from equivalence ratio
FLAG_COMPUTE_FROM_PHI = true;
% Get reactant species
app = gui_get_reactants(obj, event, app, FLAG_COMPUTE_FROM_PHI);
% Compute properties of the mixture
app = gui_compute_propReactants(obj, app);
% Create temporaly app required for preliminary calculations
temp_app = gui_create_temp_app(obj, event, FLAG_COMPUTE_FROM_PHI);
% Update UITable classes
gui_update_UITable_R(obj, app);
gui_update_UITable_R(obj, temp_app);
obj.UITable_P.Data = obj.UITable_R.Data(:, 1); % (species, numer of moles, mole fractions, temperature)
obj.UITable_R2.Data = obj.UITable_R.Data(:, 1:3); % (species, numer of moles, mole fractions)
% Update GUI: equivalence ratio, O/F and percentage Fuel
gui_update_phi(obj, app);
obj.edit_phi2.Value = obj.edit_phi.Value;
obj.edit_OF.Value = 1/temp_app.PS.strR{1}.FO;
obj.edit_F.Value = temp_app.PS.strR{1}.percentage_Fuel;
% Check List of products (only in case of ListProducts == Complete reaction)
temp_app = check_ListProducts(obj, temp_app);
catch ME
message = {sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message)};
uialert(obj.UIFigure, message, 'Warning', 'Icon', 'warning');
end
end

function app = check_ListProducts(obj, app)
if strcmpi(obj.Products.Value, 'Complete Reaction')
if isempty(obj.UITable_R.Data)
% Set lamp to Error color
obj.Lamp.Color = obj.color_lamp_warning;
% Print error
message = {'First, define initial mixture'};
uialert(obj.UIFigure, message, 'Warning', 'Icon', 'warning');
end
% Update List of Products depending of the value of the equivalence ratio
phi = app.PS.strR{1}.phi;
phi_c = app.PS.strR{1}.phi_c;
app = ListSpecies(obj, obj.Products.Value, phi, phi_c);
obj.listbox_Products.Items = app.S.LS;
end
end
4 changes: 2 additions & 2 deletions GUI/Functions/gui_get_prop.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
else
flag_prop = false;
value = sscanf(value,'%f');
if isempty(value); value = app.PD.(name).value; return; end
app.PD.(name).value = value;
% if isempty(value); value = app.PD.(name).value; return; end
% app.PD.(name).value = value;
end

extra_parameters = nargin - 3;
Expand Down
8 changes: 8 additions & 0 deletions GUI/Functions/gui_update_from_uitree.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function gui_update_from_uitree(obj, selectedNodes)
% Update GUI with the data that correspond with the selected node from
% the UITree
if isempty(selectedNodes.Children)
results = selectedNodes.NodeData;
gui_write_results(obj, results, 1, 'FLAG_REACTANTS', true);
end
end
2 changes: 1 addition & 1 deletion GUI/Functions/gui_update_frozen.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ function gui_update_frozen(obj)
obj.listbox_Products.Items = {};
end
else
gui_ReactionValueChanged(obj)
gui_ProductsValueChanged(obj)
end
end
Loading