ENGR-25_Lec-25_SimuLink-2.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer Engr/Math/Physics 25 Chp9: SimuLink-2
ENGR-25_Lec-25_SimuLink-2.ppt 2 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Learning Goals Implement Mathematical Operations in MATLAB using SimuLink Functional Blocks 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
ENGR-25_Lec-25_SimuLink-2.ppt 3 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Problem 9.30 (1) 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) P l & P r (Pa) R l & R r ([ ΔP]/[kg/s]) Using the Industry Constant of Proportionality, C v
ENGR-25_Lec-25_SimuLink-2.ppt 4 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Problem 9.30 (2) C v 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
ENGR-25_Lec-25_SimuLink-2.ppt 5 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Problem 9.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 P r & P l are Less than P bot i.e., There is OUTFLOW at the Left & Right
ENGR-25_Lec-25_SimuLink-2.ppt 6 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Problem 9.30 (4) The Tank Flows Next the Time-Rate- of-Change of m T 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 )
ENGR-25_Lec-25_SimuLink-2.ppt 7 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Problem 9.30 (5) 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
ENGR-25_Lec-25_SimuLink-2.ppt 8 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Problem 9.30 (6) Put the ODE into Integrable Form If the Pressure in the Tank is greater than Outside the ODE simplifies to
ENGR-25_Lec-25_SimuLink-2.ppt 9 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Problem 9.30 (6a) Using 1/R = C v in the ODE Use the SimuLink Integrator (1/s) on the Complicated Integrand to Find h(t) Note that h(0) is a ParaMeter (i.e., a number) within the Integrator Block
ENGR-25_Lec-25_SimuLink-2.ppt 10 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Problem 9.30 (7) Now Make a SimuLink Model To Determine h(t) In This Case The Parameters will be VARIABLES with values Taken from the WORKSPACE The 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
ENGR-25_Lec-25_SimuLink-2.ppt 11 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Problem 9.30 (8) Design a SimuLink Model to Solve for h(t) Given
ENGR-25_Lec-25_SimuLink-2.ppt 12 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Problem 9.30 (9) Now have 3-port Tank Model Use this SubSystem Model To Analyze a CASCADING Tank System Need to Properly MAP the I/O to use SubSys Mdl
ENGR-25_Lec-25_SimuLink-2.ppt 13 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Final Model
ENGR-25_Lec-25_SimuLink-2.ppt 14 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Result for 1hr Simulation
ENGR-25_Lec-25_SimuLink-2.ppt 15 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods ½ Hour Simulation Dip Due to q2(t=0) =0 Normal Time Lag >> plot(tout,simout), xlabel('time (sec)'), ylabel('Liquid Height, h (ft)'),... grid h2 final = 6.4 ft h1 final = 3.6 ft
ENGR-25_Lec-25_SimuLink-2.ppt 16 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods All Done for Today Hoke DV1 Diaphram Valve
ENGR-25_Lec-25_SimuLink-2.ppt 17 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer Engr/Math/Physics 25 Appendix
ENGR-25_Lec-25_SimuLink-2.ppt 18 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (1) INPORT Block for Rt & Lt Pressure Values Inport Create an input port for a subsystem or an external input Library → Ports & Subsystems, Sources Chg 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 = +-|
ENGR-25_Lec-25_SimuLink-2.ppt 19 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (2) Fcn Blok for SSR Fcn Apply a specified expression to the input Library → User- Defined Functions Need to Implement for u = ΔP Parameters for Fcn
ENGR-25_Lec-25_SimuLink-2.ppt 20 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (3) Gain Bloks for Hydraulic Resistances Gain Multiply the input by a constant Library → Math Operations Resistance Values will come from Variables Defined in WORKSPACE
ENGR-25_Lec-25_SimuLink-2.ppt 21 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (4) Now INport Blok for Inflow Click on Block, and Use FORMAT to Flip & Twist Block Sum the OUTflow = q l + q r +|+ |−+ +−|
ENGR-25_Lec-25_SimuLink-2.ppt 22 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (5) Then the NET INflow = q - (q l + q r ) Parameters for Scaling Gain-Blok Now Scale Net InFlow by 1/ρA ρ & A values set in WorkSpace GainBlok OutPut is the INTEGRAND
ENGR-25_Lec-25_SimuLink-2.ppt 23 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (6) Integrate using 1/s Block to Find h(t) Integrator Integrate a signal Library → Continuous The Integrator Parameters Set IC, H(t=0) as VARIABLE h0 assigned in WorkSpace Integrator Parameters
ENGR-25_Lec-25_SimuLink-2.ppt 24 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (7) Scale h(t) to Determine Pressure at the Bottom of the Tank, P FeedBack P to P l & P r to find the ΔP’s
ENGR-25_Lec-25_SimuLink-2.ppt 25 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (8) Use OUTPORTs To pick off h(t) & P Outport Create an output port for a subsystem or an external output Library → Ports & Subsystems, Sinks The Final Model
ENGR-25_Lec-25_SimuLink-2.ppt 26 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (9) Test the model with some realistic Values taken from Work Space Need 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
ENGR-25_Lec-25_SimuLink-2.ppt 27 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (9a) Parameters for STEP-Block are CRITICALLY important to obtaining the Correct Answer in the Tank- Model Test
ENGR-25_Lec-25_SimuLink-2.ppt 28 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (10) The Result from the Scope Looks OK … can forge ahead
ENGR-25_Lec-25_SimuLink-2.ppt 29 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (11) Make the Model into a SUBSYSTEM Select All Components with Bounding Box
ENGR-25_Lec-25_SimuLink-2.ppt 30 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (12) Use Menus: EDIT → CREATE SUBSYTEM
ENGR-25_Lec-25_SimuLink-2.ppt 31 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (13) ReSize SubSys Blok for Readability Move Blok w/ Mouse & Cursor Keys Flip & Twist InFlow Blok Increase Font Size using Format Menu
ENGR-25_Lec-25_SimuLink-2.ppt 32 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (14) Copy & Paste TWICE the SubSys Block into file Prob9_30_Cascade _Tank.mdl The Cascade Model after the Pastes
ENGR-25_Lec-25_SimuLink-2.ppt 33 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (15) Use CONSTANT blok to set Atmospheric pressures to ZERO Constant Generate a constant value Library → Sources The Parameters For CONSTANT Blok
ENGR-25_Lec-25_SimuLink-2.ppt 34 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (16) Delete Pressure INPORTS and replace w/ P atm = 0 2x Click the SubSys block to expose its contents COPY the SSR and R Gain-Blok from the SubSys Window
ENGR-25_Lec-25_SimuLink-2.ppt 35 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (17) PASTE the SSR and R Gain-Blok in Cascade-Tank Mdl Flip the SSR & Gain Blocks Reset the Gain to 1/R1
ENGR-25_Lec-25_SimuLink-2.ppt 36 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (18) Convert Pb1 to q1 using Cv1 = 1/R1 Connect q1 to InFlow Port on Tank2 subsys
ENGR-25_Lec-25_SimuLink-2.ppt 37 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (19) Now Use STEP block for q mi Step Generate a step function Library → Sources The Parameters for the step blok
ENGR-25_Lec-25_SimuLink-2.ppt 38 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (20) Document Heights by MUXing height Outputs to Scope MUX Block Mux 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
ENGR-25_Lec-25_SimuLink-2.ppt 39 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (21) InterConnects Completed Now Need to Edit INSIDE SubSys block for new Variable Names
ENGR-25_Lec-25_SimuLink-2.ppt 40 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (22) Edit Values in Tank1 SubSys
ENGR-25_Lec-25_SimuLink-2.ppt 41 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (23) Edit Values in Tank1 SubSys
ENGR-25_Lec-25_SimuLink-2.ppt 42 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (24) Edit Values in Tank1 SubSys Be Sure to Change the INITIAL CONDITION Somewhat Hidden in the 1/s block
ENGR-25_Lec-25_SimuLink-2.ppt 43 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (25) Edit Values in Tank2 SubSys
ENGR-25_Lec-25_SimuLink-2.ppt 44 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (26) Edit Values in Tank2 SubSys
ENGR-25_Lec-25_SimuLink-2.ppt 45 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (27) Edit Values in Tank2 SubSys Be Sure to Change the INITIAL CONDITION Somewhat Hidden in the 1/s block
ENGR-25_Lec-25_SimuLink-2.ppt 46 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.30 (28) Simulate for 1hr = 3600 seconds
ENGR-25_Lec-25_SimuLink-2.ppt 47 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Prob 9.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
ENGR-25_Lec-25_SimuLink-2.ppt 48 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Test Values to paste into WkSpc A = 3 q_in =.7 rho = 1.94 h_0 = 4.3 g = 32.2 R_l = 47 R_r = 71 For Model Test For Cascade Test A1 = 3; % sq-ft A2 = 5; % sq-ft g = 32.2; %ft/sq-sec R1 = 30; R2 = 40; rho = 1.94; % slug/cu-ft q_mi = 0.5; % slug/sec h1_0 = 2; % ft h2_0 = 5; % ft P9_30_TankSYS_Model_Input_Parameters_0712.m
ENGR-25_Lec-25_SimuLink-2.ppt 49 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods MALAB 2010 has Built in SSR
ENGR-25_Lec-25_SimuLink-2.ppt 50 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Tank Model & Test
ENGR-25_Lec-25_SimuLink-2.ppt 51 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Parameters for q_in on Test Step Time MUST be Zero
ENGR-25_Lec-25_SimuLink-2.ppt 52 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Parameters in m-file
ENGR-25_Lec-25_SimuLink-2.ppt 53 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods P9-30 Notes Pg-1
ENGR-25_Lec-25_SimuLink-2.ppt 54 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods P9-30 Notes Pg-2
ENGR-25_Lec-25_SimuLink-2.ppt 55 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods P9-30 Notes Pg-3
ENGR-25_Lec-25_SimuLink-2.ppt 56 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Using a Fixxed Step Size Apr07 No. of Time Pts appears to max out at 1000
ENGR-25_Lec-25_SimuLink-2.ppt 57 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Cascading Tanks
ENGR-25_Lec-25_SimuLink-2.ppt 58 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Cascading Tanks