1 | #*------------------------------------------------------------------- |
---|
2 | * EMSO Model Library (EML) Copyright (C) 2004 - 2008 ALSOC. |
---|
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 | * |
---|
8 | * EMSO Copyright (C) 2004 - 2008 ALSOC, original code |
---|
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 CSTR |
---|
17 | *---------------------------------------------------------------------- |
---|
18 | * Author: Argimiro R. Secchi |
---|
19 | * $Id: CSTR_noniso.mso 295 2008-06-15 19:48:17Z arge $ |
---|
20 | *--------------------------------------------------------------------*# |
---|
21 | |
---|
22 | using "types"; |
---|
23 | using "controllers/PIDs"; |
---|
24 | |
---|
25 | const_valv as positive(Brief = "Valve Constant", Default=1,Lower=0,Upper=100, Unit='m^2.5/h'); |
---|
26 | |
---|
27 | Model stream_cstr |
---|
28 | VARIABLES |
---|
29 | Ca as conc_mol; |
---|
30 | F as flow_vol; |
---|
31 | T as temperature; |
---|
32 | end |
---|
33 | |
---|
34 | Model CSTR |
---|
35 | |
---|
36 | PARAMETERS |
---|
37 | ko as frequency (DisplayUnit='1/h'); |
---|
38 | D as length; |
---|
39 | A as area; |
---|
40 | Ea as energy_mol (DisplayUnit='kJ/kmol'); |
---|
41 | R as Real (Unit='kJ/mol/K'); |
---|
42 | ro as dens_mass (DisplayUnit='kg/m^3'); |
---|
43 | Cp as cp_mass (DisplayUnit='kJ/kg/K'); |
---|
44 | U as heat_trans_coeff (DisplayUnit='kW/m^2/K'); |
---|
45 | Hr as heat_reaction (DisplayUnit='kJ/kmol'); |
---|
46 | pi as Real (Default = 3.141593); |
---|
47 | Cv as const_valv; |
---|
48 | |
---|
49 | VARIABLES |
---|
50 | At as area; |
---|
51 | T as temperature; |
---|
52 | Tw as temperature; |
---|
53 | x as fraction; |
---|
54 | V as volume; |
---|
55 | Ca as conc_mol; |
---|
56 | h as length; |
---|
57 | tau as time_h; |
---|
58 | rA as reaction_mol; |
---|
59 | k as frequency (DisplayUnit='1/h'); |
---|
60 | q as heat_rate (DisplayUnit='kJ/h'); |
---|
61 | qr as heat_rate (DisplayUnit='kJ/h'); |
---|
62 | in Inlet as stream_cstr; |
---|
63 | out Outlet as stream_cstr; |
---|
64 | |
---|
65 | SET |
---|
66 | A = pi * D^2 / 4; |
---|
67 | |
---|
68 | EQUATIONS |
---|
69 | |
---|
70 | "Overall Mass Balance" |
---|
71 | diff(V) = Inlet.F - Outlet.F; |
---|
72 | |
---|
73 | "Component Mass Balance" |
---|
74 | V * diff(Ca) = Inlet.F * (Inlet.Ca - Ca) - (-rA) * V; |
---|
75 | |
---|
76 | "Average Residence Time" |
---|
77 | tau * Inlet.F = V; |
---|
78 | |
---|
79 | "Energy Balance" |
---|
80 | ro * V * Cp * diff(T) = Inlet.F * ro * Cp * (Inlet.T - T) + qr - q; |
---|
81 | |
---|
82 | "Heat Transfer Rate" |
---|
83 | q = U * At * (T - Tw); |
---|
84 | |
---|
85 | "Reaction Heat Rate" |
---|
86 | qr = (-Hr) * (-rA) * V; |
---|
87 | |
---|
88 | "Reaction Rate" |
---|
89 | -rA = k * Ca; |
---|
90 | |
---|
91 | "Arrhenius Equation" |
---|
92 | k = ko * exp(-Ea/(R*T)); |
---|
93 | |
---|
94 | "Geometry" |
---|
95 | A * h = V; |
---|
96 | At = A + pi*D*h; |
---|
97 | |
---|
98 | "Valve Equation" |
---|
99 | Outlet.F = x * Cv * sqrt(h); |
---|
100 | |
---|
101 | "Perfect Mixture" |
---|
102 | Outlet.Ca = Ca; |
---|
103 | Outlet.T = T; |
---|
104 | end |
---|
105 | |
---|
106 | # Process with uncontrolled CSTR and multiple steady-states |
---|
107 | FlowSheet CSTR_no_control |
---|
108 | |
---|
109 | DEVICES |
---|
110 | FEED as stream_cstr; |
---|
111 | CSTR1 as CSTR; |
---|
112 | |
---|
113 | CONNECTIONS |
---|
114 | FEED to CSTR1.Inlet; |
---|
115 | |
---|
116 | SET |
---|
117 | # CSTR Parameters |
---|
118 | CSTR1.R = 8.3144 * 'kJ/kmol/K'; |
---|
119 | CSTR1.U = 300 * 'kJ/h/m^2/K'; |
---|
120 | CSTR1.ro = 1000 * 'kg/m^3'; |
---|
121 | CSTR1.Cp = 4*'kJ/kg/K'; |
---|
122 | CSTR1.Hr = -7000 * 'kJ/kmol'; |
---|
123 | CSTR1.Ea = 6e4 * 'kJ/kmol'; |
---|
124 | CSTR1.ko = 89 * '1/s'; |
---|
125 | CSTR1.D = 3.2 * 'm'; |
---|
126 | CSTR1.Cv = 2.7 * 'm^2.5/h'; |
---|
127 | |
---|
128 | EQUATIONS |
---|
129 | "Manipulated Variables" |
---|
130 | CSTR1.x = 1; |
---|
131 | CSTR1.Tw = 300 * 'K'; |
---|
132 | |
---|
133 | "Feed Stream" |
---|
134 | FEED.Ca = 300 * 'kmol/m^3'; |
---|
135 | FEED.F = 3.5 * 'm^3/h'; |
---|
136 | |
---|
137 | # Disturbance |
---|
138 | if time < 50 * 'h' then |
---|
139 | "Feed Temperature" FEED.T = 300 * 'K'; |
---|
140 | else |
---|
141 | "Feed Temperature" FEED.T = 350 * 'K'; |
---|
142 | end |
---|
143 | |
---|
144 | INITIAL |
---|
145 | "Concentration" CSTR1.Ca = 50 * 'kmol/m^3'; |
---|
146 | "Level" CSTR1.h = 1.7 * 'm'; |
---|
147 | "Temperature" CSTR1.T = 570 * 'K'; # increase to 580 K to change steady-state |
---|
148 | |
---|
149 | OPTIONS |
---|
150 | TimeStep = 1; |
---|
151 | TimeEnd = 100; |
---|
152 | TimeUnit = 'h'; |
---|
153 | DAESolver(File = "dassl"); |
---|
154 | end |
---|
155 | |
---|
156 | Model CSTR_pid as CSTR |
---|
157 | |
---|
158 | VARIABLES |
---|
159 | out LI as control_signal (Brief="Level Indicator"); |
---|
160 | out TI as control_signal (Brief="Temperature Indicator"); |
---|
161 | |
---|
162 | EQUATIONS |
---|
163 | "Level sensor" |
---|
164 | LI * 'm' = h; |
---|
165 | |
---|
166 | "Temperature sensor" |
---|
167 | TI * 'K' = T; |
---|
168 | |
---|
169 | end |
---|
170 | |
---|
171 | # Process with controlled CSTR and multiple steady-states |
---|
172 | FlowSheet CSTR_controller |
---|
173 | |
---|
174 | DEVICES |
---|
175 | FEED as stream_cstr; |
---|
176 | CSTR1 as CSTR_pid; |
---|
177 | PIDL as PID; |
---|
178 | PIDT as PID; |
---|
179 | |
---|
180 | VARIABLES |
---|
181 | Lsp as length; |
---|
182 | Tsp as temperature; |
---|
183 | |
---|
184 | |
---|
185 | CONNECTIONS |
---|
186 | FEED to CSTR1.Inlet; |
---|
187 | CSTR1.LI to PIDL.Input; |
---|
188 | CSTR1.TI to PIDT.Input; |
---|
189 | |
---|
190 | SET |
---|
191 | # CSTR Parameters |
---|
192 | CSTR1.R = 8.3144 * 'kJ/kmol/K'; |
---|
193 | CSTR1.U = 300 * 'kJ/h/m^2/K'; |
---|
194 | CSTR1.ro = 1000 * 'kg/m^3'; |
---|
195 | CSTR1.Cp = 4*'kJ/kg/K'; |
---|
196 | CSTR1.Hr = -7000 * 'kJ/kmol'; |
---|
197 | CSTR1.Ea = 6e4 * 'kJ/kmol'; |
---|
198 | CSTR1.ko = 89 * '1/s'; |
---|
199 | CSTR1.D = 3.2 * 'm'; |
---|
200 | CSTR1.Cv = 2.7 * 'm^2.5/h'; |
---|
201 | |
---|
202 | PIDL.PID_Select = "Ideal_AWBT"; |
---|
203 | PIDT.PID_Select = "Ideal_AWBT"; |
---|
204 | |
---|
205 | # Level control: PID parameters |
---|
206 | PIDL.bias=0; |
---|
207 | PIDL.alpha=0.1; |
---|
208 | PIDL.Action="Direct"; |
---|
209 | PIDL.gamma=1; |
---|
210 | PIDL.beta=1; |
---|
211 | PIDL.Clip="Clipped"; |
---|
212 | PIDL.Mode="Automatic"; |
---|
213 | PIDL.gain=1; |
---|
214 | PIDL.intTime=2.5*'h'; |
---|
215 | PIDL.derivTime=0*'s'; |
---|
216 | PIDL.tau=1*'s'; |
---|
217 | PIDL.tauSet=1*'s'; |
---|
218 | |
---|
219 | # Temperature control: PID parameters |
---|
220 | PIDT.bias = 0; |
---|
221 | PIDT.alpha=0.1; |
---|
222 | PIDT.Action="Direct"; |
---|
223 | PIDT.gamma=1; |
---|
224 | PIDT.beta=1; |
---|
225 | PIDT.Clip="Clipped"; |
---|
226 | PIDT.Mode="Automatic"; |
---|
227 | PIDT.gain=1; |
---|
228 | PIDT.intTime=2.5*'h'; |
---|
229 | PIDT.derivTime=1*'h'; |
---|
230 | PIDT.tau=1*'s'; |
---|
231 | PIDT.tauSet=1*'s'; |
---|
232 | |
---|
233 | # Operating range for control variables |
---|
234 | PIDL.MaxInput=5; |
---|
235 | PIDL.MinInput=0; |
---|
236 | PIDT.MaxInput=700; |
---|
237 | PIDT.MinInput=230; |
---|
238 | PIDT.MaxOutput=700; |
---|
239 | PIDT.MinOutput=230; |
---|
240 | |
---|
241 | EQUATIONS |
---|
242 | |
---|
243 | "Setpoints" |
---|
244 | PIDL.SetPoint * 'm' = Lsp; |
---|
245 | PIDT.SetPoint * 'K' = Tsp; |
---|
246 | |
---|
247 | "Manipulated Variables" |
---|
248 | CSTR1.x = PIDL.Output; |
---|
249 | CSTR1.Tw = PIDT.Output * 'K'; |
---|
250 | |
---|
251 | "Feed Stream" |
---|
252 | FEED.Ca = 300 * 'kmol/m^3'; |
---|
253 | FEED.F = 3.5 * 'm^3/h'; |
---|
254 | |
---|
255 | # Disturbance |
---|
256 | if time < 50 * 'h' then |
---|
257 | FEED.T = 300 * 'K'; |
---|
258 | else |
---|
259 | FEED.T = 285 * 'K'; # change to 350 K to saturate controller |
---|
260 | end |
---|
261 | |
---|
262 | # Set-point changes |
---|
263 | if time < 100 * 'h' then |
---|
264 | Tsp = 630 * 'K'; |
---|
265 | else |
---|
266 | Tsp = 400 * 'K'; |
---|
267 | end |
---|
268 | |
---|
269 | if time < 150 * 'h' then |
---|
270 | Lsp = 1.7 * 'm'; |
---|
271 | else |
---|
272 | Lsp = 4 * 'm'; |
---|
273 | end |
---|
274 | |
---|
275 | INITIAL |
---|
276 | CSTR1.Ca = 50 * 'kmol/m^3'; |
---|
277 | CSTR1.h = 1.7 * 'm'; |
---|
278 | CSTR1.T = 570 * 'K'; |
---|
279 | |
---|
280 | OPTIONS |
---|
281 | TimeStep = 1; |
---|
282 | TimeEnd = 250; |
---|
283 | TimeUnit = 'h'; |
---|
284 | DAESolver(File = "dassl"); |
---|
285 | end |
---|
286 | |
---|