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

Last change on this file since 735 was 735, checked in by gerson bicca, 13 years ago

updates (some samples are obsoletes)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.9 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 735 2009-02-27 02:00:39Z bicca $
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        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;
121        Lsp as length;
122        Tsp as temperature;
123       
124        CONNECTIONS
125        FEED to CSTR1.Inlet;
126       
127        SET
128#       CSTR Parameters
129        CSTR1.R   = 8.3144 * 'kJ/kmol/K';
130        CSTR1.U   = 300 * 'kJ/h/m^2/K';
131        CSTR1.ro  = 1000 * 'kg/m^3';
132        CSTR1.Cp  = 4*'kJ/kg/K';
133        CSTR1.Hr  = -7000 * 'kJ/kmol';
134        CSTR1.Ea  = 6e4 * 'kJ/kmol';
135        CSTR1.ko  = 89 * '1/s';
136        CSTR1.D   = 3.2 * 'm';
137        CSTR1.Cv  = 2.7 * 'm^2.5/h';
138       
139        PIDL.PID_Select = "Ideal_AWBT";
140        PIDT.PID_Select = "Ideal_AWBT";
141       
142        EQUATIONS
143
144        "Dimensionless level to connect PID"
145        L_ad*(Lmax-Lmin)=CSTR1.h-Lmin;
146        PIDL.Ports.input=L_ad;
147
148        "Dimensionless temperature to connect PID"
149        T_ad*(Tmax-Tmin)=CSTR1.T-Tmin;
150        PIDT.Ports.input=T_ad;
151       
152        "Manipulated Variables"
153        CSTR1.x  = PIDL.Ports.output;
154        CSTR1.Tw  = PIDT.Ports.output*(Tmax-Tmin)+Tmin;
155       
156#   Level control: PID parameters
157        PIDL.Parameters.bias=0;
158        PIDL.Parameters.alpha=0.1;
159        PIDL.Options.action=-1;
160        PIDL.Parameters.gamma=1;
161        PIDL.Parameters.beta=1;
162        PIDL.Options.clip=1;
163        PIDL.Options.autoMan=0;
164        PIDL.Parameters.gain=1;
165        PIDL.Parameters.intTime=2.5*'h';
166        PIDL.Parameters.derivTime=0*'s';
167        PIDL.Ports.setPoint=(Lsp - Lmin)/(Lmax - Lmin);
168        PIDL.Parameters.tau=1*'s';
169        PIDL.Parameters.tauSet=1*'s';
170
171#   Temperature control: PID parameters
172        PIDT.Parameters.bias = 0;
173        PIDT.Parameters.alpha=0.1;
174        PIDT.Options.action=1;
175        PIDT.Parameters.gamma=1;
176        PIDT.Parameters.beta=1;
177        PIDT.Options.clip=1;
178        PIDT.Options.autoMan=0;
179        PIDT.Parameters.gain=1;
180        PIDT.Parameters.intTime=2.5*'h';
181        PIDT.Parameters.derivTime=1*'h';
182        PIDT.Ports.setPoint=(Tsp - Tmin)/(Tmax - Tmin);
183        PIDT.Parameters.tau=1*'s';
184        PIDT.Parameters.tauSet=1*'s';   
185       
186        "Operating range for control variables"
187        Lmax=5*'m';
188        Lmin=0*'m';
189        Tmax=700*'K';
190        Tmin=230*'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.