1 | #*--------------------------------------------------------------------- |
---|
2 | * EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC. |
---|
3 | * |
---|
4 | * This LIBRARY is free software; you can distribute it and/or modify |
---|
5 | * it under the therms of the ALSOC FREE LICENSE as available at |
---|
6 | * http://www.enq.ufrgs.br/alsoc. |
---|
7 | * |
---|
8 | * EMSO Copyright (C) 2004 - 2007 ALSOC, original code |
---|
9 | * from http://www.rps.eng.br Copyright (C) 2002-2004. |
---|
10 | * All rights reserved. |
---|
11 | * |
---|
12 | * EMSO is distributed under the therms of the ALSOC LICENSE as |
---|
13 | * available at http://www.enq.ufrgs.br/alsoc. |
---|
14 | * |
---|
15 | *---------------------------------------------------------------------- |
---|
16 | * Model of a Gibbs reactor |
---|
17 | *---------------------------------------------------------------------- |
---|
18 | * |
---|
19 | * Description: |
---|
20 | |
---|
21 | * Thermodynamic equilibrium modeling of a reactor using Gibbs |
---|
22 | * free energy minimization approach. |
---|
23 | |
---|
24 | * |
---|
25 | |
---|
26 | * Assumptions: |
---|
27 | |
---|
28 | * * thermodynamic equilibrium |
---|
29 | |
---|
30 | * * steady-state |
---|
31 | |
---|
32 | * |
---|
33 | |
---|
34 | * Specify: |
---|
35 | |
---|
36 | * * inlet stream |
---|
37 | * * number of elements related to components |
---|
38 | |
---|
39 | * * matrix of elements by components |
---|
40 | |
---|
41 | * * equilibrium temperature |
---|
42 | * |
---|
43 | *---------------------------------------------------------------------- |
---|
44 | * Author: Rodolfo Rodrigues |
---|
45 | * $Id$ |
---|
46 | *--------------------------------------------------------------------*# |
---|
47 | |
---|
48 | using "tank_basic"; |
---|
49 | |
---|
50 | |
---|
51 | #*--------------------------------------------------------------------- |
---|
52 | * only vapour phase |
---|
53 | *--------------------------------------------------------------------*# |
---|
54 | Model gibbs_vap as tank_vap |
---|
55 | ATTRIBUTES |
---|
56 | Pallete = true; |
---|
57 | Icon = "icon/cstr"; |
---|
58 | Brief = "Model of a generic vapour-phase Gibbs CSTR"; |
---|
59 | Info = " |
---|
60 | Requires the information of: |
---|
61 | * number of elements |
---|
62 | * matrix of elements (elements by compoments) |
---|
63 | "; |
---|
64 | |
---|
65 | PARAMETERS |
---|
66 | outer NElem as Integer (Brief="Number of elements", Default=1); |
---|
67 | Rg as Real (Brief="Universal gas constant", Unit='J/mol/K', Default=8.314); |
---|
68 | na(NElem,NComp) as Real (Brief="Number of elements per component"); |
---|
69 | fs(NComp) as pressure (Brief="Fugacity in standard state", Default=1, DisplayUnit='atm'); |
---|
70 | To as temperature (Brief="Reference temperature", Default=298.15); |
---|
71 | |
---|
72 | VARIABLES |
---|
73 | out Outlet as vapour_stream; # Outlet stream |
---|
74 | |
---|
75 | G(NComp) as energy_mol (Brief="Gibbs free-energy change of formation"); |
---|
76 | lambda(NElem) as energy_mol (Brief="Lagrangian multiplier"); |
---|
77 | activ(NComp) as Real (Brief="Activity", Lower=1e-20); |
---|
78 | phi(NComp) as fugacity (Brief="Fugacity coefficient", Default=1); |
---|
79 | |
---|
80 | rate(NComp) as reaction_mol (Brief="Overall component rate of reaction"); |
---|
81 | conv(NComp) as Real (Brief="Fractional conversion of component", Default=0); |
---|
82 | Fi(NComp) as flow_mol (Brief="Component molar flow rate"); |
---|
83 | |
---|
84 | EQUATIONS |
---|
85 | "Outlet stream" |
---|
86 | Outlet.F*Outlet.z = Outletm.F*Outletm.z + rate*V; |
---|
87 | |
---|
88 | "Mechanical equilibrium" |
---|
89 | Outlet.P = Outletm.P; |
---|
90 | |
---|
91 | "Steady-state" |
---|
92 | Outlet.F = sum(Fi); |
---|
93 | |
---|
94 | "Component molar flow rate" |
---|
95 | Fi = Outlet.F*Outlet.z; |
---|
96 | |
---|
97 | "Energy balance" |
---|
98 | Outlet.F*Outlet.h = Outletm.F*Outletm.h; |
---|
99 | |
---|
100 | "Element balance" |
---|
101 | sumt(Fi*na) = sumt(Outletm.F*Outletm.z*na); |
---|
102 | |
---|
103 | "Gibbs free-energy of formation" |
---|
104 | G = PP.IdealGasGibbsOfFormation(Outlet.T); |
---|
105 | |
---|
106 | # "Gibbs free-energy of formation without Cp correction" |
---|
107 | # G = PP.IdealGasGibbsOfFormationAt25C()*Outlet.T/To+PP.IdealGasEnthalpyOfFormationAt25C()*(1-Outlet.T/To); |
---|
108 | |
---|
109 | for i in [1:NComp] |
---|
110 | "Lagrangian multiplier" |
---|
111 | G(i) + sumt(lambda*na(:,i)) = -Rg*Outlet.T*ln(activ(i)); |
---|
112 | |
---|
113 | if (Outletm.z(i) > 0) then |
---|
114 | "Molar conversion" |
---|
115 | Fi(i) = Outletm.F*Outletm.z(i)*(1 - conv(i)); |
---|
116 | else if (Outlet.z(i) > 0) then |
---|
117 | "Molar conversion" |
---|
118 | conv(i) = 1; # ? |
---|
119 | else |
---|
120 | "Molar conversion" |
---|
121 | conv(i) = 0; # ? |
---|
122 | end |
---|
123 | end |
---|
124 | |
---|
125 | end |
---|
126 | |
---|
127 | "Fugacity coefficient" |
---|
128 | phi = PP.VapourFugacityCoefficient(Outlet.T,Outlet.P,Outlet.z); |
---|
129 | |
---|
130 | "Activity" |
---|
131 | activ = phi*Outlet.P*Outlet.z/fs; |
---|
132 | end |
---|
133 | |
---|
134 | |
---|
135 | #*--------------------------------------------------------------------- |
---|
136 | * only liquid phase |
---|
137 | *--------------------------------------------------------------------*# |
---|
138 | Model gibbs_liq as tank_liq |
---|
139 | ATTRIBUTES |
---|
140 | Pallete = true; |
---|
141 | Icon = "icon/cstr"; |
---|
142 | Brief = "Model of a generic liquid-phase Gibbs CSTR"; |
---|
143 | Info = " |
---|
144 | Requires the information of: |
---|
145 | * number of elements |
---|
146 | * matrix of elements (elements by compoments) |
---|
147 | "; |
---|
148 | |
---|
149 | PARAMETERS |
---|
150 | outer NElem as Integer (Brief="Number of elements", Default=1); |
---|
151 | Rg as Real (Brief="Universal gas constant", Unit='J/mol/K', Default=8.314); |
---|
152 | na(NElem,NComp) as Real (Brief="Number of elements per component"); |
---|
153 | Ps as pressure (Brief="Pressure of standard state", Default=1, DisplayUnit='atm'); |
---|
154 | To as temperature (Brief="Reference temperature", Default=298.15); |
---|
155 | |
---|
156 | VARIABLES |
---|
157 | out Outlet as liquid_stream; # Outlet stream |
---|
158 | |
---|
159 | G(NComp) as energy_mol (Brief="Gibbs free-energy change of formation"); |
---|
160 | lambda(NElem) as energy_mol (Brief="Lagrangian multiplier"); |
---|
161 | activ(NComp) as Real (Brief="Activity", Lower=0); |
---|
162 | gamma(NComp) as fugacity (Brief="Activity coefficient", Default=1); |
---|
163 | |
---|
164 | rate(NComp) as reaction_mol (Brief="Overall component rate of reaction"); |
---|
165 | conv(NComp) as Real (Brief="Fractional conversion of component", Default=0); |
---|
166 | Fi(NComp) as flow_mol (Brief="Component molar flow rate"); |
---|
167 | |
---|
168 | EQUATIONS |
---|
169 | "Outlet stream" |
---|
170 | Outlet.F*Outlet.z = Outletm.F*Outletm.z + rate*V; |
---|
171 | |
---|
172 | "Mechanical equilibrium" |
---|
173 | Outlet.P = Outletm.P; |
---|
174 | |
---|
175 | "Steady-state" |
---|
176 | Outlet.F = sum(Fi); |
---|
177 | |
---|
178 | "Component molar flow rate" |
---|
179 | Fi = Outlet.F*Outlet.z; |
---|
180 | |
---|
181 | "Energy balance" |
---|
182 | Outlet.F*Outlet.h = Outletm.F*Outletm.h; |
---|
183 | |
---|
184 | "Element balance" |
---|
185 | sumt(Fi*na) = sumt(Outletm.F*Outletm.z*na); |
---|
186 | |
---|
187 | "Gibbs free-energy of formation" |
---|
188 | G = PP.IdealGasGibbsOfFormation(Outlet.T); |
---|
189 | |
---|
190 | # "Gibbs free-energy of formation without Cp correction" |
---|
191 | # G = PP.IdealGasGibbsOfFormationAt25C()*Outlet.T/To+PP.IdealGasEnthalpyOfFormationAt25C()*(1-Outlet.T/To); |
---|
192 | |
---|
193 | for i in [1:NComp] |
---|
194 | "Lagrangian multiplier" |
---|
195 | G(i) + sumt(lambda*na(:,i)) = -Rg*Outlet.T*ln(activ(i)); |
---|
196 | |
---|
197 | if (Outletm.z(i) > 0) then |
---|
198 | "Molar conversion" |
---|
199 | Fi(i) = Outletm.F*Outletm.z(i)*(1 - conv(i)); |
---|
200 | else if (Outlet.z(i) > 0) then |
---|
201 | "Molar conversion" |
---|
202 | conv(i) = 1; # ? |
---|
203 | else |
---|
204 | "Molar conversion" |
---|
205 | conv(i) = 0; # ? |
---|
206 | end |
---|
207 | end |
---|
208 | |
---|
209 | end |
---|
210 | |
---|
211 | "Activity coefficient" |
---|
212 | gamma = PP.LiquidFugacityCoefficient(Outlet.T,Outlet.P,Outlet.z); |
---|
213 | |
---|
214 | "Activity" |
---|
215 | activ = gamma*Outlet.z*exp(PP.LiquidVolume(Outlet.T,Outlet.P,Outlet.z)*(Outlet.P - Ps)/Rg/Outlet.T); |
---|
216 | end |
---|