/[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 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: 10216 byte(s)
Added 'exponential' terms for nitrogen correlation (still testing).
1 #include "ammonia.h"
2
3
4 /**
5 Ideal gas data for Ammonia, from Tillner-Roth, Harms-Watzenberg and
6 Baehr, 'Eine neue Fundamentalgleichung f端r Ammoniak', DKV-Tagungsbericht,
7 20:167-181, 1993. This is the ammmonia property correlation recommended
8 by NIST in its program REFPROP 7.0.
9 */
10 const IdealData ideal_data_ammonia = {
11 -15.815020 /* const */
12 , 4.255726 /* linear */
13 , 3 /* power terms */
14 , (const IdealPowTerm[]){
15 {11.474340, 1./3 }
16 ,{-1.296211, -3./2.}
17 ,{0.5706757, -7./4.}
18 }
19 , 0, (const IdealExpTerm *)0 /* no exponential terms */
20 };
21
22
23 /**
24 Residual (non-ideal) property data for Ammonia, from Tillner-Roth,
25 Harms-Watzenberg and Baehr, 'Eine neue Fundamentalgleichung f端r Ammoniak',
26 DKV-Tagungsbericht, 20:167-181, 1993. This is the ammmonia property correlation
27 recommended by NIST in its program REFPROP 7.0.
28 */
29 const HelmholtzData helmholtz_data_ammonia = {
30 /* R */ 488.189 /* J/kg/K */
31 , /* M */ 17.03026 /* kg/kmol */
32 , /* rho_star */225. /* kg/m続 */
33 , /* T_star */ 405.40 /* K */
34 , &ideal_data_ammonia
35 , 21 /* np */
36 , (const HelmholtzPowTerm[]){
37 /* a_i, t_i, d_i, l_i */
38 {0.4554431E-1, -0.5 , 2, 0}/* 1 */
39 ,{0.7238548E+0, 0.5 , 1, 0 }
40 ,{0.1229470E-1, 1 , 4, 0 }
41 ,{-0.1858814E+1, 1.5 , 1, 0 }
42 ,{0.2141882E-10, 3 , 15, 0 }/* 5 */
43 ,{-0.1430020E-1, 0 , 3, 1 }
44 ,{0.3441324E+0, 3 , 3, 1 }
45 ,{-0.2873571E+0, 4 , 1, 1 }
46 ,{0.2352589E-4, 4 , 8, 1 }
47 ,{-0.3497111E-1, 5 , 2, 1}/* 10 */
48 ,{0.2397852E-1, 3 , 1, 2}
49 ,{0.1831117E-2, 5 , 8, 2}
50 ,{-0.4085375E-1, 6 , 1, 2}
51 ,{0.2379275E+0, 8 , 2, 2}
52 ,{-0.3548972E-1, 8 , 3, 2}/* 15 */
53 ,{-0.1823729E+0, 10, 2, 2}
54 ,{0.2281556E-1, 10 , 4, 2}
55 ,{-0.6663444E-2, 5 , 3, 3}
56 ,{-0.8847486E-2, 7.5, 1, 3}
57 ,{0.2272635E-2 , 15 , 2, 3}/* 20 */
58 ,{-0.5588655E-3, 30, 4, 3}
59 }
60 , 0, 0 /* no exponential terms */
61 };
62
63
64 /*
65 Test suite. These tests attempt to validate the current code using
66 a few sample figures output by REFPROP 7.0.
67
68 To run the test, compile and run as follows:
69
70 gcc helmholtz.c ammonia.c -DTEST -o ammonia -lm && ./ammonia
71
72 These tests all currently pass with a maximum error of 2%. The error
73 seems to arise in the enthalpy data for low temperatures. Haven't been
74 able to determine where the problem comes from.
75 */
76 #ifdef TEST
77
78 #include <assert.h>
79 #include <stdlib.h>
80 #include <stdio.h>
81 #include <math.h>
82
83 /* a simple macro to actually do the testing */
84 #define ASSERT_TOL(EXPR,VAL,TOL) {\
85 double cval; cval = (EXPR);\
86 double err; err = cval - (double)(VAL);\
87 double relerrpc = (cval-(VAL))/(VAL)*100;\
88 if(fabs(relerrpc)>maxerr)maxerr=fabs(relerrpc);\
89 if(fabs(err)>TOL){\
90 fprintf(stderr,"ERROR in line %d: value of '%s' = %f, should be %f, error is %f (%.2f%%)!\n"\
91 , __LINE__, #EXPR, cval, VAL,cval-(VAL),relerrpc);\
92 exit(1);\
93 }else{\
94 fprintf(stderr," OK, %s = %8.2e with %.2f%% err.\n",#EXPR,VAL,relerrpc);\
95 /*fprintf(stderr," (err = %8.2e, tol = %8.2e, calc = %8.2e)\n",fabs(err),TOL,cval);*/\
96 }\
97 }
98
99 int main(void){
100 double rho, T, p, h, u;
101 const HelmholtzData *d;
102
103 d = &helmholtz_data_ammonia;
104 double maxerr = 0;
105
106 fprintf(stderr,"PRESSURE TESTS\n");
107
108 fprintf(stderr,"p(T,rho) = 0.1 MPa\n");
109 ASSERT_TOL(helmholtz_p(273.15 -70,724.74783,d), 0.1E6, 1E3);
110 ASSERT_TOL(helmholtz_p(273.15 -60,713.64815,d), 0.1E6, 1E3);
111 ASSERT_TOL(helmholtz_p(273.15 -50,702.11130,d), 0.1E6, 1E3);
112 ASSERT_TOL(helmholtz_p(273.15 -40,690.16351,d), 0.1E6, 1E3);
113 ASSERT_TOL(helmholtz_p(273.15 -33.588341,682.29489,d), 0.1E6,1E3);
114 ASSERT_TOL(helmholtz_p(273.15+ 0,0.76123983,d), 0.1E6, 1E3);
115 ASSERT_TOL(helmholtz_p(273.15+100,0.55135,d), 0.1E6, 1E3);
116 ASSERT_TOL(helmholtz_p(273.15+250,0.39203,d), 0.1E6, 1E3);
117 ASSERT_TOL(helmholtz_p(273.15+420,0.29562,d), 0.1E6, 1E3);
118
119 fprintf(stderr,"p(T,rho) = 1 MPa\n");
120 ASSERT_TOL(helmholtz_p(273.15 -70,725.05815,d), 1E6, 1E3);
121 ASSERT_TOL(helmholtz_p(273.15+ 0,638.97275,d), 1E6, 1E3);
122 ASSERT_TOL(helmholtz_p(273.15+ 30,7.5736465,d), 1E6, 1E3);
123 ASSERT_TOL(helmholtz_p(273.15+150,4.9816537,d), 1E6, 1E3);
124 ASSERT_TOL(helmholtz_p(273.15+200,4.4115,d), 1E6, 1E3);
125 ASSERT_TOL(helmholtz_p(273.15+350,3.3082,d), 1E6, 1E3);
126 ASSERT_TOL(helmholtz_p(273.15+420,2.9670,d), 1E6, 1E3);
127
128 fprintf(stderr,"p(T,rho) = 10 MPa\n");
129 ASSERT_TOL(helmholtz_p(273.15+-40.,694.67407,d), 10E6, 1E3);
130 ASSERT_TOL(helmholtz_p(273.15+-20.,670.54741,d), 10E6, 1E3);
131 ASSERT_TOL(helmholtz_p(273.15+50,573.07306,d), 10E6, 1E3);
132 ASSERT_TOL(helmholtz_p(273.15+110,441.76869,d), 10E6, 1E3);
133 ASSERT_TOL(helmholtz_p(273.15+150,74.732,d), 10E6, 1E3);
134 ASSERT_TOL(helmholtz_p(273.15+200,54.389,d), 10E6, 1E3);
135 ASSERT_TOL(helmholtz_p(273.15+350,35.072,d), 10E6, 1E3);
136 ASSERT_TOL(helmholtz_p(273.15+420,30.731,d), 10E6, 1E3);
137
138 fprintf(stderr,"p(T,rho) = 20 MPa\n");
139 ASSERT_TOL(helmholtz_p(273.15+150,359.40683,d), 20E6, 1E4);
140 ASSERT_TOL(helmholtz_p(273.15+200,152.83430,d), 20E6, 1E4);
141 ASSERT_TOL(helmholtz_p(273.15+350,74.590236,d), 20E6, 1E4);
142 ASSERT_TOL(helmholtz_p(273.15+420,63.601873,d), 20E6, 1E4);
143
144 //fprintf(stderr,"IDEAL HELMHOLTZ COMPONENT\n");
145 //ASSERT_TOL(helm_ideal(273.15, 0)
146
147 fprintf(stderr,"ENTHALPY TESTS\n");
148
149 /* this offset is required to attain agreement with values from REFPROP */
150 double Z = -1635.7e3 + 1492.411e3;
151
152 fprintf(stderr,"h(T,rho) at p = 0.1 MPa\n");
153 ASSERT_TOL(helmholtz_h(273.15+-60, 713.65,d), Z+75.166e3, 0.2e3);
154 ASSERT_TOL(helmholtz_h(273.15+ 0,0.76124,d), Z+1635.7e3, 0.2e3);
155 ASSERT_TOL(helmholtz_h(273.15+ 50,0.63869,d), Z+1744.0e3, 0.2e3);
156 ASSERT_TOL(helmholtz_h(273.15+200,0.43370,d), Z+2087.0e3, 0.2e3);
157 ASSERT_TOL(helmholtz_h(273.15+300,0.35769,d), Z+2340.0e3, 1e3);
158 ASSERT_TOL(helmholtz_h(273.15+420,0.29562,d), Z+2674.3e3, 1e3);
159
160 fprintf(stderr,"h(T,rho) at p = 1 MPa\n");
161 ASSERT_TOL(helmholtz_h(273.15+150,4.9817,d), Z+1949.1e3, 1e3);
162 ASSERT_TOL(helmholtz_h(273.15+200,4.4115,d), Z+2072.7e3, 1e3);
163 ASSERT_TOL(helmholtz_h(273.15+350,3.3082,d), Z+2468.2e3, 1e3);
164 ASSERT_TOL(helmholtz_h(273.15+420,2.9670,d), Z+2668.6e3, 1e3);
165
166 fprintf(stderr,"h(T,rho) at p = 10 MPa\n");
167 ASSERT_TOL(helmholtz_h(273.15+-50,706.21,d), Z+127.39e3, 2e3);
168 ASSERT_TOL(helmholtz_h(273.15+-0,645.04,d), Z+349.53e3, 2e3);
169
170 ASSERT_TOL(helmholtz_h(273.15+150,74.732,d), Z+1688.5e3, 1e3);
171 ASSERT_TOL(helmholtz_h(273.15+200,54.389,d), Z+1908.0e3, 1e3);
172 ASSERT_TOL(helmholtz_h(273.15+350,35.072,d), Z+2393.4e3, 1e3);
173 ASSERT_TOL(helmholtz_h(273.15+420,30.731,d), Z+2611.8e3, 1e3);
174
175 fprintf(stderr,"h(T,rho) at p = 20 MPa\n");
176 /* note rather larger errors in the following few lines -- why? */
177 ASSERT_TOL(helmholtz_h(273.15 -70,731.41,d), Z+51.734e3, 0.5e3);
178 ASSERT_TOL(helmholtz_h(273.15 -60,721.00318,d), Z+93.871419e3, 0.5e3);
179 ASSERT_TOL(helmholtz_h(273.15 -50,710.19289,d), Z+136.54351e3, 1e3);
180 ASSERT_TOL(helmholtz_h(273.15 -40,699.02472,d), Z+179.72030e3, 0.5e3);
181 ASSERT_TOL(helmholtz_h(273.15+ 30,612.22,d), Z+493.28e3, 0.5e3);
182 ASSERT_TOL(helmholtz_h(273.15+150,359.40683,d), Z+1162.5e3, 0.5e3);
183 ASSERT_TOL(helmholtz_h(273.15+200,152.83430,d), Z+1662.9e3, 0.5e3);
184 ASSERT_TOL(helmholtz_h(273.15+250,106.31299,d), Z+1928.6499e3, 0.5e3);
185 ASSERT_TOL(helmholtz_h(273.15+300,86.516941,d), Z+2128.9031e3, 0.5e3);
186 ASSERT_TOL(helmholtz_h(273.15+330,78.784703,d), Z+2238.2416e3, 0.5e3);
187 ASSERT_TOL(helmholtz_h(273.15+350,74.590236,d), Z+2308.8516e3, 10e3);
188 ASSERT_TOL(helmholtz_h(273.15+420,63.601873,d), Z+2549.2872e3, 10e3);
189
190 fprintf(stderr,"h(T,rho) at p = 100 MPa\n");
191 ASSERT_TOL(helmholtz_h(273.15+ 0,690.41,d), Z+422.69e3, 0.5e3);
192 ASSERT_TOL(helmholtz_h(273.15+100,591.07,d), Z+850.44e3, 0.1e3);
193 ASSERT_TOL(helmholtz_h(273.15+250,437.69,d), Z+1506.6e3, 1e3);
194 ASSERT_TOL(helmholtz_h(273.15+420,298.79,d), Z+2252.3e3, 1e3);
195
196
197
198 fprintf(stderr,"ENTROPY TESTS\n");
199
200 /* offset required to attain agreement with REFPROP */
201 double Y = -471.596704;
202
203 fprintf(stderr,"s(T,rho) at p = 0.1 MPa\n");
204 ASSERT_TOL(helmholtz_s(273.15+-60, 713.65,d), Y+0.36737e3, 0.5);
205 ASSERT_TOL(helmholtz_s(273.15+ 0,0.76124,d), Y+6.8900e3, 0.5);
206 ASSERT_TOL(helmholtz_s(273.15+ 50,0.63869,d), Y+7.2544e3, 0.5);
207 ASSERT_TOL(helmholtz_s(273.15+200,0.43370,d), Y+8.1232e3, 0.5);
208 ASSERT_TOL(helmholtz_s(273.15+300,0.35769,d), Y+8.6084e3, 1);
209 ASSERT_TOL(helmholtz_s(273.15+420,0.29562,d), Y+9.1365e3, 1);
210
211 fprintf(stderr,"s(T,rho) at p = 1 MPa\n");
212 ASSERT_TOL(helmholtz_s(273.15+-50,702.49,d), Y+0.56381e3, 0.5);
213 ASSERT_TOL(helmholtz_s(273.15+150,4.9817,d), Y+6.7008e3, 0.5);
214 ASSERT_TOL(helmholtz_s(273.15+200,4.4115,d), Y+6.9770e3, 0.5);
215 ASSERT_TOL(helmholtz_s(273.15+350,3.3082,d), Y+7.7012e3, 0.5);
216 ASSERT_TOL(helmholtz_s(273.15+420,2.9670,d), Y+8.0059e3, 0.5);
217
218 fprintf(stderr,"s(T,rho) at p = 10 MPa\n");
219 ASSERT_TOL(helmholtz_s(273.15+-70,728.11,d), Y+0.14196e3, 1);
220 ASSERT_TOL(helmholtz_s(273.15+-50,706.21,d), Y+0.54289e3, 1);
221 ASSERT_TOL(helmholtz_s(273.15+-20,670.55,d), Y+1.0975e3, 1);
222 ASSERT_TOL(helmholtz_s(273.15+ 0,645.04,d), Y+1.4403e3, 1);
223 ASSERT_TOL(helmholtz_s(273.15+125.17,356.70,d), Y+3.5463e3, 1);
224
225 ASSERT_TOL(helmholtz_s(273.15+125.17,121.58,d), Y+4.5150e3, 1);
226 ASSERT_TOL(helmholtz_s(273.15+200,54.389,d), Y+5.5906e3, 1);
227 ASSERT_TOL(helmholtz_s(273.15+350,35.072,d), Y+6.4850e3, 1);
228 ASSERT_TOL(helmholtz_s(273.15+420,30.731,d), Y+6.8171e3, 1);
229
230 fprintf(stderr,"s(T,rho) at p = 20 MPa\n");
231 ASSERT_TOL(helmholtz_s(273.15+-50,710.19,d), Y+0.52061e3, 1);
232 ASSERT_TOL(helmholtz_s(273.15+ 30,612.22,d), Y+1.8844e3, 1);
233 ASSERT_TOL(helmholtz_s(273.15+150,359.41,d), Y+3.7164e3, 1);
234 ASSERT_TOL(helmholtz_s(273.15+200,152.83,d), Y+4.8376e3, 1);
235 ASSERT_TOL(helmholtz_s(273.15+350,74.590,d), Y+6.0407e3, 1);
236 ASSERT_TOL(helmholtz_s(273.15+420,63.602,d), Y+6.4066e3, 1);
237
238 fprintf(stderr,"s(T,rho) at p = 100 MPa\n");
239 ASSERT_TOL(helmholtz_s(273.15+ 0,690.41,d), Y+1.2158e3, 1);
240 ASSERT_TOL(helmholtz_s(273.15+100,591.07,d), Y+2.5499e3, 1);
241 ASSERT_TOL(helmholtz_s(273.15+250,437.69,d), Y+4.0264e3, 1);
242 ASSERT_TOL(helmholtz_s(273.15+420,298.79,d), Y+5.2620e3, 1);
243
244 /* successful entropy tests means that helm_ideal_tau, helm_real_tau, helm_ideal and helm_resid are all OK */
245
246 fprintf(stderr,"Tests completed OK (maximum error = %0.2f%%)\n",maxerr);
247 exit(0);
248 }
249 #endif

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