BMayerChabotCollegeedu EngrMathPhysics 25 Chp10 SimuLink2 Learning Goals Implement Mathematical Operations in MATLAB using SimuLink Functional BlockIcons Employ FeedBack in the ID: 760169
Download Presentation The PPT/PDF document "Bruce Mayer, PE Licensed Electrical &..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Bruce Mayer, PELicensed Electrical & Mechanical EngineerBMayer@ChabotCollege.edu
Engr/Math/Physics 25
Chp10:
SimuLink-2
Slide2Learning Goals
Implement Mathematical Operations in MATLAB using
SimuLink
Functional
Block-Icons
Employ
FeedBack
in the
SimuLink
Environment to numerically Solve ODEs
Create Simulations of Dynamic Control Systems using
SimuLink
Block Models
Export
Simulation result to
MATLAB
WorkSpace
for Further Analysis
Slide3Problem 10.30
Make A subsystem Block for
It has been found that for many Valves the Flow Thru the valve is Related to the Pressure Drop
Inputs
q (kg/s)Pl & Pr (Pa)Rl & Rr ([ΔP]/[kg/s])
Using the Industry Constant of Proportionality, C
v
Slide4Problem 10.30
Cv is essentially the NonLinear Valve CONDUCTANCE
The Valve RESISTANCE then is simply the inverse of the C
v
Then the Flow Thru a typical On/Off Valve
Slide5Problem 10.30 (3)
To Account for potential BACK Flow under NEGATIVE ΔP Conditions use the Signed Square-Root Relation; the “SSR”
Where the SSR Fcn
Back to the Tank; ID the In-Flows Assuming Pr & Pl are Less than Pboti.e., There is OUTFLOW at the Left & Right
Slide6SSR Digression
The SSR fcn is BUILT into SimuLinkA Quick Example
The ResultFor This Problem We’ll Build our OWNSSR
plot(tout, Yin, tout,
Yssr
,
'
LineWidth
'
, 3),
xlabel
(
't'
),
ylabel
(
'9sin(t); SSR(10sin(t))'
), grid, legend(
'
sint
'
,
'SSR'
)
Slide7HomeMade SSR & test
Build Below from Scratch
Slide8Problem 10.30
The Tank Flows
Next the Time-Rate-of-Change of mT is just the difference between INflow & OUTflow; Mathematically
Now the Tank mass
m
T
Tank Mass (kg)
V Tank Volume (m
3
)
ρ
= Fluid Density (kg/m
3)
Problem 10.30
Now the OutFlows in Terms of the Fluid-Flow Resistances
p Pressure at the BOTTOM of the Tank (Pa)And From Fluid Mechanics
A NONlinear ODE in h(t)
Next, Sub into the dm
T
/dt eqn
Slide10Problem 10.30
Put the ODE into Integrable Form
If the Pressure in the Tank is greater than Outside
the tank, then the
ODE simplifies to
Slide11Problem 10.30
Using 1/R = Cv in the ODE
Use the SimuLink Integrator (1/s) on the Complicated Integrand to Find Note that is a ParaMeter (i.e., a number) within the Integrator Block
Problem 10.30
Now Make a SimuLink Model To Determine h(t)In This Case The Parameters will be VARIABLES with values Taken from the WORKSPACEThe Parameter List:
A
Tank Cross-Section Area
Assumed Circular (Cylindrical Tank)
R
l,r
Hydraulic Resistances of the LEFT & RIGHT Valves
ρ
Liquid Density
q
Liquid InFlow
h(0)
Liquid Height at t = 0
Slide13Parameters from WorkSpace
% Bruce Mayer, PE
% ENGR25 * 21Nov11
% file = P10_30_TankBLK_Model_Test_Input_Parameters_1111.m
% Use to TEST with SINGLE tank model%
%
A = 3;
%sf
q_in
= 0.7;
% slug/sec
rho = 1.94;
% slug/cu-
ft
h_0 = 4.3;
%
ft
g = 32.2;
%
ft
/
sq
-sec
R_l = 47; R_r = 71;
% valve resistances>
%
% copy-n-paste Plot Statement into Command Window
% plot(
tout,HofT
, '
LineWidth
', 3),
xlabel
('time (sec
)'),…
ylabel
('Liquid Height, h (
ft
)'), grid
Slide14Problem 10.30
Design a SimuLink Model to Solve for h(t) Given
Time For
Live Demo
Slide15Tank Model
Slide16Two-OutPut Single-Tank Model Test
SSR
Slide17Expected Result
By Scope
By Plot
Slide18Change Block Colors
Slide19Problem 10.30
Now make 3-port Tank Model SubSys
Use this SubSystem Model To Analyze a CASCADING Tank System
Need to Properly MAP the I/O to use
SubSys
Model in the
Casding
format
Slide20Map Model to 2-Tank Cascade
Need to Adapt this:
To This
=
=
Slide21Map Model to 2-Tank Cascade
Upper Tank-1 TransFormation Profile →Note also
n/a
n/a
Ref Only: Step Function Graph Code
% Bruce Mayer, PE
% MTH-15 • 29Dec16
% E25_Cascade_Tanks_qmi_Plot_BlueGreenBkGnd_161229.m
% REF: MTH15_Quick_Plot_BlueGreenBkGnd_130911.m
%
clear;
clc
; close;
%
clf
clears figure window
%
% This is a DISCRETE-point Plot
%
% The Domain Limits
xmin
= -3;
xmax
= 5;
% The FUNCTION **************************************
x = [-3, 0, 0, 5] ; y = [0, 0, 0.5, 0.5];
% ***************************************************
% the Plotting Range = 1.05*
FcnRange
<= Not used for discrete
pt
plot
ymin
= -0.11;
ymax
=0.61;
% the Range Limits
R = ymax - ymin; ymid = (ymax + ymin)/2;
ypmin = ymid - R/2; ypmax = ymid + R/2
% This Line NOT used in DISCRETE-Pt Plot
ypmin
=
ymid
- 1.025*R/2;
ypmax
=
ymid
+ 1.025*R/2
%
% The ZERO Lines
zxh
= [
xmin
xmax
];
zyh
= [0 0];
zxv
= [0 0];
zyv
= [
ypmin
ypmax
];
%
% the Plot
axes; set(gca,
'FontSize'
,12);
%
gca
stands for Get Current Axis
whitebg
([1 1 1])
% = White
BckGnd
•
whitebg
([0.8 1 1] = Blue-Green
plot(
x,y
,
'
LineWidth
'
, 4),grid, axis([
xmin
xmax
ypmin
ypmax
]),
...
xlabel
(
'\
fontsize
{14}t (sec)'
),
ylabel
(
'\
fontsize
{14}
q_m_i
= (slug/sec)'
),
...
title([
'\
fontsize
{16}Cascade-Tanks Mass-Flow
InPut
Profile'
,]),
...
annotation(
'textbox'
,[.15 .07 .0 .1],
'
FitBoxToText
'
,
'on'
,
'
EdgeColor
'
,
'none'
,
'String'
,
...
'E25 Cascade Tanks
qmi
Plot
BlueGreenBkGnd
161229.m'
,
'FontSize'
,7)
hold
on
plot(
zxv,zyv
,
'k'
,
zxh,zyh
,
'k'
,
'
LineWidth
'
, 2)
hold
off
Slide23Map Model to 2-Tank Cascade
Lower Tank-2 TransFormationDetermine by SSR+Cv Calculation
n/a
n/a
Slide24Map Model to 2-Tank Cascade
Lower Tank-2 TransFormation Detail
Final 2-Tank-Cascading Model
Result for Simulations
1200 SecondsBy Scope
300 SecondsBy Scope
Slide27½ Hour Simulation
Dip Due to
q2(t=0) = 0 Normal Time Lag
>> plot(tout,simout), xlabel('time (sec)'), ylabel('Liquid Height, h (ft)'),...grid
h2final = 6.4 ft
h1
final
= 3.6
ft
Slide28All Done for Today
Hoke DV1
DiaphramValve
Slide29Bruce Mayer, PELicensed Electrical & Mechanical EngineerBMayer@ChabotCollege.edu
Engr/Math/Physics 25
Appendix
Time For
Live Demo
Time For
WhtBd Demo
Slide30May17
May17
Slide31May17
Double
Click
to Open
Slide32Prob 10.30 (1)
INPORT Block for Rt & Lt Pressure ValuesInport Create an input port for a subsystem or an external input Library → Ports & Subsystems, SourcesChg Label, No Parameters
Summing Bloks for Rt & Lt
Δ
P’s = P-P
l,r
Sum
Add or subtract inputs
Library
→ Math Operations
Painful RePosition of “+” & “-” connection Locations
Top Node = |-+
Bot Node = +-|
Slide33Prob 10.30 (2)
Fcn Blok for SSR Fcn Apply a specified expression to the input Library → User-Defined FunctionsNeed to Implement for u = ΔP
Parameters for Fcn
Slide34Prob 10.30 (3)
Gain Bloks for Hydraulic ResistancesGain Multiply the input by a constant Library → Math OperationsResistance Values will come from Variables Defined in WORKSPACE
Slide35Prob 10.30 (4)
Now
INport Blok for InflowClick on Block, and Use FORMAT to Flip & Twist Block
Sum the OUTflow = q
l
+ qr
+|+
|−+
+−|
Slide36Prob 10.30 (5)
Then the NET INflow = q - (ql + qr)
Parameters for Scaling Gain-Blok
Now Scale Net InFlow by 1/
ρ
A
ρ
& A
values set in WorkSpace
GainBlok OutPut is the INTEGRAND
Slide37Prob 10.30 (6)
Integrate using 1/s Block to Find h(t)Integrator Integrate a signal Library → ContinuousThe Integrator ParametersSet IC, H(t=0) as VARIABLE h0 assigned in WorkSpace
Integrator Parameters
Slide38Prob 10.30 (7)
Scale h(t) to Determine Pressure at the Bottom of the Tank, P
FeedBack P to Pl & Pr to find the ΔP’s
Slide39Prob 10.30 (8)
Use OUTPORTs To pick off h(t) & POutport Create an output port for a subsystem or an external output Library → Ports & Subsystems, Sinks The Final Model
Slide40Prob 10.30 (9)
Test the model with some realistic Values taken from Work SpaceNeed to apply SOURCES to the Inputs
>> A = 3; %sf
>> q_in = 0.7; % slug/sec>> rho = 1.94; % slug/cu-ft>> h_0 = 4.3; % ft
>> g = 32.2; %ft/sq-sec>> R_l = 47; R_r = 71; % valve resistances>>
P9_30_TankBLK_Model_Test_Input_Parameters_0905.m
Slide41Prob 10.30 (9a)
Parameters for STEP-Block are CRITICALLY important to obtaining the Correct Answer in the Tank-Model Test
Slide42Prob 10.30 (10)
The Result from the Scope
Looks OK … can forge ahead
Slide43Prob 10.30 (11)
Make the Model into a SUBSYSTEMSelect All Components with Bounding Box
Slide44Prob 10.30 (12)
Use Menus: DIAGRAM → SUBSYTEM & MODLE Reference → CREATE SUBSYSTEM FROM SELECTION
Slide45Prob 10.30 (13)
ReSize SubSys Blok for Readability
Move Blok w/ Mouse & Cursor Keys
Flip & Twist InFlow Blok
Increase Font Size
using Format Menu
Slide46Prob 10.30 (14)
Copy & Paste TWICE the SubSys Block into file Prob9_30_Cascade_Tank.mdl
The Cascade Model after the Pastes
Slide47Prob 10.30 (15)
Use CONSTANT blok to set Atmospheric pressures to ZEROConstant Generate a constant value Library → Sources The Parameters For CONSTANT Blok
Slide48Prob 10.30 (16)
Delete Pressure INPORTS and replace w/ Patm = 0
2x Click the SubSys block to expose its contents
COPY the SSR and R Gain-Blok from the SubSys Window
Slide49Prob 10.30 (17)
PASTE the SSR and R Gain-Blok in Cascade-Tank Mdl
Flip the SSR & Gain BlocksReset the Gain to 1/R1
Slide50Prob 10.30 (18)
Convert Pb1 to q1 using Cv1 = 1/R1Connect q1 to InFlow Port on Tank2 subsys
Slide51Prob 10.30 (19)
Now Use STEP block for qmi Step Generate a step function Library → Sources The Parameters for the step blok
Slide52Prob 10.30 (20)
Document Heights by MUXing height Outputs to ScopeMUX BlockMux Combine several input signals into a vector or bus output signal Library → Signal Routing
Scope Block
Scope, Floating Scope, Signal Viewer Scope
Display signals generated during a simulation
Library
→ Sinks
Prob 10.30 (21)
InterConnects Completed
Now Need to Edit INSIDE SubSys block for new Variable Names
Slide54Prob 10.30 (22)
Edit Values in Tank1 SubSys
Slide55Prob 10.30 (23)
Edit Values in Tank1 SubSys
Slide56Prob 10.30 (24)
Edit Values in Tank1 SubSysBe Sure to Change the INITIAL CONDITIONSomewhat Hidden in the 1/s block
Slide57Prob 10.30 (25)
Edit Values in Tank2 SubSys
Slide58Prob 10.30 (26)
Edit Values in Tank2 SubSys
Slide59Prob 10.30 (27)
Edit Values in Tank2 SubSysBe Sure to Change the INITIAL CONDITIONSomewhat Hidden in the 1/s block
Slide60Prob 10.30 (28)
Simulate for 1hr = 3600 seconds
Simulate for 1hr = 3600 seconds
Slide61Prob 10.30 (29) To WorkSpace
Prob9_30_Cascade_Tank_ToWorkSpace.mdl
Note: SimOut Sends Tank Heights ONLY to WorkSpace
tout
is AutoMatically sent to WorkSpace by SimuLink
Slide62Test Values to paste into WkSpc
A = 3q_in = .7rho = 1.94h_0 = 4.3g = 32.2R_l = 47R_r = 71
For Model Test
For Cascade Test
A1 = 3; % sq-ftA2 = 5; % sq-ftg = 32.2; %ft/sq-secR1 = 30;R2 = 40;rho = 1.94; % slug/cu-ftq_mi = 0.5; % slug/sech1_0 = 2; % fth2_0 = 5; % ft
P9_30_TankSYS_Model_Input_Parameters_0712.m
Slide63MALAB 2010 has Built in SSR
Slide64Tank Model & Test
Slide65Parameters for q_in on Test
Step Time MUST be Zero
Slide66Parameters in m-file
% Bruce Mayer, PE
% ENGR25 * 21Nov11
% file = P10_30_Model_Input_Parameters_1111.m
% for use with files
%* Prob10_30_3port_Tank_SubSys_TEST_1111.mdl
%* Prob10_30_Cascade_Tank_1111.mdl
%
%
clc
disp
(
'
SubSys
Test parameters'
)
A =3
q_in
= 0.7
rho = 1.94
h_0 = 4.3
g = 32.2
R_l
= 47
R_r
= 71
disp
(
' '
)
%
disp
(
' '
)
disp
(
' Dual Tank Full-Systems Test Parameters'
)
A1 = 3
A2 = 5
R1 = 30
R2 = 40
rho = 1.94
q_mi
= 0.5
h1_0 = 2
h2_0 = 5
%
% copy-n-paste Plot Statement into Command Window
% plot(
tout,hOFt
),
xlabel
('time (sec)'),
ylabel
('Liquid Height, h (
ft
)'), grid
%
% TRY ALSO:
q_mi
= .45 &
TimeSim
=
1000
Slide671304 SubSys Design1304
P10_30_TankModel_SubSys_1304.mdl
Slide681304 Subsys Test 1304
P10_30_TankModel_Test_1304.mdl
Slide69Tank Cascade 1304
Slide70Final Model
P10_30_2TankSystem_1611.slx
Slide71P9-30 Notes Pg-1
Slide72P9-30 Notes Pg-2
Slide73P9-30 Notes Pg-3
Slide74Using a Fixxed Step Size
Apr07
No. of Time Pts appears to max out at 1000
Slide75Cascading Tanks
Slide76Cascading Tanks
Slide77Final Model