source: branches/gui/sample/controllers/CSTR_noniso_pid.mso @ 909

Last change on this file since 909 was 909, checked in by Argimiro Resende Secchi, 14 years ago

Starting checking new EML.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.6 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 909 2010-02-19 21:08:11Z 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
108        DEVICES
109        FEED as stream_cstr;
110        CSTR1 as CSTR;
111        PIDL as PID;
112        PIDT as PID;
113 
114        VARIABLES
115        Lsp as length;
116        Tsp as temperature;
117out     LI as control_signal (Brief="Level Indicator");
118out     TI as control_signal (Brief="Temperature Indicator");
119
120        CONNECTIONS
121        FEED to CSTR1.Inlet;
122        LI to PIDL.Input;
123        TI to PIDT.Input;
124       
125        SET
126#       CSTR Parameters
127        CSTR1.R   = 8.3144 * 'kJ/kmol/K';
128        CSTR1.U   = 300 * 'kJ/h/m^2/K';
129        CSTR1.ro  = 1000 * 'kg/m^3';
130        CSTR1.Cp  = 4*'kJ/kg/K';
131        CSTR1.Hr  = -7000 * 'kJ/kmol';
132        CSTR1.Ea  = 6e4 * 'kJ/kmol';
133        CSTR1.ko  = 89 * '1/s';
134        CSTR1.D   = 3.2 * 'm';
135        CSTR1.Cv  = 2.7 * 'm^2.5/h';
136       
137        PIDL.PID_Select = "Ideal_AWBT";
138        PIDT.PID_Select = "Ideal_AWBT";
139       
140#   Level control: PID parameters
141        PIDL.bias=0;
142        PIDL.alpha=0.1;
143        PIDL.Action="Direct";
144        PIDL.gamma=1;
145        PIDL.beta=1;
146        PIDL.Clip="Clipped";
147        PIDL.Mode="Automatic";
148        PIDL.gain=1;
149        PIDL.intTime=2.5*'h';
150        PIDL.derivTime=0*'s';
151        PIDL.tau=1*'s';
152        PIDL.tauSet=1*'s';
153
154#   Temperature control: PID parameters
155        PIDT.bias = 0;
156        PIDT.alpha=0.1;
157        PIDT.Action="Reverse";
158        PIDT.gamma=1;
159        PIDT.beta=1;
160        PIDT.Clip="Clipped";
161        PIDT.Mode="Automatic";
162        PIDT.gain=1;
163        PIDT.intTime=2.5*'h';
164        PIDT.derivTime=1*'h';
165        PIDT.tau=1*'s';
166        PIDT.tauSet=1*'s';     
167       
168#       Operating range for control variables
169        PIDL.MaxInput=5;
170        PIDL.MinInput=0;
171        PIDT.MaxInput=700;
172        PIDT.MinInput=230;     
173        PIDT.MaxOutput=700;
174        PIDT.MinOutput=230;     
175
176        EQUATIONS
177
178        "Level sensor"
179        LI * 'm' = CSTR1.h;
180
181        "Temperature sensor"
182        TI * 'K' = CSTR1.T;
183
184        "Setpoints"
185        PIDL.SetPoint * 'm' = Lsp;
186        PIDT.SetPoint * 'K' = Tsp;
187
188        "Manipulated Variables"
189        CSTR1.x = PIDL.Output;
190        CSTR1.Tw = PIDT.Output * 'K';
191
192        "Feed Stream"
193        FEED.Ca = 300 * 'kmol/m^3';
194        FEED.F = 3.5 * 'm^3/h';
195
196#   Disturbance
197        if time < 50 * 'h' then
198                FEED.T = 300 * 'K';
199        else
200                FEED.T = 285 * 'K'; # change to 350 K to saturate controller
201        end
202
203#   Set-point changes
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
211          Lsp = 1.7 * 'm';
212        else
213          Lsp = 4 * 'm';
214        end
215
216        INITIAL
217        CSTR1.Ca = 50 * 'kmol/m^3';
218        CSTR1.h = 1.7 * 'm';
219        CSTR1.T = 570 * 'K';
220       
221        OPTIONS
222        TimeStep = 1;
223        TimeEnd = 250;
224        TimeUnit = 'h';
225        DAESolver(File = "dassl");
226end
Note: See TracBrowser for help on using the repository browser.