-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from AlbertoCuadra/develop
Develop
- Loading branch information
Showing
27 changed files
with
436 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.