summaryrefslogtreecommitdiff
path: root/Utilib/src/region1.c
blob: 3028f6ce37f8630eb8381280c677006541590e0a (plain)
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
/*
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#define FREESTEAM_BUILDING_LIB
#include "region.h"

static double gam(double pi, double tau);
static double gampi(double pi, double tau);
static double gampipi(double pi, double tau);
static double gamtau(double pi, double tau);
static double gamtautau(double pi, double tau);
static double gampitau(double pi, double tau);

#define REGION1_GPT_PSTAR 16.53e6 /* Pa */
#define REGION1_GPT_TSTAR 1386. /* K */

#define DEFINE_PITAU(P,T) \
	double pi = p / REGION1_GPT_PSTAR; \
	double tau = REGION1_GPT_TSTAR / T

#define R IAPWS97_R

#include <math.h>

/*---------------------------------------------------------------- */
/* REGION 1 G(p,T) EQUATIONS                                       */

typedef struct{
	int I, J;
	double n;
} IJNData;

const IJNData REGION1_GPT_DATA[] = {
	{0,	-2,	0.14632971213167E+00}
	,{0,	-1,	-0.84548187169114E+00}
	,{0,	0,	-0.37563603672040E+01}
	,{0,	1,	0.33855169168385E+01}
	,{0,	2,	-0.95791963387872E+00}
	,{0,	3,	0.15772038513228E+00}
	,{0,	4,	-0.16616417199501E-01}
	,{0,	5,	0.81214629983568E-03}
	,{1,	-9,	0.28319080123804E-03}
	,{1,	-7,	-0.60706301565874E-03}
	,{1,	-1,	-0.18990068218419E-01}
	,{1,	0,	-0.32529748770505E-01}
	,{1,	1,	-0.21841717175414E-01}
	,{1,	3,	-0.52838357969930E-04}
	,{2,	-3,	-0.47184321073267E-03}
	,{2,	0,	-0.30001780793026E-03}
	,{2,	1,	0.47661393906987E-04}
	,{2,	3,	-0.44141845330846E-05}
	,{2,	17,	-0.72694996297594E-15}
	,{3,	-4,	-0.31679644845054E-04}
	,{3,	0,	-0.28270797985312E-05}
	,{3,	6,	-0.85205128120103E-09}
	,{4,	-5,	-0.22425281908000E-05}
	,{4,	-2,	-0.65171222895601E-06}
	,{4,	10,	-0.14341729937924E-12}
	,{5,	-8,	-0.40516996860117E-06}
	,{8,	-11,	-0.12734301741641E-08}
	,{8,	-6,	-0.17424871230634E-09}
	,{21,	-29,	-0.68762131295531E-18}
	,{23,	-31,	0.14478307828521E-19}
	,{29,	-38,	0.26335781662795E-22}
	,{30,	-39,	-0.11947622640071E-22}
	,{31,	-40,	0.18228094581404E-23}
	,{32,	-41,	-0.93537087292458E-25}
};

const unsigned REGION1_GPT_MAX = sizeof(REGION1_GPT_DATA)/sizeof(IJNData);

#define REGION1_GPT_LOOP \
	double sum = 0; \
	const IJNData *d, *e = REGION1_GPT_DATA + REGION1_GPT_MAX; \
	for(d = REGION1_GPT_DATA; d < e; ++d)

double gam(double pi, double tau){
	REGION1_GPT_LOOP{
		sum += d->n * ipow(7.1 - pi,d->I) * ipow(tau - 1.222,d->J);
	}
	return sum;
}

double gampi(double pi, double tau){
	REGION1_GPT_LOOP{
		sum +=  -d->n * d->I * ipow(7.1 - pi,d->I -1) * ipow(tau - 1.222,d->J);
	}
	return sum;
}

double gampipi(double pi, double tau){
	REGION1_GPT_LOOP{
		sum += d->n * d->I * (d->I - 1) * ipow(7.1 - pi, d->I - 2) * ipow(tau - 1.222, d->J);
    }
	return sum;
}

double gamtau(double pi, double tau){
	REGION1_GPT_LOOP{
		sum += d->n * ipow(7.1 - pi, d->I) * d->J * ipow(tau - 1.222, d->J - 1);
	}
	return sum;
}

double gamtautau(double pi, double tau){
	REGION1_GPT_LOOP{
		sum += d->n * ipow(7.1 - pi, d->I) * d->J * (d->J - 1) * ipow(tau - 1.222, d->J - 2);
	}
	return sum;
}

double gampitau(double pi, double tau){
	REGION1_GPT_LOOP{
		sum += -d->n * d->I * ipow(7.1 - pi, d->I - 1) * d->J * ipow(tau - 1.222, d->J - 1);
	}
	return sum;
}

double freesteam_region1_u_pT(double p, double T){
	DEFINE_PITAU(P,T);
	return (R * T) * (tau * gamtau(pi,tau) - pi * gampi(pi,tau));
}

double freesteam_region1_v_pT(double p, double T){
	DEFINE_PITAU(P,T);
	return (R * T / p) * pi * gampi(pi,tau);
}

double freesteam_region1_s_pT(double p, double T){
	DEFINE_PITAU(P,T);
	return R * (tau * gamtau(pi,tau) - gam(pi,tau));
}

double freesteam_region1_h_pT(double p, double T){
	DEFINE_PITAU(P,T);
	return R * T * (tau * gamtau(pi,tau));
}

double freesteam_region1_cp_pT(double p, double T){
	DEFINE_PITAU(P,T);
	return R * (-SQ(tau) * gamtautau(pi,tau));
}

double freesteam_region1_cv_pT(double p, double T){
	DEFINE_PITAU(P,T);
	return R * (-SQ(tau) * gamtautau(pi,tau) + SQ(gampi(pi,tau) -
		tau * gampitau(pi,tau)) / gampipi(pi,tau)
	);
}

double freesteam_region1_w_pT(double p, double T){
	DEFINE_PITAU(P,T);
	double gp = gampi(pi,tau);
	return sqrt(R * T * SQ(gp) / \
		(SQ(gp - tau*gampitau(pi,tau))/SQ(tau)/gamtautau(pi,tau) - gampipi(pi,tau))
	);
}

double freesteam_region1_g_pT(double p, double T){
	DEFINE_PITAU(p,T);
	return R * T * gam(pi,tau);
}

double freesteam_region1_a_pT(double p, double T){
	DEFINE_PITAU(p,T);
	return R * T * (gam(pi,tau) - gampi(pi,tau) * pi);
}


double freesteam_region1_alphav_pT(double p, double T){
	DEFINE_PITAU(P,T);
	return 1./T * (1. - tau*gampitau(pi,tau)/gampi(pi,tau));
}

double freesteam_region1_kappaT_pT(double p, double T){
	DEFINE_PITAU(P,T);
	return -1./p * pi*gampipi(pi,tau)/gampi(pi,tau);
}