-
Notifications
You must be signed in to change notification settings - Fork 0
/
steam_uv.c
172 lines (132 loc) · 4.08 KB
/
steam_uv.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
/*
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 "steam_uv.h"
#include "region1.h"
#include "region2.h"
#include "region3.h"
#include "region4.h"
#include "b23.h"
#include "backwards.h"
#include "solver2.h"
#include "zeroin.h"
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
/*-----------------required helper functions---------------*/
static MyDouble uf_p(MyDouble p){
Tsat = freesteam_region4_Tsat_p(p);
if(T < T13){
return freesteam_region1_u_pT(p, Tsat);
}else{
/* region 3 part of the saturation line */
}
}
static MyDouble ug_p(MyDouble p){
Tsat = freesteam_region4_Tsat_p(p);
if(T < T13){
return freesteam_region2_u_pT(p, Tsat);
}else{
/* region 3 part of the saturation line */
}
}
static MyDouble vf_u(MyDouble u){
/* zeroin for T such that uf(T) = u */
return freesteam_region1_v_pT(psat(T), T);
}
static MyDouble ug_v(MyDouble v){
/* zeroin for T such that vg(T) = v */
return freesteam_region2_u_pT(psat(T), T)
}
static MyDouble u13_v(MyDouble v){
/* iterate on p to find v_pT(p, T13) = v */
return u_pT(p, T13)
}
static MyDouble u23_v(MyDouble v){
/* iterate on T to get freesteam_region2_v_pT(p23(T), T) = v */
return freesteam_region2_u_pT(p, T);
/* is there a better way using region 3 (rho, T) ?? */
}
/*-----------------main routines --------------------*/
int freesteam_bounds_uv(MyDouble u, MyDouble v, int verbose){
/* lower bound on u */
MyDouble uf = uf_p(IAPWS97_PTRIPLE)
if(u < uf){
return 1;
}
MyDouble ug = ug_p(IAPWS97_PTRIPLE);
MyDouble vf = vf_p(IAPWS97_PTRIPLE), vg = vg_p(IAPWS97_PTRIPLE);
/* triple-point pressure line boundary for saturation region */
if(u < ug || v > vf){
MyDouble v1 = vf + (vg - vf)*(u - uf)/(ug - uf);
if(v > v1){
return 1;
}
}
MyDouble v2 = freesteam_region2_v_pT(IAPWS97_PMAX, IAPWS97_TMAX);
if(v > v2 && u > ug){
/* triple-point pressure line boundary for superheat region */
/* solve for T to give u,pmin --> check v */
/* maximum temperature line */
/* solve p to give region2_v_pT(p, TMAX) --> check u */
}
}
MyDouble u2 = freesteam_region2_u_pT(IAPWS97_PMAX, IAPWS97_TMAX);
if(u > u2 && v < v2){
return 2;
}
/* use steam_pu(PMAX, u) to work out if v is within limits */
if(u < uf_p(IAPWS97_PTRIPLE){
return 1;
}else if(u < ug_p(IAPWS97_PTRIPLE)
/* else if u < ug(pmin) */
/* check v < v(pmin, u) region 4 */
/* else if u > ug(pmin) */
/* check v > v(pmin, u) region 2 */
if(u < freesteam_region2_u_pT(PMAX, TMAX)){
/* check v > v(pmax, u) region 1, 3, or 2! */
}/* else if u > u(pmax, Tmax) */
/* check u < u(Tmax, v) */
}
int freesteam_region_uv(MyDouble u, MyDouble v){
/* if u < u_crit */
/* if v > vf(u) */
/* region 4 */
/* else if u > u13(v) */
/* region 3 */
/* else */
/* region 1 */
/* if u < ug(v) */
/* region 4 */
/* else if v > v_234 || u > u_23(v) */
/* region 2 */
/* else */
/* region 3 */
}
SteamState freesteam_set_uv(MyDouble u, MyDouble v){
int region = /* work out the region */
if(region == 1){
MyDouble vf = /* solved Tsat(u) */
/* iterate on p, T to solve u, v */
}else if(region == 2){
/* two-way iteration with p,T to solve u,v */
}else if(region == 3){
/* one-way iteration on T to solve v(rho,T). */
}else if(region == 4){
/* initial guess ? */
/* iterate on T, x to solve u, v */
}
}