source: trunk/sample/controllers/CSTR_noniso_pid.mso @ 1009

Last change on this file since 1009 was 1003, checked in by Argimiro Resende Secchi, 6 years ago

Fixed sintaxe problem of old version.

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