Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Homework #7

November 11, 2021


CHE 492 - Computer Methods in Chemical Engineering - Dr. Jason Bara
Done By: Bader Alghamdi

1. Objective:
This problem asks to develop an app useful for chemical engineers. MATLAB App Designer
is used to develop an app that helps in the study of a simple heat exchanger design and
provides the user with interactive cells for design inputs as well as data calculation and visual
representation of the design outputs throughout a graph. A statement showing the successful
or unsuccessful execution of the test run’s calculation.

2. Methods:
The app is designed in such a way that enables the user to input the overall heat transfer
coefficient “U”, the heat flow area “A”, and the log mean temperature difference “LMTD”.
An if statement is used to check whether the value of the input parameters are within
logical engineering range standards. If the values inserted into the input cells were within
acceptable range, pressing the Plot button would perform algorithmic calculations involved
in the design of the heat exchanger as follows:

Q=U∗HEAT EXCHANGER AREA∗LMTD

Q
HEAT EXCHANGER AREA =
U∗LMTD

The heat exchanger area (y-axis) is then plotted vs the overall heat transfer Q (x-axis) using
the plot function and a statement representing the successful calculation is shown.
However, if these inputs were out of range, a Retry button and error statement would
appear by using the app.RetryButton.Visible='on' and
app.Error.Visible='on' statements respectively. After the Retry button is pushed its
visibility is set to 'off' as well as the error statement while the Plot button is turned back
'on'. The design view of the app can be seen in Figure 1 below. The full MATALAB script
of the app created to study a simple design of a heat exchanger can be found in Appendix A.
1

Figure 1. Design view of the app created to study a simple design of a heat exchanger

3. Results:
I ran the app through several trials and tested a variety of inputs that a chemical engineer
would provide. The app ran flawlessly where it provided the user with correct results when
the inputs were right and directed him to reconfigure his inputs if they were out of logical
range. I performed two test runs that can be seen in Figures 2 and 3 below; the first
representing a successful run and the second representing an unsuccessful one.

Figure 2. Successful test run of the app


2

Figure 3. Unsuccessful test run of the app with invalid inputs

Figure 2 represents a successful run of the app where all the inputs are valid and have a positive
value. On the other hand, Figure 3 represent an unsuccessful run of the app where the heat flow
area has a negative value. The Retry button appears in this run as can be seen in Figure 3 above.

4. Discussion
The app delivered satisfactory results considering its preliminary design level. However, further
development can be made to this app by introducing several heat exchanger design parameters
such as pressure drops and heat exchanger type. Such design would require further inputs and
more complex coding but would provide the user with more reliable results saving time and effort
and contributing to the development and advancement of the chemical industry and technology.
3
New Question:
Create an application to help user in the configuration of a rigorous chemical reactor design.
4

Appendix A
A.1: Full script of the app used to study a simple design of a heat
exchanger.

A.1: Full script of the app used to study a simple design of a heat exchanger:
classdef heatexchanger < matlab.apps.AppBase

% Properties that correspond to app components


properties (Access = public)
UIFigure matlab.ui.Figure
GridLayout matlab.ui.container.GridLayout
LeftPanel matlab.ui.container.Panel
PlotButton matlab.ui.control.Button
HeatFlowAreaAEditFieldLabel matlab.ui.control.Label
HeatFlowAreaAEditField matlab.ui.control.NumericEditField
OverallheattransferUEditFieldLabel matlab.ui.control.Label
OverallheattransferUEditField matlab.ui.control.NumericEditField
LMTDEditFieldLabel matlab.ui.control.Label
LMTDEditField matlab.ui.control.NumericEditField
UIAxes matlab.ui.control.UIAxes
labelLabel matlab.ui.control.Label
HEATEXCHANGERCALCULATIONLabel matlab.ui.control.Label
Error matlab.ui.control.Label
RetryButton matlab.ui.control.Button
RightPanel matlab.ui.container.Panel
end

% Properties that correspond to apps with auto-reflow


properties (Access = private)
onePanelWidth = 576;
end

% Callbacks that handle component events


methods (Access = private)

% Code that executes after component creation


function startupFcn(app)
app.RetryButton.Visible=’off’;
app.Error.Visible=’off’;
end
1A

% Button pushed function: PlotButton


function PlotButtonPushed(app, event)
U=app.OverallheattransferUEditField.Value; %for input of U
A=app.HeatFlowAreaAEditField.Value; %for input of A
LMTD=app.LMTDEditField.Value; %for input of LMTD
Q= (U.*A.*LMTD); %for formula of heat exchanger
Y=([Q./U*LMTD]); % CALCULATION
plot(app.UIAxes,Q,Y) %plot graph
%%%%%%%%%%%%
a= [Q,Q+Y,Q+Y,Q];
b=[0,0,1,Y];
c=find(Q>Q,1,"first");
if Y(c)>Y & Y(end)<Y
patch(app.UIAxes,a,b,'Green') %draw green patch
app.labelLabel.Text="Graph is shown"; %display message
else
patch(app.UIAxes,a,b,'Green')
app.labelLabel.Text="Graph is shown";
end

end

% Value changed function: OverallheattransferUEditField


function OverallheattransferUEditFieldValueChanged(app, event)
value = app.OverallheattransferUEditField.Value;
if value<0
app.RetryButton.Visible='on';
app.RetryButton.Visible='on';
app.Error.Visible='on';
end
end

% Value changed function: HeatFlowAreaAEditField


function HeatFlowAreaAEditFieldValueChanged(app, event)
value = app.HeatFlowAreaAEditField.Value;
if value<0
app.RetryButton.Visible='on';
app.Error.Visible='on';
app.PlotButton.Enable='off';
end
end

% Button pushed function: RetryButton


function RetryButtonPushed(app, event)
2A

app.RetryButton.Visible='off';
app.Error.Visible='off';
app.PlotButton.Enable='on';
end

% Changes arrangement of the app based on UIFigure width


function updateAppLayout(app, event)
currentFigureWidth = app.UIFigure.Position(3);
if(currentFigureWidth <= app.onePanelWidth)
% Change to a 2x1 grid
app.GridLayout.RowHeight = {594, 594};
app.GridLayout.ColumnWidth = {'1x'};
app.RightPanel.Layout.Row = 2;
app.RightPanel.Layout.Column = 1;
else
% Change to a 1x2 grid
app.GridLayout.RowHeight = {'1x'};
app.GridLayout.ColumnWidth = {1014, '1x'};
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
end
end
end

% Component initialization
methods (Access = private)

% Create UIFigure and components


function createComponents(app)

% Create UIFigure and hide until all components are created


app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.AutoResizeChildren = 'off';
app.UIFigure.Position = [100 100 1026 594];
app.UIFigure.Name = 'MATLAB App';
app.UIFigure.SizeChangedFcn = createCallbackFcn(app, @updateAppLayout, true);

% Create GridLayout
app.GridLayout = uigridlayout(app.UIFigure);
app.GridLayout.ColumnWidth = {1014, '1x'};
app.GridLayout.RowHeight = {'1x'};
app.GridLayout.ColumnSpacing = 0;
app.GridLayout.RowSpacing = 0;
app.GridLayout.Padding = [0 0 0 0];
3A

app.GridLayout.Scrollable = 'on';

% Create LeftPanel
app.LeftPanel = uipanel(app.GridLayout);
app.LeftPanel.Layout.Row = 1;
app.LeftPanel.Layout.Column = 1;

% Create PlotButton
app.PlotButton = uibutton(app.LeftPanel, 'push');
app.PlotButton.ButtonPushedFcn = createCallbackFcn(app, @PlotButtonPushed, true);
app.PlotButton.Position = [292 180 100 22];
app.PlotButton.Text = 'Plot';

% Create HeatFlowAreaAEditFieldLabel
app.HeatFlowAreaAEditFieldLabel = uilabel(app.LeftPanel);
app.HeatFlowAreaAEditFieldLabel.HorizontalAlignment = 'right';
app.HeatFlowAreaAEditFieldLabel.Position = [167 296 110 22];
app.HeatFlowAreaAEditFieldLabel.Text = 'Heat Flow Area = A';

% Create HeatFlowAreaAEditField
app.HeatFlowAreaAEditField = uieditfield(app.LeftPanel, 'numeric');
app.HeatFlowAreaAEditField.ValueChangedFcn = createCallbackFcn(app,
@HeatFlowAreaAEditFieldValueChanged, true);
app.HeatFlowAreaAEditField.Position = [292 296 100 22];

% Create OverallheattransferUEditFieldLabel
app.OverallheattransferUEditFieldLabel = uilabel(app.LeftPanel);
app.OverallheattransferUEditFieldLabel.HorizontalAlignment = 'right';
app.OverallheattransferUEditFieldLabel.Position = [144 352 133 22];
app.OverallheattransferUEditFieldLabel.Text = 'Overall heat transfer =U';

% Create OverallheattransferUEditField
app.OverallheattransferUEditField = uieditfield(app.LeftPanel, 'numeric');
app.OverallheattransferUEditField.ValueChangedFcn = createCallbackFcn(app,
@OverallheattransferUEditFieldValueChanged, true);
app.OverallheattransferUEditField.Position = [292 352 100 22];

% Create LMTDEditFieldLabel
app.LMTDEditFieldLabel = uilabel(app.LeftPanel);
app.LMTDEditFieldLabel.HorizontalAlignment = 'right';
app.LMTDEditFieldLabel.Position = [239 235 38 22];
app.LMTDEditFieldLabel.Text = 'LMTD';
4A

% Create LMTDEditField
app.LMTDEditField = uieditfield(app.LeftPanel, 'numeric');
app.LMTDEditField.Position = [292 235 100 22];

% Create UIAxes
app.UIAxes = uiaxes(app.LeftPanel);
title(app.UIAxes, 'Graph')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [545 89 403 350];

% Create labelLabel
app.labelLabel = uilabel(app.LeftPanel);
app.labelLabel.Position = [545 16 279 41];
app.labelLabel.Text = 'label';

% Create HEATEXCHANGERCALCULATIONLabel
app.HEATEXCHANGERCALCULATIONLabel = uilabel(app.LeftPanel);
app.HEATEXCHANGERCALCULATIONLabel.HorizontalAlignment = 'center';
app.HEATEXCHANGERCALCULATIONLabel.FontName = 'Baskerville Old Face';
app.HEATEXCHANGERCALCULATIONLabel.FontSize = 30;
app.HEATEXCHANGERCALCULATIONLabel.FontWeight = 'bold';
app.HEATEXCHANGERCALCULATIONLabel.FontColor = [1 0 0];
app.HEATEXCHANGERCALCULATIONLabel.Position = [104 508 720 37];
app.HEATEXCHANGERCALCULATIONLabel.Text = 'HEAT EXCHANGER
CALCULATION';

% Create Error
app.Error = uilabel(app.LeftPanel);
app.Error.Position = [167 102 203 22];
app.Error.Text = 'The value you input are inacceptable';

% Create RetryButton
app.RetryButton = uibutton(app.LeftPanel, 'push');
app.RetryButton.ButtonPushedFcn = createCallbackFcn(app,
@RetryButtonPushed, true);
app.RetryButton.Position = [208 68 100 22];
app.RetryButton.Text = 'Retry';

% Create RightPanel
app.RightPanel = uipanel(app.GridLayout);
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
5A

% Show the figure after all components are created


app.UIFigure.Visible = 'on';
end
end

% App creation and deletion


methods (Access = public)

% Construct app
function app = heatexchanger

% Create UIFigure and components


createComponents(app)

% Register the app with App Designer


registerApp(app, app.UIFigure)

% Execute the startup function


runStartupFcn(app, @startupFcn)

if nargout == 0
clear app
end
end

% Code that executes before app deletion


function delete(app)

% Delete UIFigure when app is deleted


delete(app.UIFigure)
end
end
end
6A

You might also like