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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1865 - (show annotations) (download) (as text)
Mon Sep 15 08:40:14 2008 UTC (11 years, 9 months ago) by jpye
File MIME type: text/x-csrc
File size: 13993 byte(s)
Still working on fixing helmholtz_a.
1 #include "ammonia.h"
2
3 #define AMMONIA_OFFSET_H -1.4311891570e+05
4 #define AMMONIA_R 488.189
5 #define AMMONIA_TSTAR 405.40
6 /**
7 Ideal gas data for Ammonia, from Tillner-Roth, Harms-Watzenberg and
8 Baehr, 'Eine neue Fundamentalgleichung f端r Ammoniak', DKV-Tagungsbericht,
9 20:167-181, 1993. This is the ammmonia property correlation recommended
10 by NIST in its program REFPROP 7.0.
11 */
12 const IdealData ideal_data_ammonia = {
13 -15.815020 + 8.7915707880e+02/AMMONIA_R/* const */
14 , 4.255726 + 1.4311891570e+05/AMMONIA_R/AMMONIA_TSTAR /* linear */
15 , AMMONIA_TSTAR /* Tstar */
16 , AMMONIA_R /* cpstar J/kgK */
17 , 3 /* power terms */
18 , (const IdealPowTerm[]){
19 #if 0
20 {1.8871646035249E+01, -1./3}
21 ,{5.9549943513550E-04, 3./2}
22 ,{-7.4983130863099E-05, 7./4}
23 #else
24 /*
25 WARNING NOTE:
26 These parameters are currently created by a curve fit to the REFPROP output
27 using Fityk. FIXME use the published parameters for these values, and work
28 out why they weren't correct earlier (for some reason, 'correct' values gave
29 a consistent 0.01% error relative to REFPROP output).
30
31 The following parameters are ALL larger than the 'official' values above by a
32 factor of about 1.000056. It would appear that REFPROP is using a different
33 value of cpstar in its calculations (The value 488.189 is clearly stated by
34 Tillner-Roth, but perhaps REFPROP chooses to use the molecular mass instead
35 of this value, or do some other kind of scaling...)
36 */
37 {9213.45/AMMONIA_R, -1./3.}
38 ,{0.290733/AMMONIA_R, 3./2.}
39 ,{-0.036608/AMMONIA_R, 7./4.}
40 #endif
41 }
42 , 0, (const IdealExpTerm *)0 /* no exponential terms */
43 };
44
45
46 /**
47 Residual (non-ideal) property data for Ammonia, from Tillner-Roth,
48 Harms-Watzenberg and Baehr, 'Eine neue Fundamentalgleichung f端r Ammoniak',
49 DKV-Tagungsbericht, 20:167-181, 1993. This is the ammmonia property correlation
50 recommended by NIST in its program REFPROP 7.0.
51 */
52 const HelmholtzData helmholtz_data_ammonia = {
53 /* R */ AMMONIA_R /* J/kg/K */
54 , /* M */ 17.03026 /* kg/kmol */
55 , /* rho_star */225. /* kg/m続 */
56 , /* T_star */ AMMONIA_TSTAR /* K */
57 , &ideal_data_ammonia
58 , 21 /* np */
59 , (const HelmholtzPowTerm[]){
60 /* a_i, t_i, d_i, l_i */
61 {0.4554431E-1, -0.5 , 2, 0}/* 1 */
62 ,{0.7238548E+0, 0.5 , 1, 0 }
63 ,{0.1229470E-1, 1 , 4, 0 }
64 ,{-0.1858814E+1, 1.5 , 1, 0 }
65 ,{0.2141882E-10, 3 , 15, 0 }/* 5 */
66 ,{-0.1430020E-1, 0 , 3, 1 }
67 ,{0.3441324E+0, 3 , 3, 1 }
68 ,{-0.2873571E+0, 4 , 1, 1 }
69 ,{0.2352589E-4, 4 , 8, 1 }
70 ,{-0.3497111E-1, 5 , 2, 1}/* 10 */
71 ,{0.2397852E-1, 3 , 1, 2}
72 ,{0.1831117E-2, 5 , 8, 2}
73 ,{-0.4085375E-1, 6 , 1, 2}
74 ,{0.2379275E+0, 8 , 2, 2}
75 ,{-0.3548972E-1, 8 , 3, 2}/* 15 */
76 ,{-0.1823729E+0, 10, 2, 2}
77 ,{0.2281556E-1, 10 , 4, 2}
78 ,{-0.6663444E-2, 5 , 3, 3}
79 ,{-0.8847486E-2, 7.5, 1, 3}
80 ,{0.2272635E-2 , 15 , 2, 3}/* 20 */
81 ,{-0.5588655E-3, 30, 4, 3}
82 }
83 , 0, 0 /* no exponential terms */
84 };
85
86
87 /*
88 Test suite. These tests attempt to validate the current code using
89 a few sample figures output by REFPROP 7.0.
90
91 To run the test, compile and run as follows:
92
93 gcc ideal.c helmholtz.c ammonia.c -DTEST -o ammonia -lm && ./ammonia
94
95 These tests all currently pass with a maximum error of 0.09%.
96 */
97 #ifdef TEST
98
99 #include <assert.h>
100 #include <stdlib.h>
101 #include <stdio.h>
102 #include <math.h>
103
104 typedef struct{double T,p,rho,u,h,s,cv,cp,cp0,a;} TestData;
105 const TestData td[]; const unsigned ntd;
106
107 int main(void){
108 unsigned n, i;
109 double rho, T, cp0, p, u, h, a, s;
110 const HelmholtzData *d;
111
112 d = &helmholtz_data_ammonia;
113 double maxerr = 0;
114
115 n = ntd;
116 fprintf(stderr,"Running through %d test points...\n",n);
117
118 /* a simple macro to actually do the testing */
119 #define ASSERT_TOL(FN,PARAM1,PARAM2,PARAM3,VAL,TOL) {\
120 double cval; cval = FN(PARAM1,PARAM2,PARAM3);\
121 double err; err = cval - (double)(VAL);\
122 double relerrpc = (cval-(VAL))/(VAL)*100;\
123 if(fabs(relerrpc)>maxerr)maxerr=fabs(relerrpc);\
124 if(fabs(err)>fabs(TOL)){\
125 fprintf(stderr,"ERROR in line %d: value of '%s(%f,%f,%s)' = %0.8f,"\
126 " should be %f, error is %.10e (%.2f%%)!\n"\
127 , __LINE__, #FN,PARAM1,PARAM2,#PARAM3, cval, VAL,cval-(VAL)\
128 ,relerrpc\
129 );\
130 exit(1);\
131 }else{\
132 fprintf(stderr," OK, %s(%f,%f,%s) = %8.2e with %.6f%% err.\n"\
133 ,#FN,PARAM1,PARAM2,#PARAM3,VAL,relerrpc\
134 );\
135 }\
136 }
137
138 #define CP0(T,RHO,DATA) helmholtz_cp0(T,DATA)
139
140 fprintf(stderr,"CP0 TESTS\n");
141 for(i=0; i<n;++i){
142 cp0 = td[i].cp0*1e3;
143 ASSERT_TOL(CP0, td[i].T+273.15, 0., d, cp0, cp0*1e-5);
144 }
145 #undef CP0
146
147 fprintf(stderr,"PRESSURE TESTS\n");
148 for(i=0; i<n;++i){
149 p = td[i].p*1e6;
150 ASSERT_TOL(helmholtz_p, td[i].T+273.15, td[i].rho, d, p, p*1e-3);
151 }
152
153 fprintf(stderr,"INTERNAL ENERGY TESTS\n");
154 for(i=0; i<n;++i){
155 u = td[i].u*1e3;
156 ASSERT_TOL(helmholtz_u, td[i].T+273.15, td[i].rho, d, u, u*1e-3);
157 }
158 fprintf(stderr,"ENTHALPY TESTS\n");
159 for(i=0; i<n;++i){
160 h = td[i].h*1e3;
161 ASSERT_TOL(helmholtz_h, td[i].T+273.15, td[i].rho, d, h, h*1e-3);
162 }
163
164
165 double CORRECTION_a = 0;// 1.8209310576e+06;
166 fprintf(stderr,"HELMHOLTZ ENERGY TESTS\n");
167 for(i=0; i<n;++i){
168 a = td[i].a*1e3 + CORRECTION_a;
169 ASSERT_TOL(helmholtz_a, td[i].T+273.15, td[i].rho, d, a, a*1e-3);
170 }
171
172 /* entropy offset required to attain agreement with REFPROP */
173 double Y = 0;
174 fprintf(stderr,"ENTROPY TESTS\n");
175 for(i=0; i<n;++i){
176 s = td[i].s*1e3 + Y;
177 ASSERT_TOL(helmholtz_s, td[i].T+273.15, td[i].rho, d, s, 1e-3*s);
178 }
179
180 fprintf(stderr,"Tests completed OK (maximum error = %0.2f%%)\n",maxerr);
181 exit(0);
182 }
183
184 /*
185 Some test data generated by REFPROP 7.0 for p=0.1, 1, 10, 20, 100 MPa.
186 */
187 const TestData td[] = {
188 /*{T/C, , p/MPa , rho/(kg/m3) , u/(kJ/kg) , h/(kJ/kg) , s/(kJ/kgK) , cv/(kJ/kgK) , cp(kJ/kgK) , cp0/(kJ/kgK) a/(kJ/kg)}*/
189 {-7.0E+1, 1.E-1, 7.247478262E+2, 3.229029237E+1, 3.24282714E+1, 1.620191045E-1, 2.920877051E+0, 4.244712246E+0, 2.008935269E+0, -6.238887074E-1}
190 , {-3.358834071E+1, 1.E-1, 6.822948922E+2, 1.906067908E+2, 1.90753355E+2, 8.784304761E-1, 2.855271402E+0, 4.446549354E+0, 2.027472493E+0, -1.983147159E+1}
191 , {-3.358834071E+1, 1.E-1, 8.786678914E-1, 1.447205955E+3, 1.561014597E+3, 6.5982992E+0, 1.703163454E+0, 2.294671598E+0, 2.027472493E+0, -1.3349355E+2}
192 , {-2.0E+1, 1.E-1, 8.263382177E-1, 1.470672235E+3, 1.591688059E+3, 6.722856799E+0, 1.664164155E+0, 2.226407096E+0, 2.039317099E+0, -2.312189638E+2}
193 , {3.0E+1, 1.E-1, 6.82304266E-1, 1.554101898E+3, 1.700664077E+3, 7.115863679E+0, 1.647471243E+0, 2.164362521E+0, 2.099810352E+0, -6.030721764E+2}
194 , {8.0E+1, 1.E-1, 5.831571413E-1, 1.638302054E+3, 1.80978242E+3, 7.448946867E+0, 1.706378596E+0, 2.209153449E+0, 2.179739223E+0, -9.922935323E+2}
195 , {1.30E+2, 1.E-1, 5.097610128E-1, 1.725968834E+3, 1.922139191E+3, 7.746386561E+0, 1.791930531E+0, 2.28877615E+0, 2.272754856E+0, -1.396986908E+3}
196 , {1.80E+2, 1.E-1, 4.5299046E-1, 1.818169337E+3, 2.038924538E+3, 8.019355389E+0, 1.89071839E+0, 2.384574213E+0, 2.374740669E+0, -1.815801558E+3}
197 , {2.30E+2, 1.E-1, 4.076912096E-1, 1.915461928E+3, 2.160745608E+3, 8.274268056E+0, 1.997259617E+0, 2.489413305E+0, 2.482853093E+0, -2.247736044E+3}
198 , {2.80E+2, 1.E-1, 3.706742442E-1, 2.018176941E+3, 2.287955598E+3, 8.515225293E+0, 2.108580854E+0, 2.599678959E+0, 2.595030777E+0, -2.69201993E+3}
199 , {3.30E+2, 1.E-1, 3.398445366E-1, 2.126514644E+3, 2.420766836E+3, 8.745015419E+0, 2.222765313E+0, 2.713166279E+0, 2.709721662E+0, -3.148041406E+3}
200 , {3.80E+2, 1.E-1, 3.137636628E-1, 2.240589284E+3, 2.559300504E+3, 8.965613422E+0, 2.338444972E+0, 2.828362941E+0, 2.825720964E+0, -3.615301123E+3}
201 , {-7.0E+1, 1.E+0, 7.250581532E+2, 3.191292802E+1, 3.329212774E+1, 1.601599414E-1, 2.923511889E+0, 4.241967721E+0, 2.008935269E+0, -6.235640687E-1}
202 , {-2.0E+1, 1.E+0, 6.655956817E+2, 2.50822066E+2, 2.523244796E+2, 1.122985212E+0, 2.83379452E+0, 4.509597946E+0, 2.039317099E+0, -3.346164026E+1}
203 , {2.489509207E+1, 1.E+0, 6.029210949E+2, 4.586595787E+2, 4.603181705E+2, 1.878768996E+0, 2.764789412E+0, 4.783527097E+0, 2.092608239E+0, -1.012982998E+2}
204 , {2.489509207E+1, 1.E+0, 7.782283811E+0, 1.498025198E+3, 1.626522182E+3, 5.791613203E+0, 2.129812148E+0, 3.133024821E+0, 2.092608239E+0, -2.281366922E+2}
205 , {3.0E+1, 1.E+0, 7.573646544E+0, 1.510151287E+3, 1.64218808E+3, 5.843733285E+0, 2.071473976E+0, 3.009079611E+0, 2.099810352E+0, -2.613764583E+2}
206 , {8.0E+1, 1.E+0, 6.146734558E+0, 1.614152301E+3, 1.776840309E+3, 6.255779773E+0, 1.85362895E+0, 2.516587992E+0, 2.179739223E+0, -5.950763259E+2}
207 , {1.30E+2, 1.E+0, 5.259177246E+0, 1.709991264E+3, 1.900135075E+3, 6.582405217E+0, 1.860827189E+0, 2.443994372E+0, 2.272754856E+0, -9.437053987E+2}
208 , {1.80E+2, 1.E+0, 4.621587996E+0, 1.806536743E+3, 2.022912586E+3, 6.869456377E+0, 1.928949229E+0, 2.476922143E+0, 2.374740669E+0, -1.306357415E+3}
209 , {2.30E+2, 1.E+0, 4.132311779E+0, 1.906483833E+3, 2.148479127E+3, 7.132238182E+0, 2.020971903E+0, 2.550089921E+0, 2.482853093E+0, -1.682101808E+3}
210 , {2.80E+2, 1.E+0, 3.741648311E+0, 2.010971322E+3, 2.278233212E+3, 7.378029463E+0, 2.124500592E+0, 2.642300555E+0, 2.595030777E+0, -2.070185676E+3}
211 , {3.30E+2, 1.E+0, 3.421067224E+0, 2.120568346E+3, 2.412874791E+3, 7.610994396E+0, 2.234107913E+0, 2.744579111E+0, 2.709721662E+0, -2.470002925E+3}
212 , {3.80E+2, 1.E+0, 3.152561727E+0, 2.235579603E+3, 2.552781957E+3, 7.833784037E+0, 2.346907298E+0, 2.85236643E+0, 2.825720964E+0, -2.881056441E+3}
213 , {-7.0E+1, 1.E+1, 7.281133559E+2, 2.82467347E+1, 4.198085991E+1, 1.41957312E-1, 2.948363488E+0, 4.215226705E+0, 2.008935269E+0, -5.918932355E-1}
214 , {-2.0E+1, 1.E+1, 6.705474103E+2, 2.444309266E+2, 2.593441153E+2, 1.097500056E+0, 2.847709968E+0, 4.466308713E+0, 2.039317099E+0, -3.34012126E+1}
215 , {3.0E+1, 1.0E+1, 6.036532714E+2, 4.718115329E+2, 4.883773339E+2, 1.922486043E+0, 2.76482419E+0, 4.716399214E+0, 2.099810352E+0, -1.109901112E+2}
216 , {8.0E+1, 1.E+1, 5.191766069E+2, 7.182881257E+2, 7.375493941E+2, 2.682019021E+0, 2.725818451E+0, 5.40010006E+0, 2.179739223E+0, -2.288668917E+2}
217 , {1.251668991E+2, 1.0E+1, 3.566957919E+2, 1.036686156E+3, 1.064721249E+3, 3.546261425E+0, 3.120852518E+0, 1.799912569E+1, 2.263318196E+0, -3.758496986E+2}
218 , {1.251668991E+2, 1.0E+1, 1.215794756E+2, 1.368344633E+3, 1.450595358E+3, 4.515023005E+0, 3.549403632E+0, 2.75480558E+1, 2.263318196E+0, -4.300653297E+2}
219 , {1.30E+2, 1.0E+1, 1.006607688E+2, 1.433765286E+3, 1.533108854E+3, 4.721093813E+0, 3.179462337E+0, 1.218949302E+1, 2.272754856E+0, -4.69543685E+2}
220 , {1.80E+2, 1.0E+1, 6.013676382E+1, 1.664224216E+3, 1.830511847E+3, 5.423234397E+0, 2.370777153E+0, 4.100436931E+0, 2.374740669E+0, -7.93314451E+2}
221 , {2.30E+2, 1.E+1, 4.825185325E+1, 1.806069112E+3, 2.013315037E+3, 5.806541293E+0, 2.265129959E+0, 3.370696776E+0, 2.482853093E+0, -1.11549214E+3}
222 , {2.80E+2, 1.0E+1, 4.136336686E+1, 1.933702328E+3, 2.175462144E+3, 6.11393854E+0, 2.282610344E+0, 3.155805732E+0, 2.595030777E+0, -1.448222776E+3}
223 , {3.30E+2, 1.0E+1, 3.661170108E+1, 2.058308433E+3, 2.331445154E+3, 6.383938033E+0, 2.345404767E+0, 3.099738472E+0, 2.709721662E+0, -1.792163792E+3}
224 , {3.80E+2, 1.0E+1, 3.303984101E+1, 2.183905783E+3, 2.486570677E+3, 6.631017385E+0, 2.429601299E+0, 3.113246758E+0, 2.825720964E+0, -2.147143222E+3}
225 , {-7.0E+1, 2.E+1, 7.314110284E+2, 2.438989319E+1, 5.173429903E+1, 1.225158918E-1, 2.97295095E+0, 4.186833561E+0, 2.008935269E+0, -4.992102225E-1}
226 , {-2.0E+1, 2.E+1, 6.757461174E+2, 2.378074747E+2, 2.674043891E+2, 1.070658825E+0, 2.862424736E+0, 4.424294578E+0, 2.039317099E+0, -3.322980699E+1}
227 , {3.0E+1, 2.0E+1, 6.122156933E+2, 4.606156644E+2, 4.932838894E+2, 1.884416733E+0, 2.77478908E+0, 4.620255644E+0, 2.099810352E+0, -1.106452683E+2}
228 , {8.0E+1, 2.E+1, 5.368145605E+2, 6.956794002E+2, 7.329362138E+2, 2.615362829E+0, 2.713627362E+0, 5.036284223E+0, 2.179739223E+0, -2.279359829E+2}
229 , {1.30E+2, 2.0E+1, 4.294999502E+2, 9.663897317E+2, 1.012955511E+3, 3.354873661E+0, 2.741137614E+0, 6.544104233E+0, 2.272754856E+0, -3.861275849E+2}
230 , {1.80E+2, 2.0E+1, 2.039788488E+2, 1.395383189E+3, 1.493432571E+3, 4.471185097E+0, 2.869863104E+0, 1.043542616E+1, 2.374740669E+0, -6.307343372E+2}
231 , {2.30E+2, 2.0E+1, 1.191595281E+2, 1.667907891E+3, 1.835750113E+3, 5.192497178E+0, 2.520294197E+0, 4.955556508E+0, 2.482853093E+0, -9.446970641E+2}
232 , {2.80E+2, 2.0E+1, 9.305602458E+1, 1.837529361E+3, 2.052453651E+3, 5.603863917E+0, 2.442250471E+0, 3.919373117E+0, 2.595030777E+0, -1.262247965E+3}
233 , {3.30E+2, 2.E+1, 7.87847032E+1, 1.984385217E+3, 2.238241603E+3, 5.925629929E+0, 2.457876404E+0, 3.567673051E+0, 2.709721662E+0, -1.589658474E+3}
234 , {3.80E+2, 2.0E+1, 6.930562563E+1, 2.124157386E+3, 2.412734248E+3, 6.20363454E+0, 2.513826097E+0, 3.43455809E+0, 2.825720964E+0, -1.927746514E+3}
235 , {-2.0E+1, 1.E+2, 7.097079501E+2, 1.971623979E+2, 3.380654271E+2, 8.941118487E-1, 2.948865706E+0, 4.209874651E+0, 2.039317099E+0, -2.918201662E+1}
236 , {3.0E+1, 1.00E+2, 6.609898909E+2, 3.99293994E+2, 5.505822381E+2, 1.660051479E+0, 2.865882923E+0, 4.272619565E+0, 2.099810352E+0, -1.039506117E+2}
237 , {8.0E+1, 1.00E+2, 6.112193023E+2, 6.009802061E+2, 7.645876046E+2, 2.313447447E+0, 2.790639905E+0, 4.287734917E+0, 2.179739223E+0, -2.160137598E+2}
238 , {1.30E+2, 1.E+2, 5.605676047E+2, 8.013221537E+2, 9.797127692E+2, 2.88311668E+0, 2.735688771E+0, 4.322269403E+0, 2.272754856E+0, -3.610063358E+2}
239 , {1.80E+2, 1.00E+2, 5.091016945E+2, 1.000810051E+3, 1.197234461E+3, 3.391678155E+0, 2.70641506E+0, 4.380908617E+0, 2.374740669E+0, -5.361289048E+2}
240 , {2.30E+2, 1.00E+2, 4.577648376E+2, 1.19928899E+3, 1.417741767E+3, 3.853216148E+0, 2.701336718E+0, 4.435601393E+0, 2.482853093E+0, -7.394567146E+2}
241 , {2.80E+2, 1.00E+2, 4.085537409E+2, 1.39536859E+3, 1.640134431E+3, 4.274597549E+0, 2.715900681E+0, 4.45131851E+0, 2.595030777E+0, -9.691250446E+2}
242 , {3.30E+2, 1.00E+2, 3.638085408E+2, 1.587052868E+3, 1.86192272E+3, 4.658479239E+0, 2.745812238E+0, 4.411199889E+0, 2.709721662E+0, -1.222708885E+3}
243 , {3.80E+2, 1.00E+2, 3.251311703E+2, 1.772997776E+3, 2.080565949E+3, 5.006781049E+0, 2.788309263E+0, 4.330393148E+0, 2.825720964E+0, -1.497181267E+3}
244 };
245
246 const unsigned ntd = sizeof(td)/sizeof(TestData);
247
248 #endif

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