/[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 1838 - (show annotations) (download) (as text)
Thu Aug 28 08:32:29 2008 UTC (15 years, 9 months ago) by jpye
File MIME type: text/x-csrc
File size: 11138 byte(s)
Added 'exponential' terms for nitrogen correlation (still testing).
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_nitrogen = {
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 /* np */
34 , (const HelmholtzPowTerm[]){
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 , 4 /* ne */
71 , (const HelmholtzExpTerm[]){
72 {0.196688194015e2, 0., 1, 20, 325, 1.16}
73 , {-0.209115600730e2, 1., 1, 20, 325, 1.16}
74 , {0.167788306989e-1, 2., 3, 15, 300, 1.13}
75 , {0.262767566274e4, 3., 2, 25, 275, 1.25}
76 }
77 };
78
79
80 /*
81 Test suite. These tests attempt to validate the current code using
82 a few sample figures output by REFPROP 7.0.
83
84 To run the test, compile and run as follows:
85
86 gcc helmholtz.c nitrogen.c -DTEST -o nitrogen -lm && ./nitrogen
87
88 These tests all currently pass with a maximum error of 2%. The error
89 seems to arise in the enthalpy data for low temperatures. Haven't been
90 able to determine where the problem comes from.
91 */
92 #ifdef TEST
93
94 #include <assert.h>
95 #include <stdlib.h>
96 #include <stdio.h>
97 #include <math.h>
98
99 /* a simple macro to actually do the testing */
100 #define ASSERT_TOL(FN,PARAM1,PARAM2,PARAM3,VAL,TOL) {\
101 double cval; cval = FN(PARAM1,PARAM2,PARAM3);\
102 double err; err = cval - (double)(VAL);\
103 double relerrpc = (cval-(VAL))/(VAL)*100;\
104 if(fabs(relerrpc)>maxerr)maxerr=fabs(relerrpc);\
105 if(fabs(err)>TOL){\
106 fprintf(stderr,"ERROR in line %d: value of '%s(%f,%f,%s)' = %f, should be %f, error is %f (%.2f%%)!\n"\
107 , __LINE__, #FN,PARAM1,PARAM2,#PARAM3, cval, VAL,cval-(VAL),relerrpc);\
108 exit(1);\
109 }else{\
110 fprintf(stderr," OK, %s(%f,%f,%s) = %8.2e with %.2f%% err.\n",#FN,PARAM1,PARAM2,#PARAM3,VAL,relerrpc);\
111 /*fprintf(stderr," (err = %8.2e, tol = %8.2e, calc = %8.2e)\n",fabs(err),TOL,cval);*/\
112 }\
113 }
114
115 typedef struct{double T,p,rho,h,s;} TestData;
116
117
118 /*
119 A small set of data points calculated using REFPROP 7.0, for validation
120 */
121 const TestData td[] = {
122 /* {T / K , p / MPa , rho / kg/m3, h / kJ/kg, s / kJ/kgK} */
123 {-200.00000, 0.10000000, 824.94146, -130.56454, 2.7206049}
124 , {-195.90650, 0.10000000, 806.59036, -122.24684, 2.8312405}
125 , {-195.90650, 0.10000000, 4.5564811, 77.072848, 5.4116477}
126 , {-150.00000, 0.10000000, 2.7651079, 126.49637, 5.9149401}
127 , {-100.00000, 0.10000000, 1.9528859, 178.96289, 6.2726011}
128 , {-50.000000, 0.10000000, 1.5119231, 231.14631, 6.5373809}
129 , {0.00000000, 0.10000000, 1.2340278, 283.23654, 6.7480133}
130 , {50.000000, 0.10000000, 1.0426377, 335.30559, 6.9230643}
131 , {100.00000, 0.10000000, 0.90273132, 387.42000, 7.0730090}
132 , {150.00000, 0.10000000, 0.79597134, 439.66508, 7.2043968}
133 , {200.00000, 0.10000000, 0.71181434, 492.14150, 7.3216082}
134 , {250.00000, 0.10000000, 0.64376369, 544.95214, 7.4277045}
135 , {300.00000, 0.10000000, 0.58759653, 598.18966, 7.5248876}
136 , {350.00000, 0.10000000, 0.54044842, 651.92860, 7.6147756}
137 , {400.00000, 0.10000000, 0.50030750, 706.22257, 7.6985791}
138 , {450.00000, 0.10000000, 0.46571913, 761.10483, 7.7772186}
139 , {500.00000, 0.10000000, 0.43560536, 816.59095, 7.8514061}
140 , {550.00000, 0.10000000, 0.40915040, 872.68219, 7.9217018}
141 , {600.00000, 0.10000000, 0.38572547, 929.36893, 7.9885535}
142 , {650.00000, 0.10000000, 0.36483807, 986.63370, 8.0523256}
143 , {700.00000, 0.10000000, 0.34609700, 1044.4538, 8.1133192}
144 , {750.00000, 0.10000000, 0.32918753, 1102.8031, 8.1717867}
145 , {800.00000, 0.10000000, 0.31385363, 1161.6539, 8.2279428}
146 , {850.00000, 0.10000000, 0.29988486, 1220.9778, 8.2819723}
147 , {900.00000, 0.10000000, 0.28710667, 1280.7465, 8.3340357}
148 , {950.00000, 0.10000000, 0.27537304, 1340.9326, 8.3842743}
149 , {1000.0000, 0.10000000, 0.26456092, 1401.5096, 8.4328132}
150 , {-200.00000, 1.0000000, 826.97227, -129.89700, 2.7148345}
151 , {-169.40309, 1.0000000, 665.82825, -64.326777, 3.4600526}
152 , {-169.40309, 1.0000000, 41.331104, 87.734007, 4.9257424}
153 , {-150.00000, 1.0000000, 30.899666, 114.98204, 5.1673819}
154 , {-100.00000, 1.0000000, 20.189927, 173.16514, 5.5653573}
155 , {-50.000000, 1.0000000, 15.303926, 227.54808, 5.8414656}
156 , {0.00000000, 1.0000000, 12.387522, 280.82813, 6.0569512}
157 , {50.000000, 1.0000000, 10.426157, 333.64490, 6.2345305}
158 , {100.00000, 1.0000000, 9.0097433, 386.27217, 6.3859570}
159 , {150.00000, 1.0000000, 7.9362666, 438.89007, 6.5182852}
160 , {200.00000, 1.0000000, 7.0935035, 491.64902, 6.6361293}
161 , {250.00000, 1.0000000, 6.4137509, 544.68060, 6.7426703}
162 , {300.00000, 1.0000000, 5.8536009, 598.09515, 6.8401771}
163 , {350.00000, 1.0000000, 5.3838822, 651.97879, 6.9303076}
164 , {400.00000, 1.0000000, 4.9842388, 706.39293, 7.0142967}
165 , {450.00000, 1.0000000, 4.6400213, 761.37636, 7.0930813}
166 , {500.00000, 1.0000000, 4.3404109, 816.94862, 7.1673842}
167 , {550.00000, 1.0000000, 4.0772408, 873.11393, 7.2377727}
168 , {600.00000, 1.0000000, 3.8442281, 929.86491, 7.3047002}
169 , {650.00000, 1.0000000, 3.6364590, 987.18580, 7.3685349}
170 , {700.00000, 1.0000000, 3.4500344, 1045.0552, 7.4295806}
171 , {750.00000, 1.0000000, 3.2818204, 1103.4482, 7.4880919}
172 , {800.00000, 1.0000000, 3.1292688, 1162.3378, 7.5442851}
173 , {850.00000, 1.0000000, 2.9902865, 1221.6964, 7.5983461}
174 , {900.00000, 1.0000000, 2.8631379, 1281.4962, 7.6504366}
175 , {950.00000, 1.0000000, 2.7463717, 1341.7103, 7.7006986}
176 , {1000.0000, 1.0000000, 2.6387646, 1402.3126, 7.7492578}
177 , {-200.00000, 10.000000, 845.26732, -122.98508, 2.6622174}
178 , {-150.00000, 10.000000, 614.63170, -20.755043, 3.7210595}
179 , {-100.00000, 10.000000, 274.08684, 108.33718, 4.5999308}
180 , {-50.000000, 10.000000, 165.69732, 193.43373, 5.0356176}
181 , {0.00000000, 10.000000, 125.24775, 259.27189, 5.3024487}
182 , {50.000000, 10.000000, 102.49734, 319.26216, 5.5043023}
183 , {100.00000, 10.000000, 87.427859, 376.62733, 5.6694209}
184 , {150.00000, 10.000000, 76.534477, 432.63584, 5.8103035}
185 , {200.00000, 10.000000, 68.216292, 487.94924, 5.9338674}
186 , {250.00000, 10.000000, 61.619660, 542.97600, 6.0444247}
187 , {300.00000, 10.000000, 56.240667, 597.99135, 6.1448586}
188 , {350.00000, 10.000000, 51.759585, 653.18645, 6.2371858}
189 , {400.00000, 10.000000, 47.962302, 708.69313, 6.3228633}
190 , {450.00000, 10.000000, 44.699287, 764.59931, 6.4029715}
191 , {500.00000, 10.000000, 41.862548, 820.95992, 6.4783293}
192 , {550.00000, 10.000000, 39.371915, 877.80536, 6.5495709}
193 , {600.00000, 10.000000, 37.166488, 935.14803, 6.6171967}
194 , {650.00000, 10.000000, 35.199092, 992.98747, 6.6816092}
195 , {700.00000, 10.000000, 33.432569, 1051.3142, 6.7431376}
196 , {750.00000, 10.000000, 31.837217, 1110.1129, 6.8020556}
197 , {800.00000, 10.000000, 30.388987, 1169.3641, 6.8585940}
198 , {850.00000, 10.000000, 29.068188, 1229.0464, 6.9129500}
199 , {900.00000, 10.000000, 27.858530, 1289.1373, 6.9652942}
200 , {950.00000, 10.000000, 26.746414, 1349.6141, 7.0157755}
201 , {1000.0000, 10.000000, 25.720391, 1410.4542, 7.0645253}
202 , {-150.00000, 100.00000, 842.03632, 39.237402, 3.2425037}
203 , {-100.00000, 100.00000, 748.08407, 118.90189, 3.7864991}
204 , {-50.000000, 100.00000, 668.62180, 193.68381, 4.1663797}
205 , {0.00000000, 100.00000, 602.00192, 264.67164, 4.4536512}
206 , {50.000000, 100.00000, 546.37705, 332.63655, 4.6822703}
207 , {100.00000, 100.00000, 499.86285, 398.18975, 4.8709587}
208 , {150.00000, 100.00000, 460.71962, 461.86446, 5.0311389}
209 , {200.00000, 100.00000, 427.47644, 524.12999, 5.1702472}
210 , {250.00000, 100.00000, 398.95507, 585.38730, 5.2933342}
211 , {300.00000, 100.00000, 374.23539, 645.96722, 5.4039354}
212 , {350.00000, 100.00000, 352.60470, 706.13381, 5.5045853}
213 , {400.00000, 100.00000, 333.51020, 766.09157, 5.5971384}
214 , {450.00000, 100.00000, 316.52039, 825.99447, 5.6829774}
215 , {500.00000, 100.00000, 301.29531, 885.95525, 5.7631519}
216 , {550.00000, 100.00000, 287.56440, 946.05406, 5.8384731}
217 , {600.00000, 100.00000, 275.11003, 1006.3459, 5.9095787}
218 , {650.00000, 100.00000, 263.75533, 1066.8665, 5.9769785}
219 , {700.00000, 100.00000, 253.35515, 1127.6376, 6.0410866}
220 , {750.00000, 100.00000, 243.78927, 1188.6704, 6.1022442}
221 , {800.00000, 100.00000, 234.95724, 1249.9686, 6.1607365}
222 , {850.00000, 100.00000, 226.77444, 1311.5305, 6.2168049}
223 , {900.00000, 100.00000, 219.16910, 1373.3507, 6.2706560}
224 , {950.00000, 100.00000, 212.07988, 1435.4217, 6.3224685}
225 , {1000.0000, 100.00000, 205.45406, 1497.7339, 6.3723982}
226 };
227
228
229 int main(void){
230
231 double rho, T, p, h, u;
232 const HelmholtzData *d;
233
234 d = &helmholtz_data_nitrogen;
235 double maxerr = 0;
236
237 unsigned i;
238 const unsigned n = sizeof(td)/sizeof(TestData);
239
240 fprintf(stderr,"Running through %d test points...\n",n);
241
242 fprintf(stderr,"PRESSURE TESTS\n");
243 for(i=0; i<n;++i){
244 ASSERT_TOL(helmholtz_p, td[i].T+273.15, td[i].rho, d, td[i].p*1e6, 1E3);
245 }
246
247 /* offset required to attain agreement with REFPROP */
248 double Y = -471.596704;
249
250 fprintf(stderr,"ENTROPY TESTS\n");
251 for(i=0; i<n;++i){
252 ASSERT_TOL(helmholtz_s, td[i].T+273.15, td[i].rho, d, td[i].s*1e3 + Y, 1E3);
253 }
254
255 /* this offset is required to attain agreement with values from REFPROP */
256 double Z = -1635.7e3 + 1492.411e3;
257
258 fprintf(stderr,"ENTHALPY TESTS\n");
259 for(i=0; i<n;++i){
260 ASSERT_TOL(helmholtz_h, td[i].T+273.15, td[i].rho, d, td[i].h*1e3 + Z, 1E3);
261 }
262
263 fprintf(stderr,"Tests completed OK (maximum error = %0.2f%%)\n",maxerr);
264 exit(0);
265 }
266 #endif
267

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