REQUIRE "atoms.a4l";
(* => atoms.a4l, measures.a4l, system.a4l, basemodel.a4l *)
PROVIDE "phaseq_comp.a4c";
(*
* This file is part of the ASCEND Modeling Library and is released
* under the GNU Public License as described at the end of this file.
*
* Use of this module is demonstrated by the associated script file
* phaseq_comp.a4s.
*)
(*
Ascend model of the phase Equilibrium example presented by Zaher
-- Conditional Modeling. Ph.D. Thesis, Carnegie Mellon University,
Pittsburgh, PA, 15213. 1995 --. The problem consists of a phase equilibrium
calculation of a multicomponent mixture. For each of the phases (3 phases
are possible: organic-liquid, inorganic-liquid, and vapor) there is a
disjunctive statement which represents whether the phase exists or not.
Each disjunctive statement is represented by using a complementarity
formulation, in such a way that we can solve the problem by using a
conventional nonlinear solver.
This model requires:
"system.a4l"
"atoms.a4l"
*)
(* ************************************************* *)
MODEL phaseq;
phases IS_A set OF symbol_constant;
components IS_A set OF symbol_constant;
k_terms IS_A set OF integer_constant;
z[components] IS_A fraction;
y[phases][components] IS_A fraction;
phi[phases] IS_A fraction;
exist[phases] IS_A boolean_var;
P IS_A pressure;
T IS_A temperature;
Pcr[components] IS_A pressure;
Tcr[components] IS_A temperature;
B[components][k_terms] IS_A factor;
C[k_terms] IS_A factor;
A[components][components] IS_A temperature;
h1[phases],h2[phases] IS_A fraction;
(* Definition of sets *)
components :== ['B','E','W'];
phases :== ['A','O','V'];
k_terms :== [1..4];
(* Complementarity Equations *)
FOR i IN phases CREATE
SUM[y[i][j] | j IN components ] = 1.0 - h1[i];
phi[i] = h2[i];
h1[i] * h2[i] = 0;
END FOR;
(* Invariant Equations *)
FOR i IN components CREATE
y['V'][i] = y['A'][i] * (Pcr[i]/P) * exp(
((1/T) *
SUM[ ( A[i][j] - (0.5*
SUM[ A[j][k] * y['A'][k] | k IN components]
) ) * y['A'][j]
| j IN components ]) +
((Tcr[i]/T) *
SUM[ B[i][k] * ( (1 - (T/Tcr[i]))^C[k] ) | k IN k_terms] ) );
y['V'][i] = y['O'][i] * (Pcr[i]/P) * exp(
((1/T) *
SUM[ ( A[i][j] - (0.5*
SUM[ A[j][k] * y['O'][k] | k IN components]
) ) * y['O'][j]
| j IN components ]) +
((Tcr[i]/T) *
SUM[ B[i][k] * ( (1 - (T/Tcr[i]))^C[k] ) | k IN k_terms] ) );
END FOR;
FOR i IN components CREATE
SUM[phi[j]*y[j][i] | j IN phases] = z[i];
END FOR;
METHODS
METHOD specify;
P.fixed := TRUE;
T.fixed := TRUE;
FOR i IN components DO
z[i].fixed := TRUE;
Pcr[i].fixed := TRUE;
Tcr[i].fixed := TRUE;
FOR j IN components DO
A[i][j].fixed := TRUE;
END FOR;
FOR j IN k_terms DO
B[i][j].fixed := TRUE;
END FOR;
END FOR;
FOR j IN k_terms DO
C[j].fixed := TRUE;
END FOR;
END specify;
METHOD bound_self;
FOR i IN components DO
FOR j IN components DO
A[i][j].lower_bound := 0 {K};
END FOR;
END FOR;
END bound_self;
METHOD default_self;
(* Constants *)
Tcr['B'] := 562.2 {K};
Tcr['E'] := 516.2 {K};
Tcr['W'] := 647.4 {K};
Pcr['B'] := 48.3 {atm};
Pcr['E'] := 63.0 {atm};
Pcr['W'] := 217.6 {atm};
C[1] := 1.0;
C[2] := 1.5;
C[3] := 3.0;
C[4] := 6.0;
A['B']['B'] := 0.0{K};
A['B']['E'] := 576.3 {K};
A['B']['W'] := 1074.5 {K};
A['E']['B'] := 576.3 {K};
A['E']['E'] := 0.0 {K};
A['E']['W'] := 351.8 {K};
A['W']['B'] := 1074.5 {K};
A['W']['E'] := 351.8 {K};
A['W']['W'] := 0.0 {K};
B['B'][1] := -6.98273;
B['B'][2] := 1.33213;
B['B'][3] := -2.62863;
B['B'][4] := -3.33399;
B['E'][1] := -8.51838;
B['E'][2] := 0.34163;
B['E'][3] := -5.73683;
B['E'][4] := 8.32581;
B['W'][1] := -7.76451;
B['W'][2] := 1.45838;
B['W'][3] := -2.77580;
B['W'][4] := -1.23303;
RUN bound_self;
END default_self;
METHOD values;
(* fixed *)
T := 340.0 {K};
P := 1.0 {atm};
z['B'] := 0.50;
z['E'] := 0.15;
z['W'] := 0.35;
(* initial values *)
y['A']['B'] := 0.02;
y['A']['E'] := 0.03;
y['A']['W'] := 0.95;
y['O']['B'] := 0.95;
y['O']['E'] := 0.03;
y['O']['W'] := 0.02;
y['V']['B'] := 0.50;
y['V']['E'] := 0.15;
y['V']['W'] := 0.35;
phi['A'] := 0.0;
phi['O'] := 0.0;
phi['V'] := 0.0;
END values;
END phaseq;
(*
* phaseq_comp.a4c
* by Vicente Rico-Ramirez
* April 10, 1998
* Part of the ASCEND Library
* $Date: 1998/06/17 19:13:37 $
* $Revision: 1.3 $
* $Author: mthomas $
* $Source: /afs/cs.cmu.edu/project/ascend/Repository/models/phaseq_comp.a4c,v $
*
* This file is part of the ASCEND Modeling Library.
*
* Copyright (C) 1998 Carnegie Mellon University
*
* The ASCEND Modeling Library is free software; you can redistribute
* it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* The ASCEND Modeling Library is distributed in hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check
* the file named COPYING.
*)