/[ascend]/trunk/models/simpleflowsheet02.a4c
ViewVC logotype

Contents of /trunk/models/simpleflowsheet02.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 457 - (show annotations) (download) (as text)
Wed Apr 5 14:19:41 2006 UTC (13 years, 10 months ago) by aw0a
File MIME type: text/x-ascend
File size: 13453 byte(s)
modified 2_cis_hexene data in components.a4l, updated simpleflowsheetrigorous.a4c
1 REQUIRE "atoms.a4l";
2 (* => atoms.a4l, measures.a4l, system.a4l, basemodel.a4l *)
3 PROVIDE "simpleflowsheet02.a4c";
4 (*
5 * This file is part of the ASCEND Modeling Library and is released
6 * under the GNU Public License as described at the end of this file.
7 *
8 * Use of this module is demonstrated by the associated script file
9 * simpleflowsheet.a4s.
10 *)
11
12 (*
13
14 This file contains code to model the same flowsheet as
15
16 simpleflowsheet01.a4c
17
18 EXCEPT we have modified most of the models to be parameterized. We
19 strongly recommend creating parameterized models as they tend to be
20 much easier to reuse. The model simpleflowsheet01.a4c uses a modeling
21 style based on ARE_THE_SAME statements to configure the flowsheet, a
22 style that can often be easier to write initially. However, reuse is
23 not its strength.
24
25 We have included this model to aid new ASCEND users to understand
26 better how to write parameterized models.
27
28 ------------------------------------------------------------------
29
30 The following example illustrates equation based modeling using the
31 ASCEND system. The process is a simple recycle process.
32
33
34
35 -------
36 | |
37 ----------------------| split |----> purge
38 | | |
39 | -------
40 | ^
41 v |
42 ----- --------- -------
43 | | | | | |
44 ----->| mix |--->| reactor |--->| flash |
45 | | | | | |
46 ----- --------- -------
47 |
48 |
49 -----> C
50
51 This model requires: "system.a4l"
52 "atoms.a4l"
53 *)
54
55
56 (* ************************************************* *)
57
58
59 MODEL mixture(
60 components WILL_BE set OF symbol_constant;
61 );
62
63 (* Note: we now pass the set components into this model *)
64
65 y[components] IS_A fraction;
66 sumy: SUM[y[i] | i IN components] = 1.0;
67
68 METHODS
69
70 METHOD default_self;
71 END default_self;
72
73 METHOD specify;
74 y[components].fixed := TRUE;
75 y[CHOICE[components]].fixed := FALSE;
76 END specify;
77
78 METHOD reset;
79 RUN ClearAll;
80 RUN specify;
81 END reset;
82
83 END mixture;
84
85 (* ************************************************* *)
86
87
88 MODEL molar_stream(
89 components WILL_BE set OF symbol_constant;
90 );
91
92 (* Note: we now pass the set components into this model *)
93
94 state IS_A mixture(components);
95
96 (* and we pass it on into the defining of state. In this
97 manner we assure that the same set is used in both places
98 when defining the model. We had to use ARE_THE_SAME in
99 the earlier model to guarantee both used the same
100 components set.
101 *)
102
103 Ftot,f[components] IS_A molar_rate;
104
105 FOR i IN components CREATE
106 f_def[i]: f[i] = Ftot*state.y[i];
107 END FOR;
108
109 METHODS
110
111 METHOD default_self;
112 END default_self;
113
114 METHOD seqmod;
115 RUN state.specify;
116 state.y[components].fixed := FALSE;
117 END seqmod;
118
119 METHOD specify;
120 RUN seqmod;
121 f[components].fixed := TRUE;
122 END specify;
123
124 METHOD reset;
125 RUN ClearAll;
126 RUN specify;
127 END reset;
128
129 METHOD scale;
130 FOR i IN components DO
131 f[i].nominal := f[i] + 0.1{mol/s};
132 END FOR;
133 Ftot.nominal := Ftot + 0.1{mol/s};
134 END scale;
135
136 END molar_stream;
137
138 (* ************************************************* *)
139
140
141 MODEL mixer(
142 n_inputs WILL_BE integer_constant;
143 feed[1..n_inputs] WILL_BE molar_stream;
144 out WILL_BE molar_stream;
145 );
146
147 (* We pass all the streams into this model definition.
148 as opposed to defining them within this model.
149 *)
150
151
152 FOR i IN out.components CREATE
153 cmb[i]: out.f[i] = SUM[feed[1..n_inputs].f[i]];
154 END FOR;
155
156 METHODS
157
158 METHOD default_self;
159 END default_self;
160
161 METHOD seqmod;
162 END seqmod;
163
164 METHOD specify;
165 RUN seqmod;
166 RUN feed[1..n_inputs].specify;
167 END specify;
168
169 METHOD reset;
170 RUN ClearAll;
171 RUN specify;
172 END reset;
173
174 METHOD scale;
175 RUN feed[1..n_inputs].scale;
176 RUN out.scale;
177 END scale;
178
179 END mixer;
180
181 (* ************************************************* *)
182
183
184 MODEL reactor(
185 feed WILL_BE molar_stream;
186 out WILL_BE molar_stream;
187 );
188
189 turnover IS_A molar_rate;
190 stoich_coef[feed.components] IS_A factor;
191
192 FOR i IN feed.components CREATE
193 cmb[i]: out.f[i] = feed.f[i] + stoich_coef[i]*turnover;
194 END FOR;
195
196 METHODS
197
198 METHOD default_self;
199 END default_self;
200
201 METHOD seqmod;
202 turnover.fixed := TRUE;
203 stoich_coef[feed.components].fixed := TRUE;
204 END seqmod;
205
206 METHOD specify;
207 RUN seqmod;
208 RUN feed.specify;
209 END specify;
210
211 METHOD reset;
212 RUN ClearAll;
213 RUN specify;
214 END reset;
215
216 METHOD scale;
217 RUN feed.scale;
218 RUN out.scale;
219 turnover.nominal := turnover.nominal+0.0001 {kg_mole/s};
220 END scale;
221
222 END reactor;
223
224 (* ************************************************* *)
225
226
227 MODEL flash(
228 feed WILL_BE molar_stream;
229 vap WILL_BE molar_stream;
230 liq WILL_BE molar_stream;
231 );
232
233 alpha[feed.components],
234 ave_alpha IS_A factor;
235 vap_to_feed_ratio IS_A fraction;
236
237 VFratio: vap_to_feed_ratio*feed.Ftot = vap.Ftot;
238
239 FOR i IN feed.components CREATE
240 cmb[i]: feed.f[i] = vap.f[i] + liq.f[i];
241 eq[i]: vap.state.y[i]*ave_alpha = alpha[i]*liq.state.y[i];
242 END FOR;
243
244 METHODS
245
246 METHOD default_self;
247 END default_self;
248
249 METHOD seqmod;
250 alpha[feed.components].fixed := TRUE;
251 vap_to_feed_ratio.fixed := TRUE;
252 END seqmod;
253
254 METHOD specify;
255 RUN seqmod;
256 RUN feed.specify;
257 END specify;
258
259 METHOD reset;
260 RUN ClearAll;
261 RUN specify;
262 END reset;
263
264 METHOD scale;
265 RUN feed.scale;
266 RUN vap.scale;
267 RUN liq.scale;
268 END scale;
269
270 END flash;
271
272 (* ************************************************* *)
273
274
275 MODEL splitter(
276 n_outputs WILL_BE integer_constant;
277 feed WILL_BE molar_stream;
278 out[1..n_outputs] WILL_BE molar_stream;
279 );
280
281 split[1..n_outputs] IS_A fraction;
282
283 compsLessOne IS_A set OF symbol_constant;
284 compsLessOne :== feed.components - [CHOICE[feed.components]];
285
286 FOR j IN [1..n_outputs] CREATE
287 FOR i IN compsLessOne CREATE
288 splitState[j][i]: out[j].state.y[i] = feed.state.y[i];
289 END FOR;
290 cmb[j]: out[j].Ftot = split[j]*feed.Ftot;
291 END FOR;
292
293 sumSplits: SUM[split[1..n_outputs]] = 1.0;
294
295 METHODS
296
297 METHOD default_self;
298 END default_self;
299
300 METHOD seqmod;
301 split[1..n_outputs-1].fixed := TRUE;
302 END seqmod;
303
304 METHOD specify;
305 RUN seqmod;
306 RUN feed.specify;
307 END specify;
308
309 METHOD reset;
310 RUN ClearAll;
311 RUN specify;
312 END reset;
313
314 METHOD scale;
315 RUN feed.scale;
316 RUN out[1..n_outputs].scale;
317 END scale;
318
319 END splitter;
320
321 (* ************************************************* *)
322
323
324 MODEL flowsheet;
325
326 (*
327
328 It is in this model that the largest changes occur to create
329 parameterized models. We now define the set named components and all
330 the streams in this model and pass those definitions into the model
331 parts that require them. We do not and need not use any ARE_THE_SAME
332 statements.
333
334 Note in particular the use of the ALIASES statements below to allow
335 the two feeds to the mixer and the two output streams from the
336 splitter to be given array names as aliases. The mixer unit expects
337 to receive an array of n_inputs input streams. The splitter expects
338 an array of output streams. One of the inputs to the mixer is also
339 one of the outputs from the splitter. An array element such as a[1]
340 is simply the name for that element, to distinguish it from a[2].
341 Such naming does not imply contiguous storage.
342
343 *)
344
345
346
347 (* define sets *)
348
349 components IS_A set OF symbol_constant;
350 n_inputs, n_outputs IS_A integer_constant;
351 n_inputs :== 2;
352 n_outputs :== 2;
353
354 (* define streams *)
355
356 fsFeed,
357 recycle,
358 mixOut,
359 reactOut,
360 liqOut,
361 vapOut,
362 bleed IS_A molar_stream(components);
363
364 mixFeed[mixInputs] ALIASES (fsFeed,recycle)
365 WHERE mixInputs IS_A set OF integer_constant
366 WITH_VALUE (1..n_inputs);
367
368 splitOut[splitOutputs] ALIASES (bleed,recycle)
369 WHERE splitOutputs IS_A set OF integer_constant
370 WITH_VALUE (1..n_outputs);
371
372 (* define and wireup flowsheet *)
373 m1 IS_A mixer(n_inputs,mixFeed,mixOut);
374 r1 IS_A reactor(mixOut, reactOut);
375 fl1 IS_A flash(reactOut, vapOut, liqOut);
376 sp1 IS_A splitter(n_outputs, vapOut, splitOut);
377
378 METHODS
379
380 METHOD default_self;
381 END default_self;
382
383 METHOD seqmod;
384 RUN m1.seqmod;
385 RUN r1.seqmod;
386 RUN fl1.seqmod;
387 RUN sp1.seqmod;
388 END seqmod;
389
390 METHOD specify;
391 RUN seqmod;
392 RUN m1.feed[1].specify;
393 END specify;
394
395 METHOD reset;
396 RUN ClearAll;
397 RUN specify;
398 END reset;
399
400 METHOD scale;
401 RUN m1.scale;
402 RUN r1.scale;
403 RUN fl1.scale;
404 RUN sp1.scale;
405 END scale;
406
407 END flowsheet;
408
409 (* ************************************************* *)
410
411
412 MODEL controller;
413
414 fs IS_A flowsheet;
415 conv IS_A fraction;
416 key_components IS_A symbol_constant;
417
418 convControl: fs.r1.out.f[key_components] =
419 (1 - conv)*fs.r1.feed.f[key_components];
420
421 METHODS
422
423 METHOD default_self;
424 END default_self;
425
426 METHOD specify;
427 RUN fs.specify;
428 fs.r1.turnover.fixed := FALSE;
429 conv.fixed := TRUE;
430 END specify;
431
432 METHOD reset;
433 RUN ClearAll;
434 RUN specify;
435 END reset;
436
437 METHOD scale;
438 RUN fs.scale;
439 END scale;
440
441 END controller;
442
443 (* ************************************************* *)
444
445
446 MODEL test_flowsheet REFINES flowsheet;
447
448 components :== ['A','B','C'];
449
450 METHODS
451
452 METHOD default_self;
453 (* no-op. here to avoid STOP statement. *)
454 END default_self;
455
456 METHOD values;
457 m1.feed[1].f['A'] := 0.005 {kg_mole/s};
458 m1.feed[1].f['B'] := 0.095 {kg_mole/s};
459 m1.feed[1].f['C'] := 0.0 {kg_mole/s};
460
461 r1.stoich_coef['A'] := 0;
462 r1.stoich_coef['B'] := -1;
463 r1.stoich_coef['C'] := 1;
464
465 fl1.alpha['A'] := 12.0;
466 fl1.alpha['B'] := 10.0;
467 fl1.alpha['C'] := 1.0;
468 fl1.vap_to_feed_ratio := 0.9;
469 fl1.ave_alpha := 5.0;
470
471 sp1.split[1] := 0.01;
472
473 fl1.liq.Ftot := m1.feed[1].f['B'];
474 END values;
475
476 END test_flowsheet;
477
478 (* ************************************************* *)
479
480
481 MODEL test_controller REFINES controller;
482
483 fs IS_REFINED_TO test_flowsheet;
484 key_components :== 'B';
485
486 METHODS
487
488 METHOD default_self;
489 (* no-op. here to avoid STOP statement. *)
490 END default_self;
491
492 METHOD values;
493 RUN fs.values;
494 conv := 0.07;
495 END values;
496
497 END test_controller;
498
499
500 (*
501 * simpleflowsheet02.a4c
502 * by Arthur W. Westerberg
503 * Part of the ASCEND Library
504 * $Date: 2006/03/03 10:47:16 $
505 *
506 * This file is part of the ASCEND Modeling Library.
507 *
508 * Copyright (C) 1994 - 1998 Carnegie Mellon University
509 *
510 * The ASCEND Modeling Library is free software; you can redistribute
511 * it and/or modify it under the terms of the GNU General Public
512 * License as published by the Free Software Foundation; either
513 * version 2 of the License, or (at your option) any later version.
514 *
515 * The ASCEND Modeling Library is distributed in hope that it
516 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
517 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
518 * See the GNU General Public License for more details.
519 *
520 * You should have received a copy of the GNU General Public License
521 * along with the program; if not, write to the Free Software
522 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check
523 * the file named COPYING.
524 *)

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22