Skip to content

Commit

Permalink
Merge pull request #934 from AlbertoCuadra/933-update-uielements
Browse files Browse the repository at this point in the history
Update: include/remove selection of ionized and condensed species in uielements app #933
  • Loading branch information
AlbertoCuadra committed Jan 26, 2024
2 parents 22e9736 + a414302 commit f7dde42
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 28 deletions.
Binary file modified gui/addons/mlapp/uielements_app.mlapp
Binary file not shown.
98 changes: 89 additions & 9 deletions gui/addons/uielements.m
Expand Up @@ -5,6 +5,11 @@
UIElements matlab.ui.Figure
Panel_All matlab.ui.container.Panel
GridLayout matlab.ui.container.GridLayout
Panel_6 matlab.ui.container.Panel
GridLayout4 matlab.ui.container.GridLayout
condensed matlab.ui.control.CheckBox
burcat matlab.ui.control.CheckBox
ionized matlab.ui.control.CheckBox
Panel_Close matlab.ui.container.Panel
Close matlab.ui.control.Button
Panel_Export matlab.ui.container.Panel
Expand Down Expand Up @@ -320,6 +325,21 @@ function plot_property(app)
legend(ax, dline, species_label, 'FontSize', app.Misc.config.fontsize - 4, 'Location', 'best', 'interpreter', 'latex')
end


function find_species(app)
% Search species with the elements selected
if app.NE
try
LS = find_products(app, app.LE_selected, 'ind', app.S.ind_elements_DB);
catch
LS = {};
end

app.listbox_LS_DB.Items = LS;
end

end

end

methods
Expand Down Expand Up @@ -356,6 +376,10 @@ function startupFcn(app, varargin)
% Default size for plots
app.Misc.config.innerposition = [0.2, 0.15, 0.7, 0.7];
app.Misc.config.outerposition = [0.2, 0.15, 0.7, 0.7];
% Set default values
app.burcat.Value = app.S.FLAG_BURCAT;
app.ionized.Value = app.S.FLAG_ION;
app.condensed.Value = app.S.FLAG_CONDENSED;
end

% Image clicked function: element_1, element_10, element_11,
Expand All @@ -380,16 +404,9 @@ function element_1ImageClicked(app, event)
end

end
% Search species with the elements selected
if app.NE
try
LS = find_products(app, app.LE_selected, 'flag', true, 'ind', app.S.ind_elements_DB);
catch
LS = {};
end

app.listbox_LS_DB.Items = LS;
end
% Search species with the elements selected
find_species(app);
end

% Button pushed function: AddButton1
Expand Down Expand Up @@ -524,6 +541,30 @@ function listbox_LSClicked(app, event)
% Get last click | true == listbox_LS_DB, false = listbox_LS
app.FLAG_LAST_CLICK = false;
end

% Value changed function: ionized
function ionizedValueChanged(app, event)
% Consider ionized species
app.S.FLAG_ION = app.ionized.Value;
% Search species
find_species(app);
end

% Value changed function: condensed
function condensedValueChanged(app, event)
% Consider condensed species
app.S.FLAG_CONDENSED = app.condensed.Value;
% Search species
find_species(app);
end

% Value changed function: burcat
function burcatValueChanged(app, event)
% Consider species from the Third Millenium database (Burcat)
app.S.FLAG_BURCAT = app.burcat.Value;
% Search species
find_species(app);
end
end

% Component initialization
Expand Down Expand Up @@ -1466,6 +1507,45 @@ function createComponents(app)
app.Close.Position = [1 2 69 25];
app.Close.Text = 'Close';

% Create Panel_6
app.Panel_6 = uipanel(app.GridLayout);
app.Panel_6.BorderType = 'none';
app.Panel_6.BackgroundColor = [0.9098 0.9098 0.8902];
app.Panel_6.Layout.Row = [2 3];
app.Panel_6.Layout.Column = 3;

% Create GridLayout4
app.GridLayout4 = uigridlayout(app.Panel_6);
app.GridLayout4.ColumnWidth = {84};
app.GridLayout4.RowHeight = {22, 22, 22, '1x'};
app.GridLayout4.RowSpacing = 1;
app.GridLayout4.Padding = [0 10 0 10];
app.GridLayout4.BackgroundColor = [0.9098 0.9098 0.8902];

% Create ionized
app.ionized = uicheckbox(app.GridLayout4);
app.ionized.ValueChangedFcn = createCallbackFcn(app, @ionizedValueChanged, true);
app.ionized.Tooltip = {'Consider ionized species?'};
app.ionized.Text = 'Ionized';
app.ionized.Layout.Row = 1;
app.ionized.Layout.Column = 1;

% Create burcat
app.burcat = uicheckbox(app.GridLayout4);
app.burcat.ValueChangedFcn = createCallbackFcn(app, @burcatValueChanged, true);
app.burcat.Tooltip = {'Consider species from Third Millennium database (Burcat)?'};
app.burcat.Text = 'Burcat';
app.burcat.Layout.Row = 3;
app.burcat.Layout.Column = 1;

% Create condensed
app.condensed = uicheckbox(app.GridLayout4);
app.condensed.ValueChangedFcn = createCallbackFcn(app, @condensedValueChanged, true);
app.condensed.Tooltip = {'Consider condensed species?'};
app.condensed.Text = 'Conden.';
app.condensed.Layout.Row = 2;
app.condensed.Layout.Column = 1;

% Create ContextMenu
app.ContextMenu = uicontextmenu(app.UIElements);

Expand Down
1 change: 1 addition & 0 deletions modules/self/Species/Species.m
Expand Up @@ -55,4 +55,5 @@
self.FLAG_COMPLETE = false;
self.FLAG_BURCAT = false; % Find all the combinations of species from the database (without BURCAT's DB) that can appear as products for the given list of reactants
self.FLAG_ION = false; % Flag indicating to include ionized species in the automatic finder of species
self.FLAG_CONDENSED = true; % Flag indicating to include condensed species
end
53 changes: 43 additions & 10 deletions utils/databases/find_products.m
Expand Up @@ -10,6 +10,7 @@
% * ind_elements_DB (float): Matrix NS_DB x MAX_ELEMENTS with element indeces of the species contained in the database
% * FLAG_BURCAT (bool): Flag indicating to look for species also in Burcat's database
% * FLAG_ION (bool): Flag indicating to include ionized species
% * FLAG_CONDENSED (bool): Flag indicating to include condensed species
%
% Returns:
% Tuple containing
Expand All @@ -21,18 +22,22 @@
% * [LS, ind_elements_DB] = find_products(self, {'O2', 'N', 'eminus'})
% * [LS, ind_elements_DB] = find_products(self, {'O2', 'CO', 'N'}, 'flag_burcat', true)
% * [LS, ind_elements_DB] = find_products(self, {'O2', 'CO', 'N'}, 'flag_burcat', true, 'flag_ion', true)
% * [LS, ind_elements_DB] = find_products(self, {'O2', 'CO', 'N'}, 'flag_burcat', true, 'flag_ion', true, 'flag_condensed', true, 'ind', ind_elements_DB)
% * [LS, ind_elements_DB] = find_products(self, {'O2', 'CO', 'N'}, 'flag_burcat', true, 'flag_ion', true, 'ind', ind_elements_DB)


% Definitions
MAX_ELEMENTS = 5;
FLAG_BURCAT = self.S.FLAG_BURCAT; % Flag indicating to look for species also in Burcat's database
FLAG_ION = self.S.FLAG_ION; % Flag indicating to consider ionized species
FLAG_CONDENSED = self.S.FLAG_CONDENSED; % Flag indicating to consider condensed species
[elements, ~] = set_elements(); % Elements list

% Initialization
FLAG_IND = false; % Flag indicating that ind_elements_DB is an input
LS = []; % Initialize list of products

FLAG_IND = false; % Flag indicating that ind_elements_DB is an input
LS = []; % Initialize list of products
LS_DB = self.S.LS_DB; % Get list of species in the database

% Unpack
for i = 1:2:nargin-2
switch lower(varargin{i})
Expand All @@ -43,6 +48,8 @@
FLAG_BURCAT = varargin{i + 1};
case {'flag_ion', 'flag_ions'}
FLAG_ION = varargin{i + 1};
case {'flag_condensed'}
FLAG_CONDENSED = varargin{i + 1};
end

end
Expand All @@ -51,21 +58,47 @@
if FLAG_ION
species{end + 1} = 'eminus';
end
% If FLAG_BURCAT == true, then remove the species from Third millenium database

% If FLAG_BURCAT == false, then remove the species from Third millenium database (Burcat)
if ~FLAG_BURCAT
self.S.LS_DB = find_species_LS(self.S.LS_DB, {}, 'any', {'_M'}, 'all');
LS_DB = find_species_LS(LS_DB, {}, 'any', {'_M'}, 'all');

% If ind_elements_DB is given, now have to been recalculated
if FLAG_IND
FLAG_IND = false;
end

end


% If FLAG_CONDENSED == true, then include condensed species
if ~FLAG_CONDENSED
NS = length(LS_DB);
FLAG_REMOVE = false(NS, 1);
for i = 1:NS
if self.DB.(LS_DB{i}).phase == 1
FLAG_REMOVE(i) = true;
end

end

LS_DB(FLAG_REMOVE) = [];

% If ind_elements_DB is given, now have to been recalculated
if FLAG_IND
FLAG_IND = false;
end

end

% Get element indeces of the reactants
ind_elements_R = sort(get_ind_elements(species, self.DB, elements, MAX_ELEMENTS), 1);

% Get element indeces of each species in the database
if ~FLAG_IND
% Remove incompatible species
self.S.LS_DB(find_ind(self.S.LS_DB, 'Air')) = [];
LS_DB(find_ind(LS_DB, 'Air')) = [];
% Get element indeces of each species in the database
ind_elements_DB = get_ind_elements(self.S.LS_DB, self.DB, elements, MAX_ELEMENTS);
ind_elements_DB = get_ind_elements(LS_DB, self.DB, elements, MAX_ELEMENTS);
end

% Remove common vectors
Expand All @@ -80,7 +113,7 @@
% Get list of products
for i = length(ind_elements_R(:, 1)):-1:1
ind_species = all(ind_elements_DB - ind_elements_R(i, :) == 0, 2);
LS = [LS, self.S.LS_DB(ind_species)'];
LS = [LS, LS_DB(ind_species)'];
end

end
Expand Down
18 changes: 9 additions & 9 deletions utils/validations/set_inputs_thermo_validations.m
Expand Up @@ -16,39 +16,39 @@
case 'cp'
funname_NASA = @species_cP_NASA;
funname_CT = @species_cP;
y_labelname = 'Molar heat capacity at constant pressure [J/(mol-K)]';
y_labelname = '\rm{Molar\ heat\ capacity\ at\ constant\ pressure\ [J/(mol-K)]}';
case 'cv'
funname_NASA = @species_cV_NASA;
funname_CT = @species_cV;
y_labelname = 'Molar heat capacity at constant volume [J/(mol-K)]';
y_labelname = '\rm{Molar\ heat\ capacity\ at\ constant\ volume\ [J/(mol-K)]}';
case {'det', 'et'}
funname_NASA = @species_DeT_NASA;
funname_CT = @species_DeT;
y_labelname = 'Molar thermal internal energy [kJ/mol]';
y_labelname = '\rm{Molar\ thermal\ internal\ energy\ [kJ/mol]}';
case {'dht', 'ht'}
funname_NASA = @species_DhT_NASA;
funname_CT = @species_DhT;
y_labelname = 'Molar thermal enthalpy [kJ/mol]';
y_labelname = '\rm{Molar\ thermal\ enthalpy\ [kJ/mol]}';
case {'g0', 'g'}
funname_NASA = @species_g0_NASA;
funname_CT = @species_g0;
y_labelname = 'Molar Gibbs energy [kJ/mol]';
y_labelname = '\rm{Molar\ Gibbs\ energy\ [kJ/mol]}';
case {'h0', 'h'}
funname_NASA = @species_h0_NASA;
funname_CT = @species_h0;
y_labelname = 'Molar Enthalpy [kJ/mol]';
y_labelname = '\rm{Molar\ Enthalpy\ [kJ/mol]}';
case {'s0', 's'}
funname_NASA = @species_s0_NASA;
funname_CT = @species_s0;
y_labelname = 'Molar Entropy [kJ/(mol-K)]';
y_labelname = '\rm{Molar\ Entropy\ [kJ/(mol-K)]}';
case {'e', 'e0'}
funname_NASA = @species_e0_NASA;
funname_CT = @species_e0;
y_labelname = 'Internal energy [kJ/mol]';
y_labelname = '\rm{Internal\ energy\ [kJ/mol]}';
case {'gamma', 'gammas'}
funname_NASA = @species_gamma_NASA;
funname_CT = @species_gamma;
y_labelname = 'Adiabatic index [-]';
y_labelname = '\rm{Adiabatic\ index\ [-]}';
otherwise
error('There is not such property on files');
end
Expand Down

0 comments on commit f7dde42

Please sign in to comment.