-
Notifications
You must be signed in to change notification settings - Fork 5
/
HGStp.m
85 lines (78 loc) · 3.19 KB
/
HGStp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function [Tp,species,n,flag] = HGStp(species,n0,type,V0,P,options)
%**************************************************************************
%
% [Tp,species,n,flag] = HGStp(species,n0,type,V0,P,options)
%
%**************************************************************************
%
% HGStp calculates the reaction temperature considering
% dissociation, and the products composition in equilibrium
%
%**************************************************************************
% Inputs:
%--------------------------------------------------------------------------
% species --> String or code of species
% n0 --> [mols] Number of mols of each species
% usually, the number of mol of the products will be zero
% type --> Entry type that defines the state of the input.
% It can be 'T' or 'H'
% V0 --> Value of type:'T' V0=T [K] input temperature
% 'H' V0=H [kJ] input enthalpy
% P --> [bar] Pressure
% options --> (OPTIONAL) Structure with the options for the secant method.
% .xmin [K] Temperature minimum for the solver;
% .xmax [K] Temperature maximum for the solver;
% .maxiter Max iterations for the solver;
% .epsx Diferential T where the solver reachs the solution;
% .epsy Diferential S where the solver reachs the solution;
% .fchange T difference where secant method is
% changed by bisection method;
% .type Select between: 'Frozen' for frozen flow
% 'Shifting' for shifting flow
% .info Detailed info == 1; No info == 0.
% .maxrange Max range to fit in a parabola
% .dTp Improve the velocity with the approximation of
% parabola. +- dTp
% For instance, by default:
% options=struct('xmin',300,'xmax',5000,'maxiter',50,'epsx',0.1,'epsy',0.5,'fchange',5,'type','Shifting','info',0,'dTp',100)
%
% Outputs:
%--------------------------------------------------------------------------
% Tp --> [K] Exit temperature
% n --> [mols] Species resultant mols
% species --> String or code of species
% flag --> Solver error detection:
% 1 Solver has reached the solution
% -1 Solver failed. Maximum iterations
% -2 Solver failed. Initial sign change not found
%
%**************************************************************************
% Examples:
% HGStp({'H2','O2','H2O','H','O','OH'}, [2 1 0 0 0 0] , 'T', 400, 10)
% HGStp({'H2','O2','H2O','H','O','OH'}, [2 1 0 0 0 0] , 'H', 3.1, 10)
%**************************************************************************
% *HGS 2.1
% *By Caleb Fuster, Manel Soria and Arnau Miró
% *ESEIAAT UPC
% type = 'H' or 'T'
if type~='H' && type~='T'
error('Wrong type = %s',type);
end
if ~exist('options','var')
options = [];
end
global HGSdata; HGSload
[id] = HGSid(species);
% Rebuild mixtures
if max(id) >= length(HGSdata.Mm)
[species,n0] = HGSrebuild(species,n0);
[id] = HGSid(species);
end
% Compute initial enthalpy
if type=='T'
H = HGSprop(id,n0,V0,P,'H');
else
H = V0;
end
[Tp,~,n,flag]=HGSeqcond(id,n0,'H',H,P,'Shifting',options);
end