TomSym Chemical Equilibrium Problem: Difference between revisions

From TomWiki
Jump to navigationJump to search
No edit summary
No edit summary
 
Line 1: Line 1:
{{Part Of Manual|title=the TomSym Manual|link=[[TomSym|TomSym Manual]]}}
{{Part Of Manual|title=the TomSym Manual|link=[[TomSym|TomSym Manual]]}}


TomSym implementation of GAMS Example (CHEM,SEQ=21)
TomSym implementation of GAMS Example (WALL,SEQ=76)


The problem is to find the equilibrium composition of a mixture of different atoms.
A Sample Nonlinear system to solve Chemical Equilibrium models.


Bracken, J, and McCormick, G P, Chapter 5. In Selected Applications of Nonlinear Programming. John Wiley and Sons, New York, 1968, pp. 48-49.
Wall, T W, Greening, D, and Woolsey, R E D, Solving Complex Chemical Equilibria Using a Geometric-Programming Based Technique. OR 34, 3 (1987).
 
c: compounds (H, H2, H2O, N, N2, NH, NO, O, O2, OH)
 
i: atoms (H  hydrogen, N  nitrogen, O  oxygen)


<source lang="matlab">
<source lang="matlab">
% Parameters
toms ba so4 baoh oh hso4 h
 
% Atoms per compound
a = [1  2    2  0  0  1  0  0  0  1;
    0  0    0  1  2  1  1  0  0  0;
    0  0    1  0  0  0  1  1  2  1];
 
% Number of elements in mixture
h=2; n=1; o=1;
mix = [h n o]';
 
% Gibbs free energy at 3500 k and 750 psi
gibbs = [-10.021; -21.096; -37.986; -9.846; -28.653; ...
    -18.918; -28.032; -14.640; -30.594; -26.11];
 
% Gibbs energy plus pressure
gplusp = gibbs + log(750*0.07031);
 
% Variables
 
% Number of mols in mixture
toms 10x1 x
 
% Component definition
eq1 = {};
for i=1:length(mix)
    eq1 = {eq1; sum(a(i,:)*x) == mix(i)};
end


% Energy definition (xb = total number of mols in mixture)
r1 = {ba*so4 == 1};
xb = sum(x);
r2 = {baoh/ba/oh == 4.8};
r3 = {hso4/so4/h == .98};
r4 = {h*oh == 1};


% Total free energy in mixture
b1 = {ba + 1e-7*baoh == so4 + 1e-5*hso4};
energy = sum(x.*(gplusp + log((x)/xb)));
b2 = {2*ba + 1e-7*baoh + 1e-2*h == 2*so4 + 1e-5*hso4 + 1e-2*oh};


% Bounds on x and xb
x0 = {1 == ba; 1 == so4; 1 == baoh
cbnd = {0.001 <= x; 0.01 <= xb};
    1 == oh; 1 == hso4; 1 == h };


solution = ezsolve(energy,{eq1, cbnd});
solution = ezsolve(ba,{r1,r2,r3,r4,b1,b2},x0);
</source>
</source>


<pre>
<pre>
Problem type appears to be: con
Problem type appears to be: lpcon
Time for symbolic processing: 0.074995 seconds
Time for symbolic processing: 0.13614 seconds
Starting numeric solver
Starting numeric solver
===== * * * =================================================================== * * *
===== * * * =================================================================== * * *
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31
=====================================================================================
=====================================================================================
Problem: ---  1: Problem 1                      f_k     -47.706514830836568000
Problem: ---  1: Problem 1                      f_k       1.000004657593424700
                                       sum(|constr|)      0.000000000000000666
                                       sum(|constr|)      0.000000000000846878
                               f(x_k) + sum(|constr|)   -47.706514830836568000
                               f(x_k) + sum(|constr|)     1.000004657594271600
                                               f(x_0)     -0.209269531292347570
                                               f(x_0)     1.000000000000000000


Solver: snopt.  EXIT=0.  INFORM=1.
Solver: snopt.  EXIT=0.  INFORM=1.
Line 69: Line 40:
Optimality conditions satisfied
Optimality conditions satisfied


FuncEv   26 GradEv  24 Iter   15 MinorIter   37
FuncEv   1 ConstrEv    4 ConJacEv    4 Iter   3 MinorIter   5
CPU time: 0.015600 sec. Elapsed time: 0.014000 sec.  
Elapsed time: 0.008000 sec.  


</pre>
</pre>

Latest revision as of 08:48, 9 November 2011

Notice.png

This page is part of the TomSym Manual. See TomSym Manual.

TomSym implementation of GAMS Example (WALL,SEQ=76)

A Sample Nonlinear system to solve Chemical Equilibrium models.

Wall, T W, Greening, D, and Woolsey, R E D, Solving Complex Chemical Equilibria Using a Geometric-Programming Based Technique. OR 34, 3 (1987).

toms ba so4 baoh oh hso4 h

r1 = {ba*so4 == 1};
r2 = {baoh/ba/oh == 4.8};
r3 = {hso4/so4/h == .98};
r4 = {h*oh == 1};

b1 = {ba + 1e-7*baoh == so4 + 1e-5*hso4};
b2 = {2*ba + 1e-7*baoh + 1e-2*h == 2*so4 + 1e-5*hso4 + 1e-2*oh};

x0 = {1 == ba; 1 == so4; 1 == baoh
    1 == oh; 1 == hso4; 1 == h };

solution = ezsolve(ba,{r1,r2,r3,r4,b1,b2},x0);
Problem type appears to be: lpcon
Time for symbolic processing: 0.13614 seconds
Starting numeric solver
===== * * * =================================================================== * * *
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31
=====================================================================================
Problem: ---  1: Problem 1                      f_k       1.000004657593424700
                                       sum(|constr|)      0.000000000000846878
                              f(x_k) + sum(|constr|)      1.000004657594271600
                                              f(x_0)      1.000000000000000000

Solver: snopt.  EXIT=0.  INFORM=1.
SNOPT 7.2-5 NLP code
Optimality conditions satisfied

FuncEv    1 ConstrEv    4 ConJacEv    4 Iter    3 MinorIter    5
Elapsed time: 0.008000 sec.