Dynamic modeling of a non-isothermal CSTR Raymond B Cyiza Robotics and Cybernetics Applied Computer Information Technology Oslo, Norway s326055@oslomet.no Abstract—A nonlinear model dynamic model of a nonisothermal continuous stirred tank reactor was developed. The model has two output variables and four input variables. The nonlinear model was linearized using Taylor series expansion. Four experiments were designed around the operating point with step changes in the input variables. The performance of the linear model was compared to the nonlinear model using the integral of absolute error. None of the performance from the linear model to step changes in cooling medium temperature Tc, inlet temperature Ti, inlet composition cAi and inlet flow rate q can used future control purposes, since it was suspected that the composed transfer function matrix inside the simulink process was perceived to be incorrect. Also each of the performances of the linear model to all step changes showed wrong direction and magnitude, which would not be acceptable for further use. A system identification approach was done in order to develop linear models with better fitness criteria. Keywords—first principles modeling, linearization, step responses, integral error criteria, continuous stirred tank reactor, systemidentification toolbox B. Schematic diagram of the process and list of symbols Figure 1.A non-isothermal continuous stirred-tank reactor. The constants and variables of the process are given in Table I List of symbols. TABLE I. I. INTRODUCTION The aim of Assignment 2 is to develop linear transfer function models based on the non-linear, non-isothermal continuous stirred tank reactor developed in Assignment1. First, the data collection experiments are designed. Then, the data is collected from the nonlinear model implemented in Simulink for 4 input variables and 2 output variables. The four data sets are imported to SystemIdentification toolbox transfer function models are identified between the input variables and output variables. The best models are exported to Simulink and compared with the nonlinear model in Simulink. This article addresses the following questions: Can the linear model be used for control studies? Is the dynamic behavior of the linear model similar to the dynamic behavior of the non-linear model? II. SYSTEMATIC APPROACH FOR DEVELOPING DYNAMIC Symbol ππ ππ΄π π(0) Nom.value Temperature in K 350 Component A in mol/L 1 K 350 g/L 1000 mol/l 0.5 Component A π Volume L 100 π Flow rate L/min 100 Heat of reaction per mole J/mol 5*10^4 K 8750 J/min K 5*10^4 min^-1 7.2*10^10 K 300 j/g K 0.239 −βπ»π πΈ/π π/A π0 Systematic approach for developing dynamic models, presented in Chapter 2.2. in (Seborg, Edgar, Mellichamp, & Doyle, 2017) will be used to develop the models. πΆ ACIT4810 Assignment2 2020 ©tiina.komulainen@oslomet.no Unit Density ππ΄ (0) ππ (0) The end use is to compare the best data models exported from SystemIdentification toolbox with the non-linear model Simulink. Description Temperature in tank π MODELS A. Modeling objectives and end use The model’s objective is to create a dynamic model based on the non-linear, non-isothermal continuous stirred tank reactor developed in Assignment1. LIST OF SYMBOLS Activation of energy/gas constant Overall heat transfer coefficient/heat transfer area Frequency factor Cooling medium temperature Heat capacity C. Assumptions 1. The CSTR has perfect mixing → πππ’π‘ = ππ‘πππ (π) 2. Density and heat capacity C of the liquid are constant in the tank, this means that temperature dependence is negligible 3. The liquid hold-up volume π is kept constant by an overflow line → ππ΄π = ππ΄ 4. The thermal capacitances of the coolant and the cooling coil wall are negligible compared to the thermal capacitance of the liquid in the tank. 5. The increase in coolant temperature as the coolant passes through the coil is neglected 6. The overall heat transfer coefficient π and the heat transfer area π΄ are assumed to be constant. The rate of heat transfer from the reactor contents to the coolant is given by π = ππ΄(ππ − π) 8. Shaft work and heat losses to the ambient can be neglected. 1) The nonlinear model The non-isothermal tank reactor is described in Chapter 2.4.6 and Example 2.5 in (Seborg, Edgar, Mellichamp, & Doyle, 2017). ππ ππ‘ = π(ππ −π) π = + π(ππ΄π −ππ΄ ) π ππ΄(ππ −π) πππΆ − ππ΄ π0 π−πΈ/π π (2) + πππ΄ ′(π‘) ππ‘ ′ (π‘) = π11 ππ΄′ (π‘) + π12 π ′ (π‘) + π13 π′ (π‘) + π14 ππ΄π (4) Where: π11 = (−πΜ /π − π_0 π^(−πΈ/(π πΜ )) ) The heat mixing is negligible compared to the heat of reaction. ππ‘ Component A: The linearized equation for concentration of component A. Notice the variables denoted with ‘ are deviation variables from steady state marked with Μ . ππ(1) 7. πππ΄ π ′ = π − πΜ (−βπ»π )ππ΄ π0 π−πΈ/π π πΆπ (3) π12 = (− Μ Μ Μ Μ πΈk cA 0 e RπΜ 2 E − Μ Rπ ) ππ΄i − ππ΄ ) V qΜ π14 = v π13 = ( Energy: The linearized equation for temperature in tank T. Notice the variables denoted with ‘are deviation variables from steady state marked with Μ . ππ′(π‘) = π21 π′π΄ (π‘) + π22 π ′ (π‘) + π25 π′ (π‘) + π23 ππ′ (π‘) + π24 ππ′ (π‘) (5) ππ‘ Where: D. Degrees of freedom analysis (−βπ»π k 0 e π21 = Listing all the quantities: 9Constant parameters: π, π, πΆ, π , πΈ, π0 , π, π΄, βπ»π π22 E − Μ Rπ ) ππΆ (−βπ»π )πcΜ Μ Μ πΈk 1 A 0e = [−(πΜ ππΆ + ππ΄) + πππΆ RπΜ 2 E − Μ Rπ ] ππ΄ πππΆ πΜ = π π23 = 6Variables: π, ππ΄ , ππ , π, ππ΄π , ππ 2Equations:ππ(2)πππ ππ(3) Identifying ππΈ and ππ : Number of equations: ππΈ = 2 Number of variables: ππ = 6 Degrees of freedom ππΉ : ππΉ = ππ −ππΈ = 6 − 2 = 4 Identifying the output variables: Controlled output variables: π, temperature in the tank and ππ΄ ,component A Identifying the input variables: ππ , ππ΄π , π E. Simplify the ODEs and linearize the model Define deviation variables, ππ΄′ = ππ΄ − πΜ π΄ π ′ = π − πΜ ππ′ = ππ − πΜ π ′ ππ΄π = ππ΄π − Μ Μ ππ΄π Μ Μ ππ′ = ππ − πΜ π π24 π25 = ππ − π π Present the linearized models in transfer function format πΉ11 πΉ12 πΉ13 πΉ14 ππ′ (π ) ′ ′ (π ) (π ) πΆ π − π11 π − π11 π − π11 π − π11 ππ΄π [ π΄ ]= πΉ22 πΉ23 πΉ24 πΉ25 π′(π ) ππ′ (π ) [ πΉ26 πΉ26 πΉ26 πΉ26 ] [ ππ ′(π )] Where: πΉ11 = π12 πΉ22 πΉ26 + π13 πΉ12 = π12 πΉ23 πΉ26 + π14 πΉ13 = π12 πΉ24 πΉ26 πΉ14 = π12 πΉ25 πΉ26 π13 π21 πΉ22 = π − π11 π14 π25 πΉ23 = π − π11 πΉ24 = π23 πΉ25 = π24 1 πΉ26 = π π π − π22 − 21 22 π − π11 F. Classify the inputs as DVs and MVs The cooling medium temperature Tc is a manipulated variable in the CSTR shown in example 2.5 in (Seborg, Edgar, Mellichamp, & Doyle, 2017). The inlet concentration is disturbance variable. The inlet flow is a manipulated variable and the inlet temperate is a disturbance variable. First we have the manipulated variables: ππ , π Second, we have the disturbance variables: ππ΄π , ππ III. MATERIALS AND METHODS A. Hardware and Software The software was run on Acer Nitro AN517-51. MATLAB software package version R2020a was used for the simulations. The simulations method was ode15s with automatic settings for the time step and error tolerance. The simulation model was built in Simulink according to the nonlinear model and the linear state space model. The model parameters and test procedures are implemented in m script, see Appendix 1. In the first test cooling medium temperature will be changed from nominal value of 300K to 290K, then back to nominal value, then up to 302K and finally back to nominal value. TABLE II. TEST PROCEDURE1 COOLING MEDIUM Time [min] Action t=0 Initial values Tc0=300K Start simulation t=10 Tc1=290K t=20 Tc2=300K t=30 Tc3=302K t=40 Tc4=300K t=50 Stop simulation t=0 Collected variables Tc, T, cA In the second test the flowrate will be changed from nominal value of 100L/min to 90L/min, then back to nominal value, then up to 110L/min and finally back to 100L/min. TABLE III. B. Nonlinear simulation model in Simulink The nominal operating point was chosen to cA =0.8771 and Time [min] T = 324.5K as this is the global minimum of the ordinary differential functions. t=0 TEST PROCEDURE2 FLOW RATE Action t=0 Initial values qi0=100L/min Start simulation t=10 qi1 =90L/min t=20 qi2=100L/min t=30 qi3=110L/min t=40 qi4=100L/min t=50 Stop simulation Collected variables q, T, cA In the third test the inlet concentration will be changed from nominal value 1 mol/L to 0.9 mol/L, then back to nominal value 1mol/L, then up to 1.1 mol/L and finally back to nominal value. Figure 2 Nonlinear model in Simulink TABLE IV. The m-script is given in Appendix1. (Includes the linearmodel-function) C. Experimental plan – input signal design The input signal design must have high amount of variation in order for the estimation method to give enough information about the dynamics of the system. We will implement a periodic part with slow variation and large amplitude. We will then compare the sinus wave to the step changes in the cooling medium temperature, inlet flow rate, reactant component A and inlet temperature to see which model shows the best input-output dynamics. D. Experimental plan - Test procedure Time [min] TEST PROCEDURE3 INPUT CONCENTRATION Action t=0 Initial values cAi0=1 mol/L Start simulation t=10 cAi1=0.9 mol/L t=20 cAi2=1 mol/L t=30 cAi3=1.1 mol/L t=40 cAi4=1.0 mok/L t=50 Stop simulation t=0 Collected variables cAi, T, cA In the fourth test the inlet temperature will be changed from nominal value 350K to 340K, then back to nominal value, then up o 355K and then finally back to nominal value again. TABLE V. Time [min] TEST PROCEDURE4 INLET TEMPERATURE Action t=0 Initial values Ti0=350K Start simulation t=10 Ti1=340K t=20 Ti2=350K t=30 Ti3=355K t=40 Ti4=350K t=50 Stop simulation t=0 Collected variables Ti, T, cA E. Experimental plan – Modeling error indices The models are compared using the integral of absolute error(IAE) index between the nonlinear model and linear π‘5 model: πΌπ΄πΈ = ∫0 |π(π‘)|ππ‘ (6) Figure 3 Reactor temperature T variation with changes in cooling water temperature TC (Test procedure1). F. System identification procedure In order to identify the transfer functions in system identification toolbox, input data and output data will be measured from the CSTRsys2 (the transfer function in MATLAB, (Appendix1)) using a “to workspace” source from Simulink, then the data of inputs and outputs will be collected inside a .txt file so that we can implement it in our .m code while we prepare for the system identification process. G. Experimental plan – Criteria for model fitness In system identification toolbox the identified transfer function models are compared to the validation data using: πππ π(π−πΜ ) πππ‘ = [1 − ] ∗ 100 , π€βπππ π is the measured output πππ π(π−|π|) and πΜ is the simulated(predicted) model output. Figure 4 Reactant A concentration variation with changes in cooling water temperature TC (Test procedure1). IV. RESULTS A. Data collection results Here we have the collected data from the test procedures of the change in cooling water temperature, inlet flow change, component A in change and the inlet temperature change. The simulations were carried out according to the test procedure. The data collected is presented in Figures 3 - 14 Figure 8 Reactant A concentration variation with changes in inlet concentration cAi (Test procedure3). Figure 5 Reactor temperature T variation with changes in inlet flow rate qin (Test procedure2). Figure 6 Reactant A concentration variation with changes in inlet flow rate qin (Test procedure2). Figure 7 Reactor temperature T variation with changes in inlet concentration cAi (Test procedure3). Figure 9 Reactor temperature T variation with changes in inlet temperature Ti (Test procedure4). Figure 10 Reactant A concentration variation with changes in inlet temperature Ti (Test procedure4). Figure 12 Inlet flow rate qin steps in Simulink. (Test procedure 2) Step changes in cooling medium temperature, inlet flow rate, reactant A concentration through inlet and inlet temperature are: Figure 13 Reactant A cAin in Simulink. (Test procedure 3) Figure 11 Cooling medium temperature Tc steps in Simulink. (Test procedure 1) Tp1, Tp2,… P1 -27.781 P01 -0.665 P0D1 0.0076 P1D -27.781 1e-06 P2 0.9013 605.55, ay Td Tz1, Tz2,. . 1e-06 8703% -3608% 0 12.74% 0 -8703% -1387% 8.1099 P2D 310.09 10000, 0 -160.04% 0.36507 P2DZ -30.543 601.3, 1.846 419.47 -2765% P1I 0.0066 945 0.044734 3.499% P3I 0.3139 7 0.0045064, 6.82% 6.398 5391.3, 7159.4 Figure 14 Inlet temperature Tin steps in Simulink. (Test procedure 4) The IAE index was calculated for each output-input variable pairs between the non-linear and the linear model given in Table 1. Table 1:Model error indices. Output variables cA T IAE_Tc IAE_qin IAE_Ti IAE_cAin 2.62 301.1 351.2 7014 2.053 2.359e+04 2.665 585.5 B. System identification results ′ The deviation variables ππ ′ , π ′ , ππ΄π πππ ππ ′ are collected as the input values, imported with respect sample time, and the output values are first, the non-linear temperature out of tank and component A out of tank utilized as the estimation data. And for the validation data, we use the linear temperature out of the tank and linear component A out of then tank, calculated with the transfer function in the Simulink process. This is seen in Appendix1. The models chosen for the processes are first order, integrator, integrator with delay, first order with delay, second order, second order with delay, second order with delay and zero, first order integrator and finally third order integrator. Table 2: Transfer functions between reactor temperature T and cooling water temperature TC. Mod el nam e Proc ess gain Kp Time constan t(s) Ti me del Zero (s) Fit to estimat ion data Fit to validat ion data Figure 15 Model fit between reactor temperature T and cooling water temperature TC (Data from test procedure1). Table 3: Transfer functions between reactant A concentration cA and cooling water temperature TC. Mo del nam e Proce ss gain Kp Time constan t(s) Tp1, Tp2,… P1 0.35534 5058.7 P01 0.00192 06 P0D1 6.0052e -05 Ti me del ay Td Zero (s) Tz1, Tz2,. . Fit to estimat ion data 18.31% -1486% 40 15.18% Fit to validat ion data P1D P2 0.49277 6842.4 -4.628 1e-06, 0 15.54% P2DZ -2.3433 2670.8, 0 10000 -1483% 1e-06, 0 -1501% 4965.4 -470.8% P1I 0.00028 011 0.0036001 5.886% P3I 38.592 8.348e+08 , -49.86% 2074.2 P2D -257.68 1040.5 0.0023049, P2DZ 63667.1 1e-06, P1I 6.6304e -05 0.3796 17.96% P3I 0.00011 807 0.057211, 11.86% 10905 0.23 6 42.515 1.001+06 % 3223.6 12748, 2.1887 Figure 17 Model fit between reactor temperature T and inlet flow rate q (Data from test procedure2). Table 5: Transfer functions between reactant A concentration cA and inlet flow rate q. Figure 16 Model fit between reactant A concentration cA and cooling water temperature TC (Data from test procedure1) Table 4: Transfer functions between reactor temperature T and inlet flow rate q. Mo del nam e P1 Proce ss gain Kp 0.19728 Time constan t(s) Tp1, Tp2,… Ti me del ay Td 1e-06 Zero (s) Tz1, Tz2,. . Fit to estimat ion data 4.016e+04 % Fit to validat ion data Mo del nam e Proce ss gain Kp Time constan t(s) Tp1, Tp2,… P1 0.00067 31 1e-06 P01 4.1337e -05 P0D1 2.1974e -05 P1D 0.00085 955 P2 -31.035 Ti me del ay Td Zero (s) Tz1, Tz2,. . Fit to estimat ion data 2.144e+04 % -55.22% 1e-06 0 19.89% 3 2.144e+04 10000, -7075% 8.5826 P01 0.00031 049 5.844% P2D P0D1 0.00082 567 P1D 349.01 4.1523e+0 5 P2 2857.6 2.3519e+0 8, P2D -235.88 0 5.641% 0 -2.335% 0.055843 4.6714e+0 5, 0.34929 40 -0.5191% 1e-06, 0 1.659e+04 % 10000 0.00097 257 1e-06, P1I 0.04122 4431.9 -2283% P3I 3.4245e -05 0.0067825, 13.95% P2DZ 0.01316% -65.558 7618.9 8635.4, 0.72611 0 313.25 2.144e+04 % Fit to validat ion data Figure 18 Model fit between reactant A concentration cA and inlet flow rate q (Data from test procedure2). Table 6: Transfer functions between reactor temperature T and inlet concentration cAi. Mod el nam e Proc ess gain Kp Time constan t(s) Tp1, Tp2,… P1 -914.27 1e-06 P01 -46.266 P0D1 0.6273 5 P1D 3453.1 84499 P2 -7976.7 66.997, Ti me del ay Td Zero (s) Tz1, Tz2,. . Fit to estimat ion data -15570 25949, -15570 99400, Mod el nam e Proc ess gain Kp -2.0436 P01 0.1185 1 1.347e+04 % P0D1 0.0057 377 0 P1D 27347 5.7999e+0 6 P2 59362 1.7725e+0 9, 40 32.94% 0 -7.085% P2D 43889 25.04% -136.9 36820 61.56% P1I 0.0041 557 0.85501 0.1053% P3I 1.6894 0.15938, -110.9% 19.079 Tz1, Tz2,. . 1e-06 Fit to estimat ion data -2673% -1171% 5.467% 0 1.15% 0.02747% 7.3254e+0 8, 0 0.04537% 5.1133e+0 8, 1.354 1692.9 17.14% 0.24615 8.4024 8.4911, Zero (s) 0.2004 P2DZ 5.045 Ti me del ay Td 0.11714 -3.956% 37.2 Time constan t(s) Tp1, Tp2,… P1 8.0487 P2DZ Table 7: Transfer functions between reactant A concentration cA and inlet concentration cAi. 2.934e+04 % 13172 P2D Fit to validat ion data Figure 19 Model fit between reactor temperature T and inlet concentration cAi (Data from test procedure3). P1I 0.0058 578 0.014738 5.474% P3I 0.0337 78 0.0047054, -250.3% 924403, 0.24808 Fit to validat ion data Figure 20 Model fit between reactant A concentration cA and inlet concentration cAi (Data from test procedure3). Table 8: Transfer functions between reactor temperature T and inlet temperature Ti. Mod el nam e P1 Proc ess gain Kp -20.224 Time constan t(s) Tp1, Tp2,… Ti me del ay Td Zero (s) Tz1, Tz2,. . 1e-06 P01 -04833 P0D1 0.0044 191 P1D 1189.1 6.9335e+0 5 P2 17569 6.9411e+0 8, P2D 0.2817 6 Fit to estimat ion data Fit to validat ion data Figure 21 Model fit between reactor temperature T and inlet temperature Ti (Data from test procedure4). Table 9: Transfer functions between reactant A concentration and inlet temperature Ti Mod el nam e Proc ess gain Kp 1.254e+04 % Time constan t(s) Tp1, Tp2,… P1 -0.2762 4686.2 -5577% P01 0.0013 965 P0D1 3.0219 e-09 P1D 005890 1 1e-06 P2 -19.453 1e-06, 0 18.04% 0 -2.842% 0.01324% 0.125 38022, 0 -17.83% -4.1824 6.3098 11655, 1.279 1155.2 Tz1, Tz2,. . Fit to estimat ion data 22.78% -1827% 0 20.09% 0 -4114% -1878% 0.0040 786 0.07424 5.679% P3I 15.651 6.9411e+0 8, 15.26% 1e-06, 0 -1874% 6749.7 P2DZ P1I 2768.1 -12.797 -126.8% 6.4453 5.7581e05, Zero (s) 10000 P2D P2DZ Ti me del ay Td 0.1664 2 1e-06, 9 17.844 -3561% P1I 5.7152 e-05 0.21804 22.53% P3I 4.8471 e-05 0.019638, 12,47% 265.36 10156, 1.1336 Fit to validat ion data cases, namely the component A, cA and temperature out of tank T. From the system identification results the third model integrator fits the best when steps responses are changed in the cooling medium temperature Tc from procedure 1, model fit between reactor temperature T and inlet flow rate q from procedure 2, and inlet temperature Ti and model fit between reactant A and inlet temperature Ti from procedure 4. The first order integrator is best fit for the model fit between reactant A and inlet flow rate q from procedure 2. The second order model with zero and delay shows to be best fit for the model fit between reactor T and inlet concentration cAi from procedure 3. Figure 22Model fit between reactant A concentration and inlet temperature Ti (Data from test procedure4). Finally, the second order model is best fit to the model fit between reactant A concentration cA and inlet concentration cAi from test procedure 3. None of the gain parameters of Tc, Ti, qi or cAin should be used for control purposes since the difference between the nonlinear model and linear model are by a significant amount. VI. CONCLUSION AND FURTHER WORK V. ANALYSIS AND DISCUSSION The data collected from each experiment has large variation when it comes to the magnitude difference between the nonlinear and linear model. Step responses due to change in the cooling medium temperature Tc: the linear model follows the non-linear model trail with a minimum variance in temperature during the 30 to 90 second mark, but fails to follow during the initial state, which is 0 to 30 seconds mark. Step responses due to change in inlet flow rate qin: the linear model fails to follow the nonlinear model both when we observe the component A and the temperature T. Step responses due to change in component A in, cAin: in the temperature experiment the nonlinear model has the same pattern, but differs with a significant amount when comparing the temperatures, while observing the component A results, the linear model is seen to be a constant, while the nonlinear is not. Step responses due to change in inlet temperature Ti: the linear model completely fails to follow the nonlinear in both The performance observed from each experiment shows us that the nonlinear model doesn´t correlate with the linear model obtained through the transfer function, this could be an issue from the wrong implementation done inside the .m file, or, the setup of the transfer function in matrix form in simulink, this would mean that further study needs to be conducted. The linearized model in this experiment cannot be used to describe the dynamic behavior of the CSTR system due to the possibility of error in transfer function implementation inside simulink. VII. REFERENCES Seborg, D. E., Edgar, T. F., Mellichamp, D. A., & Doyle, F. J. (2017). Process Dynamics and Control (4th EMEA ed.). Hoboken NJ: Wiley. APPENDIX1 M-SCRIPT&SIMULINK