[84] | 1 | #*------------------------------------------------------------------- |
---|
[536] | 2 | * EMSO Model Library (EML) Copyright (C) 2004 - 2008 ALSOC. |
---|
[84] | 3 | * |
---|
| 4 | * This LIBRARY is free software; you can distribute it and/or modify |
---|
| 5 | * it under the therms of the ALSOC FREE LICENSE as available at |
---|
| 6 | * http://www.enq.ufrgs.br/alsoc. |
---|
| 7 | * |
---|
[536] | 8 | * EMSO Copyright (C) 2004 - 2008 ALSOC, original code |
---|
[84] | 9 | * from http://www.rps.eng.br Copyright (C) 2002-2004. |
---|
| 10 | * All rights reserved. |
---|
| 11 | * |
---|
| 12 | * EMSO is distributed under the therms of the ALSOC LICENSE as |
---|
| 13 | * available at http://www.enq.ufrgs.br/alsoc. |
---|
| 14 | * |
---|
| 15 | *-------------------------------------------------------------------- |
---|
| 16 | * Sample file for controllers |
---|
| 17 | *---------------------------------------------------------------------- |
---|
[536] | 18 | * Author: Argimiro R. Secchi |
---|
[84] | 19 | * $Id: CSTR_noniso_pid.mso 536 2008-06-15 23:18:35Z arge $ |
---|
| 20 | *--------------------------------------------------------------------*# |
---|
| 21 | |
---|
[7] | 22 | using "controllers/PIDs"; |
---|
[1] | 23 | |
---|
[190] | 24 | const_valv as positive(Brief = "Valve Constant", Default=1,Lower=0,Upper=100, Unit='m^2.5/h'); |
---|
[1] | 25 | |
---|
[536] | 26 | Model stream_cstr |
---|
[1] | 27 | VARIABLES |
---|
| 28 | Ca as conc_mol; |
---|
| 29 | F as flow_vol; |
---|
| 30 | T as temperature; |
---|
| 31 | end |
---|
| 32 | |
---|
| 33 | Model CSTR |
---|
| 34 | |
---|
| 35 | PARAMETERS |
---|
[190] | 36 | ko as frequency (DisplayUnit='1/h'); |
---|
[536] | 37 | D as length; |
---|
[1] | 38 | A as area; |
---|
[190] | 39 | Ea as energy_mol (DisplayUnit='kJ/kmol'); |
---|
| 40 | R as Real (Unit='kJ/mol/K'); |
---|
[257] | 41 | ro as dens_mass (DisplayUnit='kg/m^3'); |
---|
| 42 | Cp as cp_mass (DisplayUnit='kJ/kg/K'); |
---|
[190] | 43 | U as heat_trans_coeff (DisplayUnit='kW/m^2/K'); |
---|
| 44 | Hr as heat_reaction (DisplayUnit='kJ/kmol'); |
---|
[536] | 45 | pi as Real (Default = 3.141593); |
---|
| 46 | Cv as const_valv; |
---|
| 47 | |
---|
[1] | 48 | VARIABLES |
---|
[536] | 49 | At as area; |
---|
[1] | 50 | T as temperature; |
---|
| 51 | Tw as temperature; |
---|
[536] | 52 | x as fraction; |
---|
[1] | 53 | V as volume; |
---|
| 54 | Ca as conc_mol; |
---|
| 55 | h as length; |
---|
| 56 | tau as time_h; |
---|
| 57 | rA as reaction_mol; |
---|
[190] | 58 | k as frequency (DisplayUnit='1/h'); |
---|
[257] | 59 | q as heat_rate (DisplayUnit='kJ/h'); |
---|
| 60 | qr as heat_rate (DisplayUnit='kJ/h'); |
---|
[536] | 61 | in Inlet as stream_cstr; |
---|
| 62 | out Outlet as stream_cstr; |
---|
[1] | 63 | |
---|
[536] | 64 | SET |
---|
| 65 | A = pi * D^2 / 4; |
---|
| 66 | |
---|
[1] | 67 | EQUATIONS |
---|
| 68 | |
---|
[536] | 69 | "Overall Mass Balance" |
---|
[1] | 70 | diff(V) = Inlet.F - Outlet.F; |
---|
[34] | 71 | |
---|
[536] | 72 | "Component Mass Balance" |
---|
[257] | 73 | V * diff(Ca) = Inlet.F * (Inlet.Ca - Ca) - (-rA) * V; |
---|
| 74 | |
---|
[536] | 75 | "Average Residence Time" |
---|
[257] | 76 | tau * Inlet.F = V; |
---|
| 77 | |
---|
[536] | 78 | "Energy Balance" |
---|
[257] | 79 | ro * V * Cp * diff(T) = Inlet.F * ro * Cp * (Inlet.T - T) + qr - q; |
---|
| 80 | |
---|
[536] | 81 | "Heat Transfer Rate" |
---|
[257] | 82 | q = U * At * (T - Tw); |
---|
| 83 | |
---|
[536] | 84 | "Reaction Heat Rate" |
---|
[257] | 85 | qr = (-Hr) * (-rA) * V; |
---|
[34] | 86 | |
---|
[536] | 87 | "Reaction Rate" |
---|
[1] | 88 | -rA = k * Ca; |
---|
[34] | 89 | |
---|
[536] | 90 | "Arrhenius Equation" |
---|
[34] | 91 | k = ko * exp(-Ea/(R*T)); |
---|
| 92 | |
---|
[536] | 93 | "Geometry" |
---|
[1] | 94 | A * h = V; |
---|
[536] | 95 | At = A + pi*D*h; |
---|
[34] | 96 | |
---|
[536] | 97 | "Valve Equation" |
---|
| 98 | Outlet.F = x * Cv * sqrt(h); |
---|
[1] | 99 | |
---|
[536] | 100 | "Perfect Mixture" |
---|
[257] | 101 | Outlet.Ca = Ca; |
---|
| 102 | Outlet.T = T; |
---|
[536] | 103 | end |
---|
[1] | 104 | |
---|
[536] | 105 | # Process with controlled CSTR and multiple steady-states |
---|
[1] | 106 | FlowSheet CSTR_controller |
---|
| 107 | |
---|
| 108 | DEVICES |
---|
[536] | 109 | FEED as stream_cstr; |
---|
[190] | 110 | CSTR1 as CSTR; |
---|
[295] | 111 | PIDL as PID; |
---|
| 112 | PIDT as PID; |
---|
[1] | 113 | |
---|
| 114 | VARIABLES |
---|
| 115 | L_ad as Real; |
---|
| 116 | Lmin as length; |
---|
| 117 | Lmax as length; |
---|
| 118 | T_ad as Real; |
---|
| 119 | Tmin as temperature; |
---|
| 120 | Tmax as temperature; |
---|
[257] | 121 | Lsp as length; |
---|
| 122 | Tsp as temperature; |
---|
[1] | 123 | |
---|
| 124 | CONNECTIONS |
---|
[190] | 125 | FEED to CSTR1.Inlet; |
---|
[1] | 126 | |
---|
| 127 | SET |
---|
[536] | 128 | # CSTR Parameters |
---|
[190] | 129 | CSTR1.R = 8.3144 * 'kJ/kmol/K'; |
---|
| 130 | CSTR1.U = 300 * 'kJ/h/m^2/K'; |
---|
[257] | 131 | CSTR1.ro = 1000 * 'kg/m^3'; |
---|
| 132 | CSTR1.Cp = 4*'kJ/kg/K'; |
---|
[190] | 133 | CSTR1.Hr = -7000 * 'kJ/kmol'; |
---|
| 134 | CSTR1.Ea = 6e4 * 'kJ/kmol'; |
---|
| 135 | CSTR1.ko = 89 * '1/s'; |
---|
[536] | 136 | CSTR1.D = 3.2 * 'm'; |
---|
| 137 | CSTR1.Cv = 2.7 * 'm^2.5/h'; |
---|
[1] | 138 | |
---|
[295] | 139 | PIDL.PID_Select = "Ideal_AWBT"; |
---|
| 140 | PIDT.PID_Select = "Ideal_AWBT"; |
---|
| 141 | |
---|
[1] | 142 | EQUATIONS |
---|
| 143 | |
---|
[536] | 144 | "Dimensionless level to connect PID" |
---|
[190] | 145 | L_ad*(Lmax-Lmin)=CSTR1.h-Lmin; |
---|
[1] | 146 | PIDL.Ports.input=L_ad; |
---|
| 147 | |
---|
[536] | 148 | "Dimensionless temperature to connect PID" |
---|
[190] | 149 | T_ad*(Tmax-Tmin)=CSTR1.T-Tmin; |
---|
[1] | 150 | PIDT.Ports.input=T_ad; |
---|
| 151 | |
---|
[536] | 152 | "Manipulated Variables" |
---|
| 153 | CSTR1.x = PIDL.Ports.output; |
---|
[190] | 154 | CSTR1.Tw = PIDT.Ports.output*(Tmax-Tmin)+Tmin; |
---|
[1] | 155 | |
---|
[536] | 156 | # Level control: PID parameters |
---|
[34] | 157 | PIDL.Parameters.bias=0; |
---|
[1] | 158 | PIDL.Parameters.alpha=0.1; |
---|
[257] | 159 | PIDL.Options.action=-1; |
---|
[1] | 160 | PIDL.Parameters.gamma=1; |
---|
| 161 | PIDL.Parameters.beta=1; |
---|
| 162 | PIDL.Options.clip=1; |
---|
| 163 | PIDL.Options.autoMan=0; |
---|
[257] | 164 | PIDL.Parameters.gain=1; |
---|
| 165 | PIDL.Parameters.intTime=2.5*'h'; |
---|
[190] | 166 | PIDL.Parameters.derivTime=0*'s'; |
---|
[257] | 167 | PIDL.Ports.setPoint=(Lsp - Lmin)/(Lmax - Lmin); |
---|
[190] | 168 | PIDL.Parameters.tau=1*'s'; |
---|
| 169 | PIDL.Parameters.tauSet=1*'s'; |
---|
[536] | 170 | |
---|
| 171 | # Temperature control: PID parameters |
---|
[1] | 172 | PIDT.Parameters.bias = 0; |
---|
| 173 | PIDT.Parameters.alpha=0.1; |
---|
[34] | 174 | PIDT.Options.action=1; |
---|
[1] | 175 | PIDT.Parameters.gamma=1; |
---|
| 176 | PIDT.Parameters.beta=1; |
---|
| 177 | PIDT.Options.clip=1; |
---|
| 178 | PIDT.Options.autoMan=0; |
---|
[257] | 179 | PIDT.Parameters.gain=1; |
---|
| 180 | PIDT.Parameters.intTime=2.5*'h'; |
---|
[190] | 181 | PIDT.Parameters.derivTime=1*'h'; |
---|
[257] | 182 | PIDT.Ports.setPoint=(Tsp - Tmin)/(Tmax - Tmin); |
---|
[190] | 183 | PIDT.Parameters.tau=1*'s'; |
---|
| 184 | PIDT.Parameters.tauSet=1*'s'; |
---|
[1] | 185 | |
---|
[536] | 186 | "Operating range for control variables" |
---|
[190] | 187 | Lmax=5*'m'; |
---|
| 188 | Lmin=0*'m'; |
---|
| 189 | Tmax=700*'K'; |
---|
| 190 | Tmin=230*'K'; |
---|
[536] | 191 | |
---|
| 192 | "Feed Stream" |
---|
[190] | 193 | FEED.Ca = 300 * 'kmol/m^3'; |
---|
| 194 | FEED.F = 3.5 * 'm^3/h'; |
---|
[1] | 195 | |
---|
[536] | 196 | # Disturbance |
---|
[257] | 197 | if time < 50 * 'h' then |
---|
| 198 | FEED.T = 300 * 'K'; |
---|
| 199 | else |
---|
[536] | 200 | FEED.T = 285 * 'K'; # change to 350 K to saturate controller |
---|
[257] | 201 | end |
---|
| 202 | |
---|
[536] | 203 | # Set-point changes |
---|
[257] | 204 | if time < 100 * 'h' then |
---|
| 205 | Tsp = 630 * 'K'; |
---|
| 206 | else |
---|
| 207 | Tsp = 400 * 'K'; |
---|
| 208 | end |
---|
| 209 | |
---|
| 210 | if time < 150 * 'h' then |
---|
[536] | 211 | Lsp = 1.7 * 'm'; |
---|
[257] | 212 | else |
---|
| 213 | Lsp = 4 * 'm'; |
---|
| 214 | end |
---|
| 215 | |
---|
[1] | 216 | INITIAL |
---|
[190] | 217 | CSTR1.Ca = 50 * 'kmol/m^3'; |
---|
[536] | 218 | CSTR1.h = 1.7 * 'm'; |
---|
| 219 | CSTR1.T = 570 * 'K'; |
---|
[1] | 220 | |
---|
| 221 | OPTIONS |
---|
[257] | 222 | TimeStep = 1; |
---|
| 223 | TimeEnd = 250; |
---|
[190] | 224 | TimeUnit = 'h'; |
---|
[536] | 225 | DAESolver(File = "dassl"); |
---|
[1] | 226 | end |
---|