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

Contents of /trunk/models/phaseq.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1257 - (show annotations) (download) (as text)
Sun Jan 28 01:30:08 2007 UTC (12 years, 10 months ago) by johnpye
File MIME type: text/x-ascend
File size: 5470 byte(s)
Fixed the bounding problem in Slv9.
Added python test cases for all of the models in Vicente's thesis.
Will now add these tests to buildbot.
1 (* ASCEND modelling environment
2 Copyright (C) 1998, 2007 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 *)
19 REQUIRE "atoms.a4l";
20 (*
21 The following the conditional model is discussed in the PhD thesis of
22 Vicente Rico-Ramirez,
23 https://pse.cheme.cmu.edu/ascend/ftp/pdfThesis/victhesis.pdf
24
25 The original problem was presented by Joe Zaher
26
27 Zaher, Conditional Modeling. Ph.D. Thesis, Carnegie Mellon University,
28 Pittsburgh, PA. 1995.
29
30 The problem consists of a phase equilibrium calculation of a
31 multicomponent mixture. For each of the phases (3 phases are possible:
32 organic-liquid, inorganic-liquid, and vapor) there is a disjunctive
33 statement which represents whether the phase exists or not. It represents
34 a problem which we can represent as a conditional model and solve with
35 the ASCEND conditional solver, CMSlv.
36
37 by Vicente Rico-Ramirez, April 10, 1998
38 *)
39
40 MODEL phaseq;
41
42 phases IS_A set OF symbol_constant;
43 components IS_A set OF symbol_constant;
44 k_terms IS_A set OF integer_constant;
45 z[components] IS_A fraction;
46 y[phases][components] IS_A fraction;
47 phi[phases] IS_A fraction;
48 exist[phases] IS_A boolean_var;
49 P IS_A pressure;
50 T IS_A temperature;
51 Pcr[components] IS_A critical_pressure;
52 Tcr[components] IS_A critical_temperature;
53 B[components][k_terms] IS_A factor_constant;
54 C[k_terms] IS_A factor_constant;
55 A[components][components] IS_A temperature_constant;
56
57 (* Definition os sets *)
58
59 components :== ['B','E','W'];
60 phases :== ['A','O','V'];
61 k_terms :== [1..4];
62
63 (* Boundaries *)
64 CONDITIONAL
65 FOR i IN phases CREATE
66 cond[i]: SUM[y[i][j] | j IN components ]+ phi[i] >= 1.0;
67 END FOR;
68 END CONDITIONAL;
69
70
71 FOR i IN phases CREATE
72 (* Variant Equations *)
73 sum[i]: SUM[y[i][j] | j IN components ] = 1.0;
74 frac[i]: phi[i] = 0.0;
75 exist[i] == SATISFIED(cond[i],1e-08);
76 (* Disjunctive statement *)
77 WHEN (exist[i])
78 CASE TRUE:
79 USE sum[i];
80 CASE FALSE:
81 USE frac[i];
82 END WHEN;
83
84 END FOR;
85
86 (* Invariant Equations *)
87
88 FOR i IN components CREATE
89 y['V'][i] = y['A'][i] * (Pcr[i]/P) * exp(
90 ((1/T) *
91 SUM[ ( A[i][j] - (0.5*
92 SUM[ A[j][k] * y['A'][k] | k IN components]
93 ) ) * y['A'][j]
94 | j IN components ]) +
95 ((Tcr[i]/T) *
96 SUM[ B[i][k] * ( (1 - (T/Tcr[i]))^C[k] ) | k IN k_terms] ) );
97
98 y['V'][i] = y['O'][i] * (Pcr[i]/P) * exp(
99 ((1/T) *
100 SUM[ ( A[i][j] - (0.5*
101 SUM[ A[j][k] * y['O'][k] | k IN components]
102 ) ) * y['O'][j]
103 | j IN components ]) +
104 ((Tcr[i]/T) *
105 SUM[ B[i][k] * ( (1 - (T/Tcr[i]))^C[k] ) | k IN k_terms] ) );
106 END FOR;
107
108 FOR i IN components CREATE
109 SUM[phi[j]*y[j][i] | j IN phases] = z[i];
110 END FOR;
111
112 (* Constants *)
113 Tcr['B'] :== 562.2 {K};
114 Tcr['E'] :== 516.2 {K};
115 Tcr['W'] :== 647.4 {K};
116 Pcr['B'] :== 48.3 {atm};
117 Pcr['E'] :== 63.0 {atm};
118 Pcr['W'] :== 217.6 {atm};
119 C[1] :== 1.0;
120 C[2] :== 1.5;
121 C[3] :== 3.0;
122 C[4] :== 6.0;
123 A['B']['B'] :== 0.0{K};
124 A['B']['E'] :== 576.3 {K};
125 A['B']['W'] :== 1074.5 {K};
126 A['E']['B'] :== 576.3 {K};
127 A['E']['E'] :== 0.0 {K};
128 A['E']['W'] :== 351.8 {K};
129 A['W']['B'] :== 1074.5 {K};
130 A['W']['E'] :== 351.8 {K};
131 A['W']['W'] :== 0.0 {K};
132 B['B'][1] :== -6.98273;
133 B['B'][2] :== 1.33213;
134 B['B'][3] :== -2.62863;
135 B['B'][4] :== -3.33399;
136 B['E'][1] :== -8.51838;
137 B['E'][2] :== 0.34163;
138 B['E'][3] :== -5.73683;
139 B['E'][4] :== 8.32581;
140 B['W'][1] :== -7.76451;
141 B['W'][2] :== 1.45838;
142 B['W'][3] :== -2.77580;
143 B['W'][4] :== -1.23303;
144
145 METHODS
146
147 METHOD default_self;
148 END default_self;
149
150 METHOD specify;
151 FIX P;
152 FIX T;
153 FOR i IN components DO
154 FIX z[i];
155 END FOR;
156 END specify;
157
158 METHOD values;
159 (* fixed *)
160 T := 340.0 {K};
161 P := 1.0 {atm};
162 z['B'] := 0.50;
163 z['E'] := 0.15;
164 z['W'] := 0.35;
165 (* initial values for reals *)
166 y['A']['B'] := 0.02;
167 y['A']['E'] := 0.03;
168 y['A']['W'] := 0.95;
169
170 y['O']['B'] := 0.95;
171 y['O']['E'] := 0.03;
172 y['O']['W'] := 0.02;
173
174 y['V']['B'] := 0.50;
175 y['V']['E'] := 0.15;
176 y['V']['W'] := 0.35;
177
178 phi['A'] := 0.0;
179 phi['O'] := 0.0;
180 phi['V'] := 0.0;
181
182 (* initial values for booleans *)
183 FOR i IN phases DO
184 exist[i] := SATISFIED(cond[i],1e-08);
185 END FOR;
186 END values;
187
188 METHOD on_load;
189 RUN default_self;
190 RUN reset;
191 RUN values;
192 END on_load;
193
194 METHOD self_test;
195 (* not tests yet *)
196 END self_test;
197
198
199 END phaseq;

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