-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregion4.c
273 lines (217 loc) · 8.05 KB
/
region4.c
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
freesteam - IAPWS-IF97 steam tables library
Copyright (C) 2004-2009 John Pye
This program 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.
This program is distributed in the 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#define FREESTEAM_BUILDING_LIB
#include "region4.h"
#include "region1.h"
#include "region3.h"
#include "region2.h"
#include <math.h>
#include <stdlib.h>
const MyDouble REGION4_N[11] = { 0, 0.11670521452767E+04, -0.72421316703206E+06
, -0.17073846940092E+02, 0.12020824702470E+05, -0.32325550322333E+07
, 0.14915108613530E+02, -0.48232657361591E+04, 0.40511340542057E+06
, -0.23855557567849E+00, 0.65017534844798E+03
};
#define REGION4_PSTAR 1e6 /* Pa */
#define REGION4_TSTAR 1 /* K */
/*------------------------------------------------------------------------------
REGION 4 SATURATION CURVE psat(T)
*/
MyDouble freesteam_region4_psat_T(MyDouble T){
//fprintf(stderr,"freesteam_region4_psat_T(T = %f)\n", T );
MyDouble ups = T/REGION4_TSTAR + REGION4_N[9] / (T/REGION4_TSTAR - REGION4_N[10]);
MyDouble A = SQ(ups) + REGION4_N[1] * ups + REGION4_N[2];
MyDouble B = REGION4_N[3] * SQ(ups) + REGION4_N[4] * ups + REGION4_N[5];
MyDouble C = REGION4_N[6] * SQ(ups) + REGION4_N[7] * ups + REGION4_N[8];
MyDouble expr = 2. * C / (- B + sqrt(SQ(B) - 4. * A * C));
MyDouble psat = SQ(SQ(expr)) * REGION4_PSTAR;
/* fprintf(stderr,"freesteam_region4_psat_T = %f MPa\n", psat/1e6);*/
return psat;
}
/*------------------------------------------------------------------------------
REGION 4 SATURATION CURVE Tsat(p) (BACKWARDS EQUATION)
*/
MyDouble freesteam_region4_Tsat_p(MyDouble p){
IAPWS97_APPROXIMATE;
MyDouble beta = pow(p/REGION4_PSTAR, 0.25);
MyDouble E = SQ(beta) + REGION4_N[3] * beta + REGION4_N[6];
MyDouble F = REGION4_N[1] * SQ(beta) + REGION4_N[4] * beta + REGION4_N[7];
MyDouble G = REGION4_N[2] * SQ(beta) + REGION4_N[5] * beta + REGION4_N[8];
MyDouble D = 2. * G / (-F - sqrt(SQ(F) - 4. * E * G));
MyDouble theta = 0.5 * (REGION4_N[10] + D - sqrt(SQ(REGION4_N[10] + D) - 4.0 * (REGION4_N[9] + REGION4_N[10] * D)));
/* FIXME iterative improve this estimate? is it necessary? */
return theta /* * REGION4_TSTAR = 1 {K} */;
}
/*------------------------------------------------------------------------------
REGION 4 DENSITIES rhof(T), rhog(T) (SUPPLEMENTARY EQUATIONS)
*/
/**
Coefficients for getSatDensWater_T
*/
const MyDouble REGION4_B[7]
= { 0, 1.99274064, 1.09965342, -0.510839303, -1.75493479, -45.5170352, -6.74694450E+05 };
/**
Coefficients for getSatDensSteam_T
*/
const MyDouble REGION4_C[7]
= { 0, -2.03150240, -2.68302940, -5.38626492, -17.2991605, -44.7586581, -63.9201063 };
MyDouble freesteam_region4_rhof_T(MyDouble T){
IAPWS97_APPROXIMATE;
MyDouble tau = 1 - T / IAPWS97_TCRIT;
MyDouble tau_1_3 = pow(tau,1./3);
MyDouble tau_2_3 = SQ(tau_1_3);
MyDouble tau_5_3 = tau * tau_2_3;
MyDouble tau_16_3 = SQ(tau_5_3) * tau_5_3 * tau_1_3;
MyDouble tau_43_3 = SQ(tau_16_3) * SQ(tau_5_3) * tau_1_3;
MyDouble tau_110_3 = SQ(tau_43_3) * tau_16_3 * tau_5_3 * tau;
MyDouble delta = 1
+ REGION4_B[1]*tau_1_3
+ REGION4_B[2]*tau_2_3
+ REGION4_B[3]*tau_5_3
+ REGION4_B[4]*tau_16_3
+ REGION4_B[5]*tau_43_3
+ REGION4_B[6]*tau_110_3;
return delta * IAPWS97_RHOCRIT;
/* FIXME iteratively improve vf estimate */
}
MyDouble freesteam_region4_rhog_T(MyDouble T){
IAPWS97_APPROXIMATE;
MyDouble tau = 1. - T / IAPWS97_TCRIT;
MyDouble tau_1_6 = pow(tau,1.0/6);
MyDouble tau_2_6 = SQ(tau_1_6);
MyDouble tau_4_6 = SQ(tau_2_6);
MyDouble tau_8_6 = SQ(tau_4_6);
MyDouble tau_16_6 = SQ(tau_8_6);
MyDouble tau_18_6 = tau_16_6 * tau_2_6;
MyDouble tau_37_6 = SQ(tau_18_6) * tau_1_6;
MyDouble tau_71_6 = tau_37_6 * tau_18_6 * tau_16_6;
MyDouble ln_delta =
REGION4_C[1]*tau_2_6
+ REGION4_C[2]*tau_4_6
+ REGION4_C[3]*tau_8_6
+ REGION4_C[4]*tau_18_6
+ REGION4_C[5]*tau_37_6
+ REGION4_C[6]*tau_71_6;
return exp(ln_delta) * IAPWS97_RHOCRIT;
/* FIXME iteratively improve vg estimate */
}
/*------------------------------------------------------------------------------
INTERPOLATIONS FOR PROPERTIES WITHIN REGION 4
*/
MyDouble freesteam_region4_v_Tx(MyDouble T, MyDouble x){
MyDouble vf, vg;
if(T < REGION1_TMAX){
MyDouble psat = freesteam_region4_psat_T(T);
vf = freesteam_region1_v_pT(psat,T);
vg = freesteam_region2_v_pT(psat,T);
}else{
vf = 1./ freesteam_region4_rhof_T(T);
vg = 1./ freesteam_region4_rhog_T(T);
}
return vf + x*(vg - vf);
}
MyDouble freesteam_region4_u_Tx(MyDouble T, MyDouble x){
MyDouble uf, ug;
if(T < REGION1_TMAX){
MyDouble psat = freesteam_region4_psat_T(T);
uf = freesteam_region1_u_pT(psat,T);
ug = freesteam_region2_u_pT(psat,T);
}else{
MyDouble rhof, rhog;
rhof = freesteam_region4_rhof_T(T);
rhog = freesteam_region4_rhog_T(T);
uf = freesteam_region3_u_rhoT(rhof,T);
ug = freesteam_region3_u_rhoT(rhog,T);
}
return uf + x*(ug - uf);
}
MyDouble freesteam_region4_h_Tx(MyDouble T, MyDouble x){
MyDouble hf, hg;
if(T < REGION1_TMAX){
MyDouble psat = freesteam_region4_psat_T(T);
hf = freesteam_region1_h_pT(psat,T);
hg = freesteam_region2_h_pT(psat,T);
//fprintf(stderr,"%s: T = %f K, psat = %f MPa, hf = %f kJ/kg, hg = %f kJ/kg\n",__func__,T,psat/1e6,hf/1e3,hg);
}else{
MyDouble rhof, rhog;
rhof = freesteam_region4_rhof_T(T);
rhog = freesteam_region4_rhog_T(T);
hf = freesteam_region3_h_rhoT(rhof,T);
hg = freesteam_region3_h_rhoT(rhog,T);
}
return hf + x*(hg - hf);
}
MyDouble freesteam_region4_s_Tx(MyDouble T, MyDouble x){
MyDouble sf, sg;
if(T < REGION1_TMAX){
MyDouble psat = freesteam_region4_psat_T(T);
sf = freesteam_region1_s_pT(psat,T);
sg = freesteam_region2_s_pT(psat,T);
}else{
MyDouble rhof, rhog;
rhof = freesteam_region4_rhof_T(T);
rhog = freesteam_region4_rhog_T(T);
sf = freesteam_region3_s_rhoT(rhof,T);
sg = freesteam_region3_s_rhoT(rhog,T);
}
return sf + x*(sg - sf);
}
MyDouble freesteam_region4_cp_Tx(MyDouble T, MyDouble x){
MyDouble cpf, cpg;
if(T < REGION1_TMAX){
MyDouble psat = freesteam_region4_psat_T(T);
cpf = freesteam_region1_cp_pT(psat,T);
cpg = freesteam_region2_cp_pT(psat,T);
}else{
MyDouble rhof, rhog;
rhof = freesteam_region4_rhof_T(T);
rhog = freesteam_region4_rhog_T(T);
cpf = freesteam_region3_cp_rhoT(rhof,T);
cpg = freesteam_region3_cp_rhoT(rhog,T);
}
return cpf + x*(cpg - cpf);
}
MyDouble freesteam_region4_cv_Tx(MyDouble T, MyDouble x){
MyDouble cvf, cvg;
if(T < REGION1_TMAX){
MyDouble psat = freesteam_region4_psat_T(T);
cvf = freesteam_region1_cv_pT(psat,T);
cvg = freesteam_region2_cv_pT(psat,T);
}else{
MyDouble rhof, rhog;
rhof = freesteam_region4_rhof_T(T);
rhog = freesteam_region4_rhog_T(T);
cvf = freesteam_region3_cv_rhoT(rhof,T);
cvg = freesteam_region3_cv_rhoT(rhog,T);
}
return cvf + x*(cvg - cvf);
}
/*------------------------------------------------------------------------------
*/
MyDouble freesteam_region4_dpsatdT_T(MyDouble T){
/* calculated this derivative using implicit differentiation of the
quadratic expression, then derivatives of beta and script-theta */
MyDouble beta = pow(freesteam_region4_psat_T(T)/REGION4_PSTAR, 0.25);
#define N REGION4_N
MyDouble theta = T/REGION4_TSTAR + N[9] / (T/REGION4_TSTAR - N[10]);
MyDouble XBETA = (2.*beta + N[3])*SQ(theta) + (2.*beta*N[1] + N[4])*theta + 2.*N[2]*beta + N[5];
MyDouble XTHETA = (2.*theta + N[1])*SQ(beta) + (2.*N[3]*theta + N[4])*beta + 2.*N[6]*theta + N[7];
MyDouble dthetadT = (1 - N[9] / (T/REGION4_TSTAR - N[10]))/REGION4_TSTAR;
MyDouble dbetadtheta = -XTHETA/XBETA;
MyDouble dpdbeta = 4*SQ(beta)*beta*REGION4_PSTAR;
#undef N
return dpdbeta * dbetadtheta * dthetadT;
}