/[ascend]/trunk/models/johnpye/fprops/nitrogen.c
ViewVC logotype

Contents of /trunk/models/johnpye/fprops/nitrogen.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1835 - (show annotations) (download) (as text)
Mon Aug 25 08:18:23 2008 UTC (12 years, 1 month ago) by jpye
File MIME type: text/x-csrc
File size: 10634 byte(s)
Checked in generalised version of ideal gas component.
Working on adding the 'exponential' term for the Nitrogen correlation.
1 #include "ammonia.h"
2
3 /* Property data for Nitrogen
4
5 From Span, Lemmon, Jacobsen & Wagner
6 A Reference Quality Equation of State for Nitrogen
7 Int J Thermophysics, Vol 18, No 4, 1998.
8
9 This is the nitrogren property correlation recommended
10 by NIST in its program REFPROP 7.0. */
11
12 const IdealData ideal_data_nitrogen = {
13 -12.76953 /* constant */
14 ,-0.007841630 /* linear */
15 , 3 /* power terms */
16 , (const IdealPowTerm[]){
17 {1.934819, -1.}
18 ,{-1.247742e-5, -2.}
19 ,{6.678326e-8, -3.}
20 }
21 , 1
22 , (const IdealExpTerm[]){
23 {1.012941, 26.65788}
24 }
25 };
26
27 const HelmholtzData helmholtz_data_ammonia = {
28 /* R */ 8.31451 / 28.01348e-3 /* J/molK * kg/mol = J/kg/K */
29 , /* M */ 28.01348 /* kg/kmol */
30 , /* rho_star */ 11.1839 * 28.01348 /* mol/L * kg/kmol = kg/kL = kg/m続 = rho_c for this model*/
31 , /* T_star */ 126.192 /* K = T_c for this model */
32 , &ideal_data_nitrogen
33 , 21 /* nr */
34 , (const HelmholtzATDL[]){
35 /* a_i, t_i, d_i, l_i */
36 { 0.924803575275, 0.25, 1, 0}
37 ,{-0.492448489428, 0.875, 1, 0}
38 ,{ 0.661883336938, 0.5, 2, 0}
39 ,{-0.192902649201E1, 0.875, 2, 0}
40 ,{-0.622469309629E-1, 0.375, 3, 0}
41 ,{ 0.349943957581, 0.75, 3, 0}
42 ,{ 0.564857472498, 0.5, 1, 1}
43 ,{-0.161720005987E1, 0.75, 1, 1}
44 ,{-0.481395031883, 2., 1, 1}
45 ,{ 0.421150636384, 1.25, 3, 1}
46 ,{-0.161962230825E-1, 3.5, 3, 1}
47 ,{ 0.172100994165, 1., 4, 1}
48 ,{ 0.735448924933E-2, 0.5, 6, 1}
49 ,{ 0.168077305479E-1, 3., 6, 1}
50 ,{-0.107626664179E-2, 0., 7, 1}
51 ,{-0.137318088513E-1, 2.75, 7, 1}
52 ,{ 0.635466899859E-3, 0.75, 8, 1}
53 ,{ 0.304432279419E-2, 2.5, 8, 1}
54 ,{-0.435762336045E-1, 4., 1, 2}
55 ,{-0.723174889316E-1, 6. , 2, 2}
56 ,{ 0.389644315272E-1, 6., 3, 2}
57 ,{-0.212201363910E-1, 3., 4, 2}
58 ,{ 0.408822981509E-2, 3., 5, 2}
59 ,{-0.551990017984E-4, 6., 8, 2}
60 ,{-0.462016716479E-1, 16., 4, 3}
61 ,{-0.300311716011E-2, 11., 5, 3}
62 ,{ 0.368825891208E-1, 15., 5, 3}
63 ,{-0.255856846220E-2, 12., 8, 3}
64 ,{ 0.896915264558E-2, 12., 3, 4}
65 ,{-0.441513370350E-2, 7., 5, 4}
66 ,{ 0.133722924858E-2, 4., 6, 4}
67 ,{ 0.264832491957E-3, 16., 9, 4}
68 /* more terms here still to come */
69 }
70 };
71
72
73 /*
74 Test suite. These tests attempt to validate the current code using
75 a few sample figures output by REFPROP 7.0.
76
77 To run the test, compile and run as follows:
78
79 gcc helmholtz.c nitrogen.c -DTEST -o nitrogen -lm && ./nitrogen
80
81 These tests all currently pass with a maximum error of 2%. The error
82 seems to arise in the enthalpy data for low temperatures. Haven't been
83 able to determine where the problem comes from.
84 */
85 #ifdef TEST
86
87 #include <assert.h>
88 #include <stdlib.h>
89 #include <stdio.h>
90 #include <math.h>
91
92 /* a simple macro to actually do the testing */
93 #define ASSERT_TOL(EXPR,VAL,TOL) {\
94 double cval; cval = (EXPR);\
95 double err; err = cval - (double)(VAL);\
96 double relerrpc = (cval-(VAL))/(VAL)*100;\
97 if(fabs(relerrpc)>maxerr)maxerr=fabs(relerrpc);\
98 if(fabs(err)>TOL){\
99 fprintf(stderr,"ERROR in line %d: value of '%s' = %f, should be %f, error is %f (%.2f%%)!\n"\
100 , __LINE__, #EXPR, cval, VAL,cval-(VAL),relerrpc);\
101 exit(1);\
102 }else{\
103 fprintf(stderr," OK, %s = %8.2e with %.2f%% err.\n",#EXPR,VAL,relerrpc);\
104 /*fprintf(stderr," (err = %8.2e, tol = %8.2e, calc = %8.2e)\n",fabs(err),TOL,cval);*/\
105 }\
106 }
107
108 int main(void){
109 double rho, T, p, h, u;
110 const HelmholtzData *d;
111
112 d = &helmholtz_data_ammonia;
113 double maxerr = 0;
114
115 fprintf(stderr,"ENTROPY TESTS\n");
116
117 /* offset required to attain agreement with REFPROP */
118 double Y = -471.596704;
119
120 fprintf(stderr,"s(T,rho) at p = 0.1 MPa\n");
121 ASSERT_TOL(helmholtz_s(273.15+-60, 713.65,d), Y+0.36737e3, 0.5);
122 ASSERT_TOL(helmholtz_s(273.15+ 0,0.76124,d), Y+6.8900e3, 0.5);
123 ASSERT_TOL(helmholtz_s(273.15+ 50,0.63869,d), Y+7.2544e3, 0.5);
124 ASSERT_TOL(helmholtz_s(273.15+200,0.43370,d), Y+8.1232e3, 0.5);
125 ASSERT_TOL(helmholtz_s(273.15+300,0.35769,d), Y+8.6084e3, 1);
126 ASSERT_TOL(helmholtz_s(273.15+420,0.29562,d), Y+9.1365e3, 1);
127
128 fprintf(stderr,"s(T,rho) at p = 1 MPa\n");
129 ASSERT_TOL(helmholtz_s(273.15+-50,702.49,d), Y+0.56381e3, 0.5);
130 ASSERT_TOL(helmholtz_s(273.15+150,4.9817,d), Y+6.7008e3, 0.5);
131 ASSERT_TOL(helmholtz_s(273.15+200,4.4115,d), Y+6.9770e3, 0.5);
132 ASSERT_TOL(helmholtz_s(273.15+350,3.3082,d), Y+7.7012e3, 0.5);
133 ASSERT_TOL(helmholtz_s(273.15+420,2.9670,d), Y+8.0059e3, 0.5);
134
135 fprintf(stderr,"s(T,rho) at p = 10 MPa\n");
136 ASSERT_TOL(helmholtz_s(273.15+-70,728.11,d), Y+0.14196e3, 1);
137 ASSERT_TOL(helmholtz_s(273.15+-50,706.21,d), Y+0.54289e3, 1);
138 ASSERT_TOL(helmholtz_s(273.15+-20,670.55,d), Y+1.0975e3, 1);
139 ASSERT_TOL(helmholtz_s(273.15+ 0,645.04,d), Y+1.4403e3, 1);
140 ASSERT_TOL(helmholtz_s(273.15+125.17,356.70,d), Y+3.5463e3, 1);
141
142 ASSERT_TOL(helmholtz_s(273.15+125.17,121.58,d), Y+4.5150e3, 1);
143 ASSERT_TOL(helmholtz_s(273.15+200,54.389,d), Y+5.5906e3, 1);
144 ASSERT_TOL(helmholtz_s(273.15+350,35.072,d), Y+6.4850e3, 1);
145 ASSERT_TOL(helmholtz_s(273.15+420,30.731,d), Y+6.8171e3, 1);
146
147 fprintf(stderr,"s(T,rho) at p = 20 MPa\n");
148 ASSERT_TOL(helmholtz_s(273.15+-50,710.19,d), Y+0.52061e3, 1);
149 ASSERT_TOL(helmholtz_s(273.15+ 30,612.22,d), Y+1.8844e3, 1);
150 ASSERT_TOL(helmholtz_s(273.15+150,359.41,d), Y+3.7164e3, 1);
151 ASSERT_TOL(helmholtz_s(273.15+200,152.83,d), Y+4.8376e3, 1);
152 ASSERT_TOL(helmholtz_s(273.15+350,74.590,d), Y+6.0407e3, 1);
153 ASSERT_TOL(helmholtz_s(273.15+420,63.602,d), Y+6.4066e3, 1);
154
155 fprintf(stderr,"s(T,rho) at p = 100 MPa\n");
156 ASSERT_TOL(helmholtz_s(273.15+ 0,690.41,d), Y+1.2158e3, 1);
157 ASSERT_TOL(helmholtz_s(273.15+100,591.07,d), Y+2.5499e3, 1);
158 ASSERT_TOL(helmholtz_s(273.15+250,437.69,d), Y+4.0264e3, 1);
159 ASSERT_TOL(helmholtz_s(273.15+420,298.79,d), Y+5.2620e3, 1);
160
161 /* successful entropy tests means that helm_ideal_tau, helm_real_tau, helm_ideal and helm_resid are all OK */
162
163 fprintf(stderr,"PRESSURE TESTS\n");
164
165 fprintf(stderr,"p(T,rho) = 0.1 MPa\n");
166 ASSERT_TOL(helmholtz_p(273.15 -70,724.74783,d), 0.1E6, 1E3);
167 ASSERT_TOL(helmholtz_p(273.15 -60,713.64815,d), 0.1E6, 1E3);
168 ASSERT_TOL(helmholtz_p(273.15 -50,702.11130,d), 0.1E6, 1E3);
169 ASSERT_TOL(helmholtz_p(273.15 -40,690.16351,d), 0.1E6, 1E3);
170 ASSERT_TOL(helmholtz_p(273.15 -33.588341,682.29489,d), 0.1E6,1E3);
171 ASSERT_TOL(helmholtz_p(273.15+ 0,0.76123983,d), 0.1E6, 1E3);
172 ASSERT_TOL(helmholtz_p(273.15+100,0.55135,d), 0.1E6, 1E3);
173 ASSERT_TOL(helmholtz_p(273.15+250,0.39203,d), 0.1E6, 1E3);
174 ASSERT_TOL(helmholtz_p(273.15+420,0.29562,d), 0.1E6, 1E3);
175
176 fprintf(stderr,"p(T,rho) = 1 MPa\n");
177 ASSERT_TOL(helmholtz_p(273.15 -70,725.05815,d), 1E6, 1E3);
178 ASSERT_TOL(helmholtz_p(273.15+ 0,638.97275,d), 1E6, 1E3);
179 ASSERT_TOL(helmholtz_p(273.15+ 30,7.5736465,d), 1E6, 1E3);
180 ASSERT_TOL(helmholtz_p(273.15+150,4.9816537,d), 1E6, 1E3);
181 ASSERT_TOL(helmholtz_p(273.15+200,4.4115,d), 1E6, 1E3);
182 ASSERT_TOL(helmholtz_p(273.15+350,3.3082,d), 1E6, 1E3);
183 ASSERT_TOL(helmholtz_p(273.15+420,2.9670,d), 1E6, 1E3);
184
185 fprintf(stderr,"p(T,rho) = 10 MPa\n");
186 ASSERT_TOL(helmholtz_p(273.15+-40.,694.67407,d), 10E6, 1E3);
187 ASSERT_TOL(helmholtz_p(273.15+-20.,670.54741,d), 10E6, 1E3);
188 ASSERT_TOL(helmholtz_p(273.15+50,573.07306,d), 10E6, 1E3);
189 ASSERT_TOL(helmholtz_p(273.15+110,441.76869,d), 10E6, 1E3);
190 ASSERT_TOL(helmholtz_p(273.15+150,74.732,d), 10E6, 1E3);
191 ASSERT_TOL(helmholtz_p(273.15+200,54.389,d), 10E6, 1E3);
192 ASSERT_TOL(helmholtz_p(273.15+350,35.072,d), 10E6, 1E3);
193 ASSERT_TOL(helmholtz_p(273.15+420,30.731,d), 10E6, 1E3);
194
195 fprintf(stderr,"p(T,rho) = 20 MPa\n");
196 ASSERT_TOL(helmholtz_p(273.15+150,359.40683,d), 20E6, 1E4);
197 ASSERT_TOL(helmholtz_p(273.15+200,152.83430,d), 20E6, 1E4);
198 ASSERT_TOL(helmholtz_p(273.15+350,74.590236,d), 20E6, 1E4);
199 ASSERT_TOL(helmholtz_p(273.15+420,63.601873,d), 20E6, 1E4);
200
201 //fprintf(stderr,"IDEAL HELMHOLTZ COMPONENT\n");
202 //ASSERT_TOL(helm_ideal(273.15, 0)
203
204 fprintf(stderr,"ENTHALPY TESTS\n");
205
206 /* this offset is required to attain agreement with values from REFPROP */
207 double Z = -1635.7e3 + 1492.411e3;
208
209 fprintf(stderr,"h(T,rho) at p = 0.1 MPa\n");
210 ASSERT_TOL(helmholtz_h(273.15+-60, 713.65,d), Z+75.166e3, 0.2e3);
211 ASSERT_TOL(helmholtz_h(273.15+ 0,0.76124,d), Z+1635.7e3, 0.2e3);
212 ASSERT_TOL(helmholtz_h(273.15+ 50,0.63869,d), Z+1744.0e3, 0.2e3);
213 ASSERT_TOL(helmholtz_h(273.15+200,0.43370,d), Z+2087.0e3, 0.2e3);
214 ASSERT_TOL(helmholtz_h(273.15+300,0.35769,d), Z+2340.0e3, 1e3);
215 ASSERT_TOL(helmholtz_h(273.15+420,0.29562,d), Z+2674.3e3, 1e3);
216
217 fprintf(stderr,"h(T,rho) at p = 1 MPa\n");
218 ASSERT_TOL(helmholtz_h(273.15+150,4.9817,d), Z+1949.1e3, 1e3);
219 ASSERT_TOL(helmholtz_h(273.15+200,4.4115,d), Z+2072.7e3, 1e3);
220 ASSERT_TOL(helmholtz_h(273.15+350,3.3082,d), Z+2468.2e3, 1e3);
221 ASSERT_TOL(helmholtz_h(273.15+420,2.9670,d), Z+2668.6e3, 1e3);
222
223 fprintf(stderr,"h(T,rho) at p = 10 MPa\n");
224 ASSERT_TOL(helmholtz_h(273.15+-50,706.21,d), Z+127.39e3, 2e3);
225 ASSERT_TOL(helmholtz_h(273.15+-0,645.04,d), Z+349.53e3, 2e3);
226
227 ASSERT_TOL(helmholtz_h(273.15+150,74.732,d), Z+1688.5e3, 1e3);
228 ASSERT_TOL(helmholtz_h(273.15+200,54.389,d), Z+1908.0e3, 1e3);
229 ASSERT_TOL(helmholtz_h(273.15+350,35.072,d), Z+2393.4e3, 1e3);
230 ASSERT_TOL(helmholtz_h(273.15+420,30.731,d), Z+2611.8e3, 1e3);
231
232 fprintf(stderr,"h(T,rho) at p = 20 MPa\n");
233 /* note rather larger errors in the following few lines -- why? */
234 ASSERT_TOL(helmholtz_h(273.15 -70,731.41,d), Z+51.734e3, 0.5e3);
235 ASSERT_TOL(helmholtz_h(273.15 -60,721.00318,d), Z+93.871419e3, 0.5e3);
236 ASSERT_TOL(helmholtz_h(273.15 -50,710.19289,d), Z+136.54351e3, 1e3);
237 ASSERT_TOL(helmholtz_h(273.15 -40,699.02472,d), Z+179.72030e3, 0.5e3);
238 ASSERT_TOL(helmholtz_h(273.15+ 30,612.22,d), Z+493.28e3, 0.5e3);
239 ASSERT_TOL(helmholtz_h(273.15+150,359.40683,d), Z+1162.5e3, 0.5e3);
240 ASSERT_TOL(helmholtz_h(273.15+200,152.83430,d), Z+1662.9e3, 0.5e3);
241 ASSERT_TOL(helmholtz_h(273.15+250,106.31299,d), Z+1928.6499e3, 0.5e3);
242 ASSERT_TOL(helmholtz_h(273.15+300,86.516941,d), Z+2128.9031e3, 0.5e3);
243 ASSERT_TOL(helmholtz_h(273.15+330,78.784703,d), Z+2238.2416e3, 0.5e3);
244 ASSERT_TOL(helmholtz_h(273.15+350,74.590236,d), Z+2308.8516e3, 10e3);
245 ASSERT_TOL(helmholtz_h(273.15+420,63.601873,d), Z+2549.2872e3, 10e3);
246
247 fprintf(stderr,"h(T,rho) at p = 100 MPa\n");
248 ASSERT_TOL(helmholtz_h(273.15+ 0,690.41,d), Z+422.69e3, 0.5e3);
249 ASSERT_TOL(helmholtz_h(273.15+100,591.07,d), Z+850.44e3, 0.1e3);
250 ASSERT_TOL(helmholtz_h(273.15+250,437.69,d), Z+1506.6e3, 1e3);
251 ASSERT_TOL(helmholtz_h(273.15+420,298.79,d), Z+2252.3e3, 1e3);
252
253 fprintf(stderr,"Tests completed OK (maximum error = %0.2f%%)\n",maxerr);
254 exit(0);
255 }
256 #endif

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22