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

Contents of /trunk/models/simpleflowsheet01.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 691 - (show annotations) (download) (as text)
Thu Jun 22 01:14:09 2006 UTC (14 years ago) by johnpye
File MIME type: text/x-ascend
File size: 9993 byte(s)
Added on_load and self_test to simpleflowsheet01.a4c.
Hopefully the value I selected to test for is OK?
1 REQUIRE "atoms.a4l";
2 (* => atoms.a4l, measures.a4l, system.a4l, basemodel.a4l *)
3 PROVIDE "simpleflowsheet01.a4c";
4
5 (*
6 * simpleflowsheet01.a4c
7 * by Arthur W. Westerberg
8 * Part of the ASCEND Library
9 * $Date: 2006/04/10 10:08:42 $
10 * $Revision: 1.95 $
11 * $Author: a.westerberg $
12 *
13 * This file is part of the ASCEND Modeling Library.
14 *
15 * Copyright (C) 1998 Carnegie Mellon University
16 *
17 * The ASCEND Modeling Library is free software; you can redistribute
18 * it and/or modify it under the terms of the GNU General Public
19 * License as published by the Free Software Foundation; either
20 * version 2 of the License, or (at your option) any later version.
21 *
22 * The ASCEND Modeling Library is distributed in hope that it
23 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
24 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25 * See the GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with the program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check
30 * the file named COPYING.
31 *)
32
33
34 (*
35
36 The following example illustrates equation based modeling using the
37 ASCEND system. The process is a simple recycle process.
38
39
40
41 -------
42 | |
43 ----------------------| split |----> purge
44 | | |
45 | -------
46 | ^
47 v |
48 ----- --------- -------
49 | | | | | |
50 ----->| mix |--->| reactor |--->| flash |
51 | | | | | |
52 ----- --------- -------
53 |
54 |
55 -----> C
56
57 This model requires: "system.a4l"
58 "atoms.a4l"
59 *)
60
61
62 (* ************************************************* *)
63
64
65 MODEL mixture;
66
67 components IS_A set OF symbol_constant;
68 y[components] IS_A fraction;
69
70 SUM[y[i] | i IN components] = 1.0;
71
72 METHODS
73
74 METHOD default_self;
75 END default_self;
76
77 METHOD specify;
78 FIX y[components];
79 FREE y[CHOICE[components]];
80 END specify;
81
82 METHOD reset;
83 RUN ClearAll;
84 RUN specify;
85 END reset;
86
87 END mixture;
88
89 (* ************************************************* *)
90
91
92 MODEL molar_stream;
93
94 components IS_A set OF symbol_constant;
95 state IS_A mixture;
96 Ftot,f[components] IS_A molar_rate;
97
98 components, state.components ARE_THE_SAME;
99
100
101 FOR i IN components CREATE
102 f_def[i]: f[i] = Ftot*state.y[i];
103 END FOR;
104
105 METHODS
106
107 METHOD default_self;
108 END default_self;
109
110 METHOD seqmod;
111 RUN state.specify;
112 FREE state.y[components];
113 END seqmod;
114
115 METHOD specify;
116 RUN seqmod;
117 FIX f[components];
118 END specify;
119
120 METHOD reset;
121 RUN ClearAll;
122 RUN specify;
123 END reset;
124
125 METHOD scale;
126 FOR i IN components DO
127 f[i].nominal := f[i] + 0.1{mol/s};
128 END FOR;
129 Ftot.nominal := Ftot + 0.1{mol/s};
130 END scale;
131
132 END molar_stream;
133
134 (* ************************************************* *)
135
136
137 MODEL mixer;
138
139 n_inputs IS_A integer_constant;
140 feed[1..n_inputs], out IS_A molar_stream;
141
142 feed[1..n_inputs].components,
143 out.components ARE_THE_SAME;
144
145 FOR i IN out.components CREATE
146 cmb[i]: out.f[i] = SUM[feed[1..n_inputs].f[i]];
147 END FOR;
148
149 METHODS
150
151 METHOD default_self;
152 END default_self;
153
154 METHOD seqmod;
155 END seqmod;
156
157 METHOD specify;
158 RUN seqmod;
159 RUN feed[1..n_inputs].specify;
160 END specify;
161
162 METHOD reset;
163 RUN ClearAll;
164 RUN specify;
165 END reset;
166
167 METHOD scale;
168 RUN feed[1..n_inputs].scale;
169 RUN out.scale;
170 END scale;
171
172 END mixer;
173
174 (* ************************************************* *)
175
176
177 MODEL reactor;
178
179 feed, out IS_A molar_stream;
180 feed.components, out.components ARE_THE_SAME;
181
182 turnover IS_A molar_rate;
183 stoich_coef[feed.components] IS_A factor;
184
185 FOR i IN feed.components CREATE
186 out.f[i] = feed.f[i] + stoich_coef[i]*turnover;
187 END FOR;
188
189 METHODS
190
191 METHOD default_self;
192 END default_self;
193
194 METHOD seqmod;
195 FIX turnover;
196 FIX stoich_coef[feed.components];
197 END seqmod;
198
199 METHOD specify;
200 RUN seqmod;
201 RUN feed.specify;
202 END specify;
203
204 METHOD reset;
205 RUN ClearAll;
206 RUN specify;
207 END reset;
208
209 METHOD scale;
210 RUN feed.scale;
211 RUN out.scale;
212 turnover.nominal := turnover.nominal+0.0001 {kg_mole/s};
213 END scale;
214
215 END reactor;
216
217 (* ************************************************* *)
218
219
220 MODEL flash;
221
222 feed,vap,liq IS_A molar_stream;
223
224 feed.components,
225 vap.components,
226 liq.components ARE_THE_SAME;
227
228 alpha[feed.components],
229 ave_alpha IS_A factor;
230
231 vap_to_feed_ratio IS_A fraction;
232
233 vap_to_feed_ratio*feed.Ftot = vap.Ftot;
234
235 FOR i IN feed.components CREATE
236 cmb[i]: feed.f[i] = vap.f[i] + liq.f[i];
237 eq[i]: vap.state.y[i]*ave_alpha = alpha[i]*liq.state.y[i];
238 END FOR;
239
240 METHODS
241
242 METHOD default_self;
243 END default_self;
244
245 METHOD seqmod;
246 FIX alpha[feed.components];
247 FIX vap_to_feed_ratio;
248 END seqmod;
249
250 METHOD specify;
251 RUN seqmod;
252 RUN feed.specify;
253 END specify;
254
255 METHOD reset;
256 RUN ClearAll;
257 RUN specify;
258 END reset;
259
260 METHOD scale;
261 RUN feed.scale;
262 RUN vap.scale;
263 RUN liq.scale;
264 END scale;
265
266 END flash;
267
268 (* ************************************************* *)
269
270
271 MODEL splitter;
272
273 n_outputs IS_A integer_constant;
274 feed, out[1..n_outputs] IS_A molar_stream;
275 split[1..n_outputs] IS_A fraction;
276
277 feed.components, out[1..n_outputs].components ARE_THE_SAME;
278
279 feed.state,
280 out[1..n_outputs].state ARE_THE_SAME;
281
282 FOR j IN [1..n_outputs] CREATE
283 out[j].Ftot = split[j]*feed.Ftot;
284 END FOR;
285
286 SUM[split[1..n_outputs]] = 1.0;
287
288 METHODS
289
290 METHOD default_self;
291 END default_self;
292
293 METHOD seqmod;
294 FIX split[1..n_outputs-1];
295 END seqmod;
296
297 METHOD specify;
298 RUN seqmod;
299 RUN feed.specify;
300 END specify;
301
302 METHOD reset;
303 RUN ClearAll;
304 RUN specify;
305 END reset;
306
307 METHOD scale;
308 RUN feed.scale;
309 RUN out[1..n_outputs].scale;
310 END scale;
311
312 END splitter;
313
314 (* ************************************************* *)
315
316
317 MODEL flowsheet;
318
319 m1 IS_A mixer;
320 r1 IS_A reactor;
321 fl1 IS_A flash;
322 sp1 IS_A splitter;
323
324 (* define sets *)
325
326 m1.n_inputs :== 2;
327 sp1.n_outputs :== 2;
328
329 (* wire up flowsheet *)
330
331 m1.out, r1.feed ARE_THE_SAME;
332 r1.out, fl1.feed ARE_THE_SAME;
333 fl1.vap, sp1.feed ARE_THE_SAME;
334 sp1.out[2], m1.feed[2] ARE_THE_SAME;
335
336 METHODS
337
338 METHOD default_self;
339 END default_self;
340
341 METHOD seqmod;
342 RUN m1.seqmod;
343 RUN r1.seqmod;
344 RUN fl1.seqmod;
345 RUN sp1.seqmod;
346 END seqmod;
347
348 METHOD specify;
349 RUN seqmod;
350 RUN m1.feed[1].specify;
351 END specify;
352
353 METHOD reset;
354 RUN ClearAll;
355 RUN specify;
356 END reset;
357
358 METHOD scale;
359 RUN m1.scale;
360 RUN r1.scale;
361 RUN fl1.scale;
362 RUN sp1.scale;
363 END scale;
364
365 END flowsheet;
366
367 (* ************************************************* *)
368
369
370 MODEL controller;
371
372 fs IS_A flowsheet;
373 conv IS_A fraction;
374 key_components IS_A symbol_constant;
375 fs.r1.out.f[key_components] = (1 - conv)*fs.r1.feed.f[key_components];
376
377 METHODS
378
379 METHOD default_self;
380 END default_self;
381
382 METHOD specify;
383 RUN fs.specify;
384 FREE fs.r1.turnover;
385 FIX conv;
386 END specify;
387
388 METHOD reset;
389 RUN ClearAll;
390 RUN specify;
391 END reset;
392
393 METHOD scale;
394 RUN fs.scale;
395 END scale;
396
397 END controller;
398
399 (* ************************************************* *)
400
401
402 MODEL test_flowsheet REFINES flowsheet;
403
404 m1.out.components :== ['A','B','C'];
405
406 METHODS
407
408 METHOD default_self;
409 (* no-op. here to avoid STOP statement. *)
410 END default_self;
411
412 METHOD values;
413 m1.feed[1].f['A'] := 0.005 {kg_mole/s};
414 m1.feed[1].f['B'] := 0.095 {kg_mole/s};
415 m1.feed[1].f['C'] := 0.0 {kg_mole/s};
416
417 r1.stoich_coef['A'] := 0;
418 r1.stoich_coef['B'] := -1;
419 r1.stoich_coef['C'] := 1;
420
421 fl1.alpha['A'] := 12.0;
422 fl1.alpha['B'] := 10.0;
423 fl1.alpha['C'] := 1.0;
424 fl1.vap_to_feed_ratio := 0.9;
425 fl1.ave_alpha := 5.0;
426
427 sp1.split[1] := 0.01;
428
429 fl1.liq.Ftot := m1.feed[1].f['B'];
430 END values;
431
432 END test_flowsheet;
433
434 (* ************************************************* *)
435
436
437 MODEL test_controller REFINES controller;
438
439 fs IS_REFINED_TO test_flowsheet;
440 key_components :== 'B';
441
442 METHODS
443
444 METHOD default_self;
445 (* no-op. here to avoid STOP statement. *)
446 END default_self;
447
448 METHOD values;
449 RUN fs.values;
450 conv := 0.07;
451 END values;
452
453 METHOD on_load;
454 RUN default_self;
455 RUN reset;
456 RUN values;
457 END on_load;
458
459 METHOD self_test;
460 ASSERT abs(fs.m1.feed[2].f['C'] - 88.43978 {mol/s})< 0.0002 {mol/s};
461 END self_test;
462
463 END test_controller;
464
465
466 (*
467 * simpleflowsheet01.a4c
468 * by Arthur W. Westerberg
469 * Part of the ASCEND Library
470 * $Date: 2006.03.03 10:29:34
471 *
472 * This file is part of the ASCEND Modeling Library.
473 *
474 * Copyright (C) 1994 - 1998 Carnegie Mellon University
475 *
476 * The ASCEND Modeling Library is free software; you can redistribute
477 * it and/or modify it under the terms of the GNU General Public
478 * License as published by the Free Software Foundation; either
479 * version 2 of the License, or (at your option) any later version.
480 *
481 * The ASCEND Modeling Library is distributed in hope that it
482 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
483 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
484 * See the GNU General Public License for more details.
485 *
486 * You should have received a copy of the GNU General Public License
487 * along with the program; if not, write to the Free Software
488 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check
489 * the file named COPYING.
490 *)

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